2 ; Ullrich von Bassewitz, 16.11.2002
4 ; File name handling for CBM file I/O
7 .export fnparse, fnparsename, fnset
8 .export fnadd, fnaddmode, fncomplete, fndefunit
9 .export fnunit, fnlen, fncmd, fnbuf
12 .import __curunit, __filetype
18 ;------------------------------------------------------------------------------
19 ; fnparsename: Parse a filename (without drive spec) passed in in ptr1 and y.
24 sta tmp1 ; Remember length of name
27 lda (ptr1),y ; Get next char from filename
28 beq namedone ; Jump if end of name reached
30 ; Check for valid chars in the file name. We allow letters, digits, plus some
31 ; additional chars from a table.
44 ; Check the maximum length, store the character
47 cpx #16 ; Maximum length reached?
49 lda (ptr1),y ; Reload char
50 jsr fnadd ; Add character to name
51 iny ; Next char from name
52 inc tmp1 ; Increment length of name
53 bne nameloop ; Branch always
58 lda #33 ; Invalid file name
60 ; Done, we've successfully parsed the name.
68 ;------------------------------------------------------------------------------
69 ; fnparse: Parse a full filename passed in in a/x. Will set the following
72 ; fnlen -> length of filename
73 ; fnbuf -> filename including drive spec
74 ; fnunit -> unit from spec or default unit
76 ; Returns an error code in A or zero if all is ok.
81 stx ptr1+1 ; Save pointer to name
83 ; For now we will always use the default unit
87 ; Check the name for a drive spec
102 ; We found a drive spec, copy it to the buffer
106 bne drivedone ; Branch always
108 ; We did not find a drive spec, always use drive zero
115 ldy #$00 ; Reposition to start of name
117 ; Drive spec done. We do now have a drive spec in the buffer.
120 lda #2 ; Length of drive spec
123 ; Copy the name into the file name buffer. The subroutine returns an error
124 ; code in A and zero flag set if the were no errors.
130 ;--------------------------------------------------------------------------
131 ; fndefunit: Use the default unit
141 ;--------------------------------------------------------------------------
142 ; fnset: Tell the kernal about the file name
153 ;--------------------------------------------------------------------------
154 ; fncomplete: Complete a filename by adding ",t,m" where t is the file type
155 ; and m is the access mode passed in in the A register
157 ; fnaddmode: Add ",m" to a filename, where "m" is passed in A
161 jsr fnaddcomma ; Add a comma
163 jsr fnadd ; Add the type
179 ;--------------------------------------------------------------------------
188 fncmd: .byte 's' ; Use as scratch command
189 fnbuf: .res 35 ; Either 0:0123456789012345,t,m
190 ; Or 0:0123456789012345=0123456789012345
192 ; Characters that are ok in filenames besides digits and letters
193 fnchars:.byte ".,-_+()"
194 fncharcount = *-fnchars