chip8

CHIP-8 emulator
git clone git://git.christosmarg.xyz/chip8.git
Log | Files | Refs | README | LICENSE

commit e96d56baefc3ef1e745ffb1415d7d6aaa1c077f3
parent 787cfac056e7ac9967196cb7943b857da6aa1a78
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu, 18 Jun 2020 19:46:31 +0300

minor changes (namings)

Diffstat:
Mbin/chip8 | 0
Mobj/chip8.o | 0
Mobj/main.o | 0
Msrc/chip8.c | 6+++---
Msrc/chip8.h | 40+++++++++++++++++++---------------------
Msrc/main.c | 7+++----
6 files changed, 25 insertions(+), 28 deletions(-)

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 @@ -53,7 +53,7 @@ chip8_init(Chip8 *chip8) } int -load(Chip8 *chip8, const char *fpath) +rom_load(Chip8 *chip8, const char *fpath) { FILE *rom = fopen(fpath, "rb"); if (rom == NULL) @@ -101,7 +101,7 @@ emulate(Chip8 *chip8) if (decode(chip8)) { execute(chip8); - update_timers(chip8); + timers_update(chip8); } LOG("opcode: %x\tmemory: %x\tI: %x\tsp: %x\tpc: %d", opcode, memory[pc] << 8 | memory[pc + 1], I, sp, pc); @@ -314,7 +314,7 @@ execute(Chip8 *chip8) } void -update_timers(Chip8 *chip8) +timers_update(Chip8 *chip8) { if (delaytimer > 0) --delaytimer; if (soundtimer > 0) --soundtimer; diff --git a/src/chip8.h b/src/chip8.h @@ -14,30 +14,28 @@ #define ERROR(format, ...) (fprintf(stderr, format"\n", __VA_ARGS__)) typedef struct { - uint8_t memory[4096]; - uint16_t stack[16]; - uint16_t sp; - - uint8_t V[16]; - uint16_t opcode; - uint16_t I; - uint16_t pc; - - uint8_t delaytimer; - uint8_t soundtimer; - uint8_t gfx[64 * 32]; - uint8_t keys[16]; - int drawflag; + uint8_t memory[4096]; + uint8_t V[16]; + uint8_t gfx[64 * 32]; + uint8_t keys[16]; + uint8_t delaytimer; + uint8_t soundtimer; + uint8_t drawflag; + uint16_t stack[16]; + uint16_t sp; + uint16_t opcode; + uint16_t I; + uint16_t pc; } Chip8; extern Chip8 chip8; -void chip8_init(Chip8 *chip8); -int load(Chip8 *chip8, const char *fpath); -void emulate(Chip8 *chip8); -void fetch(Chip8 *chip8); -int decode(Chip8 *chip8); -void execute(Chip8 *chip8); -void update_timers(Chip8 *chip8); +void chip8_init(Chip8 *chip8); +int rom_load(Chip8 *chip8, const char *fpath); +void emulate(Chip8 *chip8); +void fetch(Chip8 *chip8); +int decode(Chip8 *chip8); +void execute(Chip8 *chip8); +void timers_update(Chip8 *chip8); #endif /* CHIP8_H */ diff --git a/src/main.c b/src/main.c @@ -1,7 +1,7 @@ #define _DEFAULT_SOURCE -#include "chip8.h" #include <SDL2/SDL.h> #include <unistd.h> +#include "chip8.h" static const uint8_t keymap[16] = { SDLK_1, SDLK_2, @@ -14,7 +14,7 @@ static const uint8_t keymap[16] = { SDLK_c, SDLK_v, }; -static int handle_events(Chip8 *chip8); +static int handle_events(Chip8 *chip8); static void render(SDL_Renderer *r, SDL_Texture *t, Chip8 *chip8); int @@ -32,7 +32,6 @@ handle_events(Chip8 *chip8) if (e.key.keysym.sym == keymap[i]) chip8->keys[i] = TRUE; } - if (e.type == SDL_KEYUP) for (i = 0; i < 16; i++) if (e.key.keysym.sym == keymap[i]) @@ -93,7 +92,7 @@ main(int argc, char **argv) Chip8 chip8; chip8_init(&chip8); - if (!load(&chip8, argv[1])) return EXIT_FAILURE; + if (!rom_load(&chip8, argv[1])) return EXIT_FAILURE; for (;;) { emulate(&chip8);