commit d1c25f4c52c122a081d1a8465197c69ac62a7ee5
parent 34baf1391a813f41ee4bfdfeeda1259e6d65e022
Author: Christos Margiolis <christos@margiolis.net>
Date: Wed, 26 Aug 2020 00:15:36 +0300
added chip8 in front of functions
Diffstat:
7 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1 +1,3 @@
/roms/*
+/obj/
+/bin/
diff --git a/bin/chip8 b/bin/chip8
Binary files differ.
diff --git a/obj/chip8.o b/obj/chip8.o
Binary files differ.
diff --git a/obj/main.o b/obj/main.o
Binary files differ.
diff --git a/src/chip8.c b/src/chip8.c
@@ -52,7 +52,7 @@ chip8_init(Chip8 *chip8)
}
int
-rom_load(Chip8 *chip8, const char *fpath)
+chip8_rom_load(Chip8 *chip8, const char *fpath)
{
FILE *rom = fopen(fpath, "rb");
if (rom == NULL)
@@ -94,26 +94,26 @@ rom_load(Chip8 *chip8, const char *fpath)
}
void
-emulate(Chip8 *chip8)
+chip8_emulate(Chip8 *chip8)
{
- fetch(chip8);
- if (decode(chip8))
+ chip8_fetch(chip8);
+ if (chip8_decode(chip8))
{
- execute(chip8);
- timers_update(chip8);
+ chip8_execute(chip8);
+ chip8_timers_update(chip8);
}
printf("opcode: %x\tmemory: %x\tI: %x\tsp: %x\tpc: %d\n",
opcode, memory[pc] << 8 | memory[pc + 1], I, sp, pc);
}
void
-fetch(Chip8 *chip8)
+chip8_fetch(Chip8 *chip8)
{
opcode = memory[pc] << 8 | memory[pc + 1];
}
int
-decode(Chip8 *chip8)
+chip8_decode(Chip8 *chip8)
{
int i;
switch (opcode & 0xF000)
@@ -307,13 +307,13 @@ decode(Chip8 *chip8)
}
void
-execute(Chip8 *chip8)
+chip8_execute(Chip8 *chip8)
{
pc += 2;
}
void
-timers_update(Chip8 *chip8)
+chip8_timers_update(Chip8 *chip8)
{
if (delaytimer > 0) --delaytimer;
if (soundtimer > 0) --soundtimer;
diff --git a/src/chip8.h b/src/chip8.h
@@ -28,11 +28,11 @@ typedef struct {
extern Chip8 chip8;
extern void chip8_init(Chip8 *chip8);
-extern int rom_load(Chip8 *chip8, const char *fpath);
-extern void emulate(Chip8 *chip8);
-extern void fetch(Chip8 *chip8);
-extern int decode(Chip8 *chip8);
-extern void execute(Chip8 *chip8);
-extern void timers_update(Chip8 *chip8);
+extern int chip8_rom_load(Chip8 *chip8, const char *fpath);
+extern void chip8_emulate(Chip8 *chip8);
+extern void chip8_fetch(Chip8 *chip8);
+extern int chip8_decode(Chip8 *chip8);
+extern void chip8_execute(Chip8 *chip8);
+extern void chip8_timers_update(Chip8 *chip8);
#endif /* CHIP8_H */
diff --git a/src/main.c b/src/main.c
@@ -14,11 +14,8 @@ static const uint8_t keymap[16] = {
SDLK_c, SDLK_v,
};
-static int handle_events(Chip8 *chip8);
-static void render(SDL_Renderer *r, SDL_Texture *t, Chip8 *chip8);
-
-int
-handle_events(Chip8 *chip8)
+static int
+events_handle(Chip8 *chip8)
{
int i;
SDL_Event e;
@@ -40,7 +37,7 @@ handle_events(Chip8 *chip8)
return TRUE;
}
-void
+static void
render(SDL_Renderer *r, SDL_Texture *t, Chip8 *chip8)
{
int i;
@@ -92,11 +89,11 @@ main(int argc, char **argv)
Chip8 chip8;
chip8_init(&chip8);
- if (!rom_load(&chip8, argv[1])) return EXIT_FAILURE;
+ if (!chip8_rom_load(&chip8, argv[1])) return EXIT_FAILURE;
for (;;)
{
- emulate(&chip8);
- if (!handle_events(&chip8)) return EXIT_SUCCESS;
+ chip8_emulate(&chip8);
+ if (!events_handle(&chip8)) return EXIT_SUCCESS;
if (chip8.drawflag) render(renderer, texture, &chip8);
usleep(1500);
}