uxn

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

commit 1a7af4d8d0de7c63f119cc031df4656d818b4353
parent 28b92650420100de16e307e7dc074bfae3cd3f9a
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu,  6 Jan 2022 19:20:50 -0800

Supervisor is now watching the device page

Diffstat:
Mbuild.sh | 7++++---
Dprojects/software/hypervisor.tal | 215-------------------------------------------------------------------------------
Aprojects/software/supervisor.tal | 218+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/devices/system.c | 16++--------------
Msrc/devices/system.h | 4++--
Msrc/uxn.c | 7++++---
Msrc/uxn.h | 12+++++++-----
Msrc/uxnemu.c | 16++++++++--------
8 files changed, 245 insertions(+), 250 deletions(-)

diff --git a/build.sh b/build.sh @@ -36,7 +36,7 @@ echo "Cleaning.." rm -f ./bin/uxnasm rm -f ./bin/uxnemu rm -f ./bin/uxncli -rm -f ./bin/hypervisor.rom +rm -f ./bin/supervisor.rom rm -f ./bin/boot.rom rm -f ./bin/asma.rom @@ -106,9 +106,10 @@ then cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/ fi -echo "Assembling(boot+hypervisor).." +echo "Assembling(supervisor).." +./bin/uxnasm projects/software/supervisor.tal bin/supervisor.rom +echo "Assembling(boot).." ./bin/uxnasm projects/software/boot.tal bin/boot.rom -./bin/uxnasm projects/software/hypervisor.tal bin/hypervisor.rom echo "Assembling(asma).." ./bin/uxnasm projects/software/asma.tal bin/asma.rom diff --git a/projects/software/hypervisor.tal b/projects/software/hypervisor.tal @@ -1,214 +0,0 @@ -( launcher ) - -%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } -%< { LTH } %> { GTH } %= { EQU } %! { NEQ } -%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } -%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } - -%AUTO-X { #01 .Screen/auto DEO } -%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 - &wst - ( working stack ) - #0010 .Screen/y DEO2 - DUP2 #0018 ** #0010 ++ .Screen/x DEO2 - DUP #fe00 LDA ( ptr ) EQU #41 + STH - 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-byte JSR2 - INC2 GTH2k ,&wst JCN - POP2 POP2 - -RTN - -@draw-cross ( -- ) - - ( ver ) - AUTO-Y - #0000 .Screen/y DEO2 - .center/x LDZ2 .Screen/x DEO2 - .Screen/height DEI2 #0000 - &ver - #43 .Screen/pixel DEO - .Screen/y DEI2k INC2 ROT DEO2 - INC2 GTH2k ,&ver JCN - POP2 POP2 - - ( hor ) - AUTO-X - #0000 .Screen/x DEO2 - .center/y LDZ2 .Screen/y DEO2 - .Screen/width DEI2 #0000 - &hor - #43 .Screen/pixel DEO - .Screen/x DEI2k INC2 ROT DEO2 - INC2 GTH2k ,&hor JCN - POP2 POP2 - -RTN - -@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 - #0f AND ,&parse JSR STHr ,draw-char JSR - -RTN - &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r - &above #57 ADD JMP2r - -@draw-char ( char color -- ) - - SWP - [ #20 - #00 SWP #40 SFT2 ;font ++ ] .Screen/addr DEO2 - .Screen/sprite DEOk DEO - .Screen/x DEI2k #0008 ++ ROT DEO2 - .Screen/y DEI2k #0010 -- ROT DEO2 - -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/projects/software/supervisor.tal b/projects/software/supervisor.tal @@ -0,0 +1,217 @@ +( launcher ) + +%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } +%< { LTH } %> { GTH } %= { EQU } %! { NEQ } +%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } +%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } + +%AUTO-X { #01 .Screen/auto DEO } +%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 } + +%EADDR { #fd04 } +%ECODE { #fd06 } + +( 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 + + EADDR LDA2 #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 + + EADDR LDA2 #47 ;draw-short JSR2 + + #0000 EADDR STA2 + +BRK + +@draw-stacks ( -- ) + + AUTO-YADDR + #0010 #0000 + &wst + ( working stack ) + #0010 .Screen/y DEO2 + DUP2 #0018 ** #0010 ++ .Screen/x DEO2 + DUP #fe00 LDA ( ptr ) EQU #41 + STH + 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-byte JSR2 + INC2 GTH2k ,&wst JCN + POP2 POP2 + +RTN + +@draw-cross ( -- ) + + ( ver ) + AUTO-Y + #0000 .Screen/y DEO2 + .center/x LDZ2 .Screen/x DEO2 + .Screen/height DEI2 #0000 + &ver + #43 .Screen/pixel DEO + .Screen/y DEI2k INC2 ROT DEO2 + INC2 GTH2k ,&ver JCN + POP2 POP2 + + ( hor ) + AUTO-X + #0000 .Screen/x DEO2 + .center/y LDZ2 .Screen/y DEO2 + .Screen/width DEI2 #0000 + &hor + #43 .Screen/pixel DEO + .Screen/x DEI2k INC2 ROT DEO2 + INC2 GTH2k ,&hor JCN + POP2 POP2 + +RTN + +@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 + #0f AND ,&parse JSR STHr ,draw-char JSR + +RTN + &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r + &above #57 ADD JMP2r + +@draw-char ( char color -- ) + + SWP + [ #20 - #00 SWP #40 SFT2 ;font ++ ] .Screen/addr DEO2 + .Screen/sprite DEOk DEO + .Screen/x DEI2k #0008 ++ ROT DEO2 + .Screen/y DEI2k #0010 -- ROT DEO2 + +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,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -Uxn hypervisor; +Uxn supervisor; static const char *errors[] = { "Working-stack underflow", @@ -29,27 +29,15 @@ 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; - + uxn_eval(&supervisor, PAGE_PROGRAM); if(vec) { d->vector = 0; /* need to rearm to run System/vector again */ 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 @@ -13,4 +13,4 @@ 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 +extern Uxn supervisor; +\ No newline at end of file diff --git a/src/uxn.c b/src/uxn.c @@ -108,15 +108,16 @@ err: /* clang-format on */ int -uxn_boot(Uxn *u, Uint8 *ram, Uint8 *dev, Stack *wst, Stack *rst) +uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst) { Uint32 i; char *cptr = (char *)u; for(i = 0; i < sizeof(*u); i++) cptr[i] = 0x00; + u->ram = ram; + u->devpage = devpage; u->wst = wst; u->rst = rst; - u->ram = ram; return 1; } @@ -124,10 +125,10 @@ Device * uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port)) { Device *d = &u->dev[id]; - d->addr = id * 0x10; d->u = u; d->mem = u->ram; d->dei = deifn; d->deo = deofn; + d->dat = u->devpage + id * 0x10; return d; } diff --git a/src/uxn.h b/src/uxn.h @@ -16,6 +16,9 @@ typedef signed short Sint16; typedef unsigned int Uint32; #define PAGE_PROGRAM 0x0100 +#define VISOR_DEV 0xfa00 +#define VISOR_WST 0xfb00 +#define VISOR_RST 0xfc00 #define PAGE_DEV 0xfd00 #define PAGE_WST 0xfe00 #define PAGE_RST 0xff00 @@ -28,25 +31,24 @@ typedef unsigned int Uint32; /* clang-format on */ typedef struct { - Uint8 ptr; - Uint8 dat[255]; + Uint8 ptr, dat[255]; } Stack; typedef struct Device { struct Uxn *u; - Uint8 addr, dat[16], *mem; + Uint8 *dat, *mem; Uint16 vector; Uint8 (*dei)(struct Device *d, Uint8); void (*deo)(struct Device *d, Uint8); } Device; typedef struct Uxn { + Uint8 *ram, *devpage; Stack *wst, *rst; - Uint8 *ram; Device dev[16]; } Uxn; -int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *dev, Stack *wst, Stack *rst); +int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devpage, Stack *wst, Stack *rst); int uxn_eval(Uxn *u, Uint16 pc); int uxn_halt(Uxn *u, Uint8 error, Uint16 addr); Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8)); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -278,12 +278,12 @@ start(Uxn *u, char *rom) memory = (Uint8 *)calloc(0xffff, sizeof(Uint8)); shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8)); - if(!uxn_boot(&hypervisor, shadow, shadow + PAGE_DEV, (Stack *)(shadow + 0xfb00), (Stack *)(shadow + 0xfc00))) + if(!uxn_boot(&supervisor, shadow, shadow + VISOR_DEV, (Stack *)(shadow + VISOR_WST), (Stack *)(shadow + VISOR_RST))) return error("Boot", "Failed to start uxn."); if(!uxn_boot(u, memory, shadow + PAGE_DEV, (Stack *)(shadow + PAGE_WST), (Stack *)(shadow + PAGE_RST))) return error("Boot", "Failed to start uxn."); - if(!load(&hypervisor, "hypervisor.rom")) - error("Hypervisor", "No debugger found."); + if(!load(&supervisor, "supervisor.rom")) + error("Supervisor", "No debugger found."); if(!load(u, rom)) return error("Boot", "Failed to load rom."); @@ -304,10 +304,10 @@ start(Uxn *u, char *rom) /* unused */ uxn_port(u, 0xe, nil_dei, nil_deo); /* 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); + /* Supervisor */ + uxn_port(&supervisor, 0x0, system_dei, system_deo); + uxn_port(&supervisor, 0x1, nil_dei, console_deo); + uxn_port(&supervisor, 0x2, screen_dei, screen_deo); if(!uxn_eval(u, PAGE_PROGRAM)) return error("Boot", "Failed to start rom."); @@ -485,7 +485,7 @@ run(Uxn *u) console_input(u, event.cbutton.button); } if(devsystem->dat[0xe]) - uxn_eval(&hypervisor, PAGE_PROGRAM); + uxn_eval(&supervisor, PAGE_PROGRAM); uxn_eval(u, devscreen->vector); if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe]) redraw();