aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-08-29 16:41:13 +0200
committerBad Diode <bd@badd10de.dev>2023-08-29 16:41:13 +0200
commit19776f5720806bef0f4c6d1439f76da80603f054 (patch)
tree890f6f4235a8963bd0f1d63b78c6ae464a7f5e2b
parent50a369576e85c8ff6187ca808101a9008690be15 (diff)
downloaduxngba-19776f5720806bef0f4c6d1439f76da80603f054.tar.gz
uxngba-19776f5720806bef0f4c6d1439f76da80603f054.zip
Add dei functions
-rw-r--r--src/main.c121
-rw-r--r--src/uxn-core.s269
2 files changed, 218 insertions, 172 deletions
diff --git a/src/main.c b/src/main.c
index 21313a3..8ea0106 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,29 +28,33 @@
28 28
29extern void uxn_eval_asm(u16 pc); 29extern void uxn_eval_asm(u16 pc);
30 30
31// TODO: This should be on the IWRAM for maximum speed, as these are operations 31// Stacks (On IWRAM).
32// we will use very often.
33extern u8 wst[256]; 32extern u8 wst[256];
34extern u8 rst[256]; 33extern u8 rst[256];
35extern uintptr_t deo_map[16];
36extern uintptr_t dei_map[16];
37extern uintptr_t wst_ptr; 34extern uintptr_t wst_ptr;
38extern uintptr_t rst_ptr; 35extern uintptr_t rst_ptr;
39extern u8 device_0[16]; 36
40extern u8 device_1[16]; 37// DEO/DEI mapping functiosn and device data (On IWRAM).
41extern u8 device_2[16]; 38extern uintptr_t deo_map[16];
42extern u8 device_3[16]; 39extern uintptr_t dei_map[16];
43extern u8 device_4[16]; 40extern u8 device_data[256];
44extern u8 device_5[16]; 41
45extern u8 device_6[16]; 42// DEBUG: ONLY
46extern u8 device_7[16]; 43// extern u8 device_0[16];
47extern u8 device_8[16]; 44// extern u8 device_1[16];
48extern u8 device_a[16]; 45// extern u8 device_2[16];
49extern u8 device_b[16]; 46// extern u8 device_3[16];
50extern u8 device_c[16]; 47// extern u8 device_4[16];
51extern u8 device_d[16]; 48// extern u8 device_5[16];
52extern u8 device_e[16]; 49// extern u8 device_6[16];
53extern u8 device_f[16]; 50// extern u8 device_7[16];
51// extern u8 device_8[16];
52// extern u8 device_a[16];
53// extern u8 device_b[16];
54// extern u8 device_c[16];
55// extern u8 device_d[16];
56// extern u8 device_e[16];
57// extern u8 device_f[16];
54 58
55EWRAM_BSS 59EWRAM_BSS
56u8 uxn_ram[KB(64)]; 60u8 uxn_ram[KB(64)];
@@ -66,14 +70,18 @@ deo_console(u8 *dev, u8 port) {
66 txt_putc(dev[port]); 70 txt_putc(dev[port]);
67 return; 71 return;
68 } 72 }
69 txt_printf("\n");
70} 73}
71 74
72void 75void
73stub_c(u8 port, u16 val) { 76deo_stub(u8 *dev, u8 port) {
77 (void)dev;
78 (void)port;
79}
80
81u16
82dei_stub(u8 *dev, u8 port) {
83 (void)dev;
74 (void)port; 84 (void)port;
75 (void)val;
76 txt_printf("c");
77} 85}
78 86
79void 87void
@@ -203,15 +211,30 @@ init_uxn() {
203 0x6c, 0x80, 0x18, 0x17, 0x80, 0x6f, 0x80, 0x18, 0x17, 0x80, 0x0a, 0x80, 0x18, 0x17, 211 0x6c, 0x80, 0x18, 0x17, 0x80, 0x6f, 0x80, 0x18, 0x17, 0x80, 0x0a, 0x80, 0x18, 0x17,
204 // 0xa0, 0x00, 0x68, 0x80, 0x18, 0x37, 0x80, 0x65, 0x80, 0x18, 0x17, 0x80, 0x6c, 0x80, 0x18, 0x17, 0x80, 212 // 0xa0, 0x00, 0x68, 0x80, 0x18, 0x37, 0x80, 0x65, 0x80, 0x18, 0x17, 0x80, 0x6c, 0x80, 0x18, 0x17, 0x80,
205 // 0x6c, 0x80, 0x18, 0x17, 0x80, 0x6f, 0x80, 0x18, 0x17, 0x80, 0x0a, 0x80, 0x18, 0x17, 213 // 0x6c, 0x80, 0x18, 0x17, 0x80, 0x6f, 0x80, 0x18, 0x17, 0x80, 0x0a, 0x80, 0x18, 0x17,
214 // 0xa0, 0x2c, 0xe9, 0x80, 0x08, 0x37,
206 }; 215 };
207 memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); 216 memcpy(uxn_ram + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom));
217
218 // Initialize stack and device memory.
219 for (size_t i = 0; i < 256; i++) {
220 wst[i] = 0;
221 rst[i] = 0;
222 device_data[i] = 0;
223 }
224
225 // Setup deo/dei maps.
226 for (size_t i = 0; i < 16; i++) {
227 deo_map[i] = deo_stub;
228 dei_map[i] = dei_stub;
229 }
230 deo_map[1] = deo_console;
208} 231}
209 232
210// TODO: 233// TODO:
211// - DEI/DEO
212// - OPr modes 234// - OPr modes
213// - OPk modes 235// - OPk modes
214// - OPrk modes 236// - OPrk modes
237// - Test DEI functions
215 238
216int 239int
217main(void) { 240main(void) {
@@ -246,41 +269,33 @@ main(void) {
246 // NOTE: A VBLANK is 83776 cycles, anything other than that will make it so 269 // NOTE: A VBLANK is 83776 cycles, anything other than that will make it so
247 // we fail to render at 60FPS. 270 // we fail to render at 60FPS.
248 271
249 // TODO: Initialize memory.
250 // Initialize stack.
251 for (size_t i = 0; i < 256; i++) {
252 wst[i] = 0;
253 rst[i] = 0;
254 // TODO: Init device memory.
255 }
256 // TODO: ... 272 // TODO: ...
257 deo_map[1] = deo_console;
258 // TODO: ... 273 // TODO: ...
259 274
260 uxn_eval_asm(PAGE_PROGRAM); 275 uxn_eval_asm(PAGE_PROGRAM);
261 276
262 // txt_printf("ROM"); 277 txt_printf("\nROM");
263 // for (size_t i = 0; i < 64; i++) { 278 for (size_t i = 0; i < 64; i++) {
264 // if (i % 8 == 0) { 279 if (i % 8 == 0) {
265 // txt_printf("\n"); 280 txt_printf("\n");
266 // } 281 }
267 // txt_printf("%02x ", uxn_ram[i + PAGE_PROGRAM]); 282 txt_printf("%02x ", uxn_ram[i + PAGE_PROGRAM]);
268 // } 283 }
269 // txt_printf("\n\n"); 284 txt_printf("\n");
270 285
271 // txt_printf("WST ("); 286 txt_printf("WST (");
272 // txt_printf("SIZE: %d)", wst_ptr - (uintptr_t)wst); 287 txt_printf("SIZE: %d)", wst_ptr - (uintptr_t)wst);
273 // for (size_t i = 0; i < 64; i++) { 288 for (size_t i = 0; i < 64; i++) {
274 // if (i % 8 == 0) { 289 if (i % 8 == 0) {
275 // txt_printf("\n"); 290 txt_printf("\n");
276 // } 291 }
277 // if (i >= (wst_ptr - (uintptr_t)wst)) { 292 if (i >= (wst_ptr - (uintptr_t)wst)) {
278 // txt_printf("%02x ", 0); 293 txt_printf("%02x ", 0);
279 // } else { 294 } else {
280 // txt_printf("%02x ", wst[i]); 295 txt_printf("%02x ", wst[i]);
281 // } 296 }
282 // } 297 }
283 // txt_printf("\n\n"); 298 txt_printf("\n\n");
284 // txt_printf("RST ("); 299 // txt_printf("RST (");
285 // txt_printf("SIZE: %d)", rst_ptr - (uintptr_t)rst); 300 // txt_printf("SIZE: %d)", rst_ptr - (uintptr_t)rst);
286 // for (size_t i = 0; i < 64; i++) { 301 // for (size_t i = 0; i < 64; i++) {
diff --git a/src/uxn-core.s b/src/uxn-core.s
index 17f57a3..333b4a6 100644
--- a/src/uxn-core.s
+++ b/src/uxn-core.s
@@ -17,41 +17,6 @@ rst: .space 256
17.global rst_ptr 17.global rst_ptr
18rst_ptr: .word rst 18rst_ptr: .word rst
19 19
20.global device_data
21device_data:
22 .global device_0
23 device_0: .space 16
24 .global device_1
25 device_1: .space 16
26 .global device_2
27 device_2: .space 16
28 .global device_3
29 device_3: .space 16
30 .global device_4
31 device_4: .space 16
32 .global device_5
33 device_5: .space 16
34 .global device_6
35 device_6: .space 16
36 .global device_7
37 device_7: .space 16
38 .global device_8
39 device_8: .space 16
40 .global device_9
41 device_9: .space 16
42 .global device_a
43 device_a: .space 16
44 .global device_b
45 device_b: .space 16
46 .global device_c
47 device_c: .space 16
48 .global device_d
49 device_d: .space 16
50 .global device_e
51 device_e: .space 16
52 .global device_f
53 device_f: .space 16
54
55@ UXN evaluation function. 20@ UXN evaluation function.
56@ 21@
57@ r0: PC pointer (argument for this function is the offset from UXN RAM). 22@ r0: PC pointer (argument for this function is the offset from UXN RAM).
@@ -804,90 +769,6 @@ sta2:
804 asave16 r3, r4 769 asave16 r3, r4
805 b uxn_decode 770 b uxn_decode
806 771
807.global dei_map
808dei_map:
809 .word uxn_ret
810 .word uxn_ret
811 .word uxn_ret
812 .word uxn_ret
813 .word uxn_ret
814 .word uxn_ret
815 .word uxn_ret
816 .word uxn_ret
817 .word uxn_ret
818 .word uxn_ret
819 .word uxn_ret
820 .word uxn_ret
821 .word uxn_ret
822 .word uxn_ret
823 .word uxn_ret
824 .word uxn_ret
825
826dei:
827 b uxn_decode
828
829dei2:
830 b uxn_decode
831
832.global deo_map
833deo_map:
834 .word uxn_ret
835 .word uxn_ret
836 .word uxn_ret
837 .word uxn_ret
838 .word uxn_ret
839 .word uxn_ret
840 .word uxn_ret
841 .word uxn_ret
842 .word uxn_ret
843 .word uxn_ret
844 .word uxn_ret
845 .word uxn_ret
846 .word uxn_ret
847 .word uxn_ret
848 .word uxn_ret
849 .word uxn_ret
850
851deo:
852 wpop8 r3
853 mov r4, r3, lsr #4 @ idx
854 and r3, #0x0f @ port
855 wpop8 r5 @ value
856 adr r6, deo_map
857 ldr r6, [r6, r4, lsl #2]
858 stmfd sp!, {r0, r7, lr}
859 adr r0, device_data
860 lsl r4, #4
861 add r0, r4
862 strb r5, [r0, r3]
863 mov r1, r3
864 mov lr, pc
865 bx r6
866 ldmfd sp!, {r0, r7, lr}
867 ldr r1, wst_ptr
868 ldr r2, rst_ptr
869 b uxn_decode
870
871deo2:
872 wpop8 r3
873 mov r4, r3, lsr #4 @ idx
874 and r3, #0x0f @ port
875 wpop16 r5, r6 @ value
876 adr r6, deo_map
877 ldr r6, [r6, r4, lsl #2]
878 stmfd sp!, {r0, r7, lr}
879 adr r0, device_data
880 lsl r4, #4
881 add r0, r4
882 strh r5, [r0, r3]
883 mov r1, r3
884 mov lr, pc
885 bx r6
886 ldmfd sp!, {r0, r7, lr}
887 ldr r1, wst_ptr
888 ldr r2, rst_ptr
889 b uxn_decode
890
891add: 772add:
892 wpop8 r3 773 wpop8 r3
893 wpop8 r4 774 wpop8 r4
@@ -1016,3 +897,153 @@ sft2:
1016 wpush16 r3 897 wpush16 r3
1017 b uxn_decode 898 b uxn_decode
1018 899
900dei:
901 wpop8 r3
902 mov r4, r3, lsr #4 @ idx
903 and r3, #0x0f @ port
904 adr r6, dei_map
905 ldr r6, [r6, r4, lsl #2]
906 stmfd sp!, {r0, r7, lr}
907 adr r0, device_data
908 lsl r4, #4
909 add r0, r4
910 mov r1, r3
911 mov lr, pc
912 bx r6
913 ldr r1, wst_ptr
914 ldr r2, rst_ptr
915 wpush8 r0
916 ldmfd sp!, {r0, r7, lr}
917 b uxn_decode
918
919dei2:
920 wpop8 r3
921 mov r4, r3, lsr #4 @ idx
922 and r3, #0x0f @ port
923 adr r6, dei_map
924 ldr r6, [r6, r4, lsl #2]
925 stmfd sp!, {r0, r7, lr}
926 adr r0, device_data
927 lsl r4, #4
928 add r0, r4
929 mov r1, r3
930 mov lr, pc
931 bx r6
932 ldr r1, wst_ptr
933 ldr r2, rst_ptr
934 wpush16 r0
935 ldmfd sp!, {r0, r7, lr}
936 b uxn_decode
937
938deo:
939 wpop8 r3
940 mov r4, r3, lsr #4 @ idx
941 and r3, #0x0f @ port
942 wpop8 r5 @ value
943 adr r6, deo_map
944 ldr r6, [r6, r4, lsl #2]
945 stmfd sp!, {r0, r7, lr}
946 adr r0, device_data
947 lsl r4, #4
948 add r0, r4
949 strb r5, [r0, r3]
950 mov r1, r3
951 mov lr, pc
952 bx r6
953 ldmfd sp!, {r0, r7, lr}
954 ldr r1, wst_ptr
955 ldr r2, rst_ptr
956 b uxn_decode
957
958deo2:
959 wpop8 r3
960 mov r4, r3, lsr #4 @ idx
961 and r3, #0x0f @ port
962 wpop16 r5, r6 @ value
963 adr r6, deo_map
964 ldr r6, [r6, r4, lsl #2]
965 stmfd sp!, {r0, r7, lr}
966 adr r0, device_data
967 lsl r4, #4
968 add r0, r4
969 strh r5, [r0, r3]
970 mov r1, r3
971 mov lr, pc
972 bx r6
973 ldmfd sp!, {r0, r7, lr}
974 ldr r1, wst_ptr
975 ldr r2, rst_ptr
976 b uxn_decode
977
978.global device_data
979device_data:
980 .global device_0
981 device_0: .space 16
982 .global device_1
983 device_1: .space 16
984 .global device_2
985 device_2: .space 16
986 .global device_3
987 device_3: .space 16
988 .global device_4
989 device_4: .space 16
990 .global device_5
991 device_5: .space 16
992 .global device_6
993 device_6: .space 16
994 .global device_7
995 device_7: .space 16
996 .global device_8
997 device_8: .space 16
998 .global device_9
999 device_9: .space 16
1000 .global device_a
1001 device_a: .space 16
1002 .global device_b
1003 device_b: .space 16
1004 .global device_c
1005 device_c: .space 16
1006 .global device_d
1007 device_d: .space 16
1008 .global device_e
1009 device_e: .space 16
1010 .global device_f
1011 device_f: .space 16
1012
1013.global dei_map
1014dei_map:
1015 .word uxn_ret
1016 .word uxn_ret
1017 .word uxn_ret
1018 .word uxn_ret
1019 .word uxn_ret
1020 .word uxn_ret
1021 .word uxn_ret
1022 .word uxn_ret
1023 .word uxn_ret
1024 .word uxn_ret
1025 .word uxn_ret
1026 .word uxn_ret
1027 .word uxn_ret
1028 .word uxn_ret
1029 .word uxn_ret
1030 .word uxn_ret
1031
1032.global deo_map
1033deo_map:
1034 .word uxn_ret
1035 .word uxn_ret
1036 .word uxn_ret
1037 .word uxn_ret
1038 .word uxn_ret
1039 .word uxn_ret
1040 .word uxn_ret
1041 .word uxn_ret
1042 .word uxn_ret
1043 .word uxn_ret
1044 .word uxn_ret
1045 .word uxn_ret
1046 .word uxn_ret
1047 .word uxn_ret
1048 .word uxn_ret
1049 .word uxn_ret