Browse code

Added zero-page shorthand

neauoire authored on 07/02/2021 20:13:38
Showing 7 changed files
... ...
@@ -26,6 +26,7 @@ cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn
26 26
 - `( comment )`, toggle parsing on/off
27 27
 - `|0010`, move to position in the program
28 28
 - `"hello`, push literal bytes for word "hello"
29
+- `#04`, a zero-page address, equivalent to `,0004`
29 30
 
30 31
 ### Operator modes
31 32
 
... ...
@@ -65,23 +66,20 @@ BRK ( RESET )
65 66
 
66 67
 ### Assembler
67 68
 
68
-- Complete implementing short mode
69
+- Create a benchmark file
69 70
 - Implement shorthand operators
70
-- Catch overflow/underflow
71
-- Jumps should be relative
72
-- Load program in RAM
73 71
 - Signed operations
72
+- zero-page address?
74 73
 
75 74
 ### CPU
76 75
 
77
-- Pointers/Literals
76
+- Signed operations
77
+- Catch overflow/underflow
78 78
 - A Three-Way Decision Routine(http://www.6502.org/tutorials/compare_instructions.html)
79
-- Print word to stdout
80 79
 - Draw pixel to screen
81 80
 - Detect mouse click
82 81
 - SDL Layer Emulator
83 82
 - Build PPU
84
-- Add flags..
85 83
 
86 84
 ### Devices
87 85
 
... ...
@@ -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/core.usm boot.rom
17
+./uxnasm examples/benchmark.usm boot.rom
18 18
 ./uxn boot.rom
19 19
new file mode 100644
... ...
@@ -0,0 +1,31 @@
1
+( benchmark )
2
+
3
+;iterator
4
+:dev1r FFF0
5
+:dev1w FFF1
6
+
7
+|0100 @RESET
8
+
9
+( arithmetic ) 
10
+,12 ,34 ADD ,46 EQU #00 STR
11
+,12 ,06 SUB ,0c EQU #01 STR
12
+,12 ,06 MUL ,6c EQU #02 STR
13
+,12 ,06 DIV ,03 EQU #03 STR
14
+,12 ,12 EQU #04 STR
15
+,12 ,13 NEQ #05 STR
16
+,12 ,11 GTH #06 STR
17
+,12 ,13 LTH #07 STR
18
+
19
+( arithmetic 16-bit )
20
+,1234 ,2345 ADD^ ,3579 EQU^ #08 STR
21
+,1234 ,0123 SUB^ ,1111 EQU^ #09 STR
22
+,1234 ,0102 MUL^ ,5868 EQU^ #0a STR
23
+,5678 ,0100 DIV^ ,0056 EQU^ #0b STR
24
+,1234 ,1234 EQU^ #0c STR
25
+,1234 ,0123 NEQ^ #0d STR
26
+,1234 ,1233 GTH^ #0e STR
27
+,1234 ,1235 LTH^ #0f STR
28
+
29
+|c000 @FRAME BRK 
30
+|d000 @ERROR BRK 
31
+|FFFA .RESET .FRAME .ERROR
... ...
@@ -6,27 +6,6 @@
6 6
 
7 7
 |0100 @RESET
8 8
 
9
-@word1 "hello_word ( len: 0x0b )
10
-
11
-@loop
12
-	,dev1w STR ( write to stdout )
13
-	,incr JSU ( increment itr )
14
-	,word1 ,strlen JSU ( get strlen )
15
-	NEQ ,loop ROT JSC ( loop != strlen )
16
-
17
-BRK
18
-
19
-@strlen
20
-	,0001 ADD^ LDR
21
-	RTU
22
-
23
-@incr
24
-	,iterator LDR
25
-	,01 ADD
26
-	,iterator STR 
27
-	,iterator LDR
28
-	RTU
29
-
30 9
 |c000 @FRAME BRK 
31 10
 |d000 @ERROR BRK 
32 11
 |FFFA .RESET .FRAME .ERROR
... ...
@@ -17,7 +17,7 @@
17 17
 BRK
18 18
 
19 19
 @strlen
20
-	,0001 ADD^ PEK
20
+	,0001 ADD^ LDR
21 21
 	RTU
22 22
 
23 23
 @incr
... ...
@@ -65,7 +65,7 @@ void
65 65
 echos(Stack8 *s, Uint8 len, char *name)
66 66
 {
67 67
 	int i;
68
-	printf("%s\n", name);
68
+	printf("\n%s\n", name);
69 69
 	for(i = 0; i < len; ++i) {
70 70
 		if(i % 16 == 0)
71 71
 			printf("\n");
... ...
@@ -78,7 +78,7 @@ void
78 78
 echom(Memory *m, Uint8 len, char *name)
79 79
 {
80 80
 	int i;
81
-	printf("%s\n", name);
81
+	printf("\n%s\n", name);
82 82
 	for(i = 0; i < len; ++i) {
83 83
 		if(i % 16 == 0)
84 84
 			printf("\n");
... ...
@@ -127,14 +127,14 @@ void op_and() { Uint8 a = wspop8(), b = wspop8(); wspush8(a & b); }
127 127
 void op_ora() { Uint8 a = wspop8(), b = wspop8(); wspush8(a | b); }
128 128
 void op_rol() { Uint8 a = wspop8(), b = wspop8(); wspush8(a << b); }
129 129
 /* Arithmetic */
130
-void op_add() { Uint8 a = wspop8(), b = wspop8(); wspush8(a + b); }
131
-void op_sub() { Uint8 a = wspop8(), b = wspop8(); wspush8(a - b); }
132
-void op_mul() { Uint8 a = wspop8(), b = wspop8(); wspush8(a * b); }
133
-void op_div() { Uint8 a = wspop8(), b = wspop8(); wspush8(a / b); }
134
-void op_equ() { Uint8 a = wspop8(), b = wspop8(); wspush8(a == b); }
135
-void op_neq() { Uint8 a = wspop8(), b = wspop8(); wspush8(a != b); }
136
-void op_gth() { Uint8 a = wspop8(), b = wspop8(); wspush8(a < b); }
137
-void op_lth() { Uint8 a = wspop8(), b = wspop8(); wspush8(a > b); }
130
+void op_add() { Uint8 a = wspop8(), b = wspop8(); wspush8(b + a); }
131
+void op_sub() { Uint8 a = wspop8(), b = wspop8(); wspush8(b - a); }
132
+void op_mul() { Uint8 a = wspop8(), b = wspop8(); wspush8(b * a); }
133
+void op_div() { Uint8 a = wspop8(), b = wspop8(); wspush8(b / a); }
134
+void op_equ() { Uint8 a = wspop8(), b = wspop8(); wspush8(b == a); }
135
+void op_neq() { Uint8 a = wspop8(), b = wspop8(); wspush8(b != a); }
136
+void op_gth() { Uint8 a = wspop8(), b = wspop8(); wspush8(b > a); }
137
+void op_lth() { Uint8 a = wspop8(), b = wspop8(); wspush8(b < a); }
138 138
 /* Stack(16-bits) */
139 139
 void op_pop16() { wspop16(); }
140 140
 void op_dup16() { wspush16(wspeek16(2)); }
... ...
@@ -145,14 +145,14 @@ void op_and16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a & b); }
145 145
 void op_ora16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a | b); }
146 146
 void op_rol16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a << b); }
