From 6fa2c5b570277c3bb1247a6324a21cafb1511491 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Mon, 28 Oct 2019 22:36:53 +0100 Subject: [PATCH] some work towards I/O stack modularization --- c64/,,config_generic.s | 7 ++++ c64/,,config_mega65.s | 7 ++++ c64/,,config_testing.s | 7 ++++ c64/,,config_ultimate64.s | 7 ++++ c64/kernal/chkinout_real.s | 8 +++++ c64/kernal/chrin_real.s | 4 +++ c64/kernal/iec/acptr.s | 6 ++++ c64/kernal/iec/close_iec.s | 35 +++++++++++++++++++ c64/kernal/iec/iec_check_devnum.s | 20 ++++++----- .../{close_load.s => iec/iec_close_load.s} | 10 ++++-- c64/kernal/iec/iec_cmd_close.s | 7 ++++ c64/kernal/iec/iec_cmd_open.s | 6 ++++ .../iec/iec_pull_atn_clk_release_data.s | 7 ++++ c64/kernal/iec/iec_pull_clk_release_data.s | 6 ++++ .../iec/iec_pull_clk_release_data_oneshot.s | 7 ++++ .../iec/iec_pull_data_release_atn_clk.s | 7 ++++ c64/kernal/iec/iec_release_atn.s | 6 ++++ c64/kernal/iec/iec_release_atn_clk_data.s | 6 ++++ c64/kernal/iec/iec_release_clk_data.s | 7 ++++ c64/kernal/iec/iec_release_clk_pull_data.s | 7 ++++ c64/kernal/iec/iec_return.s | 7 ++++ c64/kernal/iec/iec_rx_byte.s | 6 ++++ c64/kernal/iec/iec_set_idle.s | 7 ++++ c64/kernal/iec/iec_turnaround_to_listen.s | 5 +++ c64/kernal/iec/iec_turnaround_to_talk.s | 6 ++++ c64/kernal/iec/iec_tx_byte.s | 5 +++ c64/kernal/iec/iec_tx_command.s | 5 +++ c64/kernal/iec/iec_tx_command_finalize.s | 6 ++++ c64/kernal/iec/iec_tx_flush.s | 7 ++++ c64/kernal/iec/iec_wait1ms.s | 6 ++++ c64/kernal/iec/iec_wait20us.s | 6 ++++ c64/kernal/iec/iec_wait60us.s | 6 ++++ c64/kernal/iec/iec_wait_for_clk_release.s | 7 ++++ c64/kernal/iec/iec_wait_for_data_pull.s | 7 ++++ c64/kernal/iec/iec_wait_for_data_release.s | 6 ++++ c64/kernal/iec/listen.s | 8 +++++ c64/kernal/iec/load_iec.s | 8 ++++- c64/kernal/iec/open_iec.s | 34 ++++++++++++++++++ c64/kernal/iec/second.s | 6 ++++ c64/kernal/iec/talk.s | 8 +++++ c64/kernal/iec/tksa.s | 5 +++ c64/kernal/iec/unlsn.s | 5 +++ c64/kernal/iec/untlk.s | 8 +++++ c64/kernal/{ => init}/fffc.interop | 0 c64/kernal/{ => init}/fffc.vector_reset.s | 0 c64/kernal/{ => interrupts}/fffa.interop | 0 c64/kernal/{ => interrupts}/fffa.vector_nmi.s | 0 c64/kernal/{ => interrupts}/fffe.interop | 0 c64/kernal/{ => interrupts}/fffe.vector_irq.s | 0 c64/kernal/{ => iostack}/f291.close.s | 30 +++++----------- c64/kernal/{ => iostack}/f291.interop | 0 c64/kernal/{ => iostack}/f34a.interop | 0 c64/kernal/{ => iostack}/f34a.open.s | 27 ++------------ c64/kernal/iostack/f4a5.load.s | 14 +++----- c64/kernal/{ => keyboard}/f6ed.stop.s | 0 c64/kernal/vector_real.s | 4 +-- 56 files changed, 357 insertions(+), 69 deletions(-) create mode 100644 c64/kernal/iec/close_iec.s rename c64/kernal/{close_load.s => iec/iec_close_load.s} (67%) create mode 100644 c64/kernal/iec/open_iec.s rename c64/kernal/{ => init}/fffc.interop (100%) rename c64/kernal/{ => init}/fffc.vector_reset.s (100%) rename c64/kernal/{ => interrupts}/fffa.interop (100%) rename c64/kernal/{ => interrupts}/fffa.vector_nmi.s (100%) rename c64/kernal/{ => interrupts}/fffe.interop (100%) rename c64/kernal/{ => interrupts}/fffe.vector_irq.s (100%) rename c64/kernal/{ => iostack}/f291.close.s (58%) rename c64/kernal/{ => iostack}/f291.interop (100%) rename c64/kernal/{ => iostack}/f34a.interop (100%) rename c64/kernal/{ => iostack}/f34a.open.s (71%) rename c64/kernal/{ => keyboard}/f6ed.stop.s (100%) diff --git a/c64/,,config_generic.s b/c64/,,config_generic.s index d2b302e4..62588e3f 100644 --- a/c64/,,config_generic.s +++ b/c64/,,config_generic.s @@ -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 diff --git a/c64/,,config_mega65.s b/c64/,,config_mega65.s index 12e3d146..57c09be7 100644 --- a/c64/,,config_mega65.s +++ b/c64/,,config_mega65.s @@ -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 diff --git a/c64/,,config_testing.s b/c64/,,config_testing.s index 7f5c679a..8393da38 100644 --- a/c64/,,config_testing.s +++ b/c64/,,config_testing.s @@ -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 diff --git a/c64/,,config_ultimate64.s b/c64/,,config_ultimate64.s index 549c531d..d36e6723 100644 --- a/c64/,,config_ultimate64.s +++ b/c64/,,config_ultimate64.s @@ -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 diff --git a/c64/kernal/chkinout_real.s b/c64/kernal/chkinout_real.s index 15a986a1..427d1c63 100644 --- a/c64/kernal/chkinout_real.s +++ b/c64/kernal/chkinout_real.s @@ -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 diff --git a/c64/kernal/chrin_real.s b/c64/kernal/chrin_real.s index 684e5060..f744920c 100644 --- a/c64/kernal/chrin_real.s +++ b/c64/kernal/chrin_real.s @@ -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 diff --git a/c64/kernal/iec/acptr.s b/c64/kernal/iec/acptr.s index b7ee27ce..4c9756e4 100644 --- a/c64/kernal/iec/acptr.s +++ b/c64/kernal/iec/acptr.s @@ -10,5 +10,11 @@ ACPTR: + jsr kernalstatus_reset + +#if CONFIG_IEC jmp iec_rx_byte +#else + jmp kernalerror_ILLEGAL_DEVICE_NUMBER +#endif diff --git a/c64/kernal/iec/close_iec.s b/c64/kernal/iec/close_iec.s new file mode 100644 index 00000000..0cdc2801 --- /dev/null +++ b/c64/kernal/iec/close_iec.s @@ -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 diff --git a/c64/kernal/iec/iec_check_devnum.s b/c64/kernal/iec/iec_check_devnum.s index ff08bdc5..e6ac9c08 100644 --- a/c64/kernal/iec/iec_check_devnum.s +++ b/c64/kernal/iec/iec_check_devnum.s @@ -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 diff --git a/c64/kernal/close_load.s b/c64/kernal/iec/iec_close_load.s similarity index 67% rename from c64/kernal/close_load.s rename to c64/kernal/iec/iec_close_load.s index efb0b013..180d6c6f 100644 --- a/c64/kernal/close_load.s +++ b/c64/kernal/iec/iec_close_load.s @@ -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 diff --git a/c64/kernal/iec/iec_cmd_close.s b/c64/kernal/iec/iec_cmd_close.s index 114cf0e4..126cb04e 100644 --- a/c64/kernal/iec/iec_cmd_close.s +++ b/c64/kernal/iec/iec_cmd_close.s @@ -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 diff --git a/c64/kernal/iec/iec_cmd_open.s b/c64/kernal/iec/iec_cmd_open.s index 5cc86ccb..48fceb28 100644 --- a/c64/kernal/iec/iec_cmd_open.s +++ b/c64/kernal/iec/iec_cmd_open.s @@ -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 diff --git a/c64/kernal/iec/iec_pull_atn_clk_release_data.s b/c64/kernal/iec/iec_pull_atn_clk_release_data.s index 62da6f12..1b8ba0d9 100644 --- a/c64/kernal/iec/iec_pull_atn_clk_release_data.s +++ b/c64/kernal/iec/iec_pull_atn_clk_release_data.s @@ -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 diff --git a/c64/kernal/iec/iec_pull_clk_release_data.s b/c64/kernal/iec/iec_pull_clk_release_data.s index 2b1a58f8..18ffda0a 100644 --- a/c64/kernal/iec/iec_pull_clk_release_data.s +++ b/c64/kernal/iec/iec_pull_clk_release_data.s @@ -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 diff --git a/c64/kernal/iec/iec_pull_clk_release_data_oneshot.s b/c64/kernal/iec/iec_pull_clk_release_data_oneshot.s index b2a80988..f3d7696b 100644 --- a/c64/kernal/iec/iec_pull_clk_release_data_oneshot.s +++ b/c64/kernal/iec/iec_pull_clk_release_data_oneshot.s @@ -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 diff --git a/c64/kernal/iec/iec_pull_data_release_atn_clk.s b/c64/kernal/iec/iec_pull_data_release_atn_clk.s index f7c71da4..58d3ca1f 100644 --- a/c64/kernal/iec/iec_pull_data_release_atn_clk.s +++ b/c64/kernal/iec/iec_pull_data_release_atn_clk.s @@ -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 diff --git a/c64/kernal/iec/iec_release_atn.s b/c64/kernal/iec/iec_release_atn.s index d7493aa0..c9d49478 100644 --- a/c64/kernal/iec/iec_release_atn.s +++ b/c64/kernal/iec/iec_release_atn.s @@ -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 diff --git a/c64/kernal/iec/iec_release_atn_clk_data.s b/c64/kernal/iec/iec_release_atn_clk_data.s index 07f5c4da..b572dfc3 100644 --- a/c64/kernal/iec/iec_release_atn_clk_data.s +++ b/c64/kernal/iec/iec_release_atn_clk_data.s @@ -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 diff --git a/c64/kernal/iec/iec_release_clk_data.s b/c64/kernal/iec/iec_release_clk_data.s index 83af42aa..35deb964 100644 --- a/c64/kernal/iec/iec_release_clk_data.s +++ b/c64/kernal/iec/iec_release_clk_data.s @@ -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 diff --git a/c64/kernal/iec/iec_release_clk_pull_data.s b/c64/kernal/iec/iec_release_clk_pull_data.s index 359c02f3..ad98c987 100644 --- a/c64/kernal/iec/iec_release_clk_pull_data.s +++ b/c64/kernal/iec/iec_release_clk_pull_data.s @@ -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 diff --git a/c64/kernal/iec/iec_return.s b/c64/kernal/iec/iec_return.s index de3f8b01..b73a8d1f 100644 --- a/c64/kernal/iec/iec_return.s +++ b/c64/kernal/iec/iec_return.s @@ -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 diff --git a/c64/kernal/iec/iec_rx_byte.s b/c64/kernal/iec/iec_rx_byte.s index 2f859cf7..cd86f951 100644 --- a/c64/kernal/iec/iec_rx_byte.s +++ b/c64/kernal/iec/iec_rx_byte.s @@ -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 diff --git a/c64/kernal/iec/iec_set_idle.s b/c64/kernal/iec/iec_set_idle.s index 9b0015d0..4833eba6 100644 --- a/c64/kernal/iec/iec_set_idle.s +++ b/c64/kernal/iec/iec_set_idle.s @@ -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 diff --git a/c64/kernal/iec/iec_turnaround_to_listen.s b/c64/kernal/iec/iec_turnaround_to_listen.s index be31bf02..f77a5a54 100644 --- a/c64/kernal/iec/iec_turnaround_to_listen.s +++ b/c64/kernal/iec/iec_turnaround_to_listen.s @@ -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 diff --git a/c64/kernal/iec/iec_turnaround_to_talk.s b/c64/kernal/iec/iec_turnaround_to_talk.s index 3612460c..624c648d 100644 --- a/c64/kernal/iec/iec_turnaround_to_talk.s +++ b/c64/kernal/iec/iec_turnaround_to_talk.s @@ -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 diff --git a/c64/kernal/iec/iec_tx_byte.s b/c64/kernal/iec/iec_tx_byte.s index 3866cff0..d9b49629 100644 --- a/c64/kernal/iec/iec_tx_byte.s +++ b/c64/kernal/iec/iec_tx_byte.s @@ -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 diff --git a/c64/kernal/iec/iec_tx_command.s b/c64/kernal/iec/iec_tx_command.s index 0f126d47..04c8a0ca 100644 --- a/c64/kernal/iec/iec_tx_command.s +++ b/c64/kernal/iec/iec_tx_command.s @@ -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 diff --git a/c64/kernal/iec/iec_tx_command_finalize.s b/c64/kernal/iec/iec_tx_command_finalize.s index dc2a9c26..976fdb93 100644 --- a/c64/kernal/iec/iec_tx_command_finalize.s +++ b/c64/kernal/iec/iec_tx_command_finalize.s @@ -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 diff --git a/c64/kernal/iec/iec_tx_flush.s b/c64/kernal/iec/iec_tx_flush.s index d6db894f..fdef1d2a 100644 --- a/c64/kernal/iec/iec_tx_flush.s +++ b/c64/kernal/iec/iec_tx_flush.s @@ -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 diff --git a/c64/kernal/iec/iec_wait1ms.s b/c64/kernal/iec/iec_wait1ms.s index 24ac3025..d6a57218 100644 --- a/c64/kernal/iec/iec_wait1ms.s +++ b/c64/kernal/iec/iec_wait1ms.s @@ -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 diff --git a/c64/kernal/iec/iec_wait20us.s b/c64/kernal/iec/iec_wait20us.s index 550de20c..21c5caa5 100644 --- a/c64/kernal/iec/iec_wait20us.s +++ b/c64/kernal/iec/iec_wait20us.s @@ -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 diff --git a/c64/kernal/iec/iec_wait60us.s b/c64/kernal/iec/iec_wait60us.s index e5c7ad84..f748ea28 100644 --- a/c64/kernal/iec/iec_wait60us.s +++ b/c64/kernal/iec/iec_wait60us.s @@ -1,4 +1,8 @@ + +#if CONFIG_IEC + + iec_wait60us: // Wait 60usec @@ -21,3 +25,5 @@ iec_wait60us: // --- // 64 cycles + +#endif // CONFIG_IEC diff --git a/c64/kernal/iec/iec_wait_for_clk_release.s b/c64/kernal/iec/iec_wait_for_clk_release.s index 22edfdfa..2464cd16 100644 --- a/c64/kernal/iec/iec_wait_for_clk_release.s +++ b/c64/kernal/iec/iec_wait_for_clk_release.s @@ -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 diff --git a/c64/kernal/iec/iec_wait_for_data_pull.s b/c64/kernal/iec/iec_wait_for_data_pull.s index 9fcaa9fb..e4842c61 100644 --- a/c64/kernal/iec/iec_wait_for_data_pull.s +++ b/c64/kernal/iec/iec_wait_for_data_pull.s @@ -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 diff --git a/c64/kernal/iec/iec_wait_for_data_release.s b/c64/kernal/iec/iec_wait_for_data_release.s index 93b4a518..e75c2ef2 100644 --- a/c64/kernal/iec/iec_wait_for_data_release.s +++ b/c64/kernal/iec/iec_wait_for_data_release.s @@ -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 diff --git a/c64/kernal/iec/listen.s b/c64/kernal/iec/listen.s index ec433768..f7e59c8c 100644 --- a/c64/kernal/iec/listen.s +++ b/c64/kernal/iec/listen.s @@ -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 diff --git a/c64/kernal/iec/load_iec.s b/c64/kernal/iec/load_iec.s index 33bb0a65..eb37bcf0 100644 --- a/c64/kernal/iec/load_iec.s +++ b/c64/kernal/iec/load_iec.s @@ -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 diff --git a/c64/kernal/iec/open_iec.s b/c64/kernal/iec/open_iec.s new file mode 100644 index 00000000..33269eb9 --- /dev/null +++ b/c64/kernal/iec/open_iec.s @@ -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 diff --git a/c64/kernal/iec/second.s b/c64/kernal/iec/second.s index 9072536d..12d49f44 100644 --- a/c64/kernal/iec/second.s +++ b/c64/kernal/iec/second.s @@ -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 diff --git a/c64/kernal/iec/talk.s b/c64/kernal/iec/talk.s index ec57c592..4cd64cfe 100644 --- a/c64/kernal/iec/talk.s +++ b/c64/kernal/iec/talk.s @@ -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 diff --git a/c64/kernal/iec/tksa.s b/c64/kernal/iec/tksa.s index cd905edb..63215256 100644 --- a/c64/kernal/iec/tksa.s +++ b/c64/kernal/iec/tksa.s @@ -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 diff --git a/c64/kernal/iec/unlsn.s b/c64/kernal/iec/unlsn.s index b37f7c26..55fb5fd4 100644 --- a/c64/kernal/iec/unlsn.s +++ b/c64/kernal/iec/unlsn.s @@ -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 diff --git a/c64/kernal/iec/untlk.s b/c64/kernal/iec/untlk.s index 758d36ef..1e7f542a 100644 --- a/c64/kernal/iec/untlk.s +++ b/c64/kernal/iec/untlk.s @@ -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 diff --git a/c64/kernal/fffc.interop b/c64/kernal/init/fffc.interop similarity index 100% rename from c64/kernal/fffc.interop rename to c64/kernal/init/fffc.interop diff --git a/c64/kernal/fffc.vector_reset.s b/c64/kernal/init/fffc.vector_reset.s similarity index 100% rename from c64/kernal/fffc.vector_reset.s rename to c64/kernal/init/fffc.vector_reset.s diff --git a/c64/kernal/fffa.interop b/c64/kernal/interrupts/fffa.interop similarity index 100% rename from c64/kernal/fffa.interop rename to c64/kernal/interrupts/fffa.interop diff --git a/c64/kernal/fffa.vector_nmi.s b/c64/kernal/interrupts/fffa.vector_nmi.s similarity index 100% rename from c64/kernal/fffa.vector_nmi.s rename to c64/kernal/interrupts/fffa.vector_nmi.s diff --git a/c64/kernal/fffe.interop b/c64/kernal/interrupts/fffe.interop similarity index 100% rename from c64/kernal/fffe.interop rename to c64/kernal/interrupts/fffe.interop diff --git a/c64/kernal/fffe.vector_irq.s b/c64/kernal/interrupts/fffe.vector_irq.s similarity index 100% rename from c64/kernal/fffe.vector_irq.s rename to c64/kernal/interrupts/fffe.vector_irq.s diff --git a/c64/kernal/f291.close.s b/c64/kernal/iostack/f291.close.s similarity index 58% rename from c64/kernal/f291.close.s rename to c64/kernal/iostack/f291.close.s index d89ce4fe..c2f3c4ae 100644 --- a/c64/kernal/f291.close.s +++ b/c64/kernal/iostack/f291.close.s @@ -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 diff --git a/c64/kernal/f291.interop b/c64/kernal/iostack/f291.interop similarity index 100% rename from c64/kernal/f291.interop rename to c64/kernal/iostack/f291.interop diff --git a/c64/kernal/f34a.interop b/c64/kernal/iostack/f34a.interop similarity index 100% rename from c64/kernal/f34a.interop rename to c64/kernal/iostack/f34a.interop diff --git a/c64/kernal/f34a.open.s b/c64/kernal/iostack/f34a.open.s similarity index 71% rename from c64/kernal/f34a.open.s rename to c64/kernal/iostack/f34a.open.s index 9907cbf6..ddadebea 100644 --- a/c64/kernal/f34a.open.s +++ b/c64/kernal/iostack/f34a.open.s @@ -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 diff --git a/c64/kernal/iostack/f4a5.load.s b/c64/kernal/iostack/f4a5.load.s index 223aac93..0f1b0e36 100644 --- a/c64/kernal/iostack/f4a5.load.s +++ b/c64/kernal/iostack/f4a5.load.s @@ -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 diff --git a/c64/kernal/f6ed.stop.s b/c64/kernal/keyboard/f6ed.stop.s similarity index 100% rename from c64/kernal/f6ed.stop.s rename to c64/kernal/keyboard/f6ed.stop.s diff --git a/c64/kernal/vector_real.s b/c64/kernal/vector_real.s index 299d2c8a..5b3e4eff 100644 --- a/c64/kernal/vector_real.s +++ b/c64/kernal/vector_real.s @@ -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