A2osX/SYS/KERNEL.S.FILE.txt

452 lines
9.2 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*--------------------------------------
* 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
2017-01-12 17:43:45 +00:00
* 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
*\--------------------------------------
2017-01-12 17:43:45 +00:00
K.FOpen jsr PFT.CheckPathSTK
>PULLW K.MLI.PARAMS+1
2017-01-12 17:43:45 +00:00
>PULLB K.FOpen.MODE
>PULLB K.FOpen.TYPE
>PULLW K.FOpen.AUXTYPE
2016-08-28 20:48:01 +00:00
>MLICALL MLIGETFILEINFO
2017-01-12 17:43:45 +00:00
bcc K.FOpen.10 Already Exists
2016-08-28 20:48:01 +00:00
2017-01-12 17:43:45 +00:00
bit K.FOpen.MODE Create if not exists ?
bpl K.FOpen.9 No, return MLI error
2016-08-28 20:48:01 +00:00
lda #S.FILEINFO.ACCESS.FULL Yes, Create...
sta K.MLI.PARAMS+3 Access
2017-01-12 17:43:45 +00:00
lda K.FOpen.TYPE
sta K.MLI.PARAMS+4 File type
2017-01-12 17:43:45 +00:00
>LDYA K.FOpen.AUXTYPE
>STYA K.MLI.PARAMS+5 Aux type
lda #S.FILEINFO.STORETYPE.STD
sta K.MLI.PARAMS+7
ldx #3
.1 lda DATELO,x
sta K.MLI.PARAMS+8,x
dex
bpl .1
2016-08-28 20:48:01 +00:00
>MLICALL MLICREATE
2017-01-12 17:43:45 +00:00
bcc K.FOpen.10
K.FOpen.9 rts
2016-08-28 20:48:01 +00:00
K.FOpen.10 >LDYAI S.NODE.REG
jsr K.GetMem0YA
2017-01-12 17:43:45 +00:00
bcs K.FOpen.9
2016-08-28 20:48:01 +00:00
2017-01-12 17:43:45 +00:00
>STYA ZPPtr1
stx hFILE
2017-01-12 17:43:45 +00:00
jsr FILE.SetIOBUF
2016-09-01 15:42:38 +00:00
bcs .98
>MLICALL MLIOPEN
2016-08-28 20:48:01 +00:00
bcs .98
lda K.MLI.PARAMS+5 get ref_num
ldy #S.NODE.REG.REF
2017-01-12 17:43:45 +00:00
sta (ZPPtr1),y
sta K.MLI.PARAMS+1 Next MLI Calls are REF_NUM based
2016-08-28 20:48:01 +00:00
2017-01-12 17:43:45 +00:00
lda K.FOpen.MODE
bit #SYS.FOpen.W
beq .20 Write mode ?
2017-01-12 17:43:45 +00:00
and #SYS.FOpen.A Append ?
bne .11 yes, go to end of file
stz K.MLI.PARAMS+2
stz K.MLI.PARAMS+3
stz K.MLI.PARAMS+4
>MLICALL MLISETEOF no, reset size to 0
bcs .98
bra .20
2016-08-28 20:48:01 +00:00
.11 >MLICALL MLIGETEOF
2016-08-28 20:48:01 +00:00
bcs .98
2016-08-28 20:48:01 +00:00
>MLICALL MLISETMARK
bcs .98
2017-01-12 17:43:45 +00:00
.20 lda K.FOpen.MODE
and #SYS.FOpen.T Text Mode ?
2016-08-28 20:48:01 +00:00
beq .30
2016-08-28 20:48:01 +00:00
lda #$FF
sta K.MLI.PARAMS+2
2016-08-28 20:48:01 +00:00
lda #$0D
sta K.MLI.PARAMS+3
2016-08-28 20:48:01 +00:00
>MLICALL MLINEWLINE
.30 ldy #S.NODE.T
lda #S.NODE.T.REG
2017-01-12 17:43:45 +00:00
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
*--------------------------------------
2017-01-12 17:43:45 +00:00
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
pha
2016-09-21 15:20:37 +00:00
jsr K.GetMemPtrA
2017-01-12 17:43:45 +00:00
>STYA ZPPtr1
pla
K.FCloseA.1 sta K.FCloseA.2+1
ldy #S.NODE.REG.REF
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
beq .1
sta K.MLI.PARAMS+1
>MLICALL MLICLOSE
.1 ldy #S.NODE.REG.IOBUF
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
beq K.FCloseA.2
2016-09-21 15:20:37 +00:00
jsr K.FreeMemA
2017-01-12 17:43:45 +00:00
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 K.FWriteAY.Buf
ldx #MLIWRITE
K.FReadWrite.0 jsr FILE.SetupPrt1A
>LDYAI K.FWriteAY.Buf
>STYA K.MLI.PARAMS+2
lda #1
sta K.MLI.PARAMS+4
stz K.MLI.PARAMS+5
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
jsr A2osX.MLICALL
bcs .9
lda K.FWriteAY.Buf
.9 rts
K.FWriteAY.Buf .BS 1
*/--------------------------------------
* # 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 K.MLI.PARAMS+4
>PULLW K.MLI.PARAMS+2
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
jsr A2osX.MLICALL
bcs .9
>LDYA K.MLI.PARAMS+6
.9 rts
*/--------------------------------------
* # FFlushA
* ## In:
* A = hFILE
*\--------------------------------------
K.FFlushA jsr PFT.CheckNodeA
2016-09-26 16:00:52 +00:00
jsr FILE.SetupPrt1A
>MLICALL MLIFLUSH
rts
*/-------------------------------------
* # FSeek
* ## In:
* PUSHW = OffsetHi
* PUSHW = OffsetLo
* PUSHB = From
* PUSHB = hFILE
*\-------------------------------------
K.FSeek jsr PFT.CheckNodeSTK
>PULLA
2016-09-26 16:00:52 +00:00
jsr FILE.SetupPrt1A
>PULLA FROM
tax
2017-01-12 17:43:45 +00:00
>PULLW K.FSeek.OFFSET
>PULLW K.FSeek.OFFSET+2
cpx #SYS.FSeek.SET
bne .1
stz K.MLI.PARAMS+2
stz K.MLI.PARAMS+3
stz K.MLI.PARAMS+4
bra .8
.1 cpx #SYS.FSeek.CUR
bne .2
>MLICALL MLIGETMARK
bcc .8
rts
.2 cpx #SYS.FSeek.END
bne .98
>MLICALL MLIGETEOF
bcs .9
.8 ldx #0
ldy #3
clc
.81 lda K.MLI.PARAMS+2,x
adc K.FSeek.OFFSET,x
sta K.MLI.PARAMS+2,x
inx
dey
bne .81
bcs .99 Offset out of range!
>MLICALL MLISETMARK
.9 rts
.98 lda #SYSMGR.ERRSYN
.HS 2C bit abs
.99 lda #SYSMGR.ERRFTB
sec
rts
*--------------------------------------
2017-01-12 17:43:45 +00:00
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 K.MLI.PARAMS+2
ldx K.MLI.PARAMS+4
.9 rts
*/--------------------------------------
* # FEOFA
* ## In:
* A = hFILE
* ## Out:
* CC :
* A=0 EOF
* A !=0 NOT EOF
* CS :
*\--------------------------------------
K.FEOFA jsr PFT.CheckNodeA
2016-09-26 16:00:52 +00:00
jsr FILE.SetupPrt1A
2017-01-12 17:43:45 +00:00
jsr K.FTellA.1
bcs .9
2016-09-21 15:20:37 +00:00
>STYA K.FEOFA.MARK
stx K.FEOFA.MARK+2
>MLICALL MLIGETEOF
bcs .9
sec
lda K.MLI.PARAMS+2
2016-09-21 15:20:37 +00:00
sbc K.FEOFA.MARK
bne .8
lda K.MLI.PARAMS+3
2016-09-21 15:20:37 +00:00
sbc K.FEOFA.MARK+1
bne .8
lda K.MLI.PARAMS+4
2016-09-21 15:20:37 +00:00
sbc K.FEOFA.MARK+2
.8 clc
.9 rts
2016-09-21 15:20:37 +00:00
K.FEOFA.MARK .BS 3
*/--------------------------------------
* # RemoveYA
*\--------------------------------------
K.RemoveYA jsr PFT.CheckPathYA
>STYA K.MLI.PARAMS+1
>MLICALL MLIDESTROY
rts
*/--------------------------------------
* # Rename
* Rename a file
* ## In :
* PUSHW = New Name
* PUSHW = Old Name
* ## Out :
*\--------------------------------------
K.Rename jsr PFT.CheckPathSTK
>PULLW K.MLI.PARAMS+1
>PULLW K.MLI.PARAMS+3
2017-01-12 17:43:45 +00:00
>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 K.MLI.PARAMS+1
2017-01-12 17:43:45 +00:00
>PULLW ZPPtr2
2016-09-21 15:20:37 +00:00
>MLICALL MLIGETFILEINFO
bcs .9
ldx K.MLI.PARAMS+S.FILEINFO.ACCESS
lda #S.STAT.MODE.XO+S.STAT.MODE.WO+S.STAT.MODE.RO
cpx #S.FILEINFO.ACCESS.FULL
beq .2
lda #S.STAT.MODE.XO+S.STAT.MODE.RO
cpx #S.FILEINFO.ACCESS.R
beq .2
lda #0
.2 ldy #S.STAT.MODE
sta (ZPPtr2),y
ldx #K.Stat.DST-K.Stat.SRC
.3 ldy K.Stat.SRC-1,x
lda K.MLI.PARAMS,y
ldy K.Stat.DST-1,x
sta (ZPPtr2),y
dex
bne .3
ldy #S.STAT.SIZE
lda #0
sta (ZPPtr2),y
iny
lda K.MLI.PARAMS+S.FILEINFO.BLOCKSUSED
asl
sta (ZPPtr2),y
iny
lda K.MLI.PARAMS+S.FILEINFO.BLOCKSUSED+1
rol
sta (ZPPtr2),y
iny
lda #0
rol
sta (ZPPtr2),y
clc
2016-09-21 15:20:37 +00:00
.9 rts
*--------------------------------------
K.Stat.SRC .DA #S.FILEINFO.TYPE
.DA #S.FILEINFO.AUXTYPE,#S.FILEINFO.AUXTYPE+1
.DA #S.FILEINFO.BLOCKSUSED,#S.FILEINFO.BLOCKSUSED+1
K.Stat.DST .DA #S.STAT.P.TYPE
.DA #S.STAT.P.AUXTYPE,#S.STAT.P.AUXTYPE+1
.DA #S.STAT.BLOCKS,#S.STAT.BLOCKS+1
.DA #S.STAT.SIZE+1,#S.STAT.SIZE+2
*--------------------------------------
2017-01-12 17:43:45 +00:00
FILE.SetIOBUF >PUSHWI 1024 get a ProDOS IOBUF
>PUSHBI S.MEM.F.ALIGN+S.MEM.F.NOMOVE
jsr K.GetMem
bcs .9
>STYA K.MLI.PARAMS+3 Save Ptr to IOBUF for MLIOPEN call
2017-01-12 17:43:45 +00:00
txa
ldy #S.NODE.REG.IOBUF
sta (ZPPtr1),y
.9 rts
*--------------------------------------
2016-09-26 16:00:52 +00:00
FILE.SetupPrt1A jsr K.GetMemPtrA
2017-01-12 17:43:45 +00:00
>STYA ZPPtr1
ldy #S.NODE.REG.REF
2017-01-12 17:43:45 +00:00
lda (ZPPtr1),y
sta K.MLI.PARAMS+1
rts
2016-09-26 16:00:52 +00:00
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.FILE
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM