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)
|
static void set_raw(void)
|
||||||
{
|
{
|
||||||
if (term_raw) return;
|
if (term_raw) return;
|
||||||
|
if (!isatty(STDIN_FILENO)) return; /* never raw a pipe/heredoc */
|
||||||
struct termios t;
|
struct termios t;
|
||||||
tcgetattr(STDIN_FILENO, &oldt);
|
tcgetattr(STDIN_FILENO, &oldt);
|
||||||
t = oldt;
|
t = oldt;
|
||||||
@@ -40,6 +41,7 @@ static void set_raw(void)
|
|||||||
static void restore_term(void)
|
static void restore_term(void)
|
||||||
{
|
{
|
||||||
if (!term_raw) return;
|
if (!term_raw) return;
|
||||||
|
if (!isatty(STDIN_FILENO)) { term_raw = 0; return; }
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||||
int fl = fcntl(STDIN_FILENO, F_GETFL, 0);
|
int fl = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||||
fcntl(STDIN_FILENO, F_SETFL, fl & ~O_NONBLOCK);
|
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);
|
uint8_t acia_read(uint16_t off);
|
||||||
void acia_write(uint16_t off, uint8_t val);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+17
-6
@@ -4,6 +4,7 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "disasm.h"
|
#include "disasm.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
|
#include "acia.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -220,15 +221,25 @@ static void cmd_go(char *line)
|
|||||||
signal(SIGINT, sigint_handler);
|
signal(SIGINT, sigint_handler);
|
||||||
break_flag = 0;
|
break_flag = 0;
|
||||||
|
|
||||||
/* Simple run loop with occasional SIGINT check */
|
/* Simple run loop. Poll ACIA (safe no-op if not mapped or not a tty). */
|
||||||
while (!cpu.halted && !break_flag) {
|
while (!cpu.halted && !break_flag && !cpu.stop_requested) {
|
||||||
cpu_step();
|
cpu_step();
|
||||||
if ((cpu.total_cycles & 0x1FFF) == 0) {
|
acia_poll_input();
|
||||||
/* give ACIA a chance to flush etc. */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
signal(SIGINT, SIG_DFL);
|
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();
|
print_regs();
|
||||||
next_dasm = cpu.pc;
|
next_dasm = cpu.pc;
|
||||||
cpu.debug_mode = true;
|
cpu.debug_mode = true;
|
||||||
|
|||||||
+5
-9
@@ -4,6 +4,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
@@ -112,17 +113,12 @@ int main(int argc, char **argv)
|
|||||||
cpu.halted = false;
|
cpu.halted = false;
|
||||||
cpu.debug_mode = false;
|
cpu.debug_mode = false;
|
||||||
|
|
||||||
/* Run with ACIA polling if present */
|
printf("Running. Press Ctrl-C to return.\n");
|
||||||
printf("Running. Press Ctrl-C to return to monitor.\n");
|
while (!cpu.halted && !cpu.stop_requested) {
|
||||||
/* simple loop so we can feed ACIA chars */
|
|
||||||
while (!cpu.halted) {
|
|
||||||
cpu_step();
|
cpu_step();
|
||||||
/* ACIA input is polled inside its own layer when needed, but we help here */
|
acia_poll_input();
|
||||||
/* 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_end_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interactive || (!loadfile && !do_go)) {
|
if (interactive || (!loadfile && !do_go)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user