diff --git a/apps/plugins/varvara/devices/ppu.c b/apps/plugins/varvara/devices/ppu.c index c66516150f..2ac8778b7e 100644 --- a/apps/plugins/varvara/devices/ppu.c +++ b/apps/plugins/varvara/devices/ppu.c @@ -29,13 +29,12 @@ ppu_clear(Ppu *p) } Uint8 -ppu_set_size(Ppu *p, Uint16 width, Uint16 height) +ppu_init(Ppu *p, Uint16 width, Uint16 height, Uint8* buf) { ppu_clear(p); p->width = width; p->height = height; - p->pixels = realloc(p->pixels, p->width * p->height * sizeof(Uint8) / 2); - ppu_clear(p); + p->pixels = buf; return !!p->pixels; } diff --git a/apps/plugins/varvara/devices/ppu.h b/apps/plugins/varvara/devices/ppu.h index 1ae47c8c9e..fb00c7d59b 100644 --- a/apps/plugins/varvara/devices/ppu.h +++ b/apps/plugins/varvara/devices/ppu.h @@ -22,7 +22,7 @@ typedef struct Ppu { Uint16 width, height; } Ppu; -Uint8 ppu_set_size(Ppu *p, Uint16 width, Uint16 height); +Uint8 ppu_init(Ppu *p, Uint16 width, Uint16 height, Uint8* buf); Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); void ppu_frame(Ppu *p); diff --git a/apps/plugins/varvara/varvara.c b/apps/plugins/varvara/varvara.c index 1eda0913d8..579700e9bb 100644 --- a/apps/plugins/varvara/varvara.c +++ b/apps/plugins/varvara/varvara.c @@ -9,9 +9,9 @@ copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. -TODO screen vector, de-janking display code -TODO other devices -TODO hardware builds, support for hardware other than simulated e200 +TODO screen vector, de-janking display code, support for greyscale displays +TODO other varvara devices +TODO hardware builds TODO clean up */ @@ -139,6 +139,7 @@ static Uxn u; static Ppu ppu; static Device *devsystem, *devconsole, *devscreen; unsigned int palette[3]; +static uint8_t framebuffer[LCD_HEIGHT * LCD_WIDTH * 4]; static void memzero8(void *src, uint64_t n) @@ -165,7 +166,6 @@ inspect(Stack *s, char *name) } } -// TODO implement static void set_palette(Uint8 *addr) { @@ -178,6 +178,15 @@ set_palette(Uint8 *addr) b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; palette[i] = LCD_RGBPACK(r*8,g*8,b*8); } + #else + int i; + for(i = 0; i < 4; ++i) { + Uint8 + sum = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f; + sum += (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f; + sum += (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; + palette[i] = sum > 0x17; + } #endif } @@ -270,17 +279,21 @@ nil_talk(Device *d, Uint8 b0, Uint8 w) return 1; } -// TODO store palette in a non-guesswork format, optimise, make build on non-color devices -static int redraw(Uxn *u) +// TODO optimise, make build on non-color devices +static void redraw(void) { + rb->lcd_clear_display(); Uint16 x, y; for(y = 0; y < ppu.height; ++y) for(x = 0; x < ppu.width; ++x) { #if LCD_DEPTH > 1 rb->lcd_set_foreground(palette[ppu_read(&ppu, x, y)]); + rb->lcd_drawpixel(x, y); + #else + if(palette[ppu_read(&ppu, x, y)]) { + rb->lcd_drawpixel(x, y); + } #endif - rb->lcd_drawpixel(x, y); - } rb->lcd_update(); ppu.reqdraw = 0; @@ -302,7 +315,7 @@ enum plugin_status plugin_start(const void* parameter) (void)parameter; DEBUGF("Setting PPU size\n"); - ppu_set_size(&ppu, LCD_WIDTH, LCD_HEIGHT); + ppu_init(&ppu, LCD_WIDTH, LCD_HEIGHT, framebuffer); DEBUGF("UXN init\n"); // Clear RAM and copy rom to VM. DEBUGF("zeroing\n"); @@ -329,7 +342,7 @@ enum plugin_status plugin_start(const void* parameter) /* empty */ uxn_port(&u, 0xf, nil_talk); DEBUGF("eval\n"); uxn_eval(&u, 0x0100); - redraw(&u); + redraw(); rb->button_get(true); return PLUGIN_OK;