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 <SFML/System.h>
|
||||
#include <SFML/Graphics.h>
|
||||
#include <SFML/Window.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
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)) {
|
||||
void pollEvents(){
|
||||
while (SDL_PollEvent(&event)){
|
||||
switch(event.type){
|
||||
case sfEvtClosed:
|
||||
sfRenderWindow_close(window);
|
||||
case SDL_QUIT:
|
||||
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;
|
||||
|
||||
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);
|
||||
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 sfKeyF7: /* Scale ++ */
|
||||
displayscale++;
|
||||
updateRenderStates();
|
||||
case SDL_SCANCODE_F7: /* Scale ++ */
|
||||
displayScale++;
|
||||
break;
|
||||
|
||||
case sfKeyF8: /* CPU Singlestep */
|
||||
for (int i = 0; i < clocksteps; i++) step6502();
|
||||
case SDL_SCANCODE_F8: /* CPU Singlestep */
|
||||
for (int i = 0; i < clockSteps; i++) step6502();
|
||||
break;
|
||||
|
||||
case sfKeyF9: /* CPU Save Snapshot */
|
||||
case SDL_SCANCODE_F9: /* CPU Save Snapshot */
|
||||
break;
|
||||
|
||||
case sfKeyF10: /* CPU Load recent or given snapshot */
|
||||
case SDL_SCANCODE_F10: /* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user