some work towards I/O stack modularization

This commit is contained in:
FeralChild64 committed 2019-10-28 22:36:53 +01:00
1 parent 966658eae0
commit 6fa2c5b570
56 files changed
+357 -69

No files matched your search

+6
View File
@@ -10,5 +10,11 @@
ACPTR:
jsr kernalstatus_reset
#if CONFIG_IEC
jmp iec_rx_byte
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif
+35
View File
@@ -0,0 +1,35 @@
//
// IEC part of the CLOSE routine
//
#if CONFIG_IEC
// .Y contains LAT/FAT/SAT table index, it should stay this way
close_iec:
jsr iec_tx_flush // make sure no byte is awaiting
lda SAT, y // get secondary address
cmp #$60
bne !+
// workaround for using CLOSE on reading executable - XXX is this a proper way?
jsr iec_close_load
jmp close_remove_from_table
!:
ora $E0 // CLOSE command
sta TBTCNT
jsr iec_tx_command
bcs close_iec_end
jsr iec_tx_command_finalize
close_iec_end:
jmp close_remove_from_table
#endif // CONFIG_IEC
+11 -9
View File
@@ -6,26 +6,28 @@
//
#if CONFIG_IEC
iec_check_devnum_lvs: // for load/verify/save
cmp #$08 // below 8 are illegal for load/save
bcs !+
bcc iec_check_devnum_failed
// FALLTROUGH
iec_check_devnum_oc: // for open/close
cmp #$04 // below 4 are illegal, reserved for non-IEC devices on Commodore
bcs !+
bcc iec_check_devnum_failed
// FALLTROUGH
iec_check_devnum_failed:
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
cmp #$1F // sets carry for 31 or above
rts
iec_check_devnum_failed:
sec // indicate non-IEC device
rts
#endif // CONFIG_IEC
+29
View File
@@ -0,0 +1,29 @@
//
// Common part of CLOSE and LOAD routines for IEC
//
#if CONFIG_IEC
iec_close_load:
tax
// Command drive to stop talking and to close the file
jsr UNTLK
txa
jsr LISTEN
lda #$E0 // CLOSE command
sta TBTCNT
jsr iec_tx_command
jsr iec_tx_command_finalize
// Tell drive to unlisten
jsr UNLSN
rts
#endif // CONFIG_IEC
+7
View File
@@ -5,6 +5,10 @@
// - https://www.pagetable.com/?p=1031, https://github.com/mist64/cbmbus_doc
//
#if CONFIG_IEC
iec_cmd_close:
jsr iec_check_channel_openclose
@@ -14,3 +18,6 @@ iec_cmd_close:
ora #$E0
jmp common_open_close_unlsn_second
#endif // CONFIG_IEC
+6
View File
@@ -6,6 +6,9 @@
//
#if CONFIG_IEC
iec_cmd_open: // similar to TKSA, but without turnaround
jsr iec_check_channel_openclose
@@ -40,3 +43,6 @@ iec_check_channel_openclose:
!:
clc // mark suitable channel number
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_pull_atn_clk_release_data:
// Pulled CLK = DATA considered invalid; for extra robustness on non-emulated
@@ -13,3 +17,6 @@ iec_pull_atn_clk_release_data:
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_pull_clk_release_data:
// Pulled CLK = DATA considered invalid; for extra robustness on non-emulated
@@ -11,3 +15,5 @@ iec_pull_clk_release_data:
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_pull_clk_release_data_oneshot:
lda CIA2_PRA
@@ -6,3 +10,6 @@ iec_pull_clk_release_data_oneshot:
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
sta CIA2_PRA
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_pull_data_release_atn_clk:
// Released CLK = DATA considered valid; for extra robustness on non-emulated
@@ -13,3 +17,6 @@ iec_pull_data_release_atn_clk:
and #$FF - BIT_CIA2_PRA_ATN_OUT // release
sta CIA2_PRA
rts
#endif // CONFIG_IEC
+6
View File
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_release_atn:
lda CIA2_PRA
@@ -6,3 +10,5 @@ iec_release_atn:
sta CIA2_PRA
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_release_atn_clk_data:
// Released CLK = DATA considered valid; for extra robustness on non-emulated
@@ -14,3 +18,5 @@ iec_release_atn_clk_data:
sta CIA2_PRA
rts
#endif // CONFIG_IEC
+7
View File
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_release_clk_data:
// Released CLK = DATA considered valid; for extra robustness on non-emulated
@@ -11,3 +15,6 @@ iec_release_clk_data:
and #$FF - BIT_CIA2_PRA_CLK_OUT // release
sta CIA2_PRA
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_release_clk_pull_data:
// Released CLK = DATA considered valid; for extra robustness on non-emulated
@@ -11,3 +15,6 @@ iec_release_clk_pull_data:
and #$FF - BIT_CIA2_PRA_CLK_OUT // release
sta CIA2_PRA
rts
#endif // CONFIG_IEC
+7
View File
@@ -8,6 +8,10 @@
// take care about .A and IOSTATUS
//
#if CONFIG_IEC
iec_return_success:
// BSOUR is certainly not valid anymore
@@ -32,3 +36,6 @@ iec_return_DEVICE_NOT_FOUND:
plx_trash_a
// Report error
jmp kernalerror_DEVICE_NOT_FOUND
#endif // CONFIG_IEC
+6
View File
@@ -4,6 +4,10 @@
//
// Preserves .X and .Y registers
#if CONFIG_IEC
iec_rx_byte:
// Store .X and .Y on the stack - preserve them
@@ -143,3 +147,5 @@ iec_rx_clk_wait2:
cli
rts
#endif // CONFIG_IEC
+7
View File
@@ -1,7 +1,14 @@
#if CONFIG_IEC
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
sta CIA2_PRA
rts
#endif // CONFIG_IEC
@@ -2,6 +2,10 @@
// pages 7--8.
// See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
#if CONFIG_IEC
iec_turnaround_to_listen:
// Store .X and .Y on the stack - preserve them
@@ -34,3 +38,4 @@ iec_turnaround_to_listen:
jmp iec_return_success
#endif // CONFIG_IEC
+6
View File
@@ -2,6 +2,10 @@
// pages 7--8.
// See also https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
#if CONFIG_IEC
iec_turnaround_to_talk:
// Store .X and .Y on the stack - preserve them
@@ -25,3 +29,5 @@ iec_turnaround_to_talk:
plp
jmp iec_return_success
#endif // CONFIG_IEC
+5
View File
@@ -7,6 +7,8 @@
// Preserves .X and .Y registers
#if CONFIG_IEC
iec_tx_byte:
// Store .X and .Y on the stack - preserve them
@@ -94,3 +96,6 @@ iec_tx_common_bit_is_sent:
jmp iec_return_DEVICE_NOT_FOUND
!:
jmp iec_return_success
#endif // CONFIG_IEC
+5
View File
@@ -7,6 +7,9 @@
// Preserves .X and .Y registers
#if CONFIG_IEC
iec_tx_command:
// Store .X and .Y on the stack - preserve them
@@ -36,3 +39,5 @@ iec_tx_command:
clc // Carry flag set is used for EOI mark
jmp iec_tx_common
#endif // CONFIG_IEC
+6
View File
@@ -3,6 +3,9 @@
// Implemented based on https://www.pagetable.com/?p=1135, https://github.com/mist64/cbmbus_doc
#if CONFIG_IEC
iec_tx_command_finalize:
// Store .X and .Y on the stack - preserve them
@@ -16,3 +19,6 @@ iec_tx_command_finalize:
jsr iec_wait20us
jmp iec_return_success
#endif // CONFIG_IEC
+7
View File
@@ -3,6 +3,10 @@
//
// Preserves .X, .Y and .A registers
#if CONFIG_IEC
iec_tx_flush:
pha
@@ -13,3 +17,6 @@ iec_tx_flush:
!:
pla
rts
#endif // CONFIG_IEC
+6
View File
@@ -8,6 +8,9 @@
// 63 cycles, we need at least 17 full rasters to be 100% sure we wait enough
#if CONFIG_IEC
iec_wait1ms:
ldx #18 // we probably won't start with the beginning of raster
lda VIC_RASTER
@@ -19,3 +22,6 @@ iec_wait1ms:
bne !-
rts
#endif // CONFIG_IEC
+6
View File
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_wait20us:
// Wait 20usec
@@ -20,3 +24,5 @@ iec_wait20us:
// 1 cycle to fetch next instruction
// ---
// 21 cycles
#endif // CONFIG_IEC
+6
View File
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_wait60us:
// Wait 60usec
@@ -21,3 +25,5 @@ iec_wait60us:
// ---
// 64 cycles
#endif // CONFIG_IEC
@@ -1,7 +1,14 @@
#if CONFIG_IEC
iec_wait_for_clk_release:
lda CIA2_PRA
and #BIT_CIA2_PRA_CLK_IN
beq iec_wait_for_clk_release
rts
#endif // CONFIG_IEC
+7
View File
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_wait_for_data_pull:
lda CIA2_PRA
@@ -6,3 +10,6 @@ iec_wait_for_data_pull:
// (highest bit set = negative value)
bmi iec_wait_for_data_pull
rts
#endif // CONFIG_IEC
@@ -1,4 +1,8 @@
#if CONFIG_IEC
iec_wait_for_data_release:
lda CIA2_PRA
@@ -6,3 +10,5 @@ iec_wait_for_data_release:
// (highest bit set = negative value)
bpl iec_wait_for_data_release
rts
#endif // CONFIG_IEC
+8
View File
@@ -13,6 +13,8 @@
LISTEN:
#if CONFIG_IEC
// According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer
jsr iec_tx_flush
@@ -25,3 +27,9 @@ LISTEN:
ora #$20
jmp common_talk_listen
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif
+7 -1
View File
@@ -4,6 +4,9 @@
//
#if CONFIG_IEC
load_iec_dev_not_found:
jmp lvs_device_not_found_error
@@ -94,7 +97,10 @@ iec_load_loop:
// Close file on drive
lda FA
jsr close_load
jsr iec_close_load
// Return last address
jmp lvs_return_last_address
#endif // CONFIG_IEC
+34
View File
@@ -0,0 +1,34 @@
//
// IEC part of the OPEN routine
//
#if CONFIG_IEC
open_iec:
// We have a command to send to IEC device
jsr LISTEN
bcc !+
jmp kernalerror_DEVICE_NOT_FOUND
!:
lda SA
jsr iec_cmd_open
bcc !+
jmp kernalerror_DEVICE_NOT_FOUND
!:
#if CONFIG_MEMORY_MODEL_60K
// We need our helpers to get to filenames under ROMs or IO area
jsr install_ram_routines
#endif
// Send command ('file name')
jsr lvs_send_file_name
jmp open_done_success
#endif // CONFIG_IEC
+6
View File
@@ -12,6 +12,8 @@
SECOND:
#if CONFIG_IEC
// 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
@@ -22,4 +24,8 @@ SECOND:
jmp common_open_close_unlsn_second
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif
+8
View File
@@ -13,6 +13,8 @@
TALK:
#if CONFIG_IEC
// According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer
jsr iec_tx_flush
@@ -28,3 +30,9 @@ common_talk_listen: // common part of TALK and LISTEN
sta TBTCNT
jmp iec_tx_command
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif
+5
View File
@@ -12,6 +12,8 @@
TKSA:
#if CONFIG_IEC
// 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
@@ -22,5 +24,8 @@ TKSA:
jmp common_untlk_tksa
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif
+5
View File
@@ -13,6 +13,8 @@
UNLSN:
#if CONFIG_IEC
// According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer
jsr iec_tx_flush
@@ -21,5 +23,8 @@ UNLSN:
jmp common_open_close_unlsn_second
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif
+8
View File
@@ -13,6 +13,8 @@
UNTLK:
#if CONFIG_IEC
// According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer
jsr iec_tx_flush
@@ -31,3 +33,9 @@ common_untlk_tksa: // common part of UNTLK and TKSA
jmp iec_turnaround_to_listen
!:
rts
#else
jmp kernalerror_ILLEGAL_DEVICE_NUMBER
#endif