A2osX/BIN/X.CPMVRM.S.txt
2017-03-29 17:48:15 +02:00

638 lines
11 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
X.COPY.BUF.SIZE .EQ 4096
*--------------------------------------
ZPPtr1 .EQ ZPBIN
ZPPtr2 .EQ ZPBIN+2
ZPFileName .EQ ZPBIN+4
ZPFileStat .EQ ZPBIN+6
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.DIR .DA MSG.DIR
L.MSG.FILE .DA MSG.FILE
.DO X.COPY.TO.DEST=1
L.MSG.OVERWRTE .DA MSG.OVERWRTE
.FIN
L.MSG.OK .DA MSG.OK
L.MSG.ERR .DA MSG.ERR
L.STAT .DA STAT
.DA 0
*--------------------------------------
CS.INIT >SYSCALL GetArgC
sta ArgCount
cmp #1
beq .99
stz ArgIndex
.1 dec ArgCount
beq .7
inc ArgIndex
lda ArgIndex
>SYSCALL GetArgA
>STYA ZPPtr1
lda (ZPPtr1)
cmp #2
bne .4
ldy #1
lda (ZPPtr1),y
cmp #'-'
bne .4
iny
lda (ZPPtr1),y
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.99 >LDYA L.MSG.USAGE
>SYSCALL CPrintFYA
lda #SYSMGR.ERRSYN
sec
rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 ldy #index
lda (pData),y
.DO X.COPY.TO.DEST=1
bne .5 Already have a Src dir...
.ELSE
bne .99
.FIN
>LDYA ZPPtr1
jsr InitSrcDirPatYA
bcc .1 success, scan for any other args
rts
.DO X.COPY.TO.DEST=1
.5 ldy #hDstBasePath
lda (pData),y
bne .99 we already have a second arg....error!
>LDYA ZPPtr1
jsr InitDstDirYA
bcc .1 success, scan for any other args
rts
.FIN
.7 ldy #index processed all args
lda (pData),y
beq .99 , no src ? ERROR
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
lda (pData),y
bne .8 we also have a Dst folder
ldy #S.PS.hPREFIX no dst folder, use actual prefix
lda (pPs),y
>SYSCALL GetMemPtrA
jsr InitDstDirYA
bcs .99
.FIN
.8 lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
rts
*--------------------------------------
CS.RUN >SYSCALL GetC
bcs .11 no char
cmp #$03 Ctrl-C
bne .10
sec
rts Abort....
.10 cmp #$13 Ctrl-S
bne .11
ldy #bPause
lda (pData),y
eor #$ff
sta (pData),y
.11 ldy #bPause
lda (pData),y
bpl .1
clc
rts
.1 .DO X.COPY.TO.DEST=1
ldy #bCopy
lda (pData),y
bpl .2
jmp CS.RUN.Copy
.FIN
.2 .DO X.DELETE.SOURCE=1
ldy #hToDelete
lda (pData),y
beq .3
>SYSCALL GetMemPtrA
>SYSCALL RemoveYA
php
pha
ldy #hToDelete
lda (pData),y
>SYSCALL FreeMemA
ldy #hToDelete
lda #0
sta (pData),y
pla
plp
jsr CS.RUN.CheckErr
bcs .9
jmp CS.RUN.NEXT
.FIN
*---------------
.3 jsr GetEntry
bcs CS.RUN.LEAVE
ldy #hFilter
lda (pData),y
beq .4 No filter....
>SYSCALL GetMemPtrA
>PUSHYA
>PUSHW ZPFileName
>SYSCALL PStrMatch
bcs CS.RUN.NEXT no match, skip....
.4 ldy #S.STAT.P.DRIVE
lda (ZPFileStat),y ProDOS Device ?
bne .6
ldy #S.STAT.P.TYPE
lda (ZPFileStat),y
cmp #$0F Directory ?
bne .5
ldy #bRecurse
lda (pData),y
bpl CS.RUN.NEXT
ldy #1
lda (ZPFileName),y
cmp #'.'
beq CS.RUN.NEXT Skip "." & ".."
jmp CS.RUN.DIR
.5 jmp CS.RUN.FILE
.6 lda #MLI.ERR.UNSUPST
sec
.9 rts
*--------------------------------------
CS.RUN.CR.NEXT lda #13
>SYSCALL PutCA
lda #10
>SYSCALL PutCA
CS.RUN.NEXT jsr GetNextEntry
bcs CS.RUN.LEAVE
rts
*--------------------------------------
CS.RUN.LEAVE jsr LeaveSubDir exit this sub dir....
bcs .99 base, we are done, exit
jsr BasePath..
.DO X.DELETE.SOURCE=1
.DO X.COPY.TO.DEST=0
jsr GetEntry
bcs *
>PUSHW ZPFileName
ldy #hSrcBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>LDYA L.MSG.DIR
>SYSCALL CPrintFYA
bcs .9
ldy #hSrcBasePath
jsr CS.RUN.GetFilePath
>LDYAI UsrBuf256
>SYSCALL RemoveYA
jsr CS.RUN.CheckErr
bcs .99
.FIN
.FIN
jmp CS.RUN.NEXT
.99 ldy #RC
lda (pData),y get global RC in case of bContinue
sec
.9 rts
*--------------------------------------
CS.RUN.DIR .DO X.COPY.TO.DEST=1
>PUSHW ZPFileName Filename
ldy #hDstBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>PUSHW ZPFileName Filename
ldy #hSrcBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>LDYA L.MSG.DIR
>SYSCALL CPrintFYA
bcs CS.RUN.DIR.RTS
ldy #hDstBasePath
jsr CS.RUN.GetFilePath
>PUSHW L.STAT
>PUSHWI UsrBuf256
>SYSCALL Stat
bcs .3 File Not exists...go create
ldy #bNoConfirm
lda (pData),y
bmi .21 no prompt, nothing to create, enter subdir
>LDYA L.MSG.OVERWRTE
>SYSCALL CPrintFYA
bcs CS.RUN.DIR.RTS
.1 >SYSCALL Sleep
>SYSCALL GetC
bcs .1
cmp #3
beq .99 abort
cmp #'N'
bne .2
jmp CS.RUN.CR.NEXT no overwrite, nothing to do, no recurse
.2 cmp #'Y'
beq .21 no create, but recurse
cmp #'A'
bne .1
ldy #bNoConfirm
lda #$ff
sta (pData),y
.21 clc
lda #0
bra .4
.3 >LDYAI UsrBuf256
>SYSCALL MKDirYA
.4 jsr CS.RUN.CheckErr
bcs CS.RUN.DIR.RTS
.FIN
.7 >LDYA ZPFileName
jmp EnterSubDirYA
.99 ldy #RC
lda (pData),y get global RC in case of bContnue
sec
CS.RUN.DIR.RTS rts
*--------------------------------------
CS.RUN.FILE .DO X.COPY.TO.DEST=1
>PUSHW ZPFileName
ldy #hDstBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
.FIN
>PUSHW ZPFileName
ldy #hSrcBasePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>LDYA L.MSG.FILE
>SYSCALL CPrintFYA
bcs CS.RUN.DIR.RTS
.DO X.COPY.TO.DEST=1
ldy #hDstBasePath
jsr CS.RUN.GetFilePath
>PUSHW L.STAT
>PUSHWI UsrBuf256
>SYSCALL Stat
bcs .2 File Not exists...go create
ldy #bNoConfirm
lda (pData),y
bmi .2 no prompt, ovverwrite
>LDYA L.MSG.OVERWRTE
>SYSCALL CPrintFYA
bcs .9
.1 >SYSCALL Sleep
>SYSCALL GetC
bcs .1
cmp #3
beq .99 abort
cmp #'N'
bne .11
jmp CS.RUN.CR.NEXT no overwrite exit
rts
.11 cmp #'Y'
beq .12 copy
cmp #'A'
bne .1
ldy #bNoConfirm
lda #$ff
sta (pData),y
.12 jsr GetEntry get back current entry corrupted by SLEEP
.2 jsr CS.RUN.CopyStart
bcc .4
jsr CS.RUN.CheckErr
rts
.FIN
.4 .DO X.DELETE.SOURCE=1
ldy #hSrcBasePath
jsr CS.RUN.GetFilePath
>LDYAI UsrBuf256
>SYSCALL NewPStrYA
bcs .9
txa
ldy #hToDelete
sta (pData),y
.FIN
clc
.9 rts
.99 ldy #RC
lda (pData),y get global RC in case of bContnue
sec
rts
*--------------------------------------
.DO X.COPY.TO.DEST=1
CS.RUN.CopyStart
ldy #S.STAT.P.AUXTYPE+1
>PUSHB (ZPFileStat),y
dey
>PUSHB (ZPFileStat),y
ldy #S.STAT.P.TYPE
>PUSHB (ZPFileStat),y
>PUSHBI SYS.FOpen.R
ldy #hSrcBasePath
jsr CS.RUN.GetFilePath
>PUSHWI UsrBuf256
>SYSCALL FOpen
bcs .99
ldy #hSrcFile
sta (pData),y
ldy #S.STAT.P.AUXTYPE+1
>PUSHB (ZPFileStat),y
dey
>PUSHB (ZPFileStat),y
ldy #S.STAT.P.TYPE
>PUSHB (ZPFileStat),y
>PUSHBI SYS.FOpen.W+SYS.FOpen.X
ldy #hDstBasePath
jsr CS.RUN.GetFilePath
>PUSHWI UsrBuf256
>SYSCALL FOpen
bcs .9
ldy #hDstFile
sta (pData),y
ldy #bCopy
lda #$ff
sta (pData),y
clc
rts
.9 pha
ldy #hSrcFile
lda (pData),y
>SYSCALL FCloseA
pla
sec
.99 rts
*--------------------------------------
CS.RUN.Copy stz .90+1
>PUSHWI X.COPY.BUF.SIZE
>PUSHBI 0
>SYSCALL GetMem
bcs .9
>STYA ZPPtr1
stx .90+1
>PUSHW ZPPtr1 Dst Ptr
>PUSHWI X.COPY.BUF.SIZE Bytes To Read
ldy #hSrcFile
>PUSHB (pData),y
>SYSCALL FRead
bcc .1
cmp #MLI.ERR.EOF
bne .9
lda #0
bra .9
.1 >STYA ZPPtr2
>PUSHW ZPPtr1 Src Ptr
>PUSHW ZPPtr2 Bytes To Write
ldy #hDstFile
>PUSHB (pData),y
>SYSCALL FWrite
bcs .9
lda .90+1
>SYSCALL FreeMemA
lda #'.'
>SYSCALL PutCA
rts
.9 ldy #CopyRC
sta (pData),y
.90 lda #$00
beq CS.RUN.CopyEnd
>SYSCALL FreeMemA
*--------------------------------------
CS.RUN.CopyEnd ldy #hSrcFile
lda (pData),y
>SYSCALL FCloseA
bcc .1
jsr CS.RUN.CheckErr
.1 ldy #hDstFile
lda (pData),y
>SYSCALL FCloseA
bcc .2
jsr CS.RUN.CheckErr
.2 ldy #bCopy
lda #$0
sta (pData),y
clc
ldy #CopyRC
lda (pData),y
beq .3
sec
.3 jsr CS.RUN.CheckErr
bcs .9
jmp CS.RUN.NEXT
.9 rts
.FIN
*--------------------------------------
CS.RUN.CheckErr bcs .1
>LDYA L.MSG.OK
>SYSCALL CPrintFYA
rts
.1 ldy #RC
sta (pData),y
pha
ldy #bContinue
lda (pData),y
bpl .2
pla
>PUSHA
>LDYA L.MSG.ERR
>SYSCALL CPrintFYA
bcs .9
rts
.2 lda #13
>SYSCALL PutCA
pla
sec
rts
.9 rts
*--------------------------------------
CS.RUN.GetFilePath
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>PUSHWI UsrBuf256
>SYSCALL PStrCpy
>PUSHW ZPFileName
>PUSHWI UsrBuf256
>SYSCALL PStrCat
rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT jsr LeaveSubDir
bcc CS.QUIT
ldy #hToDelete
lda (pData),y
beq .1
>SYSCALL FreeMemA
.1 ldy #bCopy
lda (pData),y
bpl .2
ldy #hSrcFile
lda (pData),y
>SYSCALL FCloseA
ldy #hDstFile
lda (pData),y
>SYSCALL FCloseA
.2 ldy #hFilter
lda (pData),y
beq .8
>SYSCALL FreeMemA
.8 clc
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/BIN/X.CPMVRM.S