Redesigned the stack debugger

This commit is contained in:
neauoire 2023-10-31 10:59:42 -07:00
parent 90c3a25792
commit 4d3974faad
10 changed files with 56 additions and 77 deletions

View File

@ -1,4 +1,5 @@
( Opcode Tester )
( Source: https://git.sr.ht/~rabbits/uxn-utils/tree/main/item/cli/opctest/opctest.tal )
|0013
@ -10,7 +11,7 @@
> LIT2: Puts a short on the stack
> #18 DEO: Write a letter in terminal )
LIT2 "kO #18 DEO #18 DEO #0a18 DEO
[ LIT2 "kO ] #18 DEO #18 DEO #0a18 DEO
( part 2
> LITr: Put a byte on return stack
@ -18,14 +19,14 @@
> STH: Move a byte from working stack to return stack
> STH2r: Move a short from return stack to working stack )
LITr "k LIT "O STH STH2r #18 DEO #18 DEO #0a18 DEO
[ LITr "k ] [ LIT "O ] STH STH2r #18 DEO #18 DEO #0a18 DEO
( part 3
> LIT2r: Put a short on return stack
> DUP: Duplicate byte
> ADDr: Add bytes on return stack )
LIT2r "k 4d #01 DUP STH ADDr STH ADDr STH2r #18 DEO #18 DEO #0a18 DEO
[ LIT2r "k 4d ] #01 DUP STH ADDr STH ADDr STH2r #18 DEO #18 DEO #0a18 DEO
( part 4
> JSI: Subroutine to relative absolute address
@ -46,7 +47,7 @@
> LDA2k: Non-destructive load short from absolute address
> STA2: Store short at absolute address )
LIT2r 0000
[ LIT2r 0000 ]
;tests/end ;tests
&l
run-test STH ADDr
@ -56,7 +57,7 @@
( halt )
#010f DEO
#800f DEO
BRK
@ -64,7 +65,7 @@ BRK
LDA2k JSR2 DUP ?&pass
;Dict/failed pstr
[ LIT2 &name $2 ] pstr #0a18 DEO JMP2r
[ LIT2 &name $2 ] pstr/ #0a18 DEO JMP2r
&pass
JMP2r
@ -77,8 +78,9 @@ JMP2r
@pstr ( str* -- )
LDAk ?&w POP2 JMP2r
&w LDAk #18 DEO INC2 LDAk ?&w
&w ( -- )
LDAk #18 DEO
INC2 & LDAk ?&w
POP2
JMP2r
@ -106,8 +108,8 @@ JMP2r
=op-mul/a =op-mul/b =op-mul/c =op-mul/d
=op-mul/e =op-mul/f =op-mul/g =op-mul/h ]
=op-div [
=op-div/a =op-div/b =op-div/c =op-div/d
=op-div/e =op-div/f =op-div/g =op-div/h ]
=op-div/a =op-div/b =op-div/c =op-div/d =op-div/e
=op-div/f =op-div/g =op-div/h =op-div/i =op-div/j ]
=op-inc [
=op-inc/a =op-inc/b =op-inc/c =op-inc/d
=op-inc/e =op-inc/f =op-inc/g =op-inc/h ]
@ -226,10 +228,12 @@ JMP2r
&b #20 #20 DIV [ #01 ] EQU JMP2r
&c #34 #01 DIV [ #34 ] EQU JMP2r
&d #02 #ef DIV [ #00 ] EQU JMP2r
&e #1000 #0040 DIV2 [ #0040 ] EQU2 JMP2r
&f #abcd #1234 DIV2 [ #0009 ] EQU2 JMP2r
&g #8000 #0200 DIV2 [ #0040 ] EQU2 JMP2r
&h #2222 #0003 DIV2 [ #0b60 ] EQU2 JMP2r
&e #02 #00 DIV [ #00 ] EQU JMP2r
&f #1000 #0040 DIV2 [ #0040 ] EQU2 JMP2r
&g #abcd #1234 DIV2 [ #0009 ] EQU2 JMP2r
&h #8000 #0200 DIV2 [ #0040 ] EQU2 JMP2r
&i #2222 #0003 DIV2 [ #0b60 ] EQU2 JMP2r
&j #0202 #0000 DIV2 [ #0000 ] EQU2 JMP2r
@op-inc ;Dict/inc !set
&a #01 INC [ #02 ] EQU JMP2r
&b #ff INC [ #00 ] EQU JMP2r
@ -346,16 +350,15 @@ JMP2r
@special ( routine* -- f )
( test the stack order )
( test that the stack order is LIFO )
DUP2 STH2kr EQU2
ROT ROT DUP2r STHr STHr SWP EQU2 AND
JMP2r
@routine ( a b -- c ) ADD JMP2r
@subroutine ( -- ) LIT2 "kO #18 DEO #18 DEO #0a18 DEO JMP2r
@subroutine ( -- ) [ LIT2 "kO ] #18 DEO #18 DEO #0a18 DEO JMP2r
@Absolute &byte $1 &short $2
@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
@Dict [
&ok "Ok $1

View File

@ -38,10 +38,7 @@
#05 .Screen/auto DEO
draw-polycat
;&mmu #02 DEO2
BRK
&mmu 01 1234 4567 789a 2345 6789
@draw-polycat ( -- )
@ -69,6 +66,7 @@ JMP2r
.cat/timer LDZ INC [ DUP ] .cat/timer STZ
#04 SFT draw-tail
draw-cursor
.Mouse/state DEI #00 EQU ?{ #ff #00 .Mouse/state DEO }
BRK

View File

@ -77,14 +77,16 @@ static Uint8 icons[] = {
0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00,
0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80 };
static Uint8 arrow[] = {
0x00, 0x00, 0x00, 0xfe, 0x7c, 0x38, 0x10, 0x00 };
/* clang-format on */
static void
draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color)
draw_byte(Uint8 b, Uint16 x, Uint16 y, Uint8 color)
{
screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0);
screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0);
screen_blit(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0, 0);
screen_blit(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0, 0);
screen_change(x, y, x + 0x10, y + 0x8);
}
@ -92,10 +94,19 @@ static void
screen_debugger(Uxn *u)
{
int i;
for(i = 0; i < u->wst.ptr; i++)
draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
for(i = 0; i < u->rst.ptr; i++)
draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3);
for(i = 0; i < 0x08; i++) {
Uint8 pos = u->wst.ptr - 4 + i;
draw_byte(u->wst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x18, i > 4 ? 0x01 : !pos ? 0xc :
i == 4 ? 0x8 :
0x2);
}
for(i = 0; i < 0x08; i++) {
Uint8 pos = u->rst.ptr - 4 + i;
draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, i > 4 ? 0x01 : !pos ? 0xc :
i == 4 ? 0x8 :
0x2);
}
screen_blit(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0, 0);
for(i = 0; i < 0x40; i++)
draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
}

