commit b8c0af8
zzo38
·
2022-12-25 01:06:30 +0000 UTC
parent df57a72
Add \- and \= commands into assembler for making inline graphical tiles.
M
asm.doc
+6,
-0
1@@ -111,6 +111,12 @@ The following nonstandard tokens are available:
2 about special calculations. These are executed immediately at compile
3 time, before the compiled program is written to the output file.
4
5+ \- or \= followed by eight more characters and optionally ; will make
6+ a graphical tile; you should have eight such commands per tile, and
7+ a semicolon at the end of the last one. Use \- for 1bpp tiles and \=
8+ for 2bpp tiles. The colour codes are . or 0 for the background colour,
9+ and numbers 1 2 3 for the other colours.
10+
11 [@ makes a anonymous label; the matching ] command will reference the
12 same anonymous label as this one. (Nesting is allowed.)
13
M
uxnasm.c
+29,
-0
1@@ -328,6 +328,34 @@ static int special_calc(const char*w) {
2 return 1;
3 }
4
5+static int make_tile(int h,const char*w) {
6+ int i,c,v0,v1;
7+ v0=v1=0;
8+ for(i=0;i<8;i++) {
9+ switch(w[i]) {
10+ case '0': case '.': c=0; break;
11+ case '1': case '#': c=1; break;
12+ case '2': case 'X': c=2; break;
13+ case '3': case '*': c=3; break;
14+ default: return 0;
15+ }
16+ if(c>1 && !h) return 0;
17+ if(c&1) v0|=0x80>>i;
18+ if(c&2) v1|=0x80>>i;
19+ }
20+ if(p.ptr>0xFFF7) return error("Writing after the end of RAM","");
21+ p.data[p.ptr]=v0;
22+ if(h) p.data[p.ptr+8]=v1;
23+ p.ptr++;
24+ if(w[8]==';') {
25+ if(h) p.ptr+=8;
26+ } else if(w[8]) {
27+ return 0;
28+ }
29+ if(p.length<p.ptr) p.length=p.ptr;
30+ return 1;
31+}
32+
33 static int
34 parse(char *w, FILE *f)
35 {
36@@ -440,6 +468,7 @@ parse(char *w, FILE *f)
37 p.ptr=i;
38 break;
39 case '_': if(!special_calc(w+2)) return error("Special calculation error",w); break;
40+ case '-': case '=': if(!make_tile(w[1]=='=',w+2)) return error("Tile error",w); break;
41 default: return error("Invalid special",w);
42 }
43 break;