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, fnisfile, 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 the maximum length, store the character
33 cpx #16 ; Maximum length reached?
35 lda (ptr1),y ; Reload char
36 jsr fnadd ; Add character to name
37 iny ; Next char from name
38 inc tmp1 ; Increment length of name
39 bne nameloop ; Branch always
44 lda #33 ; Invalid file name
46 ; Done, we've successfully parsed the name.
54 ;------------------------------------------------------------------------------
55 ; fnparse: Parse a full filename passed in in a/x. Will set the following
58 ; fnlen -> length of filename
59 ; fnbuf -> filename including drive spec
60 ; fnunit -> unit from spec or default unit
62 ; Returns an error code in A or zero if all is ok.
67 stx ptr1+1 ; Save pointer to name
69 ; For now we will always use the default unit
73 ; Check the name for a drive spec
88 ; We found a drive spec, copy it to the buffer
92 bne drivedone ; Branch always
94 ; We did not find a drive spec, always use drive zero
101 ldy #$00 ; Reposition to start of name
103 ; Drive spec done. We do now have a drive spec in the buffer.
106 lda #2 ; Length of drive spec
109 ; Assume this is a standard file on disk
113 ; Special treatment for directory. If the file name is "$", things are
114 ; actually different: $ is directory for unit 0, $0 dito, $1 is directory
115 ; for unit 1. For simplicity, we won't check anything else if the first
116 ; character of the file name is '$'.
118 lda (ptr1),y ; Get first character
137 ; No need to check the name. Length is already 2
140 sta fnisfile ; This is not a real file
145 ;--------------------------------------------------------------------------
146 ; fndefunit: Use the default unit
156 ;--------------------------------------------------------------------------
157 ; fnset: Tell the kernal about the file name
168 ;--------------------------------------------------------------------------
169 ; fncomplete: Complete a filename by adding ",t,m" where t is the file type
170 ; and m is the access mode passed in in the A register
172 ; fnaddmode: Add ",m" to a filename, where "m" is passed in A
177 jsr fnaddmode ; Add the type
190 ;--------------------------------------------------------------------------
197 fnisfile: .res 1 ; Flags standard file (as opposed to "$")
200 fncmd: .byte 's' ; Use as scratch command
201 fnbuf: .res 35 ; Either 0:0123456789012345,t,m
202 ; Or 0:0123456789012345=0123456789012345