about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 17:17:05 +0100
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 17:17:05 +0100
commit63dd156d873bb96eeaa19b78f9baccacf2f977fd (patch)
treea0dc1c223550e3b33fc2c90c6f555fce789bdfc7
parentFeature: Implemented instructions to run the logo rom (diff)
downloadCHIP8-Emulator-63dd156d873bb96eeaa19b78f9baccacf2f977fd.tar.gz
CHIP8-Emulator-63dd156d873bb96eeaa19b78f9baccacf2f977fd.tar.bz2
CHIP8-Emulator-63dd156d873bb96eeaa19b78f9baccacf2f977fd.zip
Misc: Added the dbgprintf() macro
-rw-r--r--Makefile4
-rw-r--r--config.h6
-rw-r--r--emulator.c19
-rw-r--r--main.c7
4 files changed, 18 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index d13a7ff..17f9717 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-CC=cc
-CFLAGS=-g -Wall -I.
+CC=egcc
+CFLAGS=-std=c99 -g -Wall -I.
 
 all: chip8_emulator
 
diff --git a/config.h b/config.h
index dc5778a..a0d6073 100644
--- a/config.h
+++ b/config.h
@@ -1,8 +1,14 @@
 #ifndef _CONFIG_H_
 #define _CONFIG_H_
 
+#define DEBUG 1
+
 #define INSTRUCTIONS_PER_SECOND 700
 #define GAME_LOAD_LOCATION 0x200
 #define FONT_LOAD_LOCATION 0x50
 
+
+#define dbgprintf(fmt, ...) \
+     do { if(DEBUG) fprintf (stdout, fmt, ##__VA_ARGS__); } while(0)
+
 #endif
diff --git a/emulator.c b/emulator.c
index 5962dc1..94cd3d8 100644
--- a/emulator.c
+++ b/emulator.c
@@ -72,8 +72,8 @@ int emulator_tick(Emulator* emulator)
     uint8_t NN = (instr & 0x00FF); //second_byte
     uint16_t NNN = (instr & 0x0FFF); //last three nibbles
 
-    printf("instr: 0x%x\n", instr);
-    printf("A: 0x%x\nX: 0x%x\nY: 0x%x\nN: 0x%x\nNN: 0x%x\nNNN: 0x%x\n", first_nibble, X, Y, N, NN, NNN);
+    dbgprintf("instr: 0x%x\n", instr);
+    dbgprintf("A: 0x%x\nX: 0x%x\nY: 0x%x\nN: 0x%x\nNN: 0x%x\nNNN: 0x%x\n", first_nibble, X, Y, N, NN, NNN);
 
     switch(first_nibble)
     {
@@ -81,15 +81,16 @@ int emulator_tick(Emulator* emulator)
             switch(NNN)
             {
                 case 0x000:
+                    emulator_dump_registers(emulator);
                     exit(1); //stop executing when program over
                 case 0x0E0: //00E0: Clear screen
-                    printf("CLEAR SCREEN!\n");
+                    dbgprintf("CLEAR SCREEN!\n");
                     break;
             }
 
             break;
         case 0x1:
-            printf("JUMP! (0x%x)\n", NNN);
+            dbgprintf("JUMP! (0x%x)\n", NNN);
             emulator->pc = NNN;
             break;
         case 0x2:
@@ -101,17 +102,17 @@ int emulator_tick(Emulator* emulator)
         case 0x5:
             break;
         case 0x6:
-            printf("SET REGISTER VX! (0x%x)\n", NN);
+            dbgprintf("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);
+            dbgprintf("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);
+            dbgprintf("SET INDEX REGISTER I! (0x%x)\n", NNN);
             emulator->regs.I = NNN;
             break;
         case 0xB:
@@ -119,7 +120,7 @@ int emulator_tick(Emulator* emulator)
         case 0xC:
             break;
         case 0xD:
-            printf("DRAW!\n");
+            dbgprintf("DRAW!\n");
             break;
         case 0xE:
             break;
@@ -127,7 +128,7 @@ int emulator_tick(Emulator* emulator)
             break;
     }
 
-    putchar('\n');
+    dbgprintf("\n");
 
     return 0;
 }
diff --git a/main.c b/main.c
index 94e4a95..b97ab9f 100644
--- a/main.c
+++ b/main.c
@@ -23,13 +23,6 @@ int main(int argc, char** argv)
 
     printf("Hello brother!\n");
 
-    /*for(int i = 0; i < sizeof(emulator.memory); ++i)
-    {
-        printf("0x%x ", emulator.memory[i]);
-    }
-
-    putchar('\n');*/
-
     while(emulator.is_on == 1)
     {
         emulator_tick(&emulator);