uxn

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

commit 4db53c1cc62d7d89c6460b1fd5469c1c92928023
parent cb41bdfa9ade25d2afcdd6f8b5227154e2265554
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sun, 23 Jul 2023 11:06:21 -0700

(uxn.c) Housekeeping

Diffstat:
Msrc/uxn.c | 36+++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/uxn.c b/src/uxn.c @@ -11,42 +11,40 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +/* Registers +[ . ][ . ][ . ][ L ][ N ][ T ] < +[ . ][ . ][ . ][ H2 ][ T ] < +[ L2 ][ N2 ][ T2 ] < +*/ + #define T s->dat[s->ptr - 1] #define N s->dat[s->ptr - 2] #define L s->dat[s->ptr - 3] -#define H2 PEEK2(s->dat + s->ptr - 3) #define T2 PEEK2(s->dat + s->ptr - 2) +#define H2 PEEK2(s->dat + s->ptr - 3) #define N2 PEEK2(s->dat + s->ptr - 4) #define L2 PEEK2(s->dat + s->ptr - 6) -/* Registers - -[ . ][ . ][ . ][ L ][ N ][ T ] < -[ . ][ . ][ . ][ H2 ][ T ] < -[ L2 ][ N2 ][ T2 ] < - -*/ - -#define HALT(c) { return uxn_halt(u, ins, (c), pc - 1); } -#define SET(mul, add) { if(mul > s->ptr) HALT(1) tmp = (mul & k) + add + s->ptr; if(tmp > 254) HALT(2) s->ptr = tmp; } -#define PUT(o, v) { s->dat[(Uint8)(s->ptr - 1 - (o))] = (v); } -#define PUT2(o, v) { tmp = (v); POKE2(s->dat + (Uint8)(s->ptr - o - 2), tmp); } -#define DEO(a, b) { u->dev[(a)] = (b); if((deo_mask[(a) >> 4] >> ((a) & 0xf)) & 0x1) uxn_deo(u, (a)); } -#define DEI(a, b) { PUT((a), ((dei_mask[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? uxn_dei(u, (b)) : u->dev[(b)]) } -#define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; } +#define HALT(c) { return uxn_halt(u, ins, (c), pc - 1); } +#define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; } +#define SET(x, y) { if(x > s->ptr) HALT(1) tmp = (x & k) + y + s->ptr; if(tmp > 254) HALT(2) s->ptr = tmp; } +#define PUT(o, v) { s->dat[(s->ptr - 1 - (o))] = (v); } +#define PUT2(o, v) { tmp = (v); POKE2(s->dat + (s->ptr - o - 2), tmp); } +#define DEO(a, b) { u->dev[(a)] = (b); if((deo_mask[(a) >> 4] >> ((a) & 0xf)) & 0x1) uxn_deo(u, (a)); } +#define DEI(a, b) { PUT((a), ((dei_mask[(b) >> 4] >> ((b) & 0xf)) & 0x1) ? uxn_dei(u, (b)) : u->dev[(b)]) } int uxn_eval(Uxn *u, Uint16 pc) { - int t, n, l, k, tmp, ins; - Uint8 *ram = u->ram, opc; + int t, n, l, k, tmp, ins, opc; + Uint8 *ram = u->ram; Stack *s; if(!pc || u->dev[0x0f]) return 0; for(;;) { ins = ram[pc++]; k = ins & 0x80 ? 0xff : 0; s = ins & 0x40 ? &u->rst : &u->wst; - opc = !(ins & 0x1f) ? (0 - (ins >> 5)) : ins & 0x3f; + opc = !(ins & 0x1f) ? (0 - (ins >> 5)) & 0xff : ins & 0x3f; switch(opc) { /* IMM */ case 0x00: /* BRK */ return 1;