From 3d9e713f0799ae97a8772a5585862f5086efccf6 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Mon, 28 Oct 2019 21:27:26 +0100 Subject: [PATCH] small LOAD cleanup --- c64/kernal/chkinout_real.s | 4 +- c64/kernal/chrin_real.s | 2 +- c64/kernal/clrchn_real.s | 4 +- c64/kernal/f1ca.chrout.s | 2 +- c64/kernal/f291.close.s | 2 +- c64/kernal/f34a.open.s | 2 +- c64/kernal/f49e.load_int.s | 13 ----- c64/kernal/iec/iec_check_devnum.s | 21 +++++--- c64/kernal/iec/listen.s | 5 +- c64/kernal/{f4a5.load.s => iec/load_iec.s} | 57 +++------------------- c64/kernal/iec/talk.s | 4 +- c64/kernal/{ => iostack}/f49e.interop | 0 c64/kernal/iostack/f49e.load_int.s | 12 +++++ c64/kernal/{ => iostack}/f4a5.interop | 0 c64/kernal/iostack/f4a5.load.s | 54 ++++++++++++++++++++ c64/kernal/{ => iostack}/f5dd.interop | 0 c64/kernal/{ => iostack}/f5dd.save_int.s | 0 c64/kernal/{ => iostack}/f5ed.interop | 0 c64/kernal/{ => iostack}/f5ed.save.s | 0 c64/kernal/{ => iostack}/f6ed.interop | 0 20 files changed, 98 insertions(+), 84 deletions(-) delete mode 100644 c64/kernal/f49e.load_int.s rename c64/kernal/{f4a5.load.s => iec/load_iec.s} (57%) rename c64/kernal/{ => iostack}/f49e.interop (100%) create mode 100644 c64/kernal/iostack/f49e.load_int.s rename c64/kernal/{ => iostack}/f4a5.interop (100%) create mode 100644 c64/kernal/iostack/f4a5.load.s rename c64/kernal/{ => iostack}/f5dd.interop (100%) rename c64/kernal/{ => iostack}/f5dd.save_int.s (100%) rename c64/kernal/{ => iostack}/f5ed.interop (100%) rename c64/kernal/{ => iostack}/f5ed.save.s (100%) rename c64/kernal/{ => iostack}/f6ed.interop (100%) diff --git a/c64/kernal/chkinout_real.s b/c64/kernal/chkinout_real.s index 18bc6bc7..15a986a1 100644 --- a/c64/kernal/chkinout_real.s +++ b/c64/kernal/chkinout_real.s @@ -41,7 +41,7 @@ chkin_real: // For IEC devices, send TALK + TKSA first lda FAT,Y - jsr iec_check_devnum + jsr iec_check_devnum_oc bcs chkin_set_device jsr TALK @@ -123,7 +123,7 @@ ckout_real: // For IEC devices, send LISTEN + SECOND first lda FAT,Y - jsr iec_check_devnum + jsr iec_check_devnum_oc bcs chkout_set_device jsr LISTEN diff --git a/c64/kernal/chrin_real.s b/c64/kernal/chrin_real.s index efd96051..684e5060 100644 --- a/c64/kernal/chrin_real.s +++ b/c64/kernal/chrin_real.s @@ -23,7 +23,7 @@ chrin_real: beq chrin_keyboard // #$00 - keyboard // XXX add screen support - jsr iec_check_devnum + jsr iec_check_devnum_oc bcc chrin_iec jmp lvs_device_not_found_error // not a supported device diff --git a/c64/kernal/clrchn_real.s b/c64/kernal/clrchn_real.s index 6c97cc4d..845e2cb6 100644 --- a/c64/kernal/clrchn_real.s +++ b/c64/kernal/clrchn_real.s @@ -13,14 +13,14 @@ clrchn_real: // Handle IEC input device lda DFLTN - jsr iec_check_devnum + jsr iec_check_devnum_oc bcs !+ // Previous device was IEC one - send UNTALK first jsr UNTLK !: // Restore output device to default lda DFLTO - jsr iec_check_devnum + jsr iec_check_devnum_oc bcs !+ // Handle IEC output device jsr UNLSN diff --git a/c64/kernal/f1ca.chrout.s b/c64/kernal/f1ca.chrout.s index 8119ea4e..9ebbe75d 100644 --- a/c64/kernal/f1ca.chrout.s +++ b/c64/kernal/f1ca.chrout.s @@ -30,7 +30,7 @@ CHROUT: bne !+ jmp chrout_screen !: - jsr iec_check_devnum + jsr iec_check_devnum_oc bcs chrout_done_unknown_device // not a supported device chrout_iec: diff --git a/c64/kernal/f291.close.s b/c64/kernal/f291.close.s index ca60794b..d89ce4fe 100644 --- a/c64/kernal/f291.close.s +++ b/c64/kernal/f291.close.s @@ -20,7 +20,7 @@ CLOSE: // We have the entry index in Y - check whether this is IEC device lda FAT, y - jsr iec_check_devnum + jsr iec_check_devnum_oc bcs close_remove_from_table // IEC device diff --git a/c64/kernal/f34a.open.s b/c64/kernal/f34a.open.s index 02ce3ac9..9907cbf6 100644 --- a/c64/kernal/f34a.open.s +++ b/c64/kernal/f34a.open.s @@ -59,7 +59,7 @@ open_has_space: // Check for IEC device lda FA - jsr iec_check_devnum + jsr iec_check_devnum_oc bcc open_iec // FALLTROUGH diff --git a/c64/kernal/f49e.load_int.s b/c64/kernal/f49e.load_int.s deleted file mode 100644 index 837d896c..00000000 --- a/c64/kernal/f49e.load_int.s +++ /dev/null @@ -1,13 +0,0 @@ - -// -// XXX Note: something unusual was done with LOAD routine - although the vector at $330 points to $F4A5, -// the Kernal jump table points to $F49E (see also Mapping the C64, page 76). By experimenting -// I have already discovered that $F4A5 performs indirect jump via ($0330) vector, but it must -// be doing a little bit more - not sure yet, what. Something similar is done with SAVE. -// -// This has to be clarified. -// - -LOAD_INT: - jmp (ILOAD) - diff --git a/c64/kernal/iec/iec_check_devnum.s b/c64/kernal/iec/iec_check_devnum.s index 0071392b..ff08bdc5 100644 --- a/c64/kernal/iec/iec_check_devnum.s +++ b/c64/kernal/iec/iec_check_devnum.s @@ -5,18 +5,27 @@ // Preserves .A, .X and .Y // -iec_check_devnum: - // 0, 1, 2, or 3 are illegal - reserved for non-IEC devices on Commodore - cmp #$04 + +iec_check_devnum_lvs: // for load/verify/save + + cmp #$08 // below 8 are illegal for load/save bcs !+ + // FALLTROUGH + +iec_check_devnum_oc: // for open/close + + cmp #$04 // below 4 are illegal, reserved for non-IEC devices on Commodore + bcs !+ + + // 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 - bcs iec_check_devnum_failed - // Carry is clear here - indicates IEC device + cmp #$1F // sets carry for 31 or above rts diff --git a/c64/kernal/iec/listen.s b/c64/kernal/iec/listen.s index edb72e87..ec433768 100644 --- a/c64/kernal/iec/listen.s +++ b/c64/kernal/iec/listen.s @@ -17,7 +17,7 @@ LISTEN: jsr iec_tx_flush // Check whether device number is correct - jsr iec_check_devnum + jsr iec_check_devnum_oc bcc !+ jmp kernalerror_DEVICE_NOT_FOUND !: @@ -25,6 +25,3 @@ LISTEN: ora #$20 jmp common_talk_listen - - - diff --git a/c64/kernal/f4a5.load.s b/c64/kernal/iec/load_iec.s similarity index 57% rename from c64/kernal/f4a5.load.s rename to c64/kernal/iec/load_iec.s index 76307dc6..5c88d9e5 100644 --- a/c64/kernal/f4a5.load.s +++ b/c64/kernal/iec/load_iec.s @@ -1,60 +1,17 @@ + // -// Official Kernal routine, described in: -// -// - [RG64] C64 Programmer's Reference Guide - page 286 -// - [CM64] Compute's Mapping the Commodore 64 - page 231 -// - IEC reference at http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf -// -// CPU registers that has to be preserved (see [RG64]): none +// IEC part of the LOAD routine // - // Expects that SETLFS and SETNAM are called before hand. - // $YYXX = load address. - // (ignored if SETLFS channel = 1, i.e., like ,8,1) - // If A=1 then VERIFY instead of LOAD. - // On exit, $YYXX is the highest address into which data - // will have been placed. - - // XXX honor MSGFLG bit 6 - // XXX add VERIFY support - -LOAD: - - // Are we loading or verifying? - sta VERCKK - - // Store start address of LOAD - stx STAL+0 - sty STAL+1 - - // Reset status - jsr kernalstatus_reset - -#if CONFIG_MEMORY_MODEL_60K - // We need our helpers to get to filenames under ROMs or IO area - jsr install_ram_routines -#endif - - // Check whether we support the requested device - lda FA - and #$FC - bne !+ - jmp lvs_illegal_device_number // device number below 4, not an IEC device -!: - // Device numbers above 30 are also illegal (see https://www.pagetable.com/?p=1031), - // as the protocol combines device number with command code int one byte, - // above 30 it is no longer possible (UNLISTEN and UNTALK codes prevent using - // number 31), yet original ROMs show ILLEGAL DEVICE NUMBER error only - // for devices 0-3; in our implementation LISTEN / TALK will cause device - // not present detected for numbers above 30 +load_iec: // Display SEARCHING FOR + filename jsr lvs_display_searching_for // http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf - // p13, 16; also p16 tells us this routine doesn't mess with the file table - // in the C64, only in the drive. + // p13, 16; also p16 tells us this routine does not mess with the file + // table in the C64, only in the drive. // Call device to LISTEN (p16) lda FA @@ -111,7 +68,7 @@ LOAD: // Display start address jsr lvs_display_loading_verifying -load_loop: +iec_load_loop: // We are now ready to receive bytes jsr iec_rx_byte bcc !+ @@ -130,7 +87,7 @@ load_loop: // Check for EOI - if so, this was the last byte lda IOSTATUS and #K_STS_EOI - beq load_loop + beq iec_load_loop // Display end address jsr lvs_display_done diff --git a/c64/kernal/iec/talk.s b/c64/kernal/iec/talk.s index f895e4fb..ec57c592 100644 --- a/c64/kernal/iec/talk.s +++ b/c64/kernal/iec/talk.s @@ -17,7 +17,7 @@ TALK: jsr iec_tx_flush // Check whether device number is correct - jsr iec_check_devnum + jsr iec_check_devnum_oc bcc !+ jmp kernalerror_DEVICE_NOT_FOUND !: @@ -28,5 +28,3 @@ common_talk_listen: // common part of TALK and LISTEN sta TBTCNT jmp iec_tx_command - - diff --git a/c64/kernal/f49e.interop b/c64/kernal/iostack/f49e.interop similarity index 100% rename from c64/kernal/f49e.interop rename to c64/kernal/iostack/f49e.interop diff --git a/c64/kernal/iostack/f49e.load_int.s b/c64/kernal/iostack/f49e.load_int.s new file mode 100644 index 00000000..ca8fca9c --- /dev/null +++ b/c64/kernal/iostack/f49e.load_int.s @@ -0,0 +1,12 @@ + +// +// Note: Although the vector at $330 points to $F4A5, the Kernal jump table points to $F49E +// (see also Mapping the C64, page 76). By experimenting I have discovered that $F49E performs +// indirect jump via ($0330) vector, after setting MEMUSS. +// + +LOAD_INT: + + sty MEMUSS+1 + stx MEMUSS+0 + jmp (ILOAD) diff --git a/c64/kernal/f4a5.interop b/c64/kernal/iostack/f4a5.interop similarity index 100% rename from c64/kernal/f4a5.interop rename to c64/kernal/iostack/f4a5.interop diff --git a/c64/kernal/iostack/f4a5.load.s b/c64/kernal/iostack/f4a5.load.s new file mode 100644 index 00000000..223aac93 --- /dev/null +++ b/c64/kernal/iostack/f4a5.load.s @@ -0,0 +1,54 @@ +// +// Official Kernal routine, described in: +// +// - [RG64] C64 Programmer's Reference Guide - page 286 +// - [CM64] Compute's Mapping the Commodore 64 - page 231 +// - IEC reference at http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf +// +// CPU registers that has to be preserved (see [RG64]): none +// + + + // Expects that SETLFS and SETNAM are called before hand. + // $YYXX = load address. + // (ignored if SETLFS channel = 1, i.e., like ,8,1) + // If A=1 then VERIFY instead of LOAD. + // On exit, $YYXX is the highest address into which data + // will have been placed. + + // XXX add VERIFY support + +LOAD: + + // Are we loading or verifying? + sta VERCKK + + // Store start address of LOAD + lda MEMUSS+0 + sta STAL+0 + lda MEMUSS+1 + sty STAL+1 + + // Reset status + jsr kernalstatus_reset + +#if CONFIG_MEMORY_MODEL_60K + // We need our helpers to get to filenames under ROMs or IO area + jsr install_ram_routines +#endif + + // 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 + + cmp #$1F + bcs !+ // >= 31 + cmp #$08 + bcs_far load_iec // >= 8 +!: + jmp lvs_illegal_device_number diff --git a/c64/kernal/f5dd.interop b/c64/kernal/iostack/f5dd.interop similarity index 100% rename from c64/kernal/f5dd.interop rename to c64/kernal/iostack/f5dd.interop diff --git a/c64/kernal/f5dd.save_int.s b/c64/kernal/iostack/f5dd.save_int.s similarity index 100% rename from c64/kernal/f5dd.save_int.s rename to c64/kernal/iostack/f5dd.save_int.s diff --git a/c64/kernal/f5ed.interop b/c64/kernal/iostack/f5ed.interop similarity index 100% rename from c64/kernal/f5ed.interop rename to c64/kernal/iostack/f5ed.interop diff --git a/c64/kernal/f5ed.save.s b/c64/kernal/iostack/f5ed.save.s similarity index 100% rename from c64/kernal/f5ed.save.s rename to c64/kernal/iostack/f5ed.save.s diff --git a/c64/kernal/f6ed.interop b/c64/kernal/iostack/f6ed.interop similarity index 100% rename from c64/kernal/f6ed.interop rename to c64/kernal/iostack/f6ed.interop