diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-23 14:32:43 +0100 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-23 14:32:43 +0100 |
commit | 6be26e82cf54b9b3ce8fd70af25cb969c1079525 (patch) | |
tree | f57abca83bad24f39bd7f7b4b3b348b8ff57269e | |
parent | Feature: Implemented background and foreround color customizability (diff) | |
download | CHIP8-Emulator-6be26e82cf54b9b3ce8fd70af25cb969c1079525.tar.gz CHIP8-Emulator-6be26e82cf54b9b3ce8fd70af25cb969c1079525.tar.bz2 CHIP8-Emulator-6be26e82cf54b9b3ce8fd70af25cb969c1079525.zip |
Feature: Implemented various instructions
-rw-r--r-- | config.h | 8 | ||||
-rw-r--r-- | emulator.c | 45 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | roms/life.ch8 | bin | 0 -> 256 bytes |
4 files changed, 42 insertions, 14 deletions
diff --git a/config.h b/config.h index 1656026..b318965 100644 --- a/config.h +++ b/config.h @@ -6,13 +6,13 @@ #define SCREEN_WIDTH 852 #define SCREEN_HEIGHT 480 -#define INSTRUCTIONS_PER_SECOND 700 -#define TIMERS_THREAD_FREQUENCY 60 +#define INSTRUCTIONS_PER_SECOND 700 //Default: 700 +#define TIMERS_THREAD_FREQUENCY 60 //Default: 60 #define GAME_LOAD_LOCATION 0x200 #define FONT_LOAD_LOCATION 0x50 -#define FOREGROUND_COLOR 0x00FFFFFF -#define BLACKGROUND_COLOR 0xFF000000 +#define FOREGROUND_COLOR 0x00F00FFF //Default: 0x00FFFFFF +#define BLACKGROUND_COLOR 0xFF000000 //Default: 0xFF000000 #define dbgprintf(fmt, ...) \ do { if(DEBUG) fprintf (stdout, fmt, ##__VA_ARGS__); } while(0) diff --git a/emulator.c b/emulator.c index 7f6bdd6..5c83226 100644 --- a/emulator.c +++ b/emulator.c @@ -28,7 +28,9 @@ int emulator_initialise(Emulator* emulator) memset(emulator, 0, sizeof(Emulator)); memcpy(emulator->memory + FONT_LOAD_LOCATION, font, sizeof(font)); + emulator->is_on = 1; + emulator->keys[0].value = 'x'; //O emulator->keys[1].value = '1'; //1 emulator->keys[2].value = '2'; //2 @@ -46,7 +48,6 @@ int emulator_initialise(Emulator* emulator) emulator->keys[14].value = 'f'; //E emulator->keys[15].value = 'v'; //F - pthread_t emulator_timers_thread_id; pthread_create(&emulator_timers_thread_id, NULL, &emulator_timers_thread, emulator); @@ -87,7 +88,7 @@ int emulator_handle_key_press(Emulator* emulator, uint8_t key) { if(emulator->keys[i].value == key) { - printf("KEY ACTIVATED: %c-%d!\n", key, key); + dbgprintf("KEY ACTIVATED: %c-%d!\n", key, key); emulator->keys[i].activated = 1; break; } @@ -102,7 +103,7 @@ int emulator_handle_key_release(Emulator* emulator, uint8_t key) { if(emulator->keys[i].value == key) { - printf("KEY RELEASE: %c-%d!\n", key, key); + dbgprintf("KEY RELEASE: %c-%d!\n", key, key); emulator->keys[i].activated = 0; break; } @@ -292,8 +293,18 @@ int emulator_tick(Emulator* emulator) emulator->draw_flag = 1; break; case 0xE: - printf("TODO: Instr: 0x%x\n", instr); - assert(0); + switch(NN) + { + case 0xA1: + //skip if key not pressed + if(emulator->keys[emulator->regs.V[X]].activated == 0) + *pc += 2; + break; + default: + printf("DEFAULT: Instr: 0x%x\n", instr); + assert(0); + } + break; case 0xF: switch(NN) @@ -324,6 +335,21 @@ int emulator_tick(Emulator* emulator) dbgprintf("SET V[X] TO THE DELAY TIMER!\n"); emulator->regs.V[X] = emulator->delay_timer; break; + case 0x18: //FX18 + dbgprintf("SET THE SOUND TIMER TO V[X]!\n"); + emulator->sound_timer = emulator->regs.V[X]; + break; + case 0x33: //FX33 + { + uint8_t number = emulator->regs.V[X]; + for(uint8_t offset = 2; number > 0; --offset) + { + emulator->memory[emulator->regs.I + offset] = number % 10; //last digit + number /= 10; + } + + break; + } case 0x0A: { uint8_t key_pressed = 0; @@ -375,15 +401,16 @@ void* emulator_timers_thread(Emulator* emulator) while(emulator->is_on) { if(emulator->delay_timer > 0) + { + printf("lower timer!\n"); --emulator->delay_timer; + } if(emulator->sound_timer > 0) - { - printf("lower timer!\n"); --emulator->sound_timer; - } - usleep(1000000 / TIMERS_THREAD_FREQUENCY); + if(!DEBUG) + usleep(1000000 / TIMERS_THREAD_FREQUENCY); } return NULL; diff --git a/main.c b/main.c index 449efda..6bde0e1 100644 --- a/main.c +++ b/main.c @@ -76,7 +76,8 @@ int main(int argc, char** argv) emulator.draw_flag = 0; } - //usleep(1000000 / INSTRUCTIONS_PER_SECOND); + if(!DEBUG) + usleep(1000000 / INSTRUCTIONS_PER_SECOND); } exit: diff --git a/roms/life.ch8 b/roms/life.ch8 new file mode 100644 index 0000000..d35039a --- /dev/null +++ b/roms/life.ch8 Binary files differ |