; File name handling for CBM file I/O
;
- .export fnparse, fnset, fnaddmode, fncomplete, fndefunit
- .export fnunit, fnlen, fncmd, fnbuf
+ .export fnparse, fnparsename, fnset
+ .export fnadd, fnaddmode, fncomplete, fndefunit
+ .export fnunit, fnlen, fnisfile, fncmd, fnbuf
- .import SETNAM
- .import __curunit, __filetype
+ .import curunit, __filetype
.importzp ptr1, tmp1
.include "ctype.inc"
-
+ .include "cbm.inc"
+
;------------------------------------------------------------------------------
; fnparsename: Parse a filename (without drive spec) passed in in ptr1 and y.
lda (ptr1),y ; Get next char from filename
beq namedone ; Jump if end of name reached
-; Check for valid chars in the file name. We allow letters, digits, plus some
-; additional chars from a table.
-
- ldx #fncharcount-1
-namecheck:
- cmp fnchars,x
- beq nameok
- dex
- bpl namecheck
- tax
- lda __ctype,x
- and #CT_ALNUM
- beq invalidname
-
; Check the maximum length, store the character
-nameok: ldx tmp1
+ ldx tmp1
cpx #16 ; Maximum length reached?
bcs invalidname
lda (ptr1),y ; Reload char
lda #2 ; Length of drive spec
sta fnlen
-; Copy the name into the file name buffer. The subroutine returns an error
-; code in A and zero flag set if the were no errors.
+; Assume this is a standard file on disk
+
+ sta fnisfile
+
+; Special treatment for directory. If the file name is "$", things are
+; actually different: $ is directory for unit 0, $0 dito, $1 is directory
+; for unit 1. For simplicity, we won't check anything else if the first
+; character of the file name is '$'.
+
+ lda (ptr1),y ; Get first character
+ cmp #'$' ;
+ bne fnparsename
- jmp fnparsename
+; Juggle stuff
+
+ ldx fnbuf+0 ; unit
+ stx fnbuf+1
+ sta fnbuf+0
+
+; Add the file mask
+
+ lda #':'
+ sta fnbuf+2
+ lda #'*'
+ sta fnbuf+3
+ lda #4
+ sta fnlen
+
+; No need to check the name. Length is already 2
+
+ lda #0 ; ok flag
+ sta fnisfile ; This is not a real file
+ rts
.endproc
.proc fndefunit
- lda __curunit
+ lda curunit
sta fnunit
rts
; fnaddmode: Add ",m" to a filename, where "m" is passed in A
fncomplete:
- pha ; Save mode
- jsr fnaddcomma ; Add a comma
+ pha ; Save mode
lda __filetype
- jsr fnadd ; Add the type
+ jsr fnaddmode ; Add the type
pla
fnaddmode:
pha
- jsr fnaddcomma
+ lda #','
+ jsr fnadd
pla
fnadd: ldx fnlen
sta fnbuf,x
rts
-fnaddcomma:
- lda #','
- bne fnadd
-
;--------------------------------------------------------------------------
; Data
.bss
-fnunit: .res 1
-fnlen: .res 1
+fnunit: .res 1
+fnlen: .res 1
+fnisfile: .res 1 ; Flags standard file (as opposed to "$")
.data
-fncmd: .byte 's' ; Use as scratch command
-fnbuf: .res 35 ; Either 0:0123456789012345,t,m
- ; Or 0:0123456789012345=0123456789012345
-.rodata
-; Characters that are ok in filenames besides digits and letters
-fnchars:.byte ".,-_+()"
-fncharcount = *-fnchars
-
-
-
+fncmd: .byte 's' ; Use as scratch command
+fnbuf: .res 35 ; Either 0:0123456789012345,t,m
+ ; Or 0:0123456789012345=0123456789012345