Skip to content

Commit

Permalink
Quit hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
YonKuma committed Dec 12, 2021
1 parent c691e3f commit 0785214
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions include/piemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ typedef struct tagPIEMU_CONTEXT
SDL_GameController *controller;
SDL_AudioDeviceID audio_device;

// Hotkeys
int holdingQuit;
int awaitingQuitConfirm;
int quitTimer;

int bEndFlag;

Expand Down
38 changes: 30 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,50 @@ int main(int argc, char *argv[])

if (context.controller != NULL && SDL_GameControllerGetAttached(context.controller)) {
int Up = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_DPAD_UP);
context.keystate[KEY_UP] = Up | context.keystate[KEY_UP];
context.keystate[KEY_UP] = Up;

int Down = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
context.keystate[KEY_DOWN] = Down | context.keystate[KEY_DOWN];
context.keystate[KEY_DOWN] = Down;

int Left = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
context.keystate[KEY_LEFT] = Left | context.keystate[KEY_LEFT];
context.keystate[KEY_LEFT] = Left;

int Right = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
context.keystate[KEY_RIGHT] = Right | context.keystate[KEY_RIGHT];
context.keystate[KEY_RIGHT] = Right;

int Start = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_START);
context.keystate[KEY_START] = Start | context.keystate[KEY_START];
context.keystate[KEY_START] = Start;

int Back = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_BACK);
context.keystate[KEY_SELECT] = Back | context.keystate[KEY_SELECT];
context.keystate[KEY_SELECT] = Back;

int AButton = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_A);
context.keystate[KEY_A] = AButton | context.keystate[KEY_A];
context.keystate[KEY_A] = AButton;

int BButton = SDL_GameControllerGetButton(context.controller, SDL_CONTROLLER_BUTTON_B);
context.keystate[KEY_B] = BButton | context.keystate[KEY_B];
context.keystate[KEY_B] = BButton;
}

if (context.keystate[KEY_SELECT] && context.keystate[KEY_START]) {
if (context.awaitingQuitConfirm) {
goto L_EXIT;
} else {
context.holdingQuit = 1;
}
}

if (context.holdingQuit && ((!context.keystate[KEY_SELECT]) || (!context.keystate[KEY_START]))) {
context.holdingQuit = 0;
context.awaitingQuitConfirm = 1;
context.quitTimer = 60;
}

if (context.quitTimer > 0) {
context.quitTimer--;
}

if (context.quitTimer == 0) {
context.awaitingQuitConfirm = 0;
}

/* 画面更新。 */
Expand Down

0 comments on commit 0785214

Please sign in to comment.