147 147
 /* Arithmetic(16-bits) */
148
-void op_add16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a + b); }
149
-void op_sub16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a - b); }
150
-void op_mul16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a * b); }
151
-void op_div16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a / b); }
152
-void op_equ16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a == b); }
153
-void op_neq16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a != b); }
154
-void op_gth16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a < b); }
155
-void op_lth16() { Uint16 a = wspop16(), b = wspop16(); wspush16(a > b); }
148
+void op_add16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b + a); }
149
+void op_sub16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b - a); }
150
+void op_mul16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b * a); }
151
+void op_div16() { Uint16 a = wspop16(), b = wspop16(); wspush16(b / a); }
152
+void op_equ16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b == a); }
153
+void op_neq16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b != a); }
154
+void op_gth16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b > a); }
155
+void op_lth16() { Uint16 a = wspop16(), b = wspop16(); wspush8(b < a); }
156 156
 
157 157
 void (*ops[])() = {
158 158
 	op_brk, op_lit, op_nop, op_nop, op_nop, op_nop, op_ldr, op_str, 
... ...
@@ -163,7 +163,7 @@ void (*ops[])() = {
163 163
 	op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16
164 164
 };
165 165
 
166
-Uint8 opr[][2] = { /* todo: 16 bits mode */
166
+Uint8 opr[][2] = { 
167 167
 	{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
168 168
 	{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
169 169
 	{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
... ...
@@ -168,6 +168,7 @@ pass1(FILE *f)
168 168
 			case '@':
169 169
 			case ';': break;
170 170
 			case '.': addr += 2; break;
171
+			case '#': addr += 4; break;
171 172
 			case '"': addr += slen(w + 1) + 2; break;
172 173
 			case ',': addr += 2 + (sihx(w + 1) && slen(w + 1) == 2 ? 1 : 2); break;
173 174
 			default: return error("Unknown label", w);
... ...
@@ -195,7 +196,9 @@ pass2(FILE *f)
195 196
 			fscanf(f, "%s", w);
196 197
 		else if(w[0] == '"')
197 198
 			pushtext(w + 1);
198
-		else if((l = findlabel(w + 1)))
199
+		else if(w[0] == '#') {
200
+			pushshort(shex(w + 1) & 0xff, 1);
201
+		} else if((l = findlabel(w + 1)))
199 202
 			pushshort(l->addr, w[0] == ',');
200 203
 		else if((op = findoperator(w)) || scmp(w, "BRK"))
201 204
 			pushbyte(op, 0);