From 7eca8ea05bacb8f93b2e3ecc5a92b8f139a8c99e Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Tue, 29 Oct 2019 21:24:25 +0100 Subject: [PATCH] CHKIN and CKOUT refactoring --- c64/kernal/chkinout_real.s | 148 -------------------------- c64/kernal/f20e.chkin.jmp.s | 6 -- c64/kernal/f250.ckout.jmp.s | 6 -- c64/kernal/iec/chkin_iec.s | 30 ++++++ c64/kernal/iec/ckout_iec.s | 30 ++++++ c64/kernal/iostack/chkinout.s | 18 ++++ c64/kernal/iostack/f20e.chkin.s | 69 ++++++++++++ c64/kernal/{ => iostack}/f20e.interop | 0 c64/kernal/iostack/f250.ckout.s | 76 +++++++++++++ c64/kernal/{ => iostack}/f250.interop | 0 c64/kernal/rs232/chkin_rs232.s | 2 - c64/kernal/rs232/ckout_rs232.s | 2 - 12 files changed, 223 insertions(+), 164 deletions(-) delete mode 100644 c64/kernal/chkinout_real.s delete mode 100644 c64/kernal/f20e.chkin.jmp.s delete mode 100644 c64/kernal/f250.ckout.jmp.s create mode 100644 c64/kernal/iec/chkin_iec.s create mode 100644 c64/kernal/iec/ckout_iec.s create mode 100644 c64/kernal/iostack/chkinout.s create mode 100644 c64/kernal/iostack/f20e.chkin.s rename c64/kernal/{ => iostack}/f20e.interop (100%) create mode 100644 c64/kernal/iostack/f250.ckout.s rename c64/kernal/{ => iostack}/f250.interop (100%) diff --git a/c64/kernal/chkinout_real.s b/c64/kernal/chkinout_real.s deleted file mode 100644 index 69b4be9d..00000000 --- a/c64/kernal/chkinout_real.s +++ /dev/null @@ -1,148 +0,0 @@ - -// -// Official Kernal routines, described in: -// -// - [RG64] C64 Programmer's Reference Guide - page 275 (CHKIN) / 276 (CKOUT) -// - [CM64] Compute's Mapping the Commodore 64 - page 229 -// -// CPU registers that has to be preserved (see [RG64]): .Y, .A (see [CM64], page 213) -// - - -// CHKIN implementation - -chkin_real: - - // Store registers for preservation - pha - phy_trash_a - - // Reset status - jsr kernalstatus_reset - - // First retrieve the FAT/LAT/SAT table index (and check if file is open) - - txa - jsr find_fls - bcs chkinout_file_not_open - - // Now we have table index in Y - first filter out unsuitable devices - - lda FAT,Y - cmp #$01 - beq chkinout_device_not_present // tape not implemented - cmp #$02 - beq chkinout_device_not_present // RS-232 not implemented - - // Fail if the file is open for writing (secondary address 1) - - lda LAT, Y - cmp #$01 - beq chkin_file_not_input - -#if CONFIG_IEC - - // For IEC devices, send TALK + TKSA first - lda FAT,Y - jsr iec_check_devnum_oc - bcs chkin_set_device - - jsr TALK - bcs chkinout_device_not_present // don't set DFLTN in case of failure - - lda LAT, Y - jsr TKSA - bcs chkinout_device_not_present - -#endif // CONFIG_IEC - -chkin_set_device: - lda FAT,Y - sta DFLTN - - // FALLTROUGH - -// Common part for booth CHKIN and CKOUT - -chkinout_end: - ply_trash_a - pla - clc // indicate success - rts - -chkin_file_not_input: // XXX move this out of common section - ply_trash_a - pla - jmp kernalerror_FILE_NOT_INPUT - -chkinout_file_not_open: - ply_trash_a - pla - jmp kernalerror_FILE_NOT_OPEN - -chkinout_device_not_present: - ply_trash_a - pla - jsr kernalstatus_DEVICE_NOT_FOUND - jmp kernalerror_DEVICE_NOT_FOUND - - -// CKOUT implementation - -ckout_real: - - // Store registers for preservation - pha - phy_trash_a - - // Reset status - jsr kernalstatus_reset - - // First retrieve the FAT/LAT/SAT table index (and check if file is open) - - txa - jsr find_fls - bcs chkinout_file_not_open - - // Now we have table index in Y - first filter out unsuitable devices - - lda FAT,Y - cmp #$01 - beq chkinout_device_not_present // tape not implemented - cmp #$02 - beq chkinout_device_not_present // RS-232 not implemented - - cmp #$00 - beq ckout_file_not_output // cannot output to keyboard - XXX check real ROM behaviour - - // Fail if the file is open for reading (secondary address 0) - - lda LAT, Y - beq ckout_file_not_output - -#if CONFIG_IEC - - // For IEC devices, send LISTEN + SECOND first - lda FAT,Y - jsr iec_check_devnum_oc - bcs ckout_set_device - - jsr LISTEN - bcs chkinout_device_not_present // don't set DFLTO in case of failure - - lda LAT, Y - jsr SECOND - bcs chkinout_device_not_present - -#endif // CONFIG_IEC - -ckout_set_device: - lda FAT,Y - sta DFLTO - jmp chkinout_end - -ckout_file_not_output: - ply_trash_a - pla - jmp kernalerror_FILE_NOT_OUTPUT - diff --git a/c64/kernal/f20e.chkin.jmp.s b/c64/kernal/f20e.chkin.jmp.s deleted file mode 100644 index ba38979d..00000000 --- a/c64/kernal/f20e.chkin.jmp.s +++ /dev/null @@ -1,6 +0,0 @@ - -// In our implementation CHKIN and CKOUT are closely tied, -// placing it here would cause a collision - -CHKIN: - jmp chkin_real diff --git a/c64/kernal/f250.ckout.jmp.s b/c64/kernal/f250.ckout.jmp.s deleted file mode 100644 index 18cfbffc..00000000 --- a/c64/kernal/f250.ckout.jmp.s +++ /dev/null @@ -1,6 +0,0 @@ - -// In our implementation CHKIN and CKOUT are closely tied, -// placing it here would cause a collision - -CKOUT: - jmp ckout_real diff --git a/c64/kernal/iec/chkin_iec.s b/c64/kernal/iec/chkin_iec.s new file mode 100644 index 00000000..584e40f6 --- /dev/null +++ b/c64/kernal/iec/chkin_iec.s @@ -0,0 +1,30 @@ + +// +// IEC part of the CHKIN routine +// + + +#if CONFIG_IEC + + +chkin_iec: + + // Fail if the file is open for writing (secondary address 1) + + lda LAT, Y + cmp #$01 + beq_far chkin_file_not_input + + // Send TALK + TKSA first + lda FAT,Y + + jsr TALK + bcs_far chkinout_device_not_present + + lda LAT, Y + jsr TKSA + bcs_far chkinout_device_not_present + + jmp chkin_set_device + +#endif // CONFIG_IEC diff --git a/c64/kernal/iec/ckout_iec.s b/c64/kernal/iec/ckout_iec.s new file mode 100644 index 00000000..4a504f9c --- /dev/null +++ b/c64/kernal/iec/ckout_iec.s @@ -0,0 +1,30 @@ + +// +// IEC part of the CKOUT routine +// + + +#if CONFIG_IEC + + +ckout_iec: + + // Fail if the file is open for reading (secondary address 0) + + lda LAT, Y + beq_far ckout_file_not_output + + // Send LISTEN + SECOND first + lda FAT,Y + + jsr LISTEN + bcs_far chkinout_device_not_present + + lda LAT, Y + jsr SECOND + bcs_far chkinout_device_not_present + + jmp ckout_set_device + + +#endif // CONFIG_IEC diff --git a/c64/kernal/iostack/chkinout.s b/c64/kernal/iostack/chkinout.s new file mode 100644 index 00000000..c8d3bda8 --- /dev/null +++ b/c64/kernal/iostack/chkinout.s @@ -0,0 +1,18 @@ + +// +// Common part of CHKIN and CKOUT +// + + +chkinout_device_not_present: + + ply_trash_a + pla + jsr kernalstatus_DEVICE_NOT_FOUND + jmp kernalerror_DEVICE_NOT_FOUND + +chkinout_file_not_open: + + ply_trash_a + pla + jmp kernalerror_FILE_NOT_OPEN diff --git a/c64/kernal/iostack/f20e.chkin.s b/c64/kernal/iostack/f20e.chkin.s new file mode 100644 index 00000000..bd86226c --- /dev/null +++ b/c64/kernal/iostack/f20e.chkin.s @@ -0,0 +1,69 @@ + +// +// Official Kernal routines, described in: +// +// - [RG64] C64 Programmer's Reference Guide - page 275 +// - [CM64] Compute's Mapping the Commodore 64 - page 229 +// +// CPU registers that has to be preserved (see [RG64]): .Y, .A (see [CM64], page 213) +// + + +CHKIN: + + // Store registers for preservation + pha + phy_trash_a + + // Reset status + jsr kernalstatus_reset + + // First retrieve the FAT/LAT/SAT table index (and check if file is open) + + txa + jsr find_fls + bcs_far chkinout_file_not_open + + // Now we have table index in Y + + lda FAT,Y + + // Handle all the devices + + beq chkin_set_device // 0 - keyboard + + // Tape not supported here + +#if HAS_RS232 + + cmp #$02 + beq_far chkin_rs232 + +#endif // HAS_RS232 + +#if CONFIG_IEC + + jsr iec_check_devnum_oc + bcc_far chkin_iec + +#endif // CONFIG_IEC + + cmp #$03 // screen - only legal one left + bne_far chkinout_device_not_present + +chkin_set_device: + lda FAT,Y + sta DFLTN + + // FALLTROUGH + +chkinout_end: + ply_trash_a + pla + clc // indicate success + rts + +chkin_file_not_input: + ply_trash_a + pla + jmp kernalerror_FILE_NOT_INPUT diff --git a/c64/kernal/f20e.interop b/c64/kernal/iostack/f20e.interop similarity index 100% rename from c64/kernal/f20e.interop rename to c64/kernal/iostack/f20e.interop diff --git a/c64/kernal/iostack/f250.ckout.s b/c64/kernal/iostack/f250.ckout.s new file mode 100644 index 00000000..49a4d6a7 --- /dev/null +++ b/c64/kernal/iostack/f250.ckout.s @@ -0,0 +1,76 @@ + +// +// Official Kernal routines, described in: +// +// - [RG64] C64 Programmer's Reference Guide - page 276 +// - [CM64] Compute's Mapping the Commodore 64 - page 229 +// +// CPU registers that has to be preserved (see [RG64]): .Y, .A (see [CM64], page 213) +// + + +CKOUT: + + // Store registers for preservation + pha + phy_trash_a + + // Reset status + jsr kernalstatus_reset + + // First retrieve the FAT/LAT/SAT table index (and check if file is open) + + txa + jsr find_fls + bcs_far chkinout_file_not_open + + // Now we have table index in Y + + lda FAT,Y + + // Handle all the devices + + beq ckout_file_not_output // 0 - keyboard + + // Tape not supported here + +#if HAS_RS232 + + cmp #$02 + beq_far ckout_rs232 + +#endif // HAS_RS232 + +#if CONFIG_IEC + + jsr iec_check_devnum_oc + bcc_far ckout_iec + +#endif // CONFIG_IEC + + cmp #$03 // screen - only legal one left + bne_far chkinout_device_not_present + +ckout_set_device: + lda FAT,Y + sta DFLTO + jmp chkinout_end + +ckout_file_not_output: + ply_trash_a + pla + jmp kernalerror_FILE_NOT_OUTPUT + + + + + + + + + + + + + + diff --git a/c64/kernal/f250.interop b/c64/kernal/iostack/f250.interop similarity index 100% rename from c64/kernal/f250.interop rename to c64/kernal/iostack/f250.interop diff --git a/c64/kernal/rs232/chkin_rs232.s b/c64/kernal/rs232/chkin_rs232.s index b2cc4086..6cc6d002 100644 --- a/c64/kernal/rs232/chkin_rs232.s +++ b/c64/kernal/rs232/chkin_rs232.s @@ -3,8 +3,6 @@ // RS-232 part of the CHKIN routine // -// XXX connect to I/O stack - #if HAS_RS232 diff --git a/c64/kernal/rs232/ckout_rs232.s b/c64/kernal/rs232/ckout_rs232.s index cefe35a7..66d4b3e7 100644 --- a/c64/kernal/rs232/ckout_rs232.s +++ b/c64/kernal/rs232/ckout_rs232.s @@ -3,8 +3,6 @@ // RS-232 part of the CKOUT routine // -// XXX connect to I/O stack - #if HAS_RS232