... | ... |
@@ -28,22 +28,30 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn |
28 | 28 |
- `"hello`, push literal bytes for word "hello" |
29 | 29 |
|
30 | 30 |
``` |
31 |
-;value ( alloc a zero-page variable ) |
|
31 |
+( hello world ) |
|
32 | 32 |
|
33 |
-@0010 ( start at page 1 ) |
|
33 |
+;iterator |
|
34 |
+:dev1r FFF0 |
|
35 |
+:dev1w FFF1 |
|
34 | 36 |
|
35 |
-,03 ,02 ADD ,05 EQU |
|
36 |
-,there ROT JMC |
|
37 |
+|0100 @RESET |
|
37 | 38 |
|
38 |
-:here |
|
39 |
- ( when not equal ) |
|
40 |
- ,ee |
|
41 |
- BRK |
|
39 |
+"hello |
|
40 |
+ |
|
41 |
+@loop |
|
42 |
+ ,dev1w STR |
|
43 |
+ ,iterator LDR |
|
44 |
+ ,01 ADD |
|
45 |
+ ,iterator STR |
|
46 |
+ ,iterator LDR |
|
47 |
+ ,05 NEQ ,loop ROT JSC |
|
48 |
+ |
|
49 |
+BRK ( RESET ) |
|
50 |
+ |
|
51 |
+|c000 @FRAME BRK |
|
52 |
+|d000 @ERROR BRK |
|
53 |
+|FFFA .RESET .FRAME .ERROR |
|
42 | 54 |
|
43 |
-:there |
|
44 |
- ( when is equal ) |
|
45 |
- ,ff |
|
46 |
- BRK |
|
47 | 55 |
``` |
48 | 56 |
|
49 | 57 |
## Mission |
... | ... |
@@ -1,18 +1,20 @@ |
1 |
-( blank project ) |
|
1 |
+( hello world ) |
|
2 | 2 |
|
3 |
-;variable1 |
|
3 |
+;iterator |
|
4 | 4 |
:dev1r FFF0 |
5 | 5 |
:dev1w FFF1 |
6 | 6 |
|
7 | 7 |
|0100 @RESET |
8 | 8 |
|
9 |
-"hello |
|
9 |
+"hello |
|
10 | 10 |
|
11 |
-,dev1w STR |
|
12 |
-,dev1w STR |
|
13 |
-,dev1w STR |
|
14 |
-,dev1w STR |
|
15 |
-,dev1w STR |
|
11 |
+@loop |
|
12 |
+ ,dev1w STR |
|
13 |
+ ,iterator LDR |
|
14 |
+ ,01 ADD |
|
15 |
+ ,iterator STR |
|
16 |
+ ,iterator LDR |
|
17 |
+ ,05 NEQ ,loop ROT JSC |
|
16 | 18 |
|
17 | 19 |
BRK ( RESET ) |
18 | 20 |
|
... | ... |
@@ -85,15 +85,21 @@ echom(Memory *m, Uint8 len, char *name) |
85 | 85 |
|
86 | 86 |
/* clang-format off */ |
87 | 87 |
|
88 |
+Uint16 bytes2short(Uint8 a, Uint8 b) { return (a << 8) + b; } |
|
88 | 89 |
Uint8 rampeek8(Uint16 s) { return cpu.ram.dat[s] & 0xff; } |
90 |
+Uint8 mempeek8(Uint16 s) { return cpu.rom.dat[s]; } |
|
89 | 91 |
Uint16 mempeek16(Uint16 s) { return (cpu.rom.dat[s] << 8) + (cpu.rom.dat[s+1] & 0xff); } |
90 | 92 |
void wspush8(Uint8 b) { cpu.wst.dat[cpu.wst.ptr++] = b; } |
91 | 93 |
Uint8 wspop8(void) { return cpu.wst.dat[--cpu.wst.ptr]; } |
92 | 94 |
Uint16 wspop16(void) { return wspop8() + (wspop8() << 8); } |
93 | 95 |
Uint8 wspeek8(void) { return cpu.wst.dat[cpu.wst.ptr - 1]; } |
96 |
+Uint16 rspop16(void) { return cpu.rst.dat[--cpu.rst.ptr] + (cpu.rst.dat[--cpu.rst.ptr] << 8); } |
|
94 | 97 |
|
95 | 98 |
void op_brk() { setflag(FLAG_HALT, 1); } |
96 |
-void op_rts() { cpu.rom.ptr = cpu.rst.dat[--cpu.rst.ptr]; } |
|
99 |
+void op_rts() { |
|
100 |
+ cpu.rom.ptr = rspop16(); |
|
101 |
+ printf("RTS: %04x\n", cpu.rom.ptr); |
|
102 |
+} |
|
97 | 103 |
void op_lit() { cpu.literal += cpu.rom.dat[cpu.rom.ptr++]; } |
98 | 104 |
void op_drp() { wspop8(); } |
99 | 105 |
void op_dup() { wspush8(wspeek8()); } |
... | ... |
@@ -101,7 +107,7 @@ void op_swp() { Uint8 b = wspop8(), a = wspop8(); wspush8(b); wspush8(a); } |
101 | 107 |
void op_ovr() { wspush8(cpu.wst.dat[cpu.wst.ptr - 2]); } |
102 | 108 |
void op_rot() { Uint8 c = wspop8(),b = wspop8(),a = wspop8(); wspush8(b); wspush8(c); wspush8(a); } |
103 | 109 |
void op_jmu() { cpu.rom.ptr = wspop8(); } |
104 |
-void op_jsu() { cpu.rst.dat[cpu.rst.ptr++] = cpu.rom.ptr; cpu.rom.ptr = wspop8(); } |
|
110 |
+void op_jsu() { cpu.rst.dat[cpu.rst.ptr++] = (cpu.rom.ptr >> 8) & 0xff; cpu.rst.dat[cpu.rst.ptr++] = cpu.rom.ptr; cpu.rom.ptr = wspop16(); } |
|
105 | 111 |
void op_jmc() { if(wspop8()) op_jmu(); } |
106 | 112 |
void op_jsc() { if(wspop8()) op_jsu(); } |
107 | 113 |
void op_equ() { wspush8(wspop8() == wspop8()); } |
... | ... |
@@ -163,6 +169,7 @@ device1(Uint8 *read, Uint8 *write) |
163 | 169 |
{ |
164 | 170 |
printf("%c", *write); |
165 | 171 |
*write = 0; |
172 |
+ (void)read; |
|
166 | 173 |
return 0; |
167 | 174 |
} |
168 | 175 |
|