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 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 ; Copy the name into the file name buffer. The subroutine returns an error
110 ; code in A and zero flag set if the were no errors.
116 ;--------------------------------------------------------------------------
117 ; fndefunit: Use the default unit
127 ;--------------------------------------------------------------------------
128 ; fnset: Tell the kernal about the file name
139 ;--------------------------------------------------------------------------
140 ; fncomplete: Complete a filename by adding ",t,m" where t is the file type
141 ; and m is the access mode passed in in the A register
143 ; fnaddmode: Add ",m" to a filename, where "m" is passed in A
148 jsr fnaddmode ; Add the type
161 ;--------------------------------------------------------------------------
170 fncmd: .byte 's' ; Use as scratch command
171 fnbuf: .res 35 ; Either 0:0123456789012345,t,m
172 ; Or 0:0123456789012345=0123456789012345