neauoire authored on 11/02/2021 00:41:16
Showing 11 changed files
... ...
@@ -62,9 +62,9 @@ BRK
62 62
 
63 63
 ## TODOs
64 64
 
65
+- short variable
65 66
 - Implement signed flag to operators.
66 67
 - On-screen debugger.
67
-- 16b mode for str/ldr
68 68
 - Auto-advance ldr?
69 69
 - Getting rid of IOR/IOW would be nice..
70 70
 
... ...
@@ -139,32 +139,40 @@ makeconst(char *id, FILE *f)
139 139
 	return makelabel(id, shex(wv));
140 140
 }
141 141
 
142
+int
143
+makevariable(char *id, Uint16 *addr, FILE *f)
144
+{
145
+	char wv[64];
146
+	Uint8 origin;
147
+	fscanf(f, "%s", wv);
148
+	origin = *addr;
149
+	*addr += shex(wv);
150
+	return makelabel(id, origin);
151
+}
152
+
142 153
 int
143 154
 pass1(FILE *f)
144 155
 {
145
-	int skip = 0, vars = 0;
156
+	int skip = 0;
146 157
 	Uint16 addr = 0;
147 158
 	char w[64];
148 159
 	while(fscanf(f, "%s", w) == 1) {
149 160
 		if(cmnt(w, &skip))
150 161
 			continue;
151
-		if(w[0] == '@' && !makelabel(w + 1, addr))
152
-			return error("Pass1 failed", w);
153
-		if(w[0] == ';' && !makelabel(w + 1, vars++))
154
-			return error("Pass1 failed", w);
155
-		if(w[0] == ':') {
162
+		if(w[0] == '@') {
163
+			if(!makelabel(w + 1, addr))
164
+				return error("Pass1 failed", w);
165
+		} else if(w[0] == ';') {
166
+			if(!makevariable(w + 1, &addr, f))
167
+				return error("Pass1 failed", w);
168
+		} else if(w[0] == ':') {
156 169
 			if(!makeconst(w + 1, f))
157 170
 				return error("Pass1 failed", w);
158
-			else
159
-				continue;
160
-		}
161
-		if(findoperator(w) || scmp(w, "BRK"))
171
+		} else if(findoperator(w) || scmp(w, "BRK"))
162 172
 			addr += 1;
163 173
 		else {
164 174
 			switch(w[0]) {
165 175
 			case '|': addr = shex(w + 1); break;
166
-			case '@':
167
-			case ';': break;
168 176
 			case '"': addr += slen(w + 1) + 2; break;
169 177
 			case '#': addr += 4; break;
170 178
 			case '.': addr += 2; break;
... ...
@@ -189,12 +197,13 @@ pass2(FILE *f)
189 197
 		Uint8 op = 0;
190 198
 		Label *l;
191 199
 		if(w[0] == '@') continue;
192
-		if(w[0] == ';') continue;
193 200
 		if(cmnt(w, &skip)) continue;
194 201
 		if(w[0] == '|')
195 202
 			p.ptr = shex(w + 1);
196 203
 		else if(w[0] == ':')
197 204
 			fscanf(f, "%s", w);
205
+		else if(w[0] == ';')
206
+			fscanf(f, "%s", w);
198 207
 		else if(w[0] == '"')
199 208
 			pushtext(w + 1);
200 209
 		else if(w[0] == '#')
... ...
@@ -24,5 +24,5 @@ rm -f ./bin/emulator
24 24
 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 emulator.c -L/usr/local/lib -lSDL2 -o bin/emulator
25 25
 
26 26
 # run
27
-./bin/assembler examples/test.usm bin/boot.rom
27
+./bin/assembler examples/pixels.usm bin/boot.rom
28 28
 ./bin/emulator bin/boot.rom
... ...
@@ -37,7 +37,7 @@ SDL_Renderer *gRenderer;
37 37
 SDL_Texture *gTexture;
38 38
 Uint32 *pixels;
39 39
 
40
-Device *devscreen, *devmouse, *devkey;
40
+Device *devconsole, *devscreen, *devmouse, *devkey;
41 41
 
42 42
 int
43 43
 error(char *msg, const char *err)
... ...
@@ -288,7 +288,7 @@ main(int argc, char **argv)
288 288
 	if(!init())
289 289
 		return error("Init", "Failed");
290 290
 
291
-	portuxn(&u, "console", consoler, consolew);
291
+	devconsole = portuxn(&u, "console", consoler, consolew);
292 292
 	devscreen = portuxn(&u, "screen", screenr, screenw);
293 293
 	devmouse = portuxn(&u, "mouse", mouser, mousew);
294 294
 	devkey = portuxn(&u, "key", keyr, keyw);
... ...
@@ -1,9 +1,5 @@
1 1
 ( benchmark )
2 2
 
3
-;iterator
4
-:dev1r FFF0
5
-:dev1w FFF1
6
-
7 3
 |0100 @RESET
8 4
 
9 5
 ( arithmetic ) 
... ...
@@ -1,9 +1,5 @@
1 1
 ( blank )
2 2
 
3
-;iterator
4
-:dev1r FFF0
5
-:dev1w FFF1
6
-
7 3
 |0100 @RESET BRK
8 4
 |c000 @FRAME BRK 
9 5
 |d000 @ERROR BRK 
... ...
@@ -1,20 +1,26 @@
1 1
 ( draw pixel )
2 2
 
3
+:dev/w fff9 ( keep write port in a const )
4
+;x 2
5
+;y 2
6
+
3 7
 |0100 @RESET
4 8
 	
5
-	( redraw - color - x - y )
6
-	,00 ,01 ,0000 ,0000 ,putpixel JSR
7
-	,00 ,02 ,0001 ,0001 ,putpixel JSR
8
-	,01 ,03 ,0002 ,0002 ,putpixel JSR
9
+	( set dev/write to screen ) 
9 10
 
10
-BRK
11
+	,01 ,dev/w STR 
12
+
13
+	,0020 ,x STR^ ( set x-pos )
14
+	,0030 ,y STR^ ( set y-pos )
11 15
 
12
-@putpixel 
13
-	SWP ,01 IOW ,01 IOW ( y )
14
-	SWP ,01 IOW ,01 IOW ( x )
15
-	,01 IOW ( color )
16
+	( IOW will now send to screen ) 
17
+
18
+	,y LDR^ IOW^ ( y-pos )
19
+	,x LDR^ IOW^ ( x-pos )
20
+	,02 IOW ( color )
16 21
 	,01 IOW ( redraw )
17
-	RTS
22
+
23
+BRK
18 24
 
19 25
 |c000 @FRAME BRK 
20 26
 |d000 @ERROR BRK 
21 27
new file mode 100644
... ...
@@ -0,0 +1,47 @@
1
+( my default test file )
2
+
3
+:dev/r fff8 ( std read port )
4
+:dev/w fff9 ( std write port )
5
+
6
+;x 2 ;y 2 ;color 1 
7
+
8
+|0100 @RESET 
9
+	
10
+	,01 ,dev/w STR ( set dev/write to screen ) 
11
+	,01 ,color STR ( set color ) 	
12
+	,0020 ,x STR^ ( set x-pos )
13
+	,0030 ,y STR^ ( set y-pos )
14
+
15
+BRK
16
+
17
+|c000 @FRAME 
18
+
19
+	,colorize JSR
20
+	,move JSR
21
+	( draw )
22
+	,01 ,color LDR ,x LDR^ ,y LDR^ ,putpixel JSR
23
+
24
+BRK
25
+
26
+@colorize
27
+	,color LDR ,01 ADD ,color STR ( incr color )
28
+	,color LDR ,04 LTH RTS?
29
+	,01 ,color STR 
30
+	RTS
31
+
32
+@move
33
+	,x LDR^ ,0001 ADD^ ,x STR^ ( incr x )
34
+	,x LDR^ ,0060 LTH^ RTS?    ( if x > 60 )
35
+	,0020 ,x STR^              ( x = 0x0020 )
36
+	,y LDR^ ,0001 ADD^ ,y STR^ ( incr y )
37
+	RTS
38
+
39
+@putpixel 
40
+	IOW^ ( y short )
41
+	IOW^ ( x short )
42
+	IOW ( color byte )
43
+	IOW ( redraw byte )
44
+	RTS
45
+
46
+|d000 @ERROR BRK 
47
+|FFFA .RESET .FRAME .ERROR
... ...
@@ -2,10 +2,8 @@
2 2
 
3 3
 :dev/r fff8 ( std read port )
4 4
 :dev/w fff9 ( std write port )
5
-;width0
6
-;width1
7
-;height0
8
-;height1
5
+;width 2
6
+;height 2
9 7
 
10 8
 |0100 @RESET 
11 9
 	
... ...
@@ -13,14 +11,14 @@
13 11
 	,01 DUP ,dev/r STR ,dev/w STR 
14 12
 
15 13
 	( load screen size )
16
-	,00 IOR^ ,width0 STR^
17
-	,02 IOR^ ,height0 STR^
14
+	,00 IOR^ ,width STR^
15
+	,02 IOR^ ,height STR^
18 16
 
19 17
 	( draw pixel at screen center )
20 18
 
21 19
 	,0101 
22
-	,width0 LDR^ ,0002 DIV^ 
23
-	,height0 LDR^ ,0002 DIV^ 
20
+	,width LDR^ ,0002 DIV^ 
21
+	,height LDR^ ,0002 DIV^ 
24 22
 	,putpixel JSR
25 23
 
26 24
 BRK
... ...
@@ -3,34 +3,12 @@
3 3
 :dev/r fff8 ( std read port )
4 4
 :dev/w fff9 ( std write port )
5 5
 
6
-;i ;x0 ;x1 ;y0 ;y1
7
-
8 6
 |0100 @RESET 
9 7
 	
10 8
 	,01 ,dev/w STR ( set dev/write screen#01 ) 
11 9
 
12 10
 BRK
13 11
 
14
-|c000 @FRAME 
15
-	
16
-	,i LDR ,04 ADD ,i STR ( incr i )
17
-	,i LDR ,x1 STR ( set x )
18
-	,changerow JSR ( update y )
19
-	,01 ,02 ,x0 LDR^ ,y0 LDR^ ,putpixel JSR
20
-
21
-BRK
22
-
23
-@changerow
24
-	,i LDR ,00 NEQ RTS?
25
-	,y1 LDR ,04 ADD ,y1 STR
26
-	RTS
27
-
28
-@putpixel 
29
-	IOW^ ( y short )
30
-	IOW^ ( x short )
31
-	IOW ( color byte )
32
-	IOW ( redraw byte )
33
-	RTS
34
-
12
+|c000 @FRAME BRK
35 13
 |d000 @ERROR BRK 
36 14
 |FFFA .RESET .FRAME .ERROR
... ...
@@ -208,6 +208,6 @@ portuxn(Uxn *u, char *name, Uint8 (*rfn)(Device *, Uint8), Uint8 (*wfn)(Device *
208 208
 	d->read = rfn;
209 209
 	d->write = wfn;
210 210
 	d->len = 0;
211
-	printf("Device#%d: %s \n", u->devices, name);
211
+	printf("Device #%d: %s \n", u->devices - 1, name);
212 212
 	return d;
213 213
 }