From 8b022f1a2793d911045a18f4ba9959e37920e42d Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Sat, 30 Oct 2021 19:07:46 +0100 Subject: [PATCH] initial g --- apps/plugins/varvara/tests/vector.rom | Bin 0 -> 306 bytes apps/plugins/varvara/varvara.c | 32 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 apps/plugins/varvara/tests/vector.rom diff --git a/apps/plugins/varvara/tests/vector.rom b/apps/plugins/varvara/tests/vector.rom new file mode 100644 index 0000000000000000000000000000000000000000..42aca5d3de01bc1599efc23fc797565eb315d74f GIT binary patch literal 306 zcmZ`wF$%&!5Zs&z1_{JMP$B3^EP@Ee#!F|DBArjL^b5;`1JDCrivR!s literal 0 HcmV?d00001 diff --git a/apps/plugins/varvara/varvara.c b/apps/plugins/varvara/varvara.c index 51085a09c4..a5c856806c 100644 --- a/apps/plugins/varvara/varvara.c +++ b/apps/plugins/varvara/varvara.c @@ -10,10 +10,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 de-janking display code, support for greyscale displays +TODO proper support for greyscale displays TODO rom loading TODO other varvara devices -TODO hardware builds TODO clean up */ @@ -34,7 +33,7 @@ const Uint8 hwrom[] = { /* hello world ROM */ 0x21, }; -const Uint8 screenrom[] = { /* screen test ROM */ +const Uint8 uxn_rom[] = { /* screen test ROM */ 0x20, 0x01, 0x43, 0x80, 0x20, 0x37, 0x20, 0xf0, 0x7f, 0x80, 0x08, 0x37, 0x20, 0xf0, 0xe0, 0x80, 0x0a, 0x37, 0x20, 0xf0, 0xc0, 0x80, 0x0c, 0x37, @@ -136,7 +135,7 @@ const Uint8 screenrom[] = { /* screen test ROM */ 0x80, 0x80, }; -const Uint8 uxn_rom[] = { // screen vector test ROM +const Uint8 vector_rom[] = { // screen vector test ROM 0x20, 0x01, 0x19, 0x80, 0x20, 0x37, 0x20, 0x0f, 0x7f, 0x80, 0x08, 0x37, 0x20, 0x0f, 0xe0, 0x80, 0x0a, 0x37, 0x20, 0x0f, 0xc0, 0x80, 0x0c, 0x37, @@ -213,7 +212,7 @@ inspect(Stack *s, char *name) static void set_palette(Uint8 *addr) { - #if LCD_DEPTH > 1 + #if LCD_HAS_COLOR int i; for(i = 0; i < 4; ++i) { Uint8 @@ -222,11 +221,18 @@ set_palette(Uint8 *addr) b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; palette[i] = LCD_RGBPACK(r*8,g*8,b*8); } + #elif LCD_DEPTH > 1 // greyscale + 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; + } #else int i; for(i = 0; i < 4; ++i) { - Uint8 - sum = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f; + 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; @@ -323,14 +329,17 @@ nil_talk(Device *d, Uint8 b0, Uint8 w) return 1; } -// TODO optimise, make build on non-color devices +// TODO optimise, proper greyscale 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 + #if LCD_HAS_COLOR + rb->lcd_set_foreground(palette[ppu_read(&ppu, x, y)]); + rb->lcd_drawpixel(x, y); + #elif LCD_DEPTH > 1 rb->lcd_set_foreground(palette[ppu_read(&ppu, x, y)]); rb->lcd_drawpixel(x, y); #else @@ -356,10 +365,9 @@ static void run() { uxn_eval(&u, devscreen->vector); if(ppu.reqdraw || devsystem->dat[0xe]) redraw(); - switch(rb->button_get(false)) { + switch(rb->button_get(false)) { // TODO implement other buttons case BUTTON_NONE: break; - default: - return; + default: return; } rb->sleep(HZ/60); }