diff options
author | Bad Diode <bd@badd10de.dev> | 2023-08-30 18:14:25 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-08-30 18:14:25 +0200 |
commit | a1d4e282bc2398e43a085688dd483160c7144f3e (patch) | |
tree | b4d8a58f385be9bf68ae3a7e057226e3405f522e | |
parent | e8fdb17d27a33988fb79c792d69ff15c16a0e59c (diff) | |
download | uxngba-a1d4e282bc2398e43a085688dd483160c7144f3e.tar.gz uxngba-a1d4e282bc2398e43a085688dd483160c7144f3e.zip |
Fix dei behaviour by properly mapping u16 when needed
-rw-r--r-- | src/debug.c | 193 | ||||
-rw-r--r-- | src/main.c | 120 |
2 files changed, 218 insertions, 95 deletions
diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..fd695cb --- /dev/null +++ b/src/debug.c | |||
@@ -0,0 +1,193 @@ | |||
1 | typedef enum DebugFlags { | ||
2 | SHOW_ROM = (1 << 0), | ||
3 | SHOW_WST = (1 << 1), | ||
4 | SHOW_RST = (1 << 2), | ||
5 | SHOW_ZP = (1 << 3), | ||
6 | SHOW_DEV1 = (1 << 4), | ||
7 | SHOW_DEV2 = (1 << 6), | ||
8 | } DebugFlags; | ||
9 | |||
10 | void | ||
11 | print_debug_info(u8 flags) { | ||
12 | if (flags & SHOW_ROM) { | ||
13 | txt_printf("\nROM"); | ||
14 | for (size_t i = 0; i < 128; i++) { | ||
15 | if (i % 8 == 0) { | ||
16 | txt_printf("\n"); | ||
17 | } | ||
18 | txt_printf("%02x ", uxn_ram[i + PAGE_PROGRAM]); | ||
19 | } | ||
20 | txt_printf("\n"); | ||
21 | } | ||
22 | if (flags & SHOW_DEV1) { | ||
23 | txt_printf("\nSYSTEM"); | ||
24 | for (size_t i = 0; i < (0 + 16); i++) { | ||
25 | if (i % 8 == 0) { | ||
26 | txt_printf("\n"); | ||
27 | } | ||
28 | txt_printf(" "); | ||
29 | txt_printf("%02x", device_data[i]); | ||
30 | } | ||
31 | txt_printf("\nCONSOLE"); | ||
32 | for (size_t i = 0x10; i < (0x10 + 16); i++) { | ||
33 | if (i % 8 == 0) { | ||
34 | txt_printf("\n"); | ||
35 | } | ||
36 | txt_printf(" "); | ||
37 | txt_printf("%02x", device_data[i]); | ||
38 | } | ||
39 | txt_printf("\nSCREEN"); | ||
40 | for (size_t i = 0x20; i < (0x20 + 16); i++) { | ||
41 | if (i % 8 == 0) { | ||
42 | txt_printf("\n"); | ||
43 | } | ||
44 | txt_printf(" "); | ||
45 | txt_printf("%02x", device_data[i]); | ||
46 | } | ||
47 | txt_printf("\nCONTROLLER"); | ||
48 | for (size_t i = 0x80; i < (0x80 + 16); i++) { | ||
49 | if (i % 8 == 0) { | ||
50 | txt_printf("\n"); | ||
51 | } | ||
52 | txt_printf(" "); | ||
53 | txt_printf("%02x", device_data[i]); | ||
54 | } | ||
55 | txt_printf("\nMOUSE"); | ||
56 | for (size_t i = 0x90; i < (0x90 + 16); i++) { | ||
57 | if (i % 8 == 0) { | ||
58 | txt_printf("\n"); | ||
59 | } | ||
60 | txt_printf(" "); | ||
61 | txt_printf("%02x", device_data[i]); | ||
62 | } | ||
63 | txt_printf("\nDATETIME"); | ||
64 | for (size_t i = 0xc0; i < (0xc0 + 16); i++) { | ||
65 | if (i % 8 == 0) { | ||
66 | txt_printf("\n"); | ||
67 | } | ||
68 | txt_printf(" "); | ||
69 | txt_printf("%02x", device_data[i]); | ||
70 | } | ||
71 | } | ||
72 | if (flags & SHOW_DEV2) { | ||
73 | txt_printf("\nAUDIO 1"); | ||
74 | for (size_t i = 0x30; i < (0x30 + 16); i++) { | ||
75 | if (i % 8 == 0) { | ||
76 | txt_printf("\n"); | ||
77 | } | ||
78 | txt_printf(" "); | ||
79 | txt_printf("%02x", device_data[i]); | ||
80 | } | ||
81 | txt_printf("\nAUDIO 2"); | ||
82 | for (size_t i = 0x40; i < (0x40 + 16); i++) { | ||
83 | if (i % 8 == 0) { | ||
84 | txt_printf("\n"); | ||
85 | } | ||
86 | txt_printf(" "); | ||
87 | txt_printf("%02x", device_data[i]); | ||
88 | } | ||
89 | txt_printf("\nAUDIO 3"); | ||
90 | for (size_t i = 0x50; i < (0x50 + 16); i++) { | ||
91 | if (i % 8 == 0) { | ||
92 | txt_printf("\n"); | ||
93 | } | ||
94 | txt_printf(" "); | ||
95 | txt_printf("%02x", device_data[i]); | ||
96 | } | ||
97 | txt_printf("\nAUDIO 4"); | ||
98 | for (size_t i = 0x60; i < (0x60 + 16); i++) { | ||
99 | if (i % 8 == 0) { | ||
100 | txt_printf("\n"); | ||
101 | } | ||
102 | txt_printf(" "); | ||
103 | txt_printf("%02x", device_data[i]); | ||
104 | } | ||
105 | txt_printf("\nFILE 1"); | ||
106 | for (size_t i = 0xa0; i < (0xa0 + 16); i++) { | ||
107 | if (i % 8 == 0) { | ||
108 | txt_printf("\n"); | ||
109 | } | ||
110 | txt_printf(" "); | ||
111 | txt_printf("%02x", device_data[i]); | ||
112 | } | ||
113 | txt_printf("\nFILE 2"); | ||
114 | for (size_t i = 0xb0; i < (0xb0 + 16); i++) { | ||
115 | if (i % 8 == 0) { | ||
116 | txt_printf("\n"); | ||
117 | } | ||
118 | txt_printf(" "); | ||
119 | txt_printf("%02x", device_data[i]); | ||
120 | } | ||
121 | } | ||
122 | if (flags & SHOW_WST) { | ||
123 | txt_printf("\nWST ("); | ||
124 | txt_printf("SIZE: %d)", wst_ptr - (uintptr_t)wst); | ||
125 | for (size_t i = 0; i < 128; i++) { | ||
126 | if (i % 8 == 0) { | ||
127 | txt_printf("\n"); | ||
128 | } | ||
129 | if (i >= (wst_ptr - (uintptr_t)wst)) { | ||
130 | txt_printf("%02x ", 0); | ||
131 | } else { | ||
132 | txt_printf("%02x ", wst[i]); | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | if (flags & SHOW_RST) { | ||
137 | txt_printf("RST ("); | ||
138 | txt_printf("SIZE: %d)", rst_ptr - (uintptr_t)rst); | ||
139 | for (size_t i = 0; i < 128; i++) { | ||
140 | if (i % 8 == 0) { | ||
141 | txt_printf("\n"); | ||
142 | } | ||
143 | if (i >= (rst_ptr - (uintptr_t)rst)) { | ||
144 | txt_printf("%02x ", 0); | ||
145 | } else { | ||
146 | txt_printf("%02x ", rst[i]); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | if (flags & SHOW_ZP) { | ||
151 | txt_printf("RAM (ZP)\n"); | ||
152 | for (size_t i = 0; i < 128; i++) { | ||
153 | if (i % 8 == 0) { | ||
154 | txt_printf("\n"); | ||
155 | } | ||
156 | txt_printf("%02x ", uxn_ram[i]); | ||
157 | } | ||
158 | } | ||
159 | txt_printf("\nMOUSE"); | ||
160 | for (size_t i = 0x90; i < (0x90 + 16); i++) { | ||
161 | if (i % 8 == 0) { | ||
162 | txt_printf("\n"); | ||
163 | } | ||
164 | txt_printf(" "); | ||
165 | txt_printf("%02x", device_data[i]); | ||
166 | } | ||
167 | txt_printf("\nRAM (ZP)"); | ||
168 | for (size_t i = 0; i < 32; i++) { | ||
169 | if (i % 8 == 0) { | ||
170 | txt_printf("\n"); | ||
171 | } | ||
172 | if (i % 2 == 0) { | ||
173 | txt_printf(" "); | ||
174 | } | ||
175 | txt_printf("%02x", uxn_ram[i]); | ||
176 | } | ||
177 | txt_printf("\nWST ("); | ||
178 | txt_printf("SIZE: %d)", wst_ptr - (uintptr_t)wst); | ||
179 | for (size_t i = 0; i < 64; i++) { | ||
180 | if (i % 8 == 0) { | ||
181 | txt_printf("\n"); | ||
182 | } | ||
183 | if (i % 2 == 0) { | ||
184 | txt_printf(" "); | ||
185 | } | ||
186 | if (i >= (wst_ptr - (uintptr_t)wst)) { | ||
187 | txt_printf("%02x", 0); | ||
188 | } else { | ||
189 | txt_printf("%02x", wst[i]); | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "profiling.c" | 28 | #include "profiling.c" |
29 | #include "input.c" | 29 | #include "input.c" |
30 | #include "devices.c" | 30 | #include "devices.c" |
31 | #include "debug.c" | ||
31 | 32 | ||
32 | void | 33 | void |
33 | deo_console(u8 *dev, u8 port) { | 34 | deo_console(u8 *dev, u8 port) { |
@@ -45,10 +46,24 @@ deo_console(u8 *dev, u8 port) { | |||
45 | u16 | 46 | u16 |
46 | dei_screen(u8 *dev, u8 port) { | 47 | dei_screen(u8 *dev, u8 port) { |
47 | switch(port) { | 48 | switch(port) { |
48 | case 0x2: return (SCREEN_WIDTH); | 49 | case 0x0: |
49 | case 0x3: return (SCREEN_WIDTH >> 8); | 50 | case 0x8: |
50 | case 0x4: return (SCREEN_HEIGHT); | 51 | case 0xa: |
51 | case 0x5: return (SCREEN_HEIGHT >> 8); | 52 | case 0xc: return PEEK2(dev + port); |
53 | case 0x2: return SCREEN_WIDTH; | ||
54 | case 0x4: return SCREEN_HEIGHT; | ||
55 | default: return dev[port]; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | u16 | ||
60 | dei_mouse(u8 *dev, u8 port) { | ||
61 | switch(port) { | ||
62 | case 0x0: | ||
63 | case 0x2: | ||
64 | case 0x4: | ||
65 | case 0xa: | ||
66 | case 0xc: return PEEK2(dev + port); | ||
52 | default: return dev[port]; | 67 | default: return dev[port]; |
53 | } | 68 | } |
54 | } | 69 | } |
@@ -187,6 +202,7 @@ u16 | |||
187 | dei_stub(u8 *dev, u8 port) { | 202 | dei_stub(u8 *dev, u8 port) { |
188 | (void)dev; | 203 | (void)dev; |
189 | (void)port; | 204 | (void)port; |
205 | return dev[port]; | ||
190 | } | 206 | } |
191 | 207 | ||
192 | void | 208 | void |
@@ -216,96 +232,7 @@ init_uxn() { | |||
216 | deo_map[0x2] = deo_screen; | 232 | deo_map[0x2] = deo_screen; |
217 | dei_map[0x2] = dei_screen; | 233 | dei_map[0x2] = dei_screen; |
218 | dei_map[0xc] = dei_datetime; | 234 | dei_map[0xc] = dei_datetime; |
219 | } | 235 | dei_map[0x9] = dei_mouse; |
220 | |||
221 | typedef enum DebugFlags { | ||
222 | SHOW_ROM = (1 << 0), | ||
223 | SHOW_WST = (1 << 1), | ||
224 | SHOW_RST = (1 << 2), | ||
225 | SHOW_ZP = (1 << 3), | ||
226 | SHOW_DEV = (1 << 4), | ||
227 | SHOW_DEV2 = (1 << 5), | ||
228 | } DebugFlags; | ||
229 | |||
230 | void | ||
231 | print_debug_info(u8 flags) { | ||
232 | if (flags & SHOW_ROM) { | ||
233 | txt_printf("\nROM"); | ||
234 | for (size_t i = 0; i < 128; i++) { | ||
235 | if (i % 8 == 0) { | ||
236 | txt_printf("\n"); | ||
237 | } | ||
238 | txt_printf("%02x ", uxn_ram[i + PAGE_PROGRAM]); | ||
239 | } | ||
240 | txt_printf("\n"); | ||
241 | } | ||
242 | if (flags & SHOW_DEV) { | ||
243 | txt_printf("\nDEV MEM"); | ||
244 | for (size_t i = 0; i < 128; i++) { | ||
245 | if (i % 8 == 0) { | ||
246 | txt_printf("\n"); | ||
247 | } | ||
248 | if (i % 16 == 0) { | ||
249 | txt_printf("|"); | ||
250 | } else { | ||
251 | txt_printf(" "); | ||
252 | } | ||
253 | txt_printf("%02x", device_data[i]); | ||
254 | } | ||
255 | txt_printf("\n"); | ||
256 | } | ||
257 | if (flags & SHOW_DEV2) { | ||
258 | txt_printf("\nDEV MEM"); | ||
259 | for (size_t i = 128; i < 256; i++) { | ||
260 | if (i % 8 == 0) { | ||
261 | txt_printf("\n"); | ||
262 | } | ||
263 | if (i % 16 == 0) { | ||
264 | txt_printf("|"); | ||
265 | } else { | ||
266 | txt_printf(" "); | ||
267 | } | ||
268 | txt_printf("%02x", device_data[i]); | ||
269 | } | ||
270 | txt_printf("\n"); | ||
271 | } | ||
272 | if (flags & SHOW_WST) { | ||
273 | txt_printf("\nWST ("); | ||
274 | txt_printf("SIZE: %d)", wst_ptr - (uintptr_t)wst); | ||
275 | for (size_t i = 0; i < 128; i++) { | ||
276 | if (i % 8 == 0) { | ||
277 | txt_printf("\n"); | ||
278 | } | ||
279 | if (i >= (wst_ptr - (uintptr_t)wst)) { | ||
280 | txt_printf("%02x ", 0); | ||
281 | } else { | ||
282 | txt_printf("%02x ", wst[i]); | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | if (flags & SHOW_RST) { | ||
287 | txt_printf("RST ("); | ||
288 | txt_printf("SIZE: %d)", rst_ptr - (uintptr_t)rst); | ||
289 | for (size_t i = 0; i < 128; i++) { | ||
290 | if (i % 8 == 0) { | ||
291 | txt_printf("\n"); | ||
292 | } | ||
293 | if (i >= (rst_ptr - (uintptr_t)rst)) { | ||
294 | txt_printf("%02x ", 0); | ||
295 | } else { | ||
296 | txt_printf("%02x ", rst[i]); | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | if (flags & SHOW_ZP) { | ||
301 | txt_printf("RAM (ZP)\n"); | ||
302 | for (size_t i = 0; i < 128; i++) { | ||
303 | if (i % 8 == 0) { | ||
304 | txt_printf("\n"); | ||
305 | } | ||
306 | txt_printf("%02x ", uxn_ram[i]); | ||
307 | } | ||
308 | } | ||
309 | } | 236 | } |
310 | 237 | ||
311 | int | 238 | int |
@@ -340,7 +267,10 @@ main(void) { | |||
340 | PROF(uxn_eval_asm(PAGE_PROGRAM), eval_cycles); | 267 | PROF(uxn_eval_asm(PAGE_PROGRAM), eval_cycles); |
341 | while(true) { | 268 | while(true) { |
342 | txt_position(0, 0); | 269 | txt_position(0, 0); |
343 | print_debug_info(SHOW_DEV2); | 270 | // print_debug_info(SHOW_DEV1); |
271 | // print_debug_info(SHOW_DEV2); | ||
272 | // print_debug_info(SHOW_ZP); | ||
273 | // print_debug_info(0); | ||
344 | bios_vblank_wait(); | 274 | bios_vblank_wait(); |
345 | FRAME_START(); | 275 | FRAME_START(); |
346 | PROF(handle_input(), input_cycles); | 276 | PROF(handle_input(), input_cycles); |