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

+7
View File
@@ -38,6 +38,13 @@
// #define CONFIG_MEMORY_MODEL_60K
// I/O devices
#define CONFIG_IEC // please keep enabled for now
// #define CONFIG_TAPE // please keep disabled for now
// #define CONFIG_RS_232 // please keep disabled for now
// Multiple SID support
// #define CONFIG_SID_2ND
+7
View File
@@ -40,6 +40,13 @@
// #define CONFIG_MEMORY_MODEL_60K
// I/O devices
#define CONFIG_IEC // please keep enabled for now
// #define CONFIG_TAPE // please keep disabled for now
// #define CONFIG_RS_232 // please keep disabled for now
// Multiple SID support
#define CONFIG_SID_2ND
+7
View File
@@ -39,6 +39,13 @@
#define CONFIG_MEMORY_MODEL_60K
// I/O devices
#define CONFIG_IEC // please keep enabled for now
// #define CONFIG_TAPE // please keep disabled for now
// #define CONFIG_RS_232 // please keep disabled for now
// Multiple SID support
#define CONFIG_SID_2ND
+7
View File
@@ -38,6 +38,13 @@
// #define CONFIG_MEMORY_MODEL_60K
// I/O devices
#define CONFIG_IEC // please keep enabled for now
// #define CONFIG_TAPE // please keep disabled for now
// #define CONFIG_RS_232 // please keep disabled for now
// Multiple SID support
// #define CONFIG_SID_2ND
+8
View File
@@ -39,6 +39,8 @@ chkin_real:
cmp #$01
beq chkinout_file_not_input
#if CONFIG_IEC
// For IEC devices, send TALK + TKSA first
lda FAT,Y
jsr iec_check_devnum_oc
@@ -51,6 +53,8 @@ chkin_real:
jsr TKSA
bcs chkinout_device_not_present
#endif // CONFIG_IEC
chkin_set_device:
lda FAT,Y
sta DFLTN
@@ -121,6 +125,8 @@ ckout_real:
lda LAT, Y
beq chkinout_file_not_output
#if CONFIG_IEC
// For IEC devices, send LISTEN + SECOND first
lda FAT,Y
jsr iec_check_devnum_oc
@@ -133,6 +139,8 @@ ckout_real:
jsr SECOND
bcs chkinout_device_not_present
#endif // CONFIG_IEC
chkout_set_device:
lda FAT,Y
sta DFLTO
+4
View File
@@ -23,6 +23,8 @@ chrin_real:
beq chrin_keyboard // #$00 - keyboard
// XXX add screen support
#if CONFIG_IEC
jsr iec_check_devnum_oc
bcc chrin_iec
jmp lvs_device_not_found_error // not a supported device
@@ -33,6 +35,8 @@ chrin_iec:
bcs chrin_done_fail
// FALLTROUGH
#endif // CONFIG_IEC
chrin_done:
clc // indicate success
rts
+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
@@ -1,8 +1,12 @@
//
// Common part of CLOSE and LOAD routines for IEC
//
// Common ppart of CLOSE and LOAD routines
#if CONFIG_IEC
close_load:
iec_close_load:
tax
@@ -21,3 +25,5 @@ close_load:
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -16,30 +16,21 @@ CLOSE:
// Find the LAT / SAT / FAT entry which LAT corresponds to A
jsr find_fls
bcs close_error_not_found // XXX can we report error in IOSTATUS here?
bcs close_end // XXX can we report error in IOSTATUS here?
// We have the entry index in Y - check whether this is IEC device
#if CONFIG_IEC
// We have the entry index in .Y - check whether this is IEC device
lda FAT, y
jsr iec_check_devnum_oc
bcs close_remove_from_table
bcc_far close_iec
// IEC device
#endif // CONFIG_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 close_load
jmp close_remove_from_table
!:
ora $E0 // CLOSE command
sta TBTCNT
jsr iec_tx_command
bcs close_remove_from_table
jsr iec_tx_command_finalize
// FALLTROUGH
close_remove_from_table:
// Remove channel from the table
iny
cpy #$0A
@@ -56,9 +47,6 @@ close_remove_from_table:
dec LDTND
clc // report success - not sure if original CLOSE does this, but it's nevertheless a good practice
rts
close_error_not_found:
sec // report success - not sure if original CLOSE does this, but it's nevertheless a good practice
close_end:
rts
File renamed without changes.
File renamed without changes.
@@ -23,6 +23,7 @@ OPEN:
cmp LA
bne open_not_yet_open
jmp kernalerror_FILE_ALREADY_OPEN
open_not_yet_open:
cpy #$00
jmp !-
@@ -60,33 +61,11 @@ open_has_space:
// Check for IEC device
lda FA
jsr iec_check_devnum_oc
bcc open_iec
bcc_far open_iec
// FALLTROUGH
open_done_success:
clc
rts
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
+4 -10
View File
@@ -40,15 +40,9 @@ LOAD:
// Check whether we support the requested device
lda FA
// Try IEC - legal device numbers for LOAD are 8-30
// Device numbers above 30 can not be used as IEC (see https://www.pagetable.com/?p=1031),
// as the protocol combines device number with command code in one byte, above 30 it is
// no longer possible. Original ROMs show ILLEGAL DEVICE NUMBER error only for devices
// 0-3; our implementation is more strict here
#if CONFIG_IEC
jsr iec_check_devnum_lvs
bcc_far load_iec
#endif // CONFIG_IEC
cmp #$1F
bcs !+ // >= 31
cmp #$08
bcs_far load_iec // >= 8
!:
jmp lvs_illegal_device_number
File renamed without changes.
+2 -2
View File
@@ -12,8 +12,8 @@ vector_real:
// warning and does not mention any preparations needed.
// Initial idea was to do php, cli, ..., plp to make the routine safer,
// but it seems it might cause problem with initialization sequence,
// as the stack might be uninitialized when this routine is called
// but it seems it might cause problem with initialization on XEMU emulator
// XXX find out, why
// Prepare the user data pointer - strange order to reduce risk
// of potential similarity to the original routine