From d09b8df422d03170d0f44093a27607b8f7c1a2b6 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 8 Sep 2021 12:51:44 +0200 Subject: Add docolors implementation and test with screen.rom --- src/common.h | 4 ++++ src/main.c | 27 ++++++++++++++++++++++++++- src/ppu.c | 24 +++++++++++++++++------- src/rom.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 97 insertions(+), 10 deletions(-) diff --git a/src/common.h b/src/common.h index 1b21573..6f3bd70 100644 --- a/src/common.h +++ b/src/common.h @@ -245,6 +245,10 @@ mb_call(unsigned char ch, void *msg) { return mb_read(ch); } +// +// Utilities +// + void * memcpy(void *dest, const void *src, u32 n) { u8 *from = (u8*)src; diff --git a/src/main.c b/src/main.c index 3ecfa71..f2ffa5b 100644 --- a/src/main.c +++ b/src/main.c @@ -30,6 +30,16 @@ console_talk(Device *d, u8 b0, u8 w) { } } +static void +docolors(Device *d) { + for(size_t i = 0; i < 4; ++i) { + u8 r = ((d->dat[0x8 + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + u8 g = ((d->dat[0xa + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + u8 b = ((d->dat[0xc + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + palette[i] = (b << 16) | (g << 8) | r; + } +} + void system_talk(Device *d, u8 b0, u8 w) { // uart_puts("system_talk\n"); @@ -46,7 +56,7 @@ system_talk(Device *d, u8 b0, u8 w) { case 0xf: d->u->ram.ptr = 0x0000; break; } if(b0 > 0x7 && b0 < 0xe) { - // docolors(d); TODO + docolors(d); } } (void)b0; @@ -155,5 +165,20 @@ void main(void) { while(1) { // Echo input to standard output. uxn_eval(&u, mempeek16(devscreen->dat, 0)); + + // DEBUG: testing fb drawing. + u32 lines = SCREEN_WIDTH * SCREEN_HEIGHT / 4; + for (size_t i = 0; i < lines; i++) { + framebuffer[i] = palette[0]; + } + for (size_t i = lines; i < lines * 2; i++) { + framebuffer[i] = palette[1]; + } + for (size_t i = lines * 2; i < lines * 3; i++) { + framebuffer[i] = palette[2]; + } + for (size_t i = lines * 3; i < lines * 4; i++) { + framebuffer[i] = palette[3]; + } } } diff --git a/src/ppu.c b/src/ppu.c index 99574d7..2e0404f 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -2,8 +2,14 @@ static u32 *framebuffer = 0; +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 600 + +static u32 palette[4]; + void ppu_init(void) { + // Initialize the framebuffer. static MboxFramebufferRequest fb_request = { .buf_size = 96, .code = MBOX_REQUEST, @@ -12,16 +18,16 @@ ppu_init(void) { .id = 0x48003, .buf_size = 8, }, - .width = 1024, - .height = 1024, + .width = SCREEN_WIDTH, + .height = SCREEN_HEIGHT, }, .virtual_screen_tag = { .header = { .id = 0x48004, .buf_size = 8, }, - .width = 1024, - .height = 1024, + .width = SCREEN_WIDTH, + .height = SCREEN_HEIGHT, }, .depth_tag = { .header = { @@ -45,10 +51,14 @@ ppu_init(void) { && fb_request.framebuffer_tag.fb_addr != 0) { fb_request.framebuffer_tag.fb_addr &= 0x3FFFFFFF; framebuffer = (u32*)((uintptr_t)fb_request.framebuffer_tag.fb_addr); - for (size_t i = 0; i < 1024 * 100; i++) { - framebuffer[i] = 0xffaa22; // 0xBBGGRR - } } else { uart_puts("Unable initialize framebuffer\n"); + return; } + + // Initialize default palette. + palette[0] = 0x00444444; + palette[1] = 0x00ffffff; + palette[2] = 0x007777ff; + palette[3] = 0x00ff7777; } diff --git a/src/rom.c b/src/rom.c index 835d86a..419cad8 100644 --- a/src/rom.c +++ b/src/rom.c @@ -1,4 +1,52 @@ const u16 uxn_rom[] = { - 0x0120, 0x9413, 0x1880, 0x2117, 0x8094, 0x0df7, 0x8022, 0x8001, - 0x170e, 0x4800, 0x6c65, 0x6f6c, 0x5720, 0x726f, 0x646c, 0x6421, + 0x0120, 0x8043, 0x3720, 0xf020, 0x807f, 0x3708, 0xf020, 0x80e0, + 0x370a, 0xf020, 0x80c0, 0x370c, 0x2280, 0x8036, 0x3f01, 0x0020, + 0x3920, 0x0280, 0x8031, 0x3624, 0x0180, 0x803f, 0x3104, 0x0120, + 0x2ed4, 0x0220, 0x2e2f, 0x0220, 0x2e71, 0x0220, 0x2eae, 0x0320, + 0x2e3a, 0x8000, 0x3000, 0x2321, 0x0080, 0x8031, 0x3002, 0x0020, + 0x3848, 0x2880, 0x8037, 0x3004, 0x0020, 0x3950, 0x2a80, 0x8037, + 0x0f01, 0x0305, 0x0480, 0x801f, 0x0500, 0x3080, 0x203f, 0x9103, + 0x8038, 0x372c, 0x80cf, 0x172f, 0x0f80, 0x801c, 0x0500, 0x3080, + 0x203f, 0x9103, 0x8038, 0x372c, 0x2880, 0x2036, 0x0800, 0x8038, + 0x3728, 0x80cf, 0x172f, 0x8003, 0x1f04, 0x0080, 0x8005, 0x3f30, + 0x0320, 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, + 0xcf37, 0x2f80, 0x8017, 0x1c0f, 0x0080, 0x8005, 0x3f30, 0x0320, + 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, 0x4f37, + 0x2f80, 0x0017, 0x1080, 0x0080, 0x8003, 0x1f30, 0x0080, 0x2005, + 0x9103, 0x8038, 0x372c, 0x8003, 0x1f30, 0x0080, 0x8005, 0x3002, + 0x0020, 0x3940, 0x8038, 0x3728, 0x0480, 0x2030, 0x5000, 0x8039, + 0x372a, 0x0180, 0x2f80, 0x0317, 0x3080, 0x801f, 0x0500, 0x0480, + 0x2030, 0x4000, 0x3839, 0x2a80, 0x8037, 0x3002, 0x0020, 0x3950, + 0x2880, 0x8037, 0x8001, 0x172f, 0x8a01, 0xab80, 0x220d, 0x206c, + 0x8103, 0x2c80, 0x8037, 0x8000, 0x0300, 0x0f80, 0x801c, 0x1f40, + 0x0180, 0x801f, 0x0500, 0x0280, 0x2030, 0x4000, 0x3839, 0x2880, + 0x0337, 0xf080, 0x801c, 0x1f01, 0x0080, 0x8005, 0x3004, 0x0020, + 0x3940, 0x8038, 0x372a, 0x8003, 0x172f, 0x8901, 0xca80, 0x220d, + 0x806c, 0x8010, 0x8f00, 0x8003, 0x1f02, 0x0080, 0x8005, 0x3f40, + 0x0480, 0x2030, 0x4000, 0x3839, 0x032f, 0x0380, 0x801c, 0x0500, + 0x4080, 0x203f, 0x4000, 0x8038, 0x3002, 0x0020, 0x3808, 0x6f38, + 0x804f, 0x2000, 0xe702, 0x012e, 0x808a, 0x0dc9, 0x6c22, 0x1080, + 0x0080, 0x038f, 0x0280, 0x801f, 0x0500, 0x4080, 0x803f, 0x3004, + 0x2f38, 0x8003, 0x1c03, 0x0080, 0x8005, 0x3f40, 0x0020, 0x3840, + 0x0280, 0x2030, 0x0800, 0x3838, 0x4f6f, 0x8080, 0x0220, 0x2ee7, + 0x8a01, 0xcd80, 0x220d, 0x186c, 0x200f, 0x8103, 0x2c80, 0x8037, + 0x372a, 0x2880, 0x8037, 0xcf00, 0x8018, 0x172f, 0x2880, 0x2036, + 0x0800, 0x8038, 0x3728, 0x1080, 0x18cf, 0x2f80, 0x8017, 0x3628, + 0x0020, 0x3908, 0x2880, 0x8037, 0x362a, 0x0020, 0x3808, 0x2a80, + 0x8037, 0xcf20, 0x8018, 0x172f, 0x2880, 0x2036, 0x0800, 0x8038, + 0x3728, 0x3080, 0x184f, 0x2f80, 0x6c17, 0x0480, 0x2030, 0x4000, + 0x8039, 0x372a, 0x0280, 0x2030, 0x4800, 0x8038, 0x3728, 0x0080, + 0x2e80, 0x8017, 0x3002, 0x0020, 0x3849, 0x2880, 0x8037, 0x8001, + 0x172e, 0x0280, 0x2030, 0x4a00, 0x8038, 0x3728, 0x0280, 0x2e80, + 0x8017, 0x3002, 0x0020, 0x384b, 0x2880, 0x8037, 0x8003, 0x172e, + 0x0f6c, 0x6738, 0xdf5f, 0xbfbf, 0x00bf, 0x1807, 0x2320, 0x4844, + 0x0048, 0x827c, 0x8282, 0x8282, 0x007c, 0x1030, 0x1010, 0x1010, + 0x0010, 0x827c, 0x7c02, 0x8080, 0x00fe, 0x827c, 0x1c02, 0x8202, + 0x007c, 0x140c, 0x4424, 0xfe84, 0x0004, 0x80fe, 0x7c80, 0x8202, + 0x007c, 0x827c, 0xfc80, 0x8282, 0x007c, 0x827c, 0x1e02, 0x0202, + 0x0002, 0x827c, 0x7c82, 0x8282, 0x007c, 0x827c, 0x7e82, 0x8202, + 0x007c, 0x827c, 0x7e02, 0x8282, 0x007e, 0x82fc, 0xfc82, 0x8282, + 0x00fc, 0x827c, 0x8080, 0x8280, 0x007c, 0x82fc, 0x8282, 0x8282, + 0x00fc, 0x827c, 0xf080, 0x8280, 0x007c, 0x827c, 0xf080, 0x8080, + 0x8080, }; -- cgit v1.2.1