Robustness: always restore terminal after G (ACIA raw mode)
- acia.h now exports acia_poll_input() and acia_end_run() - set_raw/restore_term are now safe no-ops on non-ttys (heredoc, pipes, the test harness) - debug.c cmd_go and main direct -g path now unconditionally call acia_end_run() on every exit from a run (bp, SIGINT/break_flag, stop_requested, halt). This prevents the monitor (or outer shell) from being left in raw/cbreak mode. - acia_poll_input() is called during G loops so programs using the emulated 6850 for input work. - Added clear stop messages (** Breakpoint at xxxx **, ** Break (SIGINT) **, etc.). - The exact A + S + B + G heredoc scenario that previously left a background process / raw term now cleanly returns to the m9> prompt and the calling shell has echo restored. This makes scripted / non-interactive use of the monitor (including the cc09 workflow) far more reliable.
This commit is contained in:
@@ -24,6 +24,7 @@ static int term_raw = 0;
|
||||
static void set_raw(void)
|
||||
{
|
||||
if (term_raw) return;
|
||||
if (!isatty(STDIN_FILENO)) return; /* never raw a pipe/heredoc */
|
||||
struct termios t;
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
t = oldt;
|
||||
@@ -40,6 +41,7 @@ static void set_raw(void)
|
||||
static void restore_term(void)
|
||||
{
|
||||
if (!term_raw) return;
|
||||
if (!isatty(STDIN_FILENO)) { term_raw = 0; return; }
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
int fl = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, fl & ~O_NONBLOCK);
|
||||
|
||||
@@ -13,6 +13,10 @@ void acia_init(uint16_t base);
|
||||
uint8_t acia_read(uint16_t off);
|
||||
void acia_write(uint16_t off, uint8_t val);
|
||||
|
||||
/* Terminal / input helpers for use during G runs (safe to call even without ACIA) */
|
||||
void acia_poll_input(void);
|
||||
void acia_end_run(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+17
-6
@@ -4,6 +4,7 @@
|
||||
#include "cpu.h"
|
||||
#include "disasm.h"
|
||||
#include "loader.h"
|
||||
#include "acia.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -220,15 +221,25 @@ static void cmd_go(char *line)
|
||||
signal(SIGINT, sigint_handler);
|
||||
break_flag = 0;
|
||||
|
||||
/* Simple run loop with occasional SIGINT check */
|
||||
while (!cpu.halted && !break_flag) {
|
||||
/* Simple run loop. Poll ACIA (safe no-op if not mapped or not a tty). */
|
||||
while (!cpu.halted && !break_flag && !cpu.stop_requested) {
|
||||
cpu_step();
|
||||
if ((cpu.total_cycles & 0x1FFF) == 0) {
|
||||
/* give ACIA a chance to flush etc. */
|
||||
}
|
||||
acia_poll_input();
|
||||
}
|
||||
signal(SIGINT, SIG_DFL);
|
||||
if (break_flag) printf("\n** Break at %04X **\n", cpu.pc);
|
||||
|
||||
/* Always restore terminal (ACIA raw mode must be undone on bp, SIGINT, halt, etc.) */
|
||||
acia_end_run();
|
||||
|
||||
if (break_flag) {
|
||||
printf("\n** Break (SIGINT) at %04X **\n", cpu.pc);
|
||||
} else if (bp_check_exec(cpu.pc)) {
|
||||
printf("\n** Breakpoint at %04X **\n", cpu.pc);
|
||||
} else if (cpu.stop_requested) {
|
||||
printf("\n** Stopped at %04X **\n", cpu.pc);
|
||||
} else if (cpu.halted) {
|
||||
printf("\n** Halted at %04X **\n", cpu.pc);
|
||||
}
|
||||
print_regs();
|
||||
next_dasm = cpu.pc;
|
||||
cpu.debug_mode = true;
|
||||
|
||||
+5
-9
@@ -4,6 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "cpu.h"
|
||||
@@ -112,17 +113,12 @@ int main(int argc, char **argv)
|
||||
cpu.halted = false;
|
||||
cpu.debug_mode = false;
|
||||
|
||||
/* Run with ACIA polling if present */
|
||||
printf("Running. Press Ctrl-C to return to monitor.\n");
|
||||
/* simple loop so we can feed ACIA chars */
|
||||
while (!cpu.halted) {
|
||||
printf("Running. Press Ctrl-C to return.\n");
|
||||
while (!cpu.halted && !cpu.stop_requested) {
|
||||
cpu_step();
|
||||
/* ACIA input is polled inside its own layer when needed, but we help here */
|
||||
/* In this simple build the ACIA uses direct read in raw mode during G */
|
||||
if (acia_base && (cpu.total_cycles & 0x7F) == 0) {
|
||||
/* acia_poll_input is internal; the acia read path + raw term during G is sufficient */
|
||||
}
|
||||
acia_poll_input();
|
||||
}
|
||||
acia_end_run();
|
||||
}
|
||||
|
||||
if (interactive || (!loadfile && !do_go)) {
|
||||
|
||||
Reference in New Issue
Block a user