| ... | ... |
@@ -6,21 +6,20 @@ |
| 6 | 6 |
@0100 |
| 7 | 7 |
|
| 8 | 8 |
:RESET ( --- ) |
| 9 |
- |
|
| 10 |
-,22 ,var1 STR ( store 0x22 in var1 ) |
|
| 11 |
-,var1 LDR ( load var2, put value on stack ) |
|
| 12 |
- |
|
| 13 |
-BRK |
|
| 9 |
+ ,1234 |
|
| 10 |
+ BRK |
|
| 14 | 11 |
|
| 15 | 12 |
@c000 ( much further.. ) |
| 16 | 13 |
|
| 17 | 14 |
:FRAME ( --- ) |
| 18 |
- BRK |
|
| 15 |
+ ,ab ,0008 str |
|
| 16 |
+ BRK |
|
| 19 | 17 |
|
| 20 | 18 |
@d000 ( further still.. ) |
| 21 | 19 |
|
| 22 | 20 |
:ERROR ( --- ) |
| 23 |
- BRK |
|
| 21 |
+ ,cdef |
|
| 22 |
+ BRK |
|
| 24 | 23 |
|
| 25 | 24 |
@FFFA ( vectors, last 3 shorts ) |
| 26 | 25 |
|
| ... | ... |
@@ -85,45 +85,39 @@ echom(Memory *m, Uint8 len, char *name) |
| 85 | 85 |
|
| 86 | 86 |
/* clang-format off */ |
| 87 | 87 |
|
| 88 |
-Uint8 mempoke8(Uint16 p) { return cpu.rom.dat[p+1] & 0xff; }
|
|
| 89 |
-Uint16 mempoke16(Uint16 p) { return (cpu.rom.dat[p] << 8) + (cpu.rom.dat[p+1] & 0xff); }
|
|
| 90 |
-void wspush(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; }
|
|
| 91 |
-Uint8 wspop(void) { return cpu.wst.dat[--cpu.wst.ptr]; }
|
|
| 92 |
-void wspush16(Uint16 s) {
|
|
| 93 |
- |
|
| 94 |
- printf("0x%04x\n", s);
|
|
| 95 |
-} |
|
| 96 |
-Uint16 wspop16(void) { return wspop() + (wspop() << 8); }
|
|
| 97 |
-Uint8 wspeek(void) { return cpu.wst.dat[cpu.wst.ptr - 1]; }
|
|
| 98 |
-void rspush(Uint8 b) { cpu.rst.dat[cpu.rst.ptr++] = b; }
|
|
| 99 |
-Uint8 rspop(void) { return cpu.rst.dat[--cpu.rst.ptr]; }
|
|
| 88 |
+Uint8 mempeek8(Uint16 s) { return cpu.rom.dat[s] & 0xff; }
|
|
| 89 |
+Uint16 mempeek16(Uint16 s) { return (cpu.rom.dat[s] << 8) + (cpu.rom.dat[s+1] & 0xff); }
|
|
| 90 |
+void wspush8(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; }
|
|
| 91 |
+Uint8 wspop8(void) { return cpu.wst.dat[--cpu.wst.ptr]; }
|
|
| 92 |
+Uint16 wspop16(void) { return wspop8() + (wspop8() << 8); }
|
|
| 93 |
+Uint8 wspeek8(void) { return cpu.wst.dat[cpu.wst.ptr - 1]; }
|
|
| 100 | 94 |
|
| 101 | 95 |
void op_brk() { setflag(FLAG_HALT, 1); }
|
| 102 |
-void op_rts() { cpu.rom.ptr = rspop(); }
|
|
| 96 |
+void op_rts() { cpu.rom.ptr = cpu.rst.dat[--cpu.rst.ptr]; }
|
|
| 103 | 97 |
void op_lit() { cpu.literal += cpu.rom.dat[cpu.rom.ptr++]; }
|
| 104 |
-void op_drp() { wspop(); }
|
|
| 105 |
-void op_dup() { wspush(wspeek()); }
|
|
| 106 |
-void op_swp() { Uint8 b = wspop(), a = wspop(); wspush(b); wspush(a); }
|
|
| 107 |
-void op_ovr() { wspush(cpu.wst.dat[cpu.wst.ptr - 2]); }
|
|
| 108 |
-void op_rot() { Uint8 c = wspop(),b = wspop(),a = wspop(); wspush(b); wspush(c); wspush(a); }
|
|
| 109 |
-void op_jmu() { cpu.rom.ptr = wspop(); }
|
|
| 110 |
-void op_jsu() { rspush(cpu.rom.ptr); cpu.rom.ptr = wspop(); }
|
|
| 111 |
-void op_jmc() { if(wspop()) op_jmu(); }
|
|
| 112 |
-void op_jsc() { if(wspop()) op_jsu(); }
|
|
| 113 |
-void op_equ() { wspush(wspop() == wspop()); }
|
|
| 114 |
-void op_neq() { wspush(wspop() != wspop()); }
|
|
| 115 |
-void op_gth() { wspush(wspop() < wspop()); }
|
|
| 116 |
-void op_lth() { wspush(wspop() > wspop()); }
|
|
| 117 |
-void op_and() { wspush(wspop() & wspop()); }
|
|
| 118 |
-void op_ora() { wspush(wspop() | wspop()); }
|
|
| 119 |
-void op_rol() { wspush(wspop() << 1); }
|
|
| 120 |
-void op_ror() { wspush(wspop() >> 1); }
|
|
| 121 |
-void op_add() { wspush(wspop() + wspop()); }
|
|
| 122 |
-void op_sub() { wspush(wspop() - wspop()); }
|
|
| 123 |
-void op_mul() { wspush(wspop() * wspop()); }
|
|
| 124 |
-void op_div() { wspush(wspop() / wspop()); }
|
|
| 125 |
-void op_ldr() { wspush(cpu.ram.dat[wspop16()]); }
|
|
| 126 |
-void op_str() { cpu.ram.dat[wspop16()] = wspop(); }
|
|
| 98 |
+void op_drp() { wspop8(); }
|
|
| 99 |
+void op_dup() { wspush8(wspeek8()); }
|
|
| 100 |
+void op_swp() { Uint8 b = wspop8(), a = wspop8(); wspush8(b); wspush8(a); }
|
|
| 101 |
+void op_ovr() { wspush8(cpu.wst.dat[cpu.wst.ptr - 2]); }
|
|
| 102 |
+void op_rot() { Uint8 c = wspop8(),b = wspop8(),a = wspop8(); wspush8(b); wspush8(c); wspush8(a); }
|
|
| 103 |
+void op_jmu() { cpu.rom.ptr = wspop8(); }
|
|
| 104 |
+void op_jsu() { cpu.rst.dat[cpu.rst.ptr++] = cpu.rom.ptr; cpu.rom.ptr = wspop8(); }
|
|
| 105 |
+void op_jmc() { if(wspop8()) op_jmu(); }
|
|
| 106 |
+void op_jsc() { if(wspop8()) op_jsu(); }
|
|
| 107 |
+void op_equ() { wspush8(wspop8() == wspop8()); }
|
|
| 108 |
+void op_neq() { wspush8(wspop8() != wspop8()); }
|
|
| 109 |
+void op_gth() { wspush8(wspop8() < wspop8()); }
|
|
| 110 |
+void op_lth() { wspush8(wspop8() > wspop8()); }
|
|
| 111 |
+void op_and() { wspush8(wspop8() & wspop8()); }
|
|
| 112 |
+void op_ora() { wspush8(wspop8() | wspop8()); }
|
|
| 113 |
+void op_rol() { wspush8(wspop8() << 1); }
|
|
| 114 |
+void op_ror() { wspush8(wspop8() >> 1); }
|
|
| 115 |
+void op_add() { wspush8(wspop8() + wspop8()); }
|
|
| 116 |
+void op_sub() { wspush8(wspop8() - wspop8()); }
|
|
| 117 |
+void op_mul() { wspush8(wspop8() * wspop8()); }
|
|
| 118 |
+void op_div() { wspush8(wspop8() / wspop8()); }
|
|
| 119 |
+void op_ldr() { wspush8(cpu.ram.dat[wspop16()]); }
|
|
| 120 |
+void op_str() { cpu.ram.dat[wspop16()] = wspop8(); }
|
|
| 127 | 121 |
|
| 128 | 122 |
void (*ops[])(void) = {
|
| 129 | 123 |
op_brk, op_rts, op_lit, op_drp, op_dup, op_swp, op_ovr, op_rot, |
| ... | ... |
@@ -169,7 +163,7 @@ eval(void) |
| 169 | 163 |
{
|
| 170 | 164 |
Uint8 instr = cpu.rom.dat[cpu.rom.ptr++]; |
| 171 | 165 |
if(cpu.literal > 0) {
|
| 172 |
- wspush(instr); |
|
| 166 |
+ wspush8(instr); |
|
| 173 | 167 |
cpu.literal--; |
| 174 | 168 |
return 1; |
| 175 | 169 |
} |
| ... | ... |
@@ -194,14 +188,17 @@ start(FILE *f) |
| 194 | 188 |
{
|
| 195 | 189 |
reset(); |
| 196 | 190 |
fread(cpu.rom.dat, sizeof(cpu.rom.dat), 1, f); |
| 197 |
- cpu.vreset = mempoke16(0xfffa); |
|
| 198 |
- cpu.vframe = mempoke16(0xfffc); |
|
| 199 |
- cpu.verror = mempoke16(0xfffe); |
|
| 191 |
+ cpu.vreset = mempeek16(0xfffa); |
|
| 192 |
+ cpu.vframe = mempeek16(0xfffc); |
|
| 193 |
+ cpu.verror = mempeek16(0xfffe); |
|
| 200 | 194 |
/* eval reset */ |
| 195 |
+ printf("Phase: reset\n");
|
|
| 201 | 196 |
cpu.rom.ptr = cpu.vreset; |
| 202 | 197 |
while(!(cpu.status & FLAG_HALT) && eval()) |
| 203 | 198 |
; |
| 204 | 199 |
/*eval frame */ |
| 200 |
+ printf("Phase: frame\n");
|
|
| 201 |
+ setflag(FLAG_HALT, 0); |
|
| 205 | 202 |
cpu.rom.ptr = cpu.vframe; |
| 206 | 203 |
while(!(cpu.status & FLAG_HALT) && eval()) |
| 207 | 204 |
; |