about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-23 01:03:52 +0100
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-23 01:03:52 +0100
commitb4dd9ded2775682ce3d5c26243613c5858a96791 (patch)
tree3ea74602554e506b6c49083743cf600418a00af8
parentFeature: Implemented various instructions (diff)
downloadCHIP8-Emulator-b4dd9ded2775682ce3d5c26243613c5858a96791.tar.gz
CHIP8-Emulator-b4dd9ded2775682ce3d5c26243613c5858a96791.tar.bz2
CHIP8-Emulator-b4dd9ded2775682ce3d5c26243613c5858a96791.zip
Feature: Implemented reload and exit key behaviour
-rw-r--r--main.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/main.c b/main.c
index e0529b7..e528a69 100644
--- a/main.c
+++ b/main.c
@@ -22,6 +22,7 @@ int main(int argc, char** argv)
 
     emulator_initialise(&emulator);
 
+    load:
     if(emulator_load_rom(&emulator, argv[1]) != 0)
         return 2;
 
@@ -38,7 +39,18 @@ int main(int argc, char** argv)
             if(event.type == SDL_WINDOWEVENT)
                 SDL_RenderPresent(renderer);
             if(event.type == SDL_KEYDOWN)
-                emulator_handle_key_press(&emulator, event.key.keysym.sym);
+            {
+                switch(event.key.keysym.sym)
+                {
+                    case SDLK_ESCAPE:
+                        goto exit;
+                    case SDLK_F5:
+                        goto load;
+                    default:
+                        emulator_handle_key_press(&emulator, event.key.keysym.sym);
+                }
+
+            }
             if(event.type == SDL_KEYUP)
                 emulator_handle_key_release(&emulator, event.key.keysym.sym);
         }
@@ -53,7 +65,7 @@ int main(int argc, char** argv)
                 for(int h = 0; h < 32; ++h)
                 {
                     uint8_t pixel = emulator.display[w][h];
-                    pixels[64 * h + w] = (0x00FFFFFF * pixel) | 0xFF000000;
+                    pixels[64 * h + w] = (0x00FFFFFF * pixel) | 0xFF000000; //TODO: make colors customizable in config.h
                 }
             }