diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 153 |
1 files changed, 149 insertions, 4 deletions
@@ -1,14 +1,159 @@ | |||
1 | #include "common.h" | 1 | #include "common.h" |
2 | #include "ppu.c" | 2 | #include "ppu.c" |
3 | #include "uxn-fast.c" | ||
4 | #include "rom.c" | ||
3 | 5 | ||
4 | void main(void) { | 6 | static Uxn u; |
5 | // Initialize uart. | 7 | static Device *devscreen; |
6 | uart_init(); | 8 | static Device *devctrl; |
9 | static Device *devmouse; | ||
10 | static Device *devaudio; | ||
11 | |||
12 | void | ||
13 | nil_talk(Device *d, u8 b0, u8 w) { | ||
14 | (void)d; | ||
15 | (void)b0; | ||
16 | (void)w; | ||
17 | } | ||
18 | |||
19 | void | ||
20 | console_talk(Device *d, u8 b0, u8 w) { | ||
21 | char stmp[2]; | ||
22 | if(!w) { | ||
23 | return; | ||
24 | } | ||
25 | switch(b0) { | ||
26 | case 0x8: stmp[0] = d->dat[0x8]; stmp[1] = 0; uart_puts(stmp); break; | ||
27 | // case 0x9: txt_printf("0x%02x", d->dat[0x9]); break; | ||
28 | // case 0xb: txt_printf("0x%04x", mempeek16(d->dat, 0xa)); break; | ||
29 | // case 0xd: txt_printf("%s", &d->mem[mempeek16(d->dat, 0xc)]); break; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | void | ||
34 | system_talk(Device *d, u8 b0, u8 w) { | ||
35 | // uart_puts("system_talk\n"); | ||
36 | // TODO: Implement... | ||
37 | if(!w) { /* read */ | ||
38 | switch(b0) { | ||
39 | case 0x2: d->dat[0x2] = d->u->wst.ptr; break; | ||
40 | case 0x3: d->dat[0x3] = d->u->rst.ptr; break; | ||
41 | } | ||
42 | } else { /* write */ | ||
43 | switch(b0) { | ||
44 | case 0x2: d->u->wst.ptr = d->dat[0x2]; break; | ||
45 | case 0x3: d->u->rst.ptr = d->dat[0x3]; break; | ||
46 | case 0xf: d->u->ram.ptr = 0x0000; break; | ||
47 | } | ||
48 | if(b0 > 0x7 && b0 < 0xe) { | ||
49 | // docolors(d); TODO | ||
50 | } | ||
51 | } | ||
52 | (void)b0; | ||
53 | } | ||
54 | |||
55 | void | ||
56 | screen_talk(Device *d, u8 b0, u8 w) { | ||
57 | // uart_puts("screen_talk\n"); | ||
58 | // TODO: Implement... | ||
59 | // if(w && b0 == 0xe) { | ||
60 | // u16 x = mempeek16(d->dat, 0x8); | ||
61 | // u16 y = mempeek16(d->dat, 0xa); | ||
62 | // u8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; | ||
63 | // u8 *layer = d->dat[0xe] >> 4 & 0x1 ? ppu.fg : ppu.bg; | ||
64 | // u8 mode = d->dat[0xe] >> 5; | ||
65 | // u8 color = d->dat[0xf] & 0xf; | ||
66 | // if(!mode) { | ||
67 | // ppu_pixel(layer, x, y, d->dat[0xe] & 0x3); | ||
68 | // } else if(mode-- & 0x1) { | ||
69 | // u8 flipx = mode & 0x2; | ||
70 | // u8 flipy = mode & 0x4; | ||
71 | // ppu_1bpp(layer, x, y, addr, color, flipx, flipy); | ||
72 | // } else { | ||
73 | // u8 flipx = mode & 0x2; | ||
74 | // u8 flipy = mode & 0x4; | ||
75 | // ppu_2bpp(layer, x, y, addr, color, flipx, flipy); | ||
76 | // } | ||
77 | // } else if(w && b0 == 0xf) { | ||
78 | // u16 x = mempeek16(d->dat, 0x8); | ||
79 | // u16 y = mempeek16(d->dat, 0xa); | ||
80 | // u8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; | ||
81 | // u8 *layer = d->dat[0xf] >> 6 & 0x1 ? ppu.fg : ppu.bg; | ||
82 | // u8 color = d->dat[0xf] & 0xf; | ||
83 | // u8 flipx = (d->dat[0xf] >> 0x4) & 0x1; | ||
84 | // u8 flipy = (d->dat[0xf] >> 0x5) & 0x1; | ||
85 | // if(d->dat[0xf] >> 0x7 & 0x1) { | ||
86 | // ppu_2bpp(layer, x, y, addr, color, flipx, flipy); | ||
87 | // } else { | ||
88 | // ppu_1bpp(layer, x, y, addr, color, flipx, flipy); | ||
89 | // } | ||
90 | // } | ||
91 | } | ||
7 | 92 | ||
93 | static void | ||
94 | audio_talk(Device *d, u8 b0, u8 w) { | ||
95 | // TODO: Implement... | ||
96 | // uart_puts("audio_talk\n"); | ||
97 | (void)d; | ||
98 | (void)b0; | ||
99 | (void)w; | ||
100 | } | ||
101 | |||
102 | void | ||
103 | datetime_talk(Device *d, u8 b0, u8 w) { | ||
104 | // uart_puts("datetime_talk\n"); | ||
105 | // TODO: Implement... | ||
106 | (void)d; | ||
107 | (void)b0; | ||
108 | (void)w; | ||
109 | } | ||
110 | |||
111 | void | ||
112 | file_talk(Device *d, u8 b0, u8 w) { | ||
113 | // uart_puts("file_talk\n"); | ||
114 | // TODO: Implement... | ||
115 | (void)d; | ||
116 | (void)b0; | ||
117 | (void)w; | ||
118 | } | ||
119 | |||
120 | void | ||
121 | init_uxn() { | ||
122 | uart_puts("Initializing UXN.\n"); | ||
123 | uart_init(); | ||
8 | ppu_init(); | 124 | ppu_init(); |
9 | 125 | ||
126 | // Copy rom to VM. | ||
127 | memcpy(u.ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); | ||
128 | |||
129 | // Prepare devices. | ||
130 | uxn_port(&u, 0x0, "system", system_talk); | ||
131 | uxn_port(&u, 0x1, "console", console_talk); | ||
132 | devscreen = uxn_port(&u, 0x2, "screen", screen_talk); | ||
133 | devaudio = uxn_port(&u, 0x3, "audio0", audio_talk); | ||
134 | uxn_port(&u, 0x4, "audio1", audio_talk); | ||
135 | uxn_port(&u, 0x5, "audio2", audio_talk); | ||
136 | uxn_port(&u, 0x6, "audio3", audio_talk); | ||
137 | uxn_port(&u, 0x7, "---", nil_talk); | ||
138 | devctrl = uxn_port(&u, 0x8, "controller", nil_talk); | ||
139 | devmouse = uxn_port(&u, 0x9, "mouse", nil_talk); | ||
140 | uxn_port(&u, 0xa, "file", file_talk); | ||
141 | uxn_port(&u, 0xb, "datetime", datetime_talk); | ||
142 | uxn_port(&u, 0xc, "---", nil_talk); | ||
143 | uxn_port(&u, 0xd, "---", nil_talk); | ||
144 | uxn_port(&u, 0xe, "---", nil_talk); | ||
145 | uxn_port(&u, 0xf, "---", nil_talk); | ||
146 | // mempoke16(devscreen->dat, 2, ppu.hor * 8); | ||
147 | // mempoke16(devscreen->dat, 4, ppu.ver * 8); | ||
148 | } | ||
149 | |||
150 | void main(void) { | ||
151 | // Initialize uart. | ||
152 | init_uxn(); | ||
153 | |||
154 | uxn_eval(&u, 0x0100); | ||
10 | while(1) { | 155 | while(1) { |
11 | // Echo input to standard output. | 156 | // Echo input to standard output. |
12 | uart_putc(uart_getc()); | 157 | uxn_eval(&u, mempeek16(devscreen->dat, 0)); |
13 | } | 158 | } |
14 | } | 159 | } |