2002-11-16 23:45:15 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 16.11.2002
|
|
|
|
;
|
|
|
|
; File name handling for CBM file I/O
|
|
|
|
;
|
|
|
|
|
2009-02-22 14:11:34 +00:00
|
|
|
.export fnparse, fnparsename, fnset
|
|
|
|
.export fnadd, fnaddmode, fncomplete, fndefunit
|
2012-05-29 20:52:18 +00:00
|
|
|
.export fnunit, fnlen, fnisfile, fncmd, fnbuf
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2012-10-16 21:39:40 +00:00
|
|
|
.import curunit, __filetype
|
2009-02-22 14:06:12 +00:00
|
|
|
.importzp ptr1, tmp1
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.include "ctype.inc"
|
2018-07-03 19:47:42 +00:00
|
|
|
.include "cbm.inc"
|
2009-02-22 14:11:34 +00:00
|
|
|
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2009-02-22 14:06:12 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; fnparsename: Parse a filename (without drive spec) passed in in ptr1 and y.
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2009-02-22 14:06:12 +00:00
|
|
|
.proc fnparsename
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
sta tmp1 ; Remember length of name
|
|
|
|
|
|
|
|
nameloop:
|
|
|
|
lda (ptr1),y ; Get next char from filename
|
|
|
|
beq namedone ; Jump if end of name reached
|
|
|
|
|
|
|
|
; Check the maximum length, store the character
|
|
|
|
|
2010-11-15 21:50:58 +00:00
|
|
|
ldx tmp1
|
2009-02-22 14:06:12 +00:00
|
|
|
cpx #16 ; Maximum length reached?
|
|
|
|
bcs invalidname
|
|
|
|
lda (ptr1),y ; Reload char
|
|
|
|
jsr fnadd ; Add character to name
|
|
|
|
iny ; Next char from name
|
|
|
|
inc tmp1 ; Increment length of name
|
|
|
|
bne nameloop ; Branch always
|
|
|
|
|
|
|
|
; Invalid file name
|
|
|
|
|
|
|
|
invalidname:
|
|
|
|
lda #33 ; Invalid file name
|
|
|
|
|
|
|
|
; Done, we've successfully parsed the name.
|
|
|
|
|
|
|
|
namedone:
|
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; fnparse: Parse a full filename passed in in a/x. Will set the following
|
2002-11-16 23:45:15 +00:00
|
|
|
; variables:
|
|
|
|
;
|
|
|
|
; fnlen -> length of filename
|
|
|
|
; fnbuf -> filename including drive spec
|
|
|
|
; fnunit -> unit from spec or default unit
|
2008-04-13 14:49:16 +00:00
|
|
|
;
|
|
|
|
; Returns an error code in A or zero if all is ok.
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.proc fnparse
|
|
|
|
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1 ; Save pointer to name
|
|
|
|
|
2008-04-13 14:49:16 +00:00
|
|
|
; For now we will always use the default unit
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2008-04-13 14:49:16 +00:00
|
|
|
jsr fndefunit
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
; Check the name for a drive spec
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
lda (ptr1),y
|
|
|
|
cmp #'0'
|
|
|
|
beq digit
|
|
|
|
cmp #'1'
|
|
|
|
bne nodrive
|
|
|
|
|
2009-02-22 14:06:12 +00:00
|
|
|
digit: sta fnbuf+0
|
|
|
|
iny
|
2002-11-16 23:45:15 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
cmp #':'
|
|
|
|
bne nodrive
|
|
|
|
|
|
|
|
; We found a drive spec, copy it to the buffer
|
|
|
|
|
|
|
|
sta fnbuf+1
|
|
|
|
iny ; Skip colon
|
|
|
|
bne drivedone ; Branch always
|
|
|
|
|
|
|
|
; We did not find a drive spec, always use drive zero
|
|
|
|
|
|
|
|
nodrive:
|
|
|
|
lda #'0'
|
|
|
|
sta fnbuf+0
|
|
|
|
lda #':'
|
|
|
|
sta fnbuf+1
|
|
|
|
ldy #$00 ; Reposition to start of name
|
|
|
|
|
2009-02-22 14:06:12 +00:00
|
|
|
; Drive spec done. We do now have a drive spec in the buffer.
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
drivedone:
|
|
|
|
lda #2 ; Length of drive spec
|
|
|
|
sta fnlen
|
|
|
|
|
2012-05-29 20:52:18 +00:00
|
|
|
; Assume this is a standard file on disk
|
2002-11-18 19:37:02 +00:00
|
|
|
|
2012-05-29 20:52:18 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
; Juggle stuff
|
|
|
|
|
|
|
|
ldx fnbuf+0 ; unit
|
|
|
|
stx fnbuf+1
|
|
|
|
sta fnbuf+0
|
|
|
|
|
2012-08-06 18:45:26 +00:00
|
|
|
; Add the file mask
|
|
|
|
|
|
|
|
lda #':'
|
|
|
|
sta fnbuf+2
|
|
|
|
lda #'*'
|
|
|
|
sta fnbuf+3
|
|
|
|
lda #4
|
|
|
|
sta fnlen
|
|
|
|
|
2012-05-29 20:52:18 +00:00
|
|
|
; No need to check the name. Length is already 2
|
|
|
|
|
|
|
|
lda #0 ; ok flag
|
|
|
|
sta fnisfile ; This is not a real file
|
|
|
|
rts
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
2008-04-13 14:49:16 +00:00
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; fndefunit: Use the default unit
|
|
|
|
|
|
|
|
.proc fndefunit
|
|
|
|
|
2012-10-16 21:39:40 +00:00
|
|
|
lda curunit
|
2008-04-13 14:49:16 +00:00
|
|
|
sta fnunit
|
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; fnset: Tell the kernal about the file name
|
|
|
|
|
|
|
|
.proc fnset
|
|
|
|
|
|
|
|
lda fnlen
|
|
|
|
ldx #<fnbuf
|
|
|
|
ldy #>fnbuf
|
|
|
|
jmp SETNAM
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; 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
|
2003-03-13 23:09:53 +00:00
|
|
|
;
|
|
|
|
; fnaddmode: Add ",m" to a filename, where "m" is passed in A
|
2002-11-16 23:45:15 +00:00
|
|
|
|
2003-03-13 23:09:53 +00:00
|
|
|
fncomplete:
|
2013-05-09 11:56:54 +00:00
|
|
|
pha ; Save mode
|
2003-03-13 23:09:53 +00:00
|
|
|
lda __filetype
|
2012-01-01 20:03:33 +00:00
|
|
|
jsr fnaddmode ; Add the type
|
2003-03-13 23:09:53 +00:00
|
|
|
pla
|
|
|
|
fnaddmode:
|
|
|
|
pha
|
2012-01-01 20:03:33 +00:00
|
|
|
lda #','
|
|
|
|
jsr fnadd
|
2003-03-13 23:09:53 +00:00
|
|
|
pla
|
|
|
|
|
|
|
|
fnadd: ldx fnlen
|
|
|
|
inc fnlen
|
|
|
|
sta fnbuf,x
|
|
|
|
rts
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; Data
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
2012-05-29 20:52:18 +00:00
|
|
|
fnunit: .res 1
|
|
|
|
fnlen: .res 1
|
|
|
|
fnisfile: .res 1 ; Flags standard file (as opposed to "$")
|
2002-11-16 23:45:15 +00:00
|
|
|
|
|
|
|
.data
|
2012-05-29 20:52:18 +00:00
|
|
|
fncmd: .byte 's' ; Use as scratch command
|
|
|
|
fnbuf: .res 35 ; Either 0:0123456789012345,t,m
|
|
|
|
; Or 0:0123456789012345=0123456789012345
|