commit 4d3974f
neauoire
·
2023-10-31 17:59:42 +0000 UTC
parent 90c3a25
Redesigned the stack debugger
10 files changed,
+56,
-77
+20,
-17
1@@ -1,4 +1,5 @@
2 ( Opcode Tester )
3+( Source: https://git.sr.ht/~rabbits/uxn-utils/tree/main/item/cli/opctest/opctest.tal )
4
5 |0013
6
7@@ -10,7 +11,7 @@
8 > LIT2: Puts a short on the stack
9 > #18 DEO: Write a letter in terminal )
10
11- LIT2 "kO #18 DEO #18 DEO #0a18 DEO
12+ [ LIT2 "kO ] #18 DEO #18 DEO #0a18 DEO
13
14 ( part 2
15 > LITr: Put a byte on return stack
16@@ -18,14 +19,14 @@
17 > STH: Move a byte from working stack to return stack
18 > STH2r: Move a short from return stack to working stack )
19
20- LITr "k LIT "O STH STH2r #18 DEO #18 DEO #0a18 DEO
21+ [ LITr "k ] [ LIT "O ] STH STH2r #18 DEO #18 DEO #0a18 DEO
22
23 ( part 3
24 > LIT2r: Put a short on return stack
25 > DUP: Duplicate byte
26 > ADDr: Add bytes on return stack )
27
28- LIT2r "k 4d #01 DUP STH ADDr STH ADDr STH2r #18 DEO #18 DEO #0a18 DEO
29+ [ LIT2r "k 4d ] #01 DUP STH ADDr STH ADDr STH2r #18 DEO #18 DEO #0a18 DEO
30
31 ( part 4
32 > JSI: Subroutine to relative absolute address
33@@ -46,7 +47,7 @@
34 > LDA2k: Non-destructive load short from absolute address
35 > STA2: Store short at absolute address )
36
37- LIT2r 0000
38+ [ LIT2r 0000 ]
39 ;tests/end ;tests
40 &l
41 run-test STH ADDr
42@@ -56,7 +57,7 @@
43
44 ( halt )
45
46- #010f DEO
47+ #800f DEO
48
49 BRK
50
51@@ -64,7 +65,7 @@ BRK
52
53 LDA2k JSR2 DUP ?&pass
54 ;Dict/failed pstr
55- [ LIT2 &name $2 ] pstr #0a18 DEO JMP2r
56+ [ LIT2 &name $2 ] pstr/ #0a18 DEO JMP2r
57 &pass
58
59 JMP2r
60@@ -77,8 +78,9 @@ JMP2r
61
62 @pstr ( str* -- )
63
64- LDAk ?&w POP2 JMP2r
65- &w LDAk #18 DEO INC2 LDAk ?&w
66+ &w ( -- )
67+ LDAk #18 DEO
68+ INC2 & LDAk ?&w
69 POP2
70
71 JMP2r
72@@ -106,8 +108,8 @@ JMP2r
73 =op-mul/a =op-mul/b =op-mul/c =op-mul/d
74 =op-mul/e =op-mul/f =op-mul/g =op-mul/h ]
75 =op-div [
76- =op-div/a =op-div/b =op-div/c =op-div/d
77- =op-div/e =op-div/f =op-div/g =op-div/h ]
78+ =op-div/a =op-div/b =op-div/c =op-div/d =op-div/e
79+ =op-div/f =op-div/g =op-div/h =op-div/i =op-div/j ]
80 =op-inc [
81 =op-inc/a =op-inc/b =op-inc/c =op-inc/d
82 =op-inc/e =op-inc/f =op-inc/g =op-inc/h ]
83@@ -226,10 +228,12 @@ JMP2r
84 &b #20 #20 DIV [ #01 ] EQU JMP2r
85 &c #34 #01 DIV [ #34 ] EQU JMP2r
86 &d #02 #ef DIV [ #00 ] EQU JMP2r
87- &e #1000 #0040 DIV2 [ #0040 ] EQU2 JMP2r
88- &f #abcd #1234 DIV2 [ #0009 ] EQU2 JMP2r
89- &g #8000 #0200 DIV2 [ #0040 ] EQU2 JMP2r
90- &h #2222 #0003 DIV2 [ #0b60 ] EQU2 JMP2r
91+ &e #02 #00 DIV [ #00 ] EQU JMP2r
92+ &f #1000 #0040 DIV2 [ #0040 ] EQU2 JMP2r
93+ &g #abcd #1234 DIV2 [ #0009 ] EQU2 JMP2r
94+ &h #8000 #0200 DIV2 [ #0040 ] EQU2 JMP2r
95+ &i #2222 #0003 DIV2 [ #0b60 ] EQU2 JMP2r
96+ &j #0202 #0000 DIV2 [ #0000 ] EQU2 JMP2r
97 @op-inc ;Dict/inc !set
98 &a #01 INC [ #02 ] EQU JMP2r
99 &b #ff INC [ #00 ] EQU JMP2r
100@@ -346,16 +350,15 @@ JMP2r
101
102 @special ( routine* -- f )
103
104- ( test the stack order )
105+ ( test that the stack order is LIFO )
106 DUP2 STH2kr EQU2
107 ROT ROT DUP2r STHr STHr SWP EQU2 AND
108
109 JMP2r
110
111 @routine ( a b -- c ) ADD JMP2r
112-@subroutine ( -- ) LIT2 "kO #18 DEO #18 DEO #0a18 DEO JMP2r
113+@subroutine ( -- ) [ LIT2 "kO ] #18 DEO #18 DEO #0a18 DEO JMP2r
114 @Absolute &byte $1 &short $2
115-@phex ( short* -- ) SWP phex/b &b ( byte -- ) DUP #04 SFT phex/c &c ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO JMP2r
116
117 @Dict [
118 &ok "Ok $1
+1,
-3
1@@ -38,10 +38,7 @@
2 #05 .Screen/auto DEO
3 draw-polycat
4
5- ;&mmu #02 DEO2
6-
7 BRK
8- &mmu 01 1234 4567 789a 2345 6789
9
10 @draw-polycat ( -- )
11
12@@ -69,6 +66,7 @@ JMP2r
13 .cat/timer LDZ INC [ DUP ] .cat/timer STZ
14 #04 SFT draw-tail
15 draw-cursor
16+ .Mouse/state DEI #00 EQU ?{ #ff #00 .Mouse/state DEO }
17
18 BRK
19
+19,
-8
1@@ -76,15 +76,17 @@ static Uint8 icons[] = {
2 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc,
3 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00,
4 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
5- 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80};
6+ 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80 };
7+static Uint8 arrow[] = {
8+ 0x00, 0x00, 0x00, 0xfe, 0x7c, 0x38, 0x10, 0x00 };
9
10 /* clang-format on */
11
12 static void
13-draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color)
14+draw_byte(Uint8 b, Uint16 x, Uint16 y, Uint8 color)
15 {
16- screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0);
17- screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0);
18+ screen_blit(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0, 0);
19+ screen_blit(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0, 0);
20 screen_change(x, y, x + 0x10, y + 0x8);
21 }
22
23@@ -92,10 +94,19 @@ static void
24 screen_debugger(Uxn *u)
25 {
26 int i;
27- for(i = 0; i < u->wst.ptr; i++)
28- draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
29- for(i = 0; i < u->rst.ptr; i++)
30- draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3);
31+ for(i = 0; i < 0x08; i++) {
32+ Uint8 pos = u->wst.ptr - 4 + i;
33+ draw_byte(u->wst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x18, i > 4 ? 0x01 : !pos ? 0xc :
34+ i == 4 ? 0x8 :
35+ 0x2);
36+ }
37+ for(i = 0; i < 0x08; i++) {
38+ Uint8 pos = u->rst.ptr - 4 + i;
39+ draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, i > 4 ? 0x01 : !pos ? 0xc :
40+ i == 4 ? 0x8 :
41+ 0x2);
42+ }
43+ screen_blit(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0, 0);
44 for(i = 0; i < 0x40; i++)
45 draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
46 }
+1,
-20
1@@ -16,8 +16,7 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 char *boot_rom;
5-Uint8 dei_masks[0x100], deo_masks[0x100];
6-Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
7+Uint16 dev_vers[0x10];
8
9 static int
10 system_load(Uxn *u, char *filename)
11@@ -60,28 +59,10 @@ system_inspect(Uxn *u)
12 system_print(&u->rst, "rst");
13 }
14
15-void
16-system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo)
17-{
18- int i, d = (device << 0x4);
19- for(i = 0; i < 0x10; i++) {
20- dei_masks[d + i] = (dei >> i) & 0x1;
21- deo_masks[d + i] = (deo >> i) & 0x1;
22- }
23- dev_vers[device] = ver;
24- dei_mask[device] = dei;
25- deo_mask[device] = deo;
26-}
27-
28 int
29 system_version(char *name, char *date)
30 {
31- int i;
32 printf("%s, %s.\n", name, date);
33- printf("Device Version Dei Deo\n");
34- for(i = 0; i < 0x10; i++)
35- if(dev_vers[i])
36- printf("%6x %7d %04x %04x\n", i, dev_vers[i], dei_mask[i], deo_mask[i]);
37 return 0;
38 }
39
+0,
-1
1@@ -17,7 +17,6 @@ WITH REGARD TO THIS SOFTWARE.
2
3 extern char *boot_rom;
4
5-void system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo);
6 void system_reboot(Uxn *u, char *rom, int soft);
7 void system_inspect(Uxn *u);
8 int system_version(char *emulator, char *date);
+6,
-6
1@@ -13,21 +13,21 @@ WITH REGARD TO THIS SOFTWARE.
2
3 #define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; }
4 #define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); }
5-#define POKE(x, y) { if(m2) { POKE2(ram + x, y) } else ram[(x)] = (y); }
6-#define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; }
7-#define DEVR(o, p) { if(m2) { o = ((emu_dei(u, p) << 8) + emu_dei(u, p + 1)); } else o = emu_dei(u, p); }
8+#define POKE(x, y) { if(m2) { tp = &ram[x]; POKE2(tp, y) } else ram[(x)] = (y); }
9+#define PEEK(o, x) { if(m2) { tp = &ram[x]; o = PEEK2(tp); } else o = ram[(x)]; }
10+#define DEVR(o, p) { if(m2) { o = (emu_dei(u, p) << 8) | emu_dei(u, p + 1); } else o = emu_dei(u, p); }
11 #define DEVW(p, y) { if(m2) { emu_deo(u, p, y >> 8); emu_deo(u, p + 1, y); } else emu_deo(u, p, y); }
12 #define PUSH1(y) { s->dat[s->ptr++] = (y); }
13-#define PUSH2(y) { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t & 0xff; }
14+#define PUSH2(y) { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t; }
15 #define PUSHx(y) { if(m2) { PUSH2(y) } else PUSH1(y) }
16 #define POP1(o) { o = s->dat[--*sp]; }
17-#define POP2(o) { o = s->dat[--*sp] | s->dat[--*sp] << 0x8; }
18+#define POP2(o) { o = s->dat[--*sp] | (s->dat[--*sp] << 0x8); }
19 #define POPx(o) { if(m2) { POP2(o) } else POP1(o) }
20
21 int
22 uxn_eval(Uxn *u, Uint16 pc)
23 {
24- Uint8 ksp, *sp, *ram = u->ram;
25+ Uint8 ksp, *sp, *tp, *ram = u->ram;
26 Uint16 a, b, c, t;
27 if(!pc || u->dev[0x0f]) return 0;
28 for(;;) {
+1,
-2
1@@ -37,8 +37,7 @@ typedef struct Uxn {
2
3 extern Uint8 emu_dei(Uxn *u, Uint8 addr);
4 extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
5-extern Uint8 dei_masks[0x100], deo_masks[0x100];
6-extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
7+extern Uint16 dev_vers[0x10];
8
9 /* built-ins */
10
+0,
-10
1@@ -259,16 +259,6 @@ main(int argc, char **argv)
2 int i = 1;
3 if(i == argc)
4 return system_error("usage", "uxn11 [-v] file.rom [args...]");
5- /* Connect Varvara */
6- system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK);
7- system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK);
8- system_connect(0x2, SCREEN_VERSION, SCREEN_DEIMASK, SCREEN_DEOMASK);
9- system_connect(0x8, CONTROL_VERSION, CONTROL_DEIMASK, CONTROL_DEOMASK);
10- system_connect(0x9, MOUSE_VERSION, MOUSE_DEIMASK, MOUSE_DEOMASK);
11- system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
12- system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
13- system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
14- system_connect(0xf, LINK_VERSION, LINK_DEIMASK, LINK_DEOMASK);
15 /* Read flags */
16 if(argv[i][0] == '-' && argv[i][1] == 'v')
17 return system_version("Uxn11 - Graphical Varvara Emulator", "31 Oct 2023");
+8,
-4
1@@ -501,17 +501,21 @@ main(int argc, char *argv[])
2 if(argc == 1)
3 return error("usage", "uxnasm [-v] input.tal output.rom");
4 if(argv[1][0] == '-' && argv[1][1] == 'v')
5- return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 8 Aug 2023.\n");
6+ return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 27 Oct 2023.\n");
7 if(!(src = fopen(argv[1], "r")))
8 return !error("Invalid input", argv[1]);
9 if(!assemble(src))
10 return !error("Assembly", "Failed to assemble rom.");
11- if(!(dst = fopen(argv[2], "wb")))
12+ if(scmp(argv[2], "-", 2))
13+ dst = stdout;
14+ else if(!(dst = fopen(argv[2], "wb")))
15 return !error("Invalid Output", argv[2]);
16 if(p.length <= TRIM)
17 return !error("Assembly", "Output rom is empty.");
18 fwrite(p.data + TRIM, p.length - TRIM, 1, dst);
19- review(argv[2]);
20- writesym(argv[2]);
21+ if(!scmp(argv[2], "-", 2)) {
22+ review(argv[2]);
23+ writesym(argv[2]);
24+ }
25 return 0;
26 }
+0,
-6
1@@ -68,12 +68,6 @@ main(int argc, char **argv)
2 int i = 1;
3 if(i == argc)
4 return system_error("usage", "uxncli [-v] file.rom [args..]");
5- /* Connect Varvara */
6- system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK);
7- system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK);
8- system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
9- system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
10- system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
11 /* Read flags */
12 if(argv[i][0] == '-' && argv[i][1] == 'v')
13 return system_version("Uxncli - Console Varvara Emulator", "30 Oct 2023");