Browse code

Raised label limit in uxnasm

neauoire authored on 11/04/2022 22:34:53
Showing 1 changed files
... ...
@@ -19,17 +19,17 @@ typedef signed char Sint8;
19 19
 typedef unsigned short Uint16;
20 20
 
21 21
 typedef struct {
22
-	char name[64], items[64][64];
22
+	char name[0x40], items[0x40][0x40];
23 23
 	Uint8 len;
24 24
 } Macro;
25 25
 
26 26
 typedef struct {
27
-	char name[64];
27
+	char name[0x40];
28 28
 	Uint16 addr, refs;
29 29
 } Label;
30 30
 
31 31
 typedef struct {
32
-	char name[64], rune;
32
+	char name[0x40], rune;
33 33
 	Uint16 addr;
34 34
 } Reference;
35 35
 
... ...
@@ -37,10 +37,10 @@ typedef struct {
37 37
 	Uint8 data[LENGTH];
38 38
 	unsigned int ptr, length;
39 39
 	Uint16 llen, mlen, rlen;
40
-	Label labels[512];
41
-	Macro macros[256];
42
-	Reference refs[2048];
43
-	char scope[64];
40
+	Label labels[0x400];
41
+	Macro macros[0x100];
42
+	Reference refs[0x800];
43
+	char scope[0x40];
44 44
 } Program;
45 45
 
46 46
 Program p;
... ...
@@ -54,6 +54,8 @@ static char ops[][4] = {
54 54
 	"LDZ", "STZ", "LDR", "STR", "LDA", "STA", "DEI", "DEO",
55 55
 	"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"
56 56
 };
57
+static char sym_glyph[] = {'?', '!', '>', '<', '+', '-', '*', '/'};
58
+static Uint8 sym_value[] = {0x08, 0x09, 0x0a, 0x1b, 0x18, 0x19, 0x1a, 0x1b};
57 59
 
58 60
 static int   scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if(!a[i] || ++i >= len) return 1; return 0; } /* string compare */
59 61
 static int   sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */
... ...
@@ -76,7 +78,7 @@ error(const char *name, const char *msg)
76 78
 static char *
77 79
 sublabel(char *src, char *scope, char *name)
78 80
 {
79
-	return scat(scat(scpy(scope, src, 64), "/"), name);
81
+	return scat(scat(scpy(scope, src, 0x40), "/"), name);
80 82
 }
81 83
 
82 84
 static Macro *
... ...
@@ -84,7 +86,7 @@ findmacro(char *name)
84 86
 {
85 87
 	int i;
86 88
 	for(i = 0; i < p.mlen; i++)
87
-		if(scmp(p.macros[i].name, name, 64))
89
+		if(scmp(p.macros[i].name, name, 0x40))
88 90
 			return &p.macros[i];
89 91
 	return NULL;
90 92
 }
... ...
@@ -94,7 +96,7 @@ findlabel(char *name)
94 96
 {
95 97
 	int i;
96 98
 	for(i = 0; i < p.llen; i++)
97
-		if(scmp(p.labels[i].name, name, 64))
99
+		if(scmp(p.labels[i].name, name, 0x40))
98 100
 			return &p.labels[i];
99 101
 	return NULL;
100 102
 }
... ...
@@ -128,25 +130,25 @@ static int
128 130
 makemacro(char *name, FILE *f)
129 131
 {
130 132
 	Macro *m;
131
-	char word[64];
133
+	char word[0x40];
132 134
 	if(findmacro(name))
133 135
 		return error("Macro duplicate", name);
134 136
 	if(sihx(name) && slen(name) % 2 == 0)
135 137
 		return error("Macro name is hex number", name);
136 138
 	if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
137 139
 		return error("Macro name is invalid", name);
138
-	if(p.mlen == 256)
140
+	if(p.mlen == 0x100)
139 141
 		return error("Macros limit exceeded", name);
140 142
 	m = &p.macros[p.mlen++];
141
-	scpy(name, m->name, 64);
143
+	scpy(name, m->name, 0x40);
142 144
 	while(fscanf(f, "%63s", word) == 1) {
143 145
 		if(word[0] == '{') continue;
144 146
 		if(word[0] == '}') break;
145 147
 		if(word[0] == '%')
146 148
 			return error("Macro error", name);
147
-		if(m->len >= 64)
149
+		if(m->len >= 0x40)
148 150
 			return error("Macro size exceeded", name);
149
-		scpy(word, m->items[m->len++], 64);
151
+		scpy(word, m->items[m->len++], 0x40);
150 152
 	}
151 153
 	return 1;
152 154
 }
