mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-27 16:23:02 +00:00
Started work on the hypervisor
This commit is contained in:
parent
4cd52209ac
commit
b9a37077c3
5 changed files with 25 additions and 17 deletions
|
@ -45,8 +45,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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,8 @@ system_deo(Device *d, Uint8 port)
|
||||||
{
|
{
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x1: DEVPEEK16(d->vector, 0x0); break;
|
case 0x1: DEVPEEK16(d->vector, 0x0); break;
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/uxn.c
10
src/uxn.c
|
@ -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) {
|
||||||
|
@ -108,12 +108,14 @@ err:
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
int
|
int
|
||||||
uxn_boot(Uxn *u, Uint8 *memory)
|
uxn_boot(Uxn *u, Stack *wst, Stack *rst, Uint8 *memory)
|
||||||
{
|
{
|
||||||
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->wst = wst;
|
||||||
|
u->rst = rst;
|
||||||
u->ram = memory;
|
u->ram = memory;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,12 @@ typedef struct Device {
|
||||||
} Device;
|
} Device;
|
||||||
|
|
||||||
typedef struct Uxn {
|
typedef struct Uxn {
|
||||||
Stack wst, rst;
|
Stack *wst, *rst;
|
||||||
Uint8 *ram;
|
Uint8 *ram;
|
||||||
Device dev[16];
|
Device dev[16];
|
||||||
} Uxn;
|
} 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_eval(Uxn *u, Uint16 pc);
|
||||||
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
|
int uxn_halt(Uxn *u, Uint8 error, Uint16 addr);
|
||||||
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|
Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8));
|
||||||
|
|
|
@ -50,8 +50,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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ load(Uxn *u, char *filepath)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *memory;
|
static Uint8 *shadow, *memory;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
|
@ -141,8 +141,9 @@ main(int argc, char **argv)
|
||||||
Uxn u;
|
Uxn u;
|
||||||
int i, loaded = 0;
|
int i, loaded = 0;
|
||||||
|
|
||||||
|
shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8));
|
||||||
memory = (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");
|
return error("Boot", "Failed");
|
||||||
|
|
||||||
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo);
|
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo);
|
||||||
|
|
11
src/uxnemu.c
11
src/uxnemu.c
|
@ -44,6 +44,7 @@ static SDL_Rect gRect;
|
||||||
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
||||||
static Uint8 zoom = 1;
|
static Uint8 zoom = 1;
|
||||||
static Uint32 stdin_event, audio0_event;
|
static Uint32 stdin_event, audio0_event;
|
||||||
|
static Uxn hypervisor;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
clamp(int val, int min, int max)
|
clamp(int val, int min, int max)
|
||||||
|
@ -126,7 +127,7 @@ static void
|
||||||
redraw(Uxn *u)
|
redraw(Uxn *u)
|
||||||
{
|
{
|
||||||
if(devsystem->dat[0xe])
|
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);
|
screen_redraw(&uxn_screen, uxn_screen.pixels);
|
||||||
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
|
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
|
||||||
error("SDL_UpdateTexture", SDL_GetError());
|
error("SDL_UpdateTexture", SDL_GetError());
|
||||||
|
@ -272,13 +273,17 @@ load(Uxn *u, char *rom)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *memory;
|
static Uint8 *shadow, *memory;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
start(Uxn *u, char *rom)
|
start(Uxn *u, char *rom)
|
||||||
{
|
{
|
||||||
memory = (Uint8 *)calloc(0xffff, sizeof(Uint8));
|
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.");
|
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.");
|
||||||
|
|
Loading…
Reference in a new issue