Added SFML event handler

This commit is contained in:
0xmac 2024-12-02 14:06:29 +01:00
parent b35d280f12
commit f129aae3a3

66
src/events.c Normal file
View File

@ -0,0 +1,66 @@
#include <stdint.h>
#include <SFML/Graphics/RenderWindow.h>
#include <SFML/System.h>
#include <SFML/Graphics.h>
#include <SFML/Window.h>
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;
}
}
}