From 29124377fc2bbeca0c0df3fb48a37db47c1802d4 Mon Sep 17 00:00:00 2001 From: Christian Werner Date: Thu, 15 Oct 2026 02:15:38 +0200 Subject: [PATCH] CLOSE: send LISTEN, CLOSE, UNLISTEN to a serial device close_iec sent its CLOSE command under ATN without first addressing the device with LISTEN and without UNLISTEN after it, and built the command with ORA $E0 (zero page) instead of ORA #$E0, so the byte it sent was the secondary address ORed with whatever $E0 held. The drive never learned of the CLOSE, so a file written on a channel was never written to the disk. The contract (Michael Steil, "Commodore Peripheral Bus: Part 2", https://www.pagetable.com/?p=1031): CLOSE of a file on a serial device sends LISTEN, then $E0 plus the secondary address, then UNLISTEN. close_iec now does that, as iec_close_load already does for LOAD. Not reported upstream (https://github.com/MEGA65/open-roms). --- src/kernal/iec/close_iec.s | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/kernal/iec/close_iec.s b/src/kernal/iec/close_iec.s index 16a661c1..3e5c02dc 100644 --- a/src/kernal/iec/close_iec.s +++ b/src/kernal/iec/close_iec.s @@ -23,11 +23,17 @@ close_iec: jsr iec_close_load jmp close_remove_from_table @1: - ora $E0 ; CLOSE command + ; LISTEN, CLOSE, UNLISTEN - see https://www.pagetable.com/?p=1031 + lda FAT, y + jsr LISTEN + bcs close_iec_end + lda SAT, y + ora #$E0 ; CLOSE command sta TBTCNT jsr iec_tx_command bcs close_iec_end jsr iec_tx_command_finalize + jsr UNLSN ; FALLTROUGH