A2osX/SYS/KERNEL.S.IO.txt
2018-11-19 17:15:16 +01:00

479 lines
9.5 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.

NEW
PREFIX
AUTO 4,1
*/--------------------------------------
* # open
* ## C
* `hFD open(const char *pathname, short int flags);`
* ## ASM
* **In:**
* `>PUSHB flags`
* `>LDYA pathname`
* `>SYSCALL open`
* ## RETURN VALUE
* A = hFD
* REG File created on ProDOS : T=TXT,X=$0000
*\--------------------------------------
K.Open.FLAGS .BS 1
K.Open.TYPE .BS 1
K.Open.AUXTYPE .BS 2
*--------------------------------------
K.Open jsr PFT.YAToMLIPATH
>PULLB K.Open.FLAGS
lda #S.FI.T.TXT
sta K.Open.TYPE
stz K.Open.AUXTYPE
stz K.Open.AUXTYPE+1
IO.Open.I ldx #5 $/DEV/
cpx K.MLI.PATH
bcs IO.OPEN.REG
.1 lda K.MLI.PATH,x
cmp IO.DEVDIR,x
bne IO.OPEN.REG
dex
bne .1
*--------------------------------------
* /DEV/xxxxxx (CDEV,BDEV,LNK,DSOCK,SSOCK,PIPE)
*--------------------------------------
>LDYAI K.MLI.PATH+6 skip $/DEV/
jsr K.GetDevByName
bcc .7
ldx #0
.10 lda Nod.Table.hPath,x
beq .6
jsr K.GetMemPtr
>STYA ZPPtr1
ldy #0
.2 lda (ZPPtr1),y
iny
cmp K.MLI.PATH,y
bne .6
cmp #0 end of string ?
bne .2
lda Nod.Table.hFD,x return hFD
clc
rts
.6 inx
cpx #K.NOD.MAX
bne .10
lda #MLI.E.NODEV
* sec
rts no OF found
.7 >STYA pFD
phx DEVID
lda (pFD) #S.FD.T
tax
pla hFILE
jmp (.8,x)
.8 .DA STDIO.IOERR REG
.DA STDIO.IOERR DIR
.DA IO.OPEN.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA IO.OPEN.DSOCK
.DA IO.OPEN.SSOCK
.DA IO.OPEN.PIPE
IO.OPEN.9 sec
IO.OPEN.RTS rts
*--------------------------------------
IO.OPEN.REG >MLICALL MLIGETFILEINFO
bcc K.IO.OPEN.REG.E Already Exists
bit K.Open.FLAGS Create if not exists ?
bpl IO.OPEN.9 No, return MLI error
lda #S.FI.A.FULL Yes, Create...
sta K.MLI.PARAMS+3 Access
ldx #2
.1 lda K.Open.TYPE,x
sta K.MLI.PARAMS+4,x File type,Aux type
dex
bpl .1
lda #S.FI.ST.STD
sta K.MLI.PARAMS+7
ldx #3
.2 lda DATELO,x
sta K.MLI.PARAMS+8,x
dex
bpl .2
>MLICALL MLICREATE
bcs IO.OPEN.RTS
K.IO.OPEN.REG.E >LDYAI S.FD.REG
ldx #S.MEM.F.INIT0+S.MEM.F.FD
jsr MEM.GetMem.YAX
bcs IO.OPEN.RTS
>STYA pFD
stx .8+1 save hFD
* ldy #S.FD.T Done by GetMem0
* lda #S.FD.T.REG
* sta (pFD),y
jsr STDIO.SetIOBUF
bcs .9
>MLICALL MLIOPEN
bcs .9
lda K.MLI.PARAMS+5 get ref_num
ldy #S.FD.REG.REF
sta (pFD),y
sta K.MLI.PARAMS+1 Next MLI Calls are REF_NUM based
lda K.Open.FLAGS
bit #O.WRONLY
beq .20 Write mode ?
and #O.APPEND 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
bra .21
.11 >MLICALL MLIGETEOF
bcs .9
>MLICALL MLISETMARK
.21 bcs .9
.20 lda K.Open.FLAGS
and #O.TEXT Text Mode ?
beq .8
lda #$FF
sta K.MLI.PARAMS+2
lda #C.CR
sta K.MLI.PARAMS+3
>MLICALL MLINEWLINE
bcs .9
.8 lda #$ff SELF MODIFIED
rts
.9 pha Save Error Code
lda .8+1
jsr K.Close
pla
sec
rts
*--------------------------------------
IO.OPEN.CDEV sta .1+1 A=DEVID
pha
jsr K.IOCTL.GetPDrv
ldx #IOCTL.OPEN
pla pass A=DEVID To Driver
jsr K.IOCTL.pDrvJmp
bcs .9
.1 ldx #$ff SELF MODIFIED
lda Dev.Table.hFD,x
.9 rts
*--------------------------------------
IO.OPEN.DSOCK
*--------------------------------------
IO.OPEN.SSOCK
*--------------------------------------
IO.OPEN.PIPE
clc
rts
*/--------------------------------------
* # close
* ## C
* `int close(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>SYSCALL close`
*\--------------------------------------
K.Close sta IO.hFD
jsr K.GetMemPtr
>STYA pFD
lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.CLOSE.REG
.DA IO.CLOSE.DIR
.DA IO.CLOSE.CDEV
.DA IO.CLOSE.BDEV
.DA STDIO.IOERR LNK
.DA IO.CLOSE.DSOCK
.DA IO.CLOSE.SSOCK
.DA IO.CLOSE.PIPE
*--------------------------------------
IO.CLOSE.REG
IO.CLOSE.DIR ldy #S.FD.REG.REF
lda (pFD),y
beq .1
sta K.MLI.PARAMS+1
>MLICALL MLICLOSE
.1 ldy #S.FD.REG.IOBUF
lda (pFD),y
beq .2
jsr K.FreeMem
.2 lda IO.hFD
jmp K.FreeMem
*--------------------------------------
IO.CLOSE.CDEV
IO.CLOSE.BDEV
*--------------------------------------
IO.CLOSE.DSOCK
IO.CLOSE.SSOCK
*--------------------------------------
IO.CLOSE.PIPE clc
rts
*/--------------------------------------
* # read
* ## C
* `int read(hFD fd, void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHWI count`
* `>PUSHW buf`
* `lda fd`
* `>SYSCALL read`
* ## RETURN VALUE
* CC: Y,A = bytes read
* CS: A = EC
*\--------------------------------------
K.Read sta IO.hFD
jsr K.GetMemPtr
>STYA pFD
IO.Read.I lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.READ.REG
.DA STDIO.IOERR DIR
.DA IO.READ.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
.DA IO.READ.SSOCK
.DA IO.READ.PIPE
*/--------------------------------------
* # write
* ## C
* `int write(hFD fd, const void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHWI count`
* `>PUSHW buf`
* `lda fd`
* `>SYSCALL write`
* ## RETURN VALUE
* CC: Y,A = bytes written
* CS: A = EC
*\--------------------------------------
K.Write sta IO.hFD
jsr K.GetMemPtr
>STYA pFD
IO.Write.I lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.WRITE.REG
.DA STDIO.IOERR DIR
.DA IO.WRITE.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
.DA IO.WRITE.SSOCK
.DA IO.WRITE.PIPE
*--------------------------------------
IO.READ.REG ldx #MLIREAD
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.REG ldx #MLIWRITE
ldy #S.FD.REG.REF
lda (pFD),y
sta K.MLI.PARAMS+1
>PULLW K.MLI.PARAMS+2
>PULLW K.MLI.PARAMS+4
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
jsr GP.MLICall
bcs .9
>LDYA K.MLI.PARAMS+6
.9 rts
*--------------------------------------
IO.READ.CDEV ldx #IOCTL.READ
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.CDEV ldx #IOCTL.WRITE
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
jsr K.IOCTL.GetPDRV
>LDYAI K.S.IOCTL
.1 jsr K.IOCTL.pDrvJmp
bcs .9
>LDYA K.S.IOCTL+S.IOCTL.BYTECNT
.9 rts
*--------------------------------------
IO.WRITE.SSOCK ldy #S.FD.SSOCK.WRITE
.HS 2C BIT ABS
*--------------------------------------
IO.READ.SSOCK ldy #S.FD.SSOCK.READ
lda (pFD),y
tax Function Offset in LIB
ldy #S.FD.SSOCK.IOHANDLER
lda (pFD),y
jsr K.GetMemPtr
>STYA .1+1
lda IO.hFD
.1 jmp $FFFF SELF MODIFIED
*--------------------------------------
IO.READ.PIPE >PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
ldy #S.FD.PIPE.S
lda (pFD),y
bit #S.FD.PIPE.S.WOpened
beq .9 Remote PS did not opened yet the pipe
bit #S.FD.PIPE.S.WClosed
beq .99 Remote PS closed the Pipe
ldy #S.FD.PIPE.hMem
lda (pFD),y
jsr K.GetMemPtr
clc
rts
.9 lda #MLI.E.VOLFULL
sec
rts
.99 lda #MLI.E.EOF
sec
rts
*--------------------------------------
IO.WRITE.PIPE >PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
ldy #S.FD.PIPE.S
lda (pFD),y
bit #S.FD.PIPE.S.ROpened
beq .9 Remote PS did not opened yet the pipe
bit #S.FD.PIPE.S.RClosed
beq .99 Remote PS closed the Pipe
ldy #S.FD.PIPE.hMem
lda (pFD),y
jsr K.GetMemPtr
>STYA .1+2
ldy #S.FD.PIPE.Head
lda (pFD),y
inc
dey #S.FD.PIPE.Tail
cmp (pFD),y
beq .9 PIPE is full
iny
sta (pFD),y
tay
lda K.IOBuf
.1 sta $ffff,y
clc
rts
.9 lda #MLI.E.VOLFULL
sec
rts
.99 lda #MLI.E.EOF
sec
rts
*/--------------------------------------
* # IOCTL
* ## C
* `int ioctl(short int hFD, int request, void * param );`
* ## ASM
* `PUSHWI param`
* `PUSHBI request`
* `lda hFD`
* `>SYSCALL IOCTL`
* ## RETURN VALUE
* Y,A = ...
*\--------------------------------------
K.IOCTL jsr K.GetMemPtr
bcs K.IOCTL.9
>STYA pFD
jsr K.IOCTL.GetPDrv
>PULLA
tax request
>PULLYA param
K.IOCTL.pDrvJmp jmp (pDrv)
K.IOCTL.9 lda #MLI.E.NODEV
>RET 3
*--------------------------------------
K.IOCTL.GetPDrv ldy #S.FD.DEV.DRVPTR
lda (pFD),y
sta pDRV
iny
lda (pFD),y
sta pDRV+1
rts
*/--------------------------------------
* # pipe
* ## C
* `int pipe(int pipefd[2]);`
* ## ASM
*\--------------------------------------
K.Pipe
.9 sec
rts
*--------------------------------------
IO.DEVDIR >PSTR "/DEV/"
IO.hFD .BS 1
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.IO
LOAD USR/SRC/SYS/KERNEL.S
ASM