From 545bb8591e8003912b6c6b494acefd74e6b3abfd Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 9 May 2020 14:14:08 -0400 Subject: Added support for single quote marks to the emulator's assembler. Single quote marks works in the assembler just like they do in C, except that it only supports a handful of escaped characters, like '\n', and '\r'. --- asmmon.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 14 deletions(-) (limited to 'asmmon.c') diff --git a/asmmon.c b/asmmon.c index 453ff3c..198254c 100644 --- a/asmmon.c +++ b/asmmon.c @@ -114,6 +114,8 @@ void list(struct line *l, uint16_t start, uint16_t end, uint8_t all, uint8_t ln, uint8_t spaces; uint8_t tabs; char mne_lower[4]; + char ch[6]; + if (all) { end = lineidx; } @@ -202,10 +204,28 @@ void list(struct line *l, uint16_t start, uint16_t end, uint8_t all, uint8_t ln, } } + j = 0; + + if (l[i].opbase == BASE_CHAR) { + switch (l[i].op) { + default : ch[j++] = l[i].op; 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; + switch (l[i].opbase) { - case BASE_HEX: printf("$%"PRIX64, l[i].op); break; - case BASE_DEC: printf("%"PRIu64, l[i].op); break; - case BASE_BIN: printf("%%%s", showbits(l[i].op, bitnum, dbg)); break; + case BASE_HEX: printf("$%"PRIX64, l[i].op); break; + case BASE_DEC: printf("%"PRIu64, l[i].op); break; + case BASE_BIN: printf("%%%s", showbits(l[i].op, bitnum, dbg)); break; + case BASE_CHAR: printf("\'%s\'", ch); break; } bitnum = 0; opsize = 0; @@ -226,10 +246,29 @@ void list(struct line *l, uint16_t start, uint16_t end, uint8_t all, uint8_t ln, if (opsize) { bitnum = bitsize[opsize-1]; } + + j = 0; + + if (l[i].aopbase == BASE_CHAR) { + switch (l[i].aop) { + default : ch[j++] = l[i].aop; 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; + switch (l[i].aopbase) { - case BASE_HEX: printf("$%"PRIX64, l[i].aop); break; - case BASE_DEC: printf("%"PRIu64, l[i].aop); break; - case BASE_BIN: printf("%%%s", showbits(l[i].aop, bitnum, dbg)); break; + case BASE_HEX : printf("$%"PRIX64, l[i].aop); break; + case BASE_DEC : printf("%"PRIu64, l[i].aop); break; + case BASE_BIN : printf("%%%s", showbits(l[i].aop, bitnum, dbg)); break; + case BASE_CHAR: printf("\'%s\'", ch); break; } bitnum = 0; opsize = 0; @@ -443,14 +482,7 @@ uint64_t assemble(struct line *line, uint8_t dbg) { } tmpaddr += tmp; tmp = 0; - if (skip || flags & 0x80) { - if (dbg) { - printf("assemble(): The address that this line starts at is, $%"PRIX64".\n", address); - printf("assemble(): The address that this line ends on is, $%"PRIX64".\n", tmpaddr); - } - continue; - } - if (flags == 0x108) { + if (skip | (flags & 0x80) | (flags == 0x108)) { if (dbg) { printf("assemble(): The address that this line starts at is, $%"PRIX64".\n", address); printf("assemble(): The address that this line ends on is, $%"PRIX64".\n", tmpaddr); -- cgit v1.2.3-13-gbd6f