diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-20 20:57:40 +0100 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-20 20:57:40 +0100 |
commit | 976a1b93fa7a43ae17bdcf1b39707c083e83b625 (patch) | |
tree | 0c6d9134f065de609cff0348ae6ddda364ff7340 | |
parent | Feature: Implemented various instructions (diff) | |
download | CHIP8-Emulator-976a1b93fa7a43ae17bdcf1b39707c083e83b625.tar.gz CHIP8-Emulator-976a1b93fa7a43ae17bdcf1b39707c083e83b625.tar.bz2 CHIP8-Emulator-976a1b93fa7a43ae17bdcf1b39707c083e83b625.zip |
Refractoring: Refractored the stepping of the PC into a function
-rw-r--r-- | emulator.c | 14 | ||||
-rw-r--r-- | emulator.h | 1 |
2 files changed, 10 insertions, 5 deletions
diff --git a/emulator.c b/emulator.c index b843c3f..f976af3 100644 --- a/emulator.c +++ b/emulator.c @@ -71,7 +71,7 @@ int emulator_tick(Emulator* emulator) uint16_t instr_pc = *pc; - *pc += 2; + emulator_step(emulator); uint8_t first_nibble = (instr >> 12) & 0xf; uint8_t X = (instr & 0x0F00) >> 8; //second_nibble @@ -121,7 +121,7 @@ int emulator_tick(Emulator* emulator) if(emulator->regs.V[X] == NN) { dbgprintf("SKIPPED COZ THEY WERE EQUAL!\n"); - *pc += 2; + emulator_step(emulator); } break; case 0x4: @@ -133,7 +133,7 @@ int emulator_tick(Emulator* emulator) if(emulator->regs.V[X] == emulator->regs.V[Y]) { dbgprintf("SKIPPED COZ THEY WERE EQUAL!\n"); - *pc += 2; + emulator_step(emulator); } break; case 0x6: @@ -199,7 +199,7 @@ int emulator_tick(Emulator* emulator) if(emulator->regs.V[X] != emulator->regs.V[Y]) { dbgprintf("SKIPPED COZ THEY WERE NOT EQUAL!\n"); - *pc += 2; + emulator_step(emulator); } break; case 0xA: @@ -279,10 +279,14 @@ int emulator_tick(Emulator* emulator) return 0; } +void emulator_step(Emulator* emulator) +{ + emulator->pc += 2; +} + void* emulator_timers_thread(Emulator* emulator) { printf("STARTED TIMERS THREAD\n"); - while(emulator->is_on) { if(emulator->delay_timer > 0) diff --git a/emulator.h b/emulator.h index 7fac868..489ad71 100644 --- a/emulator.h +++ b/emulator.h @@ -59,6 +59,7 @@ typedef struct int emulator_initialise(Emulator* emulator); int emulator_load_rom(Emulator* emulator, char* rom_name); int emulator_tick(Emulator* emulator); +void emulator_step(Emulator* emulator); void emulator_dump_registers(Emulator* emulator); void* emulator_timers_thread(); |