Ported uxncli to latest device I/O
This commit is contained in:
parent
62a35a9b15
commit
c9ad8e9e43
6
build.sh
6
build.sh
|
@ -4,6 +4,7 @@ if [ "${1}" = '--format' ];
|
|||
then
|
||||
echo "Formatting.."
|
||||
clang-format -i src/uxn11.c
|
||||
clang-format -i src/uxncli.c
|
||||
clang-format -i src/devices/*
|
||||
fi
|
||||
|
||||
|
@ -17,11 +18,12 @@ 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
|
||||
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
|
||||
cp bin/uxncli ~/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/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli
|
||||
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
|
||||
fi
|
||||
|
||||
echo "Done."
|
||||
|
|
|
@ -58,6 +58,5 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
|
|||
case 0x2: u->wst = (Stack *)(u->ram + (d[port] ? (d[port] * 0x100) : 0x10000)); break;
|
||||
case 0x3: u->rst = (Stack *)(u->ram + (d[port] ? (d[port] * 0x100) : 0x10100)); break;
|
||||
case 0xe: system_inspect(u); break;
|
||||
default: system_deo_special(d, port);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,3 @@ WITH REGARD TO THIS SOFTWARE.
|
|||
|
||||
void system_inspect(Uxn *u);
|
||||
void system_deo(Uxn *u, Uint8 *d, Uint8 port);
|
||||
void system_deo_special(Uint8 *d, Uint8 port);
|
||||
|
|
23
src/uxn11.c
23
src/uxn11.c
|
@ -30,13 +30,6 @@ error(char *msg, const char *err)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
system_deo_special(Uint8 *d, Uint8 port)
|
||||
{
|
||||
if(port > 0x7 && port < 0xe)
|
||||
screen_palette(&uxn_screen, &d[0x8]);
|
||||
}
|
||||
|
||||
static int
|
||||
console_input(Uxn *u, char c)
|
||||
{
|
||||
|
@ -61,10 +54,10 @@ uxn11_dei(struct Uxn *u, Uint8 addr)
|
|||
{
|
||||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||
switch(d) {
|
||||
case 0x20: return screen_dei(&u->dev[d], p); break;
|
||||
case 0xa0: return file_dei(0, &u->dev[d], p); break;
|
||||
case 0xb0: return file_dei(1, &u->dev[d], p); break;
|
||||
case 0xc0: return datetime_dei(&u->dev[d], p); break;
|
||||
case 0x20: return screen_dei(&u->dev[d], p);
|
||||
case 0xa0: return file_dei(0, &u->dev[d], p);
|
||||
case 0xb0: return file_dei(1, &u->dev[d], p);
|
||||
case 0xc0: return datetime_dei(&u->dev[d], p);
|
||||
}
|
||||
return u->dev[addr];
|
||||
}
|
||||
|
@ -75,7 +68,11 @@ uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
|
|||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||
u->dev[addr] = v;
|
||||
switch(d) {
|
||||
case 0x00: system_deo(u, &u->dev[d], p); break;
|
||||
case 0x00:
|
||||
system_deo(u, &u->dev[d], p);
|
||||
if(p > 0x7 && p < 0xe)
|
||||
screen_palette(&uxn_screen, &u->dev[0x8]);
|
||||
break;
|
||||
case 0x10: console_deo(&u->dev[d], p); break;
|
||||
case 0x20: screen_deo(u->ram, &u->dev[d], p); break;
|
||||
case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
|
||||
|
@ -171,7 +168,7 @@ start(Uxn *u, char *rom)
|
|||
return error("Boot", "Failed");
|
||||
if(!load_rom(u, rom))
|
||||
return error("Load", "Failed");
|
||||
fprintf(stderr, "Loaded %s\n", rom);
|
||||
fprintf(stderr, ">> Loaded %s\n", rom);
|
||||
u->dei = uxn11_dei;
|
||||
u->deo = uxn11_deo;
|
||||
screen_resize(&uxn_screen, WIDTH, HEIGHT);
|
||||
|
|
66
src/uxncli.c
66
src/uxncli.c
|
@ -24,50 +24,54 @@ error(char *msg, const char *err)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
system_deo_special(Uint8 *d, Uint8 port)
|
||||
static int
|
||||
console_input(Uxn *u, char c)
|
||||
{
|
||||
(void)d;
|
||||
(void)port;
|
||||
Uint8 *d = &u->dev[0x10];
|
||||
d[0x02] = c;
|
||||
return uxn_eval(u, GETVEC(d));
|
||||
}
|
||||
|
||||
static void
|
||||
console_deo(Device *d, Uint8 port)
|
||||
console_deo(Uint8 *d, Uint8 port)
|
||||
{
|
||||
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr
|
||||
: 0;
|
||||
if(fd) {
|
||||
fputc(d->dat[port], fd);
|
||||
fputc(d[port], fd);
|
||||
fflush(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static Uint8
|
||||
nil_dei(Device *d, Uint8 port)
|
||||
uxn11_dei(struct Uxn *u, Uint8 addr)
|
||||
{
|
||||
return d->dat[port];
|
||||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||
switch(d) {
|
||||
case 0xa0: return file_dei(0, &u->dev[d], p);
|
||||
case 0xb0: return file_dei(1, &u->dev[d], p);
|
||||
case 0xc0: return datetime_dei(&u->dev[d], p);
|
||||
}
|
||||
return u->dev[addr];
|
||||
}
|
||||
|
||||
static void
|
||||
nil_deo(Device *d, Uint8 port)
|
||||
uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
|
||||
{
|
||||
(void)d;
|
||||
(void)port;
|
||||
}
|
||||
|
||||
static int
|
||||
console_input(Uxn *u, char c)
|
||||
{
|
||||
Device *d = &u->dev[1];
|
||||
d->dat[0x2] = c;
|
||||
return uxn_eval(u, GETVECTOR(d));
|
||||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||
u->dev[addr] = v;
|
||||
switch(d) {
|
||||
case 0x00: system_deo(u, &u->dev[d], p); break;
|
||||
case 0x10: console_deo(&u->dev[d], p); break;
|
||||
case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
|
||||
case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
run(Uxn *u)
|
||||
{
|
||||
Device *d = &u->dev[0];
|
||||
while(!d->dat[0xf]) {
|
||||
while(!u->dev[0x0f]) {
|
||||
int c = fgetc(stdin);
|
||||
if(c != EOF)
|
||||
console_input(u, (Uint8)c);
|
||||
|
@ -85,22 +89,8 @@ start(Uxn *u)
|
|||
{
|
||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
|
||||
return error("Boot", "Failed");
|
||||
/* system */ uxn_port(u, 0x0, nil_dei, system_deo);
|
||||
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
|
||||
/* empty */ uxn_port(u, 0x2, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x4, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x6, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x7, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x8, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0x9, nil_dei, nil_deo);
|
||||
/* file0 */ uxn_port(u, 0xa, file_dei, file_deo);
|
||||
/* file1 */ uxn_port(u, 0xb, file_dei, file_deo);
|
||||
/* datetime */ uxn_port(u, 0xc, datetime_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0xd, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0xe, nil_dei, nil_deo);
|
||||
/* empty */ uxn_port(u, 0xf, nil_dei, nil_deo);
|
||||
u->dei = uxn11_dei;
|
||||
u->deo = uxn11_deo;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -115,7 +105,7 @@ main(int argc, char **argv)
|
|||
return error("Start", "Failed");
|
||||
if(!load_rom(&u, argv[1]))
|
||||
return error("Load", "Failed");
|
||||
fprintf(stderr, "Loaded %s\n", argv[1]);
|
||||
fprintf(stderr, ">> Loaded %s\n", argv[1]);
|
||||
if(!uxn_eval(&u, PAGE_PROGRAM))
|
||||
return error("Init", "Failed");
|
||||
for(i = 2; i < argc; i++) {
|
||||
|
|
Loading…
Reference in New Issue