From ecf1b3aa50809d789deaf45b9d42790e864c361b Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Tue, 16 Jul 2019 22:22:01 +0200 Subject: [PATCH] small improvements for LOAD command and IEC routines --- c64/basic/cmd_load.s | 5 ++--- c64/basic/set_sane_devnum.s | 17 +++++++++++++++++ c64/basic/wedge_dos.s | 24 ++++++++++-------------- c64/kernal/chkin.s | 16 ++++++++++++++++ c64/kernal/chkout.s | 14 ++++++++++++++ c64/kernal/close.s | 25 ++++++++++--------------- c64/kernal/findfls.s | 23 +++++++++++++++++++++++ c64/kernal/load.s | 12 ++++-------- 8 files changed, 96 insertions(+), 40 deletions(-) create mode 100644 c64/basic/set_sane_devnum.s create mode 100644 c64/kernal/findfls.s diff --git a/c64/basic/cmd_load.s b/c64/basic/cmd_load.s index 9713a41b..fa5748c6 100644 --- a/c64/basic/cmd_load.s +++ b/c64/basic/cmd_load.s @@ -20,9 +20,8 @@ cmd_load: * jsr JSETMSG - ;; XXX temporary, to set valid device number - lda #$08 - sta current_device_number + ;; XXX handle device number from arguments, if not present, use the call below + jsr set_sane_devnum ;; Set filename and length lda #$00 diff --git a/c64/basic/set_sane_devnum.s b/c64/basic/set_sane_devnum.s new file mode 100644 index 00000000..501bc5d1 --- /dev/null +++ b/c64/basic/set_sane_devnum.s @@ -0,0 +1,17 @@ + +set_sane_devnum: + + ;; Take last device number, make sure it's a drive + ;; If not, set to 8 (first drive number) + ;; Device number is left in X, for SETFLS Kernal routine + + ;; Note: if tape support is introduced here, make sure DOS wedge won't get broken + + ldx current_device_number + cpx #$07 + bpl + + bcs + + ldx #$08 + stx current_device_number +* + rts diff --git a/c64/basic/wedge_dos.s b/c64/basic/wedge_dos.s index 5914c280..167338f7 100644 --- a/c64/basic/wedge_dos.s +++ b/c64/basic/wedge_dos.s @@ -5,16 +5,12 @@ wedge_dos: ;; Close all the channels, so that wedge has full control jsr wedge_dos_CLALL - - ;; Take last device number, make sure it's a drive - ;; If not, set to 8 (first drive number) - ldx DFLTN - cpx #$07 - bpl + - bcs + - ldx #$08 -* - ;; Set remaining file parameters; channel 15 is a typical one for commands + + ;; Make sure current device number is sane + jsr set_sane_devnum + + ;; Set remaining file parameters (X already set by set_sane_devnum); + ;; channel 15 is a typical one for commands lda #$0F ldy #$0F jsr JSETFLS @@ -67,7 +63,7 @@ wedge_dos_change_drive: bcs + jmp do_ILLEGAL_DEVICE_NUMBER_error * - sta DFLTN + sta current_device_number jmp basic_end_of_line wedge_dos_status: @@ -77,7 +73,7 @@ wedge_dos_status: ;; Set remaining file parameters, open the channel lda #$00 ; empty file name - jsr $FFBD ; SETNAM + jsr JSETNAM jsr wedge_dos_OPEN bcc + jmp do_DEVICE_NOT_PRESENT_error @@ -90,8 +86,8 @@ wedge_dos_status: * ;; Print out everything retrieved from the drive bne + - jsr $FFCF ; CHRIN - jsr $FFD2 ; CHROUT + jsr JCHRIN + jsr JCHROUT jmp - * ;; Clean-up and exit diff --git a/c64/kernal/chkin.s b/c64/kernal/chkin.s index 99937d2e..ffa509d7 100644 --- a/c64/kernal/chkin.s +++ b/c64/kernal/chkin.s @@ -1,3 +1,19 @@ ; Function defined on pp272-273 of C64 Programmers Reference Guide + chkin: + + ;; Implemented according to 'C64 Programmers Reference Guide', page 277 + + ;; First retrieve the FAT/LAT/SAT table index (and check if file is open) + + ; txa + ; jsr find_fls + ; bcs kernalerror_FILE_NOT_OPEN + + ;; Now we have table index in Y - check if file is open for reading + + ;; XXX continue implementation + rts + + diff --git a/c64/kernal/chkout.s b/c64/kernal/chkout.s index 262a4c59..36b5a683 100644 --- a/c64/kernal/chkout.s +++ b/c64/kernal/chkout.s @@ -1,3 +1,17 @@ ; Function defined on pp272-273 of C64 Programmers Reference Guide + chkout: + + ;; Implemented according to 'C64 Programmers Reference Guide', page 278 + + ;; First retrieve the FAT/LAT/SAT table index (and check if file is open) + + ; txa + ; jsr find_fls + ; bcs kernalerror_FILE_NOT_OPEN + + ;; Now we have table index in Y - check if file is open for writing + + ;; XXX continue implementation + rts diff --git a/c64/kernal/close.s b/c64/kernal/close.s index e89ace83..c2b7a245 100644 --- a/c64/kernal/close.s +++ b/c64/kernal/close.s @@ -4,19 +4,14 @@ close: ;; Implemented accorging to 'C64 Programmers Reference Guide', page 281 ;; XXX this needs more testing (opening 10 files at once, closing in various orders, etc) once the code is more mature - + ;; Find the LAT / SAT / FAT entry which LAT corresponds to A - - ldy LDTND - beq close_error_not_found ; table empty -* - dey - bmi close_error_not_found ; no more entries - cmp LAT, y - bne - ; does not match, try the next one - + + jsr find_fls + bcs close_error_not_found ;; XXX can we report error in IOSTATUS here? + ;; We have the entry index in Y - + ;; XXX some devices (like IEC) needs special support here, to free their internal resources! ;; Just make sure the Y register value is kept, or redo ldy DFTLN * @@ -33,9 +28,9 @@ close: * ;; Decrement the list size variable dec LDTND - ;; FALLTHROUGH (for now) - success - + + ;; FALLTHROUGH - success + close_error_not_found: - - ;; XXX it seems that this function can't report errors, am I right? + rts diff --git a/c64/kernal/findfls.s b/c64/kernal/findfls.s new file mode 100644 index 00000000..b0ad82a6 --- /dev/null +++ b/c64/kernal/findfls.s @@ -0,0 +1,23 @@ + +;; Just a helper routine + +;; Find the LAT / SAT / FAT entry index where LAT corresponds to A, returns index in Y +;; Carry flag set means not found + +find_fls: + + ldy LDTND + beq find_fls_not_found ; table empty +* + dey + bmi find_fls_not_found ; no more entries + cmp LAT, y + bne - ; does not match, try the next one + + clc + rts + +find_fls_not_found: + + sec + rts diff --git a/c64/kernal/load.s b/c64/kernal/load.s index 192397b4..bc6b3ac6 100644 --- a/c64/kernal/load.s +++ b/c64/kernal/load.s @@ -54,9 +54,6 @@ print_filename_loop: iny jmp print_filename_loop * - lda #$0d - jsr JCHROUT - ;; XXX - Use default device number ;; http://www.zimmers.net/anonftp/pub/cbm/programming/serial-bus.pdf ;; p13, 16. @@ -145,11 +142,11 @@ sent_filename: lda kernal_load_or_verify_flag beq + jsr printf - .byte "VERIFYING", 0 + .byte $0D, "VERIFYING", 0 jmp load_print_start_addr * jsr printf - .byte "LOADING", 0 + .byte $0D, "LOADING", 0 load_print_start_addr: jsr printf .byte " FROM $",0 @@ -223,9 +220,8 @@ load_done: ;; Set IEC status back to idle jsr iec_set_idle - ;; Return last address written to +1 - ;; (Even though Compute's Mapping the 64 says without the +1. - ;; I'm suspicious. Will have to check behavour on an original C64) + ;; Return last address - Compute's Mapping the 64 says without the '+1', + ;; checked on original ROMs that this is really the case ldx load_save_start_ptr+0 ldy load_save_start_ptr+1