From 0f38a92a4e7f78af494b0f223a5a6ca2fd4930b1 Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Sun, 25 Dec 2016 23:48:48 -0500 Subject: [PATCH] Fixes #95 Make video refresh rate configurable, default to 30 --- src/two.c | 22 ++++++++++++++-------- src/two.h | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/two.c b/src/two.c index 18c1b3e..61f575c 100644 --- a/src/two.c +++ b/src/two.c @@ -491,14 +491,16 @@ static bool ewm_two_step_cpu(struct ewm_two_t *two, int cycles) { return true; } -#define EWM_TWO_OPT_DRIVE1 0 -#define EWM_TWO_OPT_DRIVE2 1 -#define EWM_TWO_OPT_COLOR 2 +#define EWM_TWO_OPT_DRIVE1 (0) +#define EWM_TWO_OPT_DRIVE2 (1) +#define EWM_TWO_OPT_COLOR (2) +#define EWM_TWO_OPT_FPS (3) static struct option one_options[] = { { "drive1", required_argument, NULL, EWM_TWO_OPT_DRIVE1 }, { "drive2", required_argument, NULL, EWM_TWO_OPT_DRIVE2 }, { "color", no_argument, NULL, EWM_TWO_OPT_COLOR }, + { "fps", required_argument, NULL, EWM_TWO_OPT_FPS }, { NULL, 0, NULL, 0 } }; @@ -508,6 +510,7 @@ int ewm_two_main(int argc, char **argv) { char *drive1 = NULL; char *drive2 = NULL; bool color = false; + int fps = EWM_TWO_FPS_DEFAULT; char ch; while ((ch = getopt_long_only(argc, argv, "", one_options, NULL)) != -1) { @@ -521,6 +524,9 @@ int ewm_two_main(int argc, char **argv) { case EWM_TWO_OPT_COLOR: color = true; break; + case EWM_TWO_OPT_FPS: + fps = atoi(optarg); + break; } } @@ -592,8 +598,8 @@ int ewm_two_main(int argc, char **argv) { break; } - if ((SDL_GetTicks() - ticks) >= (1000 / 50)) { - if (!ewm_two_step_cpu(two, 1000000 / 50)) { + if ((SDL_GetTicks() - ticks) >= (1000 / fps)) { + if (!ewm_two_step_cpu(two, 1000000 / fps)) { break; } @@ -601,15 +607,15 @@ int ewm_two_main(int argc, char **argv) { // the second half of the frames we draw each second. The // latter because that is when we update flashing text. - if (two->screen_dirty || (phase == 0) || (phase == (50 / 2))) { - ewm_scr_update(two->scr, phase, 50); + if (two->screen_dirty || (phase == 0) || (phase == (fps / 2))) { + ewm_scr_update(two->scr, phase, fps); two->screen_dirty = false; SDL_RenderPresent(two->scr->renderer); } ticks = SDL_GetTicks(); phase += 1; - if (phase == 50) { + if (phase == fps) { phase = 0; } } diff --git a/src/two.h b/src/two.h index b5e5545..5165d24 100644 --- a/src/two.h +++ b/src/two.h @@ -49,6 +49,8 @@ #define EWM_A2P_BUTTON4 3 // Actually ony exists on the gs? #define EWM_A2P_BUTTON_COUNT 4 +#define EWM_TWO_FPS_DEFAULT (30) + struct mem_t; struct ewm_dsk_t; struct scr;