Supervisor is now watching the device page

This commit is contained in:
neauoire 2022-01-06 19:20:50 -08:00
parent 28b9265042
commit 1a7af4d8d0
7 changed files with 32 additions and 37 deletions

View File

@ -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

View File

@ -22,6 +22,9 @@
%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
@ -51,7 +54,7 @@
;draw-cross JSR2
;draw-stacks JSR2
.System/eaddr DEI2 #0000 !! ;on-error JCN2
EADDR LDA2 #0000 !! ;on-error JCN2
BRK
@ -93,9 +96,9 @@ BRK
;at-txt #4f ;draw-str JSR2
.System/eaddr DEI2 #47 ;draw-short JSR2
EADDR LDA2 #47 ;draw-short JSR2
#0000 .System/eaddr DEO2
#0000 EADDR STA2
BRK

View File

@ -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;
}

View File

@ -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;
extern Uxn supervisor;

View File

@ -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;
}

View File

@ -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));

View File

@ -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();