From 92d1ad01770cebd7d0cbfa6d7d91c392481d1d40 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Wed, 3 Feb 2021 16:05:07 +0100 Subject: [PATCH] rework for the initial CBDOS --- src/,,config_mega65.s | 2 + src/dos_m65/,aliases_dos.s | 4 + src/dos_m65/4020.dos_vectable.s | 5 +- src/dos_m65/dos_error_strings.s | 156 +++++++++++++++++++ src/dos_m65/dos_init.s | 5 + src/dos_m65/dos_memchk.s | 32 ++++ src/dos_m65/dos_setunit.s | 42 ----- src/dos_m65/{dos_chkunit.s => dos_unitchk.s} | 37 ++--- src/dos_m65/dos_unitnum.s | 53 +++++++ src/dos_m65/dos_unitset.s | 49 ++++++ src/kernal/iec_fast/m65dos_bridge.s | 41 +++-- src/kernal/iec_fast/m65dos_detect.s | 2 +- src/kernal/iostack/setfls.s | 6 +- 13 files changed, 349 insertions(+), 85 deletions(-) create mode 100644 src/dos_m65/dos_error_strings.s create mode 100644 src/dos_m65/dos_memchk.s delete mode 100644 src/dos_m65/dos_setunit.s rename src/dos_m65/{dos_chkunit.s => dos_unitchk.s} (51%) create mode 100644 src/dos_m65/dos_unitnum.s create mode 100644 src/dos_m65/dos_unitset.s diff --git a/src/,,config_mega65.s b/src/,,config_mega65.s index 4d13d9f8..8398be8c 100644 --- a/src/,,config_mega65.s +++ b/src/,,config_mega65.s @@ -33,6 +33,8 @@ ;; #CONFIG# IEC_JIFFYDOS_BLANK NO ;; #CONFIG# IEC_BURST_M65 NO ; please keep disabled for now +;; #CONFIG# UNIT_SDCARD 20 ; do not change for now + ; --- Tape deck configuration diff --git a/src/dos_m65/,aliases_dos.s b/src/dos_m65/,aliases_dos.s index ffc4f214..685fd5b6 100644 --- a/src/dos_m65/,aliases_dos.s +++ b/src/dos_m65/,aliases_dos.s @@ -20,3 +20,7 @@ !addr UNIT_SDCARD = $05 !addr UNIT_FLOPPY = $06 !addr UNIT_RAMDISK = $07 + + ; General DOS status + + !addr UNIT_HANDLER = $08 \ No newline at end of file diff --git a/src/dos_m65/4020.dos_vectable.s b/src/dos_m65/4020.dos_vectable.s index 63d31009..8df00ad4 100644 --- a/src/dos_m65/4020.dos_vectable.s +++ b/src/dos_m65/4020.dos_vectable.s @@ -2,8 +2,9 @@ ; A vector table to integrate DOS with the MEGA65 Kernal !word dos_INIT -!word dos_CHKUNIT -!word dos_SETUNIT +!word dos_UNITCHK +!word dos_UNITSET +!word dos_UNITNUM !word dos_ACPTR !word dos_CIOUT !word dos_LISTEN diff --git a/src/dos_m65/dos_error_strings.s b/src/dos_m65/dos_error_strings.s new file mode 100644 index 00000000..91a69be4 --- /dev/null +++ b/src/dos_m65/dos_error_strings.s @@ -0,0 +1,156 @@ + +; +; DOS error codes and strings +; + + +; XXX get rid of unnecessary error messages + + +dos_err_init_sdcard: + + !pet "m65 dos sdcard", 0 + +dos_err_init_floppy: + + !pet "m65 dos floppy", 0 + +dos_err_init_ramdisk: + + !pet "m65 dos ram disk", 0 + + +; List compiled from various manuals (CBM 1571, CBM 1581, CMD FD4000, MSD Super Disk, IDE64) + + +dos_err_00: ; not an error + + !pet "ok", 0 + +dos_err_01: ; not an error + + !pet "files scratched", 0 + +dos_err_02: ; not an error + + !pet "partition selected", 0 + +dos_err_20: ; header not found +dos_err_21: ; no data addres mark +dos_err_22: ; block not found +dos_err_23: ; data error +dos_err_27: ; header error + + !pet "read error", 0 + +dos_err_25: + + !pet "write error", 0 + +dos_err_26: + + !pet "write protect on", 0 + +dos_err_29: + + !pet "disk changed", 0 + +dos_err_30: ; invalid characters in command +dos_err_31: ; unrecognized command +dos_err_32: ; command too long +dos_err_33: ; illegal file name +dos_err_34: ; missing file name + + !pet "syntax error", 0 + +dos_err_39: + + !pet "file not found", 0 + +dos_err_49: ; disk formatted, but format not supported + + !pet "invalid format", 0 + +dos_err_50: + + !pet "record not present", 0 + +dos_err_51: + + !pet "overflow in record", 0 + +dos_err_52: + + !pet "file too large", 0 + +dos_err_60: + + !pet "write file open", 0 + +dos_err_61: + + !pet "file not open", 0 + +dos_err_62: + + !pet "file not found", 0 + +dos_err_63: + + !pet "file exists", 0 + +dos_err_64: + + !pet "file type mismatch", 0 + +dos_err_65: + + !pet "no block", 0 + +dos_err_66: + + !pet "illegal track and sector", 0 + +dos_err_67: + + !pet "illegal system t or s", 0 + +dos_err_70: + + !pet "no channel", 0 + +dos_err_71: + + !pet "directory error", 0 + +dos_err_72: + + !pet "partition full", 0 + +dos_err_73: + + !pet "dos mismatch", 0 + +dos_err_74: + + !pet "drive not ready", 0 + +dos_err_75: + + !pet "format error", 0 + +dos_err_76: + + !pet "controller error", 0 + +dos_err_77: + + !pet "selected partition illegal", 0 + +dos_err_78: + + !pet "system error", 0 + +dos_err_79: ; SD2IEC compatible + + !pet "image invalid", 0 diff --git a/src/dos_m65/dos_init.s b/src/dos_m65/dos_init.s index f7bd85f6..8ef2e514 100644 --- a/src/dos_m65/dos_init.s +++ b/src/dos_m65/dos_init.s @@ -3,6 +3,11 @@ ; Initializes DOS. For detailed description see 'm65dos_bridge.s' file ; + +!set CONFIG_UNIT_FLOPPY = 0 ; XXX floppy not supported yet +!set CONFIG_UNIT_RAMDISK = 0 ; XXX RAM disk not supported yet + + dos_INIT: ; Set the magic string 'CBDOS' diff --git a/src/dos_m65/dos_memchk.s b/src/dos_m65/dos_memchk.s new file mode 100644 index 00000000..62eea52d --- /dev/null +++ b/src/dos_m65/dos_memchk.s @@ -0,0 +1,32 @@ + +; +; Check if DOS memory is not overwritten +; + + +dos_MEMCHK: + + ; Check for magic string + + pha + phx + + ldx #$04 +@1: + lda MAGICSTR, x + cmp dos_magicstr, x + bne @fail + dex + bpl @1 + + plx + pla + clc + rts + +@fail: + + plx + pla + sec + rts diff --git a/src/dos_m65/dos_setunit.s b/src/dos_m65/dos_setunit.s deleted file mode 100644 index 1863dfe9..00000000 --- a/src/dos_m65/dos_setunit.s +++ /dev/null @@ -1,42 +0,0 @@ - -; -; Unit number handling. For detailed description see 'm65dos_bridge.s' file -; - - -dos_SETUNIT: - - ; XXX check if .X is valid - - cmp #$00 - beq dos_SETUNIT_sdcard - cmp #$01 - beq dos_SETUNIT_floppy - cmp #$02 - beq dos_SETUNIT_ramdisk - - sec - rts - -dos_SETUNIT_sdcard: - - stx UNIT_SDCARD - +skip_2_bytes_trash_nvz - - ; FALLTROUGH - -dos_SETUNIT_floppy: - - stx UNIT_FLOPPY - +skip_2_bytes_trash_nvz - - ; FALLTROUGH - -dos_SETUNIT_ramdisk: - - stx UNIT_RAMDISK - - ; FALLTROUGH - - clc - rts diff --git a/src/dos_m65/dos_chkunit.s b/src/dos_m65/dos_unitchk.s similarity index 51% rename from src/dos_m65/dos_chkunit.s rename to src/dos_m65/dos_unitchk.s index a530850d..ee94d898 100644 --- a/src/dos_m65/dos_chkunit.s +++ b/src/dos_m65/dos_unitchk.s @@ -4,58 +4,51 @@ ; -dos_CHKUNIT: +dos_UNITCHK: - ; Check for magic string + ; Check if memory content is not damaged - pha - phx - - ldx #$04 -@1: - lda MAGICSTR, x - cmp dos_magicstr, x - bne dos_CHKUNIT_mem_fail - dex - bpl @1 - - plx - pla + jsr dos_MEMCHK + bcs dos_UNITCHK_none ; Check for unit cmp UNIT_SDCARD - beq dos_CHKUNIT_sdcard + beq dos_UNITCHK_sdcard cmp UNIT_FLOPPY - beq dos_CHKUNIT_floppy + beq dos_UNITCHK_floppy cmp UNIT_RAMDISK - beq dos_CHKUNIT_ramdisk + beq dos_UNITCHK_ramdisk + + ; FALLTROUGH + +dos_UNITCHK_none: sec rts -dos_CHKUNIT_sdcard: +dos_UNITCHK_sdcard: lda #$00 +skip_2_bytes_trash_nvz ; FALLTROUGH -dos_CHKUNIT_floppy: +dos_UNITCHK_floppy: lda #$01 +skip_2_bytes_trash_nvz ; FALLTROUGH -dos_CHKUNIT_ramdisk: +dos_UNITCHK_ramdisk: lda #$02 clc rts -dos_CHKUNIT_mem_fail: +dos_UNITCHK_mem_fail: plx pla diff --git a/src/dos_m65/dos_unitnum.s b/src/dos_m65/dos_unitnum.s new file mode 100644 index 00000000..8336a779 --- /dev/null +++ b/src/dos_m65/dos_unitnum.s @@ -0,0 +1,53 @@ + +; +; Unit number handling. For detailed description see 'm65dos_bridge.s' file +; + + +dos_UNITNUM: + + ; Check if memory content is not damaged + + jsr dos_MEMCHK + bcs dos_UNITNUM_none + + ; Check what kind of device was requested + + cmp #$00 + beq dos_UNITNUM_sdcard + cmp #$01 + beq dos_UNITNUM_floppy + cmp #$02 + beq dos_UNITNUM_ramdisk + + lda #$00 + + ; FALLTROUGH + +dos_UNITNUM_none: + + sec + rts + +dos_UNITNUM_sdcard: + + lda UNIT_SDCARD + + +skip_2_bytes_trash_nvz + +dos_UNITNUM_floppy: + + lda UNIT_FLOPPY + + +skip_2_bytes_trash_nvz + +dos_UNITNUM_ramdisk: + + lda UNIT_RAMDISK + + cmp #$00 + beq dos_UNITNUM_none + + clc + rts + diff --git a/src/dos_m65/dos_unitset.s b/src/dos_m65/dos_unitset.s new file mode 100644 index 00000000..49133f6d --- /dev/null +++ b/src/dos_m65/dos_unitset.s @@ -0,0 +1,49 @@ + +; +; Unit number handling. For detailed description see 'm65dos_bridge.s' file +; + + +dos_UNITSET: + + ; Check if memory content is not damaged + + jsr dos_MEMCHK + bcc @1 + rts +@1: + ; Check what kind of device was requested + + cmp #$00 + beq dos_UNITSET_sdcard + ; XXX devioces below are not implemented yet + ; cmp #$01 + ; beq dos_UNITSET_floppy + ; cmp #$02 + ; beq dos_UNITSET_ramdisk + + sec + rts + +dos_UNITSET_sdcard: + + stx UNIT_SDCARD + +skip_2_bytes_trash_nvz + + ; FALLTROUGH + +dos_UNITSET_floppy: + + stx UNIT_FLOPPY + +skip_2_bytes_trash_nvz + + ; FALLTROUGH + +dos_UNITSET_ramdisk: + + stx UNIT_RAMDISK + + ; FALLTROUGH + + clc + rts diff --git a/src/kernal/iec_fast/m65dos_bridge.s b/src/kernal/iec_fast/m65dos_bridge.s index f0d2b00b..8acfbfc8 100644 --- a/src/kernal/iec_fast/m65dos_bridge.s +++ b/src/kernal/iec_fast/m65dos_bridge.s @@ -7,16 +7,17 @@ !addr VDOS_INIT = $4020 + 0 * 2 -!addr VDOS_CHKUNIT = $4020 + 1 * 2 -!addr VDOS_SETUNIT = $4020 + 2 * 2 -!addr VDOS_ACPTR = $4020 + 3 * 2 -!addr VDOS_CIOUT = $4020 + 4 * 2 -!addr VDOS_LISTEN = $4020 + 5 * 2 -!addr VDOS_SECOND = $4020 + 6 * 2 -!addr VDOS_TALK = $4020 + 7 * 2 -!addr VDOS_TKSA = $4020 + 8 * 2 -!addr VDOS_UNTLK = $4020 + 9 * 2 -!addr VDOS_UNLSN = $4020 + 10 * 2 +!addr VDOS_UNITCHK = $4020 + 1 * 2 +!addr VDOS_UNITSET = $4020 + 2 * 2 +!addr VDOS_UNITNUM = $4020 + 3 * 2 +!addr VDOS_ACPTR = $4020 + 4 * 2 +!addr VDOS_CIOUT = $4020 + 5 * 2 +!addr VDOS_LISTEN = $4020 + 6 * 2 +!addr VDOS_SECOND = $4020 + 7 * 2 +!addr VDOS_TALK = $4020 + 8 * 2 +!addr VDOS_TKSA = $4020 + 9 * 2 +!addr VDOS_UNTLK = $4020 + 10 * 2 +!addr VDOS_UNLSN = $4020 + 11 * 2 m65dos_init: @@ -27,24 +28,34 @@ m65dos_init: jsr (VDOS_INIT) bra m65dos_end_1 -m65dos_chkunit: ; XXX expose to BASIC +m65dos_unitchk: ; XXX expose to BASIC ; Checks is the unit number is supported by the internal DOS ; Input: .A - unit number to check ; Output: Carry set if not supported, otherwise .A contains unit type (0 = SD card, 1 = internal floppy, 2 = RAM disk) jsr map_DOS_1 - jsr (VDOS_CHKUNIT) + jsr (VDOS_UNITCHK) bra m65dos_end_1 -m65dos_setunit: ; XXX expose to BASIC +m65dos_unitset: ; XXX expose to BASIC ; Set the unit number - ; Input: .A - unit number, .X - unit type (as in m65dos_chkunit) + ; Input: .X - unit number, .A - unit type (as in m65dos_chkunit) ; Output: Carry set means error jsr map_DOS_1 - jsr (VDOS_SETUNIT) + jsr (VDOS_UNITSET) + bra m65dos_end_1 + +m65dos_unitnum: ; XXX expose to BASIC + + ; Set the unit number + ; Input: .A - unit type (as in m65dos_chkunit) + ; Output: .A - unit number, Carry set means error + + jsr map_DOS_1 + jsr (VDOS_UNITNUM) bra m65dos_end_1 m65dos_acptr: diff --git a/src/kernal/iec_fast/m65dos_detect.s b/src/kernal/iec_fast/m65dos_detect.s index b188b6d5..2cb5fed4 100644 --- a/src/kernal/iec_fast/m65dos_detect.s +++ b/src/kernal/iec_fast/m65dos_detect.s @@ -12,7 +12,7 @@ m65dos_detect: ; Output: Carry set if not supported, if supported IECPROTO isset to IEC_ROMDOS pha - jsr m65dos_chkunit + jsr m65dos_unitchk bcs @1 lda #IEC_ROMDOS diff --git a/src/kernal/iostack/setfls.s b/src/kernal/iostack/setfls.s index 36be657e..968bd9de 100644 --- a/src/kernal/iostack/setfls.s +++ b/src/kernal/iostack/setfls.s @@ -16,8 +16,8 @@ SETFLS: ; There are 6 sane ways to implement this routine, ; I hope this one will not cause similarity to CBM code - sta LA - sty SA - stx FA + sta LA ; logical number + sty SA ; secondary address + stx FA ; unit number rts