diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2020-06-01 15:15:17 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2020-06-01 15:15:17 -0400 |
commit | df81112b8369eeca5788a6f28c6b6b85ca911a95 (patch) | |
tree | fed73a1fb94485d4bc9dd25966d626c9338ccb05 | |
parent | f600bf84c453649f625b06ba232a7464e7093b32 (diff) |
Did some more refactoring to the assembler.
- Refactored the symbol, and fixup table to now use a
linked list
- Added support for local symbols to the assembler.
- Rewrote SuBEditor, and SuBAsm to use local symbols.
-rw-r--r-- | asmmon.c | 138 | ||||
-rw-r--r-- | asmmon.h | 109 | ||||
-rw-r--r-- | assemble.c | 85 | ||||
-rw-r--r-- | lexer.c | 408 | ||||
-rw-r--r-- | lexer.h | 21 | ||||
-rw-r--r-- | programs/subasm.s | 50 | ||||
-rw-r--r-- | programs/subeditor.s | 431 | ||||
-rw-r--r-- | programs/utils.s | 46 | ||||
-rw-r--r-- | sux.c | 25 |
9 files changed, 635 insertions, 678 deletions
@@ -16,9 +16,8 @@ char *comment[MAX_TOK]; uint16_t incl[MAX_TOK]; line *lines; line *last_line; -struct line tln[MAX_TOK]; -struct symbol *symbols[MAX_TOK]; -struct fixup *fixups[MAX_TOK]; +symbol *symbols = 0; +fixup *fixups = 0; static char tstr[2048]; @@ -112,8 +111,8 @@ char *showbits(uint64_t value, uint8_t bitnum, uint8_t dbg) { } void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, uint8_t dbg) { - line *s = find_line(start, dbg); - line *e = find_line(end, dbg); + line *s = (!all) ? find_line(start, dbg) : lines ; + line *e = (!all) ? find_line( end, dbg) : last_line; uint8_t j = 0; uint8_t flags = 0; uint8_t isstr; @@ -127,22 +126,18 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u char mne_lower[4]; char ch[6]; - if (all) { - s = lines; - e = last_line; - } - do { - token *t = s->tok; + token *tok = s->tok; + token *t; uint8_t am = 0xFF; uint8_t rs = 0xFF; if (dbg) { printf("list(): "); } if (ln) { - printf("%u\t", s->linenum); + printf("%u\t\t", s->linenum); } else if (addr) { - printf("$%"PRIX64":\t", s->addr); + printf("$%"PRIX64":\t\t", s->addr); } spaces = s->sspace; tabs = s->stab; @@ -156,10 +151,10 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u tabs--; } } - for (; t && t->id != TOK_COMMENT; t = t->next) { + for (; tok && tok->id != TOK_COMMENT && tok >= t; tok = tok->next) { + t = tok; switch (t->id) { - case TOK_DIR : printf(".%s ", dir_t[t->type]); break; - case TOK_STRING: printf("\"%s\"", t->str) ; break; + case TOK_DIR : printf(".%s ", dir_t[t->type] ); break; case TOK_OPCODE: for (; j < 3; j++) { mne_lower[j] = tolower(mne[t->byte][j]); @@ -169,10 +164,11 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u printf("%s", mne_lower); am = t->type; t = t->next; - if (t->id == TOK_RS) { + if (t && t->id == TOK_RS) { rs = t->type; printf("%s", rs_t[t->type]); } + putchar(' '); switch (am) { case IMM : putchar('#'); break; case IND : @@ -182,45 +178,65 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u break; case TOK_SYM: case TOK_LABEL: - printf("%s", symbols[t->word]->name); + if (t->type == 1) { + putchar('@'); + } + printf("%s", (t->sym) ? t->sym->name : "unknown"); if (t->id == TOK_LABEL) { putchar(':'); } else if (t == s->tok && t->id == TOK_SYM) { printf(" = "); } break; - case TOK_HEX: printf("$%"PRIX64, t->qword); break; - case TOK_DEC: printf( "%"PRIu64, t->qword); break; - case TOK_BIN: - if (rs != 0xFF) { - bitnum = (rs << 3); - } else { - opsize += (t->qword <= 0x000000FF) + 0; - opsize += (t->qword > 0x000000FF) + 1; - opsize += (t->qword > 0x0000FFFF) + 2; - opsize += (t->qword > 0xFFFFFFFF) + 3; - if (opsize) { - bitnum = bitsize[opsize-1]; + case TOK_HEX: + if (t->id == TOK_HEX) { + printf("$%02"PRIX64, t->qword); + } else if (t->id == TOK_DEC) { + case TOK_DEC: printf( "%"PRIu64, t->qword); + } else if (t->id == TOK_BIN) { + case TOK_BIN: if (rs != 0xFF) { + bitnum = (rs << 3); + } else { + opsize += (t->qword <= 0x000000FF) + 0; + opsize += (t->qword > 0x000000FF) + 1; + opsize += (t->qword > 0x0000FFFF) + 2; + opsize += (t->qword > 0xFFFFFFFF) + 3; + if (opsize) { + bitnum = bitsize[opsize-1]; + } } + printf("%%%s", showbits(t->qword, bitnum, dbg)); + bitnum = 0; + opsize = 0; + } else if (t->id == TOK_STRING) { + case TOK_STRING: + printf("\"%s\"", (t->str) ? t->str : ""); + } else if (t->id == TOK_CHAR) { + case TOK_CHAR: j = 0; + switch (t->byte) { + default : ch[j++] = t->byte; break; + case '\n': ch[j++] = '\\'; ch[j++] = 'n' ; break; + case '\r': ch[j++] = '\\'; ch[j++] = 'r' ; break; + case '\b': ch[j++] = '\\'; ch[j++] = 'b' ; break; + case '\\': ch[j++] = '\\'; ch[j++] = '\\'; break; + case '\'': ch[j++] = '\\'; ch[j++] = '\''; break; + case '\"': ch[j++] = '\\'; ch[j++] = '\"'; break; + } + ch[j] = '\0'; + j = 0; + printf("\'%s\'", ch); } - printf("%%%s", showbits(t->qword, bitnum, dbg)); - bitnum = 0; - opsize = 0; - break; - case TOK_CHAR: - j = 0; - switch (t->byte) { - default : ch[j++] = t->byte; break; - case '\n': ch[j++] = '\\'; ch[j++] = 'n' ; break; - case '\r': ch[j++] = '\\'; ch[j++] = 'r' ; break; - case '\b': ch[j++] = '\\'; ch[j++] = 'b' ; break; - case '\\': ch[j++] = '\\'; ch[j++] = '\\'; break; - case '\'': ch[j++] = '\\'; ch[j++] = '\''; break; - case '\"': ch[j++] = '\\'; ch[j++] = '\"'; break; + if (t->next) { + switch (t->next->id) { + case TOK_STRING: + case TOK_HEX: + case TOK_BIN: + case TOK_DEC: + case TOK_CHAR: + printf(", "); + break; + } } - ch[j] = '\0'; - j = 0; - printf("\'%s\'", ch); break; case TOK_EXPR: switch (t->type) { @@ -269,8 +285,8 @@ void list(uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t addr, u tabs--; } } - if (t->id == TOK_COMMENT) { - printf(";%s", t->str); + if (tok && tok->id == TOK_COMMENT) { + printf(";%s", (tok->str) ? tok->str : ""); } puts(""); s = s->next; @@ -308,7 +324,6 @@ int asmmon(const char *fn) { uint8_t dbg = 0; uint8_t isinclude = 0; uint16_t tmp_lineidx = 0; - init_symbol(); while (!done) { char *cmd; char *arg = malloc(sizeof(char *)*128); @@ -358,9 +373,7 @@ int asmmon(const char *fn) { if (fp2 != NULL) { fclose(fp2); } - if (lines) { - free_lines(); - } + cleanup(); return 2; case 0x02: viewmem(address); @@ -428,15 +441,16 @@ int asmmon(const char *fn) { } break; case 0x08: - if (!inc_file) { + if (!inc_count) { printf("Assembling %s\n", (strcasecmp(fn, "stdin")) ? fn : "typed in program."); + } + if (!inc_file) { + puts("Now assembling."); + bc.progsize = 0; + bc.datasize = 0; assemble(lines, &bc, dbg); progsize = bc.progsize; datasize = bc.datasize; - printf("Finished assembling %s\n", (strcasecmp(fn, "stdin")) ? fn : "typed in program."); - printf("%"PRIu64"/$%"PRIX64" bytes of program code.\n", progsize, progsize); - printf("%"PRIu64"/$%"PRIX64" bytes of data.\n", datasize, datasize); - putchar('\n'); } isinclude = (inc_file != 0); if (inc_file) { @@ -445,7 +459,6 @@ int asmmon(const char *fn) { sprintf(fn2, "%s/%s", path, string[incl[inc_count]]); isinclude = (inc_file != 0); inc_file--; - inc_count++; if (inc_file && fp2 != NULL) { fclose(fp2); } @@ -453,8 +466,11 @@ int asmmon(const char *fn) { if (fp2 == NULL) { free(path); fclose(fp); + cleanup(); return 2; } + printf("Including %s\n", string[incl[inc_count++]]); + inc_count++; } if (!isinclude) { puts("Finished assembling."); @@ -517,8 +533,6 @@ int asmmon(const char *fn) { if (fp2 != NULL) { fclose(fp2); } - if (lines) { - free_lines(); - } + cleanup(); return 0; } @@ -4,37 +4,19 @@ #define MAX_TOK 0x1000 -struct line { - uint8_t stab; - uint8_t sspace; - uint8_t dir; - uint8_t mne; - uint8_t rs; - uint8_t opbase; - uint8_t aopbase; - uint8_t am; - uint8_t cm; - uint8_t etab; - uint8_t espace; - uint8_t islabel; - uint8_t issym; - uint16_t sym; - uint16_t com; - uint16_t str; - uint16_t incl; - uint16_t linenum; - uint64_t op; - uint64_t aop; - uint64_t addr; -}; +typedef struct tok token ; +typedef struct ln line ; +typedef struct sym symbol; +typedef struct fix fixup ; struct tok { - struct tok *next; /* Pointer to the next token. */ - uint8_t id; /* Token ID. */ - uint8_t type; /* Token type ID. */ + token *next; /* Pointer to the next token. */ + uint8_t id; /* Token ID. */ + uint8_t type; /* Token type ID. */ /* Token value(s). */ union { + symbol *sym; char *str; uint8_t byte ; uint16_t word ; @@ -44,8 +26,8 @@ struct tok { }; struct ln { - struct ln *next; /* Pointer to the next line. */ - struct tok *tok; /* The token(s) for this line. */ + line *next; /* Pointer to the next line. */ + token *tok; /* The token(s) for this line. */ uint16_t count; /* Total tokens for this line. */ uint32_t linenum; /* Line number. */ uint64_t addr; /* The address of this line. */ @@ -55,20 +37,22 @@ struct ln { uint8_t espace; /* Number of ending spaces. */ }; -typedef struct tok token; -typedef struct ln line; -struct fixup { - struct symbol *s; +struct fix { + fixup *next; + symbol *s; token *t; uint64_t adr; }; -struct symbol { +struct sym { + symbol *next; + symbol *local; + uint16_t count; uint64_t val; uint8_t def; - char name[128]; + char *name; uint16_t id; }; @@ -80,10 +64,9 @@ extern line *lines; extern line *last_line; extern token *tokens; extern token *last_tok; -extern struct line tokline[]; -extern struct line tln[]; -extern struct symbol *symbols[]; -extern struct fixup *fixups[]; +extern symbol *symbols; +extern symbol *locals; +extern fixup *fixups; extern uint8_t lex_type; @@ -98,6 +81,7 @@ enum dir { enum token { TOK_DIR, + TOK_LOCAL, TOK_LABEL, TOK_SYM, TOK_EXPR, @@ -117,6 +101,7 @@ enum token { enum pre_token { PTOK_DOT, + PTOK_AT, PTOK_COLON, PTOK_EQU, PTOK_PLUS, @@ -255,23 +240,24 @@ static const char *rs_t[4] = { [3] = ".q" }; -static const char *lex_tok[16] = { - [0x0] = "TOK_DIR", - [0x1] = "TOK_LABEL", - [0x2] = "TOK_SYM", - [0x3] = "TOK_EXPR", - [0x4] = "TOK_CSV", - [0x5] = "TOK_STRING", - [0x6] = "TOK_CHAR", - [0x7] = "TOK_IND", - [0x8] = "TOK_IMM", - [0x9] = "TOK_OPCODE", - [0xA] = "TOK_RS", - [0xB] = "TOK_COMMENT", - [0xC] = "TOK_HEX", - [0xD] = "TOK_DEC", - [0xE] = "TOK_BIN", - [0xF] = "TOK_INCLUDE" +static const char *lex_tok[17] = { + [0x00] = "TOK_DIR", + [0x01] = "TOK_LOCAL", + [0x02] = "TOK_LABEL", + [0x03] = "TOK_SYM", + [0x04] = "TOK_EXPR", + [0x05] = "TOK_CSV", + [0x06] = "TOK_STRING", + [0x07] = "TOK_CHAR", + [0x08] = "TOK_IND", + [0x09] = "TOK_IMM", + [0x0A] = "TOK_OPCODE", + [0x0B] = "TOK_RS", + [0x0C] = "TOK_COMMENT", + [0x0D] = "TOK_HEX", + [0x0E] = "TOK_DEC", + [0x0F] = "TOK_BIN", + [0x10] = "TOK_INCLUDE" }; static const char *adrmode[9] = { @@ -504,19 +490,10 @@ typedef struct bc bytecount; extern uint8_t defined; extern uint8_t isfixup; -extern void init_symbol(); -extern uint16_t mksymbol(const char *name, uint64_t val, uint8_t def, uint8_t useid, uint16_t id, uint8_t dbg); -extern uint64_t use_symbol(const char *name, uint16_t id, uint64_t val, uint8_t useid, uint8_t dbg); -extern uint8_t set_symval(const char *name, uint16_t id, uint64_t val, uint8_t useid, uint8_t dbg); -extern char *get_symname(uint16_t id, uint8_t dbg); -extern uint16_t get_symid(const char *name, uint64_t val, token *t, uint8_t dbg); -extern uint16_t get_comment(const char *cmnt, uint8_t dbg); -extern uint16_t reslv_fixups(uint8_t dbg); extern line *find_line(uint32_t ln, uint8_t dbg); extern uint64_t lex(char *str, uint64_t address, uint8_t dbg); extern uint64_t parse_tokens(token *tm, bytecount *bc, uint8_t isasm, uint64_t address, uint8_t dbg); -extern token *make_token(uint8_t id, uint8_t type, uint64_t value, char *str); +extern token *make_token(uint8_t id, uint8_t type, uint64_t value, char *str, symbol *sym); extern void assemble(line *ln, bytecount *bc, uint8_t dbg); -extern void free_tokens(token *t, uint16_t count); -extern void free_lines(); +extern void cleanup(); @@ -42,7 +42,7 @@ uint64_t get_val(token *t, uint64_t addr, uint8_t size, uint8_t dbg) { break; case TOK_SYM: case TOK_LABEL: - tmp_val = use_symbol("", t->word, addr, 1, dbg); + tmp_val = (t->sym) ? t->sym->val : addr; t = t->next; break; } @@ -201,7 +201,7 @@ uint64_t handle_opcode(token *t, bytecount *bc, uint8_t isasm, uint64_t address, val.u64 = get_val(t, address, (rs != 0xFF) ? rs : 0, dbg); } opcode = opcodes[inst][type]; - if (inst == 80) { + if (inst == 78) { if (type == IMM) { rs = 1; } else { @@ -333,15 +333,17 @@ uint64_t parse_tokens(token *t, bytecount *bc, uint8_t isasm, uint64_t address, return address; } -token *make_token(uint8_t id, uint8_t type, uint64_t value, char *str) { +token *make_token(uint8_t id, uint8_t type, uint64_t value, char *str, symbol *s) { token *new_tok = malloc(sizeof(token)); (last_tok) ? (last_tok->next = new_tok) : (tokens = new_tok); new_tok->id = id; new_tok->type = type; - if (!str[0]) { - new_tok->qword = value; - } else { + if (s) { + new_tok->sym = s; + } else if (str[0]) { new_tok->str = str; + } else { + new_tok->qword = value; } new_tok->next = NULL; last_tok = new_tok; @@ -355,27 +357,78 @@ void assemble(line *ln, bytecount *bc, uint8_t dbg) { } } -void free_tokens(token *t, uint16_t count) { +static inline void free_tokens(token *t, uint16_t count) { token *tok; - while (t != NULL) { - if (count--) { - break; - } + for (; t != NULL && t >= tok; t = t->next) { tok = t; free(tok); - t = t->next; } } void free_lines() { line *l = lines; line *ln; - for (; l != NULL; l = l->next) { - if (l < ln) { - break; - } + for (; l != NULL && l >= ln; l = l->next) { free_tokens(l->tok, l->count); ln = l; free(ln); } } + +void free_locals(symbol *s) { + symbol *sym; + for (; s != NULL && s >= sym; s = s->next) { + sym = s; + if (sym->name != NULL) { + free(sym->name); + } + free(sym); + } +} + +void free_symbols() { + symbol *s = symbols; + symbol *sym = symbols; + for (; s != NULL && s >= sym; s = s->next) { + if (s->local) { + free_locals(s->local); + } + sym = s; + if (sym->name != NULL) { + free(sym->name); + } + free(sym); + } +} + +static inline void free_fixups() { + fixup *f = fixups; + fixup *fix; + for (; f != NULL && f >= fix; f = f->next) { + /*free_tokens(l->tok, l->count);*/ + fix = f; + free(fix); + } +} + +void cleanup() { + uint16_t i; + if (lines) { + free_lines(); + } + if (symbols) { + free_symbols(); + } + if (fixups) { + free_fixups(); + } + while (i < stridx || i < comidx) { + if (i < stridx) { + free(string[i]); + } + if (i < comidx) { + free(comment[i]); + } + i++; + } +} @@ -5,31 +5,21 @@ uint8_t lex_type; uint16_t sym_count = 0; token *tokens = NULL; token *last_tok = NULL; +symbol *locals = NULL; +symbol *cur_sym = NULL; -void init_symbol() { - uint16_t i = 0; - for (; i < 0x1000; i++) { - symbols[i] = 0; - fixups[i] = 0; - } -} - -uint16_t mksymbol(const char *name, uint64_t val, uint8_t def, uint8_t useid, uint16_t id, uint8_t dbg) { +symbol *mksymbol(const char *name, uint64_t val, uint8_t def, uint8_t islocal, uint8_t useid, uint16_t id, uint8_t dbg) { uint16_t i = 0; + symbol *s = (!islocal || islocal == 2) ? symbols : locals; uint8_t flag = 0; - for (; i < sym_count; i++) { - if (useid) { - flag = (id == symbols[i]->id); - } else { - if (name[0] == symbols[i]->name[0]) { - flag = !strcmp(name, symbols[i]->name); - } else { - continue; - } + for (; s; s = s->next, i++) { + if (!useid && name[0] != s->name[0]) { + continue; } + flag = (useid) ? (id == s->id) : !strcmp(name, s->name); if (flag) { if (def) { - if (symbols[i]->def) { + if (s->def) { if (dbg) { printf("mksymbol(): oof, you cannot redefine the symbol: %s\n", name); } @@ -37,126 +27,92 @@ uint16_t mksymbol(const char *name, uint64_t val, uint8_t def, uint8_t useid, ui } else { defined = 0; } - symbols[i]->def = def; - symbols[i]->val = val; - symbols[i]->id = i; + s->def = def; + s->val = val; + s->id = i; if (dbg) { printf("mksymbol(): def: %u, val: $%016"PRIX64", name: %s\n", def, val, name); - printf("mksymbol(): i: $%X, id: $%04X\n", i, symbols[i]->id); + printf("mksymbol(): i: $%X, id: $%04X\n", i, s->id); } } - return symbols[i]->id; + return s; } } - symbols[i] = malloc(sizeof(**symbols) + strlen(name)); - symbols[i]->def = def; - symbols[i]->val = val; - strcpy(symbols[i]->name, name); - symbols[i]->id = sym_count++; + size_t str_size = strlen(name)+1; + s = malloc(sizeof(*s)); + s->name = malloc(str_size); + s->def = def; + s->val = val; + s->count = 0; + memcpy(s->name, name, str_size); + s->next = (!islocal) ? symbols : locals; + s->id = sym_count++; + if (!islocal) { + s->local = NULL; + symbols = s; + } else { + cur_sym->count++; + locals = s; + } defined = 0; if (dbg) { printf("mksymbol(): def: %u, val: $%016"PRIX64", name: %s, id: $%04X\n", def, val, name, sym_count-1); } - return sym_count-1; + return s; } -uint64_t use_symbol(const char *name, uint16_t id, uint64_t val, uint8_t useid, uint8_t dbg) { - uint16_t i; - i = mksymbol(name, 0, 0, useid, id, dbg); - uint8_t is_defined = (i != 0xFFFF); - val++; +uint16_t fixup_cnt = 0; +symbol *get_sym(const char *name, uint64_t val, token *t, uint8_t islocal, uint8_t dbg) { + symbol *s = mksymbol(name, 0, 0, islocal, 0, 0, dbg); if (dbg) { - puts("use_symbol(): We also got here."); - printf("use_symbol(): i: $%X\n", i); + printf("get_sym(): Symbol ID: $%X.\n", s->id); } - if (symbols[i] != NULL) { - if (symbols[i]->def) { - return symbols[i]->val; - } else { - if (dbg) { - printf("use_symbol(): "); - printf("oof, symbol "); - if (useid) { - printf("id $%04X, ", id); - } else { - printf("%s, ", name); - } - puts("does not exist, yet."); - } - return val-1; + if (s->def) { + return s; + } else { + if (dbg) { + printf("get_sym(): oof, symbol %s, does not exist, yet.\n", name); } + fixup *f = malloc(sizeof(*f)); + f->next = fixups; + f->adr = val; + f->t = t; + f->s = s; + fixups = f; + fixup_cnt++; + return NULL; } - return val-1; } -uint8_t set_symval(const char *name, uint16_t id, uint64_t val, uint8_t useid, uint8_t dbg) { - uint16_t i = mksymbol(name, 0, 0, useid, id, dbg); - if (symbols[i] != NULL) { - if (symbols[i]->def) { - symbols[i]->val = val; - return 1; +uint16_t reslv_fixups(uint8_t dbg) { + fixup *f = fixups; + symbol *ls; + uint16_t i = 0, j = 0; + for (; f; f = f->next) { + if (f->s->def) { + if (dbg) { + printf("reslv_fixups(): Symbol ID: $%X, Symbol Name: %s, Symbol Value: $%"PRIX64".\n", f->s->id, f->s->name, f->s->val); + } + f->t->sym = f->s; } else { if (dbg) { - printf("set_symval(): "); - printf("oof, symbol "); - if (useid) { - printf("id $%04X, ", id); - } else { - printf("%s, ", name); - } - puts("does not exist, yet."); + printf("reslv_fixups(): oof, undefined reference to '%s', at $%016"PRIX64".\n", f->s->name, f->adr); } - return 0; - } - } - return 0; -} - -char *get_symname(uint16_t id, uint8_t dbg) { - if (symbols[id]->def) { - return symbols[id]->name; - } else { - if (dbg) { - printf("get_symname(): oof, symbol id $%04X, has not been defined, yet.\n", id); + i++; } - return NULL; } -} + return i; -uint16_t fixup_cnt = 0; -uint16_t get_symid(const char *name, uint64_t val, token *t, uint8_t dbg) { - uint16_t i = mksymbol(name, 0, 0, 0, 0, dbg); - if (dbg) { - printf("get_symid(): Symbol ID: $%X, i: $%X.\n", symbols[i]->id, i); - } - if (symbols[i]->def) { - return symbols[i]->id; - } else { - if (dbg) { - printf("get_symid(): oof, symbol %s, does not exist, yet.\n", name); - } - fixups[fixup_cnt] = malloc(sizeof(**fixups)); - fixups[fixup_cnt]->adr = val; - fixups[fixup_cnt]->t = t; - fixups[fixup_cnt]->s = symbols[i]; - fixup_cnt++; - return 0xFFFF; - } } uint16_t get_comment(const char *com, uint8_t dbg) { uint16_t i = 0; uint8_t iscom = 0; for (; i < comidx; i++) { - if (comment[i] != NULL) { - if (com[0] == comment[i][0]) { - iscom = !strcmp(com, comment[i]); - } - } else { - break; - } - if (iscom) { + if (comment[i] == NULL || iscom) { break; + } else if (com[0] == comment[i][0]) { + iscom = !strcmp(com, comment[i]); } } if (comment[i] == NULL || i == comidx) { @@ -178,10 +134,8 @@ uint16_t get_string(const char *str, uint8_t dbg) { for (; i < stridx; i++) { if (isstr || string[i] == NULL) { break; - } else { - if (str[0] == string[i][0]) { - isstr = !strcmp(str, string[i]); - } + } else if (str[0] == string[i][0]) { + isstr = !strcmp(str, string[i]); } } if (string[i] == NULL || i == stridx) { @@ -197,35 +151,10 @@ uint16_t get_string(const char *str, uint8_t dbg) { return i; } -uint16_t reslv_fixups(uint8_t dbg) { - uint16_t i = 0, j = 0; - for (; fixups[j]; j++) { - if (fixups[j]->s->def) { - if (dbg) { - printf("reslv_fixups(): Symbol ID: $%X, Symbol Name: %s, Symbol Value: $%"PRIX64".\n", fixups[j]->s->id, fixups[j]->s->name, fixups[j]->s->val); - } - fixups[j]->t->word = fixups[j]->s->id; - } else { - if (dbg) { - printf("reslv_fixups(): oof, undefined reference to '%s', at $%016"PRIX64".\n", fixups[j]->s->name, fixups[j]->adr); - } - i++; - } - } - return i; - -} - line *find_line(uint32_t ln, uint8_t dbg) { uint32_t i = 0; line *l = lines; for (; l && l->linenum != ln; l = l->next); - /*if (dbg) { - if (l->linenum == ln) { - printf("find_line(): Found line number %u, at line index %X.\n", ln, i); - } - printf("find_line(): linenum: %u, i: %X\n", l->linenum, i); - }*/ if (l != NULL) { if (l->linenum == ln) { if (dbg) { @@ -257,6 +186,8 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { uint8_t rs = 0; uint8_t base = 0; + uint8_t islocal = 0; + uint8_t isop = 0; int num = 0; int isch = 0; @@ -346,7 +277,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { } } l->count++; - t = make_token(lex_type, k, 0, ""); + t = make_token(lex_type, k, 0, "", NULL); } else { lex_type = TOK_RS; switch (tolower(lexeme[j-1])) { @@ -364,7 +295,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { break; } l->count++; - t = make_token(lex_type, rs, 0, ""); + t = make_token(lex_type, rs, 0, "", NULL); isop = 0; } break; @@ -391,7 +322,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { } lex_type = TOK_STRING; l->count++; - t = make_token(lex_type, 0, 0, string[strid]); + t = make_token(lex_type, 0, 0, string[strid], NULL); break; case PTOK_DOLLAR: case PTOK_PERCENT: @@ -408,17 +339,22 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { i += j; value = strtoull(lexeme, NULL, base); if (lt->id == TOK_SYM) { - mksymbol(sym, value, 1, 0, 0, dbg); + mksymbol(sym, value, 1, islocal, 0, 0, dbg); if (lt) { - lt->word = get_symid(sym, address, lt, dbg); + lt->sym = get_sym(sym, address, lt, islocal, dbg); + } + if (!islocal) { + cur_sym = symbols; + locals = cur_sym->local; } - isfixup += (lt->word == 0xFFFF); + islocal = 0; + isfixup += (lt->sym == NULL); if (dbg) { printf("lex(): isfixup: %u\n", isfixup); } } l->count++; - t = make_token(lex_type, 0, value, ""); + t = make_token(lex_type, 0, value, "", NULL); break; case PTOK_SQUOTE: i++; @@ -444,10 +380,15 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { } lex_type = TOK_CHAR; l->count++; - t = make_token(lex_type, 0, ch, ""); + t = make_token(lex_type, 0, ch, "", NULL); + break; + case PTOK_LBRACK: + case PTOK_HASH : + l->tok->type = (ptok == PTOK_LBRACK) ? IND : IMM; + lex_type = (ptok == PTOK_LBRACK) ? TOK_IND : TOK_IMM; + memset(lexeme, 0, strlen(lexeme)+1); + lexeme[j++] = str[i]; break; - case PTOK_LBRACK: l->tok->type = IND; memset(lexeme, 0, strlen(lexeme)+1); lexeme[j++] = str[i]; break; - case PTOK_HASH : l->tok->type = IMM; memset(lexeme, 0, strlen(lexeme)+1); lexeme[j++] = str[i]; break; case PTOK_PLUS: case PTOK_MINUS: case PTOK_GT: @@ -460,15 +401,13 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { case PTOK_LT : value = EXPR_HIGH ; break; } l->count++; - t = make_token(lex_type, value, 0, ""); + t = make_token(lex_type, value, 0, "", NULL); memset(lexeme, 0, strlen(lexeme)+1); lexeme[j++] = str[i]; break; case PTOK_EQU: i++; lex_type = TOK_SYM; - l->count++; - t = make_token(lex_type, 0, 0, ""); memset(lexeme, 0, strlen(lexeme)+1); lexeme[j] = str[i]; break; @@ -490,28 +429,43 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { break; case PTOK_X: case PTOK_Y: + lexeme[j] = str[i++]; + lexeme[j+1] = '\0'; + lexeme[j+2] = '\0'; + if (lex_type != TOK_IND && lex_type != TOK_CSV) { + break; + } switch (ptok) { case PTOK_X: l->tok->type = (lex_type == TOK_IND) ? INDX : ZMX; break; case PTOK_Y: l->tok->type = (lex_type == TOK_IND) ? INDY : ZMY; break; } - lexeme[j] = str[i]; - lexeme[j+1] = '\0'; - lexeme[j+2] = '\0'; - i++; + break; + case PTOK_AT: + memset(lexeme, 0, strlen(lexeme)+1); + lexeme[j] = '@'; + islocal = 1; + lex_type = TOK_LOCAL; break; case PTOK_COLON: i++; lexeme[j] = ':'; lexeme[j+1] = '\0'; lex_type = TOK_LABEL; - l->count++; - t = make_token(lex_type, 0, 0, ""); - mksymbol(sym, address, 1, 0, 0, dbg); + mksymbol(sym, address, 1, islocal, 0, 0, dbg); if (isfixup) { isfixup = reslv_fixups(dbg); } - t->word = get_symid(sym, address, t, dbg); - isfixup += (t->word == 0xFFFF); + if (lt) { + lt->id = lex_type; + lt->type = islocal; + lt->sym = get_sym(sym, address, t, islocal, dbg); + isfixup += (lt->sym == NULL); + } + if (!islocal) { + cur_sym = symbols; + locals = cur_sym->local; + } + islocal = 0; if (dbg) { printf("lex(): isfixup: %u\n", isfixup); } @@ -519,54 +473,43 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { case PTOK_SCOLON: i++; for (; isdelm(str[i+j], dbg) != 1; j++); - memcpy(lexeme, str+i, j); - lexeme[j] = '\0'; - i += j; - comid = get_comment(lexeme, dbg); - if (comid == 0xFFFF) { - /*if (line != lineidx && l[line].com != 0xFFFF) { - comid = l[line].com; - } else { - comid = comidx; - }*/ - comid = comidx; - comment[comid] = malloc(j+1); - memcpy(comment[comid], lexeme, j+1); - comidx++; + if (!j) { + lexeme[j] = ' '; + lexeme[j+1] = '\0'; + } else { - } - if (dbg) { - printf("lex(): com[0x%04X]: %s\n", comid, comment[comid]); + memcpy(lexeme, str+i, j); + lexeme[j] = '\0'; + i += j; + comid = get_comment(lexeme, dbg); + if (comid == 0xFFFF) { + /*if (line != lineidx && l[line].com != 0xFFFF) { + comid = l[line].com; + } else { + comid = comidx; + }*/ + comid = comidx; + comment[comid] = malloc(j+1); + memcpy(comment[comid], lexeme, j+1); + comidx++; + } else { + } + if (dbg) { + printf("lex(): com[0x%04X]: %s\n", comid, comment[comid]); + } } lex_type = TOK_COMMENT; l->count++; - t = make_token(lex_type, 0, 0, comment[comid]); + if (j) { + t = make_token(lex_type, 0, 0, comment[comid], NULL); + } else { + t = make_token(lex_type, 0, 0, "" , NULL); + } + break; case PTOK_ALPHA: - while (isdelm(str[i], dbg) != 16) { - switch (str[i]) { - case ')': - case ',': - case '.': - case '+': - case '<': - case '>': - case '-': - case ':': - case '=': - case ';': - case '\0': - case '\n': - isch = 0; - break; - default: - isch = 1; - lexeme[j++] = str[i++]; - break; - } - if (!isch) { - break; - } + while (!isdelm2(str[i], dbg)) { + lexeme[j++] = str[i++]; } lexeme[j] = '\0'; isch = 0; @@ -578,41 +521,16 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { lex_type = TOK_OPCODE; isop = 1; l->count++; - t = make_token(lex_type, 0xFF, k, ""); + t = make_token(lex_type, 0xFF, k, "", NULL); break; } } } } if (!isop) { - for (k = 0; lexeme[k] != '\0';) { - switch (lexeme[k]) { - case ')': - case ',': - case '.': - case '+': - case '-': - case '<': - case '>': - case ':': - case ';': - case '=': - case '\0': - case '\n': - fall = 1; - break; - default: - fall = 0; - break; - } - if (fall) { - break; - } - k++; - } lex_type = TOK_SYM; l->count++; - t = make_token(lex_type, 0, 0, ""); + t = make_token(lex_type, islocal, 0, "", NULL); memcpy(sym, lexeme, j+1); uint8_t spaces = 0; for (; isdelm(str[i+spaces], dbg) == 16; spaces++); @@ -620,8 +538,9 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { printf("lex(): spaces: %u\n", spaces); } if (str[i+spaces] != ':' && str[i+spaces] != '=') { - t->word = get_symid(lexeme, address, t, dbg); - isfixup += (t->word == 0xFFFF); + t->sym = get_sym(lexeme, address, t, islocal, dbg); + islocal = 0; + isfixup += (t->sym == NULL); if (dbg) { printf("lex(): isfixup: %u\n", isfixup); } @@ -639,31 +558,8 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { j = 0; if (lex_type == TOK_OPCODE && !isop) { j = 0; - } else { - if (lex_type == TOK_EXPR) { - i++; - } else { - switch (str[i]) { - case ')': - case ',': - case '.': - case '+': - case '-': - case '<': - case '>': - case ':': - case ';': - case '=': - case ' ': - case '\t': - case '\n': - case '\0': - break; - default: - i++; - break; - } - } + } else if (lex_type == TOK_EXPR || !isdelm2(str[i], dbg)) { + i++; } if (lex_type == TOK_COMMENT) { if (!isstart) { @@ -679,6 +575,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { lex_type = 0xFF; case TOK_CSV: case TOK_IND: + case TOK_LOCAL: memset(lexeme, 0, strlen(lexeme)+1); case TOK_SYM: break; @@ -707,5 +604,6 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { linenum += 10; } } + l->addr = address; return address; } @@ -11,9 +11,30 @@ static inline uint8_t isdelm(char c, uint8_t dbg) { } } +static inline uint8_t isdelm2(char c, uint8_t dbg) { + switch (c) { + default : return 0; + case ')' : + case ',' : + case '.' : + case '+' : + case '<' : + case '>' : + case '-' : + case ':' : + case '=' : + case ';' : + case '\0': + case '\n': return 1; + case '\t': + case ' ' : return 2; + } +} + static inline uint8_t get_ptok(char c, uint8_t dbg) { switch (c) { case '.' : return PTOK_DOT ; + case '@' : return PTOK_AT ; case ':' : return PTOK_COLON ; case '=' : return PTOK_EQU ; case '+' : return PTOK_PLUS ; diff --git a/programs/subasm.s b/programs/subasm.s index 86a8837..e009ce8 100644 --- a/programs/subasm.s +++ b/programs/subasm.s @@ -218,7 +218,7 @@ subasm: tax ; Reset X. jsr chk_shcmd ; Did we get a shortend command? bne parse_cmd ; Yes, so skip everything else. - jmp subasm_end ; + jmp @end ; jsr chk_cmd ; No, but did we get a full command? bne parse_cmd ; Yes, so skip everything else. jsr lexer ; No, so start lexing this line. @@ -255,32 +255,32 @@ chk_shcmd: phy #2 ; Preserve the screen buffer position. txy ; Set our index to zero. lda (ptr), y ; Is there nothing in the command buffer? - beq shcmd_fail ; Yes, so return that we failed. + beq @false ; Yes, so return that we failed. cmp #' ' ; No, but is this character, a space? - beq shcmd_fail ; Yes, so return that we failed. -shcmd_loop: + beq @false ; Yes, so return that we failed. +@loop: ldb (ptr2), y ; Are we at the end of the table? - beq shcmd_fail ; Yes, so return that we failed. + beq @false ; Yes, so return that we failed. cab ; No, so did the character match? - beq shcmd_fnd ; Yes, so check if there are any arguments. + beq @found ; Yes, so check if there are any arguments. iny ; No, so check the next command. - jmp shcmd_loop ; Keep looping. -shcmd_fnd: + jmp @loop ; Keep looping. +@found: sty f ; Save the command ID. ldy #1 ; Check the next character in the command buffer. lda (ptr), y ; Is this the end of the buffer? - beq shcmd_true ; Yes, so return that we succeded. + beq @true ; Yes, so return that we succeded. cmp #' ' ; No, but is this a space? - beq shcmd_true ; Yes, so return that we succeded. - jmp shcmd_fail ; No, so return that we failed. -shcmd_true: + beq @true ; Yes, so return that we succeded. + jmp @false ; No, so return that we failed. +@true: lda #1 ; Return true. - jmp shcmd_end ; We are done. -shcmd_fail: + jmp @end ; We are done. +@false: ldb #0 ; Reset B. tba ; Return false. tax ; Reset X. -shcmd_end: +@end: ply #2 ; Get back the screen buffer position. rts ; End of chk_shcmd. @@ -297,7 +297,7 @@ viewmem: ldx #0 ; Reset X. ldb #0 ; Reset B. stb idx1 ; Reset the byte count. -vmem_lp0: +@loop: lda #'\n' ; Print a newline. jsr print_char ; jsr print_hi ; Place the address in the string buffer. @@ -307,14 +307,14 @@ vmem_lp0: inc idx1 ; Increment the chunk count. ldb idx1 ; Get the chunk count. cpb #$10 ; Did we print 16 chunks? - beq vmem_end ; Yes, so we're done. + beq @end ; Yes, so we're done. lda.q idx0 ; No, so get the address index. clc ; Prepare for a non carrying add. adc #$10 ; Add 16 to the address. sta.q idx0 ; Put it back into the address. and #0 ; Reset A. - jmp vmem_lp0 ; Keep looping. -vmem_end: + jmp @loop ; Keep looping. +@end: lda #'\n' ; Print a newline. jsr print_char ; and #0 ; Reset A. @@ -323,27 +323,27 @@ vmem_end: list: nop ; -list_end: +@end: rts ; End of list. asm: nop ; -asm_end: +@end: rts ; End of asm. help: nop ; -help_end: +@end: rts ; End of help. inst: nop ; -inst_end: +@end: rts ; End of inst. run: nop ; -run_end: +@end: rts ; End of run. set: nop ; -set_end: +@end: rts ; End of set. diff --git a/programs/subeditor.s b/programs/subeditor.s index 0a42c32..26c6f7d 100644 --- a/programs/subeditor.s +++ b/programs/subeditor.s @@ -151,9 +151,9 @@ clr_arr: jsr set_ptr ; deb ; Set B back to zero. tba ; -clr_arr_st: +@loop: cpy.w scr_ptr ; Did we clear all of the array? - bcs clr_arr_end ; Yes, so we're done. + bcs @end ; Yes, so we're done. sta.q (ptr), y ; No, so clear eight bytes. sta.q (ptr2), y ; Clear eight more bytes. tya ; Copy the array index. @@ -166,8 +166,8 @@ clr_arr_st: adc #$10 ; tay ; tba ; - jmp clr_arr_st ; Keep looping. -clr_arr_end: + jmp @loop ; Keep looping. +@end: ldy.w zero ; Set the index back to zero. plb #1 ; Get whatever was in the B register, back. rts ; End of clr_arr. @@ -219,27 +219,27 @@ read: print_str: ldx #0 ; Reset X. sta.q end ; Save the parameter. -print_str2: +@reset: lda.q end ; Get the parameter. ldb #0 ; Clear the B register. jsr set_ptr ; Set the first pointer to the parameter. tba ; Clear the Accumulator. -pntstr_lp: +@loop: ldb #1 ; Enable replace mode. stb b ; lda.q ptr ; Get the first pointer. cmp.q end ; Did the pointer change? - bne print_str2 ; Yes, so set it back. + bne @reset ; Yes, so set it back. and #0 ; No, reset the accumulator. phy #2 ; Save the cursor index. txy ; Copy the string index into Y. lda (ptr), y ; Are we at the end of the string? ply #2 ; Get the cursor index back. - beq pntstr_end ; Yes, so we're done. + beq @end ; Yes, so we're done. inx ; No, so increment the string index. jsr print_char ; Print the character. - jmp pntstr_lp ; Keep looping. -pntstr_end: + jmp @loop ; Keep looping. +@end: ldb #0 ; Enable insert mode. stb b ; rts ; End of print_str. @@ -334,37 +334,37 @@ getchar: pha #1 ; Save the character. phy #2 ; Save the cursor index. cmp #'\n' ; Was the character that was typed, a newline? - bne getchar_pnt ; No, so just print the character. + bne @print ; No, so just print the character. jsr cmd_cpy ; Yes, so start copying the line to the command buffer. -getchar_pnt: +@print: ply #2 ; Get back the cursor index. pla #1 ; Get back the character. ldb e ; Is the temporary row position non zero? - bne reset_row ; Yes, so reset the row positon. -getchar_pt1: + bne @row ; Yes, so reset the row positon. +@print1: jsr print_char ; No, so print the character. lda a ; Get the return value. cmp #'\n' ; Is the return value, a newline? - beq getchar_ln ; Yes, so return 0. - jmp getchar_chr ; No, so return 1. -reset_row: + beq @true ; Yes, so return true. + jmp @false ; No, so return false. +@row: ldb e ; Get the temporary row position. cpb #maxrow ; Is temporary row position, at, or above the bottom of the screen? - beq reset_row2 ; Yes, so leave it as is. - bcs reset_row1 ; No, so set it to the bottom of the screen. - jmp reset_row2 ; Yes, so leave it as is. -reset_row1: + beq @row2 ; Yes, so leave it as is. + bcs @row1 ; No, so set it to the bottom of the screen. + jmp @row2 ; Yes, so leave it as is. +@row1: ldb #maxrow ; Set the row position to the bottom of the screen. -reset_row2: +@row2: stb scr_row ; Set the row position. - jmp getchar_pt1 ; Print the character. -getchar_ln: - lda #0 ; Return zero. - jmp getchar_end ; We are done. -getchar_chr: - lda #1 ; Return one. -getchar_end: - rts ; End of get char. + jmp @print1 ; Print the character. +@true: + lda #0 ; Return true. + jmp @end ; We are done. +@false: + lda #1 ; Return false. +@end: + rts ; End of getchar. cmd_cpy: @@ -372,12 +372,12 @@ cmd_cpy: sta scr_trow ; Save it for later. jsr findend ; Find the end of the line. ldb scr_str ; Has the screen been scrolled? - beq cmd_cpy3 ; No, so don't subtract the screen's starting point from the line number. -cmd_cpy2: + beq @start ; No, so don't subtract the screen's starting point from the line number. +@offset: sec ; Yes, so make sure that we don't subtract by the starting point, plus one. sbc scr_str ; Offset the row position, back by the screen's starting point. clc ; Clear the carry flag, so that nothing odd occurs. -cmd_cpy3: +@start: sta scr_row ; Set the row position to the end of the line. sta e ; Save it into the temporary row posiition. jsr findst ; Find the start of the line. @@ -395,53 +395,53 @@ cmd_cpy3: jsr set_ptr ; deb ; Set B back to zero. tba ; Set the accumulator to zero. -cmd_cpy_lp: +@loop: ldb #0 ; Reset the B register. lda.q (ptr), y ; Get eight bytes from the current line. -cmd_cpy_lp1: +@loop1: phy #2 ; Save the screen index. txy ; Get the command buffer index. sta (ptr2), y ; Copy one byte from the screen buffer, to the command buffer. inx ; Increment the command buffer index. ply #2 ; Get back the screen index. cpx.w #$3FF ; Are we at the end of the command buffer? - bcs cmd_cpy_nd0 ; Yes, so we're done. + bcs @end ; Yes, so we're done. iny ; No, so increment the screen index. inb ; Increment the byte count. lsr #8 ; Shift in the next byte. stb g ; Save the byte count. tab ; Save the string buffer. and #$FF ; Is this byte of the buffer, a null terminator? - beq cmd_cpy_nd ; Yes, so we're done. + beq @end1 ; Yes, so we're done. tba ; No so get back the string buffer. ldb g ; Get back the byte count. cpb #7 ; Did we shift in eight bytes? - beq cmd_cpy_lp ; Yes, so get eight more bytes. - jmp cmd_cpy_lp1 ; No, so keep shifting in more bytes. -cmd_cpy_nd0: + beq @loop ; Yes, so get eight more bytes. + jmp @loop1 ; No, so keep shifting in more bytes. +@end: ldb #0 ; Reset B. phy #2 ; Save the screen index. txy ; Get the command buffer index. stb (ptr2), y ; Terminate the command buffer. ply #2 ; Get back the screen index. -cmd_cpy_nd: +@end1: tab ; The B register is zero, so clear the Accumulator. rts ; End of cmd_cpy. findst: lda #0 ; Reset A. -findst_lp: +@loop: pha #1 ; Save the current line number. jsr getbit ; Is this the start of the line? pla #1 ; Get the current line number back. - bcc findst_done ; Yes, so we're done. + bcc @end ; Yes, so we're done. inc ; No, so check the next physical line. dec scr_row ; Are we at the top of the screen? - bpo findst_lp ; No, so keep looping. + bpo @loop ; No, so keep looping. dec ; Yes, so move back one line. inc scr_row ; Put the row postiion back to zero. -findst_done: +@end: cmp #0 ; Update all the flags. rts ; End of findst. @@ -454,12 +454,12 @@ fndend: tba ; Set the Accumulator to zero. plb #1 ; Restore the contents of the B register. phy #2 ; -fndend_lp: +@loop: lda (ptr), y ; Are we at the end of the string? - beq fndend_done ; Yes, so we're done. + beq @end ; Yes, so we're done. iny ; No, so increment the cursor index. - jmp fndend_lp ; Keep looping. -fndend_done: + jmp @loop ; Keep looping. +@end: sty.w scr_ptr3 ; ply #2 ; rts ; End of fndend. @@ -502,22 +502,22 @@ printc: lda #0 ; No, so start trying to print a character. sta d ; lda (ptr3), y ; Are we at the end of the string? - beq printc_save ; Yes, so just print the character. + beq @save ; Yes, so just print the character. lda b ; No, but was the flag set? - bne printc_save ; Yes, so don't shift the line. + bne @save ; Yes, so don't shift the line. sty.w scr_ptr ; No, so save the cursor index for later. jsr fndend ; Find the end of the line. - jmp prntc_movln ; Start shifting the line right. -prntc_updt: + jmp @shift ; Start shifting the line right. +@update: lda scr_col ; Save the current column position for later. sta scr_tcol ; -prntc_updt2: +@update1: jsr findend ; Find the end of the line. sta e ; Use it for redrawing the line. sta scr_row ; Set the row position to to the end of the line. jsr findst ; Find the start of the line. lda scr_row ; Get the start of the line. -prntc_updt3: +@update2: sta f ; Set the starting line, to the start of the line. jsr rdrw_ln ; Redraw the line. lda scr_trow ; Get the real row position back. @@ -526,8 +526,8 @@ prntc_updt3: sta scr_col ; jsr update_pos ; Update the cursor's position. dec d ; - jmp printc_sav1 ; -prntc_movln: + jmp @save1 ; +@shift: ldy.w scr_ptr3 ; inc scr_ptr3 ; tyx ; @@ -541,51 +541,50 @@ prntc_movln: sta (ptr3), y ; store typed character into the input buffer. lda scr_row ; sta scr_trow ; - jmp prntc_updt ; -printc_save: + jmp @update ; +@save: ldb d ; - bne prntc_updt ; -printc_sav1: + bne @update ; +@save1: lda a ; sta (ptr3), y ; store typed character into the input buffer. -printc_inc: +@incr: inc scr_col ; Increment the cursor's x coordinate. iny ; -printc_2: +@wrapped: ldb #1 ; stb f ; ldb scr_col ; cpb #maxcol+1 ; - bcs printc_4 ; -printc_3: + bcs @scrolled ; +@print: sta scr ; Echo typed character. ldb f ; - beq printc_wrap ; + beq @wrap ; jmp printc_end ; -printc_4: +@scrolled: ldb scr_row ; cpb #maxrow ; - bcs printc_scrl ; -printc_5: + bcs @scroll ; +@wrapped2: ldb #0 ; stb f ; - jmp printc_3 ; -printc_scrl: + jmp @print ; +@scroll: sta scr ; Echo typed character. clc ; lda #1 ; sta wrapped ; jsr scrl_down ; - jmp printc_wrap ; -printc_wrap: +@wrap: ldb #0 stb scr_col ; ldb scr_row ; cpb #maxrow ; - bcs printc_wrp2 ; -printc_wrap1: + bcs @wrap2 ; +@wrap1: inc scr_row ; -printc_wrp2: +@wrap2: phx #2 ; clc ; lda scr_row ; @@ -600,19 +599,19 @@ printc_end: nl: lda #0 ; Reset A. ldb (ptr3), y ; Is this character not a null terminator? - bne nl1 ; Yes, so don't overwrite it. + bne @scroll ; Yes, so don't overwrite it. sta (ptr3), y ; No, so overwrite it. -nl1: +@scroll: sta scr_col ; Move the cursor to the start of the next line. lda scr_row ; Get the row position. cmp #maxrow ; Are we at the bottom of the screen? - bcc nl_inc ; No, so move down one line. + bcc @incr ; No, so move down one line. jsr scrl_down ; Yes, so scroll down one line. - jmp nl_end ; We are done. -nl_inc: + jmp @end ; We are done. +@incr: inc scr_row ; Move the cursor down by one line. jsr update_pos ; Update the cursor's position. -nl_end: +@end: lda #'\n' ; Print the newline. sta a ; jmp printc_end ; @@ -667,13 +666,13 @@ back: sta scr_trow ; jsr findend ; Find the end of the line. sta scr_row ; Set our row position to the end of the line. -back0: +@find_st: jsr findst ; Does this line take up more than one real line? - beq back1 ; No, so skip updating any other lines. - bcs back_updt ; Yes, so update the other lines. + beq @shift ; No, so skip updating any other lines. + bcs @update ; Yes, so update the other lines. lda scr_trow ; Get the real row position back. sta scr_row ; -back1: +@shift: dey ; Decrement the buffer's offset. lda #0 ; Place a null terminator sta (ptr3), y ; into the buffer. @@ -685,8 +684,8 @@ back1: lda #$7F ; Print a backspace to the screen. sta scr ; lda e ; Are we updating more than one line? - beq back3 ; No, so skip to the next step. -back2: + beq @load ; No, so skip to the next step. +@find_end: jsr findend ; Yes, so find the end of the line. sta e ; Set the end parameter to it. lda scr_col ; Save the current column position for now. @@ -694,44 +693,44 @@ back2: jsr rdrw_ln ; Start redrawing the line. lda scr_tcol ; Get the real column position back. sta scr_col ; -back3: - lda scr_trow ; Get the real row position bac. +@load: + lda scr_trow ; Get the real row position back. sta scr_row ; dec scr_col ; Move the cursor back by one column, jsr update_pos ; and update it's position. jmp printc_end ; We are done. -back_updt: +@update: lda scr_row ; Set the line to start redrawing, to the start of the line. sta f ; inc e ; Set the redraw flag to true. - jmp back1 ; Start shifting the line back. + jmp @shift ; Start shifting the line back. bs: lda scr_col ; Are we at the far left of the screen? - beq back_wrap ; Yes, so check for a wrapped line. + beq @wrap ; Yes, so check for a wrapped line. jmp back ; No, so add the backspace to the buffer. -back_wrap: +@wrap: jsr getbit ; Is this line, a wrapped line? - bcs back_wrap1 ; Yes, so check if the cursor is at the top. + bcs @wrap1 ; Yes, so check if the cursor is at the top. jmp printc_end ; No, so we're done. -back_wrap1: +@wrap1: lda scr_row ; Are we at the top of the screen? - beq back_wrap2 ; Yes, so check if the screen is at the top of the buffer. - jmp backwrp ; No, so start clearing the wrap bit. -back_wrap2: + beq @wrap2 ; Yes, so check if the screen is at the top of the buffer. + jmp @wrap3 ; No, so start clearing the wrap bit. +@wrap2: lda scr_str ; Are we at the top of the buffer? - bne back_scrl ; Yes, so scroll up. + bne @scroll ; Yes, so scroll up. jmp printc_end ; No, so we're done. -back_scrl: +@scroll: clc ; Clear the carry flag, so that we don't get odd behaviour. jsr scrl_up ; Scroll up. inc scr_row ; Move down by one row. -backwrp: +@wrap3: clc ; Clear the carry flag. lda scr_row ; Add the cursor's row position, adc scr_str ; and the screen's starting row. tax ; Transfer that into X. -backwrp2: +@wrap4: dec scr_row ; Move up by one row. ldb #maxcol+1 ; Move the cursor to the absolute right of the screen. stb scr_col ; @@ -740,20 +739,20 @@ backwrp2: shftln: ldb d ; Is the flag not set? - beq shftln_lp1 ; Yes, so shift, and decrement. + beq @dec_loop ; Yes, so shift, and decrement. ldb #0 ; Clear the B register. - jmp shftln_lp0 ; No, so shift, and increment. -shftln_neg: + jmp @inc_loop ; No, so shift, and increment. +@neg: ldy.w zero ; Set the source poition to 0. stb (ptr3), y ; Clear the character that is in the source. - jmp shftln_end ; We are done. -shftln_lp0: + jmp @end ; We are done. +@inc_loop: sty.w scr_ptr2 ; Save the source position for later. ldy.w scr_ptr ; Get the previous cursor index. cpy.w scr_ptr2 ; Is the source position, at, or below the cursor index? - beq shftln_lp01 ; Yes, so keep looping. - bcs shftln_end ; No, so we're done. -shftln_lp01: + beq @inc_loop1 ; Yes, so keep looping. + bcs @end ; No, so we're done. +@inc_loop1: ldy.w scr_ptr2 ; Get the source position. lda (ptr3), y ; Get the character from the source position. phy #2 ; Save the source position for later. @@ -761,14 +760,14 @@ shftln_lp01: sta (ptr3), y ; Place the character from the source position, to the destination position. ply #2 ; Set our position back to the source. stb (ptr3), y ; Clear the character that is in the source. - bng shftln_neg ; The source underflowed, so set it back to zero, + bng @neg ; The source underflowed, so set it back to zero, dey ; Decrement the source position. dex ; Decrement the destination position. - jmp shftln_lp0 ; Keep looping. -shftln_lp1: + jmp @inc_loop ; Keep looping. +@dec_loop: stx.w scr_ptr2 ; Save the destination position for later. lda (ptr3), y ; Is the character at the source position, a null terminator? - beq shftln_end1 ; Yes, so we're done. + beq @end3 ; Yes, so we're done. phy #2 ; No, so save the source position for later. txy ; Set our position to the destination. sta (ptr3), y ; Place the character from the source position, to the destination position. @@ -776,44 +775,44 @@ shftln_lp1: ply #2 ; Set our position back to the source. stb (ptr3), y ; Clear the character that is in the source. iny ; Increment the source position. - jmp shftln_lp1 ; Keep looping. -shftln_wrap: + jmp @dec_loop ; Keep looping. +@wrap: tax ; Use the ending line as a parameter for setbit. jsr setbit ; Set the wrap bit of the ending line. - jmp shftln_end2 ; We are done. -shftln_wrp1: + jmp @end5 ; We are done. +@wrap1: tax ; Use the ending line as a parameter for clrbit. jsr clrbit ; Clear the wrap bit of the ending line. - jmp shftln_end2 ; We are done. -shftln_end: + jmp @end5 ; We are done. +@end: lda (ptr3), y ; Is this character a null terminator? - bne shftln_nd0 ; No, so just find the end of the line. + bne @end1 ; No, so just find the end of the line. lda #$20 ; Yes, so convert it to a space for now. sta (ptr3), y ; -shftln_nd0: +@end1: jsr findend ; Find the ending line. sta d ; Save ending line for later. lda (ptr3), y ; Is this character a space? cmp #$20 ; - bne shftln_nd1 ; No, so skip the conversion. + bne @end5 ; No, so skip the conversion. lda #0 ; Yes, so convert it back to zero. sta (ptr3), y ; -shftln_nd1: +@end2: lda d ; Get the ending line. cmp scr_row ; Is the ending line greater than the starting line? - beq shftln_end2 ; No, so we're done. - bcs shftln_wrap ; Yes, so set the wrap bit. - jmp shftln_end2 ; No, so we're done. -shftln_end1: + beq @end5 ; No, so we're done. + bcs @wrap ; Yes, so set the wrap bit. + jmp @end5 ; No, so we're done. +@end3: jsr findend ; Find the ending line. cpb #0 ; Is the remainder zero? - beq shftln_nd2 ; Yes, so check if the ending line is greater than the starting line. - jmp shftln_end2 ; No, so we're done. -shftln_nd2: + beq @end4 ; Yes, so check if the ending line is greater than the starting line. + jmp @end5 ; No, so we're done. +@end4: cmp scr_row ; Is the ending line greater than the starting line? - beq shftln_end2 ; No, so we're done. - bcs shftln_wrp1 ; Yes, so clear the wrap bit. -shftln_end2: + beq @end5 ; No, so we're done. + bcs @wrap1 ; Yes, so clear the wrap bit. +@end5: rts ; End of shftln. esc: @@ -864,35 +863,36 @@ shftesc_end: isup: lda c ; Load the escape code into the accumulator. cmp #'A' ; Did the user press the up arrow key? - bne isup_done ; No, so we're done. + bne @end ; No, so we're done. lda scr_row ; Yes, but is the cursor at the top of the screen? - beq isup_scrl ; Yes, so check if we need to scroll. -isup_2: + beq @scroll ; Yes, so check if we need to scroll. +@check2: lda c ; No, so load the escape code back into the accumulator. cmp #'A' ; Did the user press the up arrow key? beq up ; Yes, so move the cursor up. - jmp isup_done ; No, so we're done -isup_scrl: + jmp @end ; No, so we're done. +@scroll: lda scr_str ; Are we at the top of the screen buffer? - beq isup_done ; Yes, so we're done. + beq @end ; Yes, so we're done. jsr scrl_up ; No, so scroll up. lda #1 ; Tell the escape routine that we were successful. sta d ; +@end: isup_done: rts ; End of isup. isdown: lda c ; Load the escape code into the accumulator. cmp #'B' ; Did the user press the down arrow key? - bne isdown_done ; No, so we're done. + bne @end ; No, so we're done. lda scr_row ; Yes, so start checking the y coordinate of the cursor. cmp #maxrow ; Is the cursor at the bottom of the screen? - beq isdown_scrl ; Yes, so scroll down. + beq @scroll ; Yes, so scroll down. lda c ; No, so load the escape code back into the accumulator. cmp #'B' ; Did the user press the down arrow key? beq down ; Yes, so move the cursor down. - jmp isdown_done -isdown_scrl: + jmp @end ; No, so we're done. +@scroll: lda scr_row ; Save the cursor's row number. sta scr_trow ; lda scr_col ; Save the cursor's column number. @@ -904,42 +904,44 @@ isdown_scrl: sta scr_col ; lda #1 ; Tell the escape routine that we were successful. sta d ; +@end: isdown_done: rts ; End of isdown. isright: lda c ; Load the escape code into the accumulator. cmp #'C' ; Did the user press the right arrow key? - bne isright_dne ; No, so we're done. + bne @end2 ; No, so we're done. lda scr_col ; Yes, so start checking the x coordinate of the cursor. cmp #maxcol ; Is the cursor at the far right of the screen? - beq isright_wrp ; Yes, so check if this is a wrapped line. + beq @wrap ; Yes, so check if this is a wrapped line. jmp right ; No, so move the cursor right, like normal. -isright_wrp: +@wrap: inc scr_row ; Move down a row. jsr getbit ; Is the current line, a wrapped line? - bcs wrap_inc ; Yes, so leave the cursor where it is. + bcs @incr ; Yes, so leave the cursor where it is. dec scr_row ; No, so move the cursor back up a row. - jmp isright_dne ; We are done. -isright_scr: + jmp @end2 ; We are done. +@scroll: lda scr_str ; Are we at the top of the screen buffer? - beq isright_end ; Yes, so we're done. + beq @end ; Yes, so we're done. lda #1 ; No, so scroll down. sta wrapped ; Set the wrapped flag. jsr scrl_down ; Scroll down. - jmp isright_end ; We are done. -wrap_inc: + jmp @end ; We are done. +@incr: lda #0 ; Set the cursor to the far left of the screen. sta scr_col ; lda scr_row ; Get the current row number. cmp #maxrow ; Are we at the bottom of the screen? - beq isright_nd2 ; No, so we're done. - bcs isright_scr ; Yes, so check if we are scrolling down. - jmp isright_nd2 ; No, so we're done. -isright_end: + beq @end1 ; No, so we're done. + bcs @scroll ; Yes, so check if we are scrolling down. + jmp @end1 ; No, so we're done. +@end: dec scr_row ; Move back up a row. -isright_nd2: +@end1: jsr update_pos ; Update the cursor position. +@end2: isright_dne: lda #0 ; Unset the wrapped flag. sta wrapped ; @@ -948,40 +950,41 @@ isright_dne: isleft: lda c ; Load the escape code into the accumulator. cmp #'C' ; Did the user press right? - beq isleft_done ; Yes, so we're done + beq @end1 ; Yes, so we're done lda scr_col ; No, but is the cursor at the far left of the screen? - beq isleft_wrp ; Yes, so start checking if this is a wrapped line. + beq @wrap ; Yes, so start checking if this is a wrapped line. lda c ; No, so load the escape code back into the accumulator. cmp #'D' ; Did the user press the left arrow key? beq left ; Yes, so move the cursor left. - jmp isleft_done ; No, so we're done. -isleft_wrp: + jmp @end1 ; No, so we're done. +@wrap: jsr getbit ; Is the current line, a wrapped line? - bcs wrap_dec ; Yes, so wrap back up a line. - jmp isleft_done ; No, so we're done. -wrap_dec: + bcs @decr ; Yes, so wrap back up a line. + jmp @end1 ; No, so we're done. +@decr: lda scr_row ; Is the cursor at the top of the screen? - beq wrap_dec1 ; Yes, so don't move up a line. + beq @decr1 ; Yes, so don't move up a line. lda #1 ; No, so set the wrapped flag. sta wrapped ; dec scr_row ; Move the cursor up one line. -wrap_dec1: +@decr1: lda #maxcol ; Move the Cursor to the far right of the screen. sta scr_col ; lda #1 ; Tell the escape routine that we were successful. sta d ; lda scr_row ; Are we at the top of the screen? - beq isleft_scrl ; Yes, so check if we need to scroll. - jmp isleft_end ; No, so we're done. -isleft_scrl: + beq @scroll ; Yes, so check if we need to scroll. + jmp @end ; No, so we're done. +@scroll: lda wrapped ; Was the wrapped flag set somewhere else? - bne isleft_end ; Yes so we're done. + bne @end ; Yes so we're done. lda scr_str ; No, but are we actually at the top of the screen buffer? - beq isleft_done ; Yes, so we're done. + beq @end1 ; Yes, so we're done. jsr scrl_up ; No, so scroll up. - jmp isleft_done ; We are done. -isleft_end: + jmp @end1 ; We are done. +@end: jsr update_pos ; Update the cursor position. +@end1: isleft_done: lda #0 ; Unset the wrapped flag. sta wrapped ; @@ -1082,7 +1085,7 @@ getcol: sta scr ; to the screen. lda scr_col ; Get the cursor's x coordinate. div #10 ; Divide A by 10. - clc + clc ; adc #'0' ; Convert it to ascii, and sta scr ; print to the screen. tba ; Get the remainder. @@ -1103,26 +1106,26 @@ scrl_down: lda scr_row ; Get the cursor's line number. pha #1 ; Save it in the stack. lda wrapped ; Was the wrapped flag set? - beq scrldn_save ; Yes, so save the cursor position. -scrldn1: - jsr rdrw_row ; Redraw this row. + beq @save ; Yes, so save the cursor position. +@redraw: + jsr rdrw_row ; No, so redraw this row. lda wrapped ; Was the wrapped flag set? - beq scrldn_load ; Yes, so load the previous cursor position back. - jmp scrldn_end ; No, so we're done. -scrldn_save: + beq @load ; Yes, so load the previous cursor position back. + jmp @end ; No, so we're done. +@save: lda scr_col ; Get the cursor's column number. pha #1 ; Save it in the stack. - jmp scrldn1 ; Start redrawing the current row. -scrldn_load: + jmp @redraw ; Start redrawing the current row. +@load: pla #1 ; Get the cursor's previous column number back. sta scr_col ; -scrldn_end: +@end: pla #1 ; Get the cursor's previous line number back. sta scr_row ; jsr update_pos ; Update the cursor's position. lda #0 ; Clear the wrapped flag. sta wrapped ; -scrldn_done: +@end1: rts ; End of scrl_down. scrl_up: @@ -1146,37 +1149,37 @@ scrl_up: pla #1 ; sta scr_row ; jsr update_pos ; -scrlup_done: +@end: rts ; rdrw_row: lda #0 ; sta scr_col ; jsr update_pos ; -rdrow_st: +@loop: lda (ptr3), y ; - beq rdrow_inc ; + beq @incr ; sta scr ; -rdrow_inc: +@incr: inc scr_col ; lda (ptr3), y ; - beq rdrow_skip ; -rdrow_inc1: + beq @skip ; +@incr1: iny ; -rdrow_inc2: +@incr2: lda scr_col ; cmp #maxcol+1 ; - bcs rdrow_end ; - jmp rdrow_st ; -rdrow_skip: + bcs @end ; + jmp @loop ; +@skip: lda #' ' ; sta scr ; to the screen. - jmp rdrow_inc1 ; -rdrow_end: + jmp @incr1 ; +@end: lda #0 ; sta scr_col ; jsr update_pos ; -rdrow_done: +@end1: rts ; rdrw_ln: @@ -1187,17 +1190,17 @@ rdrw_ln: lda scr_col ; pha #1 ; jsr update_pos ; -rdrwln_lp: +@loop: lda scr_row ; cmp e ; - beq rdrwln_lp1 ; - bcs rdrwln_done ; -rdrwln_lp1: + beq @loop1 ; + bcs @end ; +@loop1: jsr rdrw_row ; -rdrwln_inc: +@incr: inc scr_row ; - jmp rdrwln_lp ; -rdrwln_done: + jmp @loop ; +@end: pla #1 ; sta scr_col ; pla #1 ; @@ -1210,21 +1213,21 @@ rdrwln_done: set_ptr: cpb #1 ; Are we setting the second pointer? - beq set_ptr2 ; Yes, so start setting it. + beq @ptr2 ; Yes, so start setting it. cpb #2 ; No, but are we setting the third pointer? - beq set_ptr3 ; Yes, so start setting it. -set_ptr1: + beq @ptr3 ; Yes, so start setting it. +@ptr1: stb.q ptr ; Reset the first pointer. sta.q ptr ; No, so set the first pointer. - jmp setptr_end ; We are done. -set_ptr2: + jmp @end ; We are done. +@ptr2: stb.q ptr2 ; Reset the second pointer. sta.q ptr2 ; Set the second pointer. - jmp setptr_end ; We are done. -set_ptr3: + jmp @end ; We are done. +@ptr3: stb.q ptr3 ; Reset the third pointer. sta.q ptr3 ; Set the third pointer. -setptr_end: +@end: rts ; End of set_ptr. ; Entry point for SuBAsm. diff --git a/programs/utils.s b/programs/utils.s index a6a14f3..6032a47 100644 --- a/programs/utils.s +++ b/programs/utils.s @@ -30,7 +30,7 @@ print_hi: print_lo: lda #0 ; Reset A. sta idx3 ; Clear the string index. -pntlo_lp: +@loop: ldx #2 ; Set digit count to 2. pha #1 ; Preserve the nibble offset. jsr print_hex ; Print the low nibble offset. @@ -41,14 +41,14 @@ pntlo_lp: pla #1 ; Get the nibble offset back. inc ; Increment the offset. cmp #$10 ; Are we at the last offset? - bcs pntlo_end ; Yes, so we're done. -pntlo_lp1: + bcs @end ; Yes, so we're done. +@loop1: pha #1 ; No, so preserve the nibble offset. lda #' ' ; Add a space to the string buffer. jsr charcpy ; pla #1 ; Get the nibble offset back. - jmp pntlo_lp ; Keep looping. -pntlo_end: + jmp @loop ; Keep looping. +@end: inx ; Increment the index by one. lda #0 ; Null terminate the string buffer. sta strbuf, x ; @@ -61,7 +61,7 @@ print_chunk: ldx #0 ; Reset X. phy #2 ; Preserve the screen buffer index. txy ; Copy the byte index to it. -pntchnk_lp: +@loop: and #0 ; Reset A. ldx #2 ; Set the digit count to 2. lda (idx0), y ; Get the byte at that address. @@ -72,11 +72,11 @@ pntchnk_lp: jsr charcpy ; iny ; Increment the byte index. cpy #$10 ; Have we read 16 bytes? - beq pntchnk_end ; Yes, so we're done. + beq @end ; Yes, so we're done. lda #' ' ; No, so add a soace to the string buffer. jsr charcpy ; - jmp pntchnk_lp ; Keep looping. -pntchnk_end: + jmp @loop ; Keep looping. +@end: ply #2 ; Get the screen buffer index back. inx ; Increment the index by one. and #0 ; Null terminate the string. @@ -99,7 +99,7 @@ print_hex: jsr set_ptr ; ldb #0 ; Reset B. pla #8 ; Get the hex value back. -pnthex_lp: +@loop: pha #8 ; Preserve the hex value. and #$F ; Mask the lowest nibble. phy #2 ; Preserve the screen buffer position. @@ -109,23 +109,23 @@ pnthex_lp: sta (ptr3) ; Save the hex digit character in the string. ply #2 ; Get back the screen buffer position. pla #8 ; Get the hex value back. -pnthex_lp1: +@isauto: cpx #1 ; Is the digit count less than one? - bcc pnthex_lp2 ; Yes, so don't decrement the digit count. + bcc @auto ; Yes, so don't decrement the digit count. dex ; No, but was the digit count zero, when decremented? - beq pnthex_end ; Yes, so we're done. - jmp pnthex_lp3 ; No, so get the next nibble. -pnthex_lp2: + beq @end ; Yes, so we're done. + jmp @next ; No, so get the next nibble. +@auto: ldb #1 ; Enable auto digit count. -pnthex_lp3: - lsr #4 ; No, but is the next nibble, a zero? - beq pnthex_lp4 ; Yes, so check if auto digit count is enabled. - jmp pnthex_lp ; No, so print the next digit. -pnthex_lp4: +@next: + lsr #4 ; Is the next nibble, a zero? + beq @isauto1 ; Yes, so check if auto digit count is enabled. + jmp @loop ; No, so print the next digit. +@isauto1: cpb #1 ; Is auto digit count enabled? - beq pnthex_end ; Yes, so we're done. - jmp pnthex_lp ; No, so keep printing more digits. -pnthex_end: + beq @end ; Yes, so we're done. + jmp @loop ; No, so keep printing more digits. +@end: rts ; End of print_hex. @@ -103,23 +103,14 @@ void *run(void *args) { } wmove(scr, lines, 1); wclrtoeol(scr); - wprintw(scr, - "pc: $%04"PRIX64 - ", a: $%016"PRIX64 - ", b: $%016"PRIX64 - ", x: $%016"PRIX64 - ", y: $%016"PRIX64 - , cpu->pc[thread] - , cpu->a[thread] - , cpu->b[thread] - , cpu->x[thread] - , cpu->y[thread]); - wprintw(scr, - ", sp: $%04X" - ", ps: $%02X" - ", inst: " - , cpu->sp[thread] - , cpu->ps.u8[thread]); + wprintw(scr, "pc: $%04"PRIX64 , cpu->pc[thread]); + wprintw(scr, ", a: $%016"PRIX64, cpu->a[thread]); + wprintw(scr, ", b: $%016"PRIX64, cpu->b[thread]); + wprintw(scr, ", x: $%016"PRIX64, cpu->x[thread]); + wprintw(scr, ", y: $%016"PRIX64, cpu->y[thread]); + wprintw(scr, ", sp: $%04X", cpu->sp[thread]); + wprintw(scr, ", ps: $%02X", cpu->ps.u8[thread]); + wprintw(scr, ", inst: "); #if keypoll pthread_mutex_unlock(&mutex); #endif |