diff options
author | Bad Diode <bd@badd10de.dev> | 2023-08-29 09:37:33 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-08-29 09:37:33 +0200 |
commit | 3473765c5bcf2dde8b22998d6dac7a3873c6f7d3 (patch) | |
tree | 3da273d17d91da0e263879fcb73fe4097dfd9109 /src | |
parent | 4c73a0d430651ef416682dc32b9365ed0a17424d (diff) | |
download | uxngba-3473765c5bcf2dde8b22998d6dac7a3873c6f7d3.tar.gz uxngba-3473765c5bcf2dde8b22998d6dac7a3873c6f7d3.zip |
Add div/div2 instructions
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/uxn-core.s | 44 |
2 files changed, 40 insertions, 12 deletions
@@ -60,6 +60,9 @@ init_uxn() { | |||
60 | // 0x80, 0x03, 0x80, 0x04, 0x1a, // #03 #04 MUL -> 0c | 60 | // 0x80, 0x03, 0x80, 0x04, 0x1a, // #03 #04 MUL -> 0c |
61 | // 0xa0, 0x00, 0x03, 0xa0, 0x00, 0x04, 0x3a, // #0003 #0004 MUL2 -> 000c | 61 | // 0xa0, 0x00, 0x03, 0xa0, 0x00, 0x04, 0x3a, // #0003 #0004 MUL2 -> 000c |
62 | // 0xa0, 0x00, 0xff, 0xa0, 0x00, 0x02, 0x3a, // #00ff #0002 MUL2 -> 01fe | 62 | // 0xa0, 0x00, 0xff, 0xa0, 0x00, 0x02, 0x3a, // #00ff #0002 MUL2 -> 01fe |
63 | // DIV test. | ||
64 | 0x80, 0x08, 0x80, 0x04, 0x1b, // #08 #04 DIV -> 02 | ||
65 | 0xa0, 0x00, 0x08, 0xa0, 0x00, 0x04, 0x3b, // #0008 #0004 DIV2 -> 0002 | ||
63 | // // INC test. | 66 | // // INC test. |
64 | // 0x80, 0x09, 0x01, // #09 INC -> 0a | 67 | // 0x80, 0x09, 0x01, // #09 INC -> 0a |
65 | // 0xa0, 0x00, 0x09, 0x21, // #0009 INC2 -> 000a | 68 | // 0xa0, 0x00, 0x09, 0x21, // #0009 INC2 -> 000a |
@@ -148,15 +151,14 @@ init_uxn() { | |||
148 | // 0xa0, 0xab, 0xcd, 0x80, 0x00, 0xa0, 0x01, 0x15, 0x2d, 0x04, 0x02, | 151 | // 0xa0, 0xab, 0xcd, 0x80, 0x00, 0xa0, 0x01, 0x15, 0x2d, 0x04, 0x02, |
149 | // JSR | 152 | // JSR |
150 | // 0x80, 0x03, 0x0e, 0x80, 0x01, 0x00, 0x80, 0x02, 0x6c, | 153 | // 0x80, 0x03, 0x0e, 0x80, 0x01, 0x00, 0x80, 0x02, 0x6c, |
151 | 0x80, 0x03, 0x0e, 0x80, 0x01, 0x00, 0x80, 0x02, 0x6c, | 154 | // 0x80, 0x03, 0x0e, 0x80, 0x01, 0x00, 0x80, 0x02, 0x6c, |
152 | }; | 155 | }; |
153 | memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); | 156 | memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); |
154 | } | 157 | } |
155 | 158 | ||
156 | // TODO: | 159 | // TODO: |
157 | // - Division | ||
158 | // - DEI/DEO | 160 | // - DEI/DEO |
159 | // - Jump instructions (JMP/JCN/JCI/JMI/JSI/JSR) | 161 | // - Jump instructions (JCI/JMI/JSI) |
160 | // - OPr modes | 162 | // - OPr modes |
161 | // - OPk modes | 163 | // - OPk modes |
162 | // - OPrk modes | 164 | // - OPrk modes |
diff --git a/src/uxn-core.s b/src/uxn-core.s index 99c5b1c..ec7537f 100644 --- a/src/uxn-core.s +++ b/src/uxn-core.s | |||
@@ -179,7 +179,7 @@ op_table: | |||
179 | .word ora @ 0x1d | 179 | .word ora @ 0x1d |
180 | .word eor @ 0x1e | 180 | .word eor @ 0x1e |
181 | .word sft @ 0x1f | 181 | .word sft @ 0x1f |
182 | .word brk @ 0x20 | 182 | .word jci @ 0x20 |
183 | .word inc2 @ 0x21 | 183 | .word inc2 @ 0x21 |
184 | .word pop2 @ 0x22 | 184 | .word pop2 @ 0x22 |
185 | .word nip2 @ 0x23 | 185 | .word nip2 @ 0x23 |
@@ -211,8 +211,7 @@ op_table: | |||
211 | .word ora2 @ 0x3d | 211 | .word ora2 @ 0x3d |
212 | .word eor2 @ 0x3e | 212 | .word eor2 @ 0x3e |
213 | .word sft2 @ 0x3f | 213 | .word sft2 @ 0x3f |
214 | @ TODO: Can we mask this instead of having empty space? | 214 | .word jmi @ 0x40 |
215 | .word brk @ 0x40 | ||
216 | .word brk @ 0x41 | 215 | .word brk @ 0x41 |
217 | .word brk @ 0x42 | 216 | .word brk @ 0x42 |
218 | .word brk @ 0x43 | 217 | .word brk @ 0x43 |
@@ -244,7 +243,7 @@ op_table: | |||
244 | .word brk @ 0x5d | 243 | .word brk @ 0x5d |
245 | .word brk @ 0x5e | 244 | .word brk @ 0x5e |
246 | .word brk @ 0x5f | 245 | .word brk @ 0x5f |
247 | .word brk @ 0x60 | 246 | .word jsi @ 0x60 |
248 | .word brk @ 0x61 | 247 | .word brk @ 0x61 |
249 | .word brk @ 0x62 | 248 | .word brk @ 0x62 |
250 | .word brk @ 0x63 | 249 | .word brk @ 0x63 |
@@ -340,7 +339,7 @@ op_table: | |||
340 | .word brk @ 0xbd | 339 | .word brk @ 0xbd |
341 | .word brk @ 0xbe | 340 | .word brk @ 0xbe |
342 | .word brk @ 0xbf | 341 | .word brk @ 0xbf |
343 | .word brk @ 0xc0 | 342 | .word litr @ 0xc0 |
344 | .word brk @ 0xc1 | 343 | .word brk @ 0xc1 |
345 | .word brk @ 0xc2 | 344 | .word brk @ 0xc2 |
346 | .word brk @ 0xc3 | 345 | .word brk @ 0xc3 |
@@ -372,7 +371,7 @@ op_table: | |||
372 | .word brk @ 0xdd | 371 | .word brk @ 0xdd |
373 | .word brk @ 0xde | 372 | .word brk @ 0xde |
374 | .word brk @ 0xdf | 373 | .word brk @ 0xdf |
375 | .word brk @ 0xe0 | 374 | .word lit2r @ 0xe0 |
376 | .word brk @ 0xe1 | 375 | .word brk @ 0xe1 |
377 | .word brk @ 0xe2 | 376 | .word brk @ 0xe2 |
378 | .word brk @ 0xe3 | 377 | .word brk @ 0xe3 |
@@ -397,7 +396,6 @@ op_table: | |||
397 | .word brk @ 0xf6 | 396 | .word brk @ 0xf6 |
398 | .word brk @ 0xf7 | 397 | .word brk @ 0xf7 |
399 | .word brk @ 0xf8 | 398 | .word brk @ 0xf8 |
400 | @ TODO: Can we mask this instead of having empty space? | ||
401 | .word lit2 @ 0xf9 | 399 | .word lit2 @ 0xf9 |
402 | .word lit @ 0xfa | 400 | .word lit @ 0xfa |
403 | .word lit2 @ 0xfb | 401 | .word lit2 @ 0xfb |
@@ -439,6 +437,18 @@ lit2: | |||
439 | wpush8 r4 | 437 | wpush8 r4 |
440 | b uxn_decode | 438 | b uxn_decode |
441 | 439 | ||
440 | litr: | ||
441 | next r3 | ||
442 | rpush8 r3 | ||
443 | b uxn_decode | ||
444 | |||
445 | lit2r: | ||
446 | next r3 | ||
447 | next r4 | ||
448 | rpush8 r3 | ||
449 | rpush8 r4 | ||
450 | b uxn_decode | ||
451 | |||
442 | inc: | 452 | inc: |
443 | wpop8 r3 | 453 | wpop8 r3 |
444 | add r3, #1 | 454 | add r3, #1 |
@@ -786,11 +796,27 @@ mul2: | |||
786 | b uxn_decode | 796 | b uxn_decode |
787 | 797 | ||
788 | div: | 798 | div: |
789 | @ TODO: Implement using ____aeabi_uidiv_from_thumb | 799 | wpop8 r3 |
800 | wpop8 r4 | ||
801 | push {r0, r1, r2, r7, lr} | ||
802 | mov r1, r3 | ||
803 | mov r0, r4 | ||
804 | bl __aeabi_uidiv | ||
805 | mov r3, r0 | ||
806 | pop {r0, r1, r2, r7, lr} | ||
807 | wpush8 r3 | ||
790 | b uxn_decode | 808 | b uxn_decode |
791 | 809 | ||
792 | div2: | 810 | div2: |
793 | @ TODO: Implement using ____aeabi_uidiv_from_thumb | 811 | wpop16 r3, r5 |
812 | wpop16 r4, r5 | ||
813 | push {r0, r1, r2, r7, lr} | ||
814 | mov r1, r3 | ||
815 | mov r0, r4 | ||
816 | bl __aeabi_uidiv | ||
817 | mov r3, r0 | ||
818 | pop {r0, r1, r2, r7, lr} | ||
819 | wpush16 r3 | ||
794 | b uxn_decode | 820 | b uxn_decode |
795 | 821 | ||
796 | and: | 822 | and: |