commit 06c57cb936c7a18ea6ea6738d1985cfc542182c8
parent 2782586f78eb9b5529406b4a6cd1ccd3cd96974f
Author: neauoire <aliceffekt@gmail.com>
Date: Mon, 1 Feb 2021 14:40:27 -0800
Progress on status flags
Diffstat:
5 files changed, 40 insertions(+), 8 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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");