From 687ed9c56a575c4e4c216d16b75c387bdf5cf6ca Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Wed, 1 May 2019 21:47:00 +0930 Subject: [PATCH] more work towards IEC bus. Also don't corrupt $DD00 VIC-II bank bits in the process. --- c64/kernal/iec_assert_clk_and_data.s | 2 +- c64/kernal/iec_assert_clk_release_data.s | 2 +- c64/kernal/iec_release_clk.s | 2 +- c64/kernal/iec_release_clk_and_data.s | 2 +- c64/kernal/iec_tx_byte.s | 37 +++++++++++++++++++- c64/kernal/open.s | 43 +++++++----------------- c64/kernal/reset_entry.s | 2 ++ 7 files changed, 54 insertions(+), 36 deletions(-) diff --git a/c64/kernal/iec_assert_clk_and_data.s b/c64/kernal/iec_assert_clk_and_data.s index 8596466a..7bb1242a 100644 --- a/c64/kernal/iec_assert_clk_and_data.s +++ b/c64/kernal/iec_assert_clk_and_data.s @@ -1,6 +1,6 @@ iec_assert_clk_and_data: lda $dd00 - and #$08 + and #$0b ora #$30 sta $dd00 rts diff --git a/c64/kernal/iec_assert_clk_release_data.s b/c64/kernal/iec_assert_clk_release_data.s index 91fbe920..2a33a4f8 100644 --- a/c64/kernal/iec_assert_clk_release_data.s +++ b/c64/kernal/iec_assert_clk_release_data.s @@ -1,6 +1,6 @@ iec_assert_clk_release_data: lda $dd00 - and #$08 + and #$0b ora #$10 sta $dd00 rts diff --git a/c64/kernal/iec_release_clk.s b/c64/kernal/iec_release_clk.s index ee227eb2..cf12e8c0 100644 --- a/c64/kernal/iec_release_clk.s +++ b/c64/kernal/iec_release_clk.s @@ -1,5 +1,5 @@ iec_release_clk: lda $dd00 - and #$18 + and #$1b sta $dd00 rts diff --git a/c64/kernal/iec_release_clk_and_data.s b/c64/kernal/iec_release_clk_and_data.s index c8bc6d9e..db554a6e 100644 --- a/c64/kernal/iec_release_clk_and_data.s +++ b/c64/kernal/iec_release_clk_and_data.s @@ -1,6 +1,6 @@ iec_release_clk_and_data: lda $DD00 - and #$08 + and #$0b sta $DD00 rts diff --git a/c64/kernal/iec_tx_byte.s b/c64/kernal/iec_tx_byte.s index 6d609ff8..0711a1f4 100644 --- a/c64/kernal/iec_tx_byte.s +++ b/c64/kernal/iec_tx_byte.s @@ -1,8 +1,44 @@ iec_tx_byte: + pha + + jsr iec_assert_clk_release_data + + ;; Give devices time to respond + jsr wait1ms + + ;; Did a device respond? (DATA will be pulled if so) + lda $DD00 + bmi + + + ;; No devices present, so we can immediately return with device not found + pla + jmp kernalerror_DEVICE_NOT_FOUND +* + + ;; Release CLK and wait for DATA to release. + jsr iec_release_clk_and_data + + ;; Wait for DATA to be released + ;; Listener is allowed to hold DATA for as long as they want. + ;; i.e., this is the part of the protocol where the listener indicates + ;; that they are busy doing something, like processing the previous + ;; character. + jsr iec_wait_for_data_release + + ;; We then wait for 60 usec (less than 200usec so we don't + ;; signal EOI), before asserting CLK again. + jsr iec_wait60us + + ;; Re-assert CLK line + jsr iec_assert_clk_release_data + + ;; Do the actual transmission of 8 bits of data ldx #8 + pla + iec_tx_byte_nextbit: ;; Is next bit 0 or 1? lsr @@ -40,7 +76,6 @@ iec_tx_byte_l1: bne - ;; Timeout - DEVICE NOT PRESENT - cli jmp kernalerror_DEVICE_NOT_FOUND * ;; All done. diff --git a/c64/kernal/open.s b/c64/kernal/open.s index a912220c..17df84f8 100644 --- a/c64/kernal/open.s +++ b/c64/kernal/open.s @@ -11,38 +11,19 @@ open: ;; Begin sending under attention jsr iec_assert_atn - jsr iec_assert_clk_release_data - - ;; Give devices time to respond - jsr wait1ms - - ;; Did a device respond? (DATA will be pulled if so) - lda $DD00 - bmi + - - ;; No devices present, so we can immediately return with device not found - cli - jmp kernalerror_DEVICE_NOT_FOUND -* - - ;; Release CLK and wait for DATA to release. - jsr iec_release_clk_and_data - - ;; Wait for DATA to be released - ;; Listener is allowed to hold DATA for as long as they want. - ;; i.e., this is the part of the protocol where the listener indicates - ;; that they are busy doing something, like processing the previous - ;; character. - jsr iec_wait_for_data_release - - ;; We then wait for 60 usec (less than 200usec so we don't - ;; signal EOI), before asserting CLK again. - jsr iec_wait60us - - ;; Re-assert CLK line - jsr iec_assert_clk_release_data ;; CLK is now asserted, and we are ready to transmit a byte + lda #$28 jsr iec_tx_byte - + bcs open_error + + ;; Indicate success + lda #$00 + clc + +open_error: + ;; Re-enable interrupts and return + ;; (iec_tx_byte will have set/cleared C flag and put result code + ;; in A if it was an error). + cli rts diff --git a/c64/kernal/reset_entry.s b/c64/kernal/reset_entry.s index 739a004c..ef5fb2db 100644 --- a/c64/kernal/reset_entry.s +++ b/c64/kernal/reset_entry.s @@ -29,6 +29,8 @@ reset_entry: ; What do we do when finished? A C64 jumps into the BASIC ROM cli ; Allow interrupts to happen + + jsr open ; c64 prg p269 jmp ($a000)