| ... | ... |
@@ -39,10 +39,10 @@ Program p; |
| 39 | 39 |
/* clang-format off */ |
| 40 | 40 |
|
| 41 | 41 |
char ops[][4] = {
|
| 42 |
- "BRK", "NOP", "LIT", "JMP", "JSR", "RTS", "LDR", "STR", |
|
| 43 |
- "---", "---", "---", "---", "AND", "XOR", "ROL", "ROR", |
|
| 42 |
+ "BRK", "NOP", "LIT", "LDR", "STR", "JMP", "JSR", "RTS", |
|
| 43 |
+ "EQU", "NEQ", "GTH", "LTH", "AND", "XOR", "ROL", "ROR", |
|
| 44 | 44 |
"POP", "DUP", "SWP", "OVR", "ROT", "---", "WSR", "RSW", |
| 45 |
- "ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH" |
|
| 45 |
+ "ADD", "SUB", "MUL", "DIV", "---", "---", "---", "---" |
|
| 46 | 46 |
}; |
| 47 | 47 |
|
| 48 | 48 |
int scin(char *s, char c) { int i = 0; while(s[i]) if(s[i++] == c) return i - 1; return -1; } /* string char index */
|
| ... | ... |
@@ -1,52 +1,60 @@ |
| 1 | 1 |
( tests/jump ) |
| 2 | 2 |
|
| 3 |
-&Console { pad 8 char 1 byte 1 short 2 }
|
|
| 4 |
- |
|
| 5 | 3 |
|0100 @RESET |
| 6 | 4 |
|
| 7 |
- ( skip forward with value ) |
|
| 5 |
+ ,test1 JSR2 |
|
| 6 |
+ ,test2 JSR2 |
|
| 7 |
+ |
|
| 8 |
+BRK |
|
| 9 |
+ |
|
| 10 |
+@test1 |
|
| 11 |
+ |
|
| 12 |
+ ( should print 11, 22, 33, 44 ) |
|
| 8 | 13 |
|
| 9 |
- #11 =dev/console.byte |
|
| 14 |
+ #11 =Console.byte |
|
| 10 | 15 |
#03 JMPS BRK BRK BRK |
| 11 | 16 |
|
| 12 | 17 |
( skip foward with id ) |
| 13 | 18 |
|
| 14 |
- #22 =dev/console.byte |
|
| 19 |
+ #22 =Console.byte |
|
| 15 | 20 |
^jump JMPS BRK BRK BRK @jump |
| 16 | 21 |
|
| 17 | 22 |
( skip patterns ) |
| 18 | 23 |
|
| 19 |
- #33 =dev/console.byte |
|
| 24 |
+ #33 =Console.byte |
|
| 20 | 25 |
|
| 21 | 26 |
,skip1 #12 #34 LTH JMP2? POP2 |
| 22 |
- #ff =dev/console.byte |
|
| 27 |
+ #ff =Console.byte |
|
| 23 | 28 |
@skip1 |
| 24 | 29 |
|
| 25 | 30 |
#12 #34 LTH ^skip2 #04 SUB MUL JMPS |
| 26 |
- #ff =dev/console.byte |
|
| 31 |
+ #ff =Console.byte |
|
| 27 | 32 |
@skip2 |
| 28 | 33 |
|
| 29 |
- #44 =dev/console.byte |
|
| 34 |
+ #44 =Console.byte |
|
| 35 |
+ |
|
| 36 |
+RTS |
|
| 37 |
+ |
|
| 38 |
+@test2 |
|
| 30 | 39 |
|
| 31 | 40 |
,end JMP2 |
| 32 | 41 |
|
| 33 | 42 |
( should print aa, bb, cc, dd ) |
| 34 | 43 |
|
| 35 |
- @label1 #aa =dev/console.byte ^label3 JMPS |
|
| 36 |
- @label2 #cc =dev/console.byte ^label4 JMPS |
|
| 37 |
- @label3 #bb =dev/console.byte ^label2 JMPS |
|
| 38 |
- @label4 #dd =dev/console.byte BRK |
|
| 44 |
+ @label1 #aa =Console.byte ^label3 JMPS |
|
| 45 |
+ @label2 #cc =Console.byte ^label4 JMPS |
|
| 46 |
+ @label3 #bb =Console.byte ^label2 JMPS |
|
| 47 |
+ @label4 #dd =Console.byte BRK |
|
| 39 | 48 |
|
| 40 | 49 |
@end |
| 41 | 50 |
|
| 42 | 51 |
^label1 JMPS |
| 43 |
- |
|
| 44 |
-BRK |
|
| 52 |
+RTS |
|
| 45 | 53 |
|
| 46 | 54 |
|c000 @FRAME |
| 47 | 55 |
|d000 @ERROR |
| 48 | 56 |
|
| 49 |
-|FF00 ;dev/console Console |
|
| 57 |
+|FF00 ;Console { pad 8 char 1 byte 1 short 2 }
|
|
| 50 | 58 |
|
| 51 | 59 |
|FFF0 .RESET .FRAME .ERROR ( vectors ) |
| 52 | 60 |
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette ) |
| 53 | 61 |
\ No newline at end of file |
| ... | ... |
@@ -90,27 +90,27 @@ void op_gth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u-
|
| 90 | 90 |
void op_lth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint16)b < (Sint16)a : b < a); }
|
| 91 | 91 |
|
| 92 | 92 |
void (*ops[])(Uxn *u) = {
|
| 93 |
- op_brk, op_nop, op_lit, op_jmp, op_jsr, op_rts, op_ldr, op_str, |
|
| 94 |
- op_nop, op_nop, op_nop, op_nop, op_and, op_xor, op_rol, op_ror, |
|
| 93 |
+ op_brk, op_nop, op_lit, op_ldr, op_str, op_jmp, op_jsr, op_rts, |
|
| 94 |
+ op_equ, op_neq, op_gth, op_lth, op_and, op_xor, op_rol, op_ror, |
|
| 95 | 95 |
op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_wsr, op_rsw, |
| 96 |
- op_add, op_sub, op_mul, op_div, op_equ, op_neq, op_gth, op_lth, |
|
| 96 |
+ op_add, op_sub, op_mul, op_div, op_nop, op_nop, op_nop, op_nop, |
|
| 97 | 97 |
/* 16-bit */ |
| 98 |
- op_brk, op_nop16, op_lit16, op_jmp16, op_jsr16, op_rts, op_ldr16, op_str16, |
|
| 99 |
- op_nop, op_nop, op_nop, op_nop, op_and16, op_xor16, op_rol16, op_ror16, |
|
| 100 |
- op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_wsr16, op_rsw16, op_nop, |
|
| 101 |
- op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16 |
|
| 98 |
+ op_brk, op_nop16, op_lit16, op_ldr16, op_str16, op_jmp16, op_jsr16, op_rts, |
|
| 99 |
+ op_equ16, op_neq16, op_gth16, op_lth16, op_and16, op_xor16, op_rol16, op_ror16, |
|
| 100 |
+ op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_nop, op_wsr16, op_rsw16, |
|
| 101 |
+ op_add16, op_sub16, op_mul16, op_div16, op_nop, op_nop, op_nop, op_nop |
|
| 102 | 102 |
}; |
| 103 | 103 |
|
| 104 |
-Uint8 opr[][2] = {
|
|
| 105 |
- {0,0}, {0,0}, {0,0}, {1,0}, {1,0}, {0,0}, {2,1}, {3,0},
|
|
| 106 |
- {2,0}, {2,0}, {0,0}, {0,0}, {2,1}, {2,1}, {2,1}, {2,1},
|
|
| 107 |
- {1,0}, {1,2}, {2,2}, {2,3}, {3,3}, {1,0}, {0,1}, {2,1},
|
|
| 108 |
- {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1}, {2,1},
|
|
| 104 |
+Uint8 opr[][4] = { /* wstack-/+ rstack-/+ */
|
|
| 105 |
+ {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,1,0,0}, {3,0,0,0}, {1,0,0,0}, {1,0,0,2}, {0,0,2,0},
|
|
| 106 |
+ {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0},
|
|
| 107 |
+ {1,0,0,0}, {1,2,0,0}, {2,2,0,0}, {2,3,0,0}, {3,3,0,0}, {0,0,0,0}, {1,0,0,1}, {0,1,1,0},
|
|
| 108 |
+ {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {2,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
|
| 109 | 109 |
/* 16-bit */ |
| 110 |
- {0,0}, {0,0}, {0,0}, {2,0}, {2,0}, {0,0}, {2,2}, {4,0}, /* TODO */
|
|
| 111 |
- {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, /* TODO */
|
|
| 112 |
- {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {2,0}, {0,2}, {0,0}, /* TODO */
|
|
| 113 |
- {4,2}, {4,2}, {4,2}, {4,2}, {4,2}, {4,2}, {4,2}, {4,2}
|
|
| 110 |
+ {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,2,0,0}, {4,0,0,0}, {2,0,0,0}, {2,0,0,0}, {0,0,0,0}, /* TODO */
|
|
| 111 |
+ {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, /* TODO */
|
|
| 112 |
+ {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,0,0,2}, {0,2,2,0}, /* TODO */
|
|
| 113 |
+ {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {4,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}
|
|
| 114 | 114 |
}; |
| 115 | 115 |
|
| 116 | 116 |
/* clang-format on */ |
| ... | ... |
@@ -121,7 +121,6 @@ int |
| 121 | 121 |
haltuxn(Uxn *u, char *name, int id) |
| 122 | 122 |
{
|
| 123 | 123 |
printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->counter);
|
| 124 |
- op_nop(u); |
|
| 125 | 124 |
return 0; |
| 126 | 125 |
} |
| 127 | 126 |
|
| ... | ... |
@@ -145,9 +144,13 @@ opcuxn(Uxn *u, Uint8 instr) |
| 145 | 144 |
if(getflag(&u->status, FLAG_SHORT)) |
| 146 | 145 |
op += 32; |
| 147 | 146 |
if(u->wst.ptr < opr[op][0]) |
| 148 |
- return haltuxn(u, "Stack underflow", op); |
|
| 147 |
+ return haltuxn(u, "Working-stack underflow", op); |
|
| 149 | 148 |
if(u->wst.ptr + opr[op][1] - opr[op][0] >= 255) |
| 150 |
- return haltuxn(u, "Stack overflow", instr); |
|
| 149 |
+ return haltuxn(u, "Working-stack overflow", instr); |
|
| 150 |
+ if(u->rst.ptr < opr[op][2]) |
|
| 151 |
+ return haltuxn(u, "Return-stack underflow", op); |
|
| 152 |
+ if(u->rst.ptr + opr[op][3] - opr[op][2] >= 255) |
|
| 153 |
+ return haltuxn(u, "Return-stack overflow", instr); |
|
| 151 | 154 |
if(!getflag(&u->status, FLAG_COND) || (getflag(&u->status, FLAG_COND) && pop8(&u->wst))) |
| 152 | 155 |
(*ops[op])(u); |
| 153 | 156 |
return 1; |