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).
This commit is contained in:
chris committed 2026-10-15 02:50:48 +02:00
1 parent ec7707d4cc
commit 51a2a43520
1 file changed
+8 -2
+8 -2
View File
@@ -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