uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit ed1f6e62636a1ab5cb20729ffac729a6d7cb7e9e
parent b94c52cbbf18ff93c79533f943446f182a14c93a
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu,  6 Jan 2022 14:32:28 -0800

Connected error reporting and the hypervisor

Diffstat:
Mprojects/software/hypervisor.tal | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/devices/system.c | 19+++++++++++++++++--
Msrc/devices/system.h | 3+++
Msrc/uxnemu.c | 6+++---
4 files changed, 150 insertions(+), 11 deletions(-)

diff --git a/projects/software/hypervisor.tal b/projects/software/hypervisor.tal @@ -9,22 +9,97 @@ %AUTO-Y { #02 .Screen/auto DEO } %AUTO-YADDR { #06 .Screen/auto DEO } +%HALT { #010f DEO } +%EMIT { #18 DEO } +%PRINT { ;print-str JSR2 #0a EMIT } +%DEBUG { ;print-hex/byte JSR2 #0a EMIT } +%DEBUG2 { ;print-hex JSR2 #0a EMIT } + +%MODALW { #0024 } +%MODALH { #0009 } + %RTN { JMP2r } %2// { #01 SFT2 } +%8** { #30 SFT2 } ( devices ) +|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ( variables ) |0000 +@center + &x $2 &y $2 + +@modal + &x $2 &y $2 + ( init ) |0100 ( -> ) + .Screen/width DEI2 2// + DUP2 .center/x STZ2 + MODALW #31 SFT2 -- .modal/x STZ2 + .Screen/height DEI2 2// + DUP2 .center/y STZ2 + MODALH #31 SFT2 -- .modal/y STZ2 + ;draw-cross JSR2 + ;draw-stacks JSR2 + + .System/eaddr DEI2 #0000 !! ;on-error JCN2 + +BRK + +@on-error ( -> ) + + ( background ) + #00 .Screen/auto DEO + ;bg-icn .Screen/addr DEO2 + MODALH #0000 + &ver + DUP2 8** .modal/y LDZ2 ++ .Screen/y DEO2 + MODALW #0000 + &hor + DUP2 8** .modal/x LDZ2 ++ .Screen/x DEO2 + #42 .Screen/sprite DEO + INC2 GTH2k ,&hor JCN + POP2 POP2 + INC2 GTH2k ,&ver JCN + POP2 POP2 + + ( corners ) + ;corner-icn .Screen/addr DEO2 + .modal/x LDZ2 .Screen/x DEO2 + .modal/y LDZ2 .Screen/y DEO2 + #42 .Screen/sprite DEO + .modal/x LDZ2 MODALW #0001 -- 8** ++ .Screen/x DEO2 + #52 .Screen/sprite DEO + + .modal/y LDZ2 MODALH #0001 -- 8** ++ .Screen/y DEO2 + #72 .Screen/sprite DEO + + .modal/x LDZ2 .Screen/x DEO2 + #62 .Screen/sprite DEO + + ( text ) + .modal/x LDZ2 #0010 ++ .Screen/x DEO2 + .modal/y LDZ2 #0010 ++ .Screen/y DEO2 + ;error-txts/0 #4f ;draw-str JSR2 + + ;at-txt #4f ;draw-str JSR2 + + .System/eaddr DEI2 #47 ;draw-short JSR2 + + #0000 .System/eaddr DEO2 + +BRK + +@draw-stacks ( -- ) AUTO-YADDR #0010 #0000 @@ -33,23 +108,23 @@ #0010 .Screen/y DEO2 DUP2 #0018 ** #0010 ++ .Screen/x DEO2 DUP #fe00 LDA ( ptr ) EQU #41 + STH - DUP2 #fe01 ++ LDA STHr ;draw-hex JSR2 + DUP2 #fe01 ++ LDA STHr ;draw-byte JSR2 ( return stack ) #0028 .Screen/y DEO2 DUP2 #0018 ** #0010 ++ .Screen/x DEO2 DUP #ff00 LDA ( ptr ) EQU #41 + STH - DUP2 #ff01 ++ LDA STHr ;draw-hex JSR2 + DUP2 #ff01 ++ LDA STHr ;draw-byte JSR2 INC2 GTH2k ,&wst JCN POP2 POP2 -BRK +RTN @draw-cross ( -- ) ( ver ) AUTO-Y #0000 .Screen/y DEO2 - .Screen/width DEI2 2// .Screen/x DEO2 + .center/x LDZ2 .Screen/x DEO2 .Screen/height DEI2 #0000 &ver #43 .Screen/pixel DEO @@ -60,7 +135,7 @@ BRK ( hor ) AUTO-X #0000 .Screen/x DEO2 - .Screen/height DEI2 2// .Screen/y DEO2 + .center/y LDZ2 .Screen/y DEO2 .Screen/width DEI2 #0000 &hor #43 .Screen/pixel DEO @@ -70,7 +145,26 @@ BRK RTN -@draw-hex ( byte color -- ) +@draw-str ( text* color -- ) + + AUTO-YADDR + STH + &while + LDAk STHkr ,draw-char JSR + INC2 LDAk ,&while JCN + POP2 + POPr + +RTN + +@draw-short ( short* color -- ) + + STH SWP STHkr ,draw-byte JSR + STHr ,draw-byte JSR + +RTN + +@draw-byte ( byte color -- ) STH DUP #04 SFT ,&parse JSR STHkr ,draw-char JSR @@ -90,4 +184,31 @@ RTN JMP2r +@print-hex ( value* -- ) + + SWP ,&byte JSR + &byte ( byte -- ) + STHk #04 SFT ,&parse JSR #18 DEO + STHr #0f AND ,&parse JSR #18 DEO + JMP2r + &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r + &above #57 ADD JMP2r + +JMP2r + +@error-txts + &0 "Working-stack 20 "underflow $1 + &1 "Return-stack 20 "underflow $1 + &2 "Working-stack 20 "overflow $1 + &3 "Return-stack 20 "overflow $1 + &4 "Working-stack 20 "division 20 "by 20 "zero $1 + &5 "Return-stack 20 "division 20 "by 20 "zero $1 +@at-txt + ', 20 "at 20 $1 + +@bg-icn + ffff ffff ffff ffff +@corner-icn + 1f7f 7fff ffff ffff + ~projects/assets/msx01x02.tal \ No newline at end of file diff --git a/src/devices/system.c b/src/devices/system.c @@ -14,6 +14,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +Uxn hypervisor; + static const char *errors[] = { "Working-stack underflow", "Return-stack underflow", @@ -27,14 +29,27 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr) { Device *d = &u->dev[0]; Uint16 vec = d->vector; + + /* hypervisor */ + d = &hypervisor.dev[0]; + vec = d->vector; + DEVPOKE16(0x4, addr); + d->dat[0x6] = error; + uxn_eval(&hypervisor, PAGE_PROGRAM); + + /* core */ + d = &u->dev[0]; + DEVPOKE16(0x4, addr); + d->dat[0x6] = error; + vec = d->vector; + if(vec) { d->vector = 0; /* need to rearm to run System/vector again */ - DEVPOKE16(0x4, addr); - d->dat[0x6] = error; if(error != 2) /* working stack overflow has special treatment */ vec += 0x0004; return uxn_eval(u, vec); } + fprintf(stderr, "Halted: %s#%04x, at 0x%04x\n", errors[error], u->ram[addr], addr); return 0; } diff --git a/src/devices/system.h b/src/devices/system.h @@ -12,3 +12,5 @@ WITH REGARD TO THIS SOFTWARE. Uint8 system_dei(Device *d, Uint8 port); void system_deo(Device *d, Uint8 port); void system_deo_special(Device *d, Uint8 port); + +extern Uxn hypervisor; +\ No newline at end of file diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -44,7 +44,6 @@ static SDL_Rect gRect; static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; static Uint8 zoom = 1; static Uint32 stdin_event, audio0_event; -static Uxn hypervisor; static int clamp(int val, int min, int max) @@ -283,10 +282,10 @@ start(Uxn *u, char *rom) return error("Boot", "Failed to start uxn."); if(!uxn_boot(u, (Stack *)(shadow + 0xfe00), (Stack *)(shadow + 0xff00), memory)) return error("Boot", "Failed to start uxn."); - if(!load(u, rom)) - return error("Boot", "Failed to load rom."); if(!load(&hypervisor, "hypervisor.rom")) error("Hypervisor", "No debugger found."); + if(!load(u, rom)) + return error("Boot", "Failed to load rom."); /* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo); /* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo); @@ -306,6 +305,7 @@ start(Uxn *u, char *rom) /* unused */ uxn_port(u, 0xf, nil_dei, nil_deo); /* Hypervisor */ + uxn_port(&hypervisor, 0x0, system_dei, system_deo); uxn_port(&hypervisor, 0x1, nil_dei, console_deo); uxn_port(&hypervisor, 0x2, screen_dei, screen_deo);