From 2ca7b61c84c535cbe0f7529f8c457135c8d2e365 Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Sun, 7 Nov 2021 19:14:52 +0000 Subject: [PATCH] things --- apps/plugins/varvara/varvara.c | 44 ++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/apps/plugins/varvara/varvara.c b/apps/plugins/varvara/varvara.c index 6fdcfaee13..251cbc6ab9 100644 --- a/apps/plugins/varvara/varvara.c +++ b/apps/plugins/varvara/varvara.c @@ -306,6 +306,9 @@ unsigned int palette[3]; static Uint8 framebuffer[LCD_HEIGHT * LCD_WIDTH * 4]; static fb_data *lcd_fb = NULL; + +static unsigned long starttick; + static void memzero8(void *src, uint64_t n) { @@ -443,18 +446,35 @@ nil_talk(Device *d, Uint8 b0, Uint8 w) return 1; } -// TODO mono, greyscale +// TODO mono and greyscale that don't suck static void redraw(void) { - if (!lcd_fb) - { - struct viewport *vp_main = rb->lcd_set_viewport(NULL); - lcd_fb = vp_main->buffer->fb_ptr; - } - for(int y = 0 ; y < LCD_WIDTH*LCD_HEIGHT; y++ ) { - lcd_fb[y] = palette[ppu_read(&ppu, y%LCD_WIDTH, y/LCD_HEIGHT)]; - } - rb->lcd_update(); + #if LCD_DEPTH > 4 + if (!lcd_fb) + { + struct viewport *vp_main = rb->lcd_set_viewport(NULL); + lcd_fb = vp_main->buffer->fb_ptr; + } + for(int i = 0 ; i < LCD_WIDTH*LCD_HEIGHT; i++ ) { + Uint32 row = i / 2; + Uint8 shift = !(i & 0x1) << 2; + Uint8 pix = framebuffer[row] >> shift; + if(pix & 0x0c) + pix = pix >> 2; + lcd_fb[i] = palette[pix & 0x3]; + } + rb->lcd_update(); + #else + rb->lcd_clear_display(); + for(Uint16 x = 0; x < LCD_WIDTH; x++ ) { + for(Uint16 y = 0; y < LCD_HEIGHT; y++ ) { + if(palette[ppu_read(&ppu, x, y)]) { + rb->lcd_drawpixel(x, y); + } + } + } + rb->lcd_update(); + #endif ppu.reqdraw = 0; } @@ -468,6 +488,7 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) // TODO fix timing static void run() { + starttick = *rb->current_tick; while(!devsystem->dat[0xf]) { uxn_eval(&u, devscreen->vector); if(ppu.reqdraw || devsystem->dat[0xe]) @@ -513,6 +534,9 @@ static void run() { uxn_eval(&u, peek16(devctrl->dat, 0)); } + if((*rb->current_tick - starttick)sleep(*rb->current_tick - starttick); + } } }