diff --git a/src/events.c b/src/events.c new file mode 100644 index 0000000..d8c329f --- /dev/null +++ b/src/events.c @@ -0,0 +1,66 @@ +#include + +#include +#include +#include +#include + +extern float displayScale; + +extern void resetSystem(); +extern void irq6502(); +extern void nmi6502(); +extern void updateRenderStates(); +extern void scanKeyboard(); + +static sfKeyCode currentKey = sfKeyUnknown; + +void pollEvents(sfRenderWindow *window){ + + sfEvent event; + while (sfRenderWindow_pollEvent(window, &event)) { + switch (event.type){ + case sfEvtClosed: + sfRenderWindow_close(window); + break; + + case sfEvtResized: + sfRenderWindow_setView(window, sfView_createFromRect((sfFloatRect){0, 0, event.size.width, event.size.height})); + break; + case sfEvtKeyPressed: + switch (event.key.code){ + case sfKeyEscape: + sfRenderWindow_close(window); + break; + + case sfKeyF2: + if (displayScale > 1) displayScale--; + updateRenderStates(); + break; + case sfKeyF3: + displayScale++; + updateRenderStates(); + break; + case sfKeyF5: + resetSystem(); + break; + case sfKeyF12: + irq6502(); + break; + case sfKeyF11: + nmi6502(); + break; + + default: + currentKey = event.key.code; + break; + } + break; + case sfEvtKeyReleased: + currentKey = sfKeyUnknown; + break; + + default: break; + } + } +}