0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-23 22:35:11 +00:00

Started work on the hypervisor

This commit is contained in:
neauoire 2022-01-05 19:48:51 -08:00
parent 4cd52209ac
commit b9a37077c3
5 changed files with 25 additions and 17 deletions

View file

@ -45,8 +45,8 @@ Uint8
system_dei(Device *d, Uint8 port)
{
switch(port) {
case 0x2: return d->u->wst.ptr;
case 0x3: return d->u->rst.ptr;
case 0x2: return d->u->wst->ptr;
case 0x3: return d->u->rst->ptr;
default: return d->dat[port];
}
}
@ -56,8 +56,8 @@ system_deo(Device *d, Uint8 port)
{
switch(port) {
case 0x1: DEVPEEK16(d->vector, 0x0); break;
case 0x2: d->u->wst.ptr = d->dat[port]; break;
case 0x3: d->u->rst.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;
default: system_deo_special(d, port);
}
}

View file

@ -39,13 +39,13 @@ uxn_eval(Uxn *u, Uint16 pc)
Stack *src, *dst;
Device *dev;
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++])) {
/* Return Mode */
if(instr & 0x40) {
src = &u->rst; dst = &u->wst;
src = u->rst; dst = u->wst;
} else {
src = &u->wst; dst = &u->rst;
src = u->wst; dst = u->rst;
}
/* Keep Mode */
if(instr & 0x80) {
@ -108,12 +108,14 @@ err:
/* clang-format on */
int
uxn_boot(Uxn *u, Uint8 *memory)
uxn_boot(Uxn *u, Stack *wst, Stack *rst, Uint8 *memory)
{
Uint32 i;
char *cptr = (char *)u;
for(i = 0; i < sizeof(*u); i++)
cptr[i] = 0x00;
u->wst = wst;
u->rst = rst;
u->ram = memory;
return 1;
}

View file

@ -38,12 +38,12 @@ typedef struct Device {
} Device;
typedef struct Uxn {
Stack wst, rst;
Stack *wst, *rst;
Uint8 *ram;
Device dev[16];
} Uxn;
int uxn_boot(Uxn *c, Uint8 *memory);
int uxn_boot(Uxn *u, Stack *wst, Stack *rst, Uint8 *memory);
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

@ -50,8 +50,8 @@ void
system_deo_special(Device *d, Uint8 port)
{
if(port == 0xe) {
inspect(&d->u->wst, "Working-stack");
inspect(&d->u->rst, "Return-stack");
inspect(d->u->wst, "Working-stack");
inspect(d->u->rst, "Return-stack");
}
}
@ -133,7 +133,7 @@ load(Uxn *u, char *filepath)
return 1;
}
static Uint8 *memory;
static Uint8 *shadow, *memory;
int
main(int argc, char **argv)
@ -141,8 +141,9 @@ main(int argc, char **argv)
Uxn u;
int i, loaded = 0;
shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8));
memory = (Uint8 *)calloc(0xffff, sizeof(Uint8));
if(!uxn_boot(&u, memory))
if(!uxn_boot(&u, (Stack *)(shadow + 0x200), (Stack *)(shadow + 0x400), memory))
return error("Boot", "Failed");
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo);

View file

@ -44,6 +44,7 @@ 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)
@ -126,7 +127,7 @@ static void
redraw(Uxn *u)
{
if(devsystem->dat[0xe])
screen_debug(&uxn_screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram);
screen_debug(&uxn_screen, u->wst->dat, u->wst->ptr, u->rst->ptr, u->ram);
screen_redraw(&uxn_screen, uxn_screen.pixels);
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
error("SDL_UpdateTexture", SDL_GetError());
@ -272,13 +273,17 @@ load(Uxn *u, char *rom)
return 1;
}
static Uint8 *memory;
static Uint8 *shadow, *memory;
static int
start(Uxn *u, char *rom)
{
memory = (Uint8 *)calloc(0xffff, sizeof(Uint8));
if(!uxn_boot(u, memory))
shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8));
if(!uxn_boot(&hypervisor, (Stack *)(shadow + 0x600), (Stack *)(shadow + 0x800), shadow))
return error("Boot", "Failed to start uxn.");
if(!uxn_boot(u, (Stack *)(shadow + 0x200), (Stack *)(shadow + 0x400), memory))
return error("Boot", "Failed to start uxn.");
if(!load(u, rom))
return error("Boot", "Failed to load rom.");