From 5b704045633baa5be2842031dd35c8861c246cd6 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Wed, 24 Jul 2019 18:02:38 +0200 Subject: [PATCH] IEC turnaround move to proper (I hope...) places --- c64/kernal/chkinout.s | 3 --- c64/kernal/iec/iec_turnaround_to_listen.s | 15 ++++++++++----- c64/kernal/iec/iec_turnaround_to_talk.s | 10 ++++++++-- c64/kernal/iec/iec_tx_command.s | 8 +------- c64/kernal/iec/iec_tx_command_finalize.s | 20 ++++++++++++++++++++ c64/kernal/load.s | 9 +++------ c64/kernal/second.s | 12 ++++++++++-- c64/kernal/talk.s | 2 -- c64/kernal/tksa.s | 19 +++++++++++++++---- c64/kernal/unlsn.s | 8 +++++--- c64/kernal/untlk.s | 9 +++++---- 11 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 c64/kernal/iec/iec_tx_command_finalize.s diff --git a/c64/kernal/chkinout.s b/c64/kernal/chkinout.s index d384b975..9a267264 100644 --- a/c64/kernal/chkinout.s +++ b/c64/kernal/chkinout.s @@ -52,9 +52,6 @@ chkin: jsr tksa bcs chkinout_end - jsr iec_turnaround_to_listen ;; XXX shouldn't this be sent by TALK/TKSA??? - bcs chkinout_end - chkin_set_device: lda FAT,Y sta DFLTN diff --git a/c64/kernal/iec/iec_turnaround_to_listen.s b/c64/kernal/iec/iec_turnaround_to_listen.s index 1033b720..0e66047a 100644 --- a/c64/kernal/iec/iec_turnaround_to_listen.s +++ b/c64/kernal/iec/iec_turnaround_to_listen.s @@ -4,6 +4,12 @@ iec_turnaround_to_listen: + ;; Store .X and .Y on the stack - preserve them + txa + pha + tya + pha + ;; Timing is critical here - execute on disabled IRQs php sei @@ -20,14 +26,13 @@ iec_turnaround_to_listen: dex bne - - ;; Timeout + ;; Timeout - XXX what errors do original Kernal report? plp - sec - rts + jmp iec_return_DEVICE_NOT_FOUND ;; CLK is pulled by the device, OK * plp - clc - rts + jmp iec_return_success + diff --git a/c64/kernal/iec/iec_turnaround_to_talk.s b/c64/kernal/iec/iec_turnaround_to_talk.s index c24639d2..666c89e2 100644 --- a/c64/kernal/iec/iec_turnaround_to_talk.s +++ b/c64/kernal/iec/iec_turnaround_to_talk.s @@ -4,6 +4,12 @@ iec_turnaround_to_talk: + ;; Store .X and .Y on the stack - preserve them + txa + pha + tya + pha + ;; Timing is critical here - execute on disabled IRQs php sei @@ -19,5 +25,5 @@ iec_turnaround_to_talk: jsr iec_pull_clk_release_data plp - clc - rts + jmp iec_return_success + diff --git a/c64/kernal/iec/iec_tx_command.s b/c64/kernal/iec/iec_tx_command.s index 153d0f6e..0e27f6af 100644 --- a/c64/kernal/iec/iec_tx_command.s +++ b/c64/kernal/iec/iec_tx_command.s @@ -55,12 +55,6 @@ iec_tx_command: jmp iec_return_DEVICE_NOT_FOUND * - ;; All done - - ;; XXX All the documentation says we should release ATN at this point, but when I do so - ;; the turnaround mechanism does not work. Why??? - ;; jsr iec_wait20us - ;; jsr iec_set_idle + ;; Done jmp iec_return_success - diff --git a/c64/kernal/iec/iec_tx_command_finalize.s b/c64/kernal/iec/iec_tx_command_finalize.s new file mode 100644 index 00000000..91ef8446 --- /dev/null +++ b/c64/kernal/iec/iec_tx_command_finalize.s @@ -0,0 +1,20 @@ + +;; Routine to finalize these IEC commands which do not end in turnaround +;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc + + +iec_tx_command_finalize: + + ;; Store .X and .Y on the stack - preserve them + txa + pha + tya + pha + + ;; Give device some time to complete command reception, release ATN, + ;; give it some time again before (possible) next command + jsr iec_wait20us + jsr iec_set_idle + jsr iec_wait20us + + jmp iec_return_success diff --git a/c64/kernal/load.s b/c64/kernal/load.s index 9675f2df..e83d3a6b 100644 --- a/c64/kernal/load.s +++ b/c64/kernal/load.s @@ -63,8 +63,9 @@ load: bcs lvs_device_not_found_error ;; Open channel #0 (p16) - lda #$00 - jsr tksa + lda #$F0 ; $F0 for TKSA + 0 for channel number + sta BSOUR + jsr iec_tx_command bcs lvs_load_verify_error ;; Send filename (p16) @@ -155,10 +156,6 @@ load_loop: ;; Command drive to stop talking and to close the file jsr untlk - ;; Turnaround to talker - according to https://www.pagetable.com/?p=1135 - ;; the turnaround only happens after a command - jsr iec_turnaround_to_talk - lda current_device_number jsr listen diff --git a/c64/kernal/second.s b/c64/kernal/second.s index 53d1391e..819fdc24 100644 --- a/c64/kernal/second.s +++ b/c64/kernal/second.s @@ -12,7 +12,15 @@ second: - and #$1F ; make sure bits encoding the command are cleared out + ;; Due to TKSA/SECOND command encoding (see https://www.pagetable.com/?p=1031), + ;; allowed channels are 0-15; report error if out of range + cmp #$10 + bcs kernalerror_FILE_NOT_INPUT + ora #$60 sta BSOUR - jmp iec_tx_command + jsr iec_tx_command + bcs + ; branch if error + jmp iec_tx_command_finalize +* + rts diff --git a/c64/kernal/talk.s b/c64/kernal/talk.s index 3952ed0c..46c26c35 100644 --- a/c64/kernal/talk.s +++ b/c64/kernal/talk.s @@ -10,8 +10,6 @@ ;; -;; XXX shouldn't this do a turnaround? - talk: ;; First check whether device number is correct diff --git a/c64/kernal/tksa.s b/c64/kernal/tksa.s index d003cfbb..06953f7d 100644 --- a/c64/kernal/tksa.s +++ b/c64/kernal/tksa.s @@ -10,12 +10,23 @@ ;; -;; XXX shouldn't this do a turnaround? - tksa: - and #$1F ; make sure bits encoding the command are cleared out + ;; Due to TKSA/SECOND command encoding (see https://www.pagetable.com/?p=1031), + ;; allowed channels are 0-15; report error if out of range + cmp #$10 + bcs kernalerror_FILE_NOT_INPUT + ora #$F0 sta BSOUR - jmp iec_tx_command + jsr iec_tx_command + bcs + ; branch if error + ;; XXX - is it really the right place to do a turnaround? I've got some doubts + ;; (it forces us to send the TKSA command 'manually' sometimes), but + ;; Luigi Di Fraia (https://luigidifraia.wordpress.com/2017/06/27/codebase64-on-the-kernal-behaviour/) + ;; claims TKSA Kernal routine actually does the turnaround + jmp iec_turnaround_to_listen +* + rts + diff --git a/c64/kernal/unlsn.s b/c64/kernal/unlsn.s index 32f0b0f5..5aa2cfdc 100644 --- a/c64/kernal/unlsn.s +++ b/c64/kernal/unlsn.s @@ -23,6 +23,8 @@ unlsn: ;; Buffer empty, send the command lda #$3F sta BSOUR - jmp iec_tx_command - - + jsr iec_tx_command + bcs + ; branch if error + jmp iec_tx_command_finalize +* + rts diff --git a/c64/kernal/untlk.s b/c64/kernal/untlk.s index 7f421bb7..4ec846a8 100644 --- a/c64/kernal/untlk.s +++ b/c64/kernal/untlk.s @@ -10,11 +10,12 @@ ;; -;; XXX shouldn't this do a turnaround? - untlk: lda #$5F sta BSOUR - jmp iec_tx_command - + jsr iec_tx_command + bcs + ; branch if error + jmp iec_turnaround_to_listen +* + rts