Browse code

(uxn.c) Housekeeping

Devine Lu Linvega authored on 26/02/2023 21:07:48
Showing 1 changed files
... ...
@@ -11,42 +11,42 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 11
 WITH REGARD TO THIS SOFTWARE.
12 12
 */
13 13
 
14
-/*	a,b,c: general use.  bs: byte/short bool.
15
-	pc: program counter. sp: ptr to src stack ptr. kptr: "keep" mode copy of src stack ptr.
16
-	x,y: macro in params. d: macro in device. j: macro temp variables. o: macro out param. */
14
+/*	a,b,c: general use. m2: byte/short mode flag.
15
+	tsp: macro temp stack ptr. ksp: "keep" mode copy of stack ptr. sp: ptr to stack ptr.
16
+	x,y: macro in params. o: macro out param. */
17 17
 
18 18
 #define HALT(c) { return uxn_halt(u, instr, (c), pc - 1); }
19
-#define JUMP(x) { if(bs) pc = (x); else pc += (Sint8)(x); }
19
+#define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); }
20 20
 #define PUSH8(x) { if(s->ptr == 0xff) HALT(2) s->dat[s->ptr++] = (x); }
21
-#define PUSH16(x) { if((j = s->ptr) >= 0xfe) HALT(2) k = (x); s->dat[j] = k >> 8; s->dat[j + 1] = k; s->ptr = j + 2; }
22
-#define PUSH(x) { if(bs) { PUSH16(x) } else { PUSH8(x) } }
23
-#define POP8(o) { if(!(j = *sp)) HALT(1) o = (Uint16)s->dat[--j]; *sp = j; }
24
-#define POP16(o) { if((j = *sp) <= 1) HALT(1) o = (s->dat[j - 2] << 8) + s->dat[j - 1]; *sp = j - 2; }
25
-#define POP(o) { if(bs) { POP16(o) } else { POP8(o) } }
26
-#define POKE(x, y) { if(bs) { u->ram[(x)] = (y) >> 8; u->ram[(x) + 1] = (y); } else { u->ram[(x)] = y; } }
27
-#define PEEK16(o, x) { o = (u->ram[(x)] << 8) + u->ram[(x) + 1]; }
28
-#define PEEK(o, x) { if(bs) PEEK16(o, x) else o = u->ram[(x)]; }
29
-#define DEVR(o, x) { o = u->dei(u, x); if (bs) o = (o << 8) + u->dei(u, (x) + 1); }
30
-#define DEVW(x, y) { if (bs) { u->deo(u, (x), (y) >> 8); u->deo(u, (x) + 1, (y)); } else { u->deo(u, x, (y)); } }
21
+#define PUSH16(x) { if((tsp = s->ptr) >= 0xfe) HALT(2) k = (x); s->dat[tsp] = k >> 8; s->dat[tsp + 1] = k; s->ptr = tsp + 2; }
22
+#define PUSH(x) { if(m2) { PUSH16(x) } else { PUSH8(x) } }
23
+#define POP8(o) { if(*sp == 0x00) HALT(1) o = s->dat[--*sp]; }
24
+#define POP16(o) { if((tsp = *sp) <= 0x01) HALT(1) o = s->dat[tsp - 1] | (s->dat[tsp - 2] << 8); *sp = tsp - 2; }
25
+#define POP(o) { if(m2) { POP16(o) } else { POP8(o) } }
26
+#define POKE(x, y) { if(m2) { u->ram[(x)] = (y) >> 8; u->ram[(x) + 1] = (y); } else { u->ram[(x)] = y; } }
27
+#define PEEK16(o, x) { o = (u->ram[(x)] << 8) | u->ram[(x) + 1]; }
28
+#define PEEK(o, x) { if(m2) PEEK16(o, x) else o = u->ram[(x)]; }
29
+#define DEVR(o, x) { o = u->dei(u, x); if (m2) o = (o << 8) | u->dei(u, (x) + 1); }
30
+#define DEVW(x, y) { if (m2) { u->deo(u, (x), (y) >> 8); u->deo(u, (x) + 1, (y)); } else { u->deo(u, x, (y)); } }
31 31
 
32 32
 int
33 33
 uxn_eval(Uxn *u, Uint16 pc)
34 34
 {
35
-	Uint8 kptr, *sp;
36
-	Uint16 a, b, c, j, k, bs, instr, opcode;
35
+	Uint8 ksp, tsp, *sp;
36
+	Uint16 a, b, c, k, m2, instr, opcode;
37 37
 	Stack *s;
38 38
 	if(!pc || u->dev[0x0f]) return 0;
39 39
 	for(;;) {
40 40
 		instr = u->ram[pc++];
41
+		opcode = instr & 0x1f;
41 42
 		/* Short Mode */
42
-		bs = instr & 0x20;
43
+		m2 = instr & 0x20;
43 44
 		/* Return Mode */
44 45
 		s = instr & 0x40 ? u->rst : u->wst;
45 46
 		/* Keep Mode */
46
-		if(instr & 0x80) { kptr = s->ptr; sp = &kptr; }
47
+		if(instr & 0x80) { ksp = s->ptr; sp = &ksp; }
47 48
 		else sp = &s->ptr;
48 49
 		/* Opcodes */
49
-		opcode = instr & 0x1f;
50 50
 		switch(opcode - (!opcode * (instr >> 5))) {
51 51
 		/* Immediate */
52 52
 		case -0x0: /* BRK */ return 1;