uxn

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

commit c68936b475b04fd76baeb1530310e777484a7b4c
parent fcf12a12dc9b6fca27cb8c7296bb40137e1c034c
Author: neauoire <aliceffekt@gmail.com>
Date:   Mon,  7 Aug 2023 16:22:57 -0700

(uxn.c) Renamed POP/PUSH to POPx/PUSHx

Diffstat:
Msrc/devices/screen.c | 35++++++++++++++++++++---------------
Msrc/uxn.c | 66+++++++++++++++++++++++++++++++++---------------------------------
2 files changed, 53 insertions(+), 48 deletions(-)

diff --git a/src/devices/screen.c b/src/devices/screen.c @@ -46,6 +46,24 @@ screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color) layer[x + y * width] = color; } +static void +screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, int x1, int y1, int color, int flipx, int flipy, int twobpp) +{ + int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5); + for(v = 0; v < 8; v++) { + Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0); + Uint16 y = y1 + (flipy ? 7 - v : v); + for(h = 7; h >= 0; --h, c >>= 1) { + Uint8 ch = (c & 1) | ((c >> 7) & 2); + if(opaque || ch) { + Uint16 x = x1 + (flipx ? 7 - h : h); + if(x < width && y < height) + layer[x + y * width] = blending[ch][color]; + } + } + } +} + void screen_palette(Uint8 *addr) { @@ -167,28 +185,15 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) Uint8 length = move >> 4; Uint8 twobpp = !!(ctrl & 0x80); Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg; - Uint8 color = ctrl & 0xf, opaque = color % 5; + Uint8 color = ctrl & 0xf; Uint16 x = PEEK2(d + 0x8), dx = (move & 0x1) << 3; Uint16 y = PEEK2(d + 0xa), dy = (move & 0x2) << 2; Uint16 addr = PEEK2(d + 0xc), addr_incr = (move & 0x4) << (1 + twobpp); int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1; int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1; - int v, h, width = uxn_screen.width, height = uxn_screen.height; Uint16 dyx = dy * fx, dxy = dx * fy; for(i = 0; i <= length; i++) { - Uint16 x1 = x + dyx * i, y1 = y + dxy * i; - for(v = 0; v < 8; v++) { - Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0); - Uint16 y = y1 + (flipy ? 7 - v : v); - for(h = 7; h >= 0; --h, c >>= 1) { - Uint8 ch = (c & 1) | ((c >> 7) & 2); - if(opaque || ch) { - Uint16 x = x1 + (flipx ? 7 - h : h); - if(x < width && y < height) - layer[x + y * width] = blending[ch][color]; - } - } - } + screen_blit(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy, twobpp); addr += addr_incr; } screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8); diff --git a/src/uxn.c b/src/uxn.c @@ -18,10 +18,10 @@ WITH REGARD TO THIS SOFTWARE. #define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; } #define PUSH1(y) { if(s->ptr == 0xff) HALT(2) s->dat[s->ptr++] = (y); } #define PUSH2(y) { if((tsp = s->ptr) >= 0xfe) HALT(2) t = (y); POKE2(&s->dat[tsp], t); s->ptr = tsp + 2; } -#define PUSH(y) { if(m2) { PUSH2(y) } else { PUSH1(y) } } +#define PUSHx(y) { if(m2) { PUSH2(y) } else { PUSH1(y) } } #define POP1(o) { if(*sp == 0x00) HALT(1) o = s->dat[--*sp]; } #define POP2(o) { if((tsp = *sp) <= 0x01) HALT(1) o = PEEK2(&s->dat[tsp - 2]); *sp = tsp - 2; } -#define POP(o) { if(m2) { POP2(o) } else { POP1(o) } } +#define POPx(o) { if(m2) { POP2(o) } else { POP1(o) } } #define DEVW(p, y) { if(m2) { DEO(p, y >> 8) DEO((p + 1), y) } else { DEO(p, y) } } #define DEVR(o, p) { if(m2) { o = ((DEI(p) << 8) + DEI(p + 1)); } else { o = DEI(p); } } @@ -51,37 +51,37 @@ uxn_eval(Uxn *u, Uint16 pc) case -0x5: /* LIT2 */ case -0x7: /* LIT2r */ PUSH2(PEEK2(ram + pc)) pc += 2; break; /* ALU */ - case 0x01: /* INC */ POP(a) PUSH(a + 1) break; - case 0x02: /* POP */ POP(a) break; - case 0x03: /* NIP */ POP(a) POP(b) PUSH(a) break; - case 0x04: /* SWP */ POP(a) POP(b) PUSH(a) PUSH(b) break; - case 0x05: /* ROT */ POP(a) POP(b) POP(c) PUSH(b) PUSH(a) PUSH(c) break; - case 0x06: /* DUP */ POP(a) PUSH(a) PUSH(a) break; - case 0x07: /* OVR */ POP(a) POP(b) PUSH(b) PUSH(a) PUSH(b) break; - case 0x08: /* EQU */ POP(a) POP(b) PUSH1(b == a) break; - case 0x09: /* NEQ */ POP(a) POP(b) PUSH1(b != a) break; - case 0x0a: /* GTH */ POP(a) POP(b) PUSH1(b > a) break; - case 0x0b: /* LTH */ POP(a) POP(b) PUSH1(b < a) break; - case 0x0c: /* JMP */ POP(a) JUMP(a) break; - case 0x0d: /* JCN */ POP(a) POP1(b) if(b) JUMP(a) break; - case 0x0e: /* JSR */ POP(a) FLIP PUSH2(pc) JUMP(a) break; - case 0x0f: /* STH */ POP(a) FLIP PUSH(a) break; - case 0x10: /* LDZ */ POP1(a) PEEK(b, a) PUSH(b) break; - case 0x11: /* STZ */ POP1(a) POP(b) POKE(a, b) break; - case 0x12: /* LDR */ POP1(a) PEEK(b, pc + (Sint8)a) PUSH(b) break; - case 0x13: /* STR */ POP1(a) POP(b) POKE(pc + (Sint8)a, b) break; - case 0x14: /* LDA */ POP2(a) PEEK(b, a) PUSH(b) break; - case 0x15: /* STA */ POP2(a) POP(b) POKE(a, b) break; - case 0x16: /* DEI */ POP1(a) DEVR(b, a) PUSH(b) break; - case 0x17: /* DEO */ POP1(a) POP(b) DEVW(a, b) break; - case 0x18: /* ADD */ POP(a) POP(b) PUSH(b + a) break; - case 0x19: /* SUB */ POP(a) POP(b) PUSH(b - a) break; - case 0x1a: /* MUL */ POP(a) POP(b) PUSH((Uint32)b * a) break; - case 0x1b: /* DIV */ POP(a) POP(b) if(!a) HALT(3) PUSH(b / a) break; - case 0x1c: /* AND */ POP(a) POP(b) PUSH(b & a) break; - case 0x1d: /* ORA */ POP(a) POP(b) PUSH(b | a) break; - case 0x1e: /* EOR */ POP(a) POP(b) PUSH(b ^ a) break; - case 0x1f: /* SFT */ POP1(a) POP(b) PUSH(b >> (a & 0xf) << (a >> 4)) break; + case 0x01: /* INC */ POPx(a) PUSHx(a + 1) break; + case 0x02: /* POP */ POPx(a) break; + case 0x03: /* NIP */ POPx(a) POPx(b) PUSHx(a) break; + case 0x04: /* SWP */ POPx(a) POPx(b) PUSHx(a) PUSHx(b) break; + case 0x05: /* ROT */ POPx(a) POPx(b) POPx(c) PUSHx(b) PUSHx(a) PUSHx(c) break; + case 0x06: /* DUP */ POPx(a) PUSHx(a) PUSHx(a) break; + case 0x07: /* OVR */ POPx(a) POPx(b) PUSHx(b) PUSHx(a) PUSHx(b) break; + case 0x08: /* EQU */ POPx(a) POPx(b) PUSH1(b == a) break; + case 0x09: /* NEQ */ POPx(a) POPx(b) PUSH1(b != a) break; + case 0x0a: /* GTH */ POPx(a) POPx(b) PUSH1(b > a) break; + case 0x0b: /* LTH */ POPx(a) POPx(b) PUSH1(b < a) break; + case 0x0c: /* JMP */ POPx(a) JUMP(a) break; + case 0x0d: /* JCN */ POPx(a) POP1(b) if(b) JUMP(a) break; + case 0x0e: /* JSR */ POPx(a) FLIP PUSH2(pc) JUMP(a) break; + case 0x0f: /* STH */ POPx(a) FLIP PUSHx(a) break; + case 0x10: /* LDZ */ POP1(a) PEEK(b, a) PUSHx(b) break; + case 0x11: /* STZ */ POP1(a) POPx(b) POKE(a, b) break; + case 0x12: /* LDR */ POP1(a) PEEK(b, pc + (Sint8)a) PUSHx(b) break; + case 0x13: /* STR */ POP1(a) POPx(b) POKE(pc + (Sint8)a, b) break; + case 0x14: /* LDA */ POP2(a) PEEK(b, a) PUSHx(b) break; + case 0x15: /* STA */ POP2(a) POPx(b) POKE(a, b) break; + case 0x16: /* DEI */ POP1(a) DEVR(b, a) PUSHx(b) break; + case 0x17: /* DEO */ POP1(a) POPx(b) DEVW(a, b) break; + case 0x18: /* ADD */ POPx(a) POPx(b) PUSHx(b + a) break; + case 0x19: /* SUB */ POPx(a) POPx(b) PUSHx(b - a) break; + case 0x1a: /* MUL */ POPx(a) POPx(b) PUSHx((Uint32)b * a) break; + case 0x1b: /* DIV */ POPx(a) POPx(b) if(!a) HALT(3) PUSHx(b / a) break; + case 0x1c: /* AND */ POPx(a) POPx(b) PUSHx(b & a) break; + case 0x1d: /* ORA */ POPx(a) POPx(b) PUSHx(b | a) break; + case 0x1e: /* EOR */ POPx(a) POPx(b) PUSHx(b ^ a) break; + case 0x1f: /* SFT */ POP1(a) POPx(b) PUSHx(b >> (a & 0xf) << (a >> 4)) break; } } }