adapted to Kick Assembler, some documentation update

This commit is contained in:
FeralChild64 committed 2019-09-07 12:35:21 +02:00
1 parent ae23dbae7b
commit de27124b4f
198 files changed
+4181 -3976

No files matched your search

+13 -13
View File
@@ -1,22 +1,22 @@
;;
;; Checks whether device number (in .A) is a correct IEC device number
;;
;; Preserves .A, .X and .Y
;;
//
// Checks whether device number (in .A) is a correct IEC device number
//
// Preserves .A, .X and .Y
//
iec_check_devnum:
;; 0, 1, 2, or 3 are illegal - reserved for non-IEC devices on Commodore
// 0, 1, 2, or 3 are illegal - reserved for non-IEC devices on Commodore
cmp #$04
bcs +
;; FALLTROUGH
bcs !+
// FALLTROUGH
iec_check_devnum_failed:
sec ; indicate non-IEC device
sec // indicate non-IEC device
rts
*
;; 31 and above are illegal too, due to IEC command encoding scheme,
;; see https://www.pagetable.com/?p=1031
!:
// 31 and above are illegal too, due to IEC command encoding scheme,
// see https://www.pagetable.com/?p=1031
cmp #$1F
bcs iec_check_devnum_failed
;; Carry is clear here - indicates IEC device
// Carry is clear here - indicates IEC device
rts
+7 -7
View File
@@ -1,16 +1,16 @@
;;
;; Kernal internal IEC routine
;;
;; - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc
;;
//
// Kernal internal IEC routine
//
// - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc
//
iec_cmd_close:
jsr iec_check_channel_openclose
bcc +
bcc !+
jmp kernalerror_FILE_NOT_INPUT
*
!:
ora #$E0
jmp common_open_close_unlsn_second
+22 -22
View File
@@ -1,42 +1,42 @@
;;
;; Kernal internal IEC routine
;;
;; - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc
;;
//
// Kernal internal IEC routine
//
// - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc
//
iec_cmd_open: ; similar to TKSA, but without turnaround
iec_cmd_open: // similar to TKSA, but without turnaround
jsr iec_check_channel_openclose
bcc +
bcc !+
jmp kernalerror_FILE_NOT_INPUT
*
!:
ora #$F0
;; FALLTROUGH
// FALLTROUGH
common_open_close_unlsn_second: ; common part of several commands
common_open_close_unlsn_second: // common part of several commands
sta IEC_TMP2
jsr iec_tx_command
bcs + ; branch if error
bcs !+ // branch if error
jmp iec_tx_command_finalize
*
!:
rts
iec_check_channel_openclose:
;; Due to OPEN/CLOSE/TKSA/SECOND command encoding (see https://www.pagetable.com/?p=1031),
;; allowed channels are 0-15; report error if out of range
// Due to OPEN/CLOSE/TKSA/SECOND command encoding (see https://www.pagetable.com/?p=1031),
// allowed channels are 0-15; report error if out of range
cmp #$10
bcc +
;; Workaround to allow reading executable files and disk directory
;; using OPEN routine - see https://www.pagetable.com/?p=273 for
;; example usage
bcc !+
// Workaround to allow reading executable files and disk directory
// using OPEN routine - see https://www.pagetable.com/?p=273 for
// example usage
cmp #$60
beq +
sec ; mark unsuitable channel number
beq !+
sec // mark unsuitable channel number
rts
*
clc ; mark suitable channel number
!:
clc // mark suitable channel number
rts
@@ -1,15 +1,15 @@
iec_pull_atn_clk_release_data:
;; Pulled CLK = DATA considered invalid; for extra robustness on non-emulated
;; hardware give some lines few more cycles to stabilize; see page 10 of
;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// Pulled CLK = DATA considered invalid; for extra robustness on non-emulated
// hardware give some lines few more cycles to stabilize; see page 10 of
// http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
lda CIA2_PRA
ora #BIT_CIA2_PRA_ATN_OUT ; pull
ora #BIT_CIA2_PRA_ATN_OUT // pull
sta CIA2_PRA
ora #BIT_CIA2_PRA_CLK_OUT ; pull
ora #BIT_CIA2_PRA_CLK_OUT // pull
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT ; release
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
rts
+5 -5
View File
@@ -1,13 +1,13 @@
iec_pull_clk_release_data:
;; Pulled CLK = DATA considered invalid; for extra robustness on non-emulated
;; hardware give some lines few more cycles to stabilize; see page 10 of
;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// Pulled CLK = DATA considered invalid; for extra robustness on non-emulated
// hardware give some lines few more cycles to stabilize; see page 10 of
// http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
lda CIA2_PRA
ora #BIT_CIA2_PRA_CLK_OUT ; pull
ora #BIT_CIA2_PRA_CLK_OUT // pull
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT ; release
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
rts
@@ -2,7 +2,7 @@
iec_pull_clk_release_data_oneshot:
lda CIA2_PRA
ora #BIT_CIA2_PRA_CLK_OUT ; pull
and #$FF - BIT_CIA2_PRA_DAT_OUT ; release
ora #BIT_CIA2_PRA_CLK_OUT // pull
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
rts
@@ -1,15 +1,15 @@
iec_pull_data_release_atn_clk:
;; Released CLK = DATA considered valid; for extra robustness on non-emulated
;; hardware give some lines few more cycles to stabilize; see page 10 of
;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// Released CLK = DATA considered valid; for extra robustness on non-emulated
// hardware give some lines few more cycles to stabilize; see page 10 of
// http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
lda CIA2_PRA
ora #BIT_CIA2_PRA_DAT_OUT ; pull
ora #BIT_CIA2_PRA_DAT_OUT // pull
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_CLK_OUT ; release
and #$FF - BIT_CIA2_PRA_CLK_OUT // release
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_ATN_OUT ; release
and #$FF - BIT_CIA2_PRA_ATN_OUT // release
sta CIA2_PRA
rts
+1 -1
View File
@@ -2,7 +2,7 @@
iec_release_atn:
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_ATN_OUT ; release
and #$FF - BIT_CIA2_PRA_ATN_OUT // release
sta CIA2_PRA
rts
+6 -6
View File
@@ -1,16 +1,16 @@
iec_release_atn_clk_data:
;; Released CLK = DATA considered valid; for extra robustness on non-emulated
;; hardware give some lines few more cycles to stabilize; see page 10 of
;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// Released CLK = DATA considered valid; for extra robustness on non-emulated
// hardware give some lines few more cycles to stabilize; see page 10 of
// http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_ATN_OUT ; release
and #$FF - BIT_CIA2_PRA_ATN_OUT // release
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT ; release
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_CLK_OUT ; release
and #$FF - BIT_CIA2_PRA_CLK_OUT // release
sta CIA2_PRA
rts
+5 -5
View File
@@ -1,13 +1,13 @@
iec_release_clk_data:
;; Released CLK = DATA considered valid; for extra robustness on non-emulated
;; hardware give some lines few more cycles to stabilize; see page 10 of
;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// Released CLK = DATA considered valid; for extra robustness on non-emulated
// hardware give some lines few more cycles to stabilize; see page 10 of
// http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT ; release
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_CLK_OUT ; release
and #$FF - BIT_CIA2_PRA_CLK_OUT // release
sta CIA2_PRA
rts
+5 -5
View File
@@ -1,13 +1,13 @@
iec_release_clk_pull_data:
;; Released CLK = DATA considered valid; for extra robustness on non-emulated
;; hardware give some lines few more cycles to stabilize; see page 10 of
;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// Released CLK = DATA considered valid; for extra robustness on non-emulated
// hardware give some lines few more cycles to stabilize; see page 10 of
// http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
lda CIA2_PRA
ora #BIT_CIA2_PRA_DAT_OUT ; pull
ora #BIT_CIA2_PRA_DAT_OUT // pull
sta CIA2_PRA
and #$FF - BIT_CIA2_PRA_CLK_OUT ; release
and #$FF - BIT_CIA2_PRA_CLK_OUT // release
sta CIA2_PRA
rts
+15 -15
View File
@@ -1,38 +1,38 @@
;;
;; Helper routines to return with error/success
;;
;; All of them restore X/Y registers from stack,
;; they take care about Carry flag,
;; error return reeset IEC line to default state,
;; take care about .A and IOSTATUS
;;
//
// Helper routines to return with error/success
//
// All of them restore X/Y registers from stack,
// they take care about Carry flag,
// error return reeset IEC line to default state,
// take care about .A and IOSTATUS
//
iec_return_success:
;; BSOUR is certainly not valid anymore
// BSOUR is certainly not valid anymore
lda #$00
sta C3PO
;; Restore registers
// Restore registers
pla
tay
pla
tax
;; Report success
// Report success
clc
rts
iec_return_DEVICE_NOT_FOUND:
;; Set IEC line to normal idle state
// Set IEC line to normal idle state
jsr iec_set_idle
;; BSOUR is certainly not valid anymore
// BSOUR is certainly not valid anymore
lda #$00
sta C3PO
;; Restore registers
// Restore registers
pla
tay
pla
tax
;; Report error
// Report error
jmp kernalerror_DEVICE_NOT_FOUND
+70 -70
View File
@@ -1,141 +1,141 @@
;; 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
// 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
// Store .X and .Y on the stack - preserve them
txa
pha
tya
pha
;; Timing is critical here - execute on disabled IRQs
// Timing is critical here - execute on disabled IRQs
php
sei
;; First, we wait for the talker to release the CLK line
// First, we wait for the talker to release the CLK line
jsr iec_wait_for_clk_release
;; We then release the DATA to signal we are ready
;; We can use this routine, since we weren't pulling CLK anyway
// We then release the DATA to signal we are ready
// We can use this routine, since we weren't pulling CLK anyway
jsr iec_release_clk_data
;; Wait till data line is released (someone else might be holding it)
// Wait till data line is released (someone else might be holding it)
jsr iec_wait_for_data_release
;; Wait for talker to pull CLK.
;; If over 200 usec (205 cycles on NTSC machine) , then it is EOI.
;; Loop iteraction takes 13 cycles, 17 full iterations are enough
// Wait for talker to pull CLK.
// If over 200 usec (205 cycles on NTSC machine) , then it is EOI.
// Loop iteraction takes 13 cycles, 17 full iterations are enough
ldx #$11 ; 2 cycles
ldx #$11 // 2 cycles
iec_rx_clk_wait1:
lda CIA2_PRA ; 4 cycles
rol ; 2 cycles, to put CLK in as the last bit
bpl iec_rx_not_eoi ; 2 cycles if not jumped
dex ; 2 cycles
bne iec_rx_clk_wait1 ; 3 cycles if jumped
lda CIA2_PRA // 4 cycles
rol // 2 cycles, to put CLK in as the last bit
bpl iec_rx_not_eoi // 2 cycles if not jumped
dex // 2 cycles
bne iec_rx_clk_wait1 // 3 cycles if jumped
;; Timeout - either this is the last byte of stream, or the stream is empty at all.
;; Mark end of stream in IOSTATUS
jsr kernalstatus_EOI
// Timeout - either this is the last byte of stream, or the stream is empty at all.
// Mark end of stream in IOSTATUS
jsr kernalstatus_EOI
iec_rx_not_empty:
;; Pull data for 60 usec to confirm it
// Pull data for 60 usec to confirm it
jsr iec_release_clk_pull_data
jsr iec_wait60us
jsr iec_release_clk_data
iec_rx_not_eoi:
;; Latch input bits in on rising edge of CLK, eight times for eight bits.
// Latch input bits in on rising edge of CLK, eight times for eight bits.
ldx #7
;; Get empty byte to load into.
// Get empty byte to load into.
lda #$00
pha
iec_rx_bit_loop:
;; Wait for CLK to release
// Wait for CLK to release
jsr iec_wait_for_clk_release
;; (we do this implicitly below, with a tighter routine,
;; so that we don't have timing problems, as the requirements
;; are quite tight. Basically we need to read the clock and data
;; bit from the same byte read.
// (we do this implicitly below, with a tighter routine,
// so that we don't have timing problems, as the requirements
// are quite tight. Basically we need to read the clock and data
// bit from the same byte read.
;; DATA now has the next bit, but inverted (well, except that it turns out not to be).
;; DATA is in bit 7, which is a bit annoying.
;; But we can clock it out with a ROL instruction
;; so that it is in C. We can then ROR it into the
;; partial data byte.
;; We use ROR so that we shift in from the top, so that
;; the first bit we shift in ends up in bit 0 after all
;; 8 bits have been read.
;; ODD: For some reason we don't need to invert the
;; received bits. This is weird, because we invert them
;; on the way out, and everything in the protocol seems
;; to indicate that we sould do so. But experimentation
;; has confirmed the bits don't need inversion on reception.
// DATA now has the next bit, but inverted (well, except that it turns out not to be).
// DATA is in bit 7, which is a bit annoying.
// But we can clock it out with a ROL instruction
// so that it is in C. We can then ROR it into the
// partial data byte.
// We use ROR so that we shift in from the top, so that
// the first bit we shift in ends up in bit 0 after all
// 8 bits have been read.
// ODD: For some reason we don't need to invert the
// received bits. This is weird, because we invert them
// on the way out, and everything in the protocol seems
// to indicate that we sould do so. But experimentation
// has confirmed the bits don't need inversion on reception.
;; Move data bit into C flag, and loop until bit 6 clears
;; i.e., the clock has been released.
// Move data bit into C flag, and loop until bit 6 clears
// i.e., the clock has been released.
* lda CIA2_PRA
!: lda CIA2_PRA
rol
bpl -
bpl !-
;; Pull it into the data byte
// Pull it into the data byte
pla
ror
pha
;; Wait for CLK to be pulled again, over 300 usec (307 cycles on NTSC)
;; consider this a timeout
ldy #$19 ; 2 cycles
// Wait for CLK to be pulled again, over 300 usec (307 cycles on NTSC)
// consider this a timeout
ldy #$19 // 2 cycles
iec_rx_clk_wait2:
lda CIA2_PRA ; 4 cycles
rol ; 2 cycles, to put CLK in as the last bit
bpl + ; 2 cycles if not jumped
dey ; 2 cycles
bne iec_rx_clk_wait2 ; 3 cycles if jumped
lda CIA2_PRA // 4 cycles
rol // 2 cycles, to put CLK in as the last bit
bpl !+ // 2 cycles if not jumped
dey // 2 cycles
bne iec_rx_clk_wait2 // 3 cycles if jumped
;; Timeout
// Timeout
jsr kernalstatus_EOI
pla
plp
;; Restore registers
// Restore registers
pla
tay
pla
tax
sec ; XXX confirm that sec is really a way to report timeout here
sec // XXX confirm that sec is really a way to report timeout here
rts
*
;; More bits?
!:
// More bits?
dex
bpl iec_rx_bit_loop
;; Then we must within 1000 usec acknowledge the frame by
;; pulling DATA. At this point, CLK is pulled by the
;; talker and DATA by us, i.e., we are ready to receive
;; the next byte. (p11).
// Then we must within 1000 usec acknowledge the frame by
// pulling DATA. At this point, CLK is pulled by the
// talker and DATA by us, i.e., we are ready to receive
// the next byte. (p11).
jsr iec_release_clk_pull_data
;; Retreive the received byte
// Retreive the received byte
pla
;; Return no-error
// Return no-error
plp
;; Restore registers
sta IEC_TMP2 ; $A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html
// Restore registers
sta IEC_TMP2 // $A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html
pla
tay
pla
+2 -2
View File
@@ -1,7 +1,7 @@
iec_set_idle:
lda CIA2_PRA
ora #BIT_CIA2_PRA_CLK_OUT ; pull
and #$FF - BIT_CIA2_PRA_DAT_OUT - BIT_CIA2_PRA_ATN_OUT ; release
ora #BIT_CIA2_PRA_CLK_OUT // pull
and #$FF - BIT_CIA2_PRA_DAT_OUT - BIT_CIA2_PRA_ATN_OUT // release
sta CIA2_PRA
rts
+15 -15
View File
@@ -1,37 +1,37 @@
;; According to http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
;; pages 7--8.
;; See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
// According to http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// pages 7--8.
// See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
iec_turnaround_to_listen:
;; Store .X and .Y on the stack - preserve them
// Store .X and .Y on the stack - preserve them
txa
pha
tya
pha
;; Timing is critical here - execute on disabled IRQs
// Timing is critical here - execute on disabled IRQs
php
sei
;; Pull DATA, release CLK and ATN (we are not sending commands)
// Pull DATA, release CLK and ATN (we are not sending commands)
jsr iec_pull_data_release_atn_clk
;; Wait for clock line to be pulled by the drive
ldx #$FF ; XXX should we really use that high number?
*
// Wait for clock line to be pulled by the drive
ldx #$FF // XXX should we really use that high number?
!:
lda CIA2_PRA
rol ; to put BIT_CIA2_PRA_CLK_IN as the last (sign) bit
bpl +
rol // to put BIT_CIA2_PRA_CLK_IN as the last (sign) bit
bpl !+
dex
bne -
bne !-
;; Timeout - XXX what errors do original Kernal report?
// Timeout - XXX what errors do original Kernal report?
plp
jmp iec_return_DEVICE_NOT_FOUND
;; CLK is pulled by the device, OK
*
// CLK is pulled by the device, OK
!:
plp
jmp iec_return_success
+8 -8
View File
@@ -1,27 +1,27 @@
;; According to http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
;; pages 7--8.
;; See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
// According to http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
// pages 7--8.
// See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
iec_turnaround_to_talk:
;; Store .X and .Y on the stack - preserve them
// Store .X and .Y on the stack - preserve them
txa
pha
tya
pha
;; Timing is critical here - execute on disabled IRQs
// Timing is critical here - execute on disabled IRQs
php
sei
;; First make sure both CLK, DATA and ATN are released at our side
// 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
// Wait till device releases CLK line
jsr iec_wait_for_clk_release
;; Pull CLK line, it should be held by talker
// Pull CLK line, it should be held by talker
jsr iec_pull_clk_release_data
plp
+40 -40
View File
@@ -1,96 +1,96 @@
;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
// Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
;; 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
// 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
iec_tx_byte:
;; Store .X and .Y on the stack - preserve them
// Store .X and .Y on the stack - preserve them
txa
pha
tya
pha
;; Notify all devices that we are going to send a byte
;; and it is going to be a data byte (released ATN)
// 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_tx_byte and iec_tx_command
;; 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
// 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
// and http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf
iec_tx_common:
;; Timing is critical here - execute on disabled IRQs
// Timing is critical here - execute on disabled IRQs
php
sei
;; Wait till all receivers are ready, they should all release DATA
// Wait till all receivers are ready, they should all release DATA
jsr iec_wait_for_data_release
bcc +
bcc !+
;; At this point a delay 256 usec or more is considered EOI,
;; receiver should now acknowledge it by pulling data for at least 60 usec
;; Keep the implementation as simple as possible: data should be released now
;; so wait until it's pushed and released again
// At this point a delay 256 usec or more is considered EOI,
// receiver should now acknowledge it by pulling data for at least 60 usec
// Keep the implementation as simple as possible: data should be released now
// so wait until it's pushed and released again
jsr iec_wait_for_data_pull
jsr iec_wait_for_data_release
*
;; Pull CLK back to indicate that DATA is not valid, keep it for 60us
;; We can use this routine as we don't hold DATA anyway (and its state doesn't even matter)
!:
// Pull CLK back to indicate that DATA is not valid, keep it for 60us
// We can use this routine as we don't hold DATA anyway (and its state doesn't even matter)
jsr iec_pull_clk_release_data_oneshot
jsr iec_wait60us
;; Now, we can start transmission of 8 bits of data
// Now, we can start transmission of 8 bits of data
ldx #7
iec_tx_common_sendbit:
;; Is next bit 0 or 1?
// Is next bit 0 or 1?
lda IEC_TMP2
lsr
sta IEC_TMP2
bcs +
bcs !+
;; Bit is 0
// Bit is 0
jsr iec_release_clk_pull_data
jmp iec_tx_common_bit_is_sent
*
;; Bit is 1
!:
// Bit is 1
jsr iec_release_clk_data
iec_tx_common_bit_is_sent:
;; Wait 20us, so that device(s) can pick DATA
// Wait 20us, so that device(s) can pick DATA
jsr iec_wait20us
;; Pull CLK for 20us again, before sending the next bit
;; or performing any other action
// Pull CLK for 20us again, before sending the next bit
// or performing any other action
jsr iec_pull_clk_release_data_oneshot
jsr iec_wait20us
;; More bits to send?
// More bits to send?
dex
bpl iec_tx_common_sendbit
plp
;; Give device time to tell if they are busy by pulling DATA
;; They should do it within 1ms
// Give device time to tell if they are busy by pulling DATA
// They should do it within 1ms
ldx #$FF
* lda CIA2_PRA
;; BPL here is checking that bit 7 clears,
;; i.e, that the DATA line is pulled by drive
bpl +
!: lda CIA2_PRA
// BPL here is checking that bit 7 clears,
// i.e, that the DATA line is pulled by drive
bpl !+
dex
bne -
bmi +
bne !-
bmi !+
jmp iec_return_DEVICE_NOT_FOUND
*
!:
jmp iec_return_success
+19 -19
View File
@@ -1,40 +1,40 @@
;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
// Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
;; 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
// 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
iec_tx_command:
;; Store .X and .Y on the stack - preserve them
// Store .X and .Y on the stack - preserve them
txa
pha
tya
pha
;; Notify all devices that we are going to send a byte
;; and it is going to be a command (pulled ATN)
// Notify all devices that we are going to send a byte
// and it is going to be a command (pulled ATN)
jsr iec_pull_atn_clk_release_data
;; Give devices time to respond (response is mandatory!) by pulling DATA
// Give devices time to respond (response is mandatory!) by pulling DATA
jsr iec_wait1ms
lda CIA2_PRA ; pulled DATA = highest bit 0 = 'plus'
bpl +
lda CIA2_PRA // pulled DATA = highest bit 0 = 'plus'
bpl !+
jmp iec_return_DEVICE_NOT_FOUND
*
;; 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 - to ask devices for status.
!:
// 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 - to ask devices for status.
jsr iec_release_clk_data
;; Common part of iec_txbyte and iec_tx_common - waits for devices
;; and transmits a byte
// Common part of iec_txbyte and iec_tx_common - waits for devices
// and transmits a byte
clc ; Carry flag set is used for EOI mark
clc // Carry flag set is used for EOI mark
jmp iec_tx_common
+5 -5
View File
@@ -1,18 +1,18 @@
;; Routine to finalize some IEC commands - which do not end in turnaround and are not followed by others
;; Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
// Routine to finalize some IEC commands - which do not end in turnaround and are not followed by others
// 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
// 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
// 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
+7 -7
View File
@@ -1,15 +1,15 @@
;; Flush the IEC output buffer (if not empty) - send byte with EOI
;;
;; Preserves .X, .Y and .A registers
// Flush the IEC output buffer (if not empty) - send byte with EOI
//
// Preserves .X, .Y and .A registers
iec_tx_flush:
pha
lda C3PO
beq +
sec ; send it with EOI
jsr iec_tx_byte ; send the command regardless of the status
*
beq !+
sec // send it with EOI
jsr iec_tx_byte // send the command regardless of the status
!:
pla
rts
+11 -11
View File
@@ -1,21 +1,21 @@
;;
;; Wait 1 ms (1000 usec)
;;
;; On NTSC this means 1023 cycles (slightly less on PAL, but we have to be sure).
;; We can't count on badlines, as the screen might be disabled.
;; Delay here is implemeented using VIC-II raster register. Since one raster is
;; 63 cycles, we need at least 17 full rasters to be 100% sure we wait enough
//
// Wait 1 ms (1000 usec)
//
// On NTSC this means 1023 cycles (slightly less on PAL, but we have to be sure).
// We can't count on badlines, as the screen might be disabled.
// Delay here is implemeented using VIC-II raster register. Since one raster is
// 63 cycles, we need at least 17 full rasters to be 100% sure we wait enough
iec_wait1ms:
ldx #18 ; we probably won't start with the beginning of raster
ldx #18 // we probably won't start with the beginning of raster
lda VIC_RASTER
*
!:
cmp VIC_RASTER
beq -
beq !-
lda VIC_RASTER
dex
bne -
bne !-
rts
+15 -15
View File
@@ -1,22 +1,22 @@
iec_wait20us:
;; Wait 20usec
// Wait 20usec
;; PAL:
;; - CPU frequency 0.985248 MHz, we need to waste at least 20 cycles
;; NTSC:
;; - CPU frequency 1.022727 MHz, we need to waste at least 21 cycles
// PAL:
// - CPU frequency 0.985248 MHz, we need to waste at least 20 cycles
// NTSC:
// - CPU frequency 1.022727 MHz, we need to waste at least 21 cycles
;; Waste cycles by reading some unimportant memory location
;; in order not to clutter VICE debug logs
// Waste cycles by reading some unimportant memory location
// in order not to clutter VICE debug logs
ora $03FF ; 4 cycles
ora $03FF ; 4 cycles
rts ; 6 cycles
ora $03FF // 4 cycles
ora $03FF // 4 cycles
rts // 6 cycles
;; 6 cycles JSR to routine,
;; 14 cycles routine with RTS
;; 1 cycle to fetch next instruction
;; ---
;; 21 cycles
// 6 cycles JSR to routine,
// 14 cycles routine with RTS
// 1 cycle to fetch next instruction
// ---
// 21 cycles
+15 -15
View File
@@ -1,23 +1,23 @@
iec_wait60us:
;; Wait 60usec
// Wait 60usec
;; PAL:
;; - CPU frequency 0.985248 MHz, we need to waste at least 60 cycles
;; NTSC:
;; - CPU frequency 1.022727 MHz, we need to waste at least 62 cycles
// PAL:
// - CPU frequency 0.985248 MHz, we need to waste at least 60 cycles
// NTSC:
// - CPU frequency 1.022727 MHz, we need to waste at least 62 cycles
;; Waste cycles in a loop
// Waste cycles in a loop
ldy #$0A ; 2 cycles
* dey ; 2 cycles * 10
bpl - ; 3 cycles * 9 + 2 cycles
rts ; 6 cycles
ldy #$0A // 2 cycles
!: dey // 2 cycles * 10
bpl !- // 3 cycles * 9 + 2 cycles
rts // 6 cycles
;; 6 cycles JSR to routine,
;; 57 cycles routine with RTS
;; 1 cycle to fetch next instruction
;; ---
;; 64 cycles
// 6 cycles JSR to routine,
// 57 cycles routine with RTS
// 1 cycle to fetch next instruction
// ---
// 64 cycles
+2 -2
View File
@@ -2,7 +2,7 @@
iec_wait_for_data_pull:
lda CIA2_PRA
;; Check the highest bit, which is DATA IN,
;; (highest bit set = negative value)
// Check the highest bit, which is DATA IN,
// (highest bit set = negative value)
bmi iec_wait_for_data_pull
rts
+2 -2
View File
@@ -2,7 +2,7 @@
iec_wait_for_data_release:
lda CIA2_PRA
;; Check the highest bit, which is DATA IN,
;; (highest bit set = negative value)
// Check the highest bit, which is DATA IN,
// (highest bit set = negative value)
bpl iec_wait_for_data_release
rts