Browse code

Renamed PEEK16/POKE16 to PEEK2/POKE2

Devine Lu Linvega authored on 12/03/2023 22:25:52
Showing 10 changed files
... ...
@@ -76,8 +76,8 @@ audio_start(int instance, Uint8 *d, Uxn *u)
76 76
 {
77 77
 	UxnAudio *c = &uxn_audio[instance];
78 78
 	Uint8 pitch = d[0xf] & 0x7f;
79
-	Uint16 addr = PEEK16(d + 0xc), adsr = PEEK16(d + 0x8);
80
-	c->len = PEEK16(d + 0xa);
79
+	Uint16 addr = PEEK2(d + 0xc), adsr = PEEK2(d + 0x8);
80
+	c->len = PEEK2(d + 0xa);
81 81
 	if(c->len > 0x10000 - addr)
82 82
 		c->len = 0x10000 - addr;
83 83
 	c->addr = &u->ram[addr];
... ...
@@ -17,7 +17,7 @@ controller_down(Uxn *u, Uint8 *d, Uint8 mask)
17 17
 {
18 18
 	if(mask) {
19 19
 		d[2] |= mask;
20
-		uxn_eval(u, PEEK16(d));
20
+		uxn_eval(u, PEEK2(d));
21 21
 	}
22 22
 }
23 23
 
... ...
@@ -26,7 +26,7 @@ controller_up(Uxn *u, Uint8 *d, Uint8 mask)
26 26
 {
27 27
 	if(mask) {
28 28
 		d[2] &= (~mask);
29
-		uxn_eval(u, PEEK16(d));
29
+		uxn_eval(u, PEEK2(d));
30 30
 	}
31 31
 }
32 32
 
... ...
@@ -35,7 +35,7 @@ controller_key(Uxn *u, Uint8 *d, Uint8 key)
35 35
 {
36 36
 	if(key) {
37 37
 		d[3] = key;
38
-		uxn_eval(u, PEEK16(d));
38
+		uxn_eval(u, PEEK2(d));
39 39
 		d[3] = 0x00;
40 40
 	}
41 41
 }
... ...
@@ -237,37 +237,37 @@ file_deo(Uint8 id, Uint8 *ram, Uint8 *d, Uint8 port)
237 237
 	Uint16 addr, len, res;
238 238
 	switch(port) {
239 239
 	case 0x5:
240
-		addr = PEEK16(d + 0x4);
241
-		len = PEEK16(d + 0xa);
240
+		addr = PEEK2(d + 0x4);
241
+		len = PEEK2(d + 0xa);
242 242
 		if(len > 0x10000 - addr)
243 243
 			len = 0x10000 - addr;
244 244
 		res = file_stat(c, &ram[addr], len);
245
-		POKE16(d + 0x2, res);
245
+		POKE2(d + 0x2, res);
246 246
 		break;
247 247
 	case 0x6:
248 248
 		res = file_delete(c);
249
-		POKE16(d + 0x2, res);
249
+		POKE2(d + 0x2, res);
250 250
 		break;
251 251
 	case 0x9:
252
-		addr = PEEK16(d + 0x8);
252
+		addr = PEEK2(d + 0x8);
253 253
 		res = file_init(c, (char *)&ram[addr], 0x10000 - addr, 0);
254
-		POKE16(d + 0x2, res);
254
+		POKE2(d + 0x2, res);
255 255
 		break;
256 256
 	case 0xd:
257
-		addr = PEEK16(d + 0xc);
258
-		len = PEEK16(d + 0xa);
257
+		addr = PEEK2(d + 0xc);
258
+		len = PEEK2(d + 0xa);
259 259
 		if(len > 0x10000 - addr)
260 260
 			len = 0x10000 - addr;
261 261
 		res = file_read(c, &ram[addr], len);
262
-		POKE16(d + 0x2, res);
262
+		POKE2(d + 0x2, res);
263 263
 		break;
264 264
 	case 0xf:
265
-		addr = PEEK16(d + 0xe);
266
-		len = PEEK16(d + 0xa);
265
+		addr = PEEK2(d + 0xe);
266
+		len = PEEK2(d + 0xa);
267 267
 		if(len > 0x10000 - addr)
268 268
 			len = 0x10000 - addr;
269 269
 		res = file_write(c, &ram[addr], len, d[0x7]);
270
-		POKE16(d + 0x2, res);
270
+		POKE2(d + 0x2, res);
271 271
 		break;
272 272
 	}
273 273
 }
