2021-09-07 02:28:07 +00:00
|
|
|
* MAINMEM.PATH.S
|
|
|
|
* (c) Bobbi 2021 GPLv3
|
|
|
|
*
|
|
|
|
* Code for handling Applecorn paths and converting them to
|
|
|
|
* ProDOS paths. Runs in main memory.
|
2021-11-04 02:55:05 +00:00
|
|
|
* TO DO: check range in :sd
|
2021-11-04 22:59:04 +00:00
|
|
|
* TO DO: need separate reference to current root and drive by name
|
|
|
|
* TO DO: check for pathname too long
|
|
|
|
* ie /filename should be filename in root
|
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
|
2021-09-17 20:17:49 +00:00
|
|
|
* Preprocess path in MOSFILE, handles:
|
|
|
|
* 1) ':sd' type slot and drive prefix (s,d are digits)
|
|
|
|
* 2) '.' or '@' for current working directory
|
|
|
|
* 3) '..' or '^' for parent directory
|
2021-09-07 02:28:07 +00:00
|
|
|
* Carry set on error, clear otherwise
|
|
|
|
PREPATH LDX MOSFILE ; Length
|
2021-09-17 21:29:36 +00:00
|
|
|
BNE :S1
|
|
|
|
JMP :EXIT ; If zero length
|
|
|
|
:S1 LDA MOSFILE+1 ; 1st char of pathname
|
2021-09-17 20:45:52 +00:00
|
|
|
CMP #':'
|
2021-09-07 02:28:07 +00:00
|
|
|
BNE :NOTCOLN ; Not colon
|
|
|
|
CPX #$03 ; Length >= 3?
|
2021-09-17 21:29:36 +00:00
|
|
|
BCS :S2
|
|
|
|
JMP :ERR ; If not
|
|
|
|
:S2 LDA MOSFILE+3 ; Drive
|
2021-09-07 02:28:07 +00:00
|
|
|
SEC
|
|
|
|
SBC #'1'
|
|
|
|
TAX
|
|
|
|
LDA MOSFILE+2 ; Slot
|
|
|
|
SEC
|
|
|
|
SBC #'0'
|
|
|
|
JSR DRV2PFX ; Slot/drv->pfx in PREFIX
|
|
|
|
JSR DEL1CHAR ; Delete ':' from MOSFILE
|
|
|
|
JSR DEL1CHAR ; Delete slot from MOSFILE
|
|
|
|
JSR DEL1CHAR ; Delete drive from MOSFILE
|
|
|
|
LDA MOSFILE ; Is there more?
|
|
|
|
BEQ :APPEND ; Only ':sd'
|
|
|
|
CMP #$02 ; Length >= 2
|
|
|
|
BCC :ERR ; If not
|
|
|
|
LDA MOSFILE+1 ; 1st char of filename
|
2021-09-17 20:17:49 +00:00
|
|
|
CMP #'/'
|
2021-09-07 02:28:07 +00:00
|
|
|
BNE :ERR
|
|
|
|
JSR DEL1CHAR ; Delete '/' from MOSFILE
|
|
|
|
BRA :APPEND
|
|
|
|
:NOTCOLN JSR GETPREF ; Current pfx -> PREFIX
|
|
|
|
:REENTER LDA MOSFILE+1 ; First char of dirname
|
2021-09-17 20:23:54 +00:00
|
|
|
CMP #'@' ; '@' means current working dir
|
2021-09-17 21:51:11 +00:00
|
|
|
BEQ :CWD
|
2021-09-17 20:23:54 +00:00
|
|
|
CMP #'^' ; '^' means parent dir
|
|
|
|
BEQ :CARET
|
2021-09-17 20:17:49 +00:00
|
|
|
CMP #'/' ; Absolute path
|
2021-09-17 20:07:59 +00:00
|
|
|
BEQ :EXIT ; Nothing to do
|
2021-09-17 20:23:54 +00:00
|
|
|
CMP #'.' ; ...
|
|
|
|
BEQ :UPDIR1
|
2021-09-17 20:07:59 +00:00
|
|
|
BRA :APPEND
|
2021-09-17 21:29:36 +00:00
|
|
|
:UPDIR1 LDA MOSFILE ; Length
|
|
|
|
CMP #$01
|
|
|
|
BEQ :CWD ; '.' on its own
|
|
|
|
LDA MOSFILE+2
|
2021-09-07 02:28:07 +00:00
|
|
|
CMP #'.' ; '..'
|
2021-09-17 21:29:36 +00:00
|
|
|
BEQ :DOTDOT
|
|
|
|
CMP #'/' ; './'
|
|
|
|
BEQ :CWD
|
|
|
|
BRA :ERR
|
|
|
|
:DOTDOT JSR DEL1CHAR ; Delete first char of MOSFILE
|
2021-09-17 20:23:54 +00:00
|
|
|
:CARET JSR PARENT ; Parent dir -> PREFIX
|
|
|
|
:CWD JSR DEL1CHAR ; Delete first char of MOSFILE
|
2021-09-17 19:46:26 +00:00
|
|
|
LDA MOSFILE ; Is there more?
|
2021-09-17 20:17:49 +00:00
|
|
|
BEQ :APPEND ; No more
|
2021-09-07 02:28:07 +00:00
|
|
|
CMP #$02 ; Len at least two?
|
2021-09-17 20:17:49 +00:00
|
|
|
BCC :ERR ; Too short!
|
2021-09-07 02:28:07 +00:00
|
|
|
LDA MOSFILE+1 ; What is next char?
|
2021-09-17 20:45:52 +00:00
|
|
|
CMP #'/' ; Is it slash?
|
2021-09-07 02:28:07 +00:00
|
|
|
BNE :ERR ; Nope!
|
|
|
|
JSR DEL1CHAR ; Delete '/' from MOSFILE
|
|
|
|
BRA :REENTER ; Go again!
|
|
|
|
:APPEND JSR APFXMF ; Append MOSFILE->PREFIX
|
2021-09-15 04:02:08 +00:00
|
|
|
JSR PFXtoMF ; Copy back to MOSFILE
|
2021-09-07 02:28:07 +00:00
|
|
|
:EXIT JSR DIGCONV ; Handle initial digits
|
2022-09-17 19:19:55 +00:00
|
|
|
JSR USCONV ; Handle any underscores
|
2021-09-07 02:28:07 +00:00
|
|
|
CLC
|
|
|
|
RTS
|
2021-10-12 15:12:03 +00:00
|
|
|
:ERR LDA #$40 ; $40=Bad filename
|
|
|
|
SEC
|
2021-09-07 02:28:07 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
* Convert path in PREFIX by removing leaf dir to leave
|
|
|
|
* parent directory. If already at top, return unchanged.
|
|
|
|
PARENT LDX PREFIX ; Length of string
|
|
|
|
BEQ :EXIT ; Prefix len zero
|
|
|
|
DEX ; Ignore trailing '/'
|
|
|
|
:L1 LDA PREFIX,X
|
2021-09-17 20:45:52 +00:00
|
|
|
CMP #'/'
|
2021-09-07 02:28:07 +00:00
|
|
|
BEQ :FOUND
|
|
|
|
DEX
|
|
|
|
CPX #$01
|
|
|
|
BNE :L1
|
|
|
|
BRA :EXIT ; No slash found
|
|
|
|
:FOUND STX PREFIX ; Truncate string
|
|
|
|
:EXIT RTS
|
|
|
|
|
|
|
|
* Convert slot/drive to prefix
|
|
|
|
* Expect slot number (1..7) in A, drive (0..1) in X
|
|
|
|
* Puts prefix (or empty string) in PREFIX
|
|
|
|
DRV2PFX CLC ; Cy=0 A=00000sss
|
|
|
|
ROR A ; s 000000ss
|
|
|
|
ROR A ; s s000000s
|
|
|
|
ROR A ; s ss000000
|
|
|
|
ROR A ; 0 sss00000
|
|
|
|
CPX #1 ; d sss00000
|
|
|
|
ROR A ; 0 dsss0000
|
|
|
|
|
|
|
|
STA ONLNPL+1 ; Device number
|
|
|
|
JSR MLI ; Call ON_LINE
|
|
|
|
DB ONLNCMD
|
|
|
|
DW ONLNPL ; Buffer set to DRVBUF2 (was $301)
|
|
|
|
LDA DRVBUF2 ; Slot/Drive/Length
|
|
|
|
AND #$0F ; Mask to get length
|
|
|
|
TAX
|
|
|
|
INC ; Plus '/' at each end
|
|
|
|
INC
|
|
|
|
STA PREFIX ; Store length
|
2021-09-17 20:45:52 +00:00
|
|
|
LDA #'/'
|
2021-09-07 02:28:07 +00:00
|
|
|
STA PREFIX+1
|
|
|
|
STA PREFIX+2,X
|
|
|
|
:L1 CPX #$00 ; Copy -> PREFIX
|
|
|
|
BEQ :EXIT
|
|
|
|
LDA DRVBUF2,X
|
|
|
|
STA PREFIX+1,X
|
|
|
|
DEX
|
|
|
|
BRA :L1
|
|
|
|
:EXIT RTS
|
|
|
|
|
|
|
|
* Delete first char of MOSFILE
|
|
|
|
DEL1CHAR LDX MOSFILE ; Length
|
|
|
|
BEQ :EXIT ; Nothing to delete
|
|
|
|
LDY #$02 ; Second char
|
|
|
|
:L1 CPY MOSFILE
|
|
|
|
BEQ :S2 ; If Y=MOSFILE okay
|
|
|
|
BCS :S1 ; If Y>MOSFILE done
|
|
|
|
:S2 LDA MOSFILE,Y
|
|
|
|
STA MOSFILE-1,Y
|
|
|
|
INY
|
|
|
|
BRA :L1
|
|
|
|
:S1 DEC MOSFILE
|
|
|
|
:EXIT RTS
|
|
|
|
|
|
|
|
* Append MOSFILE to PREFIX
|
|
|
|
APFXMF LDY PREFIX ; Length of PREFIX
|
|
|
|
LDX #$00 ; Index into MOSFILE
|
|
|
|
:L1 CPX MOSFILE ; Length of MOSFILE
|
|
|
|
BEQ :DONE
|
|
|
|
LDA MOSFILE+1,X
|
|
|
|
STA PREFIX+1,Y
|
|
|
|
INX
|
|
|
|
INY
|
|
|
|
BRA :L1
|
|
|
|
:DONE STY PREFIX ; Update length PREFIX
|
|
|
|
RTS
|
|
|
|
|
2022-09-17 19:19:55 +00:00
|
|
|
* Scan pathname in MOSFILE converting '_' to '.'
|
|
|
|
USCONV LDX MOSFILE ; Length
|
|
|
|
BEQ :EXIT ; Nothing to replace
|
|
|
|
:L1 LDA MOSFILE,X
|
|
|
|
CMP #'_'
|
|
|
|
BNE :S1
|
|
|
|
LDA #'.'
|
|
|
|
STA MOSFILE,X
|
|
|
|
:S1 DEX
|
|
|
|
BNE :L1
|
|
|
|
:EXIT RTS
|
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Scan pathname in MOSFILE converting files/dirs
|
|
|
|
* starting with digit by adding 'N' before.
|
|
|
|
DIGCONV LDY #$01 ; First char
|
|
|
|
:L1 CPY MOSFILE ; String length
|
|
|
|
BEQ :KEEPON ; Last char
|
|
|
|
BCS :DONE ; Y>MOSFILE
|
|
|
|
:KEEPON LDA MOSFILE,Y ; Load char
|
|
|
|
JSR ISDIGIT ; Is it a digit?
|
|
|
|
BCC :NOINS ; No .. skip
|
|
|
|
CPY #$01 ; First char?
|
|
|
|
BEQ :INS ; First char is digit
|
|
|
|
LDA MOSFILE-1,Y ; Prev char
|
2021-09-17 20:45:52 +00:00
|
|
|
CMP #'/' ; Slash
|
2021-09-07 02:28:07 +00:00
|
|
|
BEQ :INS ; Slash followed by digit
|
|
|
|
BRA :NOINS ; Otherwise leave it alone
|
|
|
|
:INS LDA #'N' ; Char to insert
|
|
|
|
JSR INSMF ; Insert it
|
|
|
|
INY
|
|
|
|
:NOINS INY ; Next char
|
|
|
|
BRA :L1
|
|
|
|
:DONE RTS
|
|
|
|
|
|
|
|
* Is char in A a digit? Set carry if so
|
|
|
|
ISDIGIT CMP #'9'+1
|
|
|
|
BCS :NOTDIG
|
|
|
|
CMP #'0'
|
|
|
|
BCC :NOTDIG
|
|
|
|
SEC
|
|
|
|
RTS
|
|
|
|
:NOTDIG CLC
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Insert char in A into MOSFILE at posn Y
|
|
|
|
* Preserves regs
|
|
|
|
INSMF PHA ; Preserve char
|
|
|
|
STY :INSIDX ; Stash index for later
|
|
|
|
LDY MOSFILE ; String length
|
|
|
|
INY ; Start with Y=len+1
|
|
|
|
:L1 CPY :INSIDX ; Back to ins point?
|
|
|
|
BEQ :S1 ; Yes, done moving
|
|
|
|
LDA MOSFILE-1,Y ; Move one char
|
|
|
|
STA MOSFILE,Y
|
|
|
|
DEY
|
|
|
|
BRA :L1
|
|
|
|
:S1 PLA ; Char to insert
|
|
|
|
STA MOSFILE,Y ; Insert it
|
|
|
|
INC MOSFILE ; One char longer
|
|
|
|
RTS
|
|
|
|
:INSIDX DB $00
|
|
|
|
|
|
|
|
* Copy Pascal-style string
|
|
|
|
* Source in A1L/A1H, dest in A4L/A4H
|
|
|
|
STRCPY LDY #$00
|
|
|
|
LDA (A1L),Y ; Length of source
|
|
|
|
STA (A4L),Y ; Copy length byte
|
|
|
|
TAY
|
|
|
|
:L1 CPY #$00
|
|
|
|
BEQ :DONE
|
|
|
|
LDA (A1L),Y
|
|
|
|
STA (A4L),Y
|
|
|
|
DEY
|
|
|
|
BRA :L1
|
|
|
|
:DONE RTS
|
|
|
|
|
|
|
|
* Copy MOSFILE to MFTEMP
|
|
|
|
MFtoTMP LDA #<MOSFILE
|
|
|
|
STA A1L
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA A1H
|
|
|
|
LDA #<MFTEMP
|
|
|
|
STA A4L
|
|
|
|
LDA #>MFTEMP
|
|
|
|
STA A4H
|
|
|
|
JSR STRCPY
|
|
|
|
RTS
|
|
|
|
|
2021-09-15 04:02:08 +00:00
|
|
|
* Copy MFTEMP to MOSFILE
|
2021-09-07 02:28:07 +00:00
|
|
|
TMPtoMF LDA #<MFTEMP
|
|
|
|
STA A1L
|
|
|
|
LDA #>MFTEMP
|
|
|
|
STA A1H
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA A4L
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA A4H
|
|
|
|
JSR STRCPY
|
|
|
|
RTS
|
|
|
|
|
2021-09-15 04:02:08 +00:00
|
|
|
* Copy MFTEMP to MOSFILE2
|
|
|
|
TMPtoMF2 LDA #<MFTEMP
|
|
|
|
STA A1L
|
|
|
|
LDA #>MFTEMP
|
|
|
|
STA A1H
|
|
|
|
LDA #<MOSFILE2
|
|
|
|
STA A4L
|
|
|
|
LDA #>MOSFILE2
|
|
|
|
STA A4H
|
|
|
|
JSR STRCPY
|
|
|
|
RTS
|
|
|
|
|
2021-09-07 02:28:07 +00:00
|
|
|
* Copy MOSFILE to MOSFILE2
|
|
|
|
COPYMF12 LDA #<MOSFILE
|
|
|
|
STA A1L
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA A1H
|
|
|
|
LDA #<MOSFILE2
|
|
|
|
STA A4L
|
|
|
|
LDA #>MOSFILE2
|
|
|
|
STA A4H
|
|
|
|
JSR STRCPY
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Copy MOSFILE2 to MOSFILE
|
|
|
|
COPYMF21 LDA #<MOSFILE2
|
|
|
|
STA A1L
|
|
|
|
LDA #>MOSFILE2
|
|
|
|
STA A1H
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA A4L
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA A4H
|
|
|
|
JSR STRCPY
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Copy PREFIX to MOSFILE
|
2021-09-15 04:02:08 +00:00
|
|
|
PFXtoMF LDA #<PREFIX
|
2021-09-07 02:28:07 +00:00
|
|
|
STA A1L
|
|
|
|
LDA #>PREFIX
|
|
|
|
STA A1H
|
|
|
|
LDA #<MOSFILE
|
|
|
|
STA A4L
|
|
|
|
LDA #>MOSFILE
|
|
|
|
STA A4H
|
|
|
|
JSR STRCPY
|
|
|
|
RTS
|
|
|
|
|
|
|
|
MFTEMP DS 65 ; Temp copy of MOSFILE
|
|
|
|
PREFIX DS 65 ; Buffer for ProDOS prefix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-07 03:43:42 +00:00
|
|
|
|
|
|
|
|
2021-09-09 17:38:27 +00:00
|
|
|
|
|
|
|
|
2021-09-10 05:10:16 +00:00
|
|
|
|
2021-10-18 22:46:52 +00:00
|
|
|
|
|
|
|
|
2021-10-25 00:38:32 +00:00
|
|
|
|
|
|
|
|
2021-10-26 13:31:34 +00:00
|
|
|
|
|
|
|
|
2021-10-14 00:57:16 +00:00
|
|
|
|
|
|
|
|
2021-11-13 19:57:05 +00:00
|
|
|
|
|
|
|
|
2021-11-14 23:04:10 +00:00
|
|
|
|
|
|
|
|
2021-11-05 23:16:22 +00:00
|
|
|
|
|
|
|
|
2021-09-17 21:51:11 +00:00
|
|
|
|