| ... | ... |
@@ -36,8 +36,8 @@ $01 < pointer8 > |
| 36 | 36 |
|
| 37 | 37 |
## Mission |
| 38 | 38 |
|
| 39 |
+- Carry flag? |
|
| 39 | 40 |
- Loop |
| 40 |
-- Conditional example |
|
| 41 | 41 |
- Pointers/Literals |
| 42 | 42 |
- Print word to stdout |
| 43 | 43 |
- Draw pixel to screen |
| ... | ... |
@@ -51,7 +51,6 @@ $01 < pointer8 > |
| 51 | 51 |
- Implement 16 bits operations |
| 52 | 52 |
- Jumps should be relative |
| 53 | 53 |
- Catch overflow/underflow |
| 54 |
-- Implement literals like `[2]`, and `[ 2 3 ]`. |
|
| 55 | 54 |
- Audo-detect literals length. |
| 56 | 55 |
- SDL Layer Emulator |
| 57 | 56 |
- Build PPU |
| ... | ... |
@@ -14,5 +14,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr |
| 14 | 14 |
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 |
| 15 | 15 |
|
| 16 | 16 |
# run |
| 17 |
-./uxnasm examples/cond.usm boot.rom |
|
| 17 |
+./uxnasm examples/core.usm boot.rom |
|
| 18 | 18 |
./uxn boot.rom |
| 5 | 6 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,25 @@ |
| 1 |
+< subroutines > |
|
| 2 |
+ |
|
| 3 |
+:begin |
|
| 4 |
+ .addall JSR ADD ADD |
|
| 5 |
+ +06 EQU .isequal JSR |
|
| 6 |
+ BRK |
|
| 7 |
+ |
|
| 8 |
+:add1 |
|
| 9 |
+ +01 RTS |
|
| 10 |
+ |
|
| 11 |
+:add2 |
|
| 12 |
+ +02 RTS |
|
| 13 |
+ |
|
| 14 |
+:add3 |
|
| 15 |
+ +03 RTS |
|
| 16 |
+ |
|
| 17 |
+:addall |
|
| 18 |
+ .add1 JSR |
|
| 19 |
+ .add2 JSR |
|
| 20 |
+ .add3 JSR |
|
| 21 |
+ RTS |
|
| 22 |
+ |
|
| 23 |
+:isequal |
|
| 24 |
+ .addall JSR +ff |
|
| 25 |
+ RTS |
| ... | ... |
@@ -92,7 +92,7 @@ rspop(void) |
| 92 | 92 |
|
| 93 | 93 |
void op_brk() { setflag(FLAG_HALT, 1); }
|
| 94 | 94 |
void op_rts() { cpu.mptr = rspop(); }
|
| 95 |
-void op_lit() { cpu.literal += 1;}
|
|
| 95 |
+void op_lit() { cpu.literal += 1; }
|
|
| 96 | 96 |
void op_drp() { spop(); }
|
| 97 | 97 |
void op_dup() { spush(cpu.stack[cpu.sptr - 1]); }
|
| 98 | 98 |
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]); }
|
| 100 | 100 |
void op_rot() { Uint8 c = spop(),b = spop(),a = spop(); spush(b); spush(c); spush(a); }
|
| 101 | 101 |
void op_jmp() { cpu.mptr = spop(); }
|
| 102 | 102 |
void op_jsr() { rspush(cpu.mptr); cpu.mptr = spop(); }
|
| 103 |
-void op_jmq() { if(getflag(FLAG_ZERO)) op_jmp(); }
|
|
| 104 |
-void op_jsq() { if(getflag(FLAG_ZERO)) op_jsr(); }
|
|
| 103 |
+void op_jmq() { if(getflag(FLAG_ZERO)){ op_jmp(); } setflag(FLAG_ZERO,0); }
|
|
| 104 |
+void op_jsq() { if(getflag(FLAG_ZERO)){ op_jsr(); } setflag(FLAG_ZERO,0); }
|
|
| 105 | 105 |
void op_equ() { setflag(FLAG_ZERO, spop() == spop()); }
|
| 106 | 106 |
void op_neq() { setflag(FLAG_ZERO, spop() != spop()); }
|
| 107 | 107 |
void op_lth() { setflag(FLAG_ZERO, spop() < spop()); }
|
| ... | ... |
@@ -159,6 +159,8 @@ eval() |
| 159 | 159 |
} |
| 160 | 160 |
if(instr < 24) |
| 161 | 161 |
(*ops[instr])(); |
| 162 |
+ if(instr > 0x10) |
|
| 163 |
+ setflag(FLAG_ZERO, 0); |
|
| 162 | 164 |
} |
| 163 | 165 |
|
| 164 | 166 |
void |
| ... | ... |
@@ -169,6 +171,12 @@ run(void) |
| 169 | 171 |
eval(cpu); |
| 170 | 172 |
/* debug */ |
| 171 | 173 |
printf("ended @ %d | ", cpu.counter);
|
| 174 |
+ printf("hf: %x zf: %x cf: %x tf: %x\n",
|
|
| 175 |
+ getflag(FLAG_HALT), |
|
| 176 |
+ getflag(FLAG_ZERO), |
|
| 177 |
+ getflag(FLAG_CARRY), |
|
| 178 |
+ getflag(FLAG_TRAPS)); |
|
| 179 |
+ printf("\n\n");
|
|
| 172 | 180 |
for(i = 0; i < 4; i++) |
| 173 | 181 |
printf("%d-", (cpu.status & (1 << i)) != 0);
|
| 174 | 182 |
printf("\n\n");
|