about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 18:40:19 +0100
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 18:40:19 +0100
commit8becc7265b8d8b9d5f716887de41910957175ccf (patch)
treea72c11866e6a334f46493edf67990481ec120617
parentFeature: Prepared SDL window for pixel drawing instruction (diff)
downloadCHIP8-Emulator-8becc7265b8d8b9d5f716887de41910957175ccf.tar.gz
CHIP8-Emulator-8becc7265b8d8b9d5f716887de41910957175ccf.tar.bz2
CHIP8-Emulator-8becc7265b8d8b9d5f716887de41910957175ccf.zip
Debug: Added draw debug prints
-rw-r--r--config.h2
-rw-r--r--emulator.c39
-rw-r--r--x0
3 files changed, 40 insertions, 1 deletions
diff --git a/config.h b/config.h
index a40e76f..cf73451 100644
--- a/config.h
+++ b/config.h
@@ -1,7 +1,7 @@
 #ifndef _CONFIG_H_
 #define _CONFIG_H_
 
-#define DEBUG 1
+#define DEBUG 0
 
 #define INSTRUCTIONS_PER_SECOND 700
 #define GAME_LOAD_LOCATION 0x200
diff --git a/emulator.c b/emulator.c
index 87b6e81..15c5e39 100644
--- a/emulator.c
+++ b/emulator.c
@@ -62,6 +62,20 @@ int emulator_load_rom(Emulator* emulator, char* rom_name)
     return 0;
 }
 
+static void show_screen(Emulator* em)
+{
+    printf("SCREEN: \n");
+    for(int x = 0; x < 64; ++x)
+    {
+        for(int y = 0; y < 32; ++y)
+        {
+            printf("%d ", em->display[x][y]);
+        }
+        printf("\n");
+    }
+    printf("\n");
+}
+
 int emulator_tick(Emulator* emulator)
 {
     uint16_t* pc = &emulator->pc;
@@ -124,6 +138,31 @@ int emulator_tick(Emulator* emulator)
             break;
         case 0xD:
             dbgprintf("DRAW!\n");
+            //show_screen(emulator);
+            int x = emulator->regs.V[X] % 64;
+            int y = emulator->regs.V[Y] % 32;
+            printf("DRAWING 0x%x AT (%d, %d)\n", emulator->regs.I, x, y);
+
+
+            emulator->regs.VF = 0;
+
+            for(int row = 0; row < N; ++row)
+            {
+                uint8_t pixel = emulator->memory[emulator->regs.I + row];
+                for(int xline = 0; xline < 8; xline++)
+                                {
+                                    if((pixel & (0x80 >> xline)) != 0)
+                                    {
+                                        if(emulator->display[x][y] == 1)
+                                        {
+                                            emulator->regs.V[0xF] = 1;
+                                        }
+                                        emulator->display[x][y] ^= 1;
+                                    }
+                                }
+            }
+            //show_screen(emulator);
+
             emulator->draw_flag = 1;
             break;
         case 0xE:
diff --git a/x b/x
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/x