... ...
@@ -16,30 +16,30 @@ void
16 16
 mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
17 17
 {
18 18
 	d[6] |= mask;
19
-	uxn_eval(u, PEEK16(d));
19
+	uxn_eval(u, PEEK2(d));
20 20
 }
21 21
 
22 22
 void
23 23
 mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
24 24
 {
25 25
 	d[6] &= (~mask);
26
-	uxn_eval(u, PEEK16(d));
26
+	uxn_eval(u, PEEK2(d));
27 27
 }
28 28
 
29 29
 void
30 30
 mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
31 31
 {
32
-	POKE16(d + 0x2, x);
33
-	POKE16(d + 0x4, y);
34
-	uxn_eval(u, PEEK16(d));
32
+	POKE2(d + 0x2, x);
33
+	POKE2(d + 0x4, y);
34
+	uxn_eval(u, PEEK2(d));
35 35
 }
36 36
 
37 37
 void
38 38
 mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
39 39
 {
40
-	POKE16(d + 0xa, x);
41
-	POKE16(d + 0xc, -y);
42
-	uxn_eval(u, PEEK16(d));
43
-	POKE16(d + 0xa, 0);
44
-	POKE16(d + 0xc, 0);
40
+	POKE2(d + 0xa, x);
41
+	POKE2(d + 0xc, -y);
42
+	uxn_eval(u, PEEK2(d));
43
+	POKE2(d + 0xa, 0);
44
+	POKE2(d + 0xc, 0);
45 45
 }
... ...
@@ -156,22 +156,22 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
156 156
 	switch(port) {
157 157
 	case 0x3:
158 158
 		if(!FIXED_SIZE)
159
-			screen_resize(&uxn_screen, clamp(PEEK16(d + 2), 1, 1024), uxn_screen.height);
159
+			screen_resize(&uxn_screen, clamp(PEEK2(d + 2), 1, 1024), uxn_screen.height);
160 160
 		break;
161 161
 	case 0x5:
162 162
 		if(!FIXED_SIZE)
163
-			screen_resize(&uxn_screen, uxn_screen.width, clamp(PEEK16(d + 4), 1, 1024));
163
+			screen_resize(&uxn_screen, uxn_screen.width, clamp(PEEK2(d + 4), 1, 1024));
164 164
 		break;
165 165
 	case 0xe: {
166
-		Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa);
166
+		Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa);
167 167
 		Uint8 layer = d[0xe] & 0x40;
168 168
 		screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d[0xe] & 0x3);
169
-		if(d[0x6] & 0x01) POKE16(d + 0x8, x + 1); /* auto x+1 */
170
-		if(d[0x6] & 0x02) POKE16(d + 0xa, y + 1); /* auto y+1 */
169
+		if(d[0x6] & 0x01) POKE2(d + 0x8, x + 1); /* auto x+1 */
170
+		if(d[0x6] & 0x02) POKE2(d + 0xa, y + 1); /* auto y+1 */
171 171
 		break;
172 172
 	}
173 173
 	case 0xf: {
174
-		Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa), dx, dy, addr = PEEK16(d + 0xc);
174
+		Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa), dx, dy, addr = PEEK2(d + 0xc);
175 175
 		Uint8 i, n, twobpp = !!(d[0xf] & 0x80);
176 176
 		Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
177 177
 		n = d[0x6] >> 4;
... ...
@@ -187,9 +187,9 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
187 187
 				addr += (d[0x6] & 0x04) << (1 + twobpp);
188 188
 			}
189 189
 		}
