commit 6d445ccee1fbc435af5e893a161b227a78d509f3
parent cb2496ee0f30c3c6b782c8e61ec6eaeeb07246d2
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 2 Feb 2021 13:02:51 -0800
Fixed the loop examples
Diffstat:
7 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/README.md b/README.md
@@ -20,7 +20,7 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
0302 ADD
05 EQU
-.there JMQ
+.there JMZ
:here
< when not equal >
diff --git a/examples/cond.usm b/examples/cond.usm
@@ -3,7 +3,7 @@
0302 ADD
05 EQU
-.there JMQ
+.there JMZ
:here
< when not equal >
diff --git a/examples/jump.usm b/examples/jump.usm
@@ -1,6 +1,6 @@
< jump >
-.end JMP BRK
+.end JMI BRK
:end
ff
diff --git a/examples/loop.usm b/examples/loop.usm
@@ -1,10 +1,8 @@
< loop >
-01 .loop JSR BRK
+01 .loop JSI ffff BRK
-:loop
+:loop
01 ADD
- 0f NEQ .loop JMQ
+ 0f NEQ .loop JMZ
RTS
-
-:end ff BRK
-\ No newline at end of file
diff --git a/examples/subroutines.usm b/examples/subroutines.usm
@@ -1,8 +1,8 @@
< subroutines >
:begin
- .addall JSR ADD ADD
- 06 EQU .isequal JSR
+ .addall JSI ADD ADD
+ 06 EQU .isequal JSI
BRK
:add1
@@ -15,11 +15,11 @@
03 RTS
:addall
- .add1 JSR
- .add2 JSR
- .add3 JSR
+ .add1 JSI
+ .add2 JSI
+ .add3 JSI
RTS
:isequal
- .addall JSR ff
+ .addall JSI ff
RTS
diff --git a/uxn.c b/uxn.c
@@ -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;
}
diff --git a/uxnasm.c b/uxnasm.c
@@ -33,7 +33,7 @@ Label labels[256];
char opcodes[][4] = {
"BRK", "RTS", "LIT", "POP", "DUP", "SWP", "OVR", "ROT",
- "JMP", "JSR", "JMQ", "JSQ", "EQU", "NEQ", "LTH", "GTH",
+ "JMI", "JSI", "JMZ", "JSZ", "EQU", "NEQ", "LTH", "GTH",
"AND", "ORA", "ROL", "ROR", "ADD", "SUB", "MUL", "DIV"};
/* clang-format on */