|
|
|
|
@ -87,7 +87,7 @@ rspush(Uint8 v)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Uint8 |
|
|
|
|
rwspop(void) |
|
|
|
|
rspop(void) |
|
|
|
|
{ |
|
|
|
|
return cpu.rst.dat[--cpu.rst.ptr]; |
|
|
|
|
} |
|
|
|
|
@ -97,19 +97,19 @@ rwspop(void)
|
|
|
|
|
/* clang-format off */ |
|
|
|
|
|
|
|
|
|
void op_brk() { setflag(FLAG_HALT, 1); } |
|
|
|
|
void op_rts() { cpu.rom.ptr = wspop(); } |
|
|
|
|
void op_rts() { cpu.rom.ptr = rspop(); } |
|
|
|
|
void op_lit() { cpu.literal += cpu.rom.dat[cpu.rom.ptr++]; } |
|
|
|
|
void op_drp() { wspop(); } |
|
|
|
|
void op_dup() { wspush(cpu.wst.dat[cpu.wst.ptr - 1]); } |
|
|
|
|
void op_swp() { Uint8 b = wspop(), a = wspop(); wspush(b); wspush(a); } |
|
|
|
|
void op_ovr() { wspush(cpu.wst.dat[cpu.wst.ptr - 2]); } |
|
|
|
|
void op_rot() { Uint8 c = wspop(),b = wspop(),a = wspop(); wspush(b); wspush(c); wspush(a); } |
|
|
|
|
void op_jmp() { cpu.rom.ptr = wspop(); } |
|
|
|
|
void op_jsr() { rspush(cpu.rom.ptr); cpu.rom.ptr = wspop(); } |
|
|
|
|
void op_jmq() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); } |
|
|
|
|
void op_jsq() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ rspush(cpu.rom.ptr); cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); } |
|
|
|
|
void op_equ() { setflag(FLAG_ZERO, wspop() == cpu.wst.dat[cpu.wst.ptr]); } |
|
|
|
|
void op_neq() { setflag(FLAG_ZERO, wspop() != cpu.wst.dat[cpu.wst.ptr]); } |
|
|
|
|
void op_jmi() { cpu.rom.ptr = wspop(); } |
|
|
|
|
void op_jsi() { rspush(cpu.rom.ptr); cpu.rom.ptr = wspop(); } |
|
|
|
|
void op_jmz() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); } |
|
|
|
|
void op_jsz() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ rspush(cpu.rom.ptr); cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); } |
|
|
|
|
void op_equ() { Uint8 a = wspop(); Uint8 b = wspop(); setflag(FLAG_ZERO, a == b); wspush(b); } |
|
|
|
|
void op_neq() { Uint8 a = wspop(); Uint8 b = wspop(); setflag(FLAG_ZERO, a != b); wspush(b); } |
|
|
|
|
void op_lth() { setflag(FLAG_ZERO, wspop() < cpu.wst.dat[cpu.wst.ptr]); } |
|
|
|
|
void op_gth() { setflag(FLAG_ZERO, wspop() > cpu.wst.dat[cpu.wst.ptr]); } |
|
|
|
|
void op_and() { wspush(wspop() & wspop()); } |
|
|
|
|
@ -123,13 +123,13 @@ void op_div() { wspush(wspop() / wspop()); }
|
|
|
|
|
|
|
|
|
|
void (*ops[])(void) = { |
|
|
|
|
op_brk, op_rts, op_lit, op_drp, op_dup, op_swp, op_ovr, op_rot,
|
|
|
|
|
op_jmp, op_jsr, op_jmq, op_jsq, op_equ, op_neq, op_gth, op_lth,
|
|
|
|
|
op_jmi, op_jsi, op_jmz, op_jsz, op_equ, op_neq, op_gth, op_lth,
|
|
|
|
|
op_and, op_ora, op_rol, op_ror, op_add, op_sub, op_mul, op_div}; |
|
|
|
|
|
|
|
|
|
Uint8 opr[][2] = { |
|
|
|
|
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, |
|
|
|
|
{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,1}, {0,0}, {0,0}, {0,0}, |
|
|
|
|
{1,0}, {1,0}, {1,0}, {1,0}, {2,1}, {0,0}, {0,0}, {0,0}, |
|
|
|
|
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
@ -179,7 +179,7 @@ eval()
|
|
|
|
|
} |
|
|
|
|
if(instr > 0x10) |
|
|
|
|
setflag(FLAG_ZERO, 0); |
|
|
|
|
if(cpu.counter == 64) { |
|
|
|
|
if(cpu.counter == 128) { |
|
|
|
|
printf("REACHED COUNTER\n"); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|