(uxnasm) Use save() to cat path

This commit is contained in:
Devine Lu Linvega 2024-03-28 10:47:46 -07:00
parent 4a028ed63b
commit 3dbdb19225
1 changed files with 11 additions and 13 deletions

View File

@ -52,6 +52,7 @@ static int scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i]) if
static int slen(char *s) { int i = 0; while(s[i]) i++; return i; } /* str length */ static int slen(char *s) { int i = 0; while(s[i]) i++; return i; } /* str length */
static char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* str copy */ static char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* str copy */
static char *scat(char *dst, char *src) { char *o = dst + slen(dst); while(*src) *o++ = *src++; *o = '\0'; return dst; } /* str concat */ static char *scat(char *dst, char *src) { char *o = dst + slen(dst); while(*src) *o++ = *src++; *o = '\0'; return dst; } /* str concat */
static char *save(char *s, char c) { char *o = dictnext; while((*dictnext++ = *s++) && *s); *dictnext++ = c; return o; }
#define isopcode(x) (findopcode(x) || scmp(x, "BRK", 4)) #define isopcode(x) (findopcode(x) || scmp(x, "BRK", 4))
#define isinvalid(x) (!slen(x) || sihx(x) || isopcode(x) || cndx(runes, x[0]) >= 0) #define isinvalid(x) (!slen(x) || sihx(x) || isopcode(x) || cndx(runes, x[0]) >= 0)
@ -69,18 +70,14 @@ static int parse(char *w, FILE *f, Context *ctx);
static char * static char *
push(char *s, char c) push(char *s, char c)
{ {
char *d = dict, *o = dictnext; char *d = dict;
/* find */ /* find */
for(d = dict; d < dictnext; d++) { for(d = dict; d < dictnext; d++) {
char *ss = s, *dd = d, a, b; char *ss = s, *dd = d, a, b;
while((a = *dd++) == (b = *ss++)) while((a = *dd++) == (b = *ss++))
if(!a && !b) return d; if(!a && !b) return d;
} }
/* save */ return save(s, c);
while((*dictnext++ = *s++) && *s)
;
*dictnext++ = c;
return o;
} }
static Item * static Item *
@ -379,28 +376,29 @@ resolve(void)
} }
static int static int
build(char *filename) build(char *rompath)
{ {
int i; int i;
FILE *dst, *dstsym; FILE *dst, *dstsym;
char sympath[0x60]; char *sympath;
/* rom */ /* rom */
if(!(dst = fopen(filename, "wb"))) if(!(dst = fopen(rompath, "wb")))
return !error_top("Invalid output file", filename); return !error_top("Invalid output file", rompath);
for(i = 0; i < label_len; i++) for(i = 0; i < label_len; i++)
if(labels[i].name[0] - 'A' > 25 && !labels[i].refs) if(labels[i].name[0] - 'A' > 25 && !labels[i].refs)
fprintf(stdout, "-- Unused label: %s\n", labels[i].name); fprintf(stdout, "-- Unused label: %s\n", labels[i].name);
fwrite(data + PAGE, length - PAGE, 1, dst); fwrite(data + PAGE, length - PAGE, 1, dst);
fprintf(stdout, fprintf(stdout,
"Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n", "Assembled %s in %d bytes(%.2f%% used), %d labels, %d macros.\n",
filename, rompath,
length - PAGE, length - PAGE,
(length - PAGE) / 652.80, (length - PAGE) / 652.80,
label_len, label_len,
macro_len); macro_len);
/* sym */ /* sym */
if(slen(filename) > 0x5b || !(dstsym = fopen(scat(scpy(filename, sympath, slen(filename) + 1), ".sym"), "w"))) sympath = dictnext, save(rompath, '.'), save("sym", 0);
return !error_top("Invalid symbols file", filename); if(!(dstsym = fopen(sympath, "w")))
return !error_top("Invalid symbols file", sympath);
for(i = 0; i < label_len; i++) { for(i = 0; i < label_len; i++) {
Uint8 hb = labels[i].addr >> 8, lb = labels[i].addr; Uint8 hb = labels[i].addr >> 8, lb = labels[i].addr;
fwrite(&hb, 1, 1, dstsym); fwrite(&hb, 1, 1, dstsym);