small CBDOS refactoring
This commit is contained in:
1 parent
58d74157d3
commit
8ae047b682
6 files changed
+185
-171
No files matched your search
@@ -0,0 +1,101 @@
|
|||||||
|
|
||||||
|
;
|
||||||
|
; CBM/CMD filesystem - helper routine to get the next file block
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
fs_cbm_nextfileblock:
|
||||||
|
|
||||||
|
; Fetch the next track/sector
|
||||||
|
|
||||||
|
lda PAR_SECTOR
|
||||||
|
and #$01
|
||||||
|
bne @part_2
|
||||||
|
|
||||||
|
@part_1:
|
||||||
|
|
||||||
|
; We were reading from the 1st half of the buffer
|
||||||
|
|
||||||
|
ldx SHARED_BUF_1+1
|
||||||
|
lda SHARED_BUF_1+0
|
||||||
|
bra @common_chk
|
||||||
|
|
||||||
|
@part_2:
|
||||||
|
|
||||||
|
; We were reading from the 2nd half of the buffer
|
||||||
|
|
||||||
|
ldx SHARED_BUF_1+$100+1
|
||||||
|
lda SHARED_BUF_1+$100+0
|
||||||
|
|
||||||
|
@common_chk:
|
||||||
|
|
||||||
|
bne @common_load
|
||||||
|
|
||||||
|
lda #$00 ; end of file
|
||||||
|
sec
|
||||||
|
rts
|
||||||
|
|
||||||
|
@common_load:
|
||||||
|
|
||||||
|
sta PAR_TRACK
|
||||||
|
stx PAR_SECTOR
|
||||||
|
|
||||||
|
; FALLTROUGH
|
||||||
|
|
||||||
|
fs_cbm_nextfileblock_got_ts:
|
||||||
|
|
||||||
|
; Load next track/sector
|
||||||
|
|
||||||
|
jsr lowlevel_readsector ; XXX handle read errors
|
||||||
|
|
||||||
|
; Store pointer and amount of data ready to fetch
|
||||||
|
|
||||||
|
lda #$FE
|
||||||
|
sta FD_ACPTR_LEN+0
|
||||||
|
lda #$00
|
||||||
|
sta FD_ACPTR_LEN+1
|
||||||
|
|
||||||
|
lda #$02
|
||||||
|
sta FD_ACPTR_PTR+0
|
||||||
|
lda #>SHARED_BUF_1
|
||||||
|
sta FD_ACPTR_PTR+1
|
||||||
|
|
||||||
|
lda PAR_SECTOR
|
||||||
|
and #$01
|
||||||
|
bne @part_2
|
||||||
|
|
||||||
|
@part_1:
|
||||||
|
|
||||||
|
; Sector with data is located in the 1st half of the buffer
|
||||||
|
|
||||||
|
lda SHARED_BUF_1+0
|
||||||
|
beq @exit
|
||||||
|
|
||||||
|
; Less than a full sector is used
|
||||||
|
|
||||||
|
lda SHARED_BUF_1+1
|
||||||
|
bra @not_full_buf
|
||||||
|
|
||||||
|
@part_2:
|
||||||
|
|
||||||
|
; Sector with data is located in the 2nd half of the buffer
|
||||||
|
|
||||||
|
inc FD_ACPTR_PTR+1
|
||||||
|
|
||||||
|
lda SHARED_BUF_1+$100+0
|
||||||
|
beq @exit
|
||||||
|
|
||||||
|
; Less than a full sector is used
|
||||||
|
|
||||||
|
lda SHARED_BUF_1+$100+0
|
||||||
|
|
||||||
|
@not_full_buf:
|
||||||
|
|
||||||
|
sta FD_ACPTR_LEN+0
|
||||||
|
|
||||||
|
; FALLTROUGH
|
||||||
|
|
||||||
|
@exit:
|
||||||
|
|
||||||
|
clc
|
||||||
|
rts
|
||||||
@@ -58,100 +58,7 @@ fs_cbm_read_file_open:
|
|||||||
lda FD_LOADSECTOR
|
lda FD_LOADSECTOR
|
||||||
sta PAR_SECTOR
|
sta PAR_SECTOR
|
||||||
|
|
||||||
bra fs_cbm_read_file_got_ts
|
jmp fs_cbm_nextfileblock_got_ts
|
||||||
|
|
||||||
fs_cbm_read_file:
|
|
||||||
|
|
||||||
; Fetch the next track/sector
|
|
||||||
|
|
||||||
lda PAR_SECTOR
|
|
||||||
and #$01
|
|
||||||
bne @part_2
|
|
||||||
|
|
||||||
@part_1:
|
|
||||||
|
|
||||||
; We were reading from the 1st half of the buffer
|
|
||||||
|
|
||||||
ldx SHARED_BUF_1+1
|
|
||||||
lda SHARED_BUF_1+0
|
|
||||||
bra @common_chk
|
|
||||||
|
|
||||||
@part_2:
|
|
||||||
|
|
||||||
; We were reading from the 2nd half of the buffer
|
|
||||||
|
|
||||||
ldx SHARED_BUF_1+$100+1
|
|
||||||
lda SHARED_BUF_1+$100+0
|
|
||||||
|
|
||||||
@common_chk:
|
|
||||||
|
|
||||||
bne @common_load
|
|
||||||
|
|
||||||
lda #$00 ; end of file
|
|
||||||
sec
|
|
||||||
rts
|
|
||||||
|
|
||||||
@common_load:
|
|
||||||
|
|
||||||
sta PAR_TRACK
|
|
||||||
stx PAR_SECTOR
|
|
||||||
|
|
||||||
; FALLTROUGH
|
|
||||||
|
|
||||||
fs_cbm_read_file_got_ts:
|
|
||||||
|
|
||||||
; Load next track/sector
|
|
||||||
|
|
||||||
jsr lowlevel_readsector ; XXX handle read errors
|
|
||||||
|
|
||||||
; Store pointer and amount of data ready to fetch
|
|
||||||
|
|
||||||
lda #$FE
|
|
||||||
sta FD_ACPTR_LEN+0
|
|
||||||
lda #$00
|
|
||||||
sta FD_ACPTR_LEN+1
|
|
||||||
|
|
||||||
lda #$02
|
|
||||||
sta FD_ACPTR_PTR+0
|
|
||||||
lda #>SHARED_BUF_1
|
|
||||||
sta FD_ACPTR_PTR+1
|
|
||||||
|
|
||||||
lda PAR_SECTOR
|
|
||||||
and #$01
|
|
||||||
bne @part_2
|
|
||||||
|
|
||||||
@part_1:
|
|
||||||
|
|
||||||
; Sector with data is located in the 1st half of the buffer
|
|
||||||
|
|
||||||
lda SHARED_BUF_1+0
|
|
||||||
beq @exit
|
|
||||||
|
|
||||||
; Less than a full sector is used
|
|
||||||
|
|
||||||
lda SHARED_BUF_1+1
|
|
||||||
bra @not_full_buf
|
|
||||||
|
|
||||||
@part_2:
|
|
||||||
|
|
||||||
; Sector with data is located in the 2nd half of the buffer
|
|
||||||
|
|
||||||
inc FD_ACPTR_PTR+1
|
|
||||||
|
|
||||||
lda SHARED_BUF_1+$100+0
|
|
||||||
beq @exit
|
|
||||||
|
|
||||||
; Less than a full sector is used
|
|
||||||
|
|
||||||
lda SHARED_BUF_1+$100+0
|
|
||||||
|
|
||||||
@not_full_buf:
|
|
||||||
|
|
||||||
sta FD_ACPTR_LEN+0
|
|
||||||
|
|
||||||
; FALLTROUGH
|
|
||||||
|
|
||||||
@exit:
|
|
||||||
|
|
||||||
clc
|
|
||||||
rts
|
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
;
|
||||||
|
; Hypervisor virtual filesystem - helper routine to get the next file block
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
fs_vfs_nextfileblock:
|
||||||
|
|
||||||
|
; Read chunk of data to SD card buffer
|
||||||
|
|
||||||
|
ldx SD_DESC
|
||||||
|
lda #$1A ; dos_readfile
|
||||||
|
sta HTRAP00
|
||||||
|
+nop
|
||||||
|
|
||||||
|
; XXX check error code
|
||||||
|
|
||||||
|
; Store number of bytes read
|
||||||
|
|
||||||
|
stx SD_ACPTR_LEN+0
|
||||||
|
sty SD_ACPTR_LEN+1
|
||||||
|
|
||||||
|
; Check if any data was read
|
||||||
|
|
||||||
|
tya
|
||||||
|
ora SD_ACPTR_LEN+0
|
||||||
|
bne @copy
|
||||||
|
|
||||||
|
lda #$20 ; dos_closefile
|
||||||
|
sta HTRAP00
|
||||||
|
+nop
|
||||||
|
|
||||||
|
lda #$00
|
||||||
|
sec
|
||||||
|
rts
|
||||||
|
|
||||||
|
@copy:
|
||||||
|
|
||||||
|
; Set pointer to new data
|
||||||
|
|
||||||
|
lda #<SHARED_BUF_0
|
||||||
|
sta SD_ACPTR_PTR+0
|
||||||
|
lda #>SHARED_BUF_0
|
||||||
|
sta SD_ACPTR_PTR+1
|
||||||
|
|
||||||
|
; Copy data to SHARED_BUF_0
|
||||||
|
|
||||||
|
lda #%10000000 ; select SD card buffer
|
||||||
|
tsb SD_BUFCTL
|
||||||
|
|
||||||
|
; Copy data using DMA job
|
||||||
|
|
||||||
|
lda #$00
|
||||||
|
sta DMAJOB_DST_MB
|
||||||
|
lda #<(SHARED_BUF_0 - $8000)
|
||||||
|
sta DMAJOB_DST_ADDR+0
|
||||||
|
lda #>(SHARED_BUF_0 - $8000)
|
||||||
|
sta DMAJOB_DST_ADDR+1
|
||||||
|
lda #$01
|
||||||
|
sta DMAJOB_DST_ADDR+2
|
||||||
|
|
||||||
|
jsr util_dma_launch_from_hwbuf ; execute DMA job
|
||||||
|
|
||||||
|
clc
|
||||||
|
rts
|
||||||
|
|
||||||
|
fs_vfs_file_not_found:
|
||||||
|
|
||||||
|
jsr fs_vfs_direntmem_restore ; restore $1000 memory content
|
||||||
|
|
||||||
|
ldx SD_DESC
|
||||||
|
lda #$16 ; dos_closedir
|
||||||
|
sta HTRAP00
|
||||||
|
+nop
|
||||||
|
|
||||||
|
lda #39 ; file not found error
|
||||||
|
jsr util_status_SD
|
||||||
|
|
||||||
|
lda #K_ERR_FILE_NOT_FOUND
|
||||||
|
jmp dos_EXIT_SEC_A
|
||||||
@@ -62,80 +62,6 @@ fs_vfs_read_file_open:
|
|||||||
lda #$03 ; mode: read file
|
lda #$03 ; mode: read file
|
||||||
sta SD_MODE
|
sta SD_MODE
|
||||||
|
|
||||||
jsr fs_vfs_read_file
|
jsr fs_vfs_nextfileblock
|
||||||
jmp dos_EXIT
|
jmp dos_EXIT
|
||||||
|
|
||||||
fs_vfs_read_file:
|
|
||||||
|
|
||||||
; Read chunk of data to SD card buffer
|
|
||||||
|
|
||||||
ldx SD_DESC
|
|
||||||
lda #$1A ; dos_readfile
|
|
||||||
sta HTRAP00
|
|
||||||
+nop
|
|
||||||
|
|
||||||
; XXX check error code
|
|
||||||
|
|
||||||
; Store number of bytes read
|
|
||||||
|
|
||||||
stx SD_ACPTR_LEN+0
|
|
||||||
sty SD_ACPTR_LEN+1
|
|
||||||
|
|
||||||
; Check if any data was read
|
|
||||||
|
|
||||||
tya
|
|
||||||
ora SD_ACPTR_LEN+0
|
|
||||||
bne @copy
|
|
||||||
|
|
||||||
lda #$20 ; dos_closefile
|
|
||||||
sta HTRAP00
|
|
||||||
+nop
|
|
||||||
|
|
||||||
lda #$00
|
|
||||||
sec
|
|
||||||
rts
|
|
||||||
|
|
||||||
@copy:
|
|
||||||
|
|
||||||
; Set pointer to new data
|
|
||||||
|
|
||||||
lda #<SHARED_BUF_0
|
|
||||||
sta SD_ACPTR_PTR+0
|
|
||||||
lda #>SHARED_BUF_0
|
|
||||||
sta SD_ACPTR_PTR+1
|
|
||||||
|
|
||||||
; Copy data to SHARED_BUF_0
|
|
||||||
|
|
||||||
lda #%10000000 ; select SD card buffer
|
|
||||||
tsb SD_BUFCTL
|
|
||||||
|
|
||||||
; Copy data using DMA job
|
|
||||||
|
|
||||||
lda #$00
|
|
||||||
sta DMAJOB_DST_MB
|
|
||||||
lda #<(SHARED_BUF_0 - $8000)
|
|
||||||
sta DMAJOB_DST_ADDR+0
|
|
||||||
lda #>(SHARED_BUF_0 - $8000)
|
|
||||||
sta DMAJOB_DST_ADDR+1
|
|
||||||
lda #$01
|
|
||||||
sta DMAJOB_DST_ADDR+2
|
|
||||||
|
|
||||||
jsr util_dma_launch_from_hwbuf ; execute DMA job
|
|
||||||
|
|
||||||
clc
|
|
||||||
rts
|
|
||||||
|
|
||||||
fs_vfs_file_not_found:
|
|
||||||
|
|
||||||
jsr fs_vfs_direntmem_restore ; restore $1000 memory content
|
|
||||||
|
|
||||||
ldx SD_DESC
|
|
||||||
lda #$16 ; dos_closedir
|
|
||||||
sta HTRAP00
|
|
||||||
+nop
|
|
||||||
|
|
||||||
lda #39 ; file not found error
|
|
||||||
jsr util_status_SD
|
|
||||||
|
|
||||||
lda #K_ERR_FILE_NOT_FOUND
|
|
||||||
jmp dos_EXIT_SEC_A
|
|
||||||
@@ -8,7 +8,7 @@ unit_fd_cmd_READ:
|
|||||||
|
|
||||||
lda FD_MODE
|
lda FD_MODE
|
||||||
cmp #$03
|
cmp #$03
|
||||||
+beq fs_cbm_read_file
|
+beq fs_cbm_nextfileblock
|
||||||
|
|
||||||
lda FD_DIR_PHASE
|
lda FD_DIR_PHASE
|
||||||
cmp #$01
|
cmp #$01
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ unit_sd_cmd_READ:
|
|||||||
|
|
||||||
lda SD_MODE
|
lda SD_MODE
|
||||||
cmp #$03
|
cmp #$03
|
||||||
+beq fs_vfs_read_file
|
+beq fs_vfs_nextfileblock
|
||||||
|
|
||||||
lda SD_DIR_PHASE
|
lda SD_DIR_PHASE
|
||||||
cmp #$01
|
cmp #$01
|
||||||
|
|||||||
Reference in new issue
Block a user