Browse code

Working example for dev.control

neauoire authored on 20/04/2021 04:33:52
Showing 3 changed files
... ...
@@ -18,26 +18,19 @@ contexts:
18 18
     - match: '\|(\S+)\s?'
19 19
       scope: variable.control
20 20
       pop: true
21
-    # variables
22
-    - match: '\;(\S+)\s?'
23
-      scope: string.control
21
+    - match: '\$(\S+)\s?'
22
+      scope: variable.control
24 23
       pop: true
25 24
     # constants
26 25
     - match: '\:(\S+)\s?'
27 26
       scope: string.control
28 27
       pop: true
29 28
     # structs
30
-    - match: '\&(\S+)\s?'
31
-      scope: string.control
32
-      pop: true
33
-    - match: '\$(\S+)\s?'
34
-      scope: string.control
35
-      pop: true
36 29
 
37 30
     # Special
38 31
 
39
-    - match: '\~(\S+)\s?'
40
-      scope: entity.name.type
32
+    - match: '\&(\S+)\s?'
33
+      scope: string.control
41 34
       pop: true
42 35
     - match: '\=(\S+)\s?'
43 36
       scope: entity.name.type
... ...
@@ -45,19 +38,26 @@ contexts:
45 38
 
46 39
     # Pushing to stack
47 40
 
48
-    - match: '\,(\S+)\s?'
41
+    - match: '\^(\S+)\s?'
49 42
       scope: keyword.control
50 43
       pop: true
51
-    - match: '\.(\S+)\s?'
44
+    - match: '\#(\S+)\s?'
52 45
       scope: keyword.control
53 46
       pop: true
54
-    - match: '\^(\S+)\s?'
55
-      scope: keyword.control
47
+    
48
+
49
+    # Addressing
50
+    - match: '\.(\S+)\s?'     # zero-page
51
+      scope: variable.control
56 52
       pop: true
57
-    - match: '\#(\S+)\s?'
53
+    - match: '\,(\S+)\s?'     # relative
54
+      scope: entity.name.type
55
+      pop: true
56
+    - match: '\;(\S+)\s?'     # absolute
58 57
       scope: keyword.control
59 58
       pop: true
60 59
 
60
+
61 61
       # Blocks
62 62
 
63 63
     - match: '\{'
... ...
@@ -1,119 +1,78 @@
1 1
 ( Dev/Controller )
2 2
 
