commit 4e77d3d5aec99f3a7c9bd29cfe250974f182c65c
parent 43ce262a07db197a8a745aed87d663e73047a553
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 12 Mar 2023 15:25:52 -0700
Renamed PEEK16/POKE16 to PEEK2/POKE2
Diffstat:
10 files changed, 63 insertions(+), 63 deletions(-)
diff --git a/src/devices/audio.c b/src/devices/audio.c
@@ -76,8 +76,8 @@ audio_start(int instance, Uint8 *d, Uxn *u)
{
UxnAudio *c = &uxn_audio[instance];
Uint8 pitch = d[0xf] & 0x7f;
- Uint16 addr = PEEK16(d + 0xc), adsr = PEEK16(d + 0x8);
- c->len = PEEK16(d + 0xa);
+ Uint16 addr = PEEK2(d + 0xc), adsr = PEEK2(d + 0x8);
+ c->len = PEEK2(d + 0xa);
if(c->len > 0x10000 - addr)
c->len = 0x10000 - addr;
c->addr = &u->ram[addr];
diff --git a/src/devices/controller.c b/src/devices/controller.c
@@ -17,7 +17,7 @@ controller_down(Uxn *u, Uint8 *d, Uint8 mask)
{
if(mask) {
d[2] |= mask;
- uxn_eval(u, PEEK16(d));
+ uxn_eval(u, PEEK2(d));
}
}
@@ -26,7 +26,7 @@ controller_up(Uxn *u, Uint8 *d, Uint8 mask)
{
if(mask) {
d[2] &= (~mask);
- uxn_eval(u, PEEK16(d));
+ uxn_eval(u, PEEK2(d));
}
}
@@ -35,7 +35,7 @@ controller_key(Uxn *u, Uint8 *d, Uint8 key)
{
if(key) {
d[3] = key;
- uxn_eval(u, PEEK16(d));
+ uxn_eval(u, PEEK2(d));
d[3] = 0x00;
}
}
diff --git a/src/devices/file.c b/src/devices/file.c
@@ -237,37 +237,37 @@ file_deo(Uint8 id, Uint8 *ram, Uint8 *d, Uint8 port)
Uint16 addr, len, res;
switch(port) {
case 0x5:
- addr = PEEK16(d + 0x4);
- len = PEEK16(d + 0xa);
+ addr = PEEK2(d + 0x4);
+ len = PEEK2(d + 0xa);
if(len > 0x10000 - addr)
len = 0x10000 - addr;
res = file_stat(c, &ram[addr], len);
- POKE16(d + 0x2, res);
+ POKE2(d + 0x2, res);
break;
case 0x6:
res = file_delete(c);
- POKE16(d + 0x2, res);
+ POKE2(d + 0x2, res);
break;
case 0x9:
- addr = PEEK16(d + 0x8);
+ addr = PEEK2(d + 0x8);
res = file_init(c, (char *)&ram[addr], 0x10000 - addr, 0);
- POKE16(d + 0x2, res);
+ POKE2(d + 0x2, res);
break;
case 0xd:
- addr = PEEK16(d + 0xc);
- len = PEEK16(d + 0xa);
+ addr = PEEK2(d + 0xc);
+ len = PEEK2(d + 0xa);
if(len > 0x10000 - addr)
len = 0x10000 - addr;
res = file_read(c, &ram[addr], len);
- POKE16(d + 0x2, res);
+ POKE2(d + 0x2, res);
break;
case 0xf:
- addr = PEEK16(d + 0xe);
- len = PEEK16(d + 0xa);
+ addr = PEEK2(d + 0xe);
+ len = PEEK2(d + 0xa);
if(len > 0x10000 - addr)
len = 0x10000 - addr;
res = file_write(c, &ram[addr], len, d[0x7]);
- POKE16(d + 0x2, res);
+ POKE2(d + 0x2, res);
break;
}
}
diff --git a/src/devices/mouse.c b/src/devices/mouse.c
@@ -16,30 +16,30 @@ void
mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
{
d[6] |= mask;
- uxn_eval(u, PEEK16(d));
+ uxn_eval(u, PEEK2(d));
}
void
mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
{
d[6] &= (~mask);
- uxn_eval(u, PEEK16(d));
+ uxn_eval(u, PEEK2(d));
}
void
mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
- POKE16(d + 0x2, x);
- POKE16(d + 0x4, y);
- uxn_eval(u, PEEK16(d));
+ POKE2(d + 0x2, x);
+ POKE2(d + 0x4, y);
+ uxn_eval(u, PEEK2(d));
}
void
mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
- POKE16(d + 0xa, x);
- POKE16(d + 0xc, -y);
- uxn_eval(u, PEEK16(d));
- POKE16(d + 0xa, 0);
- POKE16(d + 0xc, 0);
+ POKE2(d + 0xa, x);
+ POKE2(d + 0xc, -y);
+ uxn_eval(u, PEEK2(d));
+ POKE2(d + 0xa, 0);
+ POKE2(d + 0xc, 0);
}
diff --git a/src/devices/screen.c b/src/devices/screen.c
@@ -156,22 +156,22 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
switch(port) {
case 0x3:
if(!FIXED_SIZE)
- screen_resize(&uxn_screen, clamp(PEEK16(d + 2), 1, 1024), uxn_screen.height);
+ screen_resize(&uxn_screen, clamp(PEEK2(d + 2), 1, 1024), uxn_screen.height);
break;
case 0x5:
if(!FIXED_SIZE)
- screen_resize(&uxn_screen, uxn_screen.width, clamp(PEEK16(d + 4), 1, 1024));
+ screen_resize(&uxn_screen, uxn_screen.width, clamp(PEEK2(d + 4), 1, 1024));
break;
case 0xe: {
- Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa);
+ Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa);
Uint8 layer = d[0xe] & 0x40;
screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d[0xe] & 0x3);
- if(d[0x6] & 0x01) POKE16(d + 0x8, x + 1); /* auto x+1 */
- if(d[0x6] & 0x02) POKE16(d + 0xa, y + 1); /* auto y+1 */
+ if(d[0x6] & 0x01) POKE2(d + 0x8, x + 1); /* auto x+1 */
+ if(d[0x6] & 0x02) POKE2(d + 0xa, y + 1); /* auto y+1 */
break;
}
case 0xf: {
- Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa), dx, dy, addr = PEEK16(d + 0xc);
+ Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa), dx, dy, addr = PEEK2(d + 0xc);
Uint8 i, n, twobpp = !!(d[0xf] & 0x80);
Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
n = d[0x6] >> 4;
@@ -187,9 +187,9 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
addr += (d[0x6] & 0x04) << (1 + twobpp);
}
}
- POKE16(d + 0xc, addr); /* auto addr+length */
- POKE16(d + 0x8, x + dx); /* auto x+8 */
- POKE16(d + 0xa, y + dy); /* auto y+8 */
+ POKE2(d + 0xc, addr); /* auto addr+length */
+ POKE2(d + 0x8, x + dx); /* auto x+8 */
+ POKE2(d + 0xa, y + dy); /* auto y+8 */
break;
}
}
diff --git a/src/devices/system.c b/src/devices/system.c
@@ -36,9 +36,9 @@ static void
system_cmd(Uint8 *ram, Uint16 addr)
{
if(ram[addr] == 0x01) {
- Uint16 i, length = PEEK16(ram + addr + 1);
- Uint16 a_page = PEEK16(ram + addr + 1 + 2), a_addr = PEEK16(ram + addr + 1 + 4);
- Uint16 b_page = PEEK16(ram + addr + 1 + 6), b_addr = PEEK16(ram + addr + 1 + 8);
+ Uint16 i, length = PEEK2(ram + addr + 1);
+ Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4);
+ Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8);
int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000;
for(i = 0; i < length; i++)
ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)];
@@ -73,7 +73,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
{
switch(port) {
case 0x3:
- system_cmd(u->ram, PEEK16(d + 2));
+ system_cmd(u->ram, PEEK2(d + 2));
break;
case 0xe:
if(u->wst->ptr || u->rst->ptr) system_inspect(u);
@@ -87,7 +87,7 @@ int
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
{
Uint8 *d = &u->dev[0x00];
- Uint16 handler = PEEK16(d);
+ Uint16 handler = PEEK2(d);
if(handler) {
u->wst->ptr = 4;
u->wst->dat[0] = addr >> 0x8;
diff --git a/src/uxn.c b/src/uxn.c
@@ -14,10 +14,10 @@ WITH REGARD TO THIS SOFTWARE.
#define T s->dat[s->ptr-1]
#define N s->dat[s->ptr-2]
#define L s->dat[s->ptr-3]
-#define H2 PEEK16(s->dat+s->ptr-3)
-#define T2 PEEK16(s->dat+s->ptr-2)
-#define N2 PEEK16(s->dat+s->ptr-4)
-#define L2 PEEK16(s->dat+s->ptr-6)
+#define H2 PEEK2(s->dat+s->ptr-3)
+#define T2 PEEK2(s->dat+s->ptr-2)
+#define N2 PEEK2(s->dat+s->ptr-4)
+#define L2 PEEK2(s->dat+s->ptr-6)
/* Registers
@@ -51,13 +51,13 @@ uxn_eval(Uxn *u, Uint16 pc)
switch(opc) {
/* IMM */
case 0x00: /* BRK */ return 1;
- case 0xff: /* JCI */ pc += !!s->dat[--s->ptr] * PEEK16(u->ram + pc) + 2; break;
- case 0xfe: /* JMI */ pc += PEEK16(u->ram + pc) + 2; break;
- case 0xfd: /* JSI */ PUSH2(u->rst, pc + 2) pc += PEEK16(u->ram + pc) + 2; break;
+ case 0xff: /* JCI */ pc += !!s->dat[--s->ptr] * PEEK2(u->ram + pc) + 2; break;
+ case 0xfe: /* JMI */ pc += PEEK2(u->ram + pc) + 2; break;
+ case 0xfd: /* JSI */ PUSH2(u->rst, pc + 2) pc += PEEK2(u->ram + pc) + 2; break;
case 0xfc: /* LIT */ PUSH(s, u->ram[pc++]) break;
- case 0xfb: /* LIT2 */ PUSH2(s, PEEK16(u->ram + pc)) pc += 2; break;
+ case 0xfb: /* LIT2 */ PUSH2(s, PEEK2(u->ram + pc)) pc += 2; break;
case 0xfa: /* LITr */ PUSH(s, u->ram[pc++]) break;
- case 0xf9: /* LIT2r */ PUSH2(s, PEEK16(u->ram + pc)) pc += 2; break;
+ case 0xf9: /* LIT2r */ PUSH2(s, PEEK2(u->ram + pc)) pc += 2; break;
/* ALU */
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;
case 0x02: /* POP */ SET(1,-1) break; case 0x22: SET(2,-2) break;
@@ -74,12 +74,12 @@ uxn_eval(Uxn *u, Uint16 pc)
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;
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;
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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
+ 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;
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;
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;
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;
diff --git a/src/uxn.h b/src/uxn.h
@@ -13,8 +13,8 @@ WITH REGARD TO THIS SOFTWARE.
/* clang-format off */
-#define POKE16(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
-#define PEEK16(d) ((d)[0] << 8 | (d)[1])
+#define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
+#define PEEK2(d) ((d)[0] << 8 | (d)[1])
/* clang-format on */
diff --git a/src/uxncli.c b/src/uxncli.c
@@ -32,7 +32,7 @@ console_input(Uxn *u, char c)
{
Uint8 *d = &u->dev[0x10];
d[0x02] = c;
- return uxn_eval(u, PEEK16(d));
+ return uxn_eval(u, PEEK2(d));
}
static void
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -70,7 +70,7 @@ console_input(Uxn *u, char c)
{
Uint8 *d = &u->dev[0x10];
d[0x02] = c;
- return uxn_eval(u, PEEK16(d));
+ return uxn_eval(u, PEEK2(d));
}
static void
@@ -94,7 +94,7 @@ audio_dei(int instance, Uint8 *d, Uint8 port)
if(!audio_id) return d[port];
switch(port) {
case 0x4: return audio_get_vu(instance);
- case 0x2: POKE16(d + 0x2, audio_get_position(instance)); /* fall through */
+ case 0x2: POKE2(d + 0x2, audio_get_position(instance)); /* fall through */
default: return d[port];
}
}
@@ -392,7 +392,7 @@ handle_events(Uxn *u)
}
/* Audio */
else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) {
- uxn_eval(u, PEEK16(&u->dev[0x30 + 0x10 * (event.type - audio0_event)]));
+ uxn_eval(u, PEEK2(&u->dev[0x30 + 0x10 * (event.type - audio0_event)]));
}
/* Mouse */
else if(event.type == SDL_MOUSEMOTION)
@@ -442,7 +442,7 @@ run(Uxn *u)
{
Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60;
for(;;) {
- Uint16 screen_vector = PEEK16(&u->dev[0x20]);
+ Uint16 screen_vector = PEEK2(&u->dev[0x20]);
/* .System/halt */
if(u->dev[0x0f])
return error("Run", "Ended.");