diff --git a/c64/kernal/iec_turnaround_to_talk.s b/c64/kernal/iec_turnaround_to_talk.s index d372ad00..c8cc9b47 100644 --- a/c64/kernal/iec_turnaround_to_talk.s +++ b/c64/kernal/iec_turnaround_to_talk.s @@ -4,9 +4,15 @@ iec_turnaround_to_talk: - ;; XXX implement this - + ;; First make sure both CLK, DATA and ATN are released at our side + jsr iec_release_atn + jsr iec_release_clk_data + + ;; Wait till device releases CLK line + jsr iec_wait_for_clk_release + + ;; Pull CLK line, it should be held by talker + jsr iec_pull_clk_release_data + clc rts - - diff --git a/c64/kernal/iec_wait_for_data_pull.s b/c64/kernal/iec_wait_for_data_pull.s new file mode 100644 index 00000000..d83b57d4 --- /dev/null +++ b/c64/kernal/iec_wait_for_data_pull.s @@ -0,0 +1,7 @@ + +iec_wait_for_data_pull: + lda CI2PRA + ;; Check the highest bit, which is DATA IN, + ;; (highest bit set = negative value) + bmi iec_wait_for_data_pull + rts diff --git a/c64/kernal/load.s b/c64/kernal/load.s index 72db27b7..ccf77051 100644 --- a/c64/kernal/load.s +++ b/c64/kernal/load.s @@ -198,20 +198,18 @@ load_done: lda #$0D jsr JCHROUT * - ;; Close file on drive - start by turnaround to talker - jsr iec_turnaround_to_talk - + ;; Close file on drive + ;; Command drive to stop talking and to close the file jsr untlk - - ;; XXX XXX code below runs into infinite loop - so for now just quit - clc - cli - rts - + + ;; 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 - + lda #$e0 jsr iec_tx_command @@ -227,7 +225,7 @@ load_done: clc cli rts - + load_error: ;; Advance cursor to next line, if needed @@ -239,7 +237,7 @@ load_error: ;; XXX - Indicate KERNAL (not BASIC) LOAD error condtion sec lda #28 - + ;; Re-enable interrupts and return cli ;; (iec_tx_byte will have set/cleared C flag and put result code