From 51a2a43520b70e7848ae640be39ef52729fca3f5 Mon Sep 17 00:00:00 2001 From: Christian Werner Date: Thu, 15 Oct 2026 02:50:48 +0200 Subject: [PATCH] CLOSE: a device that does not answer sets ST to device not present When LISTEN or the CLOSE command found no device on the serial bus, close_iec freed the file number but left ST as it was, so READST after the CLOSE said 0. The contract: every device on the bus must answer ATN by pulling DATA, and when none does the result is DEVICE NOT PRESENT (Michael Steil, "Commodore Peripheral Bus: Part 2", https://www.pagetable.com/?p=1031); the C64 Programmer's Reference Guide's READST reports that as ST bit 7 ($80). close_iec now sets that bit when LISTEN or the CLOSE command fails, and still frees the file number. Commodore's ROMs give the same ST in the same scenario, as a differential test in arnitech shows. Not reported upstream (https://github.com/MEGA65/open-roms). --- src/kernal/iec/close_iec.s | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/kernal/iec/close_iec.s b/src/kernal/iec/close_iec.s index 3e5c02dc..366abd10 100644 --- a/src/kernal/iec/close_iec.s +++ b/src/kernal/iec/close_iec.s @@ -26,14 +26,20 @@ close_iec: ; LISTEN, CLOSE, UNLISTEN - see https://www.pagetable.com/?p=1031 lda FAT, y jsr LISTEN - bcs close_iec_end + bcs close_iec_not_present lda SAT, y ora #$E0 ; CLOSE command sta TBTCNT jsr iec_tx_command - bcs close_iec_end + bcs close_iec_not_present jsr iec_tx_command_finalize jsr UNLSN + jmp close_remove_from_table + +close_iec_not_present: + + ; The file is closed all the same; READST says device not present + jsr kernalstatus_DEVICE_NOT_FOUND ; FALLTROUGH