View File

@ -16,8 +16,7 @@ WITH REGARD TO THIS SOFTWARE.
*/
char *boot_rom;
Uint8 dei_masks[0x100], deo_masks[0x100];
Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
Uint16 dev_vers[0x10];
static int
system_load(Uxn *u, char *filename)
@ -60,28 +59,10 @@ system_inspect(Uxn *u)
system_print(&u->rst, "rst");
}
void
system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo)
{
int i, d = (device << 0x4);
for(i = 0; i < 0x10; i++) {
dei_masks[d + i] = (dei >> i) & 0x1;
deo_masks[d + i] = (deo >> i) & 0x1;
}
dev_vers[device] = ver;
dei_mask[device] = dei;
deo_mask[device] = deo;
}
int
system_version(char *name, char *date)
{
int i;
printf("%s, %s.\n", name, date);
printf("Device Version Dei Deo\n");
for(i = 0; i < 0x10; i++)
if(dev_vers[i])
printf("%6x %7d %04x %04x\n", i, dev_vers[i], dei_mask[i], deo_mask[i]);
return 0;
}

View File

@ -17,7 +17,6 @@ WITH REGARD TO THIS SOFTWARE.
extern char *boot_rom;
void system_connect(Uint8 device, Uint8 ver, Uint16 dei, Uint16 deo);
void system_reboot(Uxn *u, char *rom, int soft);
void system_inspect(Uxn *u);
int system_version(char *emulator, char *date);

View File

