Browse code

Merged lit counter with status flag

neauoire authored on 04/04/2021 16:37:00
Showing 2 changed files
... ...
@@ -34,7 +34,7 @@ Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u,
34 34
 /* Stack */
35 35
 void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
36 36
 void op_nop(Uxn *u) { (void)u; }
37
-void op_lit(Uxn *u) { u->literal += 1; }
37
+void op_lit(Uxn *u) { setflag(&u->status, FLAG_LIT1, 1); }
38 38
 void op_pop(Uxn *u) { pop8(u->src); }
39 39
 void op_dup(Uxn *u) { push8(u->src, peek8(u->src, 0)); }
40 40
 void op_swp(Uxn *u) { Uint8 b = pop8(u->src), a = pop8(u->src); push8(u->src, b); push8(u->src, a); }
... ...
@@ -66,7 +66,7 @@ void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b
66 66
 void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); }
67 67
 void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); }
68 68
 /* Stack */
69
-void op_lit16(Uxn *u) { u->literal += 2; }
69
+void op_lit16(Uxn *u) { setflag(&u->status, FLAG_LIT2, 1); }
70 70
 void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); }
71 71
 void op_pop16(Uxn *u) { pop16(u->src); }
72 72
 void op_dup16(Uxn *u) { push16(u->src, peek16(u->src, 0)); }
... ...
@@ -126,7 +126,11 @@ void
126 126
 lituxn(Uxn *u, Uint8 instr)
127 127
 {
128 128
 	push8(u->src, instr);
129
-	u->literal--;
129
+	if(getflag(&u->status, FLAG_LIT2)) {
130
+		setflag(&u->status, FLAG_LIT2, 0);
131
+		setflag(&u->status, FLAG_LIT1, 1);
132
+	} else if(getflag(&u->status, FLAG_LIT1))
133
+		setflag(&u->status, FLAG_LIT1, 0);
130 134
 }
131 135
 
132 136
 void
... ...
@@ -141,7 +145,7 @@ opcuxn(Uxn *u, Uint8 instr)
141 145
 int
142 146
 stepuxn(Uxn *u, Uint8 instr)
143 147
 {
144
-	if(u->literal > 0)
148
+	if(getflag(&u->status, FLAG_LIT2) || getflag(&u->status, FLAG_LIT1))
145 149
 		lituxn(u, instr);
146 150
 	else
147 151
 		opcuxn(u, instr);
... ...
@@ -155,7 +159,7 @@ stepuxn(Uxn *u, Uint8 instr)
155 159
 int
156 160
 evaluxn(Uxn *u, Uint16 vec)
157 161
 {
158
-	u->literal = 0;
162
+	u->status = 0;
159 163
 	u->ram.ptr = vec;
160 164
 	u->wst.error = 0;
161 165
 	u->rst.error = 0;
... ...
@@ -195,6 +199,6 @@ portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0
195 199
 	Device *d = &u->dev[id];
196 200
 	d->addr = PAGE_DEVICE + id * 0x10;
197 201
 	d->poke = pofn;
198
-	printf("Device #%d: %s, at 0x%04x \n", id - 1, name, d->addr);
202
+	printf("Device #%d: %s, at 0x%04x \n", id, name, d->addr);
199 203
 	return d;
200 204
 }
... ...
@@ -17,8 +17,8 @@ typedef unsigned short Uint16;
17 17
 typedef signed short Sint16;
18 18
 
19 19
 #define FLAG_HALT 0x01
20
-#define FLAG_LIT1 0x04
21
-#define FLAG_LIT2 0x08
20
+#define FLAG_LIT1 0x02
21
+#define FLAG_LIT2 0x04
22 22
 #define PAGE_DEVICE 0x0100
23 23
 #define PAGE_VECTORS 0x0200
24 24
 
... ...
@@ -40,7 +40,7 @@ typedef struct Device {
40 40
 } Device;
41 41
 
42 42
 typedef struct Uxn {
43
-	Uint8 literal, status;
43
+	Uint8 status;
44 44
 	Stack wst, rst, *src, *dst;
45 45
 	Memory ram;
46 46
 	Device dev[16];