rework in CBDOS

This commit is contained in:
FeralChild64 committed 2021-02-13 14:50:10 +01:00
1 parent f7ea553ff8
commit 13c6759904
30 files changed
+485 -412

No files matched your search

+22 -8
View File
@@ -13,20 +13,34 @@
!addr MAGICSTR = $8000 ; magic string; if not matching, DOS considered non-functional
; Register storage
!addr REG_A = $8005
!addr REG_X = $8006
!addr REG_Y = $8007
!addr REG_Z = $8008
; Reserved: $8009 - $800C
; General DOS configuration
!addr UNIT_SDCARD = $8005 ; unit number for device, 0 = none
!addr UNIT_FLOPPY = $8006 ; as above
!addr UNIT_RAMDISK = $8007 ; as above
!addr UNIT_SDCARD = $800D ; unit number for device, 0 = none
!addr UNIT_FLOPPY = $800E ; as above
!addr UNIT_RAMDISK = $800F ; as above
; General DOS status
!addr IDX1_LISTENER = $8008 ; listener idx, >=$80 = none
!addr IDX2_LISTENER = $8009 ; listener idx * 2, >=$80 = none - for calling routines via vector table
!addr IDX1_TALKER = $800A ; talker idx, >=$80 = none
!addr IDX2_TALKER = $800B ; talker idx * 2, >=$80 = none - for calling routines via vector table
!addr IDX1_LISTENER = $8010 ; listener idx, >=$80 = none
!addr IDX2_LISTENER = $8011 ; listener idx * 2, >=$80 = none - for calling routines via vector table
!addr IDX1_TALKER = $8012 ; talker idx, >=$80 = none
!addr IDX2_TALKER = $8013 ; talker idx * 2, >=$80 = none - for calling routines via vector table
; Free space: $800C-$8069
; Free space: $8014-$8063
!addr XX_MODE = $8064 ; current mode (0 = none, 1 = receiving command/file name)
!addr SD_MODE = $8064 ; - SD card
!addr FD_MODE = $8065 ; - floppy
!addr RD_MODE = $8066 ; - ram disk
!addr XX_CHANNEL = $8067 ; current channel
!addr SD_CHANNEL = $8067 ; - SD card
+8 -8
View File
@@ -5,11 +5,11 @@
!word dos_UNITCHK
!word dos_UNITSET
!word dos_UNITNUM
!word dos_ACPTR
!word dos_CIOUT
!word dos_LISTEN
!word dos_SECOND
!word dos_TALK
!word dos_TKSA
!word dos_UNTLK
!word dos_UNLSN
!word msg_ACPTR
!word msg_CIOUT
!word msg_LISTEN
!word msg_SECOND
!word msg_TALK
!word msg_TKSA
!word msg_UNTLK
!word msg_UNLSN
+1 -2
View File
@@ -8,5 +8,4 @@ dev_fd_cmd_CLOSE:
; XXX provide implementation
sec
jmp dos_SECOND_done
jmp dos_EXIT_SEC
+1 -2
View File
@@ -8,5 +8,4 @@ dev_fd_cmd_OPEN:
; XXX provide implementation
sec
jmp dos_SECOND_done
jmp dos_EXIT_SEC
+1
View File
@@ -11,6 +11,7 @@ dev_fd_init:
ldx #$00
stx FD_STATUS_IDX
stx FD_CMDFN_IDX
stx FD_MODE
dex
@1:
inx
+1 -2
View File
@@ -8,5 +8,4 @@ dev_rd_cmd_CLOSE:
; XXX provide implementation
sec
jmp dos_SECOND_done
jmp dos_EXIT_SEC
+1 -2
View File
@@ -8,5 +8,4 @@ dev_rd_cmd_OPEN:
; XXX provide implementation
sec
jmp dos_SECOND_done
jmp dos_EXIT_SEC
+1
View File
@@ -11,6 +11,7 @@ dev_rd_init:
ldx #$00
stx RD_STATUS_IDX
stx RD_CMDFN_IDX
stx RD_MODE
dex
@1:
inx
+1 -2
View File
@@ -8,5 +8,4 @@ dev_sd_cmd_CLOSE:
; XXX provide implementation
sec
jmp dos_SECOND_done
jmp dos_EXIT
+3 -3
View File
@@ -6,7 +6,7 @@
dev_sd_cmd_OPEN:
; XXX provide implementation
lda #$01 ; mode: receive command or file name
sta SD_MODE
sec
jmp dos_SECOND_done
jmp dos_EXIT
+1
View File
@@ -11,6 +11,7 @@ dev_sd_init:
ldx #$00
stx SD_STATUS_IDX
stx SD_CMDFN_IDX
stx SD_MODE
dex
@1:
inx
-80
View File
@@ -1,80 +0,0 @@
;
; Implementation of ACPTR command. For detailed description see 'm65dos_bridge.s' file.
;
dos_ACPTR: ; does not have to preserve .X
ldx IDX1_TALKER
bmi dos_ACPTR_fail
lda XX_CHANNEL, X
cmp #$0F
beq dos_ACPTR_status
; XXX providde implementation for non-status streams
jmp dos_ACPTR_fail
dos_ACPTR_status:
ldx IDX2_TALKER
jsr (dos_ACPTR_getsts_table, X)
sta TBTCNT ; byte return
beq dos_ACPTR_reset_status
clc
rts
dos_ACPTR_fail:
; XXX set error code
sec
rts
dos_ACPTR_reset_status:
lda IDX1_TALKER
jsr dos_status_00
; FALLTROUGH
dos_ACPTR_eoi:
jsr kernalstatus_EOI
clc
rts
; Sending bytes from the status string
dos_ACPTR_getsts_SD: ; get next byte of status - SD card
ldx SD_STATUS_IDX
inc SD_STATUS_IDX
lda SD_STATUS_STR,x
rts
dos_ACPTR_getsts_FD: ; get next byte of status - floppy
ldx FD_STATUS_IDX
inc FD_STATUS_IDX
lda FD_STATUS_STR,x
rts
dos_ACPTR_getsts_RD: ; get next byte of status - ram disk
ldx RD_STATUS_IDX
inc RD_STATUS_IDX
lda RD_STATUS_STR,x
rts
dos_ACPTR_getsts_table:
!word dos_ACPTR_getsts_SD
!word dos_ACPTR_getsts_FD
!word dos_ACPTR_getsts_RD
-71
View File
@@ -1,71 +0,0 @@
;
; Implementation of ACPTR command. For detailed description see 'm65dos_bridge.s' file.
;
dos_CIOUT:
pha
phx
; XXX handle cases of transferring data
; Receive command/file name byte
ldx IDX2_TALKER
jsr (dos_CIOUT_putcmdfn_table, X)
plx
pla
clc
rts
; Receiving command/file name
dos_CIOUT_putcmdfn_SD: ; get next byte of status - SD card
ldx SD_CMDFN_IDX
sta SD_CMDFN_IDX,x
inx
bpl @1
ldx #$7F
@1:
lda #$00
sta SD_CMDFN_IDX,x
rts
dos_CIOUT_putcmdfn_FD: ; get next byte of status - floppy
ldx FD_CMDFN_IDX
sta FD_CMDFN_IDX,x
inx
bpl @1
ldx #$7F
@1:
lda #$00
sta FD_CMDFN_IDX,x
rts
dos_CIOUT_putcmdfn_RD: ; get next byte of status - ram disk
ldx RD_CMDFN_IDX
sta RD_CMDFN_IDX,x
inx
bpl @1
ldx #$7F
@1:
lda #$00
sta RD_CMDFN_IDX,x
rts
dos_CIOUT_putcmdfn_table:
!word dos_CIOUT_putcmdfn_SD
!word dos_CIOUT_putcmdfn_FD
!word dos_CIOUT_putcmdfn_RD
+54
View File
@@ -0,0 +1,54 @@
; Helper routines for entering/exiting the context
dos_ENTER: ; enter DOS context
sta REG_A
stx REG_X
sty REG_Y
stz REG_Z
rts
dos_EXIT_SEC: ; exit DOS context with Carry set
sec
bra dos_EXIT_common
dos_EXIT: ; exit DOS context with Carry clear
clc
; FALLTROUGH
dos_EXIT_common:
ldz REG_Z
ldy REG_Y
ldx REG_X
lda REG_A
rts
dos_EXIT_A_SEC: ; exit DOS context with Carry set, return .A
sec
bra dos_EXIT_A_common
dos_EXIT_A: ; exit DOS context with Carry clear, return .A
clc
; FALLTROUGH
dos_EXIT_A_common:
ldz REG_Z
ldy REG_Y
ldx REG_X
rts
-9
View File
@@ -12,10 +12,6 @@
dos_status_00: ; OK
pha
phx
phy
; Set status byte pointer to the beginning
tax
@@ -76,11 +72,6 @@ dos_status_00: ; OK
; End
ply
plx
pla
clc ; mark status as OK
rts
+5 -4
View File
@@ -10,9 +10,10 @@
dos_INIT:
jsr dos_ENTER
; Set the magic string 'CBDOS'
phx
ldx #$04
@1:
lda dos_magicstr, x
@@ -20,8 +21,6 @@ dos_INIT:
dex
bpl @1
plx
; Set default device numbers
lda #CONFIG_UNIT_SDCARD
@@ -45,4 +44,6 @@ dos_INIT:
jsr dev_fd_init
jsr dev_rd_init
rts
; Exit DOS context
jmp dos_EXIT
-110
View File
@@ -1,110 +0,0 @@
;
; Implementation of LISTEN/UNLSN/TALK/UNTLK commands.
; For detailed description see 'm65dos_bridge.s' file.
;
; LISTEN
dos_LISTEN:
pha
and #$1F
beq dos_fail_TALK_LISTEN ; branch if device 0 (used to denote lack of device)
cmp UNIT_SDCARD
bne @1
lda #$00
bra dos_LISTEN_success
@1:
cmp UNIT_FLOPPY
bne @2
lda #$01
bra dos_LISTEN_success
@2:
cmp UNIT_RAMDISK
bne dos_fail_TALK_LISTEN
lda #$02
; FALLTROUGH
dos_LISTEN_success:
sta IDX1_LISTENER
asl
sta IDX2_LISTENER
; XXX should we reset XX_CMDFN_IDX ?
bra dos_common_LSN_TALK_UN
; TALK
dos_TALK:
pha
and #$1F
beq dos_fail_TALK_LISTEN ; branch if device 0 (used to denote lack of device)
cmp UNIT_SDCARD
bne @1
lda #$00
bra dos_TALK_success
@1:
cmp UNIT_FLOPPY
bne @2
lda #$01
bra dos_TALK_success
@2:
cmp UNIT_RAMDISK
bne dos_fail_TALK_LISTEN
lda #$02
; FALLTROUGH
dos_TALK_success:
sta IDX1_TALKER
asl
sta IDX2_TALKER
bra dos_common_LSN_TALK_UN
dos_fail_TALK_LISTEN:
pla
lda #K_ERR_DEVICE_NOT_FOUND
sec
rts
; UNLSN / UNTLK
dos_UNLSN:
pha
lda #$FF
sta IDX1_LISTENER
sta IDX2_LISTENER
bra dos_common_LSN_TALK_UN
dos_UNTLK:
pha
lda #$FF
sta IDX1_TALKER
sta IDX2_TALKER
; FALLTROUGH
dos_common_LSN_TALK_UN:
pla
clc
rts
-7
View File
@@ -8,9 +8,6 @@ dos_MEMCHK:
; Check for magic string
pha
phx
ldx #$04
@1:
lda MAGICSTR, x
@@ -19,14 +16,10 @@ dos_MEMCHK:
dex
bpl @1
plx
pla
clc
rts
@fail:
plx
pla
sec
rts
-71
View File
@@ -1,71 +0,0 @@
;
; Implementation of SECOND/TKSA commands.
; For detailed description see 'm65dos_bridge.s' file.
;
dos_SECOND:
pha
phx
phy
; First store the channel
tay
and #$0F ; support channels 0-15, like 1541 drive
ldx IDX1_LISTENER
bmi dos_SECOND_done ; do nothing if no listener
sta XX_CHANNEL, x ; store channel
; Determine command type
tya
and #$F0
cmp #$F0
beq dos_SECOND_OPEN
cmp #$E0
beq dos_SECOND_CLOSE
; XXX provide implementation
bra dos_SECOND_done
dos_SECOND_OPEN:
ldx IDX2_LISTENER
jmp (dos_cmd_OPEN_vectable, x)
dos_SECOND_CLOSE:
ldx IDX2_LISTENER
jmp (dos_cmd_CLOSE_vectable, x)
dos_SECOND_done:
ply
bra dos_TKSA_done ; reuse part of TKSA code
dos_TKSA:
pha
phx
and #$0F ; support channels 0-15, like 1541 drive
ldx IDX1_TALKER
bmi dos_TKSA_done ; do nothing if no taalker
sta XX_CHANNEL, x ; store channel
; FALLTROUGH
dos_TKSA_done:
plx
pla
clc
rts
+6 -13
View File
@@ -6,10 +6,12 @@
dos_UNITCHK:
jsr dos_ENTER
; Check if memory content is not damaged
jsr dos_MEMCHK
bcs dos_UNITCHK_none
bcs dos_UNITCHK_fail
; Check for unit
@@ -22,10 +24,9 @@ dos_UNITCHK:
; FALLTROUGH
dos_UNITCHK_none:
dos_UNITCHK_fail:
sec
rts
jmp dos_EXIT_SEC
dos_UNITCHK_sdcard:
@@ -44,13 +45,5 @@ dos_UNITCHK_floppy:
dos_UNITCHK_ramdisk:
lda #$02
clc
rts
dos_UNITCHK_mem_fail:
plx
pla
sec
rts
jmp dos_EXIT_A
+10 -9
View File
@@ -6,10 +6,13 @@
dos_UNITNUM:
jsr dos_ENTER
; Check if memory content is not damaged
jsr dos_MEMCHK
bcs dos_UNITNUM_none
bcs dos_UNITNUM_fail
lda REG_A
; Check what kind of device was requested
@@ -22,12 +25,11 @@ dos_UNITNUM:
; FALLTROUGH
dos_UNITNUM_none:
dos_UNITNUM_fail:
lda #$00
sec
rts
jmp dos_EXIT_A_SEC
dos_UNITNUM_sdcard:
@@ -42,13 +44,12 @@ dos_UNITNUM_floppy:
dos_UNITNUM_ramdisk:
lda UNIT_RAMDISK
bra dos_UNITNUM_common
; FALLTROUGH
dos_UNITNUM_common:
cmp #$00
beq dos_UNITNUM_none
clc
rts
beq dos_UNITNUM_fail
jmp dos_EXIT_A
+5 -7
View File
@@ -6,6 +6,8 @@
dos_UNITSET:
jsr dos_ENTER
; Check if memory content is not damaged
jsr dos_MEMCHK
@@ -18,14 +20,13 @@ dos_UNITSET:
cmp #$00
beq dos_UNITSET_sdcard
; XXX devioces below are not implemented yet
; XXX devices below are not implemented yet
; cmp #$01
; beq dos_UNITSET_floppy
; cmp #$02
; beq dos_UNITSET_ramdisk
sec
rts
jmp dos_EXIT_SEC
dos_UNITSET_sdcard:
@@ -45,7 +46,4 @@ dos_UNITSET_ramdisk:
stx UNIT_RAMDISK
; FALLTROUGH
clc
rts
jmp dos_EXIT
@@ -4,14 +4,14 @@
;
dos_cmd_OPEN_vectable:
dos_cmd_OPEN_vectab:
!word dev_sd_cmd_OPEN
!word dev_fd_cmd_OPEN
!word dev_rd_cmd_OPEN
dos_cmd_CLOSE_vectable:
dos_cmd_CLOSE_vectab:
!word dev_sd_cmd_CLOSE
!word dev_fd_cmd_CLOSE
+86
View File
@@ -0,0 +1,86 @@
;
; Implementation of ACPTR command. For detailed description see 'm65dos_bridge.s' file.
;
msg_ACPTR:
jsr dos_ENTER
; Check if there is a talker active
ldx IDX1_TALKER
bmi msg_ACPTR_fail
; Check if active channel is status one
lda XX_CHANNEL, X
cmp #$0F
beq msg_ACPTR_status
; XXX providde implementation for non-status channels
jmp msg_ACPTR_fail
msg_ACPTR_status:
ldx IDX2_TALKER
jmp (msg_ACPTR_status_vectab, X)
msg_ACPTR_status_SD: ; get next byte of status - SD card
ldx SD_STATUS_IDX
inc SD_STATUS_IDX
lda SD_STATUS_STR,x
bra msg_ACPTR_status_got
msg_ACPTR_status_FD: ; get next byte of status - floppy
ldx FD_STATUS_IDX
inc FD_STATUS_IDX
lda FD_STATUS_STR,x
bra msg_ACPTR_status_got
msg_ACPTR_status_RD: ; get next byte of status - ram disk
ldx RD_STATUS_IDX
inc RD_STATUS_IDX
lda RD_STATUS_STR,x
; FALLTROUGH
msg_ACPTR_status_got:
sta TBTCNT ; byte return
beq msg_ACPTR_reset_status
jmp dos_EXIT
msg_ACPTR_fail:
; XXX set error code
jmp dos_EXIT_SEC
msg_ACPTR_reset_status:
lda IDX1_TALKER
jsr dos_status_00
; FALLTROUGH
msg_ACPTR_eoi:
jsr kernalstatus_EOI
jmp dos_EXIT_SEC
; Vector tables for jumps
msg_ACPTR_status_vectab:
!word msg_ACPTR_status_SD
!word msg_ACPTR_status_FD
!word msg_ACPTR_status_RD
+74
View File
@@ -0,0 +1,74 @@
;
; Implementation of ACPTR command. For detailed description see 'm65dos_bridge.s' file.
;
msg_CIOUT:
jsr dos_ENTER
; Check operation mode
ldx IDX1_LISTENER
lda XX_MODE, x
cmp #$01
bne @1
; Receiving command or file name
ldx IDX2_TALKER
jmp (msg_CIOUT_cmdfn_vectab, X)
@1:
; XXX handle cases of transferring data
jmp dos_EXIT_SEC
; Receiving command/file name
msg_CIOUT_cmdfn_SD: ; get next byte of status - SD card
ldx SD_CMDFN_IDX
sta SD_CMDFN_IDX,x
inx
bpl @1
ldx #$7F
@1:
lda #$00
sta SD_CMDFN_IDX,x
jmp dos_EXIT
msg_CIOUT_cmdfn_FD: ; get next byte of status - floppy
ldx FD_CMDFN_IDX
sta FD_CMDFN_IDX,x
inx
bpl @1
ldx #$7F
@1:
lda #$00
sta FD_CMDFN_IDX,x
jmp dos_EXIT
msg_CIOUT_cmdfn_RD: ; get next byte of status - ram disk
ldx RD_CMDFN_IDX
sta RD_CMDFN_IDX,x
inx
bpl @1
ldx #$7F
@1:
lda #$00
sta RD_CMDFN_IDX,x
jmp dos_EXIT
msg_CIOUT_cmdfn_vectab:
!word msg_CIOUT_cmdfn_SD
!word msg_CIOUT_cmdfn_FD
!word msg_CIOUT_cmdfn_RD
+54
View File
@@ -0,0 +1,54 @@
;
; Implementation of LISTEN commands.
; For detailed description see 'm65dos_bridge.s' file.
;
msg_LISTEN:
jsr dos_ENTER
and #$1F
beq msg_LISTEN_fail ; branch if device 0 (used to denote lack of device)
cmp UNIT_SDCARD
bne @1
; LISTEN on SD card
lda #$00
bra msg_LISTEN_success
@1:
cmp UNIT_FLOPPY
bne @2
; LISTEN on floppy
lda #$01
bra msg_LISTEN_success
@2:
cmp UNIT_RAMDISK
bne msg_LISTEN_fail
; LISTEN on ram disk
lda #$02
; FALLTROUGH
msg_LISTEN_success:
sta IDX1_LISTENER
asl
sta IDX2_LISTENER
; XXX should we reset XX_CMDFN_IDX ?
jmp dos_EXIT
msg_LISTEN_fail:
lda #K_ERR_DEVICE_NOT_FOUND
jmp dos_EXIT_A_SEC
+49
View File
@@ -0,0 +1,49 @@
;
; Implementation of SECOND command.
; For detailed description see 'm65dos_bridge.s' file.
;
msg_SECOND:
jsr dos_ENTER
; First store the channel
tay
and #$0F ; support channels 0-15, like 1541 drive
ldx IDX1_LISTENER
bmi msg_SECOND_done ; do nothing if no listener
sta XX_CHANNEL, x ; store channel
; Determine command type
tya
and #$F0
cmp #$F0
beq msg_SECOND_OPEN
cmp #$E0
beq msg_SECOND_CLOSE
; XXX provide implementation
; FALLTROUGH
msg_SECOND_done:
jmp dos_EXIT
msg_SECOND_OPEN:
lda #$00
sta XX_CMDFN_IDX, x ; reset the index to the command/filename
ldx IDX2_LISTENER
jmp (dos_cmd_OPEN_vectab, x)
msg_SECOND_CLOSE:
ldx IDX2_LISTENER
jmp (dos_cmd_CLOSE_vectab, x)
+52
View File
@@ -0,0 +1,52 @@
;
; Implementation of TALK commands.
; For detailed description see 'm65dos_bridge.s' file.
;
msg_TALK:
jsr dos_ENTER
and #$1F
beq msg_TALK_fail ; branch if device 0 (used to denote lack of device)
cmp UNIT_SDCARD
bne @1
; TALK on SD card
lda #$00
bra msg_TALK_success
@1:
cmp UNIT_FLOPPY
bne @2
; TALK on floppy
lda #$01
bra msg_TALK_success
@2:
cmp UNIT_RAMDISK
bne msg_TALK_fail
; TALK on ram disk
lda #$02
; FALLTROUGH
msg_TALK_success:
sta IDX1_TALKER
asl
sta IDX2_TALKER
jmp dos_EXIT
msg_TALK_fail:
lda #K_ERR_DEVICE_NOT_FOUND
jmp dos_EXIT_A_SEC
+22
View File
@@ -0,0 +1,22 @@
;
; Implementation of TKSA commands.
; For detailed description see 'm65dos_bridge.s' file.
;
msg_TKSA:
jsr dos_ENTER
and #$0F ; support channels 0-15, like 1541 drive
ldx IDX1_TALKER
bmi msg_TKSA_done ; do nothing if no taalker
sta XX_CHANNEL, x ; store channel
; FALLTROUGH
msg_TKSA_done:
jmp dos_EXIT
+25
View File
@@ -0,0 +1,25 @@
;
; Implementation of UNLSN/UNTLK messages.
; For detailed description see 'm65dos_bridge.s' file.
;
msg_UNLSN:
jsr dos_ENTER
lda #$FF
sta IDX1_LISTENER
sta IDX2_LISTENER
jmp dos_EXIT
msg_UNTLK:
jsr dos_ENTER
sta IDX1_TALKER
sta IDX2_TALKER
jmp dos_EXIT