From c00bb458f40dd8ab015a1b738c1c71e7f4893ed2 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 17 Feb 2024 09:56:03 +0100 Subject: Support runtime speed scaling --- src/ahoy/config.h | 6 ++++-- src/ahoy/gui.c | 14 +++++++++++--- src/ahoy/main.c | 8 ++------ 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ahoy/config.h b/src/ahoy/config.h index 23d756f..4361d7d 100644 --- a/src/ahoy/config.h +++ b/src/ahoy/config.h @@ -3,14 +3,16 @@ #include -#define VOLMAX 10'000 +#define FPS 60 +#define CPUHZMAX 10'000 +#define VOLMAX 10'000 struct config { bool scanls; bool seeded; uint16_t seed; - unsigned cpu_hz; int vol; + int cpu_hz; }; extern struct config cfg; diff --git a/src/ahoy/gui.c b/src/ahoy/gui.c index 5ec20f3..cd01bcb 100644 --- a/src/ahoy/gui.c +++ b/src/ahoy/gui.c @@ -143,18 +143,26 @@ readevnt(void) case SDLK_SPACE: estate = estate == ES_RUNNING ? ES_PAUSED : ES_RUNNING; break; + case SDLK_l: + cfg.scanls = !cfg.scanls; + windrw(); + break; case SDLK_p: estate = ES_RESET; break; + case SDLK_EQUALS: cfg.vol = MIN(cfg.vol + 500, VOLMAX); break; case SDLK_MINUS: cfg.vol = MAX(cfg.vol - 500, 0); break; - case SDLK_l: - cfg.scanls = !cfg.scanls; - windrw(); + + case SDLK_PERIOD: + cfg.cpu_hz = MIN(cfg.cpu_hz + 10, CPUHZMAX); + break; + case SDLK_COMMA: + cfg.cpu_hz = MAX(cfg.cpu_hz - 10, FPS); break; case SDLK_1: diff --git a/src/ahoy/main.c b/src/ahoy/main.c index 85db49e..f1feef5 100644 --- a/src/ahoy/main.c +++ b/src/ahoy/main.c @@ -33,8 +33,6 @@ # warning "ckd_*() not supported on the current platform" #endif -#define FPS 60 - #define STRTOX(T, SUF) \ static T strto##SUF(const char8_t *s, rune *ch) \ { \ @@ -51,7 +49,6 @@ } STRTOX(int, i) -STRTOX(unsigned, u) STRTOX(uint16_t, u16) [[noreturn]] static void usage(void); @@ -115,8 +112,7 @@ main(int argc, char **argv) execlp("man", "man", "1", argv[0], nullptr); die("execlp: man 1 %s", argv[0]); case 'c': - NUMERIC_ARG(unsigned, UINT_MAX, "u", strtou, cpu_hz, - "cpu clock speed"); + NUMERIC_ARG(int, CPUHZMAX, "d", strtoi, cpu_hz, "cpu clock speed"); if (cfg.cpu_hz < FPS) { warnx("cpu clock speed may not be lower than the framerate (%d " "FPS)", @@ -211,7 +207,7 @@ reset: } st = SDL_GetPerformanceCounter(); - for (unsigned i = 0; i < cfg.cpu_hz / FPS; i++) + for (int i = 0; i < cfg.cpu_hz / FPS; i++) emutick(); et = SDL_GetPerformanceCounter(); dt = (double)((et - st) * 1000) / SDL_GetPerformanceFrequency(); -- cgit v1.2.3