2 ; Ullrich von Bassewitz, 16.11.2002
4 ; File name handling for CBM file I/O
7 .export fnparse, fnset, fncomplete
8 .export fnunit, fnlen, fncmd, fnbuf
10 .import __curunit, __filetype
17 ;--------------------------------------------------------------------------
18 ; fnparse: Parse a filename passed in in a/x. Will set the following
21 ; fnlen -> length of filename
22 ; fnbuf -> filename including drive spec
23 ; fnunit -> unit from spec or default unit
29 stx ptr1+1 ; Save pointer to name
31 ; For now we're always using the default unit
36 ; Check the name for a drive spec
51 ; We found a drive spec, copy it to the buffer
55 bne drivedone ; Branch always
57 ; We did not find a drive spec, always use drive zero
64 ldy #$00 ; Reposition to start of name
66 ; Drive spec done. Copy the name into the file name buffer. Check that all
67 ; file name characters are valid and that the maximum length is not exceeded.
70 lda #2 ; Length of drive spec
74 lda (ptr1),y ; Get next char from filename
75 beq namedone ; Jump if end of name reached
77 ; Check for valid chars in the file name. We allow letters, digits, plus some
78 ; additional chars from a table.
91 ; Check the maximum length, store the character
94 cpx #16 ; Maximum length reached?
96 lda (ptr1),y ; Reload char
97 sta fnbuf,x ; Store into buffer
98 inc fnlen ; Count characters
99 iny ; Next char from name
100 bne nameloop ; Branch always
105 lda #33 ; Invalid file name
107 ; Done, we've successfully parsed the name.
115 ;--------------------------------------------------------------------------
116 ; fnset: Tell the kernal about the file name
127 ;--------------------------------------------------------------------------
128 ; fncomplete: Complete a filename by adding ",t,m" where t is the file type
129 ; and m is the access mode passed in in the A register
152 ;--------------------------------------------------------------------------
161 fncmd: .byte 's' ; Use as scratch command
162 fnbuf: .res 22 ; 0:0123456789012345,t,m
165 ; Characters that are ok in filenames besides digits and letters
166 fnchars:.byte ".,-_+()"
167 fncharcount = *-fnchars