Tiny changes to the uxn core macros

This commit is contained in:
Devine Lu Linvega 2024-08-05 15:13:08 -07:00
parent bf10311d5a
commit a9d7ff23a5
3 changed files with 21 additions and 17 deletions

View File

@ -12,16 +12,18 @@ WITH REGARD TO THIS SOFTWARE.
*/ */
#define OPC(opc, body) {\ #define OPC(opc, body) {\
case 0x00|opc: {int _2=0,_r=0,a,b,c; Stack *s = &uxn.wst; Uint8 *sp = &uxn.wst.ptr; body break;}\ case 0x00|opc: {enum{_2=0,_r=0}; s = &uxn.wst, sp = &uxn.wst.ptr; body break;}\
case 0x20|opc: {int _2=1,_r=0,a,b,c; Stack *s = &uxn.wst; Uint8 *sp = &uxn.wst.ptr; body break;}\ case 0x20|opc: {enum{_2=1,_r=0}; s = &uxn.wst, sp = &uxn.wst.ptr; body break;}\
case 0x40|opc: {int _2=0,_r=1,a,b,c; Stack *s = &uxn.rst; Uint8 *sp = &uxn.rst.ptr; body break;}\ case 0x40|opc: {enum{_2=0,_r=1}; s = &uxn.rst, sp = &uxn.rst.ptr; body break;}\
case 0x60|opc: {int _2=1,_r=1,a,b,c; Stack *s = &uxn.rst; Uint8 *sp = &uxn.rst.ptr; body break;}\ case 0x60|opc: {enum{_2=1,_r=1}; s = &uxn.rst, sp = &uxn.rst.ptr; body break;}\
case 0x80|opc: {int _2=0,_r=0,a,b,c; Stack *s = &uxn.wst; Uint8 kp = uxn.wst.ptr, *sp = &kp; body break;}\ case 0x80|opc: {enum{_2=0,_r=0}; s = &uxn.wst, kp = uxn.wst.ptr, sp = &kp; body break;}\
case 0xa0|opc: {int _2=1,_r=0,a,b,c; Stack *s = &uxn.wst; Uint8 kp = uxn.wst.ptr, *sp = &kp; body break;}\ case 0xa0|opc: {enum{_2=1,_r=0}; s = &uxn.wst, kp = uxn.wst.ptr, sp = &kp; body break;}\
case 0xc0|opc: {int _2=0,_r=1,a,b,c; Stack *s = &uxn.rst; Uint8 kp = uxn.rst.ptr, *sp = &kp; body break;}\ case 0xc0|opc: {enum{_2=0,_r=1}; s = &uxn.rst, kp = uxn.rst.ptr, sp = &kp; body break;}\
case 0xe0|opc: {int _2=1,_r=1,a,b,c; Stack *s = &uxn.rst; Uint8 kp = uxn.rst.ptr, *sp = &kp; body break;}\ case 0xe0|opc: {enum{_2=1,_r=1}; s = &uxn.rst, kp = uxn.rst.ptr, sp = &kp; body break;}\
} }
/* Microcode */
#define FLP { s = _r ? &uxn.wst : &uxn.rst; } #define FLP { s = _r ? &uxn.wst : &uxn.rst; }
#define JMI { pc += uxn.ram[pc++] << 8 | uxn.ram[pc++]; } #define JMI { pc += uxn.ram[pc++] << 8 | uxn.ram[pc++]; }
#define JMP(x) { if(_2) pc = (x); else pc += (Sint8)(x); } #define JMP(x) { if(_2) pc = (x); else pc += (Sint8)(x); }
@ -30,20 +32,22 @@ WITH REGARD TO THIS SOFTWARE.
#define PO2(o) { o = s->dat[--*sp] | (s->dat[--*sp] << 8); } #define PO2(o) { o = s->dat[--*sp] | (s->dat[--*sp] << 8); }
#define PUx(y) { if(_2) { PU2(y) } else PU1(y) } #define PUx(y) { if(_2) { PU2(y) } else PU1(y) }
#define PU1(y) { s->dat[s->ptr++] = (y); } #define PU1(y) { s->dat[s->ptr++] = (y); }
#define PU2(y) { tt = (y); s->dat[s->ptr++] = tt >> 0x8; s->dat[s->ptr++] = tt; } #define PU2(y) { tt = (y); PU1(tt >> 8) PU1(tt) }
#define IMM(x, y) { uxn.x.dat[uxn.x.ptr++] = (y); } #define IMM(x, y) { uxn.x.dat[uxn.x.ptr++] = (y); }
#define DEI(o, p) { if(_2) { o = (emu_dei(p) << 8) | emu_dei(p + 1); } else o = emu_dei(p); } #define DEI(p, o) { if(_2) { o = (emu_dei(p) << 8) | emu_dei(p + 1); } else o = emu_dei(p); }
#define DEO(p, y) { if(_2) { emu_deo(p, y >> 8); emu_deo(p + 1, y); } else emu_deo(p, y); } #define DEO(p, y) { if(_2) { emu_deo(p, y >> 8), emu_deo(p + 1, y); } else emu_deo(p, y); }
#define PEK(o, x, r) { if(_2) { r = (x); o = uxn.ram[r++] << 8 | uxn.ram[r]; } else o = uxn.ram[(x)]; } #define PEK(o, x, r) { if(_2) { r = (x); o = uxn.ram[r++] << 8 | uxn.ram[r]; } else o = uxn.ram[(x)]; }
#define POK(x, y, r) { if(_2) { r = (x); uxn.ram[r++] = y >> 8; uxn.ram[r] = y; } else uxn.ram[(x)] = (y); } #define POK(x, y, r) { if(_2) { r = (x); uxn.ram[r++] = y >> 8, uxn.ram[r] = y; } else uxn.ram[(x)] = (y); }
int int
uxn_eval(Uint16 pc) uxn_eval(Uint16 pc)
{ {
int a,b,c;
Uint8 t, kp, *sp;
Uint16 tt;
Stack *s;
if(!pc || uxn.dev[0x0f]) return 0; if(!pc || uxn.dev[0x0f]) return 0;
for(;;) { for(;;) {
Uint8 t;
Uint16 tt;
switch(uxn.ram[pc++]) { switch(uxn.ram[pc++]) {
/* BRK */ case 0x00: return 1; /* BRK */ case 0x00: return 1;
/* JCI */ case 0x20: if(uxn.wst.dat[--uxn.wst.ptr]) { JMI break; } pc += 2; break; /* JCI */ case 0x20: if(uxn.wst.dat[--uxn.wst.ptr]) { JMI break; } pc += 2; break;
@ -74,7 +78,7 @@ uxn_eval(Uint16 pc)
/* STR */ OPC(0x13, PO1(a) POx(b) POK(pc + (Sint8)a, b, tt)) /* STR */ OPC(0x13, PO1(a) POx(b) POK(pc + (Sint8)a, b, tt))
/* LDA */ OPC(0x14, PO2(a) PEK(b, a, tt) PUx(b)) /* LDA */ OPC(0x14, PO2(a) PEK(b, a, tt) PUx(b))
/* STA */ OPC(0x15, PO2(a) POx(b) POK(a, b, tt)) /* STA */ OPC(0x15, PO2(a) POx(b) POK(a, b, tt))
/* DEI */ OPC(0x16, PO1(a) DEI(b, a) PUx(b)) /* DEI */ OPC(0x16, PO1(a) DEI(a, b) PUx(b))
/* DEO */ OPC(0x17, PO1(a) POx(b) DEO(a, b)) /* DEO */ OPC(0x17, PO1(a) POx(b) DEO(a, b))
/* ADD */ OPC(0x18, POx(a) POx(b) PUx(b + a)) /* ADD */ OPC(0x18, POx(a) POx(b) PUx(b + a))
/* SUB */ OPC(0x19, POx(a) POx(b) PUx(b - a)) /* SUB */ OPC(0x19, POx(a) POx(b) PUx(b - a))

View File

@ -68,7 +68,7 @@ main(int argc, char **argv)
int i = 1; int i = 1;
char *rom; char *rom;
if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') { if(i != argc && argv[i][0] == '-' && argv[i][1] == 'v') {
fprintf(stdout, "Uxncli - Console Varvara Emulator, 15 Jul 2024.\n"); fprintf(stdout, "Uxncli - Console Varvara Emulator, 5 Aug 2024.\n");
i++; i++;
} }
rom = i == argc ? "boot.rom" : argv[i++]; rom = i == argc ? "boot.rom" : argv[i++];

View File

@ -466,7 +466,7 @@ main(int argc, char **argv)
/* flags */ /* flags */
if(argc > 1 && argv[i][0] == '-') { if(argc > 1 && argv[i][0] == '-') {
if(!strcmp(argv[i], "-v")) if(!strcmp(argv[i], "-v"))
return system_error("Uxnemu - Varvara Emulator(GUI)", "26 Jul 2024."); return system_error("Uxnemu - Varvara Emulator(GUI)", "5 Aug 2024.");
else if(!strcmp(argv[i], "-2x")) else if(!strcmp(argv[i], "-2x"))
set_zoom(2, 0); set_zoom(2, 0);
else if(!strcmp(argv[i], "-3x")) else if(!strcmp(argv[i], "-3x"))