(uxnasm) Improved errors

This commit is contained in:
neauoire 2021-11-29 08:48:12 -08:00
parent 58eacef7d4
commit 25df420607
1 changed files with 19 additions and 9 deletions

View File

@ -135,14 +135,16 @@ makemacro(char *name, FILE *f)
if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name)) if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
return error("Macro name is invalid", name); return error("Macro name is invalid", name);
if(p.mlen == 256) if(p.mlen == 256)
return error("Too many macros", name); return error("Macros limit exceeded", name);
m = &p.macros[p.mlen++]; m = &p.macros[p.mlen++];
scpy(name, m->name, 64); scpy(name, m->name, 64);
while(fscanf(f, "%63s", word) == 1) { while(fscanf(f, "%63s", word) == 1) {
if(word[0] == '{') continue; if(word[0] == '{') continue;
if(word[0] == '}') break; if(word[0] == '}') break;
if(m->len > 64) if(word[0] == '%')
return error("Macro too large", name); return error("Macro error", name);
if(m->len >= 64)
return error("Macro size exceeded", name);
scpy(word, m->items[m->len++], 64); scpy(word, m->items[m->len++], 64);
} }
return 1; return 1;
@ -159,7 +161,7 @@ makelabel(char *name)
if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name)) if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name))
return error("Label name is invalid", name); return error("Label name is invalid", name);
if(p.llen == 512) if(p.llen == 512)
return error("Too many labels", name); return error("Labels limit exceeded", name);
l = &p.labels[p.llen++]; l = &p.labels[p.llen++];
l->addr = p.ptr; l->addr = p.ptr;
l->refs = 0; l->refs = 0;
@ -173,7 +175,7 @@ makereference(char *scope, char *label, Uint16 addr)
char subw[64]; char subw[64];
Reference *r; Reference *r;
if(p.rlen == 2048) if(p.rlen == 2048)
return error("Too many references", label); return error("References limit exceeded", label);
r = &p.refs[p.rlen++]; r = &p.refs[p.rlen++];
if(label[1] == '&') if(label[1] == '&')
scpy(sublabel(subw, scope, label + 2), r->name, 64); scpy(sublabel(subw, scope, label + 2), r->name, 64);
@ -187,6 +189,8 @@ makereference(char *scope, char *label, Uint16 addr)
static void static void
writebyte(Uint8 b) writebyte(Uint8 b)
{ {
if(p.ptr < TRIM)
fprintf(stderr, "-- Writing in zero-page: %02x\n", b);
p.data[p.ptr++] = b; p.data[p.ptr++] = b;
p.length = p.ptr; p.length = p.ptr;
litlast = 0; litlast = 0;
@ -221,7 +225,7 @@ doinclude(const char *filename)
FILE *f; FILE *f;
char w[64]; char w[64];
if(!(f = fopen(filename, "r"))) if(!(f = fopen(filename, "r")))
return error("Include failed to open", filename); return error("Include missing", filename);
while(fscanf(f, "%63s", w) == 1) while(fscanf(f, "%63s", w) == 1)
if(!tokenize(w, f)) if(!tokenize(w, f))
return error("Unknown token", w); return error("Unknown token", w);
@ -390,8 +394,14 @@ review(char *filename)
if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z') if(p.labels[i].name[0] >= 'A' && p.labels[i].name[0] <= 'Z')
continue; /* Ignore capitalized labels(devices) */ continue; /* Ignore capitalized labels(devices) */
else if(!p.labels[i].refs) else if(!p.labels[i].refs)
fprintf(stderr, "--- Unused label: %s\n", p.labels[i].name); fprintf(stderr, "-- Unused label: %s\n", p.labels[i].name);
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); 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);
} }
int int
@ -401,7 +411,7 @@ main(int argc, char *argv[])
if(argc < 3) if(argc < 3)
return !error("usage", "input.tal output.rom"); return !error("usage", "input.tal output.rom");
if(!(src = fopen(argv[1], "r"))) if(!(src = fopen(argv[1], "r")))
return !error("Invalid Input", argv[1]); return !error("Invalid input", argv[1]);
if(!assemble(src)) if(!assemble(src))
return !error("Assembly", "Failed to assemble rom."); return !error("Assembly", "Failed to assemble rom.");
if(!(dst = fopen(argv[2], "wb"))) if(!(dst = fopen(argv[2], "wb")))