Stacks are mapped in ram
This commit is contained in:
parent
461bb5ae32
commit
defceb7851
16
README.md
16
README.md
|
@ -2,6 +2,22 @@
|
||||||
|
|
||||||
An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C.
|
An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C.
|
||||||
|
|
||||||
|
## Uxn11/System
|
||||||
|
|
||||||
|
This emulator's system device supports changing a stack's location to a page of memory. The default memory mapping is as follows:
|
||||||
|
|
||||||
|
- `0000-ffff`, as **RAM**.
|
||||||
|
- `10000-100ff`, as **working stack**.
|
||||||
|
- `10100-101ff`, as **return stack**.
|
||||||
|
|
||||||
|
To use the last page of ram(`0xff00`) to host the working stack:
|
||||||
|
|
||||||
|
```
|
||||||
|
#ff .System/wst DEO
|
||||||
|
```
|
||||||
|
|
||||||
|
The stack mapping is 254 bytes of data, a byte for the pointer and a byte for an error code.
|
||||||
|
|
||||||
## Graphical
|
## Graphical
|
||||||
|
|
||||||
All you need is X11.
|
All you need is X11.
|
||||||
|
|
13
build.sh
13
build.sh
|
@ -8,11 +8,16 @@ rm -f ./bin/*
|
||||||
echo "Building.."
|
echo "Building.."
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
|
|
||||||
# Build(debug)
|
if [ "${1}" = '--install' ];
|
||||||
|
then
|
||||||
|
echo "Installing.."
|
||||||
|
gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
|
||||||
|
gcc src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxncli
|
||||||
|
cp bin/uxn11 ~/bin
|
||||||
|
else
|
||||||
gcc -std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11
|
gcc -std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11
|
||||||
|
gcc -std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli
|
||||||
# Build(release)
|
fi
|
||||||
# gcc src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
|
|
||||||
|
|
||||||
echo "Running.."
|
echo "Running.."
|
||||||
bin/uxn11 ~/roms/left.rom # etc/mouse.rom
|
bin/uxn11 ~/roms/left.rom # etc/mouse.rom
|
||||||
|
|
|
@ -37,8 +37,8 @@ system_print(Stack *s, char *name)
|
||||||
void
|
void
|
||||||
system_inspect(Uxn *u)
|
system_inspect(Uxn *u)
|
||||||
{
|
{
|
||||||
system_print(&u->wst, "wst");
|
system_print(u->wst, "wst");
|
||||||
system_print(&u->rst, "rst");
|
system_print(u->rst, "rst");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -51,22 +51,12 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
|
||||||
|
|
||||||
/* IO */
|
/* IO */
|
||||||
|
|
||||||
Uint8
|
|
||||||
system_dei(Device *d, Uint8 port)
|
|
||||||
{
|
|
||||||
switch(port) {
|
|
||||||
case 0x2: return d->u->wst.ptr;
|
|
||||||
case 0x3: return d->u->rst.ptr;
|
|
||||||
default: return d->dat[port];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
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 = (Stack*)(d->u->ram + (d->dat[port] ? (d->dat[port] * 0x100) : 0x10000)); break;
|
||||||
case 0x3: d->u->rst.ptr = d->dat[port]; break;
|
case 0x3: d->u->rst = (Stack*)(d->u->ram + (d->dat[port] ? (d->dat[port] * 0x100) : 0x10100)); break;
|
||||||
case 0xe: system_inspect(d->u); break;
|
case 0xe: system_inspect(d->u); break;
|
||||||
default: system_deo_special(d, port);
|
default: system_deo_special(d, port);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,5 @@ typedef struct SystemDevice {
|
||||||
} SystemDevice;
|
} SystemDevice;
|
||||||
|
|
||||||
void system_inspect(Uxn *u);
|
void system_inspect(Uxn *u);
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -38,9 +38,9 @@ uxn_eval(Uxn *u, Uint16 pc)
|
||||||
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) {
|
||||||
|
@ -110,6 +110,8 @@ uxn_boot(Uxn *u, Uint8 *ram)
|
||||||
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->wst = (Stack*)(ram + 0x10000);
|
||||||
|
u->rst = (Stack*)(ram + 0x10100);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ typedef unsigned int Uint32;
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Uint8 ptr, dat[255];
|
Uint8 dat[255],ptr;
|
||||||
} Stack;
|
} Stack;
|
||||||
|
|
||||||
typedef struct Device {
|
typedef struct Device {
|
||||||
|
@ -38,7 +38,7 @@ typedef struct Device {
|
||||||
|
|
||||||
typedef struct Uxn {
|
typedef struct Uxn {
|
||||||
Uint8 *ram;
|
Uint8 *ram;
|
||||||
Stack wst, rst;
|
Stack *wst, *rst;
|
||||||
Device dev[16];
|
Device dev[16];
|
||||||
} Uxn;
|
} Uxn;
|
||||||
|
|
||||||
|
|
|
@ -155,12 +155,12 @@ processEvent(void)
|
||||||
static int
|
static int
|
||||||
start(Uxn *u, char *rom)
|
start(Uxn *u, char *rom)
|
||||||
{
|
{
|
||||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
|
if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
|
||||||
return error("Boot", "Failed");
|
return error("Boot", "Failed");
|
||||||
if(!load_rom(u, rom))
|
if(!load_rom(u, rom))
|
||||||
return error("Load", "Failed");
|
return error("Load", "Failed");
|
||||||
fprintf(stderr, "Loaded %s\n", rom);
|
fprintf(stderr, "Loaded %s\n", rom);
|
||||||
/* system */ uxn_port(u, 0x0, system_dei, system_deo);
|
/* system */ uxn_port(u, 0x0, nil_dei, system_deo);
|
||||||
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
||||||
/* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
|
/* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
|
||||||
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
||||||
|
|
|
@ -83,9 +83,9 @@ uxn_interrupt(void)
|
||||||
static int
|
static int
|
||||||
start(Uxn *u)
|
start(Uxn *u)
|
||||||
{
|
{
|
||||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
|
if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
|
||||||
return error("Boot", "Failed");
|
return error("Boot", "Failed");
|
||||||
/* system */ uxn_port(u, 0x0, system_dei, system_deo);
|
/* system */ uxn_port(u, 0x0, nil_dei, system_deo);
|
||||||
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
||||||
/* empty */ uxn_port(u, 0x2, nil_dei, nil_deo);
|
/* empty */ uxn_port(u, 0x2, nil_dei, nil_deo);
|
||||||
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
||||||
|
|
Loading…
Reference in New Issue