diff options
author | Bad Diode <bd@badd10de.dev> | 2023-08-28 12:15:25 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-08-28 12:15:25 +0200 |
commit | 95ad808ef8ea804ed778719606781ba35bfe7a6f (patch) | |
tree | 277bf6960f5388c74a96506fa91b3eb3eb309268 | |
parent | 8357708a6f73401886bc2bdf405cb19adf419cbc (diff) | |
download | uxngba-95ad808ef8ea804ed778719606781ba35bfe7a6f.tar.gz uxngba-95ad808ef8ea804ed778719606781ba35bfe7a6f.zip |
Add multiply instructions
-rw-r--r-- | src/main.c | 60 | ||||
-rw-r--r-- | src/uxn-core.s | 17 |
2 files changed, 35 insertions, 42 deletions
@@ -26,8 +26,6 @@ | |||
26 | #include "profiling.c" | 26 | #include "profiling.c" |
27 | #include "devices.c" | 27 | #include "devices.c" |
28 | 28 | ||
29 | #define STACK_SIZE 16 | ||
30 | u8 stack[STACK_SIZE] = {0}; | ||
31 | extern void uxn_eval_asm(u16 pc); | 29 | extern void uxn_eval_asm(u16 pc); |
32 | 30 | ||
33 | // TODO: This should be on the IWRAM for maximum speed, as these are operations | 31 | // TODO: This should be on the IWRAM for maximum speed, as these are operations |
@@ -39,7 +37,7 @@ extern uintptr_t wst_ptr; | |||
39 | extern uintptr_t rst_ptr; | 37 | extern uintptr_t rst_ptr; |
40 | 38 | ||
41 | EWRAM_BSS | 39 | EWRAM_BSS |
42 | u8 uxn_ram[KB(64) * 2]; | 40 | u8 uxn_ram[KB(64)]; |
43 | 41 | ||
44 | void | 42 | void |
45 | init_uxn() { | 43 | init_uxn() { |
@@ -49,39 +47,18 @@ init_uxn() { | |||
49 | // uxn_boot(u, uxn_ram, uxn_dei, uxn_deo); | 47 | // uxn_boot(u, uxn_ram, uxn_dei, uxn_deo); |
50 | 48 | ||
51 | // Copy rom to VM. | 49 | // Copy rom to VM. |
52 | u8 uxn_rom[32] = { | 50 | u8 uxn_rom[] = { |
53 | // Hello world (h) | ||
54 | // 0x80, 0x68, 0x80, 0x18, 0x17, | ||
55 | // | 51 | // |
56 | // ADD test | 52 | // ADD test. |
57 | // 0x80, 0x04, 0x80, 0x03, 0x80, 0x02, 0x80, 0x01, 0x18, 0x18 | 53 | 0x80, 0x04, 0x80, 0x08, 0x18, // #04 #08 ADD -> 0c |
58 | // SUB test | 54 | 0xa0, 0x00, 0x04, 0xa0, 0x00, 0x08, 0x38, // #0004 #0008 ADD2 -> 000c |
59 | // 0x80, 0x04, 0x80, 0x03, 0x80, 0x02, 0x80, 0x01, 0x19, 0x19, 0x19 | 55 | // SUB test. |
60 | // LIT2 04 03 LIT2 02 01 ADD ADD ADD BRK | 56 | 0x80, 0x08, 0x80, 0x03, 0x19, // #08 #03 ADD -> 05 |
61 | // 0xa0, 0x04, 0x03, | 57 | 0xa0, 0x00, 0x08, 0xa0, 0x00, 0x03, 0x39, // #0008 #0003 ADD2 -> 0005 |
62 | // 0xa0, 0x04, 0x03, 0xa0, 0x02, 0x01, | 58 | // MUL test. |
63 | // 0xa0, 0x04, 0x03, 0xa0, 0x02, 0x01, 0x18, 0x18, 0x00 | 59 | 0x80, 0x03, 0x80, 0x04, 0x1a, // #03 #04 MUL -> 0c |
64 | // #0004 #0008 ADD | 60 | 0xa0, 0x00, 0x03, 0xa0, 0x00, 0x04, 0x3a, // #0003 #0004 MUL2 -> 000c |
65 | // 0xa0, 0x00, 0x04, 0xa0, 0x00, 0x08, 0x18, | 61 | 0xa0, 0x00, 0xff, 0xa0, 0x00, 0x02, 0x3a, // #00ff #0002 MUL2 -> 01fe |
66 | // #0004 #0008 ADD2 | ||
67 | // 0x80, 0xFF, 0xff, | ||
68 | // 0xa0, 0x00, 0x08, 0xa0, 0x00, 0x04, 0x38, | ||
69 | // 0xa0, 0x00, 0x08, 0xa0, 0x00, 0x04, 0x38, | ||
70 | // 0xa0, 0x00, 0x08, 0xa0, 0x00, 0x03, 0x39, | ||
71 | // 0xa0, 0x00, 0x01, 0x38, | ||
72 | // | ||
73 | // 0x80, 0xFF, 0xff, | ||
74 | // 0xa0, 0xba, 0xdd, | ||
75 | // 0xa0, 0x10, 0xde, | ||
76 | // 0xa0, 0xfe, 0xed, | ||
77 | // 0xa0, 0xde, 0xaf, | ||
78 | // 0xa0, 0xba, 0xdd, | ||
79 | // 0xa0, 0x10, 0xde, | ||
80 | // 0xa0, 0xfe, 0xed, | ||
81 | // 0xa0, 0xde, 0xaf, | ||
82 | // | ||
83 | // #0008 #0003 SUB2 | ||
84 | // 0xa0, 0x00, 0x08, 0xa0, 0x00, 0x03, | ||
85 | }; | 62 | }; |
86 | memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); | 63 | memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); |
87 | } | 64 | } |
@@ -127,8 +104,8 @@ main(void) { | |||
127 | io_ports[i] = 0; | 104 | io_ports[i] = 0; |
128 | } | 105 | } |
129 | 106 | ||
130 | txt_printf("ROM\n\n"); | 107 | txt_printf("ROM"); |
131 | for (size_t i = 0; i < 32; i++) { | 108 | for (size_t i = 0; i < 64; i++) { |
132 | if (i % 8 == 0) { | 109 | if (i % 8 == 0) { |
133 | txt_printf("\n"); | 110 | txt_printf("\n"); |
134 | } | 111 | } |
@@ -137,17 +114,16 @@ main(void) { | |||
137 | txt_printf("\n\n"); | 114 | txt_printf("\n\n"); |
138 | 115 | ||
139 | uxn_eval_asm(PAGE_PROGRAM); | 116 | uxn_eval_asm(PAGE_PROGRAM); |
140 | txt_printf("STACK\n"); | 117 | txt_printf("STACK ("); |
141 | txt_printf("PTR: %d\n", wst_ptr - (uintptr_t)wst); | 118 | txt_printf("PTR: %d)", wst_ptr - (uintptr_t)wst); |
142 | for (size_t i = 0; i < STACK_SIZE; i++) { | 119 | for (size_t i = 0; i < 64; i++) { |
143 | if (i % 8 == 0) { | 120 | if (i % 8 == 0) { |
144 | txt_printf("\n"); | 121 | txt_printf("\n"); |
145 | } | 122 | } |
146 | txt_printf("%02x ", wst[i]); | 123 | txt_printf("%02x ", wst[i]); |
147 | } | 124 | } |
148 | 125 | ||
149 | uintptr_t stack_base = wst; | 126 | uintptr_t stack_size = wst_ptr - (uintptr_t)wst; |
150 | uintptr_t stack_size = wst_ptr - stack_base; | ||
151 | while(true) { | 127 | while(true) { |
152 | txt_position(0,0); | 128 | txt_position(0,0); |
153 | // bios_vblank_wait(); | 129 | // bios_vblank_wait(); |
diff --git a/src/uxn-core.s b/src/uxn-core.s index 32ec26b..e35707f 100644 --- a/src/uxn-core.s +++ b/src/uxn-core.s | |||
@@ -257,15 +257,32 @@ sub2: | |||
257 | b uxn_decode | 257 | b uxn_decode |
258 | 258 | ||
259 | mul: | 259 | mul: |
260 | ldr r3, [r1, #-1]! | ||
261 | ldr r4, [r1, #-1]! | ||
262 | mul r4, r3, r4 | ||
263 | strb r4, [r1], #1 | ||
260 | b uxn_decode | 264 | b uxn_decode |
261 | 265 | ||
262 | mul2: | 266 | mul2: |
267 | ldrb r3, [r1, #-1]! | ||
268 | ldrb r5, [r1, #-1]! | ||
269 | orr r3, r5, r3, lsl #8 | ||
270 | ldrb r4, [r1, #-1]! | ||
271 | ldrb r5, [r1, #-1]! | ||
272 | orr r4, r5, r4, lsl #8 | ||
273 | mul r5, r3, r4 | ||
274 | lsr r3, r5, #24 | ||
275 | strb r3, [r1], #1 | ||
276 | lsr r5, #16 | ||
277 | strb r5, [r1], #1 | ||
263 | b uxn_decode | 278 | b uxn_decode |
264 | 279 | ||
265 | div: | 280 | div: |
281 | @ TODO: Implement using ____aeabi_uidiv_from_thumb | ||
266 | b uxn_decode | 282 | b uxn_decode |
267 | 283 | ||
268 | div2: | 284 | div2: |
285 | @ TODO: Implement using ____aeabi_uidiv_from_thumb | ||
269 | b uxn_decode | 286 | b uxn_decode |
270 | 287 | ||
271 | and: | 288 | and: |