From 0015e66099e604d00bb03c96e720eee948c0378d Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Tue, 20 Oct 2026 21:50:00 +0100 Subject: [PATCH] Added Ctrl-key combination support on Unix --- interrupts.c | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/interrupts.c b/interrupts.c index 755cde7..44bf77a 100644 --- a/interrupts.c +++ b/interrupts.c @@ -1319,12 +1319,53 @@ static int host_function_scan (int scan, unsigned modifier) { return scan + 6; } + } else if (modifier == 5) { + + if (scan >= 0x3B && scan <= 0x44) { + return scan + 0x23; + } + + if (scan == 0x85 || scan == 0x86) { + return scan + 4; + } + + switch (scan) { + + case 0x47: return 0x77; /* Ctrl+Home */ + case 0x48: return 0x8D; /* Ctrl+Up */ + case 0x49: return 0x84; /* Ctrl+Page Up */ + case 0x4B: return 0x73; /* Ctrl+Left */ + case 0x4D: return 0x74; /* Ctrl+Right */ + case 0x4F: return 0x75; /* Ctrl+End */ + case 0x50: return 0x91; /* Ctrl+Down */ + case 0x51: return 0x76; /* Ctrl+Page Down */ + case 0x52: return 0x92; /* Ctrl+Insert */ + case 0x53: return 0x93; /* Ctrl+Delete */ + + } + } return scan; } +static int host_control_scan (int key) { + + if (key >= 1 && key <= 26) { + + if (key == 8) return 0x0E; /* Backspace and Ctrl+H are indistinguishable. */ + if (key == 9) return 0x0F; /* Tab and Ctrl+I are indistinguishable. */ + if (key == 13) return 0x1C; /* Enter and Ctrl+M are indistinguishable. */ + + return host_alt_scan ((unsigned char) ('a' + key - 1)); + + } + + return 0; + +} + static int host_read_key_from (FILE *source) { struct termios oldt, newt; @@ -1951,10 +1992,8 @@ static int bios_read_key (CPU8086 *cpu, int wait) { if (extended) { ch = scan << 8; - } - - if (ch == '\n') { - ch = '\r'; + } else if (changed && ch > 0 && ch <= 26) { + ch |= host_control_scan (ch) << 8; } bios_read_done: @@ -5503,10 +5542,6 @@ static void int_21 (CPU8086 *cpu) { c = '\r'; } - if (c == '\n') { - c = '\r'; - } - set_reg8 (cpu, REG_AX, (uint8_t) c); /* AL */ cpu->flags &= ~FLAG_CF; -- 2.34.1