3
-%++ { #0001 ADD2 }
4
-%-- { #0001 SUB2 }
3
+%++ { #0001 ADD2 } %-- { #0001 SUB2 }
5 4
 %2/ { #0002 DIV2 }
6 5
 
7 6
 ( variables )
8 7
 
9
-@slime [
10
-	&color 00
11
-	&end
12
-]
8
+@slime $1
13 9
 
14 10
 ( devices )
15 11
 
16
-|0100 @System [
17
-	&vector 0000 
18
-	&pad    0000 
19
-			0000 
20
-			0000
21
-	&r      0daf 
22
-	&g      02ff 
23
-	&b      035f 
24
-	&end    
25
-]
26
-
27
-|0110 @Console [
28
-	&pad    0000
29
-			0000
30
-			0000
31
-			0000
32
-	&char   00 
33
-	&byte   00 
34
-	&short  0000 
35
-	&string 0000
36
-	&end
37
-]
38
-
39
-|0120 @Screen [
40
-	&vector 0000 
41
-	&width  0000 
42
-	&height 0000 
43
-	&pad    0000 
44
-	&x      0000 
45
-	&y      0000 
46
-	&addr   0000 
47
-	&color  00 
48
-	&end    
49
-]
50
-
51
-|0140 @Controller [
52
-	&vector 0000 
53
-	&button 00 
54
-	&key    00 
55
-	&end    
56
-]
12
+|0100 @System     &vector $2 &pad    $6 &r      $2 &g     $2 &b      $2
13
+|0110 @Console    &pad    $8 &char   $1 &byte   $1 &short $2 &string $2
14
+|0120 @Screen     &vector $2 &width  $2 &height $2 &pad   $2 &x      $2 &y $2 &addr $2 &color $1 
15
+|0140 @Controller &vector $2 &button $1 &key    $1
57 16
 
58 17
 |0200
59 18
 	
60 19
 	( theme ) 
61
-	#0daf ,System/r STR2 
62
-	#02ff ,System/g STR2 
63
-	#035f ,System/b STR2
20
+	#0daf ;System/r STR2 
21
+	#02ff ;System/g STR2 
22
+	#035f ;System/b STR2
64 23
 
65 24
 	( vectors ) 
66
-	,on-frame ,Screen/vector STR2
25
+	;on-frame ;Screen/vector STR2
67 26
 	
68 27
 	( set origin )
69
-	,Screen/width LDR2 2/ ,Screen/x STR2
70
-	,Screen/height LDR2 2/ ,Screen/y STR2
71
-	,default_icn ,Screen/addr STR2
72
-	#31 ,Screen/color POK2
73
-	#2a ,slime/color POK2
28
+	;Screen/width LDR2 2/ ;Screen/x STR2
29
+	;Screen/height LDR2 2/ ;Screen/y STR2
30
+	;default_icn ;Screen/addr STR2
31
+	#31 ;Screen/color POK2
32
+	#2a .slime POK
74 33
 
75 34
 BRK
76 35
 
77 36
 @on-frame
78 37
 
79
-	#2a ,slime/color POK2
80
-	,default_icn ,Screen/addr STR2
38
+	#2a .slime POK
39
+	;default_icn ;Screen/addr STR2
81 40
 
82 41
 	( hold ctrl key to change slime color )
83 42
 
84
-	,Controller/button PEK2 #0f AND
85
-		DUP #01 NEQ ^&no-ctrl JNZ #25 ,slime/color POK2 &no-ctrl
86
-		DUP #02 NEQ ^&no-alt JNZ #2f ,slime/color POK2 &no-alt
43
+	;Controller/button PEK2 #0f AND
44
+		DUP #01 NEQ ,&no-ctrl JNZ #25 .slime POK &no-ctrl
45
+		DUP #02 NEQ ,&no-alt JNZ #2f .slime POK &no-alt
87 46
 	POP
88 47
 
89
-	( clear ) #30 ,Screen/color POK2
48
+	( clear ) #30 ;Screen/color POK2
90 49
 
91 50
 	( detect movement )
92
-	,Controller/button PEK2 #f0 AND
93
-		DUP #04 SFT #01 AND #01 NEQ ^&no-up JNZ 
51
+	;Controller/button PEK2 #f0 AND
52
+		DUP #04 SFT #01 AND #01 NEQ ,&no-up JNZ 
94 53
 			( move ) 
95
-			,Screen/y LDR2 -- ,Screen/y STR2 
96
-			,up_icn ,Screen/addr STR2 &no-up
97
-		DUP #05 SFT #01 AND #01 NEQ ^&no-down JNZ 
54
+			;Screen/y LDR2 -- ;Screen/y STR2 
55
+			;up_icn ;Screen/addr STR2 &no-up
56
+		DUP #05 SFT #01 AND #01 NEQ ,&no-down JNZ 
98 57
 			( move ) 
99
-			,Screen/y LDR2 ++ ,Screen/y STR2 
100
-			,down_icn ,Screen/addr STR2 &no-down
101
-		DUP #06 SFT #01 AND #01 NEQ ^&no-left JNZ 
58
+			;Screen/y LDR2 ++ ;Screen/y STR2 
59
+			;down_icn ;Screen/addr STR2 &no-down
60
+		DUP #06 SFT #01 AND #01 NEQ ,&no-left JNZ 
102 61
 			( move ) 
103
-			,Screen/x LDR2 -- ,Screen/x STR2 
104
-			,left_icn ,Screen/addr STR2 &no-left
105
-		DUP #07 SFT #01 AND #01 NEQ ^&no-right JNZ 
62
+			;Screen/x LDR2 -- ;Screen/x STR2 
63
+			;left_icn ;Screen/addr STR2 &no-left
64
+		DUP #07 SFT #01 AND #01 NEQ ,&no-right JNZ 
106 65
 			( move ) 
107
-			,Screen/x LDR2 ++ ,Screen/x STR2 
108
-			,right_icn ,Screen/addr STR2 &no-right
66
+			;Screen/x LDR2 ++ ;Screen/x STR2 
67
+			;right_icn ;Screen/addr STR2 &no-right
109 68
 	POP
110 69
 
111 70
 	( draw face )
112
-	#31 ,Screen/color POK2
71
+	#31 ;Screen/color POK2
113 72
 
114 73
 	( draw slime )
115
-	,slime_icn ,Screen/addr STR2
116
-	,slime/color PEK2 ,Screen/color POK2
74
+	;slime_icn ;Screen/addr STR2
75
+	.slime PEK ;Screen/color POK2
117 76
 
118 77
 BRK
119 78
 
... ...
@@ -210,9 +210,9 @@ walktoken(char *w)
210 210
 	if(findopcode(w) || scmp(w, "BRK", 4))
211 211
 		return 1;
212 212
 	switch(w[0]) {
213
-	case ',': return 3; /* lit2 addr-hb addr-lb */
214
-	case '.': return 2; /* addr-hb addr-lb */
215
-	case '^': return 2; /* Relative jump: lit addr-offset */
213
+	case '.': return 2; /* zero-page: LIT addr-lb */
214
+	case ';': return 3; /* absolute: LIT addr-hb addr-lb */
215
+	case ',': return 2; /* Relative jump: lit addr-offset */
216 216
 	case '#': return (slen(w + 1) == 4 ? 3 : 2);
217 217
 	}
218 218
 	if((m = findmacro(w))) {
... ...
@@ -231,18 +231,16 @@ parsetoken(char *w)
231 231
 	Label *l;
232 232
 	Macro *m;
233 233
 
234
-	if(w[0] == '^' && (l = findlabel(w + 1))) {
235
-		int off = l->addr - p.ptr - 3;
236
-		if(off < -126 || off > 126) {
237
-			printf("Address %s is too far(%d).\n", w, off);
238
-			return 0;
239
-		}
240
-		pushbyte((Sint8)(l->addr - p.ptr - 3), 1);
241
-		return ++l->refs;
242
-	} else if(w[0] == '.' && (l = findlabel(w + 1))) {
243
-		pushshort(l->addr, 0);
234
+	if(w[0] == '.' && (l = findlabel(w + 1))) { /* zero-page */
235
+		pushbyte(l->addr, 1);
244 236
 		return ++l->refs;
245 237
 	} else if(w[0] == ',' && (l = findlabel(w + 1))) {
238
+		int off = l->addr - p.ptr - 3;
239
+		if(off < -126 || off > 126)
240
+			return error("Address is too far", w);
241
+		pushbyte((Sint8)off, 1);
242
+		return ++l->refs;
243
+	} else if(w[0] == ';' && (l = findlabel(w + 1))) { /* absolute */
246 244
 		pushshort(l->addr, 1);
247 245
 		return ++l->refs;
248 246
 	} else if((op = findopcode(w)) || scmp(w, "BRK", 4)) {
... ...
@@ -302,7 +300,9 @@ pass1(FILE *f)
302 300
 			if(shex(w + 1) < addr)
303 301
 				return error("Memory Overwrite", w);
304 302
 			addr = shex(w + 1);
305
-		} else
303
+		} else if(w[0] == '$')
304
+			addr += shex(w + 1);
305
+		else
306 306
 			addr += walktoken(w);
307 307
 	}
308 308
 	rewind(f);
... ...
@@ -324,7 +324,11 @@ pass2(FILE *f)
324 324
 			p.ptr = shex(w + 1);
325 325
 			continue;
326 326
 		}
327
-		if(w[0] == '@') {
327
+		else if(w[0] == '$') {
328
+			p.ptr += shex(w + 1);
329
+			continue;
330
+		}
331
+		else if(w[0] == '@') {
328 332
 			scpy(w + 1, scope, 64);
329 333
 			continue;
330 334
 		}