Browse code

Removed addr ptr moves to assmbler

neauoire authored on 01/03/2021 17:38:54
Showing 6 changed files
... ...
@@ -37,8 +37,6 @@ evaluxn(u, u->vframe); /* Each frame
37 37
 - `=label`, helper to STR, equivalent to `,label STR`, or `label STR2`.
38 38
 - `~label`, helper to LDR, equivalent to `,label LDR2`, or `,label LDR2`.
39 39
 - `|0010`, move to position in the program.
40
-- `<23`, move the program position `23` bytes backward.
41
-- `>12`, move the program position `12` bytes forward.
42 40
 - `( comment )`, toggle parsing on/off.
43 41
 - `[ 0123 abcd ]`, write shorts to memory.
44 42
 - `[ Hello World ]`, write text to memory.
... ...
@@ -53,33 +51,35 @@ evaluxn(u, u->vframe); /* Each frame
53 51
 ```
54 52
 ( hello world )
55 53
 
56
-&Console { pad 8 stdio 1 }
54
+&Console { pad 8 char 1 byte 1 }
57 55
 
58 56
 |0100 @RESET 
59 57
 	
60
-	,text1 ,print-label JSR ( print to console )
58
+	,text1 ,print-label JSR
59
+	,text2 ,print-label JSR
61 60
 
62 61
 BRK
63 62
 
64 63
 @print-label ( text )
65 64
 
66 65
 	@cliloop
67
-		DUP2 LDR =dev/console.stdio              ( write pointer value to console )
66
+		DUP2 LDR =dev/console.char               ( write pointer value to console )
68 67
 		#0001 ADD2                               ( increment string pointer )
69 68
 		DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2  ( while *ptr!=0 goto loop )
70 69
 	POP2
71
-		
70
+
72 71
 RTS                 
73 72
 
74
-@text1 [ Hello World ] <1 .00 ( add text to memory, return 1 byte, add null byte )
73
+@text1 [ Hello World 0a00 ] ( store text with a linebreak and null byte )
74
+@text2 [ Welcome to UxnVM 0a00 ]
75 75
 
76 76
 |c000 @FRAME
77 77
 |d000 @ERROR 
78 78
 
79 79
 |FF00 ;dev/console Console
80 80
 
81
-|FFF0 .RESET .FRAME .ERROR
82
-|FFF8 [ f3f0 f30b f30a ] ( palette )
81
+|FFF0 .RESET .FRAME .ERROR ( vectors )
82
+|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )
83 83
 ```
84 84
 
85 85
 ## Emulator
... ...
@@ -280,7 +280,10 @@ pass1(FILE *f)
280 280
 		if(skipblock(w, &cbits, '[', ']')) {
281 281
 			if(w[0] == '[' || w[0] == ']')
282 282
 				continue;
283
-			addr += sihx(w) ? 2 : slen(w) + 1;
283
+			if(sihx(w))
284
+				addr += slen(w) == 4 ? 2 : 1;
285
+			else
286
+				addr += slen(w) + 1;
284 287
 		} else if(w[0] == '@') {
285 288
 			if(!makelabel(w + 1, addr, 0, NULL))
286 289
 				return error("Pass1 failed", w);
... ...
@@ -302,8 +305,6 @@ pass1(FILE *f)
302 305
 					return error("Memory Overlap", w);
303 306
 				addr = shex(w + 1);
304 307
 				break;
305
-			case '<': addr -= shex(w + 1); break;
306
-			case '>': addr += shex(w + 1); break;
307 308
 			case '=': addr += 4; break; /* STR helper (lit addr-hb addr-lb str) */
308 309
 			case '~': addr += 4; break; /* LDR helper (lit addr-hb addr-lb ldr) */
309 310
 			case ',': addr += 3; break;
... ...
@@ -335,11 +336,11 @@ pass2(FILE *f)
335 336
 		/* clang-format off */
