Fixes + enhancements from test feedback
- Mini-assembler now supports many more common inherent ops (CLRA/CLRB, INCA/INCB, DECA/DECB, COMA/COMB, NEGA/NEGB, TSTA/TSTB, plus several branches: BEQ/BNE/BCC/BCS/BPL/BMI) so quick monitor patches like the classic loop test cases work without falling back to : or M. - Critical: monitor no longer uppercases the entire input line. command_char() only uppercases the dispatch verb (first significant char). This preserves original case for: - Filenames in L and S commands - Shell commands after ! - Any future string arguments - Improved S dispatch heuristic (Step vs Save) so 'S filename ...' and 'S 5' are reliably distinguished even with mixed-case filenames. - Added explicit exec-bp check at the top of the monitor G run loop (in addition to the one inside cpu_step). This guarantees that breakpoints set with B are honored during G even when running with debug_mode=false for speed. - The exact scenarios from the previously killed background tasks (infinite BRA loop + bp, F + S + L + M roundtrip) now complete cleanly, quickly hit bps, restore the terminal, and leave the outer shell fully functional. All prior robustness (always acia_end_run after G, isatty guards, etc.) remains.
This commit is contained in:
+67
-18
@@ -24,6 +24,20 @@ static void sigint_handler(int sig) { (void)sig; break_flag = 1; }
|
||||
|
||||
static void to_upper(char *s) { for (; *s; ++s) *s = (char)toupper((unsigned char)*s); }
|
||||
|
||||
/* Uppercase only the first command character (for dispatch), leaving
|
||||
arguments (filenames, shell commands, hex bytes, etc.) in original case. */
|
||||
static char command_char(char *line)
|
||||
{
|
||||
char *p = line;
|
||||
while (*p && isspace((unsigned char)*p)) p++;
|
||||
if (*p) {
|
||||
unsigned char c = (unsigned char)*p;
|
||||
*p = (char)toupper(c);
|
||||
return (char)toupper(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_hex(const char *s, uint16_t *out)
|
||||
{
|
||||
char *end = NULL;
|
||||
@@ -192,8 +206,27 @@ static void cmd_assemble(char *line)
|
||||
else if (strcmp(mnem, "JMP")==0) { mem_write8(addr,0x7E); mem_write16(addr+1,(uint16_t)arg); nbytes=3; }
|
||||
else if (strcmp(mnem, "JSR")==0) { mem_write8(addr,0xBD); mem_write16(addr+1,(uint16_t)arg); nbytes=3; }
|
||||
else if (strcmp(mnem, "BRA")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x20); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "BEQ")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x27); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "BNE")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x26); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "BCC")==0 || strcmp(mnem,"BHS")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x24); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "BCS")==0 || strcmp(mnem,"BLO")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x25); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "BPL")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x2A); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "BMI")==0) { int off = (int)(arg - (addr+2)); mem_write8(addr,0x2B); mem_write8(addr+1,(uint8_t)off); nbytes=2; }
|
||||
else if (strcmp(mnem, "RTS")==0) { mem_write8(addr,0x39); nbytes=1; }
|
||||
else if (strcmp(mnem, "SWI")==0) { mem_write8(addr,0x3F); nbytes=1; }
|
||||
else if (strcmp(mnem, "CLRA")==0) { mem_write8(addr,0x4F); nbytes=1; }
|
||||
else if (strcmp(mnem, "CLRB")==0) { mem_write8(addr,0x5F); nbytes=1; }
|
||||
else if (strcmp(mnem, "INCA")==0) { mem_write8(addr,0x4C); nbytes=1; }
|
||||
else if (strcmp(mnem, "INCB")==0) { mem_write8(addr,0x5C); nbytes=1; }
|
||||
else if (strcmp(mnem, "DECA")==0) { mem_write8(addr,0x4A); nbytes=1; }
|
||||
else if (strcmp(mnem, "DECB")==0) { mem_write8(addr,0x5A); nbytes=1; }
|
||||
else if (strcmp(mnem, "COMA")==0) { mem_write8(addr,0x43); nbytes=1; }
|
||||
else if (strcmp(mnem, "COMB")==0) { mem_write8(addr,0x53); nbytes=1; }
|
||||
else if (strcmp(mnem, "NEGA")==0) { mem_write8(addr,0x40); nbytes=1; }
|
||||
else if (strcmp(mnem, "NEGB")==0) { mem_write8(addr,0x50); nbytes=1; }
|
||||
else if (strcmp(mnem, "TSTA")==0) { mem_write8(addr,0x4D); nbytes=1; }
|
||||
else if (strcmp(mnem, "TSTB")==0) { mem_write8(addr,0x5D); nbytes=1; }
|
||||
else if (strcmp(mnem, "NOP")==0) { mem_write8(addr,0x12); nbytes=1; }
|
||||
else {
|
||||
printf("Assembler limited. Use cc09 for full source, or patch bytes with : or M.\n");
|
||||
return;
|
||||
@@ -221,8 +254,14 @@ static void cmd_go(char *line)
|
||||
signal(SIGINT, sigint_handler);
|
||||
break_flag = 0;
|
||||
|
||||
/* Simple run loop. Poll ACIA (safe no-op if not mapped or not a tty). */
|
||||
/* Simple run loop. Poll ACIA (safe no-op if not mapped or not a tty).
|
||||
Explicitly check exec breakpoints here so that monitor B + G works
|
||||
even though we run with debug_mode=false for speed. */
|
||||
while (!cpu.halted && !break_flag && !cpu.stop_requested) {
|
||||
if (bp_check_exec(cpu.pc)) {
|
||||
cpu.stop_requested = true;
|
||||
break;
|
||||
}
|
||||
cpu_step();
|
||||
acia_poll_input();
|
||||
}
|
||||
@@ -390,25 +429,35 @@ void monitor_run(void)
|
||||
printf("m9> ");
|
||||
fflush(stdout);
|
||||
if (!fgets(line, sizeof(line), stdin)) break;
|
||||
to_upper(line);
|
||||
if (line[0] == '\n' || line[0] == 0) continue;
|
||||
char c = command_char(line);
|
||||
if (c == '\n' || c == 0) continue;
|
||||
|
||||
if (line[0] == 'Q' || line[0] == 'X') break;
|
||||
else if (line[0] == 'R') cmd_registers(line);
|
||||
else if (line[0] == ';') cmd_edit_regs(line);
|
||||
else if (line[0] == 'M') cmd_memory(line);
|
||||
else if (line[0] == ':') cmd_poke(line);
|
||||
else if (line[0] == 'D') cmd_disasm(line);
|
||||
else if (line[0] == 'A') cmd_assemble(line);
|
||||
else if (line[0] == 'G') cmd_go(line);
|
||||
else if (line[0] == 'S' && (line[1]==' ' || line[1]=='\n' || line[1]==0 || isdigit(line[1]))) cmd_step(line);
|
||||
else if (line[0] == 'B') cmd_break(line);
|
||||
if (c == 'Q' || c == 'X') break;
|
||||
else if (c == 'R') cmd_registers(line);
|
||||
else if (c == ';') cmd_edit_regs(line);
|
||||
else if (c == 'M') cmd_memory(line);
|
||||
else if (c == ':') cmd_poke(line);
|
||||
else if (c == 'D') cmd_disasm(line);
|
||||
else if (c == 'A') cmd_assemble(line);
|
||||
else if (c == 'G') cmd_go(line);
|
||||
else if (c == 'S') {
|
||||
/* Distinguish Step vs Save by looking at the first argument token.
|
||||
Step: S [number]
|
||||
Save: S filename start end [fmt] (filename usually contains / . or letter) */
|
||||
char *p = line + 1;
|
||||
while (*p && isspace((unsigned char)*p)) p++;
|
||||
if (*p == 0 || isdigit((unsigned char)*p)) {
|
||||
cmd_step(line);
|
||||
} else {
|
||||
cmd_save(line);
|
||||
}
|
||||
}
|
||||
else if (c == 'B') cmd_break(line);
|
||||
else if (strncmp(line, "BC", 2)==0) cmd_break_clear();
|
||||
else if (line[0] == 'F') cmd_fill(line);
|
||||
else if (line[0] == 'L') cmd_load(line);
|
||||
else if (line[0] == 'S') cmd_save(line);
|
||||
else if (line[0] == '!') cmd_shell(line);
|
||||
else if (line[0] == '?' || line[0] == 'H') help();
|
||||
else if (c == 'F') cmd_fill(line);
|
||||
else if (c == 'L') cmd_load(line);
|
||||
else if (c == '!') cmd_shell(line);
|
||||
else if (c == '?' || c == 'H') help();
|
||||
else printf("Unknown. Type ? for help.\n");
|
||||
}
|
||||
puts("Exiting mimic09.");
|
||||
|
||||
Reference in New Issue
Block a user