aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-09-08 12:51:44 +0200
committerBad Diode <bd@badd10de.dev>2021-09-08 12:51:44 +0200
commitd09b8df422d03170d0f44093a27607b8f7c1a2b6 (patch)
tree8873e3ee9753a6aa5defe8fc0fe3357ea5787e5e
parent10d0cb73c6998789756c84b8bcbd958783e679ab (diff)
downloaduxnrpi-d09b8df422d03170d0f44093a27607b8f7c1a2b6.tar.gz
uxnrpi-d09b8df422d03170d0f44093a27607b8f7c1a2b6.zip
Add docolors implementation and test with screen.rom
-rw-r--r--src/common.h4
-rw-r--r--src/main.c27
-rw-r--r--src/ppu.c24
-rw-r--r--src/rom.c52
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) {
245 return mb_read(ch); 245 return mb_read(ch);
246} 246}
247 247
248//
249// Utilities
250//
251
248void * 252void *
249memcpy(void *dest, const void *src, u32 n) { 253memcpy(void *dest, const void *src, u32 n) {
250 u8 *from = (u8*)src; 254 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) {
30 } 30 }
31} 31}
32 32
33static void
34docolors(Device *d) {
35 for(size_t i = 0; i < 4; ++i) {
36 u8 r = ((d->dat[0x8 + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11;
37 u8 g = ((d->dat[0xa + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11;
38 u8 b = ((d->dat[0xc + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11;
39 palette[i] = (b << 16) | (g << 8) | r;
40 }
41}
42
33void 43void
34system_talk(Device *d, u8 b0, u8 w) { 44system_talk(Device *d, u8 b0, u8 w) {
35 // uart_puts("system_talk\n"); 45 // uart_puts("system_talk\n");
@@ -46,7 +56,7 @@ system_talk(Device *d, u8 b0, u8 w) {
46 case 0xf: d->u->ram.ptr = 0x0000; break; 56 case 0xf: d->u->ram.ptr = 0x0000; break;
47 } 57 }
48 if(b0 > 0x7 && b0 < 0xe) { 58 if(b0 > 0x7 && b0 < 0xe) {
49 // docolors(d); TODO 59 docolors(d);
50 } 60 }
51 } 61 }
52 (void)b0; 62 (void)b0;
@@ -155,5 +165,20 @@ void main(void) {
155 while(1) { 165 while(1) {
156 // Echo input to standard output. 166 // Echo input to standard output.
157 uxn_eval(&u, mempeek16(devscreen->dat, 0)); 167 uxn_eval(&u, mempeek16(devscreen->dat, 0));
168
169 // DEBUG: testing fb drawing.
170 u32 lines = SCREEN_WIDTH * SCREEN_HEIGHT / 4;
171 for (size_t i = 0; i < lines; i++) {
172 framebuffer[i] = palette[0];
173 }
174 for (size_t i = lines; i < lines * 2; i++) {
175 framebuffer[i] = palette[1];
176 }
177 for (size_t i = lines * 2; i < lines * 3; i++) {
178 framebuffer[i] = palette[2];
179 }
180 for (size_t i = lines * 3; i < lines * 4; i++) {
181 framebuffer[i] = palette[3];
182 }
158 } 183 }
159} 184}
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 @@
2 2
3static u32 *framebuffer = 0; 3static u32 *framebuffer = 0;
4 4
5#define SCREEN_WIDTH 800
6#define SCREEN_HEIGHT 600
7
8static u32 palette[4];
9
5void 10void
6ppu_init(void) { 11ppu_init(void) {
12 // Initialize the framebuffer.
7 static MboxFramebufferRequest fb_request = { 13 static MboxFramebufferRequest fb_request = {
8 .buf_size = 96, 14 .buf_size = 96,
9 .code = MBOX_REQUEST, 15 .code = MBOX_REQUEST,
@@ -12,16 +18,16 @@ ppu_init(void) {
12 .id = 0x48003, 18 .id = 0x48003,
13 .buf_size = 8, 19 .buf_size = 8,
14 }, 20 },
15 .width = 1024, 21 .width = SCREEN_WIDTH,
16 .height = 1024, 22 .height = SCREEN_HEIGHT,
17 }, 23 },
18 .virtual_screen_tag = { 24 .virtual_screen_tag = {
19 .header = { 25 .header = {
20 .id = 0x48004, 26 .id = 0x48004,
21 .buf_size = 8, 27 .buf_size = 8,
22 }, 28 },
23 .width = 1024, 29 .width = SCREEN_WIDTH,
24 .height = 1024, 30 .height = SCREEN_HEIGHT,
25 }, 31 },
26 .depth_tag = { 32 .depth_tag = {
27 .header = { 33 .header = {
@@ -45,10 +51,14 @@ ppu_init(void) {
45 && fb_request.framebuffer_tag.fb_addr != 0) { 51 && fb_request.framebuffer_tag.fb_addr != 0) {
46 fb_request.framebuffer_tag.fb_addr &= 0x3FFFFFFF; 52 fb_request.framebuffer_tag.fb_addr &= 0x3FFFFFFF;
47 framebuffer = (u32*)((uintptr_t)fb_request.framebuffer_tag.fb_addr); 53 framebuffer = (u32*)((uintptr_t)fb_request.framebuffer_tag.fb_addr);
48 for (size_t i = 0; i < 1024 * 100; i++) {
49 framebuffer[i] = 0xffaa22; // 0xBBGGRR
50 }
51 } else { 54 } else {
52 uart_puts("Unable initialize framebuffer\n"); 55 uart_puts("Unable initialize framebuffer\n");
56 return;
53 } 57 }
58
59 // Initialize default palette.
60 palette[0] = 0x00444444;
61 palette[1] = 0x00ffffff;
62 palette[2] = 0x007777ff;
63 palette[3] = 0x00ff7777;
54} 64}
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 @@
1const u16 uxn_rom[] = { 1const u16 uxn_rom[] = {
2 0x0120, 0x9413, 0x1880, 0x2117, 0x8094, 0x0df7, 0x8022, 0x8001, 2 0x0120, 0x8043, 0x3720, 0xf020, 0x807f, 0x3708, 0xf020, 0x80e0,
3 0x170e, 0x4800, 0x6c65, 0x6f6c, 0x5720, 0x726f, 0x646c, 0x6421, 3 0x370a, 0xf020, 0x80c0, 0x370c, 0x2280, 0x8036, 0x3f01, 0x0020,
4 0x3920, 0x0280, 0x8031, 0x3624, 0x0180, 0x803f, 0x3104, 0x0120,
5 0x2ed4, 0x0220, 0x2e2f, 0x0220, 0x2e71, 0x0220, 0x2eae, 0x0320,
6 0x2e3a, 0x8000, 0x3000, 0x2321, 0x0080, 0x8031, 0x3002, 0x0020,
7 0x3848, 0x2880, 0x8037, 0x3004, 0x0020, 0x3950, 0x2a80, 0x8037,
8 0x0f01, 0x0305, 0x0480, 0x801f, 0x0500, 0x3080, 0x203f, 0x9103,
9 0x8038, 0x372c, 0x80cf, 0x172f, 0x0f80, 0x801c, 0x0500, 0x3080,
10 0x203f, 0x9103, 0x8038, 0x372c, 0x2880, 0x2036, 0x0800, 0x8038,
11 0x3728, 0x80cf, 0x172f, 0x8003, 0x1f04, 0x0080, 0x8005, 0x3f30,
12 0x0320, 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880,
13 0xcf37, 0x2f80, 0x8017, 0x1c0f, 0x0080, 0x8005, 0x3f30, 0x0320,
14 0x3891, 0x2c80, 0x8037, 0x3628, 0x0020, 0x3808, 0x2880, 0x4f37,
15 0x2f80, 0x0017, 0x1080, 0x0080, 0x8003, 0x1f30, 0x0080, 0x2005,
16 0x9103, 0x8038, 0x372c, 0x8003, 0x1f30, 0x0080, 0x8005, 0x3002,
17 0x0020, 0x3940, 0x8038, 0x3728, 0x0480, 0x2030, 0x5000, 0x8039,
18 0x372a, 0x0180, 0x2f80, 0x0317, 0x3080, 0x801f, 0x0500, 0x0480,
19 0x2030, 0x4000, 0x3839, 0x2a80, 0x8037, 0x3002, 0x0020, 0x3950,
20 0x2880, 0x8037, 0x8001, 0x172f, 0x8a01, 0xab80, 0x220d, 0x206c,
21 0x8103, 0x2c80, 0x8037, 0x8000, 0x0300, 0x0f80, 0x801c, 0x1f40,
22 0x0180, 0x801f, 0x0500, 0x0280, 0x2030, 0x4000, 0x3839, 0x2880,
23 0x0337, 0xf080, 0x801c, 0x1f01, 0x0080, 0x8005, 0x3004, 0x0020,
24 0x3940, 0x8038, 0x372a, 0x8003, 0x172f, 0x8901, 0xca80, 0x220d,
25 0x806c, 0x8010, 0x8f00, 0x8003, 0x1f02, 0x0080, 0x8005, 0x3f40,
26 0x0480, 0x2030, 0x4000, 0x3839, 0x032f, 0x0380, 0x801c, 0x0500,
27 0x4080, 0x203f, 0x4000, 0x8038, 0x3002, 0x0020, 0x3808, 0x6f38,
28 0x804f, 0x2000, 0xe702, 0x012e, 0x808a, 0x0dc9, 0x6c22, 0x1080,
29 0x0080, 0x038f, 0x0280, 0x801f, 0x0500, 0x4080, 0x803f, 0x3004,
30 0x2f38, 0x8003, 0x1c03, 0x0080, 0x8005, 0x3f40, 0x0020, 0x3840,
31 0x0280, 0x2030, 0x0800, 0x3838, 0x4f6f, 0x8080, 0x0220, 0x2ee7,
32 0x8a01, 0xcd80, 0x220d, 0x186c, 0x200f, 0x8103, 0x2c80, 0x8037,
33 0x372a, 0x2880, 0x8037, 0xcf00, 0x8018, 0x172f, 0x2880, 0x2036,
34 0x0800, 0x8038, 0x3728, 0x1080, 0x18cf, 0x2f80, 0x8017, 0x3628,
35 0x0020, 0x3908, 0x2880, 0x8037, 0x362a, 0x0020, 0x3808, 0x2a80,
36 0x8037, 0xcf20, 0x8018, 0x172f, 0x2880, 0x2036, 0x0800, 0x8038,
37 0x3728, 0x3080, 0x184f, 0x2f80, 0x6c17, 0x0480, 0x2030, 0x4000,
38 0x8039, 0x372a, 0x0280, 0x2030, 0x4800, 0x8038, 0x3728, 0x0080,
39 0x2e80, 0x8017, 0x3002, 0x0020, 0x3849, 0x2880, 0x8037, 0x8001,
40 0x172e, 0x0280, 0x2030, 0x4a00, 0x8038, 0x3728, 0x0280, 0x2e80,
41 0x8017, 0x3002, 0x0020, 0x384b, 0x2880, 0x8037, 0x8003, 0x172e,
42 0x0f6c, 0x6738, 0xdf5f, 0xbfbf, 0x00bf, 0x1807, 0x2320, 0x4844,
43 0x0048, 0x827c, 0x8282, 0x8282, 0x007c, 0x1030, 0x1010, 0x1010,
44 0x0010, 0x827c, 0x7c02, 0x8080, 0x00fe, 0x827c, 0x1c02, 0x8202,
45 0x007c, 0x140c, 0x4424, 0xfe84, 0x0004, 0x80fe, 0x7c80, 0x8202,
46 0x007c, 0x827c, 0xfc80, 0x8282, 0x007c, 0x827c, 0x1e02, 0x0202,
47 0x0002, 0x827c, 0x7c82, 0x8282, 0x007c, 0x827c, 0x7e82, 0x8202,
48 0x007c, 0x827c, 0x7e02, 0x8282, 0x007e, 0x82fc, 0xfc82, 0x8282,
49 0x00fc, 0x827c, 0x8080, 0x8280, 0x007c, 0x82fc, 0x8282, 0x8282,
50 0x00fc, 0x827c, 0xf080, 0x8280, 0x007c, 0x827c, 0xf080, 0x8080,
51 0x8080,
4}; 52};