From b4f334bbbfd831aff331acdb8dc23e8fdc515e84 Mon Sep 17 00:00:00 2001 From: Christian Werner Date: Sun, 18 Oct 2026 08:16:40 +0200 Subject: [PATCH] fix(iec): disable IRQs before releasing CLK to send a byte iec_tx_byte and iec_tx_command released CLK and only then disabled IRQs. An IRQ in between took about 500 cycles, longer than a listener's EOI wait and acknowledgement, so the talker waited for an acknowledgement that had come and gone, and a LOAD over the bus hung after its file name. Which byte an IRQ hit depended on where the build placed the code. --- src/kernal/iec/iec_tx_byte.s | 14 +++++++++----- src/kernal/iec/iec_tx_command.s | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/kernal/iec/iec_tx_byte.s b/src/kernal/iec/iec_tx_byte.s index 014dca9e..ef0efffd 100644 --- a/src/kernal/iec/iec_tx_byte.s +++ b/src/kernal/iec/iec_tx_byte.s @@ -62,6 +62,14 @@ iec_tx_byte: jsr kernalstatus_DEVICE_NOT_FOUND jmp iec_return_DEVICE_NOT_FOUND @1: + ; Timing is critical from here on - execute on disabled IRQs, from before + ; CLK is released: an IRQ between the release and the EOI wait would hide + ; the listener's EOI acknowledgement, and the transfer would hang + ; The best practice would be to do PHP first, but it seems this is not + ; what the original ROM does; furthermore, pushing additional bytes to + ; stack can wreck autostart software loading at $0100 + sei + ; Notify all devices that we are going to send a byte ; and it is going to be a data byte (released ATN) jsr iec_release_atn_clk_data @@ -72,11 +80,7 @@ iec_tx_byte: iec_tx_common: - ; Timing is critical here - execute on disabled IRQs - ; The best practice would be to do PHP first, but it seems this is not - ; what the original ROM does; furthermore, pushing additional bytes to - ; stack can wreck autostart software loading at $0100 - sei + ; Entered with IRQs disabled, by iec_tx_byte and iec_tx_command ; Wait till all receivers are ready, they should all release DATA jsr iec_wait_for_data_release diff --git a/src/kernal/iec/iec_tx_command.s b/src/kernal/iec/iec_tx_command.s index 3e4a223d..c8b19295 100644 --- a/src/kernal/iec/iec_tx_command.s +++ b/src/kernal/iec/iec_tx_command.s @@ -32,7 +32,10 @@ iec_tx_command: ; (can be busy processing something), we have to wait till they are all ; ready (or bored with DOS attack...) ; Release back CLK, keep DATA released - to ask devices for status. + ; From here on IRQs are disabled, as in iec_tx_byte: a listener takes a + ; talker that waits too long after the release for EOI + sei jsr iec_release_clk_data ; Common part of iec_txbyte and iec_tx_common - waits for devices