From 691ae45b3916379b0b1d845a5581d9068426b134 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 18 May 2020 20:56:45 -0400 Subject: Fixed some more bugs in the assembler. --- asmmon.c | 40 +++++----------------------------------- asmmon.h | 1 + lexer.c | 7 +++++-- programs/subasm-2.s | 2 ++ 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/asmmon.c b/asmmon.c index dcffb67..81e4b28 100644 --- a/asmmon.c +++ b/asmmon.c @@ -487,9 +487,6 @@ void assemble(struct line *line, bytecount *bc, uint8_t dbg) { tmp+=2; bc->datasize+=2; break; - case DIR_INCLUDE: - incl[inc_file++] = line[i].incl; - break; } tmpaddr += tmp; tmp = 0; @@ -768,21 +765,13 @@ int asmmon(const char *fn) { } i++; } - if (!isinclude) { - list(tokline, start, end, isstart, islinenum, isaddr, isdebug); - } else { - list(tln, start, end, isstart, islinenum, isaddr, isdebug); - } + list(tokline, start, end, isstart, islinenum, isaddr, isdebug); } else { - if (!isinclude) { - list(tokline, 0, 0, 1, 0, 0, 0); - } else { - list(tln, 0, 0, 1, 0, 0, 0); - } + list(tokline, 0, 0, 1, 0, 0, 0); } break; case 0x08: - if (!isinclude) { + if (!inc_file) { printf("Assembling %s\n", (strcasecmp(fn, "stdin")) ? fn : "typed in program."); assemble(tokline, &bc, dbg); progsize = bc.progsize; @@ -791,26 +780,13 @@ int asmmon(const char *fn) { printf("%"PRIu64"/$%"PRIX64" bytes of program code.\n", progsize, progsize); printf("%"PRIu64"/$%"PRIX64" bytes of data.\n", datasize, datasize); putchar('\n'); - } else { - printf("Assembling %s\n", string[incl[inc_count]]); - assemble(tln, &bc, dbg); - progsize += bc.progsize; - datasize += bc.datasize; - printf("Finished assembling %s\n", string[incl[inc_count]]); - printf("%"PRIu64"/$%"PRIX64" bytes of program code.\n", bc.progsize, bc.progsize); - printf("%"PRIu64"/$%"PRIX64" bytes of data.\n", bc.datasize, bc.datasize); - putchar('\n'); } isinclude = (inc_file != 0); if (inc_file) { size = strlen(path)+strlen(string[incl[inc_count]])+1; char *fn2 = malloc(size+1); sprintf(fn2, "%s/%s", path, string[incl[inc_count]]); - if (!tmp_lineidx) { - tmp_lineidx = lineidx; - } - lineidx = 0; - linenum = 10; + isinclude = (inc_file != 0); inc_file--; inc_count++; if (inc_file && fp2 != NULL) { @@ -822,8 +798,6 @@ int asmmon(const char *fn) { fclose(fp); return 2; } - } else if (!inc_file && tmp_lineidx) { - lineidx = tmp_lineidx; } if (!isinclude) { puts("Finished assembling."); @@ -872,11 +846,7 @@ int asmmon(const char *fn) { case 0xFF: break; default: - if (!isinclude) { - address = lex(lex_line, tokline, address, dbg); - } else { - address = lex(lex_line, tln, address, dbg); - } + address = lex(lex_line, tokline, address, dbg); break; } } diff --git a/asmmon.h b/asmmon.h index 032830c..019be00 100644 --- a/asmmon.h +++ b/asmmon.h @@ -435,6 +435,7 @@ extern uint16_t linenum; extern uint16_t lineidx; extern uint16_t stridx; extern uint16_t comidx; +extern uint16_t inc_file; /* Number of included files. */ typedef struct { uint64_t progsize; diff --git a/lexer.c b/lexer.c index 4c398a4..77dff16 100644 --- a/lexer.c +++ b/lexer.c @@ -16,10 +16,12 @@ uint16_t mksymbol(const char *name, uint64_t val, uint8_t def, uint8_t useid, ui uint8_t flag = 0; for (; i < sym_count; i++) { if (useid) { - flag = id == symbols[i]->id; + flag = (id == symbols[i]->id); } else { if (name[0] == symbols[i]->name[0]) { flag = !strcmp(name, symbols[i]->name); + } else { + continue; } } if (flag) { @@ -199,7 +201,7 @@ uint16_t reslv_fixups(struct line *l, uint8_t dbg) { for (; fixups[j]; j++) { if (fixups[j]->s->def) { if (dbg) { - printf("reslv_fixups(): Symbol ID: $%X, Symbol Name: %s.\n", fixups[j]->s->id, fixups[j]->s->name); + printf("reslv_fixups(): Symbol ID: $%X, Symbol Name: %s, Symbol Value: $%X.\n", fixups[j]->s->id, fixups[j]->s->name, fixups[j]->s->val); } l[fixups[j]->ln].sym = fixups[j]->s->id; } else { @@ -550,6 +552,7 @@ uint64_t lex(char *str, struct line *l, uint64_t address, uint8_t dbg) { } if (l[line].dir == DIR_INCLUDE) { l[line].incl = strid; + incl[inc_file++] = strid; } lex_type = TOK_STRING; break; diff --git a/programs/subasm-2.s b/programs/subasm-2.s index 26af017..f10dac8 100644 --- a/programs/subasm-2.s +++ b/programs/subasm-2.s @@ -275,6 +275,8 @@ pnthex_end: print_space: lda #' ' ; Set the character to a space. phb #1 ; Preserve the spacing count. + ldb #1 ; Enable replace mode. + stb b ; jsl print_char ; Print the space. plb #1 ; Get the spacing count back. deb ; Have we printed all of the spacing? -- cgit v1.2.3-13-gbd6f