| ... | ... |
@@ -34,6 +34,17 @@ $01 < pointer8 > |
| 34 | 34 |
:label ADD RTS |
| 35 | 35 |
``` |
| 36 | 36 |
|
| 37 |
+## Mission |
|
| 38 |
+ |
|
| 39 |
+- Loop |
|
| 40 |
+- Conditional example |
|
| 41 |
+- Pointers/Literals |
|
| 42 |
+- Print word to stdout |
|
| 43 |
+- Draw pixel to screen |
|
| 44 |
+- Detect mouse click |
|
| 45 |
+- 16 bits addressing |
|
| 46 |
+- jumping to subroutine should be relative |
|
| 47 |
+ |
|
| 37 | 48 |
## TODOs |
| 38 | 49 |
|
| 39 | 50 |
- Implement addressing |
| ... | ... |
@@ -44,6 +55,7 @@ $01 < pointer8 > |
| 44 | 55 |
- Audo-detect literals length. |
| 45 | 56 |
- SDL Layer Emulator |
| 46 | 57 |
- Build PPU |
| 58 |
+- Interrupts |
|
| 47 | 59 |
|
| 48 | 60 |
## Refs |
| 49 | 61 |
|
| ... | ... |
@@ -13,12 +13,6 @@ rm -f ./boot.rom |
| 13 | 13 |
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 uxnasm.c -o uxnasm |
| 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 |
-# build(fast) |
|
| 17 |
-# cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn |
|
| 18 |
- |
|
| 19 |
-# Size |
|
| 20 |
-# echo "Size: $(du -sk ./uxn)" |
|
| 21 |
- |
|
| 22 | 16 |
# run |
| 23 |
-./uxnasm example.usm boot.rom |
|
| 17 |
+./uxnasm examples/cond.usm boot.rom |
|
| 24 | 18 |
./uxn boot.rom |
| ... | ... |
@@ -91,8 +91,8 @@ rspop(void) |
| 91 | 91 |
/* clang-format off */ |
| 92 | 92 |
|
| 93 | 93 |
void op_brk() { setflag(FLAG_HALT, 1); }
|
| 94 |
-void op_lit() { cpu.literal += cpu.memory[cpu.mptr++]; }
|
|
| 95 |
-void op_nop() { }
|
|
| 94 |
+void op_rts() { cpu.mptr = rspop(); }
|
|
| 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_jeq() { if(getflag(FLAG_ZERO)) cpu.mptr = spop(); }
|
|
| 104 |
-void op_rts() { cpu.mptr = rspop(); }
|
|
| 103 |
+void op_jmq() { if(getflag(FLAG_ZERO)) op_jmp(); }
|
|
| 104 |
+void op_jsq() { if(getflag(FLAG_ZERO)) op_jsr(); }
|
|
| 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()); }
|
| ... | ... |
@@ -116,8 +116,8 @@ void op_mul() { spush(spop() * spop()); }
|
| 116 | 116 |
void op_div() { spush(spop() / spop()); }
|
| 117 | 117 |
|
| 118 | 118 |
void (*ops[])(void) = {
|
| 119 |
- op_brk, op_lit, op_nop, op_drp, op_dup, op_swp, op_ovr, op_rot, |
|
| 120 |
- op_jmp, op_jsr, op_jeq, op_rts, op_equ, op_neq, op_gth, op_lth, |
|
| 119 |
+ op_brk, op_rts, op_lit, op_drp, op_dup, op_swp, op_ovr, op_rot, |
|
| 120 |
+ op_jmp, op_jsr, op_jmq, op_jsq, op_equ, op_neq, op_gth, op_lth, |
|
| 121 | 121 |
op_and, op_ora, op_rol, op_ror, op_add, op_sub, op_mul, op_div}; |
| 122 | 122 |
|
| 123 | 123 |
/* clang-format on */ |
| ... | ... |
@@ -31,8 +31,8 @@ Label labels[256]; |
| 31 | 31 |
|
| 32 | 32 |
char opcodes[][4] = {
|
| 33 | 33 |
"BRK", |
| 34 |
+ "RTS", |
|
| 34 | 35 |
"LIT", |
| 35 |
- "---", |
|
| 36 | 36 |
"POP", |
| 37 | 37 |
"DUP", |
| 38 | 38 |
"SWP", |
| ... | ... |
@@ -41,8 +41,8 @@ char opcodes[][4] = {
|
| 41 | 41 |
/* */ |
| 42 | 42 |
"JMP", |
| 43 | 43 |
"JSR", |
| 44 |
- "JEQ", |
|
| 45 |
- "RTS", |
|
| 44 |
+ "JMQ", |
|
| 45 |
+ "JSQ", |
|
| 46 | 46 |
"EQU", |
| 47 | 47 |
"NEQ", |
| 48 | 48 |
"LTH", |
| ... | ... |
@@ -164,11 +164,10 @@ int |
| 164 | 164 |
getlength(char *w) |
| 165 | 165 |
{
|
| 166 | 166 |
if(findop(w) || scmp(w, "BRK")) return 1; |
| 167 |
- if(w[0] == '.') return 3; |
|
| 167 |
+ if(w[0] == '.') return 2; |
|
| 168 | 168 |
if(w[0] == ':') return 0; |
| 169 |
- if(w[0] == '[') return 2; |
|
| 170 |
- if(sihx(w)) return 1; |
|
| 171 |
- if(w[0] == ']') return 0; |
|
| 169 |
+ if(w[0] == '+') return 2; |
|
| 170 |
+ if(w[0] == '-') return 2; |
|
| 172 | 171 |
printf("Unknown length %s\n", w);
|
| 173 | 172 |
return 0; |
| 174 | 173 |
} |
| ... | ... |
@@ -205,28 +204,23 @@ pass2(FILE *f) |
| 205 | 204 |
int skip = 0; |
| 206 | 205 |
char word[64]; |
| 207 | 206 |
while(fscanf(f, "%s", word) == 1) {
|
| 208 |
- Uint8 op; |
|
| 207 |
+ Uint8 op = 0; |
|
| 209 | 208 |
Label *l; |
| 210 | 209 |
if(word[0] == ':') continue; |
| 211 | 210 |
suca(word); |
| 212 | 211 |
if(comment(word, &skip)) continue; |
| 213 |
- if(word[0] == ']') continue; |
|
| 214 |
- if(word[0] == '+') {
|
|
| 215 |
- addprg(0x01); |
|
| 216 |
- addprg(1); |
|
| 217 |
- addprg(shex(word + 1)); |
|
| 218 |
- } else if(word[0] == '[') {
|
|
| 219 |
- addprg(0x01); |
|
| 212 |
+ /* literals */ |
|
| 213 |
+ if(word[0] == '+' || word[0] == '-') |
|
| 214 |
+ addprg(0x02); |
|
| 215 |
+ if(word[0] == '+') |
|
| 220 | 216 |
addprg(shex(word + 1)); |
| 221 |
- } else if((op = findop(word))) |
|
| 217 |
+ else if(word[0] == '-') |
|
| 218 |
+ addprg((Uint8)(-1 * shex(word + 1))); |
|
| 219 |
+ /* opcodes */ |
|
| 220 |
+ else if((op = findop(word)) || scmp(word, "BRK")) |
|
| 222 | 221 |
addprg(op); |
| 223 |
- else if(sihx(word)) |
|
| 224 |
- addprg(shex(word)); |
|
| 225 |
- else if(scmp(word, "BRK")) |
|
| 226 |
- addprg(0x00); |
|
| 227 | 222 |
else if((l = findlabel(word + 1))) {
|
| 228 |
- addprg(0x01); |
|
| 229 |
- addprg(1); |
|
| 223 |
+ addprg(0x02); |
|
| 230 | 224 |
addprg(l->addr); |
| 231 | 225 |
} else |
| 232 | 226 |
printf("unknown: %s\n", word);
|