Removed Devices

This commit is contained in:
neauoire 2022-04-05 11:42:50 -07:00
parent dba7b1f486
commit 725bc38aba
8 changed files with 56 additions and 66 deletions

View File

@ -1,4 +1,4 @@
# Uxn # Uxn11
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.

View File

@ -1,7 +1,12 @@
#!/bin/sh -e #!/bin/sh -e
if [ "${1}" = '--format' ];
then
echo "Formatting.."
clang-format -i src/uxn11.c clang-format -i src/uxn11.c
clang-format -i src/devices/* clang-format -i src/devices/*
fi
echo "Cleaning.." echo "Cleaning.."
rm -f ./bin/* rm -f ./bin/*

View File

@ -154,43 +154,43 @@ file_delete(UxnFile *c)
/* IO */ /* IO */
void void
file_deo(Uint8 id, Uint8 *ram, Device *d, Uint8 port) file_deo(Uint8 id, Uint8 *ram, Uint8 *d, Uint8 port)
{ {
UxnFile *c = &uxn_file[id]; UxnFile *c = &uxn_file[id];
Uint16 addr, len, res; Uint16 addr, len, res;
switch(port) { switch(port) {
case 0x5: case 0x5:
DEVPEEK16(addr, 0x4); PEKDEV(addr, 0x4);
DEVPEEK16(len, 0xa); PEKDEV(len, 0xa);
if(len > 0x10000 - addr) if(len > 0x10000 - addr)
len = 0x10000 - addr; len = 0x10000 - addr;
res = file_stat(c, &ram[addr], len); res = file_stat(c, &ram[addr], len);
DEVPOKE16(0x2, res); POKDEV(0x2, res);
break; break;
case 0x6: case 0x6:
res = file_delete(c); res = file_delete(c);
DEVPOKE16(0x2, res); POKDEV(0x2, res);
break; break;
case 0x9: case 0x9:
DEVPEEK16(addr, 0x8); PEKDEV(addr, 0x8);
res = file_init(c, (char *)&ram[addr], 0x10000 - addr); res = file_init(c, (char *)&ram[addr], 0x10000 - addr);
DEVPOKE16(0x2, res); POKDEV(0x2, res);
break; break;
case 0xd: case 0xd:
DEVPEEK16(addr, 0xc); PEKDEV(addr, 0xc);
DEVPEEK16(len, 0xa); PEKDEV(len, 0xa);
if(len > 0x10000 - addr) if(len > 0x10000 - addr)
len = 0x10000 - addr; len = 0x10000 - addr;
res = file_read(c, &ram[addr], len); res = file_read(c, &ram[addr], len);
DEVPOKE16(0x2, res); POKDEV(0x2, res);
break; break;
case 0xf: case 0xf:
DEVPEEK16(addr, 0xe); PEKDEV(addr, 0xe);
DEVPEEK16(len, 0xa); PEKDEV(len, 0xa);
if(len > 0x10000 - addr) if(len > 0x10000 - addr)
len = 0x10000 - addr; len = 0x10000 - addr;
res = file_write(c, &ram[addr], len, d->dat[0x7]); res = file_write(c, &ram[addr], len, d[0x7]);
DEVPOKE16(0x2, res); POKDEV(0x2, res);
break; break;
} }
} }

View File

@ -13,6 +13,6 @@ WITH REGARD TO THIS SOFTWARE.
#define POLYFILEY 2 #define POLYFILEY 2
#define DEV_FILE0 0xa #define DEV_FILE0 0xa
void file_deo(Uint8 id, Uint8 *ram, Device *d, Uint8 port); void file_deo(Uint8 id, Uint8 *ram, Uint8 *d, Uint8 port);
Uint8 file_dei(Uint8 id, Uint8 *d, Uint8 port); Uint8 file_dei(Uint8 id, Uint8 *d, Uint8 port);
int load_rom(Uxn *u, char *filename); int load_rom(Uxn *u, char *filename);

View File

