diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 16:58:51 +0100 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 16:58:51 +0100 |
commit | 90f1c5689c4fc5f4ad75d544496c16ce54d01533 (patch) | |
tree | 460bb2e568b7b6f9f0015fc4657653ab0cacefd5 | |
parent | Feature: Added placeholder for basic instructions needed to run the logo rom (diff) | |
download | CHIP8-Emulator-90f1c5689c4fc5f4ad75d544496c16ce54d01533.tar.gz CHIP8-Emulator-90f1c5689c4fc5f4ad75d544496c16ce54d01533.tar.bz2 CHIP8-Emulator-90f1c5689c4fc5f4ad75d544496c16ce54d01533.zip |
Feature: Implemented instructions to run the logo rom
-rw-r--r-- | emulator.c | 6 | ||||
-rw-r--r-- | emulator.h | 46 |
2 files changed, 33 insertions, 19 deletions
diff --git a/emulator.c b/emulator.c index 6bfdaa0..5962dc1 100644 --- a/emulator.c +++ b/emulator.c @@ -81,7 +81,7 @@ int emulator_tick(Emulator* emulator) switch(NNN) { case 0x000: - exit(1); + exit(1); //stop executing when program over case 0x0E0: //00E0: Clear screen printf("CLEAR SCREEN!\n"); break; @@ -90,6 +90,7 @@ int emulator_tick(Emulator* emulator) break; case 0x1: printf("JUMP! (0x%x)\n", NNN); + emulator->pc = NNN; break; case 0x2: break; @@ -101,14 +102,17 @@ int emulator_tick(Emulator* emulator) break; case 0x6: printf("SET REGISTER VX! (0x%x)\n", NN); + emulator->regs.V[X] = NN; break; case 0x7: printf("ADD VALUE TO REGISTER VX! (0x%x)\n", NN); + emulator->regs.V[X] += NN; break; case 0x8: break; case 0xA: printf("SET INDEX REGISTER I! (0x%x)\n", NNN); + emulator->regs.I = NNN; break; case 0xB: break; diff --git a/emulator.h b/emulator.h index 78ae516..05cd3ef 100644 --- a/emulator.h +++ b/emulator.h @@ -1,32 +1,42 @@ #ifndef _EMULATOR_H_ #define _EMULATOR_H_ -#include <stdio.h> #include <config.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/stat.h> #include <string.h> typedef struct { // general purpose registers - uint8_t V0; - uint8_t V1; - uint8_t V2; - uint8_t V3; - uint8_t V4; - uint8_t V5; - uint8_t V6; - uint8_t V7; - uint8_t V8; - uint8_t V9; - uint8_t VA; - uint8_t VB; - uint8_t VC; - uint8_t VD; - uint8_t VE; - uint8_t VF; //flag register + union + { + uint8_t V[16]; //VF is the flag register + + struct + { + uint8_t V0; + uint8_t V1; + uint8_t V2; + uint8_t V3; + uint8_t V4; + uint8_t V5; + uint8_t V6; + uint8_t V7; + uint8_t V8; + uint8_t V9; + uint8_t VA; + uint8_t VB; + uint8_t VC; + uint8_t VD; + uint8_t VE; + uint8_t VF; //flag register + }; + }; - uint16_t I; // index register + // index register + uint16_t I; } Registers; typedef struct |