uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 818ade6db1564a1fb9b9c8e0d0ded2f0ac4a07c9
parent 3dafa868cb307b45b3785ebb0e4dafc933b9b110
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun,  4 Apr 2021 20:58:47 -0700

Fixed emulator frame bug

Diffstat:
Mbuild.sh | 2+-
Mprojects/examples/dev.keys.usm | 3+--
Msrc/emulator.c | 43++++++++++++++++++-------------------------
Msrc/uxn.c | 3+--
4 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/build.sh b/build.sh @@ -28,7 +28,7 @@ else fi echo "Assembling.." -./bin/assembler projects/examples/dev.controller.usm bin/boot.rom +./bin/assembler projects/software/nasu.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/projects/examples/dev.keys.usm b/projects/examples/dev.keys.usm @@ -6,7 +6,6 @@ ;cursor { x 2 y 2 blink 1 } - |0100 ;Console { pad 8 char 1 byte 1 short 2 } |0110 ;Screen { width 2 height 2 pad 4 y 2 x 2 color 1 } |0120 ;Sprite { pad 8 x 2 y 2 addr 2 color 1 } @@ -28,7 +27,7 @@ BRK ( theme ) #0daf =System.r #02ff =System.g #035f =System.b ( update cursor ) - #02 ~cursor.blink #01 EQU ADD =Sprite.color + #02 =Sprite.color ,cursor_icn =Sprite.addr ~cursor.blink MOD2 #00 EQU =cursor.blink diff --git a/src/emulator.c b/src/emulator.c @@ -579,41 +579,34 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) #pragma mark - Generics -void -runevents(Uxn *u) -{ - SDL_Event event; - while(SDL_PollEvent(&event) != 0) { - switch(event.type) { - case SDL_QUIT: quit(); break; - case SDL_MOUSEBUTTONUP: - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEMOTION: domouse(u, &event); break; - case SDL_TEXTINPUT: dotext(u, &event); break; - case SDL_KEYDOWN: doctrl(u, &event, 1); break; - case SDL_KEYUP: doctrl(u, &event, 0); break; - case SDL_WINDOWEVENT: - if(event.window.event == SDL_WINDOWEVENT_EXPOSED) - redraw(pixels, u); - break; - } - } -} - int start(Uxn *u) { evaluxn(u, PAGE_VECTORS); redraw(pixels, u); while(1) { - float elapsed; - double start = SDL_GetPerformanceCounter(); - runevents(u); + SDL_Event event; + double elapsed, start = SDL_GetPerformanceCounter(); + while(SDL_PollEvent(&event) != 0) { + switch(event.type) { + case SDL_QUIT: quit(); break; + case SDL_MOUSEBUTTONUP: + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEMOTION: domouse(u, &event); break; + case SDL_TEXTINPUT: dotext(u, &event); break; + case SDL_KEYDOWN: doctrl(u, &event, 1); break; + case SDL_KEYUP: doctrl(u, &event, 0); break; + case SDL_WINDOWEVENT: + if(event.window.event == SDL_WINDOWEVENT_EXPOSED) + redraw(pixels, u); + break; + } + } evaluxn(u, PAGE_VECTORS + 0x08); if(screen.reqdraw) redraw(pixels, u); elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f; - SDL_Delay((int)(16.666f - elapsed)); + SDL_Delay(clamp(16.666f - elapsed, 0, 1000)); } } diff --git a/src/uxn.c b/src/uxn.c @@ -145,10 +145,9 @@ evaluxn(Uxn *u, Uint16 vec) u->ram.ptr = vec; u->wst.error = 0; u->rst.error = 0; - while(u->ram.ptr) { + while(u->ram.ptr) if(!stepuxn(u, u->ram.dat[u->ram.ptr++])) return 0; - } return 1; }