@ -32,7 +32,7 @@ uxn_eval(Uxn *u, Uint16 pc)
unsigned int a, b, c, j, k, bs, instr, errcode; unsigned int a, b, c, j, k, bs, instr, errcode;
Uint8 kptr, *sp; Uint8 kptr, *sp;
Stack *src, *dst; Stack *src, *dst;
if(!pc || u->dev[0].dat[0xf]) return 0; if(!pc || u->dev[0x0f]) return 0;
while((instr = u->ram[pc++])) { while((instr = u->ram[pc++])) {
/* Return Mode */ /* Return Mode */
if(instr & 0x40) { if(instr & 0x40) {
@ -110,6 +110,6 @@ uxn_boot(Uxn *u, Uint8 *ram)
u->ram = ram; u->ram = ram;
u->wst = (Stack *)(ram + 0x10000); u->wst = (Stack *)(ram + 0x10000);
u->rst = (Stack *)(ram + 0x10100); u->rst = (Stack *)(ram + 0x10100);
u->dpg = (Uint8*)(ram + 0x10200); u->dev = (Uint8 *)(ram + 0x10200);
return 1; return 1;
} }

View File

@ -19,10 +19,6 @@ typedef unsigned int Uint32;
/* clang-format off */ /* clang-format off */
#define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; }
#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
#define GETVEC(d) ((d)[0] << 8 | (d)[1]) #define GETVEC(d) ((d)[0] << 8 | (d)[1])
#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); } #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; } #define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
@ -33,16 +29,11 @@ typedef struct {
Uint8 dat[255], ptr; Uint8 dat[255], ptr;
} Stack; } Stack;
typedef struct Device {
Uint8 dat[16];
} Device;
typedef struct Uxn { typedef struct Uxn {
Uint8 *ram, *dpg; Uint8 *ram, *dev;
Stack *wst, *rst; Stack *wst, *rst;
Uint8 (*dei)(struct Uxn *u, Uint8 address); Uint8 (*dei)(struct Uxn *u, Uint8 address);
void (*deo)(struct Uxn *u, Uint8 address, Uint8 value); void (*deo)(struct Uxn *u, Uint8 address, Uint8 value);
Device dev[16];
} Uxn; } Uxn;
int uxn_boot(Uxn *u, Uint8 *ram); int uxn_boot(Uxn *u, Uint8 *ram);

View File

@ -40,8 +40,8 @@ system_deo_special(Uint8 *d, Uint8 port)
static int static int
console_input(Uxn *u, char c) console_input(Uxn *u, char c)
{ {
Uint8 *d = u->dev[1].dat; Uint8 *d = &u->dev[0x10];
d[0x2] = c; d[0x02] = c;
return uxn_eval(u, GETVEC(d)); return uxn_eval(u, GETVEC(d));
} }
@ -59,33 +59,27 @@ console_deo(Uint8 *d, Uint8 port)
static Uint8 static Uint8
uxn11_dei(struct Uxn *u, Uint8 addr) uxn11_dei(struct Uxn *u, Uint8 addr)
{ {
Uint8 p = addr & 0x0f; Uint8 p = addr & 0x0f, d = addr & 0xf0;
Device *d = &u->dev[addr >> 4]; switch(d) {
switch(addr & 0xf0) { case 0x20: return screen_dei(&u->dev[d], p); break;
case 0x20: return screen_dei(d->dat, p); break; case 0xa0: return file_dei(0, &u->dev[d], p); break;
case 0x80: return u->dpg[0x80 + p]; break; case 0xb0: return file_dei(1, &u->dev[d], p); break;
case 0x90: return u->dpg[0x90 + p]; break; case 0xc0: return datetime_dei(&u->dev[d], p); break;
case 0xa0: return file_dei(0, d->dat, p); break;
case 0xb0: return file_dei(1, d->dat, p); break;
case 0xc0: return datetime_dei(d->dat, p); break;
} }
return d->dat[p]; return u->dev[addr];
} }
static void static void
uxn11_deo(Uxn *u, Uint8 addr, Uint8 v) uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
{ {
Uint8 p = addr & 0x0f; Uint8 p = addr & 0x0f, d = addr & 0xf0;
Device *d = &u->dev[addr >> 4]; u->dev[addr] = v;
d->dat[p] = v; switch(d) {
switch(addr & 0xf0) { case 0x00: system_deo(u, &u->dev[d], p); break;
case 0x00: system_deo(u, d->dat, p); break; case 0x10: console_deo(&u->dev[d], p); break;
case 0x10: console_deo(d->dat, p); break; case 0x20: screen_deo(u->ram, &u->dev[d], p); break;
case 0x20: screen_deo(u->ram, d->dat, p); break; case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
case 0x80: u->dpg[0x80 + p] = v; break; case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
case 0x90: u->dpg[0x90 + p] = v; break;
case 0xa0: file_deo(0, u->ram, d, p); break;
case 0xb0: file_deo(1, u->ram, d, p); break;
} }
} }
@ -146,26 +140,26 @@ processEvent(Uxn *u)
KeySym sym; KeySym sym;
char buf[7]; char buf[7];
XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
controller_down(u, &u->dpg[0x80], get_button(sym)); controller_down(u, &u->dev[0x80], get_button(sym));
controller_key(u, &u->dpg[0x80], sym < 0x80 ? sym : buf[0]); controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : buf[0]);
} break; } break;
case KeyRelease: { case KeyRelease: {
KeySym sym; KeySym sym;
char buf[7]; char buf[7];
XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
controller_up(u, &u->dpg[0x80], get_button(sym)); controller_up(u, &u->dev[0x80], get_button(sym));
} break; } break;
case ButtonPress: { case ButtonPress: {
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
mouse_down(u, &u->dpg[0x90], 0x1 << (e->button - 1)); mouse_down(u, &u->dev[0x90], 0x1 << (e->button - 1));
} break; } break;
case ButtonRelease: { case ButtonRelease: {
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
mouse_up(u, &u->dpg[0x90], 0x1 << (e->button - 1)); mouse_up(u, &u->dev[0x90], 0x1 << (e->button - 1));
} break; } break;
case MotionNotify: { case MotionNotify: {
XMotionEvent *e = (XMotionEvent *)&ev; XMotionEvent *e = (XMotionEvent *)&ev;
mouse_pos(u, &u->dpg[0x90], e->x, e->y); mouse_pos(u, &u->dev[0x90], e->x, e->y);
} break; } break;
} }
} }
@ -236,7 +230,7 @@ main(int argc, char **argv)
processEvent(&u); processEvent(&u);
if(poll(&fds[1], 1, 0)) { if(poll(&fds[1], 1, 0)) {
read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */ read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */
uxn_eval(&u, GETVEC(u.dev[0x2].dat)); /* Call the vector once, even if the timer fired multiple times */ uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
} }
if(uxn_screen.fg.changed || uxn_screen.bg.changed) if(uxn_screen.fg.changed || uxn_screen.bg.changed)
redraw(); redraw();

View File

@ -25,7 +25,7 @@ error(char *msg, const char *err)
} }
void void
system_deo_special(Device *d, Uint8 port) system_deo_special(Uint8 *d, Uint8 port)
{ {
(void)d; (void)d;
(void)port; (void)port;