336 337
 		if(skipblock(w, &cbits, '[', ']')) {
337 338
 			if(w[0] == '[' || w[0] == ']') { continue; }
338
-			if(slen(w) == 4 && sihx(w)) pushshort(shex(w), 0); else pushtext(w, 0);
339
+			if(slen(w) == 4 && sihx(w)) pushshort(shex(w), 0); 
340
+			else if(slen(w) == 2 && sihx(w)) pushbyte(shex(w), 0); 
341
+			else pushtext(w, 0);
339 342
 		}
340 343
 		else if(w[0] == '|') p.ptr = shex(w + 1);
341
-		else if(w[0] == '<') p.ptr -= shex(w + 1);
342
-		else if(w[0] == '>') p.ptr += shex(w + 1);
343 344
 		else if((op = findopcode(w)) || scmp(w, "BRK", 4)) pushbyte(op, 0);
344 345
 		else if(w[0] == ':') fscanf(f, "%s", w);
345 346
 		else if(w[0] == ';') fscanf(f, "%s", w);
... ...
@@ -332,7 +332,7 @@ console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
332 332
 	switch(b0) {
333 333
 	case 0x08: printf("%c", b1); break;
334 334
 	case 0x09: printf("%02x", b1); break;
335
-	case 0x0a: printf("%d", b1); break;
335
+	case 0x0b: printf("%04x", (m[ptr + 0x0a] << 8) + b1); break;
336 336
 	}
337 337
 	fflush(stdout);
338 338
 	(void)m;
... ...
@@ -377,6 +377,8 @@ Uint8
377 377
 system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)
378 378
 {
379 379
 	loadtheme(&m[0xfff8]);
380
+	(void)ptr;
381
+	(void)b0;
380 382
 	return b1;
381 383
 }
382 384
 
... ...
@@ -1,10 +1,13 @@
1 1
 ( hello world )
2 2
 
3
-&Console { pad 8 char 1 byte 1 }
3
+&Console { pad 8 char 1 byte 1 short 2 }
4 4
 
5 5
 |0100 @RESET 
6 6
 	
7
-	,text1 ,print-label JSR ( print to console )
7
+	,text1 ,print-label JSR
8
+	,text2 ,print-label JSR
9
+	#ab =dev/console.byte
10
+	#cdef =dev/console.short
8 11
 
9 12
 BRK
10 13
 
... ...
@@ -18,7 +21,8 @@ BRK
18 21
 
19 22
 RTS                 
20 23
 
21
-@text1 [ Hello World ] <1 .00 ( add text to memory, return 1 byte, add null byte )
24
+@text1 [ Hello World 0a00 ] ( store text with a linebreak and null byte )
25
+@text2 [ Welcome to UxnVM 0a00 ]
22 26
 
23 27
 |c000 @FRAME
24 28
 |d000 @ERROR 
... ...
@@ -213,10 +213,10 @@ RTS
213 213
 	0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
214 214
 ]
215 215
 
216
-@mouse0_text   [ no click ] <1 .00
217
-@mouse1_text   [ mouse 1_ ] <1 .00
218
-@mouse2_text   [ mouse _2 ] <1 .00
219
-@mouse12_text  [ mouse 12 ] <1 .00
216
+@mouse0_text   [ no click 00 ]
217
+@mouse1_text   [ mouse 1_ 00 ]
218
+@mouse2_text   [ mouse _2 00 ]
219
+@mouse12_text  [ mouse 12 00 ]
220 220
 
221 221
 |d000 @ERROR BRK 
222 222
 
... ...
@@ -140,7 +140,7 @@ RTS
140 140
 	0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c
141 141
 ]
142 142
 
143
-@text [ Label Text ] <1 .00 ( add characters to memory )
143
+@text [ Label Text 00 ] ( add characters to memory )
144 144
 
145 145
 |c000 @FRAME BRK 
146 146
 |d000 @ERROR BRK