Minor changes
Handle numpad the same way numerical keys were handled Reduce audio buffer Change some debugging output strings
This commit is contained in:
parent
1ecb8a7a8a
commit
3b0b343337
35
src/main.c
35
src/main.c
@ -106,7 +106,8 @@ init_SDL(const char* path)
|
|||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED,
|
||||||
64 * SCALE,
|
64 * SCALE,
|
||||||
32 * SCALE,
|
32 * SCALE,
|
||||||
SDL_WINDOW_SHOWN);
|
SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
|
|
||||||
if (!w) {
|
if (!w) {
|
||||||
fputs("ERROR: Failed to create a window\n", stderr);
|
fputs("ERROR: Failed to create a window\n", stderr);
|
||||||
return 0;
|
return 0;
|
||||||
@ -114,11 +115,11 @@ init_SDL(const char* path)
|
|||||||
|
|
||||||
s = SDL_GetWindowSurface(w);
|
s = SDL_GetWindowSurface(w);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
fputs("ERROR: Failed to create SDL surface\n", stderr);
|
fputs("ERROR: Failed to get window's surface\n", stderr);
|
||||||
return 0;
|
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);
|
fputs("ERROR: Failed to open audio\n", stderr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -134,8 +135,7 @@ init_SDL(const char* path)
|
|||||||
|
|
||||||
if (atexit(cleanup)) {
|
if (atexit(cleanup)) {
|
||||||
fputs("ERROR: Failed to set exit function\n", stderr);
|
fputs("ERROR: Failed to set exit function\n", stderr);
|
||||||
SDL_FreeSurface(s);
|
cleanup();
|
||||||
SDL_Quit();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +197,8 @@ load_rom(const char* path)
|
|||||||
return 0;
|
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);
|
fputs("Loaded ROM:\n", stderr);
|
||||||
uint_fast8_t c = 0;
|
uint_fast8_t c = 0;
|
||||||
@ -219,33 +220,43 @@ event_handler(void)
|
|||||||
{
|
{
|
||||||
if (e.type == SDL_KEYDOWN) {
|
if (e.type == SDL_KEYDOWN) {
|
||||||
switch (e.key.keysym.sym) {
|
switch (e.key.keysym.sym) {
|
||||||
|
case SDLK_KP_0:
|
||||||
case SDLK_0:
|
case SDLK_0:
|
||||||
key[0x0] = 1;
|
key[0x0] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_1:
|
||||||
case SDLK_1:
|
case SDLK_1:
|
||||||
key[0x1] = 1;
|
key[0x1] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_2:
|
||||||
case SDLK_2:
|
case SDLK_2:
|
||||||
key[0x2] = 1;
|
key[0x2] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_3:
|
||||||
case SDLK_3:
|
case SDLK_3:
|
||||||
key[0x3] = 1;
|
key[0x3] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_4:
|
||||||
case SDLK_4:
|
case SDLK_4:
|
||||||
key[0x4] = 1;
|
key[0x4] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_5:
|
||||||
case SDLK_5:
|
case SDLK_5:
|
||||||
key[0x5] = 1;
|
key[0x5] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_6:
|
||||||
case SDLK_6:
|
case SDLK_6:
|
||||||
key[0x6] = 1;
|
key[0x6] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_7:
|
||||||
case SDLK_7:
|
case SDLK_7:
|
||||||
key[0x7] = 1;
|
key[0x7] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_8:
|
||||||
case SDLK_8:
|
case SDLK_8:
|
||||||
key[0x8] = 1;
|
key[0x8] = 1;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_9:
|
||||||
case SDLK_9:
|
case SDLK_9:
|
||||||
key[0x9] = 1;
|
key[0x9] = 1;
|
||||||
break;
|
break;
|
||||||
@ -270,37 +281,47 @@ event_handler(void)
|
|||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
exit(0);
|
exit(0);
|
||||||
default:
|
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) {
|
} else if (e.type == SDL_KEYUP) {
|
||||||
switch (e.key.keysym.sym) {
|
switch (e.key.keysym.sym) {
|
||||||
|
case SDLK_KP_0:
|
||||||
case SDLK_0:
|
case SDLK_0:
|
||||||
key[0x0] = 0;
|
key[0x0] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_1:
|
||||||
case SDLK_1:
|
case SDLK_1:
|
||||||
key[0x1] = 0;
|
key[0x1] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_2:
|
||||||
case SDLK_2:
|
case SDLK_2:
|
||||||
key[0x2] = 0;
|
key[0x2] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_3:
|
||||||
case SDLK_3:
|
case SDLK_3:
|
||||||
key[0x3] = 0;
|
key[0x3] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_4:
|
||||||
case SDLK_4:
|
case SDLK_4:
|
||||||
key[0x4] = 0;
|
key[0x4] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_5:
|
||||||
case SDLK_5:
|
case SDLK_5:
|
||||||
key[0x5] = 0;
|
key[0x5] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_6:
|
||||||
case SDLK_6:
|
case SDLK_6:
|
||||||
key[0x6] = 0;
|
key[0x6] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_7:
|
||||||
case SDLK_7:
|
case SDLK_7:
|
||||||
key[0x7] = 0;
|
key[0x7] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_8:
|
||||||
case SDLK_8:
|
case SDLK_8:
|
||||||
key[0x8] = 0;
|
key[0x8] = 0;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_KP_9:
|
||||||
case SDLK_9:
|
case SDLK_9:
|
||||||
key[0x9] = 0;
|
key[0x9] = 0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user