@ -13,21 +13,21 @@ WITH REGARD TO THIS SOFTWARE.
#define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; }
#define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); }
#define POKE(x, y) { if(m2) { POKE2(ram + x, y) } else ram[(x)] = (y); }
#define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; }
#define DEVR(o, p) { if(m2) { o = ((emu_dei(u, p) << 8) + emu_dei(u, p + 1)); } else o = emu_dei(u, p); }
#define POKE(x, y) { if(m2) { tp = &ram[x]; POKE2(tp, y) } else ram[(x)] = (y); }
#define PEEK(o, x) { if(m2) { tp = &ram[x]; o = PEEK2(tp); } else o = ram[(x)]; }
#define DEVR(o, p) { if(m2) { o = (emu_dei(u, p) << 8) | emu_dei(u, p + 1); } else o = emu_dei(u, p); }
#define DEVW(p, y) { if(m2) { emu_deo(u, p, y >> 8); emu_deo(u, p + 1, y); } else emu_deo(u, p, y); }
#define PUSH1(y) { s->dat[s->ptr++] = (y); }
#define PUSH2(y) { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t & 0xff; }
#define PUSH2(y) { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t; }
#define PUSHx(y) { if(m2) { PUSH2(y) } else PUSH1(y) }
#define POP1(o) { o = s->dat[--*sp]; }
#define POP2(o) { o = s->dat[--*sp] | s->dat[--*sp] << 0x8; }
#define POP2(o) { o = s->dat[--*sp] | (s->dat[--*sp] << 0x8); }
#define POPx(o) { if(m2) { POP2(o) } else POP1(o) }
int
uxn_eval(Uxn *u, Uint16 pc)
{
Uint8 ksp, *sp, *ram = u->ram;
Uint8 ksp, *sp, *tp, *ram = u->ram;
Uint16 a, b, c, t;
if(!pc || u->dev[0x0f]) return 0;
for(;;) {

View File

@ -37,8 +37,7 @@ typedef struct Uxn {
extern Uint8 emu_dei(Uxn *u, Uint8 addr);
extern void emu_deo(Uxn *u, Uint8 addr, Uint8 value);
extern Uint8 dei_masks[0x100], deo_masks[0x100];
extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10];
extern Uint16 dev_vers[0x10];
/* built-ins */

View File

@ -259,16 +259,6 @@ main(int argc, char **argv)
int i = 1;
if(i == argc)
return system_error("usage", "uxn11 [-v] file.rom [args...]");
/* Connect Varvara */
system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK);
system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK);
system_connect(0x2, SCREEN_VERSION, SCREEN_DEIMASK, SCREEN_DEOMASK);
system_connect(0x8, CONTROL_VERSION, CONTROL_DEIMASK, CONTROL_DEOMASK);
system_connect(0x9, MOUSE_VERSION, MOUSE_DEIMASK, MOUSE_DEOMASK);
system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
system_connect(0xf, LINK_VERSION, LINK_DEIMASK, LINK_DEOMASK);
/* Read flags */
if(argv[i][0] == '-' && argv[i][1] == 'v')
return system_version("Uxn11 - Graphical Varvara Emulator", "31 Oct 2023");

View File

@ -501,17 +501,21 @@ main(int argc, char *argv[])
if(argc == 1)
return error("usage", "uxnasm [-v] input.tal output.rom");
if(argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 8 Aug 2023.\n");
return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 27 Oct 2023.\n");
if(!(src = fopen(argv[1], "r")))
return !error("Invalid input", argv[1]);
if(!assemble(src))
return !error("Assembly", "Failed to assemble rom.");
if(!(dst = fopen(argv[2], "wb")))
if(scmp(argv[2], "-", 2))
dst = stdout;
else if(!(dst = fopen(argv[2], "wb")))
return !error("Invalid Output", argv[2]);
if(p.length <= TRIM)
return !error("Assembly", "Output rom is empty.");
fwrite(p.data + TRIM, p.length - TRIM, 1, dst);
if(!scmp(argv[2], "-", 2)) {
review(argv[2]);
writesym(argv[2]);
}
return 0;
}

View File

@ -68,12 +68,6 @@ main(int argc, char **argv)
int i = 1;
if(i == argc)
return system_error("usage", "uxncli [-v] file.rom [args..]");
/* Connect Varvara */
system_connect(0x0, SYSTEM_VERSION, SYSTEM_DEIMASK, SYSTEM_DEOMASK);
system_connect(0x1, CONSOLE_VERSION, CONSOLE_DEIMASK, CONSOLE_DEOMASK);
system_connect(0xa, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
system_connect(0xb, FILE_VERSION, FILE_DEIMASK, FILE_DEOMASK);
system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
/* Read flags */
if(argv[i][0] == '-' && argv[i][1] == 'v')
return system_version("Uxncli - Console Varvara Emulator", "30 Oct 2023");