Minor changes

Handle numpad the same way numerical keys were handled
Reduce audio buffer
Change some debugging output strings
This commit is contained in:
Franck STAUFFER 2020-08-04 08:53:08 +02:00
parent 1ecb8a7a8a
commit 3b0b343337
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261

View File

@ -106,7 +106,8 @@ init_SDL(const char* path)
SDL_WINDOWPOS_UNDEFINED,
64 * SCALE,
32 * SCALE,
SDL_WINDOW_SHOWN);
SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
if (!w) {
fputs("ERROR: Failed to create a window\n", stderr);
return 0;
@ -114,11 +115,11 @@ init_SDL(const char* path)
s = SDL_GetWindowSurface(w);
if (!s) {
fputs("ERROR: Failed to create SDL surface\n", stderr);
fputs("ERROR: Failed to get window's surface\n", stderr);
return 0;
}
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 2048)) {
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 1024)) {
fputs("ERROR: Failed to open audio\n", stderr);
return 0;
}
@ -134,8 +135,7 @@ init_SDL(const char* path)
if (atexit(cleanup)) {
fputs("ERROR: Failed to set exit function\n", stderr);
SDL_FreeSurface(s);
SDL_Quit();
cleanup();
return 0;
}
@ -197,7 +197,8 @@ load_rom(const char* path)
return 0;
}
fprintf(stderr, "INFO: %ldB loaded from %s/%s\n", size, getenv("PWD"), path);
fprintf(
stderr, "INFO: %ldB loaded from %s/%s\n", size, getenv("PWD"), path);
fputs("Loaded ROM:\n", stderr);
uint_fast8_t c = 0;
@ -219,33 +220,43 @@ event_handler(void)
{
if (e.type == SDL_KEYDOWN) {
switch (e.key.keysym.sym) {
case SDLK_KP_0:
case SDLK_0:
key[0x0] = 1;
break;
case SDLK_KP_1:
case SDLK_1:
key[0x1] = 1;
break;
case SDLK_KP_2:
case SDLK_2:
key[0x2] = 1;
break;
case SDLK_KP_3:
case SDLK_3:
key[0x3] = 1;
break;
case SDLK_KP_4:
case SDLK_4:
key[0x4] = 1;
break;
case SDLK_KP_5:
case SDLK_5:
key[0x5] = 1;
break;
case SDLK_KP_6:
case SDLK_6:
key[0x6] = 1;
break;
case SDLK_KP_7:
case SDLK_7:
key[0x7] = 1;
break;
case SDLK_KP_8:
case SDLK_8:
key[0x8] = 1;
break;
case SDLK_KP_9:
case SDLK_9:
key[0x9] = 1;
break;
@ -270,37 +281,47 @@ event_handler(void)
case SDLK_ESCAPE:
exit(0);
default:
fputs("WARNING: Unhandled input detected\n", stderr);
fprintf(stderr, "WARNING: Unhandled input detected: %s\n", SDL_GetKeyName(e.key.keysym.sym));
}
} else if (e.type == SDL_KEYUP) {
switch (e.key.keysym.sym) {
case SDLK_KP_0:
case SDLK_0:
key[0x0] = 0;
break;
case SDLK_KP_1:
case SDLK_1:
key[0x1] = 0;
break;
case SDLK_KP_2:
case SDLK_2:
key[0x2] = 0;
break;
case SDLK_KP_3:
case SDLK_3:
key[0x3] = 0;
break;
case SDLK_KP_4:
case SDLK_4:
key[0x4] = 0;
break;
case SDLK_KP_5:
case SDLK_5:
key[0x5] = 0;
break;
case SDLK_KP_6:
case SDLK_6:
key[0x6] = 0;
break;
case SDLK_KP_7:
case SDLK_7:
key[0x7] = 0;
break;
case SDLK_KP_8:
case SDLK_8:
key[0x8] = 0;
break;
case SDLK_KP_9:
case SDLK_9:
key[0x9] = 0;
break;