commit c9189ad

zzo38  ·  2022-11-15 03:08:53 +0000 UTC
parent 910af7f
Add the standard - and _ signs like the nonstandard \. and \, signs.
2 files changed,  +30, -2
+8, -2
 1@@ -70,7 +70,11 @@ The following standard tokens are available:
 2  specified name.
 3 
 4  : and a name will write the 16-bit address of the specified name directly,
 5- without any opcode.
 6+ without any opcode. (It is like ; but excluding the LIT2 instruction.)
 7+
 8+ - and a name is like . but without the LIT opcode.
 9+
10+ _ and a name is like , but without the LIT opcode.
11 
12  " and any characters (other than whitespaces) will emit that sequence of
13  characters without any opcodes or delimiters. (If you need spaces, then
14@@ -87,7 +91,9 @@ The following nonstandard tokens are available:
15 
16  \~ and a file name will include the contents of the binary file.
17 
18- \. or \, is like . or , but excluding the LIT instruction.
19+ \. or \, is like . or , but excluding the LIT instruction. (These are
20+ like - and _ but are nonstandard; they were added before the - and _
21+ signs were made standard.)
22 
23  \ and a number pushes the number to the special stack (which is a stack
24  which exists only at compile-time).
+22, -0
 1@@ -394,6 +394,14 @@ parse(char *w, FILE *f)
 2 		makereference(p.scope, w, p.ptr);
 3 		if(!writeshort(0xffff, 0)) return 0;
 4 		break;
 5+	case '-': /* raw byte zero-page */
 6+		makereference(p.scope, w, p.ptr);
 7+		if(!writebyte(0xff)) return 0;
 8+		break;
 9+	case '_': /* raw byte relative */
10+		makereference(p.scope, w, p.ptr);
11+		if(!writebyte(0xff)) return 0;
12+		break;
13 	case '"': /* raw string */
14 		i = 0;
15 		while((c = w[++i]))
16@@ -478,6 +486,14 @@ resolve(void)
17 	for(i = 0; i < p.rlen; i++) {
18 		Reference *r = &p.refs[i];
19 		switch(r->rune) {
20+		case '_':
21+			if(!(l = findlabel(r->name)))
22+				return error("Unknown relative reference", r->name);
23+			p.data[r->addr] = (Sint8)(l->addr - r->addr - 2);
24+			if((Sint8)p.data[r->addr] != (l->addr - r->addr - 2))
25+				return error("Relative reference is too far", r->name);
26+			l->refs++;
27+			break;
28 		case '.':
29 			if(!(l = findlabel(r->name)))
30 				return error("Unknown zero-page reference", r->name);
31@@ -492,6 +508,12 @@ resolve(void)
32 				return error("Relative reference is too far", r->name);
33 			l->refs++;
34 			break;
35+		case '-':
36+			if(!(l = findlabel(r->name)))
37+				return error("Unknown absolute reference", r->name);
38+			p.data[r->addr] = l->addr & 0xff;
39+			l->refs++;
40+			break;
41 		case ';':
42 			if(!(l = findlabel(r->name)))
43 				return error("Unknown absolute reference", r->name);