190
-		POKE16(d + 0xc, addr);   /* auto addr+length */
191
-		POKE16(d + 0x8, x + dx); /* auto x+8 */
192
-		POKE16(d + 0xa, y + dy); /* auto y+8 */
190
+		POKE2(d + 0xc, addr);   /* auto addr+length */
191
+		POKE2(d + 0x8, x + dx); /* auto x+8 */
192
+		POKE2(d + 0xa, y + dy); /* auto y+8 */
193 193
 		break;
194 194
 	}
195 195
 	}
... ...
@@ -36,9 +36,9 @@ static void
36 36
 system_cmd(Uint8 *ram, Uint16 addr)
37 37
 {
38 38
 	if(ram[addr] == 0x01) {
39
-		Uint16 i, length = PEEK16(ram + addr + 1);
40
-		Uint16 a_page = PEEK16(ram + addr + 1 + 2), a_addr = PEEK16(ram + addr + 1 + 4);
41
-		Uint16 b_page = PEEK16(ram + addr + 1 + 6), b_addr = PEEK16(ram + addr + 1 + 8);
39
+		Uint16 i, length = PEEK2(ram + addr + 1);
40
+		Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4);
41
+		Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8);
42 42
 		int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000;
43 43
 		for(i = 0; i < length; i++)
44 44
 			ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)];
