From b21ce3116d38ac65e86ccfe818118a8a20bee0af Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 21 Jun 2019 21:47:39 +0200 Subject: [PATCH] more IEC work - iec_tx_command can now detect missing devices --- ...see_data.s => iec_pull_clk_release_data.s} | 0 c64/kernal/iec_tx_byte.s | 19 ++++++++++++- c64/kernal/iec_tx_command.s | 24 ++++++++++++++-- c64/kernal/iec_tx_common.s | 28 ++----------------- c64/kernal/open.s | 14 +++------- 5 files changed, 46 insertions(+), 39 deletions(-) rename c64/kernal/{iec_pull_clk_releasee_data.s => iec_pull_clk_release_data.s} (100%) diff --git a/c64/kernal/iec_pull_clk_releasee_data.s b/c64/kernal/iec_pull_clk_release_data.s similarity index 100% rename from c64/kernal/iec_pull_clk_releasee_data.s rename to c64/kernal/iec_pull_clk_release_data.s diff --git a/c64/kernal/iec_tx_byte.s b/c64/kernal/iec_tx_byte.s index ed1b0b7a..c422f270 100644 --- a/c64/kernal/iec_tx_byte.s +++ b/c64/kernal/iec_tx_byte.s @@ -14,8 +14,25 @@ iec_tx_byte: pla jsr iec_tx_common - + + ;; All done - give device time to tell if they are busy by pulling DATA + ;; They should do it within 1ms + ldx #$FF +* lda CI2PRA + ;; BPL here is checking that bit 7 of $DD00 clears, + ;; i.e, that the DATA line is pulled by drive + bpl + + dex + bne - + bpl iec_tx_byte_error +* ;; All done clc rts +iec_tx_byte_error: + + jsr iec_set_idle + jmp kernalerror_DEVICE_NOT_FOUND + + diff --git a/c64/kernal/iec_tx_command.s b/c64/kernal/iec_tx_command.s index 690fd5a5..ca50f4a2 100644 --- a/c64/kernal/iec_tx_command.s +++ b/c64/kernal/iec_tx_command.s @@ -14,7 +14,7 @@ iec_tx_command: ;; Did at least one device respond by pulling DATA? lda CI2PRA - and #BIT_CI2PRA_DAT_IN + and #BIT_CI2PRA_DAT_IN ; XXX try to optimize this, move to separate routine beq + ;; No devices present on the bus, so we can immediately return with device not found @@ -39,7 +39,27 @@ iec_tx_command: pla jsr iec_tx_common - ;; All done + ;; According to https://www.pagetable.com/?p=1135 there is some complicated and dangerous + ;; flow here, but http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf (page 6) + ;; advices to just wait 1ms and check the DATA status + jsr wait1ms + lda CI2PRA + and #BIT_CI2PRA_DAT_IN ; XXX try to optimize this, move to separate routine + beq + + + ;; XXX possible optimization of the flow above: for many commands it is enough + ;; to wait for the DATA being pulled, as confirmation is expected from + ;; a single device only - but not sure if it's worth the trouble + + jsr printf + .byte "DBG: NO CONFIRMATION FROM DEVICE", $0D, 0 + + jsr iec_set_idle + jmp kernalerror_DEVICE_NOT_FOUND +* + ;; All done - before exiting wait a moment and restore bus to idle state + jsr iec_wait20us + jsr iec_set_idle clc rts diff --git a/c64/kernal/iec_tx_common.s b/c64/kernal/iec_tx_common.s index ca5fb247..73753f72 100644 --- a/c64/kernal/iec_tx_common.s +++ b/c64/kernal/iec_tx_common.s @@ -1,6 +1,7 @@ ;; This is a common part of iec_tx_byte and iec_tx_command ;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc +;; and http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf iec_tx_common: @@ -48,33 +49,8 @@ iec_tx_common_bit_is_sent: dex bpl iec_tx_common_nextbit pla - - ;; Whole byte send, make sure ATN is released - jsr iec_release_atn_clk_data - - ;; XXX the flow below is REALLY dangerous, as if there are multiple devices, - ;; one can signal that it's busy much earlier (more than 100ms) than the other. - ;; Can we do something about it? - ;; All done - give devices time to tell if they are busy by pulling DATA - ;; They should do it within 1ms - ldx #$FF -* lda CI2PRA - ;; BPL here is checking that bit 7 of $DD00 clears, - ;; i.e, that the DATA line is pulled by drive - bpl + - dex - bne - - bpl iec_tx_common_done -* - ;; Wait 100us to give busy devices some time - jsr iec_wait100us - -iec_tx_common_done: - - ;; Byte sent, return - clc - rts + rts ; Flow continues differently for data/command iec_tx_common_nextbit: diff --git a/c64/kernal/open.s b/c64/kernal/open.s index a28e438d..e10ea78e 100644 --- a/c64/kernal/open.s +++ b/c64/kernal/open.s @@ -84,25 +84,19 @@ open_iec: ;; Request device to talk lda current_device_number jsr talk - bcs open_iec_error ; XXX what about the accumulator? + bcs open_iec_error - jsr printf - .byte "DBG: OPEN 1", $0D, 0 - ;; Send secondary address lda current_secondary_address jsr second - bcs open_iec_error ; XXX what about the accumulator? - - jsr printf - .byte "DBG: OPEN 2", $0D, 0 + bcs open_iec_error ;; Turnaround jsr iec_turnaround_to_listen - bcs open_iec_error ; XXX what about the accumulator? + bcs open_iec_error jsr printf - .byte "DBG: OPEN 3 - DEVICE EXISTS", $0D, 0 + .byte "DBG: TURNAROUND SUCCEEDED", $0D, 0 ;; Indicate success lda #$00