A2osX/SYS/KERNEL.S.IO.txt
2018-10-11 17:23:06 +02:00

453 lines
9.1 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 /A2OSX.BUILD
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 pha
>PULLB K.Open.FLAGS
lda #S.FI.T.TXT
sta K.Open.TYPE
stz K.Open.AUXTYPE
stz K.Open.AUXTYPE+1
pla
IO.Open.I jsr STDIO.SetMLIPathYA
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,DSOCK,SSOCK,PIPE)
*--------------------------------------
>LDYAI K.MLI.PATH+6 skip $/DEV/
jsr K.GetDevByName
bcs IO.OPEN.RTS
>STYA pFD
phx DEVID
lda (pFD) #S.FD.T
tax
pla
jmp (.2,x)
.2 .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
lda K.Open.TYPE
sta K.MLI.PARAMS+4 File type
>LDYA K.Open.AUXTYPE
>STYA K.MLI.PARAMS+5 Aux type
lda #S.FI.ST.STD
sta K.MLI.PARAMS+7
ldx #3
.1 lda DATELO,x
sta K.MLI.PARAMS+8,x
dex
bpl .1
>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
rts
.9 pha
lda .8+1
pha
jsr IO.Close.I
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 pha save hFD
jsr K.GetMemPtr
>STYA pFD
IO.Close.I lda (pFD) #S.FD.T
tax
pla
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 pha save hFD
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 pla
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 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 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
>LDYA K.MLI.PARAMS+6
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.HANDLER
lda (pFD),y
jsr K.GetMemPtr
>STYA .1
ldy #S.FD.SSOCK.HSKT
lda (pFD),y
.1 jmp $ffff
*--------------------------------------
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 .9
>STYA pFD
jsr K.IOCTL.GetPDrv
>PULLA
tax request
>PULLYA param
jmp (pDRV) SELF MODIFIED x = op
.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
K.IOCTL.pDrvJmp jmp (pDrv)
*/--------------------------------------
* # pipe
* ## C
* `int pipe(int pipefd[2]);`
* ## ASM
*\--------------------------------------
K.Pipe
.9 sec
rts
*--------------------------------------
IO.DEVDIR >PSTR "/DEV/"
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.IO
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM