Removed a few indirections
This commit is contained in:
parent
574c4250c3
commit
c990a2a407
|
@ -151,18 +151,12 @@ file_delete(UxnFile *c)
|
||||||
return unlink(c->current_filename);
|
return unlink(c->current_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static UxnFile *
|
|
||||||
file_instance(Device *d)
|
|
||||||
{
|
|
||||||
return &uxn_file[d - &d->u->dev[DEV_FILE0]];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* IO */
|
/* IO */
|
||||||
|
|
||||||
void
|
void
|
||||||
file_deo(Device *d, Uint8 port)
|
file_deo(Uint8 id, Device *d, Uint8 port)
|
||||||
{
|
{
|
||||||
UxnFile *c = file_instance(d);
|
UxnFile *c = &uxn_file[id];
|
||||||
Uint16 addr, len, res;
|
Uint16 addr, len, res;
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x5:
|
case 0x5:
|
||||||
|
@ -202,18 +196,18 @@ file_deo(Device *d, Uint8 port)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
file_dei(Device *d, Uint8 port)
|
file_dei(Uint8 id, Uint8 *d, Uint8 port)
|
||||||
{
|
{
|
||||||
UxnFile *c = file_instance(d);
|
UxnFile *c = &uxn_file[id];
|
||||||
Uint16 res;
|
Uint16 res;
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0xc:
|
case 0xc:
|
||||||
case 0xd:
|
case 0xd:
|
||||||
res = file_read(c, &d->dat[port], 1);
|
res = file_read(c, &d[port], 1);
|
||||||
DEVPOKE16(0x2, res);
|
POKDEV(0x2, res);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return d->dat[port];
|
return d[port];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Boot */
|
/* Boot */
|
||||||
|
|
|
@ -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(Device *d, Uint8 port);
|
void file_deo(Uint8 id, Device *d, Uint8 port);
|
||||||
Uint8 file_dei(Device *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);
|
||||||
|
|
|
@ -9,11 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
WITH REGARD TO THIS SOFTWARE.
|
WITH REGARD TO THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct SystemDevice {
|
|
||||||
Device device;
|
|
||||||
struct UxnScreen *screen;
|
|
||||||
} SystemDevice;
|
|
||||||
|
|
||||||
void system_inspect(Uxn *u);
|
void system_inspect(Uxn *u);
|
||||||
void system_deo(Uxn *u, Uint8 *d, Uint8 port);
|
void system_deo(Uxn *u, Uint8 *d, Uint8 port);
|
||||||
void system_deo_special(Uint8 *d, Uint8 port);
|
void system_deo_special(Uint8 *d, Uint8 port);
|
||||||
|
|
|
@ -110,6 +110,7 @@ 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);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ typedef struct Device {
|
||||||
} Device;
|
} Device;
|
||||||
|
|
||||||
typedef struct Uxn {
|
typedef struct Uxn {
|
||||||
Uint8 *ram;
|
Uint8 *ram, *dpg;
|
||||||
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);
|
||||||
|
|
36
src/uxn11.c
36
src/uxn11.c
|
@ -42,9 +42,9 @@ system_deo_special(Uint8 *d, Uint8 port)
|
||||||
static int
|
static int
|
||||||
console_input(Uxn *u, char c)
|
console_input(Uxn *u, char c)
|
||||||
{
|
{
|
||||||
Device *d = &u->dev[1];
|
Uint8 *d = u->dev[1].dat;
|
||||||
d->dat[0x2] = c;
|
d[0x2] = c;
|
||||||
return uxn_eval(u, GETVEC(d->dat));
|
return uxn_eval(u, GETVEC(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -65,8 +65,8 @@ uxn11_dei(struct Uxn *u, Uint8 addr)
|
||||||
Device *d = &u->dev[addr >> 4];
|
Device *d = &u->dev[addr >> 4];
|
||||||
switch(addr & 0xf0) {
|
switch(addr & 0xf0) {
|
||||||
case 0x20: return screen_dei(d->dat, p); break;
|
case 0x20: return screen_dei(d->dat, p); break;
|
||||||
case 0xa0: return file_dei(d, p); break;
|
case 0xa0: return file_dei(0, d->dat, p); break;
|
||||||
case 0xb0: return file_dei(d, p); break;
|
case 0xb0: return file_dei(1, d->dat, p); break;
|
||||||
case 0xc0: return datetime_dei(d->dat, p); break;
|
case 0xc0: return datetime_dei(d->dat, p); break;
|
||||||
}
|
}
|
||||||
return d->dat[p];
|
return d->dat[p];
|
||||||
|
@ -82,8 +82,8 @@ uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
|
||||||
case 0x00: system_deo(u, d->dat, p); break;
|
case 0x00: system_deo(u, d->dat, p); break;
|
||||||
case 0x10: console_deo(d->dat, p); break;
|
case 0x10: console_deo(d->dat, p); break;
|
||||||
case 0x20: screen_deo(u->ram, d->dat, p); break;
|
case 0x20: screen_deo(u->ram, d->dat, p); break;
|
||||||
case 0xa0: file_deo(d, p); break;
|
case 0xa0: file_deo(0, d, p); break;
|
||||||
case 0xb0: file_deo(d, p); break;
|
case 0xb0: file_deo(1, d, p); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ get_button(KeySym sym)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
processEvent(void)
|
processEvent(Uxn *u)
|
||||||
{
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
XNextEvent(display, &ev);
|
XNextEvent(display, &ev);
|
||||||
|
@ -144,26 +144,26 @@ processEvent(void)
|
||||||
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(devctrl->u, devctrl->dat, get_button(sym));
|
controller_down(u, devctrl->dat, get_button(sym));
|
||||||
controller_key(devctrl->u, devctrl->dat, sym < 0x80 ? sym : buf[0]);
|
controller_key(u, devctrl->dat, 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(devctrl->u, devctrl->dat, get_button(sym));
|
controller_up(u, devctrl->dat, get_button(sym));
|
||||||
} break;
|
} break;
|
||||||
case ButtonPress: {
|
case ButtonPress: {
|
||||||
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
|
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
|
||||||
mouse_down(devmouse->u, devmouse->dat, 0x1 << (e->button - 1));
|
mouse_down(u, devmouse->dat, 0x1 << (e->button - 1));
|
||||||
} break;
|
} break;
|
||||||
case ButtonRelease: {
|
case ButtonRelease: {
|
||||||
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
|
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
|
||||||
mouse_up(devmouse->u, devmouse->dat, 0x1 << (e->button - 1));
|
mouse_up(u, devmouse->dat, 0x1 << (e->button - 1));
|
||||||
} break;
|
} break;
|
||||||
case MotionNotify: {
|
case MotionNotify: {
|
||||||
XMotionEvent *e = (XMotionEvent *)&ev;
|
XMotionEvent *e = (XMotionEvent *)&ev;
|
||||||
mouse_pos(devmouse->u, devmouse->dat, e->x, e->y);
|
mouse_pos(u, devmouse->dat, e->x, e->y);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ nil_deo(Device *d, Uint8 port)
|
||||||
static int
|
static int
|
||||||
start(Uxn *u, char *rom)
|
start(Uxn *u, char *rom)
|
||||||
{
|
{
|
||||||
if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
|
if(!uxn_boot(u, (Uint8 *)calloc(0x10300, 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");
|
||||||
|
@ -202,8 +202,8 @@ start(Uxn *u, char *rom)
|
||||||
/* empty */ uxn_port(u, 0x7, nil_dei, nil_deo);
|
/* empty */ uxn_port(u, 0x7, nil_dei, nil_deo);
|
||||||
/* control */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo);
|
/* control */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo);
|
||||||
/* mouse */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo);
|
/* mouse */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo);
|
||||||
/* file0 */ uxn_port(u, 0xa, file_dei, file_deo);
|
/* file0 */ uxn_port(u, 0xa, nil_dei, nil_deo);
|
||||||
/* file1 */ uxn_port(u, 0xb, file_dei, file_deo);
|
/* file1 */ uxn_port(u, 0xb, nil_dei, nil_deo);
|
||||||
/* datetime */ uxn_port(u, 0xc, nil_dei, nil_deo);
|
/* datetime */ uxn_port(u, 0xc, nil_dei, nil_deo);
|
||||||
/* empty */ uxn_port(u, 0xd, nil_dei, nil_deo);
|
/* empty */ uxn_port(u, 0xd, nil_dei, nil_deo);
|
||||||
/* reserved */ uxn_port(u, 0xe, nil_dei, nil_deo);
|
/* reserved */ uxn_port(u, 0xe, nil_dei, nil_deo);
|
||||||
|
@ -262,7 +262,7 @@ main(int argc, char **argv)
|
||||||
if(poll(fds, 2, 1000) <= 0)
|
if(poll(fds, 2, 1000) <= 0)
|
||||||
continue;
|
continue;
|
||||||
while(XPending(display))
|
while(XPending(display))
|
||||||
processEvent();
|
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, GETVECTOR(devscreen)); /* Call the vector once, even if the timer fired multiple times */
|
uxn_eval(&u, GETVECTOR(devscreen)); /* Call the vector once, even if the timer fired multiple times */
|
||||||
|
|
Loading…
Reference in New Issue