From 06c57cb936c7a18ea6ea6738d1985cfc542182c8 Mon Sep 17 00:00:00 2001 From: neauoire Date: Mon, 1 Feb 2021 14:40:27 -0800 Subject: [PATCH] Progress on status flags --- README.md | 3 +-- build.sh | 2 +- examples/core.usm | 3 ++- examples/subroutines.usm | 25 +++++++++++++++++++++++++ uxn.c | 14 +++++++++++--- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 examples/subroutines.usm diff --git a/README.md b/README.md index 9243915..3ce29ff 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ $01 < pointer8 > ## Mission +- Carry flag? - Loop -- Conditional example - Pointers/Literals - Print word to stdout - Draw pixel to screen @@ -51,7 +51,6 @@ $01 < pointer8 > - Implement 16 bits operations - Jumps should be relative - Catch overflow/underflow -- Implement literals like `[2]`, and `[ 2 3 ]`. - Audo-detect literals length. - SDL Layer Emulator - Build PPU diff --git a/build.sh b/build.sh index 341ae70..1df615f 100755 --- a/build.sh +++ b/build.sh @@ -14,5 +14,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined uxn.c -o uxn # run -./uxnasm examples/cond.usm boot.rom +./uxnasm examples/core.usm boot.rom ./uxn boot.rom diff --git a/examples/core.usm b/examples/core.usm index 79a0434..3b9ccf5 100644 --- a/examples/core.usm +++ b/examples/core.usm @@ -1,3 +1,4 @@ < core > -+12 -34 \ No newline at end of file ++12 +34 ADD + diff --git a/examples/subroutines.usm b/examples/subroutines.usm new file mode 100644 index 0000000..bee09c1 --- /dev/null +++ b/examples/subroutines.usm @@ -0,0 +1,25 @@ +< subroutines > + +:begin + .addall JSR ADD ADD + +06 EQU .isequal JSR + BRK + +:add1 + +01 RTS + +:add2 + +02 RTS + +:add3 + +03 RTS + +:addall + .add1 JSR + .add2 JSR + .add3 JSR + RTS + +:isequal + .addall JSR +ff + RTS diff --git a/uxn.c b/uxn.c index 55b906d..450828c 100644 --- a/uxn.c +++ b/uxn.c @@ -92,7 +92,7 @@ rspop(void) void op_brk() { setflag(FLAG_HALT, 1); } void op_rts() { cpu.mptr = rspop(); } -void op_lit() { cpu.literal += 1;} +void op_lit() { cpu.literal += 1; } void op_drp() { spop(); } void op_dup() { spush(cpu.stack[cpu.sptr - 1]); } void op_swp() { Uint8 b = spop(), a = spop(); spush(b); spush(a); } @@ -100,8 +100,8 @@ void op_ovr() { spush(cpu.stack[cpu.sptr - 2]); } void op_rot() { Uint8 c = spop(),b = spop(),a = spop(); spush(b); spush(c); spush(a); } void op_jmp() { cpu.mptr = spop(); } void op_jsr() { rspush(cpu.mptr); cpu.mptr = spop(); } -void op_jmq() { if(getflag(FLAG_ZERO)) op_jmp(); } -void op_jsq() { if(getflag(FLAG_ZERO)) op_jsr(); } +void op_jmq() { if(getflag(FLAG_ZERO)){ op_jmp(); } setflag(FLAG_ZERO,0); } +void op_jsq() { if(getflag(FLAG_ZERO)){ op_jsr(); } setflag(FLAG_ZERO,0); } void op_equ() { setflag(FLAG_ZERO, spop() == spop()); } void op_neq() { setflag(FLAG_ZERO, spop() != spop()); } void op_lth() { setflag(FLAG_ZERO, spop() < spop()); } @@ -159,6 +159,8 @@ eval() } if(instr < 24) (*ops[instr])(); + if(instr > 0x10) + setflag(FLAG_ZERO, 0); } void @@ -169,6 +171,12 @@ run(void) eval(cpu); /* debug */ printf("ended @ %d | ", cpu.counter); + printf("hf: %x zf: %x cf: %x tf: %x\n", + getflag(FLAG_HALT), + getflag(FLAG_ZERO), + getflag(FLAG_CARRY), + getflag(FLAG_TRAPS)); + printf("\n\n"); for(i = 0; i < 4; i++) printf("%d-", (cpu.status & (1 << i)) != 0); printf("\n\n");