diff --git a/.gitignore b/.gitignore index 797051dc..a28e5087 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,26 @@ + +# Intermediate compilation files + c64/basic/combined.s c64/kernal/combined.s temp.s temp.map -newbasic -newkern -newrom + src/compress_text +src/pngprepare src/preprocess ophis.bin c64/basic/OUT.BIN c64/kernal/OUT.BIN -*project +# Compilation output + +chargen +newbasic +newkern +newrom + +# Various IDE project files, temporary files, etc. + +*project +.*swp diff --git a/c64/kernal/iec_release_atn_clk_data.s b/c64/kernal/iec_release_atn_clk_data.s new file mode 100644 index 00000000..c35af0da --- /dev/null +++ b/c64/kernal/iec_release_atn_clk_data.s @@ -0,0 +1,7 @@ + +iec_release_atn_clk_data: + lda CI2PRA + and #$FF - BIT_CI2PRA_ATN_OUT - BIT_CI2PRA_CLK_OUT - BIT_CI2PRA_DAT_OUT ; release + sta CI2PRA + rts + diff --git a/c64/kernal/iec_tx_byte.s b/c64/kernal/iec_tx_byte.s index 365f38f0..ed1b0b7a 100644 --- a/c64/kernal/iec_tx_byte.s +++ b/c64/kernal/iec_tx_byte.s @@ -5,6 +5,17 @@ iec_tx_byte: pha -;; XXX to be filled-in + ;; Notify all devices that we are going to send a byte + ;; and it is going to be a data byte (released ATN) + jsr iec_release_atn_clk_data + + ;; Common part of iec_txbyte and iec_tx_common - waits for devices + ;; and transmits a byte + + pla + jsr iec_tx_common + + ;; All done + clc rts diff --git a/c64/kernal/iec_tx_command.s b/c64/kernal/iec_tx_command.s index 9e03974c..d8f4f795 100644 --- a/c64/kernal/iec_tx_command.s +++ b/c64/kernal/iec_tx_command.s @@ -29,68 +29,17 @@ iec_tx_command: ;; At least one device responded, but they are still allowed to stall ;; (can be busy processing something), we have to wait till they are all ;; ready (or bored with DOS attack...) - ;; - release back CLK, keep DATA released - ;; - afterwards wait till all devices also release DATA + ;; Release back CLK, keep DATA released - to ask devices for status. jsr iec_release_clk_data - jsr iec_wait_for_data_release - ;; Pull CLK back to indicate that DATA is not valid, keep it for 60us - ;; Don't wait too long, as 200us or more is considered EOI - - jsr iec_pull_clk_release_data - jsr iec_wait60us - - ;; Now, we can start transmission of 8 bits of data - ldx #7 - pla - -iec_tx_command_nextbit: - ;; Is next bit 0 or 1? - lsr - pha - bcs + - - ;; Bit is 0 - jsr iec_release_clk_pull_data - jmp iec_tx_command_bitset -* - ;; Bit is 1 - jsr iec_release_clk_data + ;; Common part of iec_txbyte and iec_tx_common - waits for devices + ;; and transmits a byte -iec_tx_command_bitset: - - ;; Wait 20us, so that device(s) can pick DATA - jsr iec_wait20us - - ;; Pull CLK for 20us again - jsr iec_pull_clk_release_data - jsr iec_wait20us - - ;; More bits to send? pla - dex - bpl iec_tx_command_nextbit + jsr iec_tx_common - ;; 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_command_done -* - ;; Wait 100us to give busy devices some time - jsr iec_wait100us - -iec_tx_command_done: + ;; All done clc rts diff --git a/c64/kernal/iec_tx_common.s b/c64/kernal/iec_tx_common.s new file mode 100644 index 00000000..05565b80 --- /dev/null +++ b/c64/kernal/iec_tx_common.s @@ -0,0 +1,74 @@ + +;; 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 + +iec_tx_common: + + ;; Store the bye to send on a stack + pha + + ;; Wait till all receivers are ready, they should all release DATA + jsr iec_wait_for_data_release + + ;; Pull CLK back to indicate that DATA is not valid, keep it for 60us + ;; Don't wait too long, as 200us or more is considered EOI + + jsr iec_pull_clk_release_data + jsr iec_wait60us + + ;; Now, we can start transmission of 8 bits of data + ldx #7 + pla + +iec_tx_common_sendbit: + ;; Is next bit 0 or 1? + lsr + pha + bcs + + + ;; Bit is 0 + jsr iec_release_clk_pull_data + jmp iec_tx_common_bit_is_sent +* + ;; Bit is 1 + jsr iec_release_clk_data + +iec_tx_common_bit_is_sent: + + ;; Wait 20us, so that device(s) can pick DATA + jsr iec_wait20us + + ;; More bits to send? + pla + dex + bpl iec_tx_common_nextbit + + ;; 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 + rts + +iec_tx_common_nextbit: + + ;; Pull CLK for 20us again, before + jsr iec_pull_clk_release_data + jsr iec_wait20us + + jmp iec_tx_common_sendbit diff --git a/c64/kernal/iec_tx_eoi.s b/c64/kernal/iec_tx_eoi.s new file mode 100644 index 00000000..bb7e3d6d --- /dev/null +++ b/c64/kernal/iec_tx_eoi.s @@ -0,0 +1,11 @@ + +iec_tx_eoi: + + ;; Wait at least 200us + jsr iec_wait100us + jsr iec_wait100us + + ;; Restore the bus to idle state + jsr iec_set_idle + + rts