aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-08-31 09:24:29 +0200
committerBad Diode <bd@badd10de.dev>2023-08-31 09:24:29 +0200
commitea85184fdadf08760aa8f88871f96ddf8dde2914 (patch)
tree7cefaf976881d3d4a1035e2213689dfb982b8f88
parent7a02b549a38dadb48c43143ff94c9094abf25555 (diff)
downloaduxngba-ea85184fdadf08760aa8f88871f96ddf8dde2914.tar.gz
uxngba-ea85184fdadf08760aa8f88871f96ddf8dde2914.zip
Fix dup(2kr) and ovr(2kr) behaviour
-rw-r--r--src/config.c2
-rw-r--r--src/debug.c67
-rw-r--r--src/devices.c12
-rw-r--r--src/input.c4
-rw-r--r--src/main.c9
-rw-r--r--src/uxn-core.s24
6 files changed, 79 insertions, 39 deletions
diff --git a/src/config.c b/src/config.c
index d100233..9879ef1 100644
--- a/src/config.c
+++ b/src/config.c
@@ -9,3 +9,5 @@
9#endif 9#endif
10 10
11#define PROF_ENABLE 0 11#define PROF_ENABLE 0
12#define TEXT_DISABLE 0
13#define SOUND_DISABLE 0
diff --git a/src/debug.c b/src/debug.c
index fd695cb..17c1c73 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -156,37 +156,46 @@ print_debug_info(u8 flags) {
156 txt_printf("%02x ", uxn_ram[i]); 156 txt_printf("%02x ", uxn_ram[i]);
157 } 157 }
158 } 158 }
159 txt_printf("\nMOUSE"); 159 if (flags == 0) {
160 for (size_t i = 0x90; i < (0x90 + 16); i++) { 160 txt_printf("\nRAM (ZP)");
161 if (i % 8 == 0) { 161 for (size_t i = 0; i < 32; i++) {
162 txt_printf("\n"); 162 if (i % 8 == 0) {
163 } 163 txt_printf("\n");
164 txt_printf(" "); 164 }
165 txt_printf("%02x", device_data[i]); 165 if (i % 2 == 0) {
166 } 166 txt_printf(" ");
167 txt_printf("\nRAM (ZP)"); 167 }
168 for (size_t i = 0; i < 32; i++) { 168 txt_printf("%02x", uxn_ram[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 } 169 }
183 if (i % 2 == 0) { 170 txt_printf("\nWST (");
184 txt_printf(" "); 171 txt_printf("SIZE: %d)", wst_ptr - (uintptr_t)wst);
172 for (size_t i = 0; i < 32; i++) {
173 if (i % 8 == 0) {
174 txt_printf("\n");
175 }
176 if (i % 2 == 0) {
177 txt_printf(" ");
178 }
179 if (i >= (wst_ptr - (uintptr_t)wst)) {
180 txt_printf("%02x", 0);
181 } else {
182 txt_printf("%02x", wst[i]);
183 }
185 } 184 }
186 if (i >= (wst_ptr - (uintptr_t)wst)) { 185 txt_printf("\nRST (");
187 txt_printf("%02x", 0); 186 txt_printf("SIZE: %d)", rst_ptr - (uintptr_t)rst);
188 } else { 187 for (size_t i = 0; i < 32; i++) {
189 txt_printf("%02x", wst[i]); 188 if (i % 8 == 0) {
189 txt_printf("\n");
190 }
191 if (i % 2 == 0) {
192 txt_printf(" ");
193 }
194 if (i >= (rst_ptr - (uintptr_t)rst)) {
195 txt_printf("%02x", 0);
196 } else {
197 txt_printf("%02x", rst[i]);
198 }
190 } 199 }
191 } 200 }
192} 201}
diff --git a/src/devices.c b/src/devices.c
index c65d79b..2146bd3 100644
--- a/src/devices.c
+++ b/src/devices.c
@@ -109,16 +109,18 @@ void
109deo_system(u8 *dev, u8 port) { 109deo_system(u8 *dev, u8 port) {
110 switch(port) { 110 switch(port) {
111 case 0x3: { 111 case 0x3: {
112 // TODO: Rom bank switching (Needs testing). 112 // Rom bank switching (Needs testing).
113 u16 addr = PEEK2(dev + 0x2); 113 u16 addr = PEEK2(dev + 0x2);
114 if(uxn_ram[addr] == 0x01) { 114 if(uxn_ram[addr] == 0x01) {
115 u16 i, length = PEEK2(uxn_ram + addr + 1); 115 u16 length = PEEK2(uxn_ram + addr + 1);
116 u16 a_page = PEEK2(uxn_ram + addr + 1 + 2); 116 u16 a_page = PEEK2(uxn_ram + addr + 1 + 2);
117 u16 a_addr = PEEK2(uxn_ram + addr + 1 + 4); 117 u16 a_addr = PEEK2(uxn_ram + addr + 1 + 4);
118 u16 b_page = PEEK2(uxn_ram + addr + 1 + 6);
118 u16 b_addr = PEEK2(uxn_ram + addr + 1 + 8); 119 u16 b_addr = PEEK2(uxn_ram + addr + 1 + 8);
120 u8 *ram = uxn_ram;
119 u8 *rom = uxn_rom + (a_page % RAM_PAGES) * 0x10000; 121 u8 *rom = uxn_rom + (a_page % RAM_PAGES) * 0x10000;
120 for(i = 0; i < length; i++) { 122 for(size_t i = 0; i < length; i++) {
121 uxn_ram[(u16)(b_addr + i)] = rom[(u16)(a_addr + i)]; 123 ram[b_addr + i] = rom[a_addr + i];
122 } 124 }
123 } 125 }
124 } break; 126 } break;
@@ -177,8 +179,8 @@ dei_datetime(u8 *dev, u8 port) {
177 case 0x8: return t->tm_yday; 179 case 0x8: return t->tm_yday;
178 case 0x9: return t->tm_yday >> 8; 180 case 0x9: return t->tm_yday >> 8;
179 case 0xa: return t->tm_isdst; 181 case 0xa: return t->tm_isdst;
180 default: return dev[port];
181 } 182 }
183 return dev[port];
182} 184}
183 185
184u16 186u16
diff --git a/src/input.c b/src/input.c
index 689479e..c78864d 100644
--- a/src/input.c
+++ b/src/input.c
@@ -5,9 +5,7 @@ typedef enum {
5} ControlMethod; 5} ControlMethod;
6 6
7const ControlMethod ctrl_methods[] = { 7const ControlMethod ctrl_methods[] = {
8 CONTROL_CONTROLLER, 8 CONTROL_METHODS
9 CONTROL_MOUSE,
10 CONTROL_KEYBOARD,
11}; 9};
12static ControlMethod ctrl_idx = 0; 10static ControlMethod ctrl_idx = 0;
13 11
diff --git a/src/main.c b/src/main.c
index 13a32c7..f296498 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,7 +36,8 @@ init_uxn() {
36 dma_fill(uxn_ram, fill, sizeof(uxn_ram), 3); 36 dma_fill(uxn_ram, fill, sizeof(uxn_ram), 3);
37 uxn_rom = _binary_build_uxn_rom_start; 37 uxn_rom = _binary_build_uxn_rom_start;
38 uxn_rom_size = (size_t)_binary_build_uxn_rom_size; 38 uxn_rom_size = (size_t)_binary_build_uxn_rom_size;
39 memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, uxn_rom_size); 39 size_t size = MIN(0x10000 - PAGE_PROGRAM, uxn_rom_size);
40 memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, size);
40 41
41 // Initialize stack and device memory. 42 // Initialize stack and device memory.
42 for (size_t i = 0; i < 256; i++) { 43 for (size_t i = 0; i < 256; i++) {
@@ -70,6 +71,7 @@ init_uxn() {
70 dei_map[0xc] = (uintptr_t) dei_datetime; 71 dei_map[0xc] = (uintptr_t) dei_datetime;
71 dei_map[0x9] = (uintptr_t) dei_mouse; 72 dei_map[0x9] = (uintptr_t) dei_mouse;
72} 73}
74
73int 75int
74main(void) { 76main(void) {
75 // Adjust system wait times. 77 // Adjust system wait times.
@@ -86,7 +88,7 @@ main(void) {
86 video_init(); 88 video_init();
87 89
88 // Initialize text engine. 90 // Initialize text engine.
89#ifndef TEXT_DISABLE 91#if !defined(TEXT_DISABLE) || TEXT_DISABLE == 0
90 txt_init(1, TEXT_LAYER); 92 txt_init(1, TEXT_LAYER);
91 txt_position(0,0); 93 txt_position(0,0);
92#endif 94#endif
@@ -95,13 +97,16 @@ main(void) {
95 init_uxn(); 97 init_uxn();
96 98
97 // Enable sound. 99 // Enable sound.
100#if !defined(SOUND_DISABLE) || SOUND_DISABLE == 0
98 init_sound(); 101 init_sound();
102#endif
99 103
100 // Main loop. 104 // Main loop.
101 u8 frame_counter = 0; 105 u8 frame_counter = 0;
102 PROF(uxn_eval_asm(PAGE_PROGRAM), eval_cycles); 106 PROF(uxn_eval_asm(PAGE_PROGRAM), eval_cycles);
103 while(true) { 107 while(true) {
104 txt_position(0, 0); 108 txt_position(0, 0);
109 // print_debug_info(0);
105 bios_vblank_wait(); 110 bios_vblank_wait();
106 FRAME_START(); 111 FRAME_START();
107 PROF(handle_input(), input_cycles); 112 PROF(handle_input(), input_cycles);
diff --git a/src/uxn-core.s b/src/uxn-core.s
index 7d73b18..255bb99 100644
--- a/src/uxn-core.s
+++ b/src/uxn-core.s
@@ -1922,6 +1922,7 @@ rot2k:
1922dupk: 1922dupk:
1923 wpeek8 r3, #-1 1923 wpeek8 r3, #-1
1924 wpush8 r3 1924 wpush8 r3
1925 wpush8 r3
1925 b uxn_decode 1926 b uxn_decode
1926 1927
1927dup2k: 1928dup2k:
@@ -1929,16 +1930,27 @@ dup2k:
1929 wpeek8 r4, #-1 1930 wpeek8 r4, #-1
1930 wpush8 r3 1931 wpush8 r3
1931 wpush8 r4 1932 wpush8 r4
1933 wpush8 r3
1934 wpush8 r4
1932 b uxn_decode 1935 b uxn_decode
1933 1936
1934ovrk: 1937ovrk:
1935 wpeek8 r3, #-2 1938 wpeek8 r3, #-2
1939 wpeek8 r4, #-1
1940 wpush8 r3
1941 wpush8 r4
1936 wpush8 r3 1942 wpush8 r3
1937 b uxn_decode 1943 b uxn_decode
1938 1944
1939ovr2k: 1945ovr2k:
1940 wpeek8 r3, #-4 1946 wpeek8 r3, #-4
1941 wpeek8 r4, #-3 1947 wpeek8 r4, #-3
1948 wpeek8 r5, #-2
1949 wpeek8 r6, #-1
1950 wpush8 r3
1951 wpush8 r4
1952 wpush8 r5
1953 wpush8 r6
1942 wpush8 r3 1954 wpush8 r3
1943 wpush8 r4 1955 wpush8 r4
1944 b uxn_decode 1956 b uxn_decode
@@ -2342,6 +2354,7 @@ rot2kr:
2342dupkr: 2354dupkr:
2343 rpeek8 r3, #-1 2355 rpeek8 r3, #-1
2344 rpush8 r3 2356 rpush8 r3
2357 rpush8 r3
2345 b uxn_decode 2358 b uxn_decode
2346 2359
2347dup2kr: 2360dup2kr:
@@ -2349,16 +2362,27 @@ dup2kr:
2349 rpeek8 r4, #-1 2362 rpeek8 r4, #-1
2350 rpush8 r3 2363 rpush8 r3
2351 rpush8 r4 2364 rpush8 r4
2365 rpush8 r3
2366 rpush8 r4
2352 b uxn_decode 2367 b uxn_decode
2353 2368
2354ovrkr: 2369ovrkr:
2355 rpeek8 r3, #-2 2370 rpeek8 r3, #-2
2371 rpeek8 r4, #-1
2372 rpush8 r3
2373 rpush8 r4
2356 rpush8 r3 2374 rpush8 r3
2357 b uxn_decode 2375 b uxn_decode
2358 2376
2359ovr2kr: 2377ovr2kr:
2360 rpeek8 r3, #-4 2378 rpeek8 r3, #-4
2361 rpeek8 r4, #-3 2379 rpeek8 r4, #-3
2380 rpeek8 r5, #-2
2381 rpeek8 r6, #-1
2382 rpush8 r3
2383 rpush8 r4
2384 rpush8 r5
2385 rpush8 r6
2362 rpush8 r3 2386 rpush8 r3
2363 rpush8 r4 2387 rpush8 r4
2364 b uxn_decode 2388 b uxn_decode