mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-30 08:51:06 +00:00
416 lines
8.8 KiB
Plaintext
416 lines
8.8 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
LOMEM $900
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* For All SYS.xxxx calls, X = #SYSCall
|
||
* Must be kept in X before calling
|
||
* PFT.Check
|
||
*/--------------------------------------
|
||
* #FOpen
|
||
* Open a file
|
||
* ##In :
|
||
* PUSHW = AUXTYPE
|
||
* PUSHB = TYPE
|
||
* PUSHB = MODE
|
||
* SYS.FOpen.R : if R and !exists -> ERROR
|
||
* SYS.FOpen.W : if W and !exists -> CREATE
|
||
* SYS.FOpen.A : Append
|
||
* SYS.FOpen.T : Open/Append in Text mode
|
||
* SYS.FOpen.X : Create if not exists
|
||
* PUSHW = PATH (PSTR)
|
||
* ##Out :
|
||
* CC : A = hFILE
|
||
* CS : A = EC
|
||
*\--------------------------------------
|
||
K.FOpen jsr PFT.CheckPathSTK
|
||
>PULLW MLICALL.PARAMS+1
|
||
>PULLB K.FOpen.MODE
|
||
>PULLB K.FOpen.TYPE
|
||
>PULLW K.FOpen.AUXTYPE
|
||
|
||
>MLICALL MLIGETFILEINFO
|
||
bcc K.FOpen.10 Already Exists
|
||
|
||
bit K.FOpen.MODE Create if not exists ?
|
||
bpl K.FOpen.9 No, return MLI error
|
||
|
||
lda #S.FILEINFO.ACCESS.FULL Yes, Create...
|
||
sta MLICALL.PARAMS+3 Access
|
||
lda K.FOpen.TYPE
|
||
sta MLICALL.PARAMS+4 File type
|
||
>LDYA K.FOpen.AUXTYPE
|
||
>STYA MLICALL.PARAMS+5 Aux type
|
||
lda #S.FILEINFO.STORETYPE.STD
|
||
sta MLICALL.PARAMS+7
|
||
|
||
ldx #3
|
||
.1 lda DATELO,x
|
||
sta MLICALL.PARAMS+8,x
|
||
dex
|
||
bpl .1
|
||
|
||
>MLICALL MLICREATE
|
||
bcc K.FOpen.10
|
||
K.FOpen.9 rts
|
||
|
||
K.FOpen.10 >PUSHWI S.NODE.REG
|
||
>PUSHBI S.MEM.F.INIT0
|
||
jsr K.GetMem
|
||
bcs K.FOpen.9
|
||
|
||
>STYA ZPPtr1
|
||
stx hFILE
|
||
|
||
jsr FILE.SetIOBUF
|
||
bcs .98
|
||
|
||
>MLICALL MLIOPEN
|
||
bcs .98
|
||
|
||
lda MLICALL.PARAMS+5 get ref_num
|
||
ldy #S.NODE.REG.REF
|
||
sta (ZPPtr1),y
|
||
|
||
sta MLICALL.PARAMS+1 Next MLI Calls are REF_NUM based
|
||
|
||
lda K.FOpen.MODE
|
||
bit #SYS.FOpen.W
|
||
beq .20 Write mode ?
|
||
|
||
and #SYS.FOpen.A Append ?
|
||
bne .11 yes, go to end of file
|
||
|
||
stz MLICALL.PARAMS+2
|
||
stz MLICALL.PARAMS+3
|
||
stz MLICALL.PARAMS+4
|
||
>MLICALL MLISETEOF no, reset size to 0
|
||
bcs .98
|
||
bra .20
|
||
|
||
.11 >MLICALL MLIGETEOF
|
||
bcs .98
|
||
|
||
>MLICALL MLISETMARK
|
||
bcs .98
|
||
|
||
.20 lda K.FOpen.MODE
|
||
and #SYS.FOpen.T Text Mode ?
|
||
beq .30
|
||
|
||
lda #$FF
|
||
sta MLICALL.PARAMS+2
|
||
lda #$0D
|
||
sta MLICALL.PARAMS+3
|
||
>MLICALL MLINEWLINE
|
||
|
||
.30 ldy #S.NODE.T
|
||
lda #S.NODE.T.REG
|
||
sta (ZPPtr1),y
|
||
lda hFILE
|
||
clc
|
||
rts CC
|
||
|
||
.98 pha save MLI error
|
||
lda hFILE
|
||
jsr K.FCloseA.1
|
||
pla get back MLI error
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
K.FOpen.MODE .BS 1
|
||
K.FOpen.TYPE .BS 1
|
||
K.FOpen.AUXTYPE .BS 2
|
||
hFILE .BS 1
|
||
*/--------------------------------------
|
||
* #FCloseA
|
||
* Close a file
|
||
* ##In :
|
||
* A = hFILE
|
||
* ##Out :
|
||
*\--------------------------------------
|
||
K.FCloseA jsr PFT.CheckNodeA
|
||
sta K.FCloseA.2+1
|
||
jsr K.GetMemPtrA
|
||
>STYA ZPPtr1
|
||
|
||
K.FCloseA.1 ldy #S.NODE.REG.REF
|
||
lda (ZPPtr1),y
|
||
beq .1
|
||
sta MLICALL.PARAMS+1
|
||
>MLICALL MLICLOSE
|
||
|
||
.1 ldy #S.NODE.REG.IOBUF
|
||
lda (ZPPtr1),y
|
||
beq K.FCloseA.2
|
||
jsr K.FreeMemA
|
||
|
||
K.FCloseA.2 lda #$ff Self Modified
|
||
jmp K.FreeMemA
|
||
*/--------------------------------------
|
||
* #FReadA
|
||
* Read ONE byte from file
|
||
* ##In :
|
||
* A = hFILE
|
||
* ##Out :
|
||
* A = Byte Read
|
||
*\--------------------------------------
|
||
K.FReadA jsr PFT.CheckNodeA
|
||
ldx #MLIREAD
|
||
bra K.FReadWrite.0
|
||
*/--------------------------------------
|
||
* #FWriteAY
|
||
* ##In:
|
||
* A = hFILE
|
||
* Y = char
|
||
* #Out:
|
||
* Y,A = Bytes Written
|
||
*\--------------------------------------
|
||
K.FWriteAY jsr PFT.CheckNodeA
|
||
sty MLICALL.TMPBUF
|
||
ldx #MLIWRITE
|
||
K.FReadWrite.0 jsr FILE.SetupPrt1A
|
||
>LDYAI MLICALL.TMPBUF
|
||
>STYA MLICALL.PARAMS+2
|
||
lda #1
|
||
sta MLICALL.PARAMS+4
|
||
stz MLICALL.PARAMS+5
|
||
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
|
||
jsr A2osX.MLICALL
|
||
bcs .9
|
||
lda MLICALL.TMPBUF
|
||
.9 rts
|
||
*/--------------------------------------
|
||
* #FRead
|
||
* Read bytes from file
|
||
* ##In :
|
||
* PUSHW = Dest Ptr
|
||
* PUSHW = Bytes To Read
|
||
* PUSHB = hFILE
|
||
* ##Out :
|
||
* Y,A = Bytes Read
|
||
*\--------------------------------------
|
||
K.FRead jsr PFT.CheckNodeSTK
|
||
ldx #MLIREAD
|
||
bra K.FReadWrite.1
|
||
*/--------------------------------------
|
||
* #FWrite
|
||
* ##In:
|
||
* PUSHW = Src Ptr
|
||
* PUSHW = Bytes To Write
|
||
* PUSHB = hFILE
|
||
* #Out:
|
||
* Y,A = Bytes Written
|
||
*\--------------------------------------
|
||
K.FWrite jsr PFT.CheckNodeSTK
|
||
ldx #MLIWRITE
|
||
K.FReadWrite.1 >PULLA
|
||
jsr FILE.SetupPrt1A
|
||
>PULLW MLICALL.PARAMS+4
|
||
>PULLW MLICALL.PARAMS+2
|
||
|
||
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
|
||
jsr A2osX.MLICALL
|
||
bcs .9
|
||
>LDYA MLICALL.PARAMS+6
|
||
.9 rts
|
||
*/--------------------------------------
|
||
* #FFlushA
|
||
* ##In:
|
||
* A = hFILE
|
||
*\--------------------------------------
|
||
K.FFlushA jsr PFT.CheckNodeA
|
||
jsr FILE.SetupPrt1A
|
||
>MLICALL MLIFLUSH
|
||
rts
|
||
*/-------------------------------------
|
||
* #FSeek
|
||
* ##In:
|
||
* PUSHW = OffsetHi
|
||
* PUSHW = OffsetLo
|
||
* PUSHB = From
|
||
* PUSHB = hFILE
|
||
*\-------------------------------------
|
||
K.FSeek jsr PFT.CheckNodeSTK
|
||
>PULLA
|
||
jsr FILE.SetupPrt1A
|
||
>PULLB K.FSeek.FROM
|
||
>PULLW K.FSeek.OFFSET
|
||
>PULLW K.FSeek.OFFSET+2
|
||
|
||
lda K.FSeek.FROM
|
||
|
||
* cmp #SYS.FSeek.SET =0
|
||
|
||
bne .1
|
||
stz MLICALL.PARAMS+2
|
||
stz MLICALL.PARAMS+3
|
||
stz MLICALL.PARAMS+4
|
||
bra .8
|
||
|
||
.1 cmp #SYS.FSeek.CUR
|
||
bne .2
|
||
>MLICALL MLIGETMARK
|
||
bcc .8
|
||
rts
|
||
|
||
.2 cmp #SYS.FSeek.END
|
||
bne .98
|
||
>MLICALL MLIGETEOF
|
||
bcs .9
|
||
|
||
.8 lda MLICALL.PARAMS+2
|
||
adc K.FSeek.OFFSET
|
||
sta MLICALL.PARAMS+2
|
||
lda MLICALL.PARAMS+3
|
||
adc K.FSeek.OFFSET+1
|
||
sta MLICALL.PARAMS+3
|
||
lda MLICALL.PARAMS+4
|
||
adc K.FSeek.OFFSET+2
|
||
sta MLICALL.PARAMS+4
|
||
bcs .99 Offset out of range!
|
||
|
||
>MLICALL MLISETMARK
|
||
|
||
.9 rts
|
||
|
||
.98 lda #SYSMGR.ERRSYN
|
||
.HS 2C bit abs
|
||
.99 lda #SYSMGR.ERRFTB
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
K.FSeek.FROM .BS 1
|
||
K.FSeek.OFFSET .BS 4
|
||
*/--------------------------------------
|
||
* #FTellA
|
||
* ##In:
|
||
* A = hFILE
|
||
* ##Out:
|
||
* Y,A,X = Offset
|
||
*\--------------------------------------
|
||
K.FTellA jsr PFT.CheckNodeA
|
||
K.FTellA.1 jsr FILE.SetupPrt1A
|
||
>MLICALL MLIGETMARK
|
||
bcs .9
|
||
>LDYA MLICALL.PARAMS+2
|
||
ldx MLICALL.PARAMS+4
|
||
.9 rts
|
||
*/--------------------------------------
|
||
* #FEOFA
|
||
* ##In:
|
||
* A = hFILE
|
||
* ##Out:
|
||
* CC :
|
||
* A=0 EOF
|
||
* A !=0 NOT EOF
|
||
* CS :
|
||
*\--------------------------------------
|
||
K.FEOFA jsr PFT.CheckNodeA
|
||
jsr FILE.SetupPrt1A
|
||
jsr K.FTellA.1
|
||
bcs .9
|
||
>STYA K.FEOFA.MARK
|
||
stx K.FEOFA.MARK+2
|
||
|
||
>MLICALL MLIGETEOF
|
||
bcs .9
|
||
|
||
sec
|
||
lda MLICALL.PARAMS+2
|
||
sbc K.FEOFA.MARK
|
||
bne .8
|
||
lda MLICALL.PARAMS+3
|
||
sbc K.FEOFA.MARK+1
|
||
bne .8
|
||
lda MLICALL.PARAMS+4
|
||
sbc K.FEOFA.MARK+2
|
||
.8 clc
|
||
.9 rts
|
||
K.FEOFA.MARK .BS 3
|
||
*/--------------------------------------
|
||
* #RemoveYA
|
||
*\--------------------------------------
|
||
K.RemoveYA jsr PFT.CheckPathYA
|
||
>STYA MLICALL.PARAMS+1
|
||
>MLICALL MLIDESTROY
|
||
rts
|
||
*/--------------------------------------
|
||
* #Rename
|
||
* Rename a file
|
||
* ##In :
|
||
* PUSHW = New Name
|
||
* PUSHW = Old Name
|
||
* ##Out :
|
||
*\--------------------------------------
|
||
K.Rename jsr PFT.CheckPathSTK
|
||
>PULLW MLICALL.PARAMS+1
|
||
>PULLW MLICALL.PARAMS+3
|
||
>MLICALL MLIRename
|
||
rts
|
||
*/--------------------------------------
|
||
* #Stat
|
||
* Return information about a file
|
||
* ##In :
|
||
* PUSHW = PTR to S.STAT buffer
|
||
* PUSHW = PTR to Filename (PSTR)
|
||
* ##Out :
|
||
*\--------------------------------------
|
||
K.Stat jsr PFT.CheckPathSTK
|
||
>PULLW MLICALL.PARAMS+1
|
||
>PULLW ZPPtr2
|
||
>MLICALL MLIGETFILEINFO
|
||
bcs .9
|
||
jsr FILE.MLI2STAT
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
FILE.SetIOBUF >PUSHWI 1024 get a ProDOS IOBUF
|
||
>PUSHBI S.MEM.F.ALIGN+S.MEM.F.NOMOVE
|
||
jsr K.GetMem
|
||
bcs .9
|
||
|
||
>STYA MLICALL.PARAMS+3 Save Ptr to IOBUF for MLIOPEN call
|
||
txa
|
||
ldy #S.NODE.REG.IOBUF
|
||
sta (ZPPtr1),y
|
||
.9 rts
|
||
*--------------------------------------
|
||
FILE.SetupPrt1A jsr K.GetMemPtrA
|
||
>STYA ZPPtr1
|
||
ldy #S.NODE.REG.REF
|
||
lda (ZPPtr1),y
|
||
sta MLICALL.PARAMS+1
|
||
rts
|
||
*--------------------------------------
|
||
FILE.MLI2STAT lda MLICALL.PARAMS+S.FILEINFO.ACCESS
|
||
cmp #S.FILEINFO.ACCESS.FULL
|
||
bne .1
|
||
|
||
lda #S.STAT.MODE.XO+S.STAT.MODE.WO+S.STAT.MODE.RO
|
||
bra .2
|
||
|
||
.1 and #S.FILEINFO.ACCESS.R
|
||
beq .2
|
||
lda #S.STAT.MODE.XO+S.STAT.MODE.RO
|
||
|
||
.2 ldy #S.STAT.MODE
|
||
sta (ZPPtr2),y
|
||
|
||
ldx #2
|
||
ldy #S.STAT.P.TYPE+2
|
||
|
||
.3 lda MLICALL.PARAMS+S.FILEINFO.TYPE,x
|
||
sta (ZPPtr2),y
|
||
dey
|
||
dex
|
||
bpl .3
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE SYS/KERNEL.S.FILE
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|