From a2c02bde97a43cf422735fcf32fadb527313eb0d Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 25 Jul 2019 17:38:00 +0200 Subject: [PATCH] ACPTR now preserves registers, changed IEC temporary byte storage --- STATUS.md | 2 +- c64/aliases/,aliases_ram_lowmem.s | 3 +++ c64/kernal/acptr.s | 2 -- c64/kernal/close.s | 2 +- c64/kernal/iec/iec_rx_byte.s | 42 ++++++++++++++++++++++++------- c64/kernal/iec/iec_tx_byte.s | 4 ++- c64/kernal/iec/iec_tx_command.s | 4 ++- c64/kernal/iec/iec_tx_common.s | 10 +++----- c64/kernal/load.s | 8 +++--- c64/kernal/talk.s | 2 +- c64/kernal/unlsn.s | 2 +- c64/kernal/untlk.s | 2 +- 12 files changed, 55 insertions(+), 28 deletions(-) diff --git a/STATUS.md b/STATUS.md index 813b8708..e0d57f7b 100644 --- a/STATUS.md +++ b/STATUS.md @@ -79,7 +79,7 @@ NOTE: Even the 'DONE' routines won't support features described as missing in on | $FF9C | MEMBOT | DONE | | | $FF9F | SCNKEY | DONE | could be better integrated with ROM (aliases) | | $FFA2 | SETTMO | NOT DONE | | -| $FFA5 | ACPTR | PARTIAL | * work in progress | +| $FFA5 | ACPTR | DONE | | | $FFA8 | CIOUT | DONE | | | $FFAB | UNTLK | DONE | | | $FFAE | UNLSN | DONE | | diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s index c0a88d1d..ac9f8dd8 100644 --- a/c64/aliases/,aliases_ram_lowmem.s +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -31,6 +31,9 @@ .alias TIME $A0 ; $A0-$A2, jiffy clock + .alias IEC_TMP1 $A3 ; temporary variable for tape and IEC + .alias IEC_TMP2 $A4 ; temporary variable for tape and IEC + ;; 2-byte location below seems to be a good place for temporary storage, ;; it seems used for timing during tape reads only - see: ;; - 'C64 Programmer's Reference Guide', page 314 diff --git a/c64/kernal/acptr.s b/c64/kernal/acptr.s index 028233c2..8d3da68f 100644 --- a/c64/kernal/acptr.s +++ b/c64/kernal/acptr.s @@ -8,10 +8,8 @@ ;; CPU registers that has to be preserved (see [RG64]): .Y ;; -;; XXX preserve register Y! acptr: - ;; XXX temporary implementation jsr kernalstatus_reset jmp iec_rx_byte diff --git a/c64/kernal/close.s b/c64/kernal/close.s index d1aed3ac..523b8b3d 100644 --- a/c64/kernal/close.s +++ b/c64/kernal/close.s @@ -29,7 +29,7 @@ close: * lda SAT, y ; get secondary address ora $E0 ; CLOSE command - sta BSOUR + sta IEC_TMP2 jsr iec_tx_command bcs close_remove_from_table jsr iec_tx_command_finalize diff --git a/c64/kernal/iec/iec_rx_byte.s b/c64/kernal/iec/iec_rx_byte.s index 9819636c..c9a3b501 100644 --- a/c64/kernal/iec/iec_rx_byte.s +++ b/c64/kernal/iec/iec_rx_byte.s @@ -1,9 +1,17 @@ - ;; Receive a byte from the IEC bus. - ;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc, - ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf (page 11) +;; Receive a byte from the IEC bus. +;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc, +;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf (page 11) +;; +;; Preserves .X and .Y registers iec_rx_byte: + ;; Store .X and .Y on the stack - preserve them + txa + pha + tya + pha + ;; Timing is critical here - execute on disabled IRQs php sei @@ -96,12 +104,19 @@ iec_rx_clk_wait2: dey ; 2 cycles bne iec_rx_clk_wait2 ; 3 cycles if jumped - ;; Timeout - jsr kernalstatus_EOI - pla - plp - sec ; XXX confirm that sec is really a way to report timeout here - rts + ;; Timeout + jsr kernalstatus_EOI + pla + plp + + ;; Restore registers + pla + tay + pla + tax + + sec ; XXX confirm that sec is really a way to report timeout here + rts * ;; More bits? dex @@ -118,6 +133,15 @@ iec_rx_clk_wait2: ;; Return no-error plp + + ;; Restore registers + sta IEC_TMP2 ; $A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html + pla + tay + pla + tax + lda IEC_TMP2 + clc rts diff --git a/c64/kernal/iec/iec_tx_byte.s b/c64/kernal/iec/iec_tx_byte.s index a1eac09b..767dce76 100644 --- a/c64/kernal/iec/iec_tx_byte.s +++ b/c64/kernal/iec/iec_tx_byte.s @@ -1,7 +1,9 @@ ;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc -;; Expects byte to send in BSOUR; Carry flag set = signal EOI +;; Expects byte to send in IEC_TMP2 ($A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html) +;; Carry flag set = signal EOI +;; ;; Preserves .X and .Y registers diff --git a/c64/kernal/iec/iec_tx_command.s b/c64/kernal/iec/iec_tx_command.s index 0e27f6af..e2da97f2 100644 --- a/c64/kernal/iec/iec_tx_command.s +++ b/c64/kernal/iec/iec_tx_command.s @@ -1,7 +1,9 @@ ;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc -;; Expects command to send in BSOUR; Carry flag set = signal EOI +;; Expects byte to send in IEC_TMP2 ($A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html) +;; Carry flag set = signal EOI +;; ;; Preserves .X and .Y registers diff --git a/c64/kernal/iec/iec_tx_common.s b/c64/kernal/iec/iec_tx_common.s index 87b0aef1..8cc63e0f 100644 --- a/c64/kernal/iec/iec_tx_common.s +++ b/c64/kernal/iec/iec_tx_common.s @@ -3,9 +3,8 @@ ;; 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 -;; Expects byte to send in BSOUR; Carry flag set = signal EOI - -;; XXX is it OK to use BSOUR for data exchange? Maybe there is a better way? +;; Expects byte to send in IEC_TMP2 ($A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html) +;; Carry flag set = signal EOI iec_tx_common: @@ -42,11 +41,10 @@ iec_tx_common: iec_tx_common_sendbit: ;; Is next bit 0 or 1? - lda BSOUR + lda IEC_TMP2 lsr - sta BSOUR + sta IEC_TMP2 bcs + - ;; XXX we are actually destroying BSOUR here... is it allowed? ;; Bit is 0 jsr iec_release_clk_pull_data diff --git a/c64/kernal/load.s b/c64/kernal/load.s index b3137cfe..59ae8715 100644 --- a/c64/kernal/load.s +++ b/c64/kernal/load.s @@ -64,7 +64,7 @@ load: ;; Open channel #0 (p16) lda #$F0 ; $F0 for TKSA + 0 for channel number - sta BSOUR + sta IEC_TMP2 jsr iec_tx_command bcs lvs_load_verify_error jsr iec_tx_command_finalize @@ -89,7 +89,7 @@ load_send_filename: sec * ;; Transmit one character - sta BSOUR + sta IEC_TMP2 jsr iec_tx_byte jmp load_send_filename @@ -106,7 +106,7 @@ load_filename_sent: bcs lvs_load_verify_error lda #$60 ; open channel / data (p3) , required according to p13 - sta BSOUR + sta IEC_TMP2 jsr iec_tx_command bcs lvs_load_verify_error @@ -161,7 +161,7 @@ load_loop: jsr listen lda #$E0 - sta BSOUR + sta IEC_TMP2 jsr iec_tx_command jsr iec_tx_command_finalize diff --git a/c64/kernal/talk.s b/c64/kernal/talk.s index d4ca5742..fbd0fabc 100644 --- a/c64/kernal/talk.s +++ b/c64/kernal/talk.s @@ -25,7 +25,7 @@ talk: common_talk_listen: ; common part of TALK and LISTEN - sta BSOUR + sta IEC_TMP2 jmp iec_tx_command diff --git a/c64/kernal/unlsn.s b/c64/kernal/unlsn.s index fd4e4480..1cc9b998 100644 --- a/c64/kernal/unlsn.s +++ b/c64/kernal/unlsn.s @@ -21,7 +21,7 @@ unlsn: common_unlsn_second: ; common part of UNSLS and SECOND - sta BSOUR + sta IEC_TMP2 jsr iec_tx_command bcs + ; branch if error jmp iec_tx_command_finalize diff --git a/c64/kernal/untlk.s b/c64/kernal/untlk.s index 4085698e..e8054e0d 100644 --- a/c64/kernal/untlk.s +++ b/c64/kernal/untlk.s @@ -21,7 +21,7 @@ untlk: common_untlk_tksa: ; common part of UNTLK and TKSA - sta BSOUR + sta IEC_TMP2 jsr iec_tx_command bcs + ; branch if error ;; XXX - for TKSA, is it really the right place to do a turnaround? I've got some doubts