0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-30 01:33:01 +00:00

Removed supervisor

This commit is contained in:
neauoire 2022-01-12 18:40:51 -08:00
parent 0518385a6d
commit 459855d825
11 changed files with 25 additions and 390 deletions

6
TODO
View file

@ -1,6 +0,0 @@
# TODOs
- Emulation controls should be handled by the supervisor.
- Overlap the supervisor device page with the core device page.
- The boot rom should display "no roms" when the list is empty.
-

View file

@ -36,7 +36,6 @@ echo "Cleaning.."
rm -f ./bin/uxnasm rm -f ./bin/uxnasm
rm -f ./bin/uxnemu rm -f ./bin/uxnemu
rm -f ./bin/uxncli rm -f ./bin/uxncli
rm -f ./bin/supervisor.rom
rm -f ./bin/launcher.rom rm -f ./bin/launcher.rom
rm -f ./bin/asma.rom rm -f ./bin/asma.rom
@ -108,8 +107,6 @@ then
cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/ cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
fi fi
echo "Assembling(supervisor).."
./bin/uxnasm projects/software/supervisor.tal bin/supervisor.rom
echo "Assembling(launcher).." echo "Assembling(launcher).."
./bin/uxnasm projects/software/launcher.tal bin/launcher.rom ./bin/uxnasm projects/software/launcher.tal bin/launcher.rom
echo "Assembling(asma).." echo "Assembling(asma).."

View file

