uxn

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

commit ab889172cf3e3ad20d71f5dc93626aeddea6c577
parent 18a48a28c578004c62b58d2d485a95fb64bd2208
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun,  4 Apr 2021 09:37:00 -0700

Merged lit counter with status flag

Diffstat:
Msrc/uxn.c | 16++++++++++------
Msrc/uxn.h | 6+++---
2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/uxn.c b/src/uxn.c @@ -34,7 +34,7 @@ Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u, /* Stack */ void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); } void op_nop(Uxn *u) { (void)u; } -void op_lit(Uxn *u) { u->literal += 1; } +void op_lit(Uxn *u) { setflag(&u->status, FLAG_LIT1, 1); } void op_pop(Uxn *u) { pop8(u->src); } void op_dup(Uxn *u) { push8(u->src, peek8(u->src, 0)); } void op_swp(Uxn *u) { Uint8 b = pop8(u->src), a = pop8(u->src); push8(u->src, b); push8(u->src, a); } @@ -66,7 +66,7 @@ void op_ora(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b ^ a); } void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); } /* Stack */ -void op_lit16(Uxn *u) { u->literal += 2; } +void op_lit16(Uxn *u) { setflag(&u->status, FLAG_LIT2, 1); } void op_nop16(Uxn *u) { printf("%04x\n", pop16(u->src)); } void op_pop16(Uxn *u) { pop16(u->src); } void op_dup16(Uxn *u) { push16(u->src, peek16(u->src, 0)); } @@ -126,7 +126,11 @@ void lituxn(Uxn *u, Uint8 instr) { push8(u->src, instr); - u->literal--; + if(getflag(&u->status, FLAG_LIT2)) { + setflag(&u->status, FLAG_LIT2, 0); + setflag(&u->status, FLAG_LIT1, 1); + } else if(getflag(&u->status, FLAG_LIT1)) + setflag(&u->status, FLAG_LIT1, 0); } void @@ -141,7 +145,7 @@ opcuxn(Uxn *u, Uint8 instr) int stepuxn(Uxn *u, Uint8 instr) { - if(u->literal > 0) + if(getflag(&u->status, FLAG_LIT2) || getflag(&u->status, FLAG_LIT1)) lituxn(u, instr); else opcuxn(u, instr); @@ -155,7 +159,7 @@ stepuxn(Uxn *u, Uint8 instr) int evaluxn(Uxn *u, Uint16 vec) { - u->literal = 0; + u->status = 0; u->ram.ptr = vec; u->wst.error = 0; u->rst.error = 0; @@ -195,6 +199,6 @@ portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0 Device *d = &u->dev[id]; d->addr = PAGE_DEVICE + id * 0x10; d->poke = pofn; - printf("Device #%d: %s, at 0x%04x \n", id - 1, name, d->addr); + printf("Device #%d: %s, at 0x%04x \n", id, name, d->addr); return d; } diff --git a/src/uxn.h b/src/uxn.h @@ -17,8 +17,8 @@ typedef unsigned short Uint16; typedef signed short Sint16; #define FLAG_HALT 0x01 -#define FLAG_LIT1 0x04 -#define FLAG_LIT2 0x08 +#define FLAG_LIT1 0x02 +#define FLAG_LIT2 0x04 #define PAGE_DEVICE 0x0100 #define PAGE_VECTORS 0x0200 @@ -40,7 +40,7 @@ typedef struct Device { } Device; typedef struct Uxn { - Uint8 literal, status; + Uint8 status; Stack wst, rst, *src, *dst; Memory ram; Device dev[16];