From b1e7fde1a31c26495820226da7a8ad0083f7ff37 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Wed, 1 Oct 2025 23:33:18 +0200 Subject: [PATCH] polmon: now with ctrl+break! --- polmon.cc | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/polmon.cc b/polmon.cc index 2f18441..3bc55bf 100644 --- a/polmon.cc +++ b/polmon.cc @@ -1,5 +1,6 @@ #include #include +#include #ifndef WOZMON #define WOZMON 0 @@ -13,6 +14,7 @@ #define SHOWTITLE 0 #define BOOTSTRAP 0 #define LAUNCH 0 +#define CTRLBREAK 0 #endif // WOZMON #ifndef BACKSPACE @@ -43,6 +45,10 @@ #define LAUNCH 1 #endif +#ifndef CTRLBREAK +#define CTRLBREAK 1 +#endif + namespace { #if WOZMON @@ -234,6 +240,35 @@ void LaunchFile(const char* name) { : "ax", "memory"); } +#if CTRLBREAK + +constexpr uint16_t kCtrlBreakVector = (0x1b * 4); + +extern "C" void cbreak(); +asm(" .section .text.cbreak \n" + "cbreak: \n" + " xor %ax, %ax \n" + " mov %ds, %ax \n" + " cli \n" + " mov %ss, %ax \n" + " mov $0x2000, %sp \n" + " sti \n" + " pushf \n" + " push %ax \n" + " mov $0x1000, %ax \n" + " push %ax \n" + " mov $0x20, %al \n" + " out %al, $0x20 \n" + " iret \n"); + +void InstallCtrlBreak() { + auto vec = reinterpret_cast(kCtrlBreakVector); + vec[0] = cbreak; + vec[1] = 0; +} + +#endif // CTRLBREAK + bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) { bool dump = true; for (const char* ptr = buf; *ptr;) { @@ -372,7 +407,12 @@ void polmon() { } // namespace -int main() { polmon(); } +int main() { +#if CTRLBREAK + InstallCtrlBreak(); +#endif // CTRLBREAK + polmon(); +} #if BOOTSTRAP __attribute__((section(".init"), noreturn, used)) void _start() {