@ -1,314 +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 }
%SYS_EADDR { #fd04 }
%SYS_ECODE { #fd06 }
%SYS_DEBUG { #fd0e }
%WST { #fe00 }
%RST { #ff00 }
( 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
|80 @Controller &vector $2 &button $1 &key $1 &func $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
( vectors )
;on-error .System/vector DEO2
;on-frame .Screen/vector DEO2
;on-button .Controller/vector DEO2
( print initial memory )
SYS_DEBUG LDA #00 = ,&no-debug JCN
;print-stacks JSR2
&no-debug
BRK
@on-frame ( -> )
;draw-cross JSR2
;draw-stacks JSR2
BRK
@on-button ( -> )
.Controller/func DEI DUP DEBUG
DUP #02 ! ,&no-f2 JCN
;toggle-debugger JSR2
&no-f2
DUP #08 ! ,&no-f4 JCN
;reboot JSR2
&no-f4
POP
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
SYS_EADDR LDA2 #47 ;draw-short JSR2
#0000 SYS_EADDR STA2
BRK
@toggle-debugger ( -- )
( toggle debug )
( #fd0e STH2k LDA #00 = STH2r STA )
RTN
@reboot ( -- )
( clear devices/stacks )
#fd00 #0300 ;mclr JSR2
( load rom )
RTN
&boot-path "launcher.rom $1
@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
@mclr ( addr* len* -- )
OVR2 ++ SWP2
&loop
STH2k #00 STH2r STA
INC2 GTH2k ,&loop JCN
POP2 POP2
JMP2r
@print-stacks ( -- )
#0a EMIT
WST ;&wst-txt ,print-stack JSR
RST ;&rst-txt ,print-stack JSR
RTN
&wst-txt "Working-stack $1
&rst-txt "Return-stack $1
@print-stack ( addr* name* -- )
PRINT
( keep ptr ) LDAk STH
( keep counter ) LITr 00
( skip ptr ) INC2
DUP2 #0020 ++ SWP2
&loop
( print cell )
EQUkr STHr #3b * #20 + EMIT
LDAk ;print-hex/byte JSR2
EQUkr STHr #3d * #20 + EMIT
( break into columns )
SUB2k #0001 -- #0007 AND2 #0000 !! ,&no-lb JCN
#0a EMIT
&no-lb
INCr
INC2 GTH2k ,&loop JCN
POP2 POP2
POP2r
RTN
@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
@print-str ( string* -- )
#0001 SUB2
&while
INC2 LDAk DUP #18 DEO ,&while JCN
POP2
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

View file

@ -150,7 +150,7 @@ file_deo(Device *d, Uint8 port)
case 0x5: case 0x5:
DEVPEEK16(a, 0x4); DEVPEEK16(a, 0x4);
DEVPEEK16(b, 0xa); DEVPEEK16(b, 0xa);
res = file_stat(&bank1[a], b); res = file_stat(&bank0[a], b);
DEVPOKE16(0x2, res); DEVPOKE16(0x2, res);
break; break;
case 0x6: case 0x6:
@ -159,19 +159,19 @@ file_deo(Device *d, Uint8 port)
break; break;
case 0x9: case 0x9:
DEVPEEK16(a, 0x8); DEVPEEK16(a, 0x8);
res = file_init(&bank1[a]); res = file_init(&bank0[a]);
DEVPOKE16(0x2, res); DEVPOKE16(0x2, res);
break; break;
case 0xd: case 0xd:
DEVPEEK16(a, 0xc); DEVPEEK16(a, 0xc);
DEVPEEK16(b, 0xa); DEVPEEK16(b, 0xa);
res = file_read(&bank1[a], b); res = file_read(&bank0[a], b);
DEVPOKE16(0x2, res); DEVPOKE16(0x2, res);
break; break;
case 0xf: case 0xf:
DEVPEEK16(a, 0xe); DEVPEEK16(a, 0xe);
DEVPEEK16(b, 0xa); DEVPEEK16(b, 0xa);
res = file_write(&bank1[a], b, d->dat[0x7]); res = file_write(&bank0[a], b, d->dat[0x7]);
DEVPOKE16(0x2, res); DEVPOKE16(0x2, res);
break; break;
} }

View file

@ -12,4 +12,4 @@ WITH REGARD TO THIS SOFTWARE.
void file_deo(Device *d, Uint8 port); void file_deo(Device *d, Uint8 port);
extern Uint8 *bank1; extern Uint8 *bank0;

View file

@ -14,8 +14,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE. WITH REGARD TO THIS SOFTWARE.
*/ */
Uxn supervisor;
static const char *errors[] = { static const char *errors[] = {
"Working-stack underflow", "Working-stack underflow",
"Return-stack underflow", "Return-stack underflow",
@ -31,7 +29,6 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
Uint16 vec = GETVECTOR(d); Uint16 vec = GETVECTOR(d);
DEVPOKE16(0x4, addr); DEVPOKE16(0x4, addr);
d->dat[0x6] = error; d->dat[0x6] = error;
uxn_eval(&supervisor, GETVECTOR(&supervisor.dev[0]));
if(vec) { if(vec) {
/* need to rearm to run System/vector again */ /* need to rearm to run System/vector again */
d->dat[0] = 0; d->dat[0] = 0;
@ -50,8 +47,8 @@ Uint8
system_dei(Device *d, Uint8 port) system_dei(Device *d, Uint8 port)
{ {
switch(port) { switch(port) {
case 0x2: return d->u->wst->ptr; case 0x2: return d->u->wst.ptr;
case 0x3: return d->u->rst->ptr; case 0x3: return d->u->rst.ptr;
default: return d->dat[port]; default: return d->dat[port];
} }
} }
@ -60,8 +57,8 @@ void
system_deo(Device *d, Uint8 port) system_deo(Device *d, Uint8 port)
{ {
switch(port) { switch(port) {
case 0x2: d->u->wst->ptr = d->dat[port]; break; case 0x2: d->u->wst.ptr = d->dat[port]; break;
case 0x3: d->u->rst->ptr = d->dat[port]; break; case 0x3: d->u->rst.ptr = d->dat[port]; break;
default: system_deo_special(d, port); default: system_deo_special(d, port);
} }
} }

View file

@ -12,5 +12,3 @@ WITH REGARD TO THIS SOFTWARE.
Uint8 system_dei(Device *d, Uint8 port); Uint8 system_dei(Device *d, Uint8 port);
void system_deo(Device *d, Uint8 port); void system_deo(Device *d, Uint8 port);
void system_deo_special(Device *d, Uint8 port); void system_deo_special(Device *d, Uint8 port);
extern Uxn supervisor;

View file

@ -39,13 +39,13 @@ uxn_eval(Uxn *u, Uint16 pc)
Stack *src, *dst; Stack *src, *dst;
Device *dev; Device *dev;
if(!pc || u->dev[0].dat[0xf]) return 0; if(!pc || u->dev[0].dat[0xf]) return 0;
if(u->wst->ptr > 0xf8) u->wst->ptr = 0xf8; if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8;
while((instr = u->ram[pc++])) { while((instr = u->ram[pc++])) {
/* Return Mode */ /* Return Mode */
if(instr & 0x40) { if(instr & 0x40) {
src = u->rst; dst = u->wst; src = &u->rst; dst = &u->wst;
} else { } else {
src = u->wst; dst = u->rst; src = &u->wst; dst = &u->rst;
} }
/* Keep Mode */ /* Keep Mode */
if(instr & 0x80) { if(instr & 0x80) {
@ -112,16 +112,13 @@ err:
/* clang-format on */ /* clang-format on */
int int
uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devices, Stack *wst, Stack *rst) uxn_boot(Uxn *u, Uint8 *ram)
{ {
Uint32 i; Uint32 i;
char *cptr = (char *)u; char *cptr = (char *)u;
for(i = 0; i < sizeof(*u); i++) for(i = 0; i < sizeof(*u); i++)
cptr[i] = 0x00; cptr[i] = 0x00;
u->ram = ram; u->ram = ram;
u->devices = devices;
u->wst = wst;
u->rst = rst;
return 1; return 1;
} }
@ -130,7 +127,6 @@ uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(
{ {
Device *d = &u->dev[id]; Device *d = &u->dev[id];
d->u = u; d->u = u;
d->dat = u->devices + id * 0x10;
d->dei = deifn; d->dei = deifn;
d->deo = deofn; d->deo = deofn;
return d; return d;

View file

@ -37,18 +37,18 @@ typedef struct {
typedef struct Device { typedef struct Device {
struct Uxn *u; struct Uxn *u;
Uint8 *dat, *mem; Uint8 dat[16], *mem;
Uint8 (*dei)(struct Device *d, Uint8); Uint8 (*dei)(struct Device *d, Uint8);
void (*deo)(struct Device *d, Uint8); void (*deo)(struct Device *d, Uint8);
} Device; } Device;
typedef struct Uxn { typedef struct Uxn {
Uint8 *ram, *devices; Uint8 *ram;
Stack *wst, *rst; Stack wst, rst;
Device dev[16]; Device dev[16];
} Uxn; } Uxn;
int uxn_boot(Uxn *u, Uint8 *ram, Uint8 *devices, Stack *wst, Stack *rst); int uxn_boot(Uxn *u, Uint8 *ram);
int uxn_eval(Uxn *u, Uint16 pc); int uxn_eval(Uxn *u, Uint16 pc);
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr); int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
int uxn_interrupt(Uxn *u); int uxn_interrupt(Uxn *u);

View file

@ -3,7 +3,7 @@
#include "uxn.h" #include "uxn.h"
Uint8 *bank0, *bank1; Uint8 *bank0;
#include "devices/system.h" #include "devices/system.h"
#include "devices/file.h" #include "devices/file.h"
@ -23,6 +23,7 @@ WITH REGARD TO THIS SOFTWARE.
int int
uxn_interrupt(Uxn *u) uxn_interrupt(Uxn *u)
{ {
(void)u;
return 0; return 0;
} }
@ -53,8 +54,8 @@ void
system_deo_special(Device *d, Uint8 port) system_deo_special(Device *d, Uint8 port)
{ {
if(port == 0xe) { if(port == 0xe) {
inspect(d->u->wst, "Working-stack"); inspect(&d->u->wst, "Working-stack");
inspect(d->u->rst, "Return-stack"); inspect(&d->u->rst, "Return-stack");
} }
} }
@ -118,8 +119,7 @@ static int
start(Uxn *u) start(Uxn *u)
{ {
bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8));
bank1 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); if(!uxn_boot(u, bank0))
if(!uxn_boot(u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST)))
return error("Boot", "Failed"); return error("Boot", "Failed");
/* system */ uxn_port(u, 0x0, system_dei, system_deo); /* system */ uxn_port(u, 0x0, system_dei, system_deo);
/* console */ uxn_port(u, 0x1, nil_dei, console_deo); /* console */ uxn_port(u, 0x1, nil_dei, console_deo);

View file

@ -3,7 +3,7 @@
#include "uxn.h" #include "uxn.h"
Uint8 *bank0, *bank1; Uint8 *bank0;
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma clang diagnostic push #pragma clang diagnostic push
@ -87,6 +87,7 @@ audio_finished_handler(UxnAudio *c)
int int
uxn_interrupt(Uxn *u) uxn_interrupt(Uxn *u)
{ {
(void)u;
return 0; return 0;
} }
@ -261,10 +262,9 @@ load(Uxn *u, char *rom)
static int static int
start(Uxn *u, char *rom) start(Uxn *u, char *rom)
{ {
bank1 = (Uint8 *)calloc(0x10000, sizeof(Uint8));
bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8));
if(!uxn_boot(u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) if(!uxn_boot(u, bank0))
return error("Boot", "Failed to start uxn."); return error("Boot", "Failed to start uxn.");
if(!load(u, rom)) if(!load(u, rom))
return error("Boot", "Failed to load rom."); return error("Boot", "Failed to load rom.");
@ -285,21 +285,9 @@ start(Uxn *u, char *rom)
/* unused */ uxn_port(u, 0xe, nil_dei, nil_deo); /* unused */ uxn_port(u, 0xe, nil_dei, nil_deo);
/* unused */ uxn_port(u, 0xf, nil_dei, nil_deo); /* unused */ uxn_port(u, 0xf, nil_dei, nil_deo);
/* Supervisor */
if(!uxn_boot(&supervisor, bank0, bank0 + VISOR_DEV, (Stack *)(bank0 + VISOR_WST), (Stack *)(bank0 + VISOR_RST)))
return error("Boot", "Failed to start uxn.");
if(!load(&supervisor, "supervisor.rom"))
error("Supervisor", "No debugger found.");
/* system */ uxn_port(&supervisor, 0x0, system_dei, system_deo);
/* console */ uxn_port(&supervisor, 0x1, nil_dei, console_deo);
/* screen */ uxn_port(&supervisor, 0x2, screen_dei, screen_deo);
/* control */ uxn_port(&supervisor, 0x8, nil_dei, nil_deo);
if(!uxn_eval(u, PAGE_PROGRAM)) if(!uxn_eval(u, PAGE_PROGRAM))
return error("Boot", "Failed to start rom."); return error("Boot", "Failed to start rom.");
uxn_eval(&supervisor, PAGE_PROGRAM);
return 1; return 1;
} }
@ -357,22 +345,6 @@ get_button(SDL_Event *event)
return 0x00; return 0x00;
} }
static Uint8
get_fkey(SDL_Event *event)
{
switch(event->key.keysym.sym) {
case SDLK_F1: return 0x01;
case SDLK_F2: return 0x02;
case SDLK_F3: return 0x04;
case SDLK_F4: return 0x08;
case SDLK_F5: return 0x10;
case SDLK_F6: return 0x20;
case SDLK_F7: return 0x40;
case SDLK_F8: return 0x80;
}
return 0x00;
}
static Uint8 static Uint8
get_button_joystick(SDL_Event *event) get_button_joystick(SDL_Event *event)
{ {
@ -468,9 +440,6 @@ run(Uxn *u)
controller_down(devctrl, get_button(&event)); controller_down(devctrl, get_button(&event));
else else
do_shortcut(u, &event); do_shortcut(u, &event);
/* function keys are sent to supervisor */
if(get_fkey(&event))
controller_special(&supervisor.dev[0x8], get_fkey(&event));
ksym = event.key.keysym.sym; ksym = event.key.keysym.sym;
if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym) if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym)
break; break;
@ -490,8 +459,6 @@ run(Uxn *u)
else if(event.type == stdin_event) else if(event.type == stdin_event)
console_input(u, event.cbutton.button); console_input(u, event.cbutton.button);
} }
if(devsystem->dat[0xe])
uxn_eval(&supervisor, GETVECTOR(&supervisor.dev[2]));
uxn_eval(u, GETVECTOR(devscreen)); uxn_eval(u, GETVECTOR(devscreen));
if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe]) if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe])
redraw(); redraw();