uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 87de244d3740908fea7ae151bcec3f71705a4e7a
parent 18de47cc1c603622a2867a7431b7b55d9102f072
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Wed,  1 Mar 2023 10:35:42 -0800

Replaced some macros

Diffstat:
Msrc/devices/screen.c | 27+++++++++------------------
Msrc/devices/system.c | 4+---
Msrc/uxn.c | 19+++++++------------
Msrc/uxn.h | 18+++++++++++-------
Msrc/uxnemu.c | 2+-
5 files changed, 29 insertions(+), 41 deletions(-)

diff --git a/src/devices/screen.c b/src/devices/screen.c @@ -156,35 +156,26 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) switch(port) { case 0x3: if(!FIXED_SIZE) { - Uint16 w; - PEKDEV(w, 0x2); - screen_resize(&uxn_screen, clamp(w, 1, 1024), uxn_screen.height); + screen_resize(&uxn_screen, clamp(PEEK16(d + 2), 1, 1024), uxn_screen.height); } break; case 0x5: if(!FIXED_SIZE) { - Uint16 h; - PEKDEV(h, 0x4); - screen_resize(&uxn_screen, uxn_screen.width, clamp(h, 1, 1024)); + screen_resize(&uxn_screen, uxn_screen.width, clamp(PEEK16(d + 4), 1, 1024)); } break; case 0xe: { - Uint16 x, y; + Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa); Uint8 layer = d[0xe] & 0x40; - PEKDEV(x, 0x8); - PEKDEV(y, 0xa); screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d[0xe] & 0x3); - if(d[0x6] & 0x01) POKDEV(0x8, x + 1); /* auto x+1 */ - if(d[0x6] & 0x02) POKDEV(0xa, y + 1); /* auto y+1 */ + if(d[0x6] & 0x01) POKE16(d + 0x8, x + 1); /* auto x+1 */ + if(d[0x6] & 0x02) POKE16(d + 0xa, y + 1); /* auto y+1 */ break; } case 0xf: { - Uint16 x, y, dx, dy, addr; + Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa), dx, dy, addr = PEEK16(d + 0xc); Uint8 i, n, twobpp = !!(d[0xf] & 0x80); Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; - PEKDEV(x, 0x8); - PEKDEV(y, 0xa); - PEKDEV(addr, 0xc); n = d[0x6] >> 4; dx = (d[0x6] & 0x01) << 3; dy = (d[0x6] & 0x02) << 2; @@ -198,9 +189,9 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) addr += (d[0x6] & 0x04) << (1 + twobpp); } } - POKDEV(0xc, addr); /* auto addr+length */ - POKDEV(0x8, x + dx); /* auto x+8 */ - POKDEV(0xa, y + dy); /* auto y+8 */ + POKE16(d + 0xc, addr); /* auto addr+length */ + POKE16(d + 0x8, x + dx); /* auto x+8 */ + POKE16(d + 0xa, y + dy); /* auto y+8 */ break; } } diff --git a/src/devices/system.c b/src/devices/system.c @@ -71,11 +71,9 @@ system_load(Uxn *u, char *filename) void system_deo(Uxn *u, Uint8 *d, Uint8 port) { - Uint16 a; switch(port) { case 0x3: - PEKDEV(a, 0x2); - system_cmd(u->ram, a); + system_cmd(u->ram, PEEK16(d + 2)); break; case 0xe: if(u->wst->ptr || u->rst->ptr) system_inspect(u); diff --git a/src/uxn.c b/src/uxn.c @@ -17,19 +17,14 @@ WITH REGARD TO THIS SOFTWARE. #define HALT(c) { return uxn_halt(u, instr, (c), pc - 1); } #define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); } - #define PUSH8(x) { if(s->ptr == 0xff) HALT(2) s->dat[s->ptr++] = (x); } -#define PUSH16(x) { if((tsp = s->ptr) >= 0xfe) HALT(2) t = (x); s->dat[tsp] = t >> 8; s->dat[tsp + 1] = t; s->ptr = tsp + 2; } +#define PUSH16(x) { if((tsp = s->ptr) >= 0xfe) HALT(2) t = (x); POKE16(&s->dat[tsp], t); s->ptr = tsp + 2; } #define PUSH(x) { if(m2) { PUSH16(x) } else { PUSH8(x) } } - #define POP8(o) { if(*sp == 0x00) HALT(1) o = s->dat[--*sp]; } -#define POP16(o) { if((tsp = *sp) <= 0x01) HALT(1) o = s->dat[tsp - 1] | (s->dat[tsp - 2] << 8); *sp = tsp - 2; } +#define POP16(o) { if((tsp = *sp) <= 0x01) HALT(1) o = PEEK16(&s->dat[tsp - 2]); *sp = tsp - 2; } #define POP(o) { if(m2) { POP16(o) } else { POP8(o) } } - -#define POKE(x, y) { if(m2) { t = (y); u->ram[(x)] = t >> 8; u->ram[(x) + 1] = t; } else { u->ram[(x)] = (y); } } -#define PEEK16(o, x) { o = (u->ram[(x)] << 8) | u->ram[(x) + 1]; } -#define PEEK(o, x) { if(m2) PEEK16(o, x) else o = u->ram[(x)]; } - +#define POKE(x, y) { if(m2) { t = (y); POKE16(u->ram + x, t) } else { u->ram[(x)] = (y); } } +#define PEEK(o, x) { if(m2) { o = PEEK16(u->ram + x); } else o = u->ram[(x)]; } #define DEVR(o, x) { o = u->dei(u, x); if(m2) o = (o << 8) | u->dei(u, (x) + 1); } #define DEVW(x, y) { if(m2) { u->deo(u, (x), (y) >> 8); u->deo(u, (x) + 1, (y)); } else { u->deo(u, x, (y)); } } @@ -55,12 +50,12 @@ uxn_eval(Uxn *u, Uint16 pc) /* Immediate */ case -0x0: /* BRK */ return 1; case -0x1: /* JCI */ POP8(b) if(!b) { pc += 2; break; } - case -0x2: /* JMI */ PEEK16(a, pc) pc += a + 2; break; - case -0x3: /* JSI */ s = u->rst; PUSH16(pc + 2) PEEK16(a, pc) pc += a + 2; break; + case -0x2: /* JMI */ pc += PEEK16(u->ram + pc) + 2; break; + case -0x3: /* JSI */ s = u->rst; PUSH16(pc + 2) pc += PEEK16(u->ram + pc) + 2; break; case -0x4: /* LIT */ case -0x6: /* LITr */ a = u->ram[pc++]; PUSH8(a) break; case -0x5: /* LIT2 */ - case -0x7: /* LIT2r */ PEEK16(a, pc) PUSH16(a) pc += 2; break; + case -0x7: /* LIT2r */ PUSH16(PEEK16(u->ram + pc)) pc += 2; break; /* ALU */ case 0x01: /* INC */ POP(a) PUSH(a + 1) break; case 0x02: /* POP */ POP(a) break; diff --git a/src/uxn.h b/src/uxn.h @@ -9,22 +9,25 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -typedef unsigned char Uint8; -typedef signed char Sint8; -typedef unsigned short Uint16; -typedef signed short Sint16; -typedef unsigned int Uint32; - #define PAGE_PROGRAM 0x0100 /* clang-format off */ +#define POKE16(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); } +#define PEEK16(d) ((d)[0] << 8 | (d)[1]) + #define GETVEC(d) ((d)[0] << 8 | (d)[1]) #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); } #define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; } /* clang-format on */ +typedef unsigned char Uint8; +typedef signed char Sint8; +typedef unsigned short Uint16; +typedef signed short Sint16; +typedef unsigned int Uint32; + typedef struct { Uint8 dat[255], ptr; } Stack; @@ -41,4 +44,4 @@ typedef void Deo(Uxn *u, Uint8 addr, Uint8 value); int uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr); int uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo); -int uxn_eval(Uxn *u, Uint16 pc); +int uxn_eval(Uxn *u, Uint16 pc); +\ No newline at end of file diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -87,7 +87,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: POKDEV(0x2, audio_get_position(instance)); /* fall through */ + case 0x2: POKE16(d + 0x2, audio_get_position(instance)); /* fall through */ default: return d[port]; } }