(uxn-fast.c) Removed function pointers, instead use exterm
This commit is contained in:
parent
3190cf3238
commit
8ae1c191d7
|
@ -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:
|
If you wish to build the emulator without graphics mode:
|
||||||
|
|
||||||
```sh
|
```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
|
### Plan 9
|
||||||
|
|
|
@ -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 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 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 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 DEO(a, b) { u->dev[a] = b; if((deo_masks[(a) >> 4] >> ((a) & 0xf)) & 0x1) uxn_deo(u, a); }
|
||||||
#define LISTEN(a, b) { PUT(a, ((receive_events[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? u->dei(u, b) : u->dev[b]) }
|
#define DEI(a, b) { PUT(a, ((dei_masks[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? uxn_dei(u, b) : u->dev[b]) }
|
||||||
|
|
||||||
static
|
static
|
||||||
Uint16 send_events[] = {
|
Uint16 deo_masks[] = {
|
||||||
0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000,
|
0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000,
|
||||||
0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000 };
|
0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000 };
|
||||||
static
|
static
|
||||||
Uint16 receive_events[] = {
|
Uint16 dei_masks[] = {
|
||||||
0x0000, 0x0000, 0x0014, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000,
|
0x0000, 0x0000, 0x0014, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000,
|
||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x07fd, 0x0000, 0x0000, 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 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 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 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 0x36: /* DEI2 */ t=T; INC(1, 1) DEI(1, t) DEI(0, t + 1) break;
|
||||||
case 0x16: /* DEI */ t=T; INC(1, 0) LISTEN(0, t) 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) SEND(t, l) SEND(t + 1, n) 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) SEND(t, 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 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 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;
|
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
|
int
|
||||||
uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo)
|
uxn_boot(Uxn *u, Uint8 *ram)
|
||||||
{
|
{
|
||||||
Uint32 i;
|
Uint32 i;
|
||||||
char *cptr = (char *)u;
|
char *cptr = (char *)u;
|
||||||
|
@ -146,7 +146,5 @@ uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo)
|
||||||
u->rst = (Stack *)(ram + 0xf0100);
|
u->rst = (Stack *)(ram + 0xf0100);
|
||||||
u->dev = (Uint8 *)(ram + 0xf0200);
|
u->dev = (Uint8 *)(ram + 0xf0200);
|
||||||
u->ram = ram;
|
u->ram = ram;
|
||||||
u->dei = dei;
|
|
||||||
u->deo = deo;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
12
src/uxn.h
12
src/uxn.h
|
@ -35,9 +35,13 @@ typedef struct Uxn {
|
||||||
void (*deo)(struct Uxn *u, Uint8 addr);
|
void (*deo)(struct Uxn *u, Uint8 addr);
|
||||||
} Uxn;
|
} Uxn;
|
||||||
|
|
||||||
typedef Uint8 Dei(Uxn *u, Uint8 addr);
|
/* required functions */
|
||||||
typedef void Deo(Uxn *u, Uint8 addr);
|
|
||||||
|
|
||||||
int uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr);
|
extern Uint8 uxn_dei(Uxn *u, Uint8 addr);
|
||||||
int uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo);
|
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);
|
int uxn_eval(Uxn *u, Uint16 pc);
|
10
src/uxncli.c
10
src/uxncli.c
|
@ -47,8 +47,8 @@ console_deo(Uint8 *d, Uint8 port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
Uint8
|
||||||
emu_dei(Uxn *u, Uint8 addr)
|
uxn_dei(Uxn *u, Uint8 addr)
|
||||||
{
|
{
|
||||||
switch(addr & 0xf0) {
|
switch(addr & 0xf0) {
|
||||||
case 0xc0: return datetime_dei(u, addr);
|
case 0xc0: return datetime_dei(u, addr);
|
||||||
|
@ -56,8 +56,8 @@ emu_dei(Uxn *u, Uint8 addr)
|
||||||
return u->dev[addr];
|
return u->dev[addr];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
emu_deo(Uxn *u, Uint8 addr)
|
uxn_deo(Uxn *u, Uint8 addr)
|
||||||
{
|
{
|
||||||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||||
switch(d) {
|
switch(d) {
|
||||||
|
@ -75,7 +75,7 @@ main(int argc, char **argv)
|
||||||
int i;
|
int i;
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
return emu_error("Usage", "uxncli game.rom args");
|
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");
|
return emu_error("Boot", "Failed");
|
||||||
if(!system_load(&u, argv[1]))
|
if(!system_load(&u, argv[1]))
|
||||||
return emu_error("Load", "Failed");
|
return emu_error("Load", "Failed");
|
||||||
|
|
10
src/uxnemu.c
10
src/uxnemu.c
|
@ -108,8 +108,8 @@ audio_deo(int instance, Uint8 *d, Uint8 port, Uxn *u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8
|
Uint8
|
||||||
emu_dei(Uxn *u, Uint8 addr)
|
uxn_dei(Uxn *u, Uint8 addr)
|
||||||
{
|
{
|
||||||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||||
switch(d) {
|
switch(d) {
|
||||||
|
@ -123,8 +123,8 @@ emu_dei(Uxn *u, Uint8 addr)
|
||||||
return u->dev[addr];
|
return u->dev[addr];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
emu_deo(Uxn *u, Uint8 addr)
|
uxn_deo(Uxn *u, Uint8 addr)
|
||||||
{
|
{
|
||||||
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
Uint8 p = addr & 0x0f, d = addr & 0xf0;
|
||||||
switch(d) {
|
switch(d) {
|
||||||
|
@ -263,7 +263,7 @@ static int
|
||||||
start(Uxn *u, char *rom)
|
start(Uxn *u, char *rom)
|
||||||
{
|
{
|
||||||
free(u->ram);
|
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.");
|
return error("Boot", "Failed to start uxn.");
|
||||||
if(!system_load(u, rom))
|
if(!system_load(u, rom))
|
||||||
return error("Boot", "Failed to load rom.");
|
return error("Boot", "Failed to load rom.");
|
||||||
|
|
Loading…
Reference in New Issue