diff options
Diffstat (limited to 'asmmon.c')
-rw-r--r-- | asmmon.c | 86 |
1 files changed, 62 insertions, 24 deletions
@@ -1,4 +1,6 @@ #include "asmmon.h" +#include "lexer.h" + uint16_t linenum = 10; uint16_t lineidx = 0; uint16_t stridx = 0; @@ -34,9 +36,9 @@ void viewmem(uint64_t address) { } puts("\n"); for (uint8_t hi = 0; hi < 0x10; hi++) { - printf("$%016"PRIX64":\t", (address & ~0xF)+(hi << 4)); + printf("$%016"PRIX64":\t", (address)+(hi << 4)); for (uint8_t lo = 0; lo < 0x10; lo++) { - printf("%02X", addr[(address & ~0xF)+lo+(hi << 4)]); + printf("%02X", addr[(address)+lo+(hi << 4)]); if (lo < 0x0F) { putchar(' '); } @@ -367,6 +369,7 @@ int asmmon(const char *fn) { char lex_line[0x1000]; uint16_t size = 0; uint8_t cmds = 0; + uint8_t is_valid = 0; /* Is single character command. */ uint8_t isshcmd = 0; if (!isinclude) { @@ -385,20 +388,52 @@ int asmmon(const char *fn) { memcpy(cmd, lex_line, size); cmd = strtok_r(cmd, " \t\n", &tmp); if (cmd != NULL) { - isshcmd = (cmd[1] == '\0' || cmd[1] == ' '); - switch (cmd[0]) { - case 'q': cmds = (isshcmd || !strcasecmp(cmd, "quit" )) << 0; break; - case 'v': cmds = (isshcmd || !strcasecmp(cmd, "viewmem")) << 1; break; - case 'l': cmds = (isshcmd || !strcasecmp(cmd, "list" )) << 2; break; - case 'a': cmds = (isshcmd || !strcasecmp(cmd, "asm" )) << 3; break; - case 'h': cmds = (isshcmd || !strcasecmp(cmd, "help" )) << 4; break; - case 'i': cmds = (isshcmd || !strcasecmp(cmd, "inst" )) << 5; break; - case 'd': cmds = (isshcmd || !strcasecmp(cmd, "done" )) << 6; break; - case 's': cmds = (isshcmd || !strcasecmp(cmd, "set" )) << 7; break; - case ' ': - case '\t': - cmds = 0xFF; - break; + int cmd_len = strlen(cmd); + isshcmd = (cmd_len > 0 && cmd_len <= 3 && (cmd[1] == '\0' || cmd[1] == ' ')); + if (tmp) { + int stop = 0; + for (int i = 0; !(isdelm(tmp[i], 0) & 1) && !stop; i++) { + switch (get_ptok(tmp[i], 0)) { + case PTOK_NUMBER : + case PTOK_ALPHA : + case PTOK_DOLLAR : + case PTOK_PERCENT: + case PTOK_DQUOTE : + case PTOK_SQUOTE : + case PTOK_B : + case PTOK_X : + case PTOK_Y : + case PTOK_S : + case PTOK_P : + case PTOK_MINUS : + case PTOK_PLUS : is_valid = 1; break; + default : is_valid = 0; stop = 1; break; + } + } + if (strlen(tmp) <= 1) { + is_valid = 1; + } + } + if (is_valid) { + switch (cmd[0]) { + case 'q': cmds = (isshcmd || !strcasecmp(cmd, "quit" )) << 0; break; + case 'v': cmds = (isshcmd || !strcasecmp(cmd, "viewmem")) << 1; break; + case 'l': cmds = (isshcmd || !strcasecmp(cmd, "list" )) << 2; break; + case 'a': cmds = (isshcmd || !strcasecmp(cmd, "asm" )) << 3; break; + case 'h': cmds = (isshcmd || !strcasecmp(cmd, "help" )) << 4; break; + case 'i': cmds = (isshcmd || !strcasecmp(cmd, "inst" )) << 5; break; + case 'd': cmds = (isshcmd || !strcasecmp(cmd, "done" )) << 6; break; + case 's': cmds = (isshcmd || !strcasecmp(cmd, "set" )) << 7; break; + case ' ': + case '\t': + default: + is_valid = 0; + cmds = 0xFF; + break; + } + if (!cmds) { + is_valid = 0; + } } switch (cmds) { case 0x01: @@ -525,13 +560,14 @@ int asmmon(const char *fn) { } break; case 0x40: - done = 1; - break; + done = 1; + break; case 0x80: if (tmp != NULL) { uint16_t i = 0; uint16_t j = 0; uint8_t isdebug = 0; + is_valid = 0; while (tmp[i] != '\0') { if (isspace(tmp[i])) { for (; isspace(tmp[i]); i++); @@ -541,6 +577,7 @@ int asmmon(const char *fn) { j = 0; isdebug = (arg[j] == 'd' || !strcasecmp(arg, "debug")); if (isdebug) { + is_valid = 1; dbg = !dbg; if (dbg) { puts("Debug mode has been enabled."); @@ -550,14 +587,15 @@ int asmmon(const char *fn) { } i++; } + } else { + is_valid = 0; } - break; case 0xFF: - break; - default: - address = lex(lex_line, address, bline, dbg); - bline = 0; - break; + default : break; + } + if (!is_valid) { + address = lex(lex_line, address, bline, dbg); + bline = 0; } } else if (lex_line[0] == '\n') { bline++; |