; File name handling for CBM file I/O
;
- .export fnparse, fnset, fncomplete
+ .export fnparse, fnset, fnaddmode, fncomplete
.export fnunit, fnlen, fncmd, fnbuf
.import SETNAM
cpx #18 ; Maximum length reached?
bcs invalidname
lda (ptr1),y ; Reload char
- sta fnbuf,x ; Store into buffer
- inc fnlen ; Count characters
+ jsr fnadd ; Add character to name
iny ; Next char from name
bne nameloop ; Branch always
;--------------------------------------------------------------------------
; fncomplete: Complete a filename by adding ",t,m" where t is the file type
; and m is the access mode passed in in the A register
+;
+; fnaddmode: Add ",m" to a filename, where "m" is passed in A
-.proc fncomplete
-
+fncomplete:
pha ; Save mode
- ldx fnlen
- lda #','
- sta fnbuf,x
- inx
- lda __filetype
- sta fnbuf,x
- inx
- lda #','
- sta fnbuf,x
- inx
- pla
- sta fnbuf,x
- inx
- stx fnlen
- rts
+ jsr fnaddcomma ; Add a comma
+ lda __filetype
+ jsr fnadd ; Add the type
+ pla
+fnaddmode:
+ pha
+ jsr fnaddcomma
+ pla
+
+fnadd: ldx fnlen
+ inc fnlen
+ sta fnbuf,x
+ rts
-.endproc
+fnaddcomma:
+ lda #','
+ bne fnadd
;--------------------------------------------------------------------------
; Data
fncharcount = *-fnchars
-
+
.import SETLFS, OPEN, CLOSE
.import addysp, popax
- .import scratch, fnparse, fncomplete, fnset
+ .import scratch, fnparse, fnaddmode, fncomplete, fnset
.import opencmdchannel, closecmdchannel, readdiskerror
.import __oserror
.import fnunit
bne append ; Branch if yes
ldx #'w'
append: txa
- jsr fncomplete
+ jsr fncomplete ; Add type and mode to the name
; Setup the real open flags
; Read bit is set. Add an 'r' to the name
doread: lda #'r'
- jsr fncomplete
+ jsr fnaddmode ; Add the mode to the name
lda #LFN_READ
; Common read/write code. Flags in A, handle in tmp2