aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-14 03:44:39 +0200
committerkdx <kikoodx@paranoici.org>2023-04-14 03:44:39 +0200
commitdcbc2dfa4dba9bf800d730f76f3c63faa3accb81 (patch)
treeb6a28f5cec940d4b61979096244b792033c58301
parentcccfd1feffba5cab4510ed1d0597a9a7961854ef (diff)
downloadorga-dcbc2dfa4dba9bf800d730f76f3c63faa3accb81.tar.gz
input sample and clean fps manager
-rw-r--r--samples/input.orgaasm9
-rw-r--r--src/orgaemu.c12
2 files changed, 17 insertions, 4 deletions
diff --git a/samples/input.orgaasm b/samples/input.orgaasm
index a5da548..46b4c9e 100644
--- a/samples/input.orgaasm
+++ b/samples/input.orgaasm
@@ -1,4 +1,7 @@
@loop
- SLP
- LIT ,Input LDA DBG POP
- JMP ,loop
+ SLP ( cycle input events )
+ LIT ,Input LDA ( get input )
+ DBG ( print to console )
+ #0008 AND ( loop until start is pressed )
+ JEZ ,loop
+ RET
diff --git a/src/orgaemu.c b/src/orgaemu.c
index c1c898f..e22f270 100644
--- a/src/orgaemu.c
+++ b/src/orgaemu.c
@@ -30,6 +30,7 @@ static size_t stack_ptr = 0, rstack_ptr = 0;
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
static SDL_Texture *target = NULL;
+static Uint64 next_time = 0;
static int
fail(void)
@@ -114,8 +115,16 @@ render(uint16_t *mem)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, target, NULL, &dest);
+
+ next_time += 1000 / 30;
+ const Uint64 cur_time = SDL_GetTicks64();
+ if (next_time <= cur_time) {
+ fprintf(stderr, "lagging %lu\n", cur_time - next_time);
+ next_time = cur_time;
+ } else
+ SDL_Delay(next_time - cur_time);
+
SDL_RenderPresent(renderer);
- SDL_Delay(1000 / 30); /* TODO: proper fps cap */
}
static void
@@ -390,6 +399,7 @@ main(int argc, char **argv)
fprintf(stderr, "%s\n", SDL_GetError());
return fail();
}
+ next_time = SDL_GetTicks64();
exec_data(mem);
return fail(), 0;