2 ; Ullrich von Bassewitz, 16.11.2002
4 ; File name handling for CBM file I/O
7 .export fnparse, fnset, fnaddmode, fncomplete, fndefunit
8 .export fnunit, fnlen, fncmd, fnbuf
11 .import __curunit, __filetype
17 ;------------------------------------------------------------------------------
18 ; fnparsename: Parse a filename (without drive spec) passed in in ptr1 and y.
23 sta tmp1 ; Remember length of name
26 lda (ptr1),y ; Get next char from filename
27 beq namedone ; Jump if end of name reached
29 ; Check for valid chars in the file name. We allow letters, digits, plus some
30 ; additional chars from a table.
43 ; Check the maximum length, store the character
46 cpx #16 ; Maximum length reached?
48 lda (ptr1),y ; Reload char
49 jsr fnadd ; Add character to name
50 iny ; Next char from name
51 inc tmp1 ; Increment length of name
52 bne nameloop ; Branch always
57 lda #33 ; Invalid file name
59 ; Done, we've successfully parsed the name.
67 ;------------------------------------------------------------------------------
68 ; fnparse: Parse a full filename passed in in a/x. Will set the following
71 ; fnlen -> length of filename
72 ; fnbuf -> filename including drive spec
73 ; fnunit -> unit from spec or default unit
75 ; Returns an error code in A or zero if all is ok.
80 stx ptr1+1 ; Save pointer to name
82 ; For now we will always use the default unit
86 ; Check the name for a drive spec
101 ; We found a drive spec, copy it to the buffer
105 bne drivedone ; Branch always
107 ; We did not find a drive spec, always use drive zero
114 ldy #$00 ; Reposition to start of name
116 ; Drive spec done. We do now have a drive spec in the buffer.
119 lda #2 ; Length of drive spec
122 ; Copy the name into the file name buffer. The subroutine returns an error
123 ; code in A and zero flag set if the were no errors.
129 ;--------------------------------------------------------------------------
130 ; fndefunit: Use the default unit
140 ;--------------------------------------------------------------------------
141 ; fnset: Tell the kernal about the file name
152 ;--------------------------------------------------------------------------
153 ; fncomplete: Complete a filename by adding ",t,m" where t is the file type
154 ; and m is the access mode passed in in the A register
156 ; fnaddmode: Add ",m" to a filename, where "m" is passed in A
160 jsr fnaddcomma ; Add a comma
162 jsr fnadd ; Add the type
178 ;--------------------------------------------------------------------------
187 fncmd: .byte 's' ; Use as scratch command
188 fnbuf: .res 35 ; Either 0:0123456789012345,t,m
189 ; Or 0:0123456789012345=0123456789012345
191 ; Characters that are ok in filenames besides digits and letters
192 fnchars:.byte ".,-_+()"
193 fncharcount = *-fnchars