(uxn-fast.c) Removed function pointers, instead use exterm

This commit is contained in:
Devine Lu Linvega 2023-03-05 10:44:23 -08:00
parent 3190cf3238
commit 8ae1c191d7
5 changed files with 29 additions and 27 deletions

View File

@ -31,7 +31,7 @@ Build the assembler and emulator by running the `build.sh` script. The assembler
If you wish to build the emulator without graphics mode:
```sh
cc src/devices/datetime.c src/devices/system.c src/devices/file.c src/uxn.c -DNDEBUG -Os -g0 -s src/uxncli.c -o bin/uxncli
cc src/devices/datetime.c src/devices/system.c src/devices/file.c src/uxn-fast.c -DNDEBUG -Os -g0 -s src/uxncli.c -o bin/uxncli
```
### Plan 9

View File

@ -34,15 +34,15 @@ WITH REGARD TO THIS SOFTWARE.
#define PUT2(o, v) { tmp = (v); s->dat[s->ptr - o - 2] = tmp >> 8; s->dat[s->ptr - o - 1] = tmp; }
#define PUSH(stack, v) { if(s->ptr > 254) HALT(2) stack->dat[stack->ptr++] = (v); }
#define PUSH2(stack, v) { if(s->ptr > 253) HALT(2) tmp = (v); stack->dat[stack->ptr] = (v) >> 8; stack->dat[stack->ptr + 1] = (v); stack->ptr += 2; }
#define SEND(a, b) { u->dev[a] = b; if((send_events[(a) >> 4] >> ((a) & 0xf)) & 0x1) u->deo(u, a); }
#define LISTEN(a, b) { PUT(a, ((receive_events[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? u->dei(u, b) : u->dev[b]) }
#define DEO(a, b) { u->dev[a] = b; if((deo_masks[(a) >> 4] >> ((a) & 0xf)) & 0x1) uxn_deo(u, a); }
#define DEI(a, b) { PUT(a, ((dei_masks[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? uxn_dei(u, b) : u->dev[b]) }
static
Uint16 send_events[] = {
Uint16 deo_masks[] = {
0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000,
0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000 };
static
Uint16 receive_events[] = {
Uint16 dei_masks[] = {
0x0000, 0x0000, 0x0014, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x07fd, 0x0000, 0x0000, 0x0000 };
@ -111,10 +111,10 @@ uxn_eval(Uxn *u, Uint16 pc)
case 0x14: /* LDA */ t=T2; INC(2,-1) PUT(0, u->ram[t]) break;
case 0x35: /* STA2 */ t=T2;n=N2; DEC(4, 0) POKE16(u->ram + t, n) break;
case 0x15: /* STA */ t=T2;n=L; DEC(3, 0) u->ram[t] = n; break;
case 0x36: /* DEI2 */ t=T; INC(1, 1) LISTEN(1, t) LISTEN(0, t + 1) break;
case 0x16: /* DEI */ t=T; INC(1, 0) LISTEN(0, t) break;
case 0x37: /* DEO2 */ t=T;n=N;l=L; DEC(3, 0) SEND(t, l) SEND(t + 1, n) break;
case 0x17: /* DEO */ t=T;n=N; DEC(2, 0) SEND(t, n) break;
case 0x36: /* DEI2 */ t=T; INC(1, 1) DEI(1, t) DEI(0, t + 1) break;
case 0x16: /* DEI */ t=T; INC(1, 0) DEI(0, t) break;
case 0x37: /* DEO2 */ t=T;n=N;l=L; DEC(3, 0) DEO(t, l) DEO(t + 1, n) break;
case 0x17: /* DEO */ t=T;n=N; DEC(2, 0) DEO(t, n) break;
case 0x38: /* ADD2 */ t=T2;n=N2; INC(4,-2) PUT2(0, n + t) break;
case 0x18: /* ADD */ t=T;n=N; INC(2,-1) PUT(0, n + t) break;
case 0x39: /* SUB2 */ t=T2;n=N2; INC(4,-2) PUT2(0, n - t) break;
@ -136,7 +136,7 @@ uxn_eval(Uxn *u, Uint16 pc)
}
int
uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo)
uxn_boot(Uxn *u, Uint8 *ram)
{
Uint32 i;
char *cptr = (char *)u;
@ -146,7 +146,5 @@ uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo)
u->rst = (Stack *)(ram + 0xf0100);
u->dev = (Uint8 *)(ram + 0xf0200);
u->ram = ram;
u->dei = dei;
u->deo = deo;
return 1;
}

View File

@ -35,9 +35,13 @@ typedef struct Uxn {
void (*deo)(struct Uxn *u, Uint8 addr);
} Uxn;
typedef Uint8 Dei(Uxn *u, Uint8 addr);
typedef void Deo(Uxn *u, Uint8 addr);
/* required functions */
int uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr);
int uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo);
int uxn_eval(Uxn *u, Uint16 pc);
extern Uint8 uxn_dei(Uxn *u, Uint8 addr);
extern void uxn_deo(Uxn *u, Uint8 addr);
extern int uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr);
/* built-ins */
int uxn_boot(Uxn *u, Uint8 *ram);
int uxn_eval(Uxn *u, Uint16 pc);

View File

@ -47,8 +47,8 @@ console_deo(Uint8 *d, Uint8 port)
}
}
static Uint8
emu_dei(Uxn *u, Uint8 addr)
Uint8
uxn_dei(Uxn *u, Uint8 addr)
{
switch(addr & 0xf0) {
case 0xc0: return datetime_dei(u, addr);
@ -56,8 +56,8 @@ emu_dei(Uxn *u, Uint8 addr)
return u->dev[addr];
}
static void
emu_deo(Uxn *u, Uint8 addr)
void
uxn_deo(Uxn *u, Uint8 addr)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
switch(d) {
@ -75,7 +75,7 @@ main(int argc, char **argv)
int i;
if(argc < 2)
return emu_error("Usage", "uxncli game.rom args");
if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), emu_dei, emu_deo))
if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
return emu_error("Boot", "Failed");
if(!system_load(&u, argv[1]))
return emu_error("Load", "Failed");

View File

@ -108,8 +108,8 @@ audio_deo(int instance, Uint8 *d, Uint8 port, Uxn *u)
}
}
static Uint8
emu_dei(Uxn *u, Uint8 addr)
Uint8
uxn_dei(Uxn *u, Uint8 addr)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
switch(d) {
@ -123,8 +123,8 @@ emu_dei(Uxn *u, Uint8 addr)
return u->dev[addr];
}
static void
emu_deo(Uxn *u, Uint8 addr)
void
uxn_deo(Uxn *u, Uint8 addr)
{
Uint8 p = addr & 0x0f, d = addr & 0xf0;
switch(d) {
@ -263,7 +263,7 @@ static int
start(Uxn *u, char *rom)
{
free(u->ram);
if(!uxn_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), emu_dei, emu_deo))
if(!uxn_boot(u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
return error("Boot", "Failed to start uxn.");
if(!system_load(u, rom))
return error("Boot", "Failed to load rom.");