Skip to content

Commit d4e0fcb

Browse files
committed
feat: chdir/getcwd, FAT32 directory flags, and CWD fixes
- Add kernel.Chdir call for changing/querying the current working directory - Populate directory.file.flags with FAT32 attributes byte - Initialize cwd_cluster to root cluster on volume mount - Use unfiltered fat32_read_dirent (hidden filtering moved to userland) - Add _use_cwd path in directory open for empty-path CWD resolution
1 parent ef5ff5c commit d4e0fcb

7 files changed

Lines changed: 531 additions & 14 deletions

File tree

f256/fat32.asm

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ dir_close .fill 3
5252

5353
dir_mkdir .fill 3
5454
dir_rmdir .fill 3
55+
56+
dir_chdir .fill 3
5557
.endn
5658
.endv
5759

@@ -626,9 +628,26 @@ open_dir
626628
sta kernel.stream.entry.state,x
627629

628630
; Open_dir
631+
; Check if buffer starts with null (empty path = use CWD).
629632
jsr terminate_dir
630633
lda kernel.fs.args.buf,y
634+
pha ; save page for set_ptr
635+
sta fname+1
636+
stz fname+0
637+
lda (fname) ; read first byte of path
638+
beq _use_cwd
639+
; Non-empty path: pass to FAT32 library
640+
pla
631641
call fat.set_ptr
642+
bra _do_open
643+
_use_cwd
644+
; Empty path: clear fat32_ptr so library uses CWD
645+
pla ; discard page
646+
inc mmu_ctrl
647+
stz $1a ; fat32_ptr (ZP $1A in FAT32 library space)
648+
stz $1b
649+
dec mmu_ctrl
650+
_do_open
632651
call fat.dir_open
633652
bcc _context
634653

@@ -868,14 +887,13 @@ _done tya
868887

869888
copy_details
870889

871-
; Mount the source
890+
; Mount the source at dirent.attributes (name + $100)
872891
lda fat.dirent+0
873-
clc
874-
adc #5 ; attrs(1) + start(4)
875892
sta kernel.src+0
876893
lda fat.dirent+1
877-
adc #1 ; skip the name
878-
adc #$60 ; $2k there, $8k here.
894+
inc a ; skip the 256-byte name
895+
clc
896+
adc #$60 ; $2k there, $8k here.
879897
sta kernel.src+1
880898

881899
; Mount the dest
@@ -888,7 +906,22 @@ copy_details
888906
; the event queue needs access to user RAM.
889907
lda #7 ; fat32 ram block
890908
sta mmu+4
891-
909+
910+
; Read FAT32 attributes byte and store in event flags
911+
phy
912+
ldy #0
913+
lda (kernel.src),y ; dirent.attributes
914+
ply
915+
sta kernel.event.entry.directory.file.flags,y
916+
917+
; Advance source to size field: skip attrs(1) + start(4)
918+
lda kernel.src+0
919+
clc
920+
adc #5
921+
sta kernel.src+0
922+
bcc +
923+
inc kernel.src+1
924+
+
892925
; Round up the size
893926
phy
894927
ldy #0

fat32/f256jr.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ used: .res 1
5353

5454
jmp fat32_open_dir
5555
jmp fat32_get_vollabel
56-
jmp fat32_read_dirent_filter_hidden
56+
jmp fat32_read_dirent
5757
jmp fat32_get_free_space
5858
jmp fat32_close
5959

6060
jmp fat32_mkdir
6161
jmp fat32_rmdir
6262

63+
jmp fat32_chdir
64+
6365
get_error:
6466
lda fat32_errno
6567
rts

fat32/fat32.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ mount:
12891289

12901290
; Root cluster
12911291
set32 cur_volume + fs::rootdir_cluster, sector_buffer + 44
1292+
set32 cur_volume + fs::cwd_cluster, sector_buffer + 44
12921293

12931294
; Calculate LBA of first FAT
12941295
add32_16 cur_volume + fs::lba_fat, cur_volume + fs::lba_partition, sector_buffer + 14

kernel/api.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Yield .fill 4 ; Give unused time to the kernel.
2121
Putch .fill 4 ; deprecated
2222
RunBlock .fill 4 ; Chain to resident program by block ID.
2323
RunNamed .fill 4 ; Chain to resident program by name.
24-
.fill 4 ; reserved
24+
Chdir .fill 4 ; Change/get current working directory.
2525

2626
BlockDevice .namespace
2727
List .fill 4 ; Returns a bit-set of available block-accessible devices.

0 commit comments

Comments
 (0)