Browse code

(uxnasm) Cleanup

neauoire authored on 27/11/2021 22:07:25
Showing 1 changed files
... ...
@@ -14,10 +14,6 @@ WITH REGARD TO THIS SOFTWARE.
14 14
 #define TRIM 0x0100
15 15
 #define LENGTH 0x10000
16 16
 
17
-#define REFERENCES 2048
18
-#define LABELS 512
19
-#define MACROS 256
20
-
21 17
 typedef unsigned char Uint8;
22 18
 typedef signed char Sint8;
23 19
 typedef unsigned short Uint16;
... ...
@@ -40,9 +36,9 @@ typedef struct {
40 36
 typedef struct {
41 37
 	Uint8 data[LENGTH];
42 38
 	Uint16 ptr, length, llen, mlen, rlen;
43
-	Label labels[LABELS];
44
-	Macro macros[MACROS];
45
-	Reference refs[REFERENCES];
39
+	Label labels[512];
40
+	Macro macros[256];
41
+	Reference refs[2048];
46 42
 	char scope[64];
47 43
 } Program;
48 44
 
... ...
@@ -132,7 +128,7 @@ makemacro(char *name, FILE *f)
132 128
 		return error("Macro name is hex number", name);
133 129
 	if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
134 130
 		return error("Macro name is invalid", name);
135
-	if(p.mlen == MACROS)
131
+	if(p.mlen == 256)
136 132
 		return error("Too many macros", name);
137 133
 	m = &p.macros[p.mlen++];
138 134
 	scpy(name, m->name, 64);
... ...
@@ -156,7 +152,7 @@ makelabel(char *name)
156 152
 		return error("Label name is hex number", name);
157 153
 	if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
158 154
 		return error("Label name is invalid", name);
159
-	if(p.llen == LABELS)
155
+	if(p.llen == 512)
160 156
 		return error("Too many labels", name);
161 157
 	l = &p.labels[p.llen++];
162 158
 	l->addr = p.ptr;
... ...
@@ -165,20 +161,6 @@ makelabel(char *name)
165 161
 	return 1;
166 162
 }
167 163
 
168
-static int
169
-doinclude(const char *filename)
170
-{
171
-	FILE *f;
172
-	char w[64];
173
-	if(!(f = fopen(filename, "r")))
174
-		return error("Include failed to open", filename);
175
-	while(fscanf(f, "%63s", w) == 1)
176
-		if(!tokenize(w, f))
177
-			return error("Unknown token", w);
178
-	fclose(f);
179
-	return 1;
180
-}
181
-
182 164
 static void
183 165
 writebyte(Uint8 b, int lit)
184 166
 {
... ...
@@ -231,6 +213,20 @@ prefill(char *scope, char *label, Uint16 addr)
231 213
 	r->addr = addr;
232 214
 }
233 215
 
216
+static int
217
+doinclude(const char *filename)
218
+{
219
+	FILE *f;
220
+	char w[64];
221
+	if(!(f = fopen(filename, "r")))
222
+		return error("Include failed to open", filename);
223
+	while(fscanf(f, "%63s", w) == 1)
224
+		if(!tokenize(w, f))
225
+			return error("Unknown token", w);
226
+	fclose(f);
227
+	return 1;
228
+}
229
+
234 230
 static int
235 231
 tokenize(char *w, FILE *f)
236 232
 {
... ...
@@ -368,18 +364,6 @@ resolve(void)
368 364
 	return 1;
369 365
 }
370 366
 
371
-static void
372
-review(char *filename)
373
-{
374
-	int i;
375
-	for(i = 0; i < p.llen; ++i)
376
-		if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z')
377
-			continue; /* Ignore capitalized labels(devices) */
378
-		else if(!p.labels[i].refs)
379
-			fprintf(stderr, "--- Unused label: %s\n", p.labels[i].name);
380
-	fprintf(stderr, "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", filename, p.length - TRIM, p.length / 652.80, p.llen, p.mlen);
381
-}
382
-
383 367
 static int
384 368
 assemble(FILE *f)
385 369
 {
... ...
@@ -392,6 +376,18 @@ assemble(FILE *f)
392 376
 	return 1;
393 377
 }
394 378
 
379
+static void
380
+review(char *filename)
381
+{
382
+	int i;
383
+	for(i = 0; i < p.llen; ++i)
384
+		if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z')
385
+			continue; /* Ignore capitalized labels(devices) */
386
+		else if(!p.labels[i].refs)
387
+			fprintf(stderr, "--- Unused label: %s\n", p.labels[i].name);
388
+	fprintf(stderr, "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", filename, p.length - TRIM, p.length / 652.80, p.llen, p.mlen);
389
+}
390
+
395 391
 int
396 392
 main(int argc, char *argv[])
397 393
 {