uxn

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

commit 90540742ae9114e87db1089b343fb9c2c3b0638c
parent a444641a6a718a96d334af5aa4568f042d180518
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 29 Aug 2021 14:41:05 -0700

Standardizing fns names before merge

Diffstat:
Metc/mkuxn-fast.lua | 4++--
Metc/mkuxn-fast.moon | 4++--
Msrc/uxn-fast.c | 186++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/uxn.c | 52++++++++++++++++++++++++++--------------------------
Msrc/uxn.h | 4++--
Msrc/uxncli.c | 16++++++++--------
Msrc/uxnemu.c | 52++++++++++++++++++++++++++--------------------------
7 files changed, 159 insertions(+), 159 deletions(-)

diff --git a/etc/mkuxn-fast.lua b/etc/mkuxn-fast.lua @@ -3,7 +3,7 @@ local replacements = { op_and16 = '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d & b); push8(u->src, c & a); }', op_ora16 = '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d | b); push8(u->src, c | a); }', op_eor16 = '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d ^ b); push8(u->src, c ^ a); }', - op_lit16 = '{ push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); }', + op_lit16 = '{ push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }', op_swp16 = '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, d); push8(u->src, c); }', op_ovr16 = '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d); push8(u->src, c); push8(u->src, b); push8(u->src, a); push8(u->src, d); push8(u->src, c); }', op_dup16 = '{ Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, b); push8(u->src, a); }', @@ -295,7 +295,7 @@ See etc/mkuxn-fast.moon for instructions. local _continue_0 = false repeat local l = f:read('*l') - if l:match(' push') or l:match('[ *]pop') or l:match('devpeek16') then + if l:match(' push') or l:match('[ *]pop') or l:match('devr16') then _continue_0 = true break end diff --git a/etc/mkuxn-fast.moon b/etc/mkuxn-fast.moon @@ -23,7 +23,7 @@ replacements = op_and16: '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d & b); push8(u->src, c & a); }' op_ora16: '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d | b); push8(u->src, c | a); }' op_eor16: '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d ^ b); push8(u->src, c ^ a); }' - op_lit16: '{ push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); }' + op_lit16: '{ push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); }' op_swp16: '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, d); push8(u->src, c); }' op_ovr16: '{ Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src), d = pop8(u->src); push8(u->src, d); push8(u->src, c); push8(u->src, b); push8(u->src, a); push8(u->src, d); push8(u->src, c); }' op_dup16: '{ Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, b); push8(u->src, a); }' @@ -214,7 +214,7 @@ See etc/mkuxn-fast.moon for instructions. wanted = true while true l = f\read '*l' - if l\match' push' or l\match'[ *]pop' or l\match'devpeek16' + if l\match' push' or l\match'[ *]pop' or l\match'devr16' continue if l == '/* Stack */' wanted = false diff --git a/src/uxn-fast.c b/src/uxn-fast.c @@ -29,13 +29,13 @@ See etc/mkuxn-fast.moon for instructions. #pragma mark - Operations /* clang-format off */ -static void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } -static Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; } -static void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } -static Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } -void mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } -Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } -static void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } +static void poke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } +static Uint8 peek8(Uint8 *m, Uint16 a) { return m[a]; } +static void devw8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } +static Uint8 devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } +void poke16(Uint8 *m, Uint16 a, Uint16 b) { poke8(m, a, b >> 8); poke8(m, a + 1, b); } +Uint16 peek16(Uint8 *m, Uint16 a) { return (peek8(m, a) << 8) + peek8(m, a + 1); } +static void devw16(Device *d, Uint8 a, Uint16 b) { devw8(d, a, b >> 8); devw8(d, a + 1, b); } /* clang-format on */ @@ -57,7 +57,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x00: /* LIT */ case 0x80: /* LITk */ { - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, u->ram.ptr++); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr > 254, 0)) { u->wst.error = 2; @@ -289,7 +289,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x10: /* LDZ */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr - 1] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -302,7 +302,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint8 b = u->wst.dat[u->wst.ptr - 2]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -315,7 +315,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x12: /* LDR */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->wst.dat[u->wst.ptr - 1] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -328,7 +328,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint8 b = u->wst.dat[u->wst.ptr - 2]; - mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -341,7 +341,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x14: /* LDA */ { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); - u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr - 2] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -355,7 +355,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); Uint8 b = u->wst.dat[u->wst.ptr - 3]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -368,7 +368,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x16: /* DEI */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); + u->wst.dat[u->wst.ptr - 1] = devr8(&u->dev[a >> 4], a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -380,7 +380,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x17: /* DEO */ { Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; - devpoke8(&u->dev[a >> 4], a, b); + devw8(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -504,7 +504,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x20: /* LITr */ case 0xa0: /* LITkr */ { - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, u->ram.ptr++); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr > 254, 0)) { u->rst.error = 2; @@ -736,7 +736,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x30: /* LDZr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr - 1] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -749,7 +749,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint8 b = u->rst.dat[u->rst.ptr - 2]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -762,7 +762,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x32: /* LDRr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->rst.dat[u->rst.ptr - 1] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -775,7 +775,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint8 b = u->rst.dat[u->rst.ptr - 2]; - mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -788,7 +788,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x34: /* LDAr */ { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); - u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr - 2] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -802,7 +802,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); Uint8 b = u->rst.dat[u->rst.ptr - 3]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -815,7 +815,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x36: /* DEIr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); + u->rst.dat[u->rst.ptr - 1] = devr8(&u->dev[a >> 4], a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -827,7 +827,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x37: /* DEOr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; - devpoke8(&u->dev[a >> 4], a, b); + devw8(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -951,8 +951,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x40: /* LIT2 */ case 0xc0: /* LIT2k */ { - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); - u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, u->ram.ptr++); + u->wst.dat[u->wst.ptr + 1] = peek8(u->ram.dat, u->ram.ptr++); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr > 253, 0)) { u->wst.error = 2; @@ -1192,8 +1192,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x50: /* LDZ2 */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a); - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a + 1); + u->wst.dat[u->wst.ptr - 1] = peek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -1211,7 +1211,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -1224,8 +1224,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x52: /* LDR2 */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); + u->wst.dat[u->wst.ptr - 1] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -1243,7 +1243,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); - mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -1256,8 +1256,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x54: /* LDA2 */ { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); - u->wst.dat[u->wst.ptr - 2] = mempeek8(u->ram.dat, a); - u->wst.dat[u->wst.ptr - 1] = mempeek8(u->ram.dat, a + 1); + u->wst.dat[u->wst.ptr - 2] = peek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr - 1] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -1270,7 +1270,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); Uint16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 4, 0)) { u->wst.error = 1; @@ -1283,8 +1283,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x56: /* DEI2 */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); - u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a + 1); + u->wst.dat[u->wst.ptr - 1] = devr8(&u->dev[a >> 4], a); + u->wst.dat[u->wst.ptr] = devr8(&u->dev[a >> 4], a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -1302,7 +1302,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); - devpoke16(&u->dev[a >> 4], a, b); + devw16(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -1435,8 +1435,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x60: /* LIT2r */ case 0xe0: /* LIT2kr */ { - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr++); - u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr++); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, u->ram.ptr++); + u->rst.dat[u->rst.ptr + 1] = peek8(u->ram.dat, u->ram.ptr++); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr > 253, 0)) { u->rst.error = 2; @@ -1676,8 +1676,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x70: /* LDZ2r */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a); - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a + 1); + u->rst.dat[u->rst.ptr - 1] = peek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -1695,7 +1695,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -1708,8 +1708,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x72: /* LDR2r */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); + u->rst.dat[u->rst.ptr - 1] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -1727,7 +1727,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); - mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -1740,8 +1740,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x74: /* LDA2r */ { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); - u->rst.dat[u->rst.ptr - 2] = mempeek8(u->ram.dat, a); - u->rst.dat[u->rst.ptr - 1] = mempeek8(u->ram.dat, a + 1); + u->rst.dat[u->rst.ptr - 2] = peek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr - 1] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -1754,7 +1754,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); Uint16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 4, 0)) { u->rst.error = 1; @@ -1767,8 +1767,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x76: /* DEI2r */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr - 1] = devpeek8(&u->dev[a >> 4], a); - u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a + 1); + u->rst.dat[u->rst.ptr - 1] = devr8(&u->dev[a >> 4], a); + u->rst.dat[u->rst.ptr] = devr8(&u->dev[a >> 4], a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -1786,7 +1786,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); - devpoke16(&u->dev[a >> 4], a, b); + devw16(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -2167,7 +2167,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x90: /* LDZk */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -2185,7 +2185,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint8 b = u->wst.dat[u->wst.ptr - 2]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -2197,7 +2197,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x92: /* LDRk */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -2215,7 +2215,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint8 b = u->wst.dat[u->wst.ptr - 2]; - mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -2227,7 +2227,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x94: /* LDAk */ { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -2245,7 +2245,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); Uint8 b = u->wst.dat[u->wst.ptr - 3]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -2257,7 +2257,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x96: /* DEIk */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); + u->wst.dat[u->wst.ptr] = devr8(&u->dev[a >> 4], a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -2274,7 +2274,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0x97: /* DEOk */ { Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; - devpoke8(&u->dev[a >> 4], a, b); + devw8(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -2677,7 +2677,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xb0: /* LDZkr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -2695,7 +2695,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint8 b = u->rst.dat[u->rst.ptr - 2]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -2707,7 +2707,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xb2: /* LDRkr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -2725,7 +2725,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint8 b = u->rst.dat[u->rst.ptr - 2]; - mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -2737,7 +2737,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xb4: /* LDAkr */ { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -2755,7 +2755,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); Uint8 b = u->rst.dat[u->rst.ptr - 3]; - mempoke8(u->ram.dat, a, b); + poke8(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -2767,7 +2767,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xb6: /* DEIkr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); + u->rst.dat[u->rst.ptr] = devr8(&u->dev[a >> 4], a); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -2784,7 +2784,7 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xb7: /* DEOkr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; - devpoke8(&u->dev[a >> 4], a, b); + devw8(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -3198,8 +3198,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xd0: /* LDZ2k */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); - u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, a + 1); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr + 1] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -3217,7 +3217,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -3229,8 +3229,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xd2: /* LDR2k */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); - u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->wst.dat[u->wst.ptr + 1] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -3248,7 +3248,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); - mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -3260,8 +3260,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xd4: /* LDA2k */ { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); - u->wst.dat[u->wst.ptr] = mempeek8(u->ram.dat, a); - u->wst.dat[u->wst.ptr + 1] = mempeek8(u->ram.dat, a + 1); + u->wst.dat[u->wst.ptr] = peek8(u->ram.dat, a); + u->wst.dat[u->wst.ptr + 1] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; @@ -3279,7 +3279,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); Uint16 b = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 4, 0)) { u->wst.error = 1; @@ -3291,8 +3291,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xd6: /* DEI2k */ { Uint8 a = u->wst.dat[u->wst.ptr - 1]; - u->wst.dat[u->wst.ptr] = devpeek8(&u->dev[a >> 4], a); - u->wst.dat[u->wst.ptr + 1] = devpeek8(&u->dev[a >> 4], a + 1); + u->wst.dat[u->wst.ptr] = devr8(&u->dev[a >> 4], a); + u->wst.dat[u->wst.ptr + 1] = devr8(&u->dev[a >> 4], a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 1, 0)) { u->wst.error = 1; @@ -3310,7 +3310,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->wst.dat[u->wst.ptr - 1]; Uint16 b = (u->wst.dat[u->wst.ptr - 2] | (u->wst.dat[u->wst.ptr - 3] << 8)); - devpoke16(&u->dev[a >> 4], a, b); + devw16(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 3, 0)) { u->wst.error = 1; @@ -3733,8 +3733,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xf0: /* LDZ2kr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); - u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, a + 1); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr + 1] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -3752,7 +3752,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -3764,8 +3764,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xf2: /* LDR2kr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a); - u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a); + u->rst.dat[u->rst.ptr + 1] = peek8(u->ram.dat, u->ram.ptr + (Sint8)a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -3783,7 +3783,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); - mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); + poke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; @@ -3795,8 +3795,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xf4: /* LDA2kr */ { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); - u->rst.dat[u->rst.ptr] = mempeek8(u->ram.dat, a); - u->rst.dat[u->rst.ptr + 1] = mempeek8(u->ram.dat, a + 1); + u->rst.dat[u->rst.ptr] = peek8(u->ram.dat, a); + u->rst.dat[u->rst.ptr + 1] = peek8(u->ram.dat, a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; @@ -3814,7 +3814,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); Uint16 b = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); - mempoke16(u->ram.dat, a, b); + poke16(u->ram.dat, a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 4, 0)) { u->rst.error = 1; @@ -3826,8 +3826,8 @@ uxn_eval(Uxn *u, Uint16 vec) case 0xf6: /* DEI2kr */ { Uint8 a = u->rst.dat[u->rst.ptr - 1]; - u->rst.dat[u->rst.ptr] = devpeek8(&u->dev[a >> 4], a); - u->rst.dat[u->rst.ptr + 1] = devpeek8(&u->dev[a >> 4], a + 1); + u->rst.dat[u->rst.ptr] = devr8(&u->dev[a >> 4], a); + u->rst.dat[u->rst.ptr + 1] = devr8(&u->dev[a >> 4], a + 1); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 1, 0)) { u->rst.error = 1; @@ -3845,7 +3845,7 @@ uxn_eval(Uxn *u, Uint16 vec) { Uint8 a = u->rst.dat[u->rst.ptr - 1]; Uint16 b = (u->rst.dat[u->rst.ptr - 2] | (u->rst.dat[u->rst.ptr - 3] << 8)); - devpoke16(&u->dev[a >> 4], a, b); + devw16(&u->dev[a >> 4], a, b); #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 3, 0)) { u->rst.error = 1; diff --git a/src/uxn.c b/src/uxn.c @@ -23,18 +23,18 @@ static void push8(Stack *s, Uint8 a) { if(s->ptr == 0xff) { s->error = 2; retu static Uint8 pop8_keep(Stack *s) { if(s->kptr == 0) { s->error = 1; return 0; } return s->dat[--s->kptr]; } static Uint8 pop8_nokeep(Stack *s) { if(s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; } static Uint8 (*pop8)(Stack *s); -static void mempoke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } -static Uint8 mempeek8(Uint8 *m, Uint16 a) { return m[a]; } -static void devpoke8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } -static Uint8 devpeek8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } +static void poke8(Uint8 *m, Uint16 a, Uint8 b) { m[a] = b; } +static Uint8 peek8(Uint8 *m, Uint16 a) { return m[a]; } +static void devw8(Device *d, Uint8 a, Uint8 b) { d->dat[a & 0xf] = b; d->talk(d, a & 0x0f, 1); } +static Uint8 devr8(Device *d, Uint8 a) { d->talk(d, a & 0x0f, 0); return d->dat[a & 0xf]; } static void push16(Stack *s, Uint16 a) { push8(s, a >> 8); push8(s, a); } static Uint16 pop16(Stack *s) { Uint8 a = pop8(s), b = pop8(s); return a + (b << 8); } -void mempoke16(Uint8 *m, Uint16 a, Uint16 b) { mempoke8(m, a, b >> 8); mempoke8(m, a + 1, b); } -Uint16 mempeek16(Uint8 *m, Uint16 a) { return (mempeek8(m, a) << 8) + mempeek8(m, a + 1); } -static void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8); devpoke8(d, a + 1, b); } -static Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); } +void poke16(Uint8 *m, Uint16 a, Uint16 b) { poke8(m, a, b >> 8); poke8(m, a + 1, b); } +Uint16 peek16(Uint8 *m, Uint16 a) { return (peek8(m, a) << 8) + peek8(m, a + 1); } +static void devw16(Device *d, Uint8 a, Uint16 b) { devw8(d, a, b >> 8); devw8(d, a + 1, b); } +static Uint16 devr16(Device *d, Uint16 a) { return (devr8(d, a) << 8) + devr8(d, a + 1); } /* Stack */ -static void op_lit(Uxn *u) { push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); } +static void op_lit(Uxn *u) { push8(u->src, peek8(u->ram.dat, u->ram.ptr++)); } static void op_inc(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a + 1); } static void op_pop(Uxn *u) { pop8(u->src); } static void op_dup(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a); push8(u->src, a); } @@ -52,14 +52,14 @@ static void op_jnz(Uxn *u) { Uint8 a = pop8(u->src); if(pop8(u->src)) u->ram.ptr static void op_jsr(Uxn *u) { Uint8 a = pop8(u->src); push16(u->dst, u->ram.ptr); u->ram.ptr += (Sint8)a; } static void op_sth(Uxn *u) { Uint8 a = pop8(u->src); push8(u->dst, a); } /* Memory */ -static void op_ldz(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u->ram.dat, a)); } -static void op_stz(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, a, b); } -static void op_ldr(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a)); } -static void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); } -static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, mempeek8(u->ram.dat, a)); } -static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); mempoke8(u->ram.dat, a, b); } -static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, devpeek8(&u->dev[a >> 4], a)); } -static void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devpoke8(&u->dev[a >> 4], a, b); } +static void op_ldz(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, peek8(u->ram.dat, a)); } +static void op_stz(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); poke8(u->ram.dat, a, b); } +static void op_ldr(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, peek8(u->ram.dat, u->ram.ptr + (Sint8)a)); } +static void op_str(Uxn *u) { Uint8 a = pop8(u->src); Uint8 b = pop8(u->src); poke8(u->ram.dat, u->ram.ptr + (Sint8)a, b); } +static void op_lda(Uxn *u) { Uint16 a = pop16(u->src); push8(u->src, peek8(u->ram.dat, a)); } +static void op_sta(Uxn *u) { Uint16 a = pop16(u->src); Uint8 b = pop8(u->src); poke8(u->ram.dat, a, b); } +static void op_dei(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, devr8(&u->dev[a >> 4], a)); } +static void op_deo(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); devw8(&u->dev[a >> 4], a, b); } /* Arithmetic */ static void op_add(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b + a); } static void op_sub(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b - a); } @@ -70,7 +70,7 @@ static void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u-> static void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); } static void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); } /* Stack(16-bits) */ -static void op_lit16(Uxn *u) { push16(u->src, mempeek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; } +static void op_lit16(Uxn *u) { push16(u->src, peek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; } static void op_inc16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, a + 1); } static void op_pop16(Uxn *u) { pop16(u->src); } static void op_dup16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, a); push16(u->src, a); } @@ -88,14 +88,14 @@ static void op_jnz16(Uxn *u) { Uint16 a = pop16(u->src); if(pop8(u->src)) u->ram static void op_jsr16(Uxn *u) { push16(u->dst, u->ram.ptr); u->ram.ptr = pop16(u->src); } static void op_sth16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->dst, a); } /* Memory(16-bits) */ -static void op_ldz16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u->ram.dat, a)); } -static void op_stz16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, a, b); } -static void op_ldr16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, mempeek16(u->ram.dat, u->ram.ptr + (Sint8)a)); } -static void op_str16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); } -static void op_lda16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, mempeek16(u->ram.dat, a)); } -static void op_sta16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); mempoke16(u->ram.dat, a, b); } -static void op_dei16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, devpeek16(&u->dev[a >> 4], a)); } -static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devpoke16(&u->dev[a >> 4], a, b); } +static void op_ldz16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, peek16(u->ram.dat, a)); } +static void op_stz16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); poke16(u->ram.dat, a, b); } +static void op_ldr16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, peek16(u->ram.dat, u->ram.ptr + (Sint8)a)); } +static void op_str16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); poke16(u->ram.dat, u->ram.ptr + (Sint8)a, b); } +static void op_lda16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, peek16(u->ram.dat, a)); } +static void op_sta16(Uxn *u) { Uint16 a = pop16(u->src); Uint16 b = pop16(u->src); poke16(u->ram.dat, a, b); } +static void op_dei16(Uxn *u) { Uint8 a = pop8(u->src); push16(u->src, devr16(&u->dev[a >> 4], a)); } +static void op_deo16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); devw16(&u->dev[a >> 4], a, b); } /* Arithmetic(16-bits) */ static void op_add16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b + a); } static void op_sub16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b - a); } diff --git a/src/uxn.h b/src/uxn.h @@ -40,8 +40,8 @@ typedef struct Uxn { struct Uxn; -void mempoke16(Uint8 *m, Uint16 a, Uint16 b); -Uint16 mempeek16(Uint8 *m, Uint16 a); +void poke16(Uint8 *m, Uint16 a, Uint16 b); +Uint16 peek16(Uint8 *m, Uint16 a); int uxn_boot(Uxn *c); int uxn_eval(Uxn *u, Uint16 vec); diff --git a/src/uxncli.c b/src/uxncli.c @@ -77,10 +77,10 @@ file_talk(Device *d, Uint8 b0, Uint8 w) { Uint8 read = b0 == 0xd; if(w && (read || b0 == 0xf)) { - char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)]; - Uint16 result = 0, length = mempeek16(d->dat, 0xa); - long offset = (mempeek16(d->dat, 0x4) << 16) + mempeek16(d->dat, 0x6); - Uint16 addr = mempeek16(d->dat, b0 - 1); + char *name = (char *)&d->mem[peek16(d->dat, 0x8)]; + Uint16 result = 0, length = peek16(d->dat, 0xa); + long offset = (peek16(d->dat, 0x4) << 16) + peek16(d->dat, 0x6); + Uint16 addr = peek16(d->dat, b0 - 1); FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w")); if(f) { fprintf(stderr, "%s %s %s #%04x, ", read ? "Loading" : "Saving", name, read ? "to" : "from", addr); @@ -89,7 +89,7 @@ file_talk(Device *d, Uint8 b0, Uint8 w) fprintf(stderr, "%04x bytes\n", result); fclose(f); } - mempoke16(d->dat, 0x2, result); + poke16(d->dat, 0x2, result); } } @@ -99,14 +99,14 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w) time_t seconds = time(NULL); struct tm *t = localtime(&seconds); t->tm_year += 1900; - mempoke16(d->dat, 0x0, t->tm_year); + poke16(d->dat, 0x0, t->tm_year); d->dat[0x2] = t->tm_mon; d->dat[0x3] = t->tm_mday; d->dat[0x4] = t->tm_hour; d->dat[0x5] = t->tm_min; d->dat[0x6] = t->tm_sec; d->dat[0x7] = t->tm_wday; - mempoke16(d->dat, 0x08, t->tm_yday); + poke16(d->dat, 0x08, t->tm_yday); d->dat[0xa] = t->tm_isdst; (void)b0; (void)w; @@ -138,7 +138,7 @@ run(Uxn *u) Uint16 vec = PAGE_PROGRAM; uxn_eval(u, vec); while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) { - vec = mempeek16(devconsole->dat, 0); + vec = peek16(devconsole->dat, 0); if(!vec) vec = u->ram.ptr; /* continue after last BRK */ uxn_eval(u, vec); } diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -221,8 +221,8 @@ domouse(SDL_Event *event) Uint8 flag = 0x00; Uint16 x = clamp(event->motion.x / zoom - PAD, 0, ppu.width - 1); Uint16 y = clamp(event->motion.y / zoom - PAD, 0, ppu.height - 1); - mempoke16(devmouse->dat, 0x2, x); - mempoke16(devmouse->dat, 0x4, y); + poke16(devmouse->dat, 0x2, x); + poke16(devmouse->dat, 0x4, y); switch(event->button.button) { case SDL_BUTTON_LEFT: flag = 0x01; break; case SDL_BUTTON_RIGHT: flag = 0x10; break; @@ -320,16 +320,16 @@ static void screen_talk(Device *d, Uint8 b0, Uint8 w) { if(w && b0 == 0xe) { - Uint16 x = mempeek16(d->dat, 0x8); - Uint16 y = mempeek16(d->dat, 0xa); + Uint16 x = peek16(d->dat, 0x8); + Uint16 y = peek16(d->dat, 0xa); Uint8 layer = d->dat[0xe] >> 4 & 0x1; ppu_pixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); reqdraw = 1; } else if(w && b0 == 0xf) { - Uint16 x = mempeek16(d->dat, 0x8); - Uint16 y = mempeek16(d->dat, 0xa); + Uint16 x = peek16(d->dat, 0x8); + Uint16 y = peek16(d->dat, 0xa); Uint8 layer = d->dat[0xf] >> 0x6 & 0x1; - Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; + Uint8 *addr = &d->mem[peek16(d->dat, 0xc)]; if(d->dat[0xf] >> 0x7 & 0x1) ppu_2bpp(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); else @@ -343,10 +343,10 @@ file_talk(Device *d, Uint8 b0, Uint8 w) { Uint8 read = b0 == 0xd; if(w && (read || b0 == 0xf)) { - char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)]; - Uint16 result = 0, length = mempeek16(d->dat, 0xa); - long offset = (mempeek16(d->dat, 0x4) << 16) + mempeek16(d->dat, 0x6); - Uint16 addr = mempeek16(d->dat, b0 - 1); + char *name = (char *)&d->mem[peek16(d->dat, 0x8)]; + Uint16 result = 0, length = peek16(d->dat, 0xa); + long offset = (peek16(d->dat, 0x4) << 16) + peek16(d->dat, 0x6); + Uint16 addr = peek16(d->dat, b0 - 1); FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w")); if(f) { fprintf(stderr, "%s %s %s #%04x, ", read ? "Loading" : "Saving", name, read ? "to" : "from", addr); @@ -355,7 +355,7 @@ file_talk(Device *d, Uint8 b0, Uint8 w) fprintf(stderr, "%04x bytes\n", result); fclose(f); } - mempoke16(d->dat, 0x2, result); + poke16(d->dat, 0x2, result); } } @@ -366,17 +366,17 @@ audio_talk(Device *d, Uint8 b0, Uint8 w) if(!audio_id) return; if(!w) { if(b0 == 0x2) - mempoke16(d->dat, 0x2, c->i); + poke16(d->dat, 0x2, c->i); else if(b0 == 0x4) d->dat[0x4] = apu_get_vu(c); } else if(b0 == 0xf) { SDL_LockAudioDevice(audio_id); - c->len = mempeek16(d->dat, 0xa); - c->addr = &d->mem[mempeek16(d->dat, 0xc)]; + c->len = peek16(d->dat, 0xa); + c->addr = &d->mem[peek16(d->dat, 0xc)]; c->volume[0] = d->dat[0xe] >> 4; c->volume[1] = d->dat[0xe] & 0xf; c->repeat = !(d->dat[0xf] & 0x80); - apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f); + apu_start(c, peek16(d->dat, 0x8), d->dat[0xf] & 0x7f); SDL_UnlockAudioDevice(audio_id); SDL_PauseAudioDevice(audio_id, 0); } @@ -388,14 +388,14 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w) time_t seconds = time(NULL); struct tm *t = localtime(&seconds); t->tm_year += 1900; - mempoke16(d->dat, 0x0, t->tm_year); + poke16(d->dat, 0x0, t->tm_year); d->dat[0x2] = t->tm_mon; d->dat[0x3] = t->tm_mday; d->dat[0x4] = t->tm_hour; d->dat[0x5] = t->tm_min; d->dat[0x6] = t->tm_sec; d->dat[0x7] = t->tm_wday; - mempoke16(d->dat, 0x08, t->tm_yday); + poke16(d->dat, 0x08, t->tm_yday); d->dat[0xa] = t->tm_isdst; (void)b0; (void)w; @@ -459,19 +459,19 @@ run(Uxn *u) case SDL_KEYDOWN: case SDL_KEYUP: doctrl(u, &event, event.type == SDL_KEYDOWN); - uxn_eval(u, mempeek16(devctrl->dat, 0)); + uxn_eval(u, peek16(devctrl->dat, 0)); devctrl->dat[3] = 0; break; case SDL_MOUSEWHEEL: devmouse->dat[7] = event.wheel.y; - uxn_eval(u, mempeek16(devmouse->dat, 0)); + uxn_eval(u, peek16(devmouse->dat, 0)); devmouse->dat[7] = 0; break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: domouse(&event); - uxn_eval(u, mempeek16(devmouse->dat, 0)); + uxn_eval(u, peek16(devmouse->dat, 0)); break; case SDL_WINDOWEVENT: if(event.window.event == SDL_WINDOWEVENT_EXPOSED) @@ -482,12 +482,12 @@ run(Uxn *u) default: if(event.type == stdin_event) { devconsole->dat[0x2] = event.cbutton.button; - uxn_eval(u, mempeek16(devconsole->dat, 0)); + uxn_eval(u, peek16(devconsole->dat, 0)); } else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) - uxn_eval(u, mempeek16((devaudio0 + (event.type - audio0_event))->dat, 0)); + uxn_eval(u, peek16((devaudio0 + (event.type - audio0_event))->dat, 0)); } } - uxn_eval(u, mempeek16(devscreen->dat, 0)); + uxn_eval(u, peek16(devscreen->dat, 0)); if(reqdraw || devsystem->dat[0xe]) redraw(u); if(!BENCH) { @@ -544,8 +544,8 @@ main(int argc, char **argv) uxn_port(&u, 0xf, "---", nil_talk); /* Write screen size to dev/screen */ - mempoke16(devscreen->dat, 2, ppu.width); - mempoke16(devscreen->dat, 4, ppu.height); + poke16(devscreen->dat, 2, ppu.width); + poke16(devscreen->dat, 4, ppu.height); run(&u); quit();