(uxn.c) Housekeeping

This commit is contained in:
Devine Lu Linvega 2023-07-23 11:06:21 -07:00
parent cb41bdfa9a
commit 4db53c1cc6
1 changed files with 18 additions and 20 deletions

View File

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