diff --git a/src/,,config_mega65.s b/src/,,config_mega65.s index 1c9cdbf5..545005e5 100644 --- a/src/,,config_mega65.s +++ b/src/,,config_mega65.s @@ -130,6 +130,13 @@ // #define CONFIG_SHOW_FEATURES +// Built-in DOS configuration + +.const CONFIG_UNIT_SDCARD = 0 // do not change, DOS is not implemented yet +.const CONFIG_UNIT_FLOPPY = 0 // do not change, DOS is not implemented yet +.const CONFIG_UNIT_RAMDISK = 0 // do not change, DOS is not implemented yet + + // Debug options // #define CONFIG_DBG_STUBS_BRK diff --git a/src/dos_m65/,aliases_dos.s b/src/dos_m65/,aliases_dos.s new file mode 100644 index 00000000..c9578fa7 --- /dev/null +++ b/src/dos_m65/,aliases_dos.s @@ -0,0 +1,11 @@ +// +// Memory locations for the DOS +// + + // + // Page 0 + // + + .label UNIT_SDCARD = $00 + .label UNIT_FLOPPY = $01 + .label UNIT_RAMDISK = $02 diff --git a/src/dos_m65/4000.dos_vectable.s b/src/dos_m65/4000.dos_vectable.s index 365f1761..2f99face 100644 --- a/src/dos_m65/4000.dos_vectable.s +++ b/src/dos_m65/4000.dos_vectable.s @@ -3,6 +3,7 @@ .word dos_INIT .word dos_CHKUNIT +.word dos_SETUNIT .word dos_ACPTR .word dos_CIOUT .word dos_LISTEN diff --git a/src/dos_m65/dos_chkunit.s b/src/dos_m65/dos_chkunit.s new file mode 100644 index 00000000..94088238 --- /dev/null +++ b/src/dos_m65/dos_chkunit.s @@ -0,0 +1,38 @@ + +// +// Unit number handling. For detailed description see 'm65dos_bridge.s' file +// + + +dos_CHKUNIT: + + cmp UNIT_SDCARD + beq dos_CHKUNIT_sdcard + cmp UNIT_FLOPPY + beq dos_CHKUNIT_floppy + cmp UNIT_RAMDISK + beq dos_CHKUNIT_ramdisk + + sec + rts + +dos_CHKUNIT_sdcard: + + lda #$00 + skip_2_bytes_trash_nvz + + // FALLTROUGH + +dos_CHKUNIT_floppy: + + lda #$01 + skip_2_bytes_trash_nvz + + // FALLTROUGH + +dos_CHKUNIT_ramdisk: + + lda #$02 + + clc + rts diff --git a/src/dos_m65/dos_init.s b/src/dos_m65/dos_init.s new file mode 100644 index 00000000..82471370 --- /dev/null +++ b/src/dos_m65/dos_init.s @@ -0,0 +1,17 @@ + +// +// Initializes DOS. For detailed description see 'm65dos_bridge.s' file +// + +dos_INIT: + + lda #CONFIG_UNIT_SDCARD + sta UNIT_SDCARD + lda #CONFIG_UNIT_FLOPPY + sta UNIT_FLOPPY + lda #CONFIG_UNIT_RAMDISK + sta UNIT_RAMDISK + + // XXX initialize drivers, etc. + + rts diff --git a/src/dos_m65/dos_setunit.s b/src/dos_m65/dos_setunit.s new file mode 100644 index 00000000..cc9c53f9 --- /dev/null +++ b/src/dos_m65/dos_setunit.s @@ -0,0 +1,42 @@ + +// +// 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/stubs.s b/src/dos_m65/stubs.s index 56a37771..4dcdd351 100644 --- a/src/dos_m65/stubs.s +++ b/src/dos_m65/stubs.s @@ -1,10 +1,6 @@ // Dummy implementations - XXX to be replaced with real ones -dos_INIT: - nop -dos_CHKUNIT: - nop dos_ACPTR: nop dos_CIOUT: diff --git a/src/kernal/iec/acptr.s b/src/kernal/iec/acptr.s index 4739e5db..2f19f92d 100644 --- a/src/kernal/iec/acptr.s +++ b/src/kernal/iec/acptr.s @@ -22,6 +22,11 @@ ACPTR: rts !: +#if ROM_LAYOUT_M65 + jsr m65dos_check + bcc_16 m65dos_acptr // branch if device is handeld by internal DOS +#endif + #if CONFIG_IEC #if CONFIG_IEC_JIFFYDOS jmp iec_rx_dispatch diff --git a/src/kernal/iec/ciout.s b/src/kernal/iec/ciout.s index 6a35c029..a8f0d2e8 100644 --- a/src/kernal/iec/ciout.s +++ b/src/kernal/iec/ciout.s @@ -35,6 +35,11 @@ ciout_store_in_buffer: ciout_send_byte: +#if ROM_LAYOUT_M65 + jsr m65dos_check + bcc_16 m65dos_ciout // branch if device is handeld by internal DOS +#endif + clc // send without EOI #if CONFIG_IEC_JIFFYDOS jsr iec_tx_dispatch diff --git a/src/kernal/iec/iec_cmd_close.s b/src/kernal/iec/iec_cmd_close.s index 095e2000..567edc1f 100644 --- a/src/kernal/iec/iec_cmd_close.s +++ b/src/kernal/iec/iec_cmd_close.s @@ -20,6 +20,13 @@ iec_cmd_close: !: ora #$E0 +#if ROM_LAYOUT_M65 + + jsr m65dos_check + bcc_16 m65dos_second // branch if device is handeld by internal DOS + +#endif + jmp common_open_close_unlsn_second diff --git a/src/kernal/iec/iec_cmd_open.s b/src/kernal/iec/iec_cmd_open.s index a4a0e2df..c93da420 100644 --- a/src/kernal/iec/iec_cmd_open.s +++ b/src/kernal/iec/iec_cmd_open.s @@ -20,6 +20,13 @@ iec_cmd_open: // similar to TKSA, but without turnaround !: ora #$F0 +#if ROM_LAYOUT_M65 + + jsr m65dos_check + bcc_16 m65dos_second // branch if device is handeld by internal DOS + +#endif + #if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_MEGA_65 pha jsr burst_advertise diff --git a/src/kernal/iec/listen.s b/src/kernal/iec/listen.s index 33bb554d..ddb05c9b 100644 --- a/src/kernal/iec/listen.s +++ b/src/kernal/iec/listen.s @@ -16,11 +16,22 @@ LISTEN: -#if CONFIG_IEC +#if CONFIG_IEC || ROM_LAYOUT_M65 // According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer jsr iec_tx_flush +#endif + +#if ROM_LAYOUT_M65 + + jsr m65dos_detect + bcc_16 m65dos_listen // branch if device is handeld by internal DOS + +#endif + +#if CONFIG_IEC + // Check whether device number is correct jsr iec_check_devnum_oc bcc !+ diff --git a/src/kernal/iec/second.s b/src/kernal/iec/second.s index 60fce725..bfe484f4 100644 --- a/src/kernal/iec/second.s +++ b/src/kernal/iec/second.s @@ -13,8 +13,18 @@ // +// XXX cleanup: iec_cmd_open and iec_cmd_close should just do ORA and jump directly here + + SECOND: +#if ROM_LAYOUT_M65 + + jsr m65dos_check + bcc_16 m65dos_second // branch if device is handeld by internal DOS + +#endif + #if CONFIG_IEC // Due to OPEN/CLOSE/TKSA/SECOND command encoding, allowed channels are 0-15; it is the caller @@ -22,8 +32,6 @@ SECOND: // - https://www.lemon64.com/forum/viewtopic.php?t=57694&sid=531ba3592bcffadef2ac8b9162f2e529 // - https://www.pagetable.com/?p=1031 (Kernal API description) - // XXX consider checking whether value is in range (contrary to original ROM implementation) - jmp common_open_close_unlsn_second #else diff --git a/src/kernal/iec/talk.s b/src/kernal/iec/talk.s index 23b0504e..dd0de963 100644 --- a/src/kernal/iec/talk.s +++ b/src/kernal/iec/talk.s @@ -16,11 +16,22 @@ TALK: -#if CONFIG_IEC +#if CONFIG_IEC || ROM_LAYOUT_M65 // According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer jsr iec_tx_flush +#endif + +#if ROM_LAYOUT_M65 + + jsr m65dos_detect + bcc_16 m65dos_talk // branch if device is handeld by internal DOS + +#endif + +#if CONFIG_IEC + // Check whether device number is correct jsr iec_check_devnum_oc bcc !+ diff --git a/src/kernal/iec/tksa.s b/src/kernal/iec/tksa.s index 59d0b9e5..be37b006 100644 --- a/src/kernal/iec/tksa.s +++ b/src/kernal/iec/tksa.s @@ -15,6 +15,13 @@ TKSA: +#if ROM_LAYOUT_M65 + + jsr m65dos_check + bcc_16 m65dos_tksa // branch if device is handeld by internal DOS + +#endif + #if CONFIG_IEC // Due to OPEN/CLOSE/TKSA/SECOND command encoding, allowed channels are 0-15; it is the caller diff --git a/src/kernal/iec/unlsn.s b/src/kernal/iec/unlsn.s index d727fd92..57a2f98a 100644 --- a/src/kernal/iec/unlsn.s +++ b/src/kernal/iec/unlsn.s @@ -16,11 +16,22 @@ UNLSN: -#if CONFIG_IEC +#if CONFIG_IEC || ROM_LAYOUT_M65 // According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer jsr iec_tx_flush +#endif + +#if ROM_LAYOUT_M65 + + jsr m65dos_check + bcc_16 m65dos_unlsn // branch if device is handeld by internal DOS + +#endif + +#if CONFIG_IEC + #if CONFIG_IEC_JIFFYDOS || CONFIG_IEC_DOLPHINDOS lda #$FF // do not use JiffyDOS / DolphinDOS anymore, trigger JiffyDOS detection diff --git a/src/kernal/iec/untlk.s b/src/kernal/iec/untlk.s index 2fab716a..8193bed7 100644 --- a/src/kernal/iec/untlk.s +++ b/src/kernal/iec/untlk.s @@ -16,11 +16,22 @@ UNTLK: -#if CONFIG_IEC +#if CONFIG_IEC || ROM_LAYOUT_M65 // According to serial-bus.pdf (page 15) this routine flushes the IEC out buffer jsr iec_tx_flush +#endif + +#if ROM_LAYOUT_M65 + + jsr m65dos_check + bcc_16 m65dos_untlk // branch if device is handeld by internal DOS + +#endif + +#if CONFIG_IEC + #if CONFIG_IEC_JIFFYDOS || CONFIG_IEC_DOLPHINDOS lda #$FF // do not use JiffyDOS / DolphinDOS anymore, trigger JiffyDOS detection diff --git a/src/kernal/iec_fast/m65dos_bridge.s b/src/kernal/iec_fast/m65dos_bridge.s index 11208afe..40b21c85 100644 --- a/src/kernal/iec_fast/m65dos_bridge.s +++ b/src/kernal/iec_fast/m65dos_bridge.s @@ -8,44 +8,58 @@ .label VDOS_INIT = $4000 + 0 * 2 .label VDOS_CHKUNIT = $4000 + 1 * 2 -.label VDOS_ACPTR = $4000 + 2 * 2 -.label VDOS_CIOUT = $4000 + 3 * 2 -.label VDOS_LISTEN = $4000 + 4 * 2 -.label VDOS_SECOND = $4000 + 5 * 2 -.label VDOS_TALK = $4000 + 6 * 2 -.label VDOS_TKSA = $4000 + 7 * 2 -.label VDOS_UNTLK = $4000 + 8 * 2 -.label VDOS_UNLSN = $4000 + 9 * 2 - - -// XXX connect this to core IEC implementation +.label VDOS_SETUNIT = $4000 + 2 * 2 +.label VDOS_ACPTR = $4000 + 3 * 2 +.label VDOS_CIOUT = $4000 + 4 * 2 +.label VDOS_LISTEN = $4000 + 5 * 2 +.label VDOS_SECOND = $4000 + 6 * 2 +.label VDOS_TALK = $4000 + 7 * 2 +.label VDOS_TKSA = $4000 + 8 * 2 +.label VDOS_UNTLK = $4000 + 9 * 2 +.label VDOS_UNLSN = $4000 + 10 * 2 m65dos_init: + // Initializes the DOS internal variables + jsr map_DOS_1 jsr_ind VDOS_INIT jmp_8 !+ -m65dos_chkunit: +m65dos_chkunit: // 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_ind VDOS_CHKUNIT jmp_8 !+ +m65dos_setunit: // XXX expose to BASIC + + // Set the unit number + // Input: .A - unit number, .X - unit type (as in m65dos_chkunit) + // Output: Carry set means error + + jsr map_DOS_1 + jsr_ind VDOS_SETUNIT + jmp_8 !+ + m65dos_acptr: jsr map_DOS_1 jsr_ind VDOS_ACPTR !: - jmp map_NORMAL_from_DOS_1 // try to make ACPTR slightly faster + jmp map_NORMAL_from_DOS_1 // ACPTR is slightly faster m65dos_ciout: jsr map_DOS_1 jsr_ind VDOS_CIOUT !: - jmp map_NORMAL_from_DOS_1 // try to make CIOUT slightly faster + jmp map_NORMAL_from_DOS_1 // CIOUT is slightly faster m65dos_listen: diff --git a/src/kernal/iec_fast/m65dos_check.s b/src/kernal/iec_fast/m65dos_check.s new file mode 100644 index 00000000..ba3b25b8 --- /dev/null +++ b/src/kernal/iec_fast/m65dos_check.s @@ -0,0 +1,22 @@ +// #LAYOUT# M65 KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// MEGA65 pseudo-IEC internal DOS support - check if the current device is already handled by internal DOS +// + + +m65dos_check: + + pha + lda IECPROTO + cmp #IEC_ROMDOS + beq !+ + + pla + sec + rts +!: + pla + clc + rts diff --git a/src/kernal/iec_fast/m65dos_detect.s b/src/kernal/iec_fast/m65dos_detect.s new file mode 100644 index 00000000..ff7c9eb9 --- /dev/null +++ b/src/kernal/iec_fast/m65dos_detect.s @@ -0,0 +1,22 @@ +// #LAYOUT# M65 KERNAL_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// MEGA65 pseudo-IEC internal DOS support - detect if a drive should be handled by internal DOS +// + + +m65dos_detect: + + // Checks if drive is supported by internal DOS + // Output: Carry set if not supported, if supported IECPROTO isset to IEC_ROMDOS + + pha + jsr m65dos_chkunit + bcs !+ + + lda #IEC_ROMDOS + sta IECPROTO +!: + pla + rts