diff --git a/cli/uxncore/makefile b/cli/uxncore/makefile index f0a7734..b722493 100644 --- a/cli/uxncore/makefile +++ b/cli/uxncore/makefile @@ -5,12 +5,14 @@ LIN=uxncli ${DIR}/uxnlin.rom EMU=uxncli ROM=bin/${ID}.rom -all: ${ROM} bin/main +all: ${ROM} lint: @ ${LIN} src/${ID}.tal run: all - @ ${EMU} ${ROM} + @ ${EMU} ${ROM} > src/core.c + @ cat src/a.c src/core.c src/b.c > src/main.c + @ cc src/main.c -o bin/main @ ./bin/main @ rm ./bin/main clean: @@ -22,9 +24,6 @@ uninstall: .PHONY: all clean lint run install uninstall -bin/main: src/main.c - @ cc src/main.c -o bin/main - ${ROM}: src/* @ mkdir -p bin @ ${ASM} src/${ID}.tal ${ROM} diff --git a/cli/uxncore/src/a.c b/cli/uxncore/src/a.c new file mode 100644 index 0000000..305f959 --- /dev/null +++ b/cli/uxncore/src/a.c @@ -0,0 +1,49 @@ +#include + +typedef unsigned char Uint8; +typedef signed char Sint8; +typedef unsigned short Uint16; + +typedef struct { + Uint8 dat[0x100], ptr; +} Stack; + +typedef struct Uxn { + Uint8 ram[0x10000], dev[0x100]; + Stack wst, rst; +} Uxn; + +Uxn uxn; + +static void +system_print(Stack *s) +{ + Uint8 i; + for(i = s->ptr - 7; i != (Uint8)(s->ptr); i++) + fprintf(stderr, "%02x%c", s->dat[i], i == 0xff ? '|' : ' '); + fprintf(stderr, "< \n"); +} + +void +system_inspect(void) +{ + fprintf(stderr, "WST "), system_print(&uxn.wst); + fprintf(stderr, "RST "), system_print(&uxn.rst); +} + +Uint8 +emu_dei(Uint8 addr) +{ + return uxn.dev[addr]; +} + +void +emu_deo(Uint8 addr, Uint8 value) +{ + uxn.dev[addr] = value; + switch(addr) { + case 0x18: fputc(uxn.dev[0x18], stdout), fflush(stdout); return; + case 0x19: fputc(uxn.dev[0x19], stderr), fflush(stderr); return; + } +} + diff --git a/cli/uxncore/src/b.c b/cli/uxncore/src/b.c new file mode 100644 index 0000000..d0afde9 --- /dev/null +++ b/cli/uxncore/src/b.c @@ -0,0 +1,16 @@ +int +main(int argc, char **argv) +{ + /* test */ + uxn.ram[0x100] = 0x80; + uxn.ram[0x101] = 0x12; + + uxn.ram[0x102] = 0x80; + uxn.ram[0x103] = 0x34; + + uxn.ram[0x104] = 0x80; + uxn.ram[0x105] = 0x56; + if(uxn_eval(0x0100) && (uxn.dev[0x10] << 8 | uxn.dev[0x11])) + while(!uxn.dev[0x0f]) ; + return uxn.dev[0x0f] & 0x7f; +} \ No newline at end of file diff --git a/cli/uxncore/src/core.c b/cli/uxncore/src/core.c new file mode 100644 index 0000000..0d4152c --- /dev/null +++ b/cli/uxncore/src/core.c @@ -0,0 +1,265 @@ +int +uxn_eval(Uint16 pc) { + for(;;) { + switch(uxn.ram[pc]) { + case 0x00: /* BRK */ return 1; break; + case 0x01: /* INC */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0x02: /* POP */ uxn.wst.ptr--; pc++; break; + case 0x03: /* NIP */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0x04: /* SWP */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0x05: /* ROT */ break; + case 0x06: /* DUP */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0x07: /* OVR */ break; + case 0x08: /* EQU */ return 1; break; + case 0x09: /* NEQ */ return 1; break; + case 0x0a: /* GTH */ return 1; break; + case 0x0b: /* LTH */ return 1; break; + case 0x0c: /* JMP */ return 1; break; + case 0x0d: /* JCN */ return 1; break; + case 0x0e: /* JSR */ return 1; break; + case 0x0f: /* STH */ return 1; break; + case 0x10: /* LDZ */ return 1; break; + case 0x11: /* STZ */ return 1; break; + case 0x12: /* LDR */ return 1; break; + case 0x13: /* STR */ return 1; break; + case 0x14: /* LDA */ return 1; break; + case 0x15: /* STA */ return 1; break; + case 0x16: /* DEI */ return 1; break; + case 0x17: /* DEO */ return 1; break; + case 0x18: /* ADD */ return 1; break; + case 0x19: /* SUB */ return 1; break; + case 0x1a: /* MUL */ return 1; break; + case 0x1b: /* DIV */ return 1; break; + case 0x1c: /* AND */ return 1; break; + case 0x1d: /* ORA */ return 1; break; + case 0x1e: /* EOR */ return 1; break; + case 0x1f: /* SFT */ return 1; break; + case 0x20: /* JCI */ return 1; break; + case 0x21: /* INC2 */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0x22: /* POP2 */ uxn.wst.ptr--; pc++; break; + case 0x23: /* NIP2 */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0x24: /* SWP2 */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0x25: /* ROT2 */ break; + case 0x26: /* DUP2 */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0x27: /* OVR2 */ break; + case 0x28: /* EQU2 */ return 1; break; + case 0x29: /* NEQ2 */ return 1; break; + case 0x2a: /* GTH2 */ return 1; break; + case 0x2b: /* LTH2 */ return 1; break; + case 0x2c: /* JMP2 */ return 1; break; + case 0x2d: /* JCN2 */ return 1; break; + case 0x2e: /* JSR2 */ return 1; break; + case 0x2f: /* STH2 */ return 1; break; + case 0x30: /* LDZ2 */ return 1; break; + case 0x31: /* STZ2 */ return 1; break; + case 0x32: /* LDR2 */ return 1; break; + case 0x33: /* STR2 */ return 1; break; + case 0x34: /* LDA2 */ return 1; break; + case 0x35: /* STA2 */ return 1; break; + case 0x36: /* DEI2 */ return 1; break; + case 0x37: /* DEO2 */ return 1; break; + case 0x38: /* ADD2 */ return 1; break; + case 0x39: /* SUB2 */ return 1; break; + case 0x3a: /* MUL2 */ return 1; break; + case 0x3b: /* DIV2 */ return 1; break; + case 0x3c: /* AND2 */ return 1; break; + case 0x3d: /* ORA2 */ return 1; break; + case 0x3e: /* EOR2 */ return 1; break; + case 0x3f: /* SFT2 */ return 1; break; + case 0x40: /* JMI */ return 1; break; + case 0x41: /* INCr */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0x42: /* POPr */ uxn.rst.ptr--; pc++; break; + case 0x43: /* NIPr */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0x44: /* SWPr */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0x45: /* ROTr */ break; + case 0x46: /* DUPr */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0x47: /* OVRr */ break; + case 0x48: /* EQUr */ return 1; break; + case 0x49: /* NEQr */ return 1; break; + case 0x4a: /* GTHr */ return 1; break; + case 0x4b: /* LTHr */ return 1; break; + case 0x4c: /* JMPr */ return 1; break; + case 0x4d: /* JCNr */ return 1; break; + case 0x4e: /* JSRr */ return 1; break; + case 0x4f: /* STHr */ return 1; break; + case 0x50: /* LDZr */ return 1; break; + case 0x51: /* STZr */ return 1; break; + case 0x52: /* LDRr */ return 1; break; + case 0x53: /* STRr */ return 1; break; + case 0x54: /* LDAr */ return 1; break; + case 0x55: /* STAr */ return 1; break; + case 0x56: /* DEIr */ return 1; break; + case 0x57: /* DEOr */ return 1; break; + case 0x58: /* ADDr */ return 1; break; + case 0x59: /* SUBr */ return 1; break; + case 0x5a: /* MULr */ return 1; break; + case 0x5b: /* DIVr */ return 1; break; + case 0x5c: /* ANDr */ return 1; break; + case 0x5d: /* ORAr */ return 1; break; + case 0x5e: /* EORr */ return 1; break; + case 0x5f: /* SFTr */ return 1; break; + case 0x60: /* JSI */ return 1; break; + case 0x61: /* INC2r */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0x62: /* POP2r */ uxn.rst.ptr--; pc++; break; + case 0x63: /* NIP2r */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0x64: /* SWP2r */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0x65: /* ROT2r */ break; + case 0x66: /* DUP2r */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0x67: /* OVR2r */ break; + case 0x68: /* EQU2r */ return 1; break; + case 0x69: /* NEQ2r */ return 1; break; + case 0x6a: /* GTH2r */ return 1; break; + case 0x6b: /* LTH2r */ return 1; break; + case 0x6c: /* JMP2r */ return 1; break; + case 0x6d: /* JCN2r */ return 1; break; + case 0x6e: /* JSR2r */ return 1; break; + case 0x6f: /* STH2r */ return 1; break; + case 0x70: /* LDZ2r */ return 1; break; + case 0x71: /* STZ2r */ return 1; break; + case 0x72: /* LDR2r */ return 1; break; + case 0x73: /* STR2r */ return 1; break; + case 0x74: /* LDA2r */ return 1; break; + case 0x75: /* STA2r */ return 1; break; + case 0x76: /* DEI2r */ return 1; break; + case 0x77: /* DEO2r */ return 1; break; + case 0x78: /* ADD2r */ return 1; break; + case 0x79: /* SUB2r */ return 1; break; + case 0x7a: /* MUL2r */ return 1; break; + case 0x7b: /* DIV2r */ return 1; break; + case 0x7c: /* AND2r */ return 1; break; + case 0x7d: /* ORA2r */ return 1; break; + case 0x7e: /* EOR2r */ return 1; break; + case 0x7f: /* SFT2r */ return 1; break; + case 0x80: /* LITk */ uxn.wst.dat[uxn.wst.ptr++] = uxn.ram[++pc]; pc++; break; + case 0x81: /* INCk */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0x82: /* POPk */ uxn.wst.ptr--; pc++; break; + case 0x83: /* NIPk */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0x84: /* SWPk */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0x85: /* ROTk */ break; + case 0x86: /* DUPk */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0x87: /* OVRk */ break; + case 0x88: /* EQUk */ return 1; break; + case 0x89: /* NEQk */ return 1; break; + case 0x8a: /* GTHk */ return 1; break; + case 0x8b: /* LTHk */ return 1; break; + case 0x8c: /* JMPk */ return 1; break; + case 0x8d: /* JCNk */ return 1; break; + case 0x8e: /* JSRk */ return 1; break; + case 0x8f: /* STHk */ return 1; break; + case 0x90: /* LDZk */ return 1; break; + case 0x91: /* STZk */ return 1; break; + case 0x92: /* LDRk */ return 1; break; + case 0x93: /* STRk */ return 1; break; + case 0x94: /* LDAk */ return 1; break; + case 0x95: /* STAk */ return 1; break; + case 0x96: /* DEIk */ return 1; break; + case 0x97: /* DEOk */ return 1; break; + case 0x98: /* ADDk */ return 1; break; + case 0x99: /* SUBk */ return 1; break; + case 0x9a: /* MULk */ return 1; break; + case 0x9b: /* DIVk */ return 1; break; + case 0x9c: /* ANDk */ return 1; break; + case 0x9d: /* ORAk */ return 1; break; + case 0x9e: /* EORk */ return 1; break; + case 0x9f: /* SFTk */ return 1; break; + case 0xa0: /* LIT2k */ break; + case 0xa1: /* INC2k */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0xa2: /* POP2k */ uxn.wst.ptr--; pc++; break; + case 0xa3: /* NIP2k */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0xa4: /* SWP2k */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0xa5: /* ROT2k */ break; + case 0xa6: /* DUP2k */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0xa7: /* OVR2k */ break; + case 0xa8: /* EQU2k */ return 1; break; + case 0xa9: /* NEQ2k */ return 1; break; + case 0xaa: /* GTH2k */ return 1; break; + case 0xab: /* LTH2k */ return 1; break; + case 0xac: /* JMP2k */ return 1; break; + case 0xad: /* JCN2k */ return 1; break; + case 0xae: /* JSR2k */ return 1; break; + case 0xaf: /* STH2k */ return 1; break; + case 0xb0: /* LDZ2k */ return 1; break; + case 0xb1: /* STZ2k */ return 1; break; + case 0xb2: /* LDR2k */ return 1; break; + case 0xb3: /* STR2k */ return 1; break; + case 0xb4: /* LDA2k */ return 1; break; + case 0xb5: /* STA2k */ return 1; break; + case 0xb6: /* DEI2k */ return 1; break; + case 0xb7: /* DEO2k */ return 1; break; + case 0xb8: /* ADD2k */ return 1; break; + case 0xb9: /* SUB2k */ return 1; break; + case 0xba: /* MUL2k */ return 1; break; + case 0xbb: /* DIV2k */ return 1; break; + case 0xbc: /* AND2k */ return 1; break; + case 0xbd: /* ORA2k */ return 1; break; + case 0xbe: /* EOR2k */ return 1; break; + case 0xbf: /* SFT2k */ return 1; break; + case 0xc0: /* LITkr */ uxn.rst.dat[uxn.rst.ptr++] = uxn.ram[++pc]; pc++; break; + case 0xc1: /* INCkr */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0xc2: /* POPkr */ uxn.rst.ptr--; pc++; break; + case 0xc3: /* NIPkr */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0xc4: /* SWPkr */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0xc5: /* ROTkr */ break; + case 0xc6: /* DUPkr */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0xc7: /* OVRkr */ break; + case 0xc8: /* EQUkr */ return 1; break; + case 0xc9: /* NEQkr */ return 1; break; + case 0xca: /* GTHkr */ return 1; break; + case 0xcb: /* LTHkr */ return 1; break; + case 0xcc: /* JMPkr */ return 1; break; + case 0xcd: /* JCNkr */ return 1; break; + case 0xce: /* JSRkr */ return 1; break; + case 0xcf: /* STHkr */ return 1; break; + case 0xd0: /* LDZkr */ return 1; break; + case 0xd1: /* STZkr */ return 1; break; + case 0xd2: /* LDRkr */ return 1; break; + case 0xd3: /* STRkr */ return 1; break; + case 0xd4: /* LDAkr */ return 1; break; + case 0xd5: /* STAkr */ return 1; break; + case 0xd6: /* DEIkr */ return 1; break; + case 0xd7: /* DEOkr */ return 1; break; + case 0xd8: /* ADDkr */ return 1; break; + case 0xd9: /* SUBkr */ return 1; break; + case 0xda: /* MULkr */ return 1; break; + case 0xdb: /* DIVkr */ return 1; break; + case 0xdc: /* ANDkr */ return 1; break; + case 0xdd: /* ORAkr */ return 1; break; + case 0xde: /* EORkr */ return 1; break; + case 0xdf: /* SFTkr */ return 1; break; + case 0xe0: /* LIT2kr */ return 1; break; + case 0xe1: /* INC2kr */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0xe2: /* POP2kr */ uxn.rst.ptr--; pc++; break; + case 0xe3: /* NIP2kr */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0xe4: /* SWP2kr */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0xe5: /* ROT2kr */ break; + case 0xe6: /* DUP2kr */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0xe7: /* OVR2kr */ break; + case 0xe8: /* EQU2kr */ return 1; break; + case 0xe9: /* NEQ2kr */ return 1; break; + case 0xea: /* GTH2kr */ return 1; break; + case 0xeb: /* LTH2kr */ return 1; break; + case 0xec: /* JMP2kr */ return 1; break; + case 0xed: /* JCN2kr */ return 1; break; + case 0xee: /* JSR2kr */ return 1; break; + case 0xef: /* STH2kr */ return 1; break; + case 0xf0: /* LDZ2kr */ return 1; break; + case 0xf1: /* STZ2kr */ return 1; break; + case 0xf2: /* LDR2kr */ return 1; break; + case 0xf3: /* STR2kr */ return 1; break; + case 0xf4: /* LDA2kr */ return 1; break; + case 0xf5: /* STA2kr */ return 1; break; + case 0xf6: /* DEI2kr */ return 1; break; + case 0xf7: /* DEO2kr */ return 1; break; + case 0xf8: /* ADD2kr */ return 1; break; + case 0xf9: /* SUB2kr */ return 1; break; + case 0xfa: /* MUL2kr */ return 1; break; + case 0xfb: /* DIV2kr */ return 1; break; + case 0xfc: /* AND2kr */ return 1; break; + case 0xfd: /* ORA2kr */ return 1; break; + case 0xfe: /* EOR2kr */ return 1; break; + case 0xff: /* SFT2kr */ return 1; break; + } + system_inspect(); + } +} + diff --git a/cli/uxncore/src/main.c b/cli/uxncore/src/main.c index 0d69519..02b048b 100644 --- a/cli/uxncore/src/main.c +++ b/cli/uxncore/src/main.c @@ -20,7 +20,7 @@ system_print(Stack *s) { Uint8 i; for(i = s->ptr - 7; i != (Uint8)(s->ptr); i++) - fprintf(stderr, "%02x%c", s->dat[i], i == 1 ? '|' : ' '); + fprintf(stderr, "%02x%c", s->dat[i], i == 0xff ? '|' : ' '); fprintf(stderr, "< \n"); } @@ -47,29 +47,266 @@ emu_deo(Uint8 addr, Uint8 value) } } -#define FLIP { s = ins & 0x40 ? &uxn.wst : &uxn.rst; } -#define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); } -#define POP1(o) { o = s->dat[--*sp]; } -#define POP2(o) { o = s->dat[--*sp] | (s->dat[--*sp] << 0x8); } -#define POPx(o) { if(m2) { POP2(o) } else POP1(o) } -#define PUSH1(y) { s->dat[s->ptr++] = (y); } -#define PUSH2(y) { tt = (y); s->dat[s->ptr++] = tt >> 0x8; s->dat[s->ptr++] = tt; } -#define PUSHx(y) { if(m2) { PUSH2(y) } else PUSH1(y) } -#define PEEK(o, x, r) { if(m2) { r = (x); o = uxn.ram[r++] << 8 | uxn.ram[r]; } else o = uxn.ram[(x)]; } -#define POKE(x, y, r) { if(m2) { r = (x); uxn.ram[r++] = y >> 8; uxn.ram[r] = y; } else uxn.ram[(x)] = (y); } -#define DEVR(o, p) { if(m2) { o = (emu_dei(p) << 8) | emu_dei(p + 1); } else o = emu_dei(p); } -#define DEVW(p, y) { if(m2) { emu_deo(p, y >> 8); emu_deo(p + 1, y); } else emu_deo(p, y); } - int -uxn_eval(Uint16 pc) -{ - if(!pc || uxn.dev[0x0f]) return 0; +uxn_eval(Uint16 pc) { for(;;) { switch(uxn.ram[pc]) { - case 0x00: return 1; - case 0x01: pc++; break; - case 0x80: uxn.wst.dat[uxn.wst.ptr++] = uxn.ram[++pc]; pc++; break; - default: return 1; + case 0x00: /* BRK */ return 1; break; + case 0x01: /* INC */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0x02: /* POP */ uxn.wst.ptr--; pc++; break; + case 0x03: /* NIP */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0x04: /* SWP */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0x05: /* ROT */ break; + case 0x06: /* DUP */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0x07: /* OVR */ break; + case 0x08: /* EQU */ return 1; break; + case 0x09: /* NEQ */ return 1; break; + case 0x0a: /* GTH */ return 1; break; + case 0x0b: /* LTH */ return 1; break; + case 0x0c: /* JMP */ return 1; break; + case 0x0d: /* JCN */ return 1; break; + case 0x0e: /* JSR */ return 1; break; + case 0x0f: /* STH */ return 1; break; + case 0x10: /* LDZ */ return 1; break; + case 0x11: /* STZ */ return 1; break; + case 0x12: /* LDR */ return 1; break; + case 0x13: /* STR */ return 1; break; + case 0x14: /* LDA */ return 1; break; + case 0x15: /* STA */ return 1; break; + case 0x16: /* DEI */ return 1; break; + case 0x17: /* DEO */ return 1; break; + case 0x18: /* ADD */ return 1; break; + case 0x19: /* SUB */ return 1; break; + case 0x1a: /* MUL */ return 1; break; + case 0x1b: /* DIV */ return 1; break; + case 0x1c: /* AND */ return 1; break; + case 0x1d: /* ORA */ return 1; break; + case 0x1e: /* EOR */ return 1; break; + case 0x1f: /* SFT */ return 1; break; + case 0x20: /* JCI */ return 1; break; + case 0x21: /* INC2 */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0x22: /* POP2 */ uxn.wst.ptr--; pc++; break; + case 0x23: /* NIP2 */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0x24: /* SWP2 */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0x25: /* ROT2 */ break; + case 0x26: /* DUP2 */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0x27: /* OVR2 */ break; + case 0x28: /* EQU2 */ return 1; break; + case 0x29: /* NEQ2 */ return 1; break; + case 0x2a: /* GTH2 */ return 1; break; + case 0x2b: /* LTH2 */ return 1; break; + case 0x2c: /* JMP2 */ return 1; break; + case 0x2d: /* JCN2 */ return 1; break; + case 0x2e: /* JSR2 */ return 1; break; + case 0x2f: /* STH2 */ return 1; break; + case 0x30: /* LDZ2 */ return 1; break; + case 0x31: /* STZ2 */ return 1; break; + case 0x32: /* LDR2 */ return 1; break; + case 0x33: /* STR2 */ return 1; break; + case 0x34: /* LDA2 */ return 1; break; + case 0x35: /* STA2 */ return 1; break; + case 0x36: /* DEI2 */ return 1; break; + case 0x37: /* DEO2 */ return 1; break; + case 0x38: /* ADD2 */ return 1; break; + case 0x39: /* SUB2 */ return 1; break; + case 0x3a: /* MUL2 */ return 1; break; + case 0x3b: /* DIV2 */ return 1; break; + case 0x3c: /* AND2 */ return 1; break; + case 0x3d: /* ORA2 */ return 1; break; + case 0x3e: /* EOR2 */ return 1; break; + case 0x3f: /* SFT2 */ return 1; break; + case 0x40: /* JMI */ return 1; break; + case 0x41: /* INCr */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0x42: /* POPr */ uxn.rst.ptr--; pc++; break; + case 0x43: /* NIPr */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0x44: /* SWPr */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0x45: /* ROTr */ break; + case 0x46: /* DUPr */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0x47: /* OVRr */ break; + case 0x48: /* EQUr */ return 1; break; + case 0x49: /* NEQr */ return 1; break; + case 0x4a: /* GTHr */ return 1; break; + case 0x4b: /* LTHr */ return 1; break; + case 0x4c: /* JMPr */ return 1; break; + case 0x4d: /* JCNr */ return 1; break; + case 0x4e: /* JSRr */ return 1; break; + case 0x4f: /* STHr */ return 1; break; + case 0x50: /* LDZr */ return 1; break; + case 0x51: /* STZr */ return 1; break; + case 0x52: /* LDRr */ return 1; break; + case 0x53: /* STRr */ return 1; break; + case 0x54: /* LDAr */ return 1; break; + case 0x55: /* STAr */ return 1; break; + case 0x56: /* DEIr */ return 1; break; + case 0x57: /* DEOr */ return 1; break; + case 0x58: /* ADDr */ return 1; break; + case 0x59: /* SUBr */ return 1; break; + case 0x5a: /* MULr */ return 1; break; + case 0x5b: /* DIVr */ return 1; break; + case 0x5c: /* ANDr */ return 1; break; + case 0x5d: /* ORAr */ return 1; break; + case 0x5e: /* EORr */ return 1; break; + case 0x5f: /* SFTr */ return 1; break; + case 0x60: /* JSI */ return 1; break; + case 0x61: /* INC2r */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0x62: /* POP2r */ uxn.rst.ptr--; pc++; break; + case 0x63: /* NIP2r */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0x64: /* SWP2r */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0x65: /* ROT2r */ break; + case 0x66: /* DUP2r */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0x67: /* OVR2r */ break; + case 0x68: /* EQU2r */ return 1; break; + case 0x69: /* NEQ2r */ return 1; break; + case 0x6a: /* GTH2r */ return 1; break; + case 0x6b: /* LTH2r */ return 1; break; + case 0x6c: /* JMP2r */ return 1; break; + case 0x6d: /* JCN2r */ return 1; break; + case 0x6e: /* JSR2r */ return 1; break; + case 0x6f: /* STH2r */ return 1; break; + case 0x70: /* LDZ2r */ return 1; break; + case 0x71: /* STZ2r */ return 1; break; + case 0x72: /* LDR2r */ return 1; break; + case 0x73: /* STR2r */ return 1; break; + case 0x74: /* LDA2r */ return 1; break; + case 0x75: /* STA2r */ return 1; break; + case 0x76: /* DEI2r */ return 1; break; + case 0x77: /* DEO2r */ return 1; break; + case 0x78: /* ADD2r */ return 1; break; + case 0x79: /* SUB2r */ return 1; break; + case 0x7a: /* MUL2r */ return 1; break; + case 0x7b: /* DIV2r */ return 1; break; + case 0x7c: /* AND2r */ return 1; break; + case 0x7d: /* ORA2r */ return 1; break; + case 0x7e: /* EOR2r */ return 1; break; + case 0x7f: /* SFT2r */ return 1; break; + case 0x80: /* LITk */ uxn.wst.dat[uxn.wst.ptr++] = uxn.ram[++pc]; pc++; break; + case 0x81: /* INCk */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0x82: /* POPk */ uxn.wst.ptr--; pc++; break; + case 0x83: /* NIPk */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0x84: /* SWPk */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0x85: /* ROTk */ break; + case 0x86: /* DUPk */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0x87: /* OVRk */ break; + case 0x88: /* EQUk */ return 1; break; + case 0x89: /* NEQk */ return 1; break; + case 0x8a: /* GTHk */ return 1; break; + case 0x8b: /* LTHk */ return 1; break; + case 0x8c: /* JMPk */ return 1; break; + case 0x8d: /* JCNk */ return 1; break; + case 0x8e: /* JSRk */ return 1; break; + case 0x8f: /* STHk */ return 1; break; + case 0x90: /* LDZk */ return 1; break; + case 0x91: /* STZk */ return 1; break; + case 0x92: /* LDRk */ return 1; break; + case 0x93: /* STRk */ return 1; break; + case 0x94: /* LDAk */ return 1; break; + case 0x95: /* STAk */ return 1; break; + case 0x96: /* DEIk */ return 1; break; + case 0x97: /* DEOk */ return 1; break; + case 0x98: /* ADDk */ return 1; break; + case 0x99: /* SUBk */ return 1; break; + case 0x9a: /* MULk */ return 1; break; + case 0x9b: /* DIVk */ return 1; break; + case 0x9c: /* ANDk */ return 1; break; + case 0x9d: /* ORAk */ return 1; break; + case 0x9e: /* EORk */ return 1; break; + case 0x9f: /* SFTk */ return 1; break; + case 0xa0: /* LIT2k */ break; + case 0xa1: /* INC2k */ uxn.wst.dat[uxn.wst.ptr - 1]++; break; + case 0xa2: /* POP2k */ uxn.wst.ptr--; pc++; break; + case 0xa3: /* NIP2k */ uxn.wst.dat[uxn.wst.ptr--] = uxn.wst.dat[uxn.wst.ptr]; break; + case 0xa4: /* SWP2k */ uxn.wst.dat[uxn.wst.ptr - 1] = uxn.wst.dat[uxn.wst.ptr - 2]; break; + case 0xa5: /* ROT2k */ break; + case 0xa6: /* DUP2k */ uxn.wst.dat[uxn.wst.ptr] = uxn.wst.dat[uxn.wst.ptr]; uxn.wst.ptr++; break; + case 0xa7: /* OVR2k */ break; + case 0xa8: /* EQU2k */ return 1; break; + case 0xa9: /* NEQ2k */ return 1; break; + case 0xaa: /* GTH2k */ return 1; break; + case 0xab: /* LTH2k */ return 1; break; + case 0xac: /* JMP2k */ return 1; break; + case 0xad: /* JCN2k */ return 1; break; + case 0xae: /* JSR2k */ return 1; break; + case 0xaf: /* STH2k */ return 1; break; + case 0xb0: /* LDZ2k */ return 1; break; + case 0xb1: /* STZ2k */ return 1; break; + case 0xb2: /* LDR2k */ return 1; break; + case 0xb3: /* STR2k */ return 1; break; + case 0xb4: /* LDA2k */ return 1; break; + case 0xb5: /* STA2k */ return 1; break; + case 0xb6: /* DEI2k */ return 1; break; + case 0xb7: /* DEO2k */ return 1; break; + case 0xb8: /* ADD2k */ return 1; break; + case 0xb9: /* SUB2k */ return 1; break; + case 0xba: /* MUL2k */ return 1; break; + case 0xbb: /* DIV2k */ return 1; break; + case 0xbc: /* AND2k */ return 1; break; + case 0xbd: /* ORA2k */ return 1; break; + case 0xbe: /* EOR2k */ return 1; break; + case 0xbf: /* SFT2k */ return 1; break; + case 0xc0: /* LITkr */ uxn.rst.dat[uxn.rst.ptr++] = uxn.ram[++pc]; pc++; break; + case 0xc1: /* INCkr */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0xc2: /* POPkr */ uxn.rst.ptr--; pc++; break; + case 0xc3: /* NIPkr */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0xc4: /* SWPkr */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0xc5: /* ROTkr */ break; + case 0xc6: /* DUPkr */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0xc7: /* OVRkr */ break; + case 0xc8: /* EQUkr */ return 1; break; + case 0xc9: /* NEQkr */ return 1; break; + case 0xca: /* GTHkr */ return 1; break; + case 0xcb: /* LTHkr */ return 1; break; + case 0xcc: /* JMPkr */ return 1; break; + case 0xcd: /* JCNkr */ return 1; break; + case 0xce: /* JSRkr */ return 1; break; + case 0xcf: /* STHkr */ return 1; break; + case 0xd0: /* LDZkr */ return 1; break; + case 0xd1: /* STZkr */ return 1; break; + case 0xd2: /* LDRkr */ return 1; break; + case 0xd3: /* STRkr */ return 1; break; + case 0xd4: /* LDAkr */ return 1; break; + case 0xd5: /* STAkr */ return 1; break; + case 0xd6: /* DEIkr */ return 1; break; + case 0xd7: /* DEOkr */ return 1; break; + case 0xd8: /* ADDkr */ return 1; break; + case 0xd9: /* SUBkr */ return 1; break; + case 0xda: /* MULkr */ return 1; break; + case 0xdb: /* DIVkr */ return 1; break; + case 0xdc: /* ANDkr */ return 1; break; + case 0xdd: /* ORAkr */ return 1; break; + case 0xde: /* EORkr */ return 1; break; + case 0xdf: /* SFTkr */ return 1; break; + case 0xe0: /* LIT2kr */ return 1; break; + case 0xe1: /* INC2kr */ uxn.rst.dat[uxn.rst.ptr - 1]++; break; + case 0xe2: /* POP2kr */ uxn.rst.ptr--; pc++; break; + case 0xe3: /* NIP2kr */ uxn.rst.dat[uxn.rst.ptr--] = uxn.rst.dat[uxn.rst.ptr]; break; + case 0xe4: /* SWP2kr */ uxn.rst.dat[uxn.rst.ptr - 1] = uxn.rst.dat[uxn.rst.ptr - 2]; break; + case 0xe5: /* ROT2kr */ break; + case 0xe6: /* DUP2kr */ uxn.rst.dat[uxn.rst.ptr] = uxn.rst.dat[uxn.rst.ptr]; uxn.rst.ptr++; break; + case 0xe7: /* OVR2kr */ break; + case 0xe8: /* EQU2kr */ return 1; break; + case 0xe9: /* NEQ2kr */ return 1; break; + case 0xea: /* GTH2kr */ return 1; break; + case 0xeb: /* LTH2kr */ return 1; break; + case 0xec: /* JMP2kr */ return 1; break; + case 0xed: /* JCN2kr */ return 1; break; + case 0xee: /* JSR2kr */ return 1; break; + case 0xef: /* STH2kr */ return 1; break; + case 0xf0: /* LDZ2kr */ return 1; break; + case 0xf1: /* STZ2kr */ return 1; break; + case 0xf2: /* LDR2kr */ return 1; break; + case 0xf3: /* STR2kr */ return 1; break; + case 0xf4: /* LDA2kr */ return 1; break; + case 0xf5: /* STA2kr */ return 1; break; + case 0xf6: /* DEI2kr */ return 1; break; + case 0xf7: /* DEO2kr */ return 1; break; + case 0xf8: /* ADD2kr */ return 1; break; + case 0xf9: /* SUB2kr */ return 1; break; + case 0xfa: /* MUL2kr */ return 1; break; + case 0xfb: /* DIV2kr */ return 1; break; + case 0xfc: /* AND2kr */ return 1; break; + case 0xfd: /* ORA2kr */ return 1; break; + case 0xfe: /* EOR2kr */ return 1; break; + case 0xff: /* SFT2kr */ return 1; break; } system_inspect(); } @@ -81,10 +318,13 @@ main(int argc, char **argv) /* test */ uxn.ram[0x100] = 0x80; uxn.ram[0x101] = 0x12; + uxn.ram[0x102] = 0x80; uxn.ram[0x103] = 0x34; - uxn.ram[0x104] = 0x01; + + uxn.ram[0x104] = 0x80; + uxn.ram[0x105] = 0x56; if(uxn_eval(0x0100) && (uxn.dev[0x10] << 8 | uxn.dev[0x11])) while(!uxn.dev[0x0f]) ; return uxn.dev[0x0f] & 0x7f; -} +} \ No newline at end of file diff --git a/cli/uxncore/src/uxncore.tal b/cli/uxncore/src/uxncore.tal index 5a40d8d..8ca2a41 100644 --- a/cli/uxncore/src/uxncore.tal +++ b/cli/uxncore/src/uxncore.tal @@ -91,6 +91,7 @@ @op-brk ( byte -- ) DUP #80 EQU ?op-lit + DUP #c0 EQU ?op-lit DUP #a0 EQU ?op-lit2 ;dict/return POP JMP2r @@ -109,9 +110,8 @@ [ LIT2 "] 18 ] DEO [ LIT2 "; 18 ] DEO #2018 DEO - - - [ LIT2 "; 18 ] DEO + + POP JMP2r @op-lit2 ( byte -- ) @@ -131,6 +131,8 @@ [ LIT2 "; 18 ] DEO + #2018 DEO + POP JMP2r @op-nip ( byte -- ) @@ -241,6 +243,12 @@ @ ( -- ) ;dict/pc ! +@ ( -- ) + + + [ LIT2 "; 18 ] DEO + JMP2r + ( @|utils ) @@ -278,9 +286,9 @@ 00 &jsi "JSI 00 ] @dict ( strings ) - &start "int 0a "uxn_eval(Uint16 20 "pc) 20 "{ 0a 09 "Uint8 20 "*ram 20 "= 20 "u->ram; 0a 09 "switch(ram[pc]) 20 "{ $1 - &end 09 "} 0a "} 0a $1 - &case 09 "case 20 $1 + &start "int 0a "uxn_eval(Uint16 20 "pc) 20 "{ 0a 09 "for(;;) 20 "{ 0a 0909 "switch(uxn.ram[pc]) 20 "{ $1 + &end 0909 "} 0a 0909 "system_inspect(); 0a 09 "} 0a "} 0a $1 + &case 0909 "case 20 $1 &break "break; $1 &return "return 20 "1; $1 &uxn-wst-dat "uxn.wst.dat $1