From 13603f61f8c794d5cf0d120cd2e41355838de8e9 Mon Sep 17 00:00:00 2001 From: 0xmac Date: Tue, 7 Jan 2025 14:35:49 +0100 Subject: [PATCH] Updated events.c for SDL --- src/events.c | 84 ++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 46 deletions(-) diff --git a/src/events.c b/src/events.c index 382a3a8..2c130df 100644 --- a/src/events.c +++ b/src/events.c @@ -1,10 +1,8 @@ #include -#include -#include -#include +#include +extern int clockSteps; extern float displayScale; -extern int clocksteps; extern uint8_t halt; extern uint8_t showDebug; extern uint8_t showHelp; @@ -16,81 +14,75 @@ extern void step6502(); extern void updateRenderStates(); extern void scanKeyboard(); -static sfKeyCode currentKey = sfKeyUnknown; +static SDL_Scancode currentKey = SDL_SCANCODE_UNKNOWN; +static SDL_Event event; -void pollEvents(sfRenderWindow *window){ - - sfEvent event; - while (sfRenderWindow_pollEvent(window, &event)) { - switch (event.type){ - case sfEvtClosed: - sfRenderWindow_close(window); - break; +void pollEvents(){ + while (SDL_PollEvent(&event)){ + switch(event.type){ + case SDL_QUIT: + printf("Exited.\n"); + exit(0); - case sfEvtResized: - sfRenderWindow_setView(window, sfView_createFromRect((sfFloatRect){0, 0, event.size.width, event.size.height})); - break; - case sfEvtKeyPressed: - switch (event.key.code){ - case sfKeyF1: /* Close Window or show help*/ - sfRenderWindow_close(window); + case SDL_KEYDOWN: + switch (event.key.keysym.scancode){ + case SDL_SCANCODE_F1: /* Close Window or show help*/ + exit(EXIT_SUCCESS); break; - case sfKeyF2: /* Show Key Help */ + case SDL_SCANCODE_F2: /* Show Key Help */ showHelp = !showHelp; break; - case sfKeyF3: /* Show Debug Menu */ + case SDL_SCANCODE_F3: /* Show Debug Menu */ showDebug = !showDebug; break; - case sfKeyF4: /* CPU Halt */ + case SDL_SCANCODE_F4: /* CPU Halt */ halt = !halt; break; - case sfKeyF5: /* CPU Reset */ + case SDL_SCANCODE_F5: /* CPU Reset */ resetSystem(); break; - case sfKeyF6: /* Scale -- */ - if (displayscale > 1) displayscale--; - updateRenderStates(); + case SDL_SCANCODE_F6: /* Scale -- */ + if (displayScale > 1) displayScale--; + break; + + case SDL_SCANCODE_F7: /* Scale ++ */ + displayScale++; + break; + + case SDL_SCANCODE_F8: /* CPU Singlestep */ + for (int i = 0; i < clockSteps; i++) step6502(); break; - case sfKeyF7: /* Scale ++ */ - displayscale++; - updateRenderStates(); + case SDL_SCANCODE_F9: /* CPU Save Snapshot */ break; - case sfKeyF8: /* CPU Singlestep */ - for (int i = 0; i < clocksteps; i++) step6502(); - break; - - case sfKeyF9: /* CPU Save Snapshot */ + case SDL_SCANCODE_F10: /* CPU Load recent or given snapshot */ break; - case sfKeyF10: /* CPU Load recent or given snapshot */ - break; - - case sfKeyF11: /* CPU NMI */ + case SDL_SCANCODE_F11: /* CPU NMI */ nmi6502(); break; - case sfKeyF12: /* CPU IRQ */ + case SDL_SCANCODE_F12: /* CPU IRQ */ irq6502(); break; - + default: - currentKey = event.key.code; + currentKey = event.key.keysym.scancode; break; } break; - case sfEvtKeyReleased: + case SDL_KEYUP: // To tell keyboard.c, that no key is being pressed - currentKey = sfKeyUnknown; + currentKey = SDL_SCANCODE_UNKNOWN; + break; + default: break; - - default: break; } } }