Browse code

Moved wsr/rsw ops

neauoire authored on 27/02/2021 04:00:01
Showing 3 changed files
... ...
@@ -46,7 +46,7 @@ Program p;
46 46
 char ops[][4] = {
47 47
 	"BRK", "NOP", "LIT", "---", "---", "---", "LDR", "STR",
48 48
 	"JMP", "JSR", "---", "RTS", "AND", "ORA", "ROL", "ROR",
49
-	"POP", "DUP", "SWP", "OVR", "ROT", "WSR", "RSW", "---",
49
+	"POP", "DUP", "SWP", "OVR", "ROT", "---", "WSR", "RSW",
50 50
 	"ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH"
51 51
 };
52 52
 
... ...
@@ -50,8 +50,8 @@ void op_dup(Uxn *u) { push8(&u->wst, peek8(&u->wst, 0)); }
50 50
 void op_swp(Uxn *u) { Uint8 b = pop8(&u->wst), a = pop8(&u->wst); push8(&u->wst, b); push8(&u->wst, a); }
51 51
 void op_ovr(Uxn *u) { push8(&u->wst, peek8(&u->wst, 1)); }
52 52
 void op_rot(Uxn *u) { Uint8 c = pop8(&u->wst), b = pop8(&u->wst), a = pop8(&u->wst); push8(&u->wst, b); push8(&u->wst, c); push8(&u->wst, a); }
53
-void op_wsr(Uxn *u) { Uint8 a = pop8(&u->wst); push8(&u->rst, a); u->balance++; }
54
-void op_rsw(Uxn *u) { Uint8 a = pop8(&u->rst); push8(&u->wst, a); u->balance--; }
53
+void op_wsr(Uxn *u) { Uint8 a = pop8(&u->wst); push8(&u->rst, a); }
54
+void op_rsw(Uxn *u) { Uint8 a = pop8(&u->rst); push8(&u->wst, a); }
55 55
 /* Arithmetic */
56 56
 void op_add(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint8)b + (Sint8)a : b + a); }
57 57
 void op_sub(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint8)b - (Sint8)a : b - a); }
... ...
@@ -76,8 +76,8 @@ void op_dup16(Uxn *u) { push16(&u->wst, peek16(&u->wst, 0)); }
76 76
 void op_swp16(Uxn *u) { Uint16 b = pop16(&u->wst), a = pop16(&u->wst); push16(&u->wst, b); push16(&u->wst, a); }
77 77
 void op_ovr16(Uxn *u) { push16(&u->wst, peek16(&u->wst, 1)); }
78 78
 void op_rot16(Uxn *u) { Uint16 c = pop16(&u->wst), b = pop16(&u->wst), a = pop16(&u->wst); push16(&u->wst, b); push16(&u->wst, c); push16(&u->wst, a); }
79
-void op_wsr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->rst, a); u->balance += 2; }
80
-void op_rsw16(Uxn *u) { Uint16 a = pop16(&u->rst); push16(&u->wst, a); u->balance -= 2; }
79
+void op_wsr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->rst, a); }
80
+void op_rsw16(Uxn *u) { Uint16 a = pop16(&u->rst); push16(&u->wst, a); }
81 81
 /* Arithmetic(16-bits) */
82 82
 void op_add16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint16)b + (Sint16)a : b + a); }
83 83
 void op_sub16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint16)b - (Sint16)a : b - a); }
... ...
@@ -91,7 +91,7 @@ void op_lth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u-
91 91
 void (*ops[])(Uxn *u) = {
92 92
 	op_brk, op_nop, op_lit, op_nop, op_nop, op_nop, op_ldr, op_str, 
93 93
 	op_jmp, op_jsr, op_nop, op_rts, op_and, op_ora, op_rol, op_ror, 
94
-	op_pop, op_dup, op_swp, op_ovr, op_rot, op_wsr, op_rsw, op_nop,
94
+	op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_wsr, op_rsw,
95 95
 	op_add, op_sub, op_mul, op_div, op_equ, op_neq, op_gth, op_lth,
96 96
 	/* 16-bit */
97 97
 	op_brk,   op_nop16, op_lit16, op_nop,   op_nop,   op_nop,   op_ldr16, op_str16, 
... ...
@@ -139,8 +139,6 @@ opcuxn(Uxn *u, Uint8 instr)
139 139
 	setflag(&u->status, FLAG_SHORT, (instr >> 5) & 1);
140 140
 	setflag(&u->status, FLAG_SIGN, (instr >> 6) & 1);
141 141
 	setflag(&u->status, FLAG_COND, (instr >> 7) & 1);
142
-	if((op == 0x09 || op == 0x0b) && u->balance)
143
-		return haltuxn(u, "Stack unbalance", op);
144 142
 	if(getflag(&u->status, FLAG_SHORT))
145 143
 		op += 32;
146 144
 	if(u->wst.ptr < opr[op][0])
... ...
@@ -38,7 +38,7 @@ typedef struct Device {
38 38
 } Device;
39 39
 
40 40
 typedef struct {
41
-	Uint8 literal, status, balance, devices;
41
+	Uint8 literal, status, devices;
42 42
 	Uint16 counter, devr, devw, vreset, vframe, verror;
43 43
 	Stack wst, rst;
44 44
 	Memory ram;