Browse code

Fixed the loop examples

neauoire authored on 02/02/2021 21:02:51
Showing 7 changed files
... ...
@@ -20,7 +20,7 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
20 20
 0302	ADD 
21 21
 05		EQU
22 22
 
23
-.there	JMQ
23
+.there	JMZ
24 24
 
25 25
 :here
26 26
 	< when not equal >
... ...
@@ -3,7 +3,7 @@
3 3
 0302	ADD 
4 4
 05		EQU
5 5
 
6
-.there	JMQ
6
+.there	JMZ
7 7
 
8 8
 :here
9 9
 	< when not equal >
... ...
@@ -1,6 +1,6 @@
1 1
 < jump >
2 2
 
3
-.end JMP BRK
3
+.end JMI BRK
4 4
 
5 5
 :end 
6 6
 	ff
... ...
@@ -1,10 +1,8 @@
1 1
 < loop >
2 2
 
3
-01 .loop JSR BRK
3
+01 .loop JSI ffff BRK
4 4
 
5
-:loop
5
+:loop 
6 6
 	01 ADD
7
-	0f NEQ .loop JMQ
7
+	0f NEQ .loop JMZ
8 8
 	RTS
9
-
10
-:end ff BRK
11 9
\ No newline at end of file
... ...
@@ -1,8 +1,8 @@
1 1
 < subroutines >
2 2
 
3 3
 :begin
4
-  .addall JSR ADD ADD
5
-  06 EQU .isequal JSR
4
+  .addall JSI ADD ADD
5
+  06 EQU .isequal JSI
6 6
   BRK
7 7
 
8 8
 :add1
... ...
@@ -15,11 +15,11 @@
15 15
   03 RTS
16 16
 
17 17
 :addall
18
-  .add1 JSR
19
-  .add2 JSR
20
-  .add3 JSR
18
+  .add1 JSI
19
+  .add2 JSI
20
+  .add3 JSI
21 21
   RTS
22 22
 
23 23
 :isequal
24
-  .addall JSR ff
24
+  .addall JSI ff
25 25
   RTS
... ...
@@ -87,7 +87,7 @@ rspush(Uint8 v)
87 87
 }
88 88
 
89 89
 Uint8
90
-rwspop(void)
90
+rspop(void)
91 91
 {
92 92
 	return cpu.rst.dat[--cpu.rst.ptr];
93 93
 }
... ...
@@ -97,19 +97,19 @@ rwspop(void)
97 97
 /* clang-format off */
98 98
 
99 99
 void op_brk() { setflag(FLAG_HALT, 1); }
100
-void op_rts() {	cpu.rom.ptr = wspop(); }
100
+void op_rts() {	cpu.rom.ptr = rspop(); }
101 101
 void op_lit() { cpu.literal += cpu.rom.dat[cpu.rom.ptr++]; }
102 102
 void op_drp() { wspop(); }
103 103
 void op_dup() { wspush(cpu.wst.dat[cpu.wst.ptr - 1]); }
104 104
 void op_swp() { Uint8 b = wspop(), a = wspop(); wspush(b); wspush(a); }
105 105
 void op_ovr() { wspush(cpu.wst.dat[cpu.wst.ptr - 2]); }
106 106
 void op_rot() { Uint8 c = wspop(),b = wspop(),a = wspop(); wspush(b); wspush(c); wspush(a); }
107
-void op_jmp() { cpu.rom.ptr = wspop(); }
108
-void op_jsr() { rspush(cpu.rom.ptr); cpu.rom.ptr = wspop(); }
109
-void op_jmq() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); }
110
-void op_jsq() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ rspush(cpu.rom.ptr); cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); }
111
-void op_equ() { setflag(FLAG_ZERO, wspop() == cpu.wst.dat[cpu.wst.ptr]); }
112
-void op_neq() { setflag(FLAG_ZERO, wspop() != cpu.wst.dat[cpu.wst.ptr]); }
107
+void op_jmi() { cpu.rom.ptr = wspop(); }
108
+void op_jsi() { rspush(cpu.rom.ptr); cpu.rom.ptr = wspop(); }
109
+void op_jmz() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); }
110
+void op_jsz() { Uint8 a = wspop(); if(getflag(FLAG_ZERO)){ rspush(cpu.rom.ptr); cpu.rom.ptr = a; } setflag(FLAG_ZERO,0); }
111
+void op_equ() { Uint8 a = wspop(); Uint8 b = wspop(); setflag(FLAG_ZERO, a == b); wspush(b); }
112
+void op_neq() { Uint8 a = wspop(); Uint8 b = wspop(); setflag(FLAG_ZERO, a != b); wspush(b); }
113 113
 void op_lth() {	setflag(FLAG_ZERO, wspop() < cpu.wst.dat[cpu.wst.ptr]); }
114 114
 void op_gth() {	setflag(FLAG_ZERO, wspop() > cpu.wst.dat[cpu.wst.ptr]); }
115 115
 void op_and() {	wspush(wspop() & wspop()); }
... ...
@@ -123,13 +123,13 @@ void op_div() { wspush(wspop() / wspop()); }
123 123
 
124 124
 void (*ops[])(void) = {
125 125
 	op_brk, op_rts, op_lit, op_drp, op_dup, op_swp, op_ovr, op_rot, 
126
-	op_jmp, op_jsr, op_jmq, op_jsq, op_equ, op_neq, op_gth, op_lth, 
126
+	op_jmi, op_jsi, op_jmz, op_jsz, op_equ, op_neq, op_gth, op_lth, 
127 127
 	op_and, op_ora, op_rol, op_ror, op_add, op_sub, op_mul, op_div};
128 128
 
129 129
 Uint8 opr[][2] = {
130 130
 	{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
131 131
 	{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
132
-	{0,0}, {0,0}, {0,0}, {0,0}, {2,1}, {0,0}, {0,0}, {0,0},
132
+	{1,0}, {1,0}, {1,0}, {1,0}, {2,1}, {0,0}, {0,0}, {0,0},
133 133
 	{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
134 134
 };
135 135
 
... ...
@@ -179,7 +179,7 @@ eval()
179 179
 	}
180 180
 	if(instr > 0x10)
181 181
 		setflag(FLAG_ZERO, 0);
182
-	if(cpu.counter == 64) {
182
+	if(cpu.counter == 128) {
183 183
 		printf("REACHED COUNTER\n");
184 184
 		return 0;
185 185
 	}
... ...
@@ -33,7 +33,7 @@ Label labels[256];
33 33
 
34 34
 char opcodes[][4] = {
35 35
 	"BRK", "RTS", "LIT", "POP", "DUP", "SWP", "OVR", "ROT",
36
-	"JMP", "JSR", "JMQ", "JSQ", "EQU", "NEQ", "LTH", "GTH",
36
+	"JMI", "JSI", "JMZ", "JSZ", "EQU", "NEQ", "LTH", "GTH",
37 37
 	"AND", "ORA", "ROL", "ROR", "ADD", "SUB", "MUL", "DIV"};
38 38
 
39 39
 /* clang-format on */