diff --git a/src/dos_m65/filesystem_cbm/fs_cbm_nextdirentry.s b/src/dos_m65/filesystem_cbm/fs_cbm_nextdirentry.s index 20080bb2..c6734b2f 100644 --- a/src/dos_m65/filesystem_cbm/fs_cbm_nextdirentry.s +++ b/src/dos_m65/filesystem_cbm/fs_cbm_nextdirentry.s @@ -49,7 +49,14 @@ fs_cbm_nextdirentry: ; XXX most likely copying is not necessary (compare all CBM and CMD filesystems) - ; XXX just make the hypervisor file system emulate these structures - ldy #$02 ; start from determining file type + ldy #$00 ; start from getting track and sector of file beginning + jsr code_LDA_nnnn_Y + sta FD_LOADTRACK + iny + jsr code_LDA_nnnn_Y + sta FD_LOADSECTOR + + iny ; determining file type jsr code_LDA_nnnn_Y beq fs_cbm_nextdirentry ; ignore deleted files (but allow DEL files in some cases) diff --git a/src/dos_m65/filesystem_cbm/fs_cbm_read_file.s b/src/dos_m65/filesystem_cbm/fs_cbm_read_file.s index 9f7e22bc..e22d3ae6 100644 --- a/src/dos_m65/filesystem_cbm/fs_cbm_read_file.s +++ b/src/dos_m65/filesystem_cbm/fs_cbm_read_file.s @@ -48,19 +48,108 @@ fs_cbm_read_file_open: jsr util_dir_filter bne @lp_find ; if does not match, try the next entry - ; Found the file - load it, start from fetching initial track/sector + ; Found the file, load it - inc $D020 + lda FD_LOADTRACK + sta PAR_TRACK + lda FD_LOADSECTOR + sta PAR_SECTOR - - - - ; XXX provide implementation, use FD_LOADTRACK and FD_LOADSECTOR - - jmp dos_EXIT_SEC + bra fs_cbm_read_file_got_ts fs_cbm_read_file: - ; XXX provide implementation + ; Fetch the next track/sector - jmp dos_EXIT_SEC + lda FD_LOADSECTOR + and #$01 + bne @part_2 + +@part_1: + + ; We were reading from the 1st half of the buffer + + lda SHARED_BUF_1+1 + sta PAR_SECTOR + lda SHARED_BUF_1+0 + bra @common_chk + +@part_2: + + ; We were reading from the 2nd half of the buffer + + lda SHARED_BUF_1+$100+1 + sta PAR_SECTOR + lda SHARED_BUF_1+$100+0 + +@common_chk: + + bne @common_load + + lda #$00 ; end of file + sec + rts + +@common_load: + + sta PAR_TRACK + + ; 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