... ...
@@ -73,7 +73,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
73 73
 {
74 74
 	switch(port) {
75 75
 	case 0x3:
76
-		system_cmd(u->ram, PEEK16(d + 2));
76
+		system_cmd(u->ram, PEEK2(d + 2));
77 77
 		break;
78 78
 	case 0xe:
79 79
 		if(u->wst->ptr || u->rst->ptr) system_inspect(u);
... ...
@@ -87,7 +87,7 @@ int
87 87
 uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
88 88
 {
89 89
 	Uint8 *d = &u->dev[0x00];
90
-	Uint16 handler = PEEK16(d);
90
+	Uint16 handler = PEEK2(d);
91 91
 	if(handler) {
92 92
 		u->wst->ptr = 4;
93 93
 		u->wst->dat[0] = addr >> 0x8;
... ...
@@ -14,10 +14,10 @@ WITH REGARD TO THIS SOFTWARE.
14 14
 #define T s->dat[s->ptr-1]
15 15
 #define N s->dat[s->ptr-2]
16 16
 #define L s->dat[s->ptr-3]
17
-#define H2 PEEK16(s->dat+s->ptr-3)
18
-#define T2 PEEK16(s->dat+s->ptr-2)
19
-#define N2 PEEK16(s->dat+s->ptr-4)
20
-#define L2 PEEK16(s->dat+s->ptr-6)
17
+#define H2 PEEK2(s->dat+s->ptr-3)
18
+#define T2 PEEK2(s->dat+s->ptr-2)
19
+#define N2 PEEK2(s->dat+s->ptr-4)
20
+#define L2 PEEK2(s->dat+s->ptr-6)
21 21
 
22 22
 /* Registers
23 23
 
... ...
@@ -51,13 +51,13 @@ uxn_eval(Uxn *u, Uint16 pc)
51 51
 		switch(opc) {
52 52
 			/* IMM */
53 53
 			case 0x00: /* BRK   */ return 1;
54
-			case 0xff: /* JCI   */ pc += !!s->dat[--s->ptr] * PEEK16(u->ram + pc) + 2; break;
55
-			case 0xfe: /* JMI   */ pc += PEEK16(u->ram + pc) + 2; break;
56
-			case 0xfd: /* JSI   */ PUSH2(u->rst, pc + 2) pc += PEEK16(u->ram + pc) + 2; break;
54
+			case 0xff: /* JCI   */ pc += !!s->dat[--s->ptr] * PEEK2(u->ram + pc) + 2; break;
55
+			case 0xfe: /* JMI   */ pc += PEEK2(u->ram + pc) + 2; break;
56
+			case 0xfd: /* JSI   */ PUSH2(u->rst, pc + 2) pc += PEEK2(u->ram + pc) + 2; break;
57 57
 			case 0xfc: /* LIT   */ PUSH(s, u->ram[pc++]) break;
58
-			case 0xfb: /* LIT2  */ PUSH2(s, PEEK16(u->ram + pc)) pc += 2; break;
58
+			case 0xfb: /* LIT2  */ PUSH2(s, PEEK2(u->ram + pc)) pc += 2; break;
59 59
 			case 0xfa: /* LITr  */ PUSH(s, u->ram[pc++]) break;
60
-			case 0xf9: /* LIT2r */ PUSH2(s, PEEK16(u->ram + pc)) pc += 2; break;
60
+			case 0xf9: /* LIT2r */ PUSH2(s, PEEK2(u->ram + pc)) pc += 2; break;
61 61
 			/* ALU */
62 62
 			case 0x01: /* INC  */ t=T;         SET(1, 0) PUT(0, t + 1) break;                           case 0x21: t=T2;           SET(2, 0) PUT2(0, t + 1) break;
63 63
 			case 0x02: /* POP  */              SET(1,-1) break;                                         case 0x22:                 SET(2,-2) break;
... ...
@@ -74,12 +74,12 @@ uxn_eval(Uxn *u, Uint16 pc)
74 74
 			case 0x0d: /* JCN  */ t=T;n=N;     SET(2,-2) pc += !!n * (Sint8)t; break;                   case 0x2d: t=T2;n=L;       SET(3,-3) if(n) pc = t; break;
75 75
 			case 0x0e: /* JSR  */ t=T;         SET(1,-1) PUSH2(u->rst, pc) pc += (Sint8)t; break;       case 0x2e: t=T2;           SET(2,-2) PUSH2(u->rst, pc) pc = t; break;
76 76
 			case 0x0f: /* STH  */ t=T;         SET(1,-1) PUSH((ins & 0x40 ? u->wst : u->rst), t) break; case 0x2f: t=T2;           SET(2,-2) PUSH2((ins & 0x40 ? u->wst : u->rst), t) break;
77
-			case 0x10: /* LDZ  */ t=T;         SET(1, 0) PUT(0, u->ram[t]) break;                       case 0x30: t=T;            SET(1, 1) PUT2(0, PEEK16(u->ram + t)) break;
78
-			case 0x11: /* STZ  */ t=T;n=N;     SET(2,-2) u->ram[t] = n; break;                          case 0x31: t=T;n=H2;       SET(3,-3) POKE16(u->ram + t, n) break;
79
-			case 0x12: /* LDR  */ t=T;         SET(1, 0) PUT(0, u->ram[pc + (Sint8)t]) break;           case 0x32: t=T;            SET(1, 1) PUT2(0, PEEK16(u->ram + pc + (Sint8)t)) break;
80
-			case 0x13: /* STR  */ t=T;n=N;     SET(2,-2) u->ram[pc + (Sint8)t] = n; break;              case 0x33: t=T;n=H2;       SET(3,-3) POKE16(u->ram + pc + (Sint8)t, n) break;
81
-			case 0x14: /* LDA  */ t=T2;        SET(2,-1) PUT(0, u->ram[t]) break;                       case 0x34: t=T2;           SET(2, 0) PUT2(0, PEEK16(u->ram + t)) break;
82
-			case 0x15: /* STA  */ t=T2;n=L;    SET(3,-3) u->ram[t] = n; break;                          case 0x35: t=T2;n=N2;      SET(4,-4) POKE16(u->ram + t, n) break;
77
+			case 0x10: /* LDZ  */ t=T;         SET(1, 0) PUT(0, u->ram[t]) break;                       case 0x30: t=T;            SET(1, 1) PUT2(0, PEEK2(u->ram + t)) break;
78
+			case 0x11: /* STZ  */ t=T;n=N;     SET(2,-2) u->ram[t] = n; break;                          case 0x31: t=T;n=H2;       SET(3,-3) POKE2(u->ram + t, n) break;
79
+			case 0x12: /* LDR  */ t=T;         SET(1, 0) PUT(0, u->ram[pc + (Sint8)t]) break;           case 0x32: t=T;            SET(1, 1) PUT2(0, PEEK2(u->ram + pc + (Sint8)t)) break;
80
+			case 0x13: /* STR  */ t=T;n=N;     SET(2,-2) u->ram[pc + (Sint8)t] = n; break;              case 0x33: t=T;n=H2;       SET(3,-3) POKE2(u->ram + pc + (Sint8)t, n) break;
81
+			case 0x14: /* LDA  */ t=T2;        SET(2,-1) PUT(0, u->ram[t]) break;                       case 0x34: t=T2;           SET(2, 0) PUT2(0, PEEK2(u->ram + t)) break;
82
+			case 0x15: /* STA  */ t=T2;n=L;    SET(3,-3) u->ram[t] = n; break;                          case 0x35: t=T2;n=N2;      SET(4,-4) POKE2(u->ram + t, n) break;
83 83
 			case 0x16: /* DEI  */ t=T;         SET(1, 0) DEI(0, t) break;                               case 0x36: t=T;            SET(1, 1) DEI(1, t) DEI(0, t + 1) break;
84 84
 			case 0x17: /* DEO  */ t=T;n=N;     SET(2,-2) DEO(t, n) break;                               case 0x37: t=T;n=N;l=L;    SET(3,-3) DEO(t, l) DEO(t + 1, n) break;
85 85
 			case 0x18: /* ADD  */ t=T;n=N;     SET(2,-1) PUT(0, n + t) break;                           case 0x38: t=T2;n=N2;      SET(4,-2) PUT2(0, n + t) break;
... ...
@@ -13,8 +13,8 @@ WITH REGARD TO THIS SOFTWARE.
13 13
 
14 14
 /* clang-format off */
15 15
 
16
-#define POKE16(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
17
-#define PEEK16(d) ((d)[0] << 8 | (d)[1])
16
+#define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
17
+#define PEEK2(d) ((d)[0] << 8 | (d)[1])
18 18
 
19 19
 /* clang-format on */
20 20
 
... ...
@@ -32,7 +32,7 @@ console_input(Uxn *u, char c)
32 32
 {
33 33
 	Uint8 *d = &u->dev[0x10];
34 34
 	d[0x02] = c;
35
-	return uxn_eval(u, PEEK16(d));
35
+	return uxn_eval(u, PEEK2(d));
36 36
 }
37 37
 
38 38
 static void
... ...
@@ -70,7 +70,7 @@ console_input(Uxn *u, char c)
70 70
 {
71 71
 	Uint8 *d = &u->dev[0x10];
72 72
 	d[0x02] = c;
73
-	return uxn_eval(u, PEEK16(d));
73
+	return uxn_eval(u, PEEK2(d));
74 74
 }
75 75
 
76 76
 static void
... ...
@@ -94,7 +94,7 @@ audio_dei(int instance, Uint8 *d, Uint8 port)
94 94
 	if(!audio_id) return d[port];
95 95
 	switch(port) {
96 96
 	case 0x4: return audio_get_vu(instance);
97
-	case 0x2: POKE16(d + 0x2, audio_get_position(instance)); /* fall through */
97
+	case 0x2: POKE2(d + 0x2, audio_get_position(instance)); /* fall through */
98 98
 	default: return d[port];
99 99
 	}
100 100
 }
... ...
@@ -392,7 +392,7 @@ handle_events(Uxn *u)
392 392
 		}
393 393
 		/* Audio */
394 394
 		else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) {
395
-			uxn_eval(u, PEEK16(&u->dev[0x30 + 0x10 * (event.type - audio0_event)]));
395
+			uxn_eval(u, PEEK2(&u->dev[0x30 + 0x10 * (event.type - audio0_event)]));
396 396
 		}
397 397
 		/* Mouse */
398 398
 		else if(event.type == SDL_MOUSEMOTION)
... ...
@@ -442,7 +442,7 @@ run(Uxn *u)
442 442
 {
443 443
 	Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60;
444 444
 	for(;;) {
445
-		Uint16 screen_vector = PEEK16(&u->dev[0x20]);
445
+		Uint16 screen_vector = PEEK2(&u->dev[0x20]);
446 446
 		/* .System/halt */
447 447
 		if(u->dev[0x0f])
448 448
 			return error("Run", "Ended.");