Browse code

Return stack is now St8

neauoire authored on 11/02/2021 17:45:35
Showing 4 changed files
... ...
@@ -38,7 +38,7 @@ consolew(Device *d, Uint8 b)
38 38
 }
39 39
 
40 40
 void
41
-echos(Stack8 *s, Uint8 len, char *name)
41
+echos(St8 *s, Uint8 len, char *name)
42 42
 {
43 43
 	int i;
44 44
 	printf("\n%s\n", name);
... ...
@@ -106,7 +106,7 @@ init(void)
106 106
 }
107 107
 
108 108
 void
109
-echos(Stack8 *s, Uint8 len, char *name)
109
+echos(St8 *s, Uint8 len, char *name)
110 110
 {
111 111
 	int i;
112 112
 	printf("\n%s\n", name);
... ...
@@ -19,15 +19,32 @@ WITH REGARD TO THIS SOFTWARE.
19 19
 
20 20
 void   setflag(Uint8 *st, char flag, int b) { if(b) *st |= flag; else *st &= (~flag); }
21 21
 int    getflag(Uint8 *st, char flag) { return *st & flag; }
22
+Uint8  mempeek8(Uxn *u, Uint16 s) { return u->ram.dat[s]; }
23
+Uint16 mempeek16(Uxn *u, Uint16 s) { return (u->ram.dat[s] << 8) + (u->ram.dat[s + 1] & 0xff); }
24
+
22 25
 void   wspush8(Uxn *u, Uint8 b) { u->wst.dat[u->wst.ptr++] = b; }
23 26
 Uint8  wspop8(Uxn *u) { return u->wst.dat[--u->wst.ptr]; }
24 27
 Uint8  wspeek8(Uxn *u, Uint8 o) { return u->wst.dat[u->wst.ptr - o]; }
25
-Uint8  mempeek8(Uxn *u, Uint16 s) { return u->ram.dat[s]; }
26 28
 void   wspush16(Uxn *u, Uint16 s) { wspush8(u,s >> 8); wspush8(u,s & 0xff); }
27 29
 Uint16 wspop16(Uxn *u) { return wspop8(u) + (wspop8(u) << 8); }
28 30
 Uint16 wspeek16(Uxn *u, Uint8 o) { return (u->wst.dat[u->wst.ptr - o] << 8) + u->wst.dat[u->wst.ptr - o + 1]; }
29
-void   rspush16(Uxn *u, Uint16 a) { u->rst.dat[u->rst.ptr++] = a; }
30
-Uint16 mempeek16(Uxn *u, Uint16 s) { return (u->ram.dat[s] << 8) + (u->ram.dat[s + 1] & 0xff); }
31
+
32
+
33
+Uint8 rspop8(Uxn *u){
34
+	return u->rst.dat[--u->rst.ptr];
35
+}
36
+
37
+void   rspush16(Uxn *u, Uint16 a) { 
38
+
39
+
40
+	u->rst.dat[u->rst.ptr++] = (a >> 8) & 0xff;  
41
+	u->rst.dat[u->rst.ptr++] = a & 0xff;  
42
+
43
+}
44
+Uint16 rspop16(Uxn *u) { 
45
+	return rspop8(u) + (rspop8(u) << 8); 
46
+}
47
+
31 48
 
32 49
 /* I/O */
33 50
 void op_brk(Uxn *u) { setflag(&u->status,FLAG_HALT, 1); }
... ...
@@ -40,8 +57,8 @@ void op_ldr(Uxn *u) { Uint16 a = wspop16(u); wspush8(u, u->ram.dat[a]); }
40 57
 void op_str(Uxn *u) { Uint16 a = wspop16(u); Uint8 b = wspop8(u); u->ram.dat[a] = b; }
41 58
 /* Logic */
42 59
 void op_jmp(Uxn *u) { u->ram.ptr = wspop16(u); }
43
-void op_jsr(Uxn *u) { u->rst.dat[u->rst.ptr++] = u->ram.ptr; u->ram.ptr = wspop16(u); }
44
-void op_rts(Uxn *u) { u->ram.ptr = u->rst.dat[--u->rst.ptr]; }
60
+void op_jsr(Uxn *u) { rspush16(u, u->ram.ptr); u->ram.ptr = wspop16(u); }
61
+void op_rts(Uxn *u) { u->ram.ptr = rspop16(u); }
45 62
 /* Stack */
46 63
 void op_pop(Uxn *u) { wspop8(u); }
47 64
 void op_dup(Uxn *u) { wspush8(u, wspeek8(u, 1)); }
... ...
@@ -22,12 +22,7 @@ typedef unsigned short Uint16;
22 22
 typedef struct {
23 23
 	Uint8 ptr;
24 24
 	Uint8 dat[256];
25
-} Stack8;
26
-
27
-typedef struct {
28
-	Uint8 ptr;
29
-	Uint16 dat[256];
30
-} Stack16;
25
+} St8;
31 26
 
32 27
 typedef struct {
33 28
 	Uint16 ptr;
... ...
@@ -43,8 +38,7 @@ typedef struct Device {
43 38
 typedef struct {
44 39
 	Uint8 literal, status, devices;
45 40
 	Uint16 counter, devr, devw, vreset, vframe, verror;
46
-	Stack8 wst;
47
-	Stack16 rst;
41
+	St8 wst, rst;
48 42
 	Memory ram;
49 43
 	Device dev[256];
50 44
 } Uxn;