... ...
@@ -161,27 +163,27 @@ makelabel(char *name)
161 163
 		return error("Label name is hex number", name);
162 164
 	if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
163 165
 		return error("Label name is invalid", name);
164
-	if(p.llen == 512)
166
+	if(p.llen == 0x400)
165 167
 		return error("Labels limit exceeded", name);
166 168
 	l = &p.labels[p.llen++];
167 169
 	l->addr = p.ptr;
168 170
 	l->refs = 0;
169
-	scpy(name, l->name, 64);
171
+	scpy(name, l->name, 0x40);
170 172
 	return 1;
171 173
 }
172 174
 
173 175
 static int
174 176
 makereference(char *scope, char *label, Uint16 addr)
175 177
 {
176
-	char subw[64];
178
+	char subw[0x40];
177 179
 	Reference *r;
178
-	if(p.rlen == 2048)
180
+	if(p.rlen == 0x800)
179 181
 		return error("References limit exceeded", label);
180 182
 	r = &p.refs[p.rlen++];
181 183
 	if(label[1] == '&')
182
-		scpy(sublabel(subw, scope, label + 2), r->name, 64);
184
+		scpy(sublabel(subw, scope, label + 2), r->name, 0x40);
183 185
 	else
184
-		scpy(label + 1, r->name, 64);
186
+		scpy(label + 1, r->name, 0x40);
185 187
 	r->rune = label[0];
186 188
 	r->addr = addr;
187 189
 	return 1;
... ...
@@ -190,16 +192,12 @@ makereference(char *scope, char *label, Uint16 addr)
190 192
 static int
191 193
 writebyte(Uint8 b)
192 194
 {
193
-	if(p.ptr < TRIM) {
194
-		fprintf(stderr, "-- Writing in zero-page: %02x\n", b);
195
-		return 0;
196
-	} else if(p.ptr > 0xffff) {
197
-		fprintf(stderr, "-- Writing after the end of RAM: %02x\n", b);
198
-		return 0;
199
-	} else if(p.ptr < p.length) {
200
-		fprintf(stderr, "-- Memory overwrite: %04x -> %04x\n", p.length, p.ptr);
201
-		return 0;
202
-	}
195
+	if(p.ptr < TRIM)
196
+		return error("Writing in zero-page", "");
197
+	else if(p.ptr > 0xffff)
198
+		return error("Writing after the end of RAM", "");
199
+	else if(p.ptr < p.length)
200
+		return error("Memory overwrite", "");
203 201
 	p.data[p.ptr++] = b;
204 202
 	p.length = p.ptr;
205 203
 	litlast = 0;
... ...
@@ -233,7 +231,7 @@ static int
233 231
 doinclude(const char *filename)
234 232
 {
235 233
 	FILE *f;
236
-	char w[64];
234
+	char w[0x40];
237 235
 	if(!(f = fopen(filename, "r")))
238 236
 		return error("Include missing", filename);
239 237
 	while(fscanf(f, "%63s", w) == 1)
... ...
@@ -247,7 +245,7 @@ static int
247 245
 parse(char *w, FILE *f)
248 246
 {
249 247
 	int i;
250
-	char word[64], subw[64], c;
248
+	char word[0x40], subw[0x40], c;
251 249
 	Macro *m;
252 250
 	if(slen(w) >= 63)
253 251
 		return error("Invalid token", w);
... ...
@@ -287,7 +285,7 @@ parse(char *w, FILE *f)
287 285
 	case '@': /* label */
288 286
 		if(!makelabel(w + 1))
289 287
 			return error("Invalid label", w);
290
-		scpy(w + 1, p.scope, 64);
288
+		scpy(w + 1, p.scope, 0x40);
291 289
 		litlast = 0;
292 290
 		break;
293 291
 	case '&': /* sublabel */
... ...
@@ -401,8 +399,8 @@ resolve(void)
401 399
 static int
402 400
 assemble(FILE *f)
403 401
 {
404
-	char w[64];
405
-	scpy("on-reset", p.scope, 64);
402
+	char w[0x40];
403
+	scpy("on-reset", p.scope, 0x40);
406 404
 	while(fscanf(f, "%63s", w) == 1)
407 405
 		if(!parse(w, f))
408 406
 			return error("Unknown token", w);