Updated events.c for SDL
This commit is contained in:
parent
c777421c79
commit
13603f61f8
74
src/events.c
74
src/events.c
@ -1,10 +1,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <SFML/System.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SFML/Graphics.h>
|
|
||||||
#include <SFML/Window.h>
|
|
||||||
|
|
||||||
|
extern int clockSteps;
|
||||||
extern float displayScale;
|
extern float displayScale;
|
||||||
extern int clocksteps;
|
|
||||||
extern uint8_t halt;
|
extern uint8_t halt;
|
||||||
extern uint8_t showDebug;
|
extern uint8_t showDebug;
|
||||||
extern uint8_t showHelp;
|
extern uint8_t showHelp;
|
||||||
@ -16,81 +14,75 @@ extern void step6502();
|
|||||||
extern void updateRenderStates();
|
extern void updateRenderStates();
|
||||||
extern void scanKeyboard();
|
extern void scanKeyboard();
|
||||||
|
|
||||||
static sfKeyCode currentKey = sfKeyUnknown;
|
static SDL_Scancode currentKey = SDL_SCANCODE_UNKNOWN;
|
||||||
|
static SDL_Event event;
|
||||||
|
|
||||||
void pollEvents(sfRenderWindow *window){
|
void pollEvents(){
|
||||||
|
while (SDL_PollEvent(&event)){
|
||||||
sfEvent event;
|
|
||||||
while (sfRenderWindow_pollEvent(window, &event)) {
|
|
||||||
switch(event.type){
|
switch(event.type){
|
||||||
case sfEvtClosed:
|
case SDL_QUIT:
|
||||||
sfRenderWindow_close(window);
|
printf("Exited.\n");
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
switch (event.key.keysym.scancode){
|
||||||
|
case SDL_SCANCODE_F1: /* Close Window or show help*/
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfEvtResized:
|
case SDL_SCANCODE_F2: /* Show Key Help */
|
||||||
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);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case sfKeyF2: /* Show Key Help */
|
|
||||||
showHelp = !showHelp;
|
showHelp = !showHelp;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF3: /* Show Debug Menu */
|
case SDL_SCANCODE_F3: /* Show Debug Menu */
|
||||||
showDebug = !showDebug;
|
showDebug = !showDebug;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF4: /* CPU Halt */
|
case SDL_SCANCODE_F4: /* CPU Halt */
|
||||||
halt = !halt;
|
halt = !halt;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF5: /* CPU Reset */
|
case SDL_SCANCODE_F5: /* CPU Reset */
|
||||||
resetSystem();
|
resetSystem();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF6: /* Scale -- */
|
case SDL_SCANCODE_F6: /* Scale -- */
|
||||||
if (displayscale > 1) displayscale--;
|
if (displayScale > 1) displayScale--;
|
||||||
updateRenderStates();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF7: /* Scale ++ */
|
case SDL_SCANCODE_F7: /* Scale ++ */
|
||||||
displayscale++;
|
displayScale++;
|
||||||
updateRenderStates();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF8: /* CPU Singlestep */
|
case SDL_SCANCODE_F8: /* CPU Singlestep */
|
||||||
for (int i = 0; i < clocksteps; i++) step6502();
|
for (int i = 0; i < clockSteps; i++) step6502();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF9: /* CPU Save Snapshot */
|
case SDL_SCANCODE_F9: /* CPU Save Snapshot */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF10: /* CPU Load recent or given snapshot */
|
case SDL_SCANCODE_F10: /* CPU Load recent or given snapshot */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF11: /* CPU NMI */
|
case SDL_SCANCODE_F11: /* CPU NMI */
|
||||||
nmi6502();
|
nmi6502();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sfKeyF12: /* CPU IRQ */
|
case SDL_SCANCODE_F12: /* CPU IRQ */
|
||||||
irq6502();
|
irq6502();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
currentKey = event.key.code;
|
currentKey = event.key.keysym.scancode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case sfEvtKeyReleased:
|
case SDL_KEYUP:
|
||||||
// To tell keyboard.c, that no key is being pressed
|
// To tell keyboard.c, that no key is being pressed
|
||||||
currentKey = sfKeyUnknown;
|
currentKey = SDL_SCANCODE_UNKNOWN;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user