about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 14:43:22 +0100
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 14:43:22 +0100
commitf24b01fa9967873e575a56541c9dc7fd4a32eb45 (patch)
treed89fd6e584d98de09bded3cc119cc214ed746349
parentFeature: Added registers (diff)
downloadCHIP8-Emulator-f24b01fa9967873e575a56541c9dc7fd4a32eb45.tar.gz
CHIP8-Emulator-f24b01fa9967873e575a56541c9dc7fd4a32eb45.tar.bz2
CHIP8-Emulator-f24b01fa9967873e575a56541c9dc7fd4a32eb45.zip
Misc: Load roms after 0x200
-rw-r--r--chip8_emulator.corebin0 -> 314704 bytes
-rw-r--r--emulator.c3
-rw-r--r--emulator.h6
-rw-r--r--main.c4
4 files changed, 9 insertions, 4 deletions
diff --git a/chip8_emulator.core b/chip8_emulator.core
new file mode 100644
index 0000000..4e75aa7
--- /dev/null
+++ b/chip8_emulator.core
Binary files differdiff --git a/emulator.c b/emulator.c
index afc78b1..699999c 100644
--- a/emulator.c
+++ b/emulator.c
@@ -13,7 +13,8 @@ int emulator_load_rom(Emulator* emulator, char* rom_name)
     struct stat st;
     fstat(fileno(rom), &st);
 
-    int bytes_read = fread(emulator->memory, 1, st.st_size, rom);
+     //rom loaded after 0x200 into memory
+    int bytes_read = fread(emulator->memory + 0x200, 1, st.st_size, rom);
     if(bytes_read != st.st_size)
     {
         perror("doesnt cuadrar\n");
diff --git a/emulator.h b/emulator.h
index c8114cb..b685bea 100644
--- a/emulator.h
+++ b/emulator.h
@@ -23,13 +23,17 @@ typedef struct
     uint8_t VD;
     uint8_t VE;
     uint8_t VF; //flag register
+
+    uint16_t I; // index register
 } Registers;
 
 typedef struct
 {
     uint8_t is_on;
-    uint16_t pc;
+    uint16_t pc; //program counter
     Registers regs;
+    uint8_t sp; //stack pointer
+    uint16_t stack[16];
     uint8_t memory[4096];
 } Emulator;
 
diff --git a/main.c b/main.c
index 53dd85c..48d35ee 100644
--- a/main.c
+++ b/main.c
@@ -21,12 +21,12 @@ int main(int argc, char** argv)
 
     printf("Hello brother!\n");
 
-    /*for(int i = 0; i < sizeof(emulator.memory); ++i)
+    for(int i = 0; i < sizeof(emulator.memory); ++i)
     {
         printf("%c ", emulator.memory[i]);
     }
 
-    putchar('\n');*/
+    putchar('\n');
 
     while(emulator.is_on)
     {