Progress on status flags

This commit is contained in:
neauoire 2021-02-01 14:40:27 -08:00
parent 2782586f78
commit 06c57cb936
5 changed files with 40 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,4 @@
< core >
+12 -34
+12 +34 ADD

25
examples/subroutines.usm Normal file
View File

@ -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

14
uxn.c
View File

@ -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");