... | ... |
@@ -31,6 +31,7 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn |
31 | 31 |
### Operator modes |
32 | 32 |
|
33 | 33 |
- `,1234 ,0001 ADD^`, 16-bits operators have the short flag `^`. |
34 |
+- `,12 ,11 GTH JMP?`, conditional operators have the cond flag `?`. |
|
34 | 35 |
|
35 | 36 |
``` |
36 | 37 |
( hello world ) |
... | ... |
@@ -41,14 +42,19 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn |
41 | 42 |
|
42 | 43 |
|0100 @RESET |
43 | 44 |
|
44 |
-"hello |
|
45 |
+@word1 "hello_word ( len: 0x0b ) |
|
45 | 46 |
|
46 | 47 |
@loop |
47 |
- ,dev1w STR |
|
48 |
- ,incr JSU ( call incr ) |
|
49 |
- ,05 NEQ ,loop ROT JSC |
|
48 |
+ ,dev1w STR ( write to stdout ) |
|
49 |
+ ,incr JSR ( increment itr ) |
|
50 |
+ ,word1 ,strlen JSR ( get strlen ) |
|
51 |
+ NEQ ,loop ROT JSR? ( loop != strlen ) |
|
50 | 52 |
|
51 |
-BRK ( RESET ) |
|
53 |
+BRK |
|
54 |
+ |
|
55 |
+@strlen |
|
56 |
+ ,0001 ADD^ LDR |
|
57 |
+ RTS |
|
52 | 58 |
|
53 | 59 |
@incr |
54 | 60 |
,iterator LDR |
... | ... |
@@ -56,7 +62,7 @@ BRK ( RESET ) |
56 | 62 |
,iterator STR |
57 | 63 |
,iterator LDR |
58 | 64 |
RTS |
59 |
- |
|
65 |
+ |
|
60 | 66 |
|c000 @FRAME BRK |
61 | 67 |
|d000 @ERROR BRK |
62 | 68 |
|FFFA .RESET .FRAME .ERROR |
... | ... |
@@ -66,10 +72,8 @@ BRK ( RESET ) |
66 | 72 |
|
67 | 73 |
### Assembler |
68 | 74 |
|
69 |
-- Create a benchmark file |
|
70 | 75 |
- Implement shorthand operators |
71 | 76 |
- Signed operations |
72 |
-- zero-page address? |
|
73 | 77 |
|
74 | 78 |
### CPU |
75 | 79 |
|
... | ... |
@@ -77,6 +81,7 @@ BRK ( RESET ) |
77 | 81 |
- Catch overflow/underflow |
78 | 82 |
- A Three-Way Decision Routine(http://www.6502.org/tutorials/compare_instructions.html) |
79 | 83 |
- Draw pixel to screen |
84 |
+- Redo overflow/underflow mappping |
|
80 | 85 |
- Detect mouse click |
81 | 86 |
- SDL Layer Emulator |
82 | 87 |
- 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/benchmark.usm boot.rom |
|
17 |
+./uxnasm examples/hello.usm boot.rom |
|
18 | 18 |
./uxn boot.rom |
... | ... |
@@ -10,22 +10,22 @@ |
10 | 10 |
|
11 | 11 |
@loop |
12 | 12 |
,dev1w STR ( write to stdout ) |
13 |
- ,incr JSU ( increment itr ) |
|
14 |
- ,word1 ,strlen JSU ( get strlen ) |
|
15 |
- NEQ ,loop ROT JSC ( loop != strlen ) |
|
13 |
+ ,incr JSR ( increment itr ) |
|
14 |
+ ,word1 ,strlen JSR ( get strlen ) |
|
15 |
+ NEQ ,loop ROT JSR? ( loop != strlen ) |
|
16 | 16 |
|
17 | 17 |
BRK |
18 | 18 |
|
19 | 19 |
@strlen |
20 | 20 |
,0001 ADD^ LDR |
21 |
- RTU |
|
21 |
+ RTS |
|
22 | 22 |
|
23 | 23 |
@incr |
24 | 24 |
,iterator LDR |
25 | 25 |
,01 ADD |
26 | 26 |
,iterator STR |
27 | 27 |
,iterator LDR |
28 |
- RTU |
|
28 |
+ RTS |
|
29 | 29 |
|
30 | 30 |
|c000 @FRAME BRK |
31 | 31 |
|d000 @ERROR BRK |
... | ... |
@@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE. |
14 | 14 |
#define FLAG_HALT 0x01 |
15 | 15 |
#define FLAG_SHORT 0x02 |
16 | 16 |
#define FLAG_SIGN 0x04 |
17 |
-#define FLAG_TRAPS 0x08 |
|
17 |
+#define FLAG_COND 0x08 |
|
18 | 18 |
|
19 | 19 |
typedef unsigned char Uint8; |
20 | 20 |
typedef unsigned short Uint16; |
... | ... |
@@ -92,8 +92,6 @@ echom(Memory *m, Uint8 len, char *name) |
92 | 92 |
/* clang-format off */ |
93 | 93 |
|
94 | 94 |
Uint16 bytes2short(Uint8 a, Uint8 b) { return (a << 8) + b; } |
95 |
-Uint8 rampeek8(Uint16 s) { return cpu.ram.dat[s] & 0xff; } |
|
96 |
-Uint8 mempeek8(Uint16 s) { return cpu.ram.dat[s]; } |
|
97 | 95 |
Uint16 mempeek16(Uint16 s) { return (cpu.ram.dat[s] << 8) + (cpu.ram.dat[s+1] & 0xff); } |
98 | 96 |
void wspush8(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; } |
99 | 97 |
void wspush16(Uint16 s) { wspush8(s >> 8); wspush8(s & 0xff); } |
... | ... |
@@ -107,16 +105,13 @@ void rspush16(Uint16 a) { cpu.rst.dat[cpu.rst.ptr++] = a; } |
107 | 105 |
/* I/O */ |
108 | 106 |
void op_brk() { setflag(FLAG_HALT, 1); } |
109 | 107 |
void op_lit() { cpu.literal += cpu.ram.dat[cpu.ram.ptr++]; } |
110 |
-void op_nop() { } |
|
108 |
+void op_nop() { printf("NOP");} |
|
111 | 109 |
void op_ldr() { wspush8(cpu.ram.dat[wspop16()]); } |
112 | 110 |
void op_str() { cpu.ram.dat[wspop16()] = wspop8(); } |
113 | 111 |
/* Logic */ |
114 |
-void op_jmu() { cpu.ram.ptr = wspop16(); } |
|
115 |
-void op_jmc() { Uint8 a = wspop8(); if(a) op_jmu(); } |
|
116 |
-void op_jsu() { rspush16(cpu.ram.ptr); cpu.ram.ptr = wspop16(); } |
|
117 |
-void op_jsc() { Uint8 a = wspop8(); if(a) op_jsu(); } |
|
118 |
-void op_rtu() { cpu.ram.ptr = rspop16(); } |
|
119 |
-void op_rtc() { /* TODO */ } |
|
112 |
+void op_jmp() { cpu.ram.ptr = wspop16(); } |
|
113 |
+void op_jsr() { rspush16(cpu.ram.ptr); cpu.ram.ptr = wspop16(); } |
|
114 |
+void op_rts() { cpu.ram.ptr = rspop16(); } |
|
120 | 115 |
/* Stack */ |
121 | 116 |
void op_pop() { wspop8(); } |
122 | 117 |
void op_dup() { wspush8(wspeek8(1)); } |
... | ... |
@@ -156,14 +151,14 @@ void op_lth16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b < a); } |
156 | 151 |
|
157 | 152 |
void (*ops[])() = { |
158 | 153 |
op_brk, op_lit, op_nop, op_nop, op_nop, op_nop, op_ldr, op_str, |
159 |
- op_jmu, op_jmc, op_jsu, op_jsc, op_rtu, op_rtc, op_nop, op_nop, |
|
154 |
+ op_jmp, op_jsr, op_nop, op_rts, op_nop, op_nop, op_nop, op_nop, |
|
160 | 155 |
op_pop, op_dup, op_swp, op_ovr, op_rot, op_and, op_ora, op_rol, |
161 | 156 |
op_add, op_sub, op_mul, op_div, op_equ, op_neq, op_gth, op_lth, |
162 | 157 |
op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_and16, op_ora16, op_rol16, |
163 | 158 |
op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16 |
164 | 159 |
}; |
165 | 160 |
|
166 |
-Uint8 opr[][2] = { |
|
161 |
+Uint8 opr[][2] = { /* TODO */ |
|
167 | 162 |
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, |
168 | 163 |
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, |
169 | 164 |
{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, |
... | ... |
@@ -202,8 +197,7 @@ opc(Uint8 src, Uint8 *op) |
202 | 197 |
int |
203 | 198 |
eval(void) |
204 | 199 |
{ |
205 |
- Uint8 instr = cpu.ram.dat[cpu.ram.ptr++]; |
|
206 |
- Uint8 op; |
|
200 |
+ Uint8 op, instr = cpu.ram.dat[cpu.ram.ptr++]; |
|
207 | 201 |
/* when literal */ |
208 | 202 |
if(cpu.literal > 0) { |
209 | 203 |
wspush8(instr); |
... | ... |
@@ -213,19 +207,23 @@ eval(void) |
213 | 207 |
/* when opcode */ |
214 | 208 |
opc(instr, &op); |
215 | 209 |
setflag(FLAG_SHORT, (instr >> 5) & 1); |
216 |
- setflag(FLAG_SIGN, (instr >> 6) & 1); |
|
217 |
- if((instr >> 7) & 1) |
|
218 |
- printf("Unused flag: %02x\n", instr); |
|
210 |
+ setflag(FLAG_SIGN, (instr >> 6) & 1); /* TODO: Implement */ |
|
211 |
+ setflag(FLAG_COND, (instr >> 7) & 1); |
|
212 |
+ /* TODO: overflow */ |
|
219 | 213 |
if(cpu.wst.ptr < opr[op][0]) |
220 | 214 |
return error("Stack underflow", op); |
215 |
+ /* short mode */ |
|
221 | 216 |
if(getflag(FLAG_SHORT)) |
222 | 217 |
op += 16; |
223 |
- (*ops[op])(); |
|
224 |
- |
|
225 |
- /* experimental */ |
|
218 |
+ /* cond mode */ |
|
219 |
+ if(getflag(FLAG_COND)) { |
|
220 |
+ if(wspop8()) |
|
221 |
+ (*ops[op])(); |
|
222 |
+ } else |
|
223 |
+ (*ops[op])(); |
|
224 |
+ /* devices: experimental */ |
|
226 | 225 |
if(cpu.ram.dat[0xfff1]) |
227 | 226 |
device1(&cpu.ram.dat[0xfff0], &cpu.ram.dat[0xfff1]); |
228 |
- |
|
229 | 227 |
cpu.counter++; |
230 | 228 |
return 1; |
231 | 229 |
} |
... | ... |
@@ -245,7 +243,7 @@ debug(void) |
245 | 243 |
getflag(FLAG_HALT) != 0, |
246 | 244 |
getflag(FLAG_SHORT) != 0, |
247 | 245 |
getflag(FLAG_SIGN) != 0, |
248 |
- getflag(FLAG_TRAPS) != 0); |
|
246 |
+ getflag(FLAG_COND) != 0); |
|
249 | 247 |
} |
250 | 248 |
|
251 | 249 |
int |
... | ... |
@@ -32,7 +32,7 @@ Program p; |
32 | 32 |
|
33 | 33 |
char ops[][4] = { |
34 | 34 |
"BRK", "LIT", "---", "---", "PEK", "POK", "LDR", "STR", |
35 |
- "JMU", "JMC", "JSU", "JSC", "RTU", "RTC", "---", "---", |
|
35 |
+ "JMP", "JSR", "RTI", "RTS", "---", "---", "---", "---", |
|
36 | 36 |
"POP", "DUP", "SWP", "OVR", "ROT", "AND", "ORA", "ROL", |
37 | 37 |
"ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH" |
38 | 38 |
}; |
... | ... |
@@ -103,7 +103,7 @@ findoperator(char *s) |
103 | 103 |
while(s[3 + m]) { |
104 | 104 |
if(s[3 + m] == '^') i |= (1 << 5); /* mode: 16 bits */ |
105 | 105 |
if(s[3 + m] == '~') i |= (1 << 6); /* mode: signed */ |
106 |
- if(s[3 + m] == '&') i |= (1 << 7); /* mode: unused */ |
|
106 |
+ if(s[3 + m] == '?') i |= (1 << 7); /* mode: conditional */ |
|
107 | 107 |
m++; |
108 | 108 |
} |
109 | 109 |
return i; |