mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-26 13:49:18 +00:00
299 lines
6.0 KiB
Plaintext
299 lines
6.0 KiB
Plaintext
NEW
|
||
PREFIX /A2OSX.BUILD
|
||
AUTO 4,1
|
||
*/--------------------------------------
|
||
* # open
|
||
* ## C
|
||
* `int open(const char *pathname, int flags);`
|
||
* ## ASM
|
||
* **In:**
|
||
* `>PUSHB flags`
|
||
* `>LDYA pathname`
|
||
* `>SYSCALL open`
|
||
* **Out:**
|
||
* A = hFD
|
||
* note : if file is created on ProDOS : T=TXT,X=$0000
|
||
*\--------------------------------------
|
||
K.Open jsr PFT.CheckPathYA check if not /mnt
|
||
|
||
K.Open.I jsr IO.SetMLIPathYA local pathname...
|
||
|
||
ldx #5 /DEV/
|
||
cpx K.MLI.PATH
|
||
bcs K.Open.REG
|
||
|
||
.1 lda K.MLI.PATH,x
|
||
cmp IO.DEVDIR,x
|
||
bne K.Open.REG
|
||
dex
|
||
bne .1
|
||
|
||
K.Open.DEV ldy #K.MLI.PATH+6 skip L/DEV/
|
||
lda /K.MLI.PATH+6
|
||
|
||
jsr K.GetDevByName
|
||
bcs .9
|
||
|
||
>STYA pFD
|
||
stx .8+1 DEVID
|
||
|
||
ldy #S.FD.DEV.DRVPTR
|
||
lda (pFD),y
|
||
sta .1+1
|
||
iny
|
||
lda (pFD),y
|
||
sta .1+2
|
||
|
||
>PULLA get flags
|
||
lda .8+1 pass A=DEVID To Driver
|
||
ldx #IOCTL.OPEN
|
||
.1 jsr $ffff SELF MODIFIED
|
||
bcs .99
|
||
|
||
.8 lda #$ff SELF MODIFIED
|
||
.99 rts
|
||
|
||
.9 >RET 1 discard flags
|
||
|
||
K.Open.REG >LDYAI K.MLI.PATH
|
||
>STYA K.MLI.PARAMS+1
|
||
|
||
lda (pStack)
|
||
* sta K.S.IOCTL
|
||
|
||
>RET 1
|
||
*--------------------------------------
|
||
* int close(int fd);
|
||
*--------------------------------------
|
||
K.Close jsr K.GetMemPtr
|
||
>STYA pFD
|
||
|
||
lda (pFD) #S.FD.T
|
||
tax
|
||
jmp (.1,x)
|
||
|
||
.1 .DA IO.CLOSE.REG
|
||
.DA STDIO.IOERR DIR
|
||
.DA IO.CLOSE.CDEV
|
||
.DA STDIO.IOERR BDEV
|
||
.DA STDIO.IOERR LNK
|
||
.DA STDIO.IOERR DSOCK
|
||
.DA IO.CLOSE.SSOCK
|
||
.DA IO.CLOSE.FIFO
|
||
*--------------------------------------
|
||
IO.CLOSE.REG
|
||
*--------------------------------------
|
||
IO.CLOSE.CDEV
|
||
*--------------------------------------
|
||
IO.CLOSE.SSOCK
|
||
*--------------------------------------
|
||
IO.CLOSE.FIFO clc
|
||
rts
|
||
*/--------------------------------------
|
||
* # read
|
||
* ## C
|
||
* `int read(int fd, void *buf, size_t count);`
|
||
*\--------------------------------------
|
||
K.Read jsr IO.SELECT
|
||
bcs K.Read.9
|
||
|
||
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
|
||
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
|
||
|
||
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.FIFO
|
||
|
||
K.Read.9 >RET 4
|
||
*--------------------------------------
|
||
* int write(int fd, const void *buf, size_t count);
|
||
*--------------------------------------
|
||
K.Write jsr IO.SELECT
|
||
bcs K.Write.9
|
||
|
||
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
|
||
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
|
||
|
||
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.FIFO
|
||
|
||
K.Write.9 >RET 4
|
||
*--------------------------------------
|
||
IO.READ.REG clc
|
||
.HS B0 BCS
|
||
*--------------------------------------
|
||
IO.WRITE.REG sec
|
||
>PUSHW K.S.IOCTL+S.IOCTL.BYTECNT
|
||
>PUSHW K.S.IOCTL+S.IOCTL.BUFPTR
|
||
ldy #S.FD.REG.REF
|
||
lda (pFD),y
|
||
bcs .1
|
||
|
||
jmp K.FRead
|
||
.1 jmp K.FWrite
|
||
*--------------------------------------
|
||
IO.READ.CDEV ldx #IOCTL.READ
|
||
.HS 2C BIT ABS
|
||
*--------------------------------------
|
||
IO.WRITE.CDEV ldx #IOCTL.WRITE
|
||
|
||
ldy #S.FD.DEV.DRVPTR
|
||
lda (pFD),y
|
||
sta .1+1
|
||
iny
|
||
lda (pFD),y
|
||
sta .1+2
|
||
|
||
>LDYAI K.S.IOCTL
|
||
|
||
.1 jmp $ffff
|
||
*--------------------------------------
|
||
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
|
||
>PUSHB (pFD),y
|
||
>PUSHB K.IOBuf
|
||
|
||
.1 jmp $ffff
|
||
*--------------------------------------
|
||
IO.READ.FIFO
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
IO.WRITE.FIFO ldy #S.FD.FIFO.S
|
||
lda (pFD),y
|
||
beq .9 Remote PS did not opened yet the pipe
|
||
cmp #S.FD.FIFO.S.Closed
|
||
beq .99 Remote PS closed the Pipe
|
||
|
||
ldy #S.FD.FIFO.hMem
|
||
lda (pFD),y
|
||
jsr K.GetMemPtr
|
||
>STYA .1+2
|
||
|
||
ldy #S.FD.FIFO.Head
|
||
lda (pFD),y
|
||
inc
|
||
dey #S.FD.FIFO.Tail
|
||
cmp (pFD),y
|
||
beq .9 FIFO is full
|
||
iny
|
||
sta (pFD),y
|
||
tay
|
||
lda K.IOBuf
|
||
.1 sta $ffff,y
|
||
clc
|
||
rts
|
||
|
||
.9 lda #MLI.E.VOLFULL
|
||
.HS 2C bit abs
|
||
.99 lda #MLI.E.EOF
|
||
sec
|
||
rts
|
||
*/--------------------------------------
|
||
* # IOCTL
|
||
* ## C
|
||
* `int ioctl(int devid, int request, void * param );`
|
||
* ## ASM
|
||
* **In:**
|
||
* `PUSHWI param`
|
||
* `PUSHBI request`
|
||
* `lda devid`
|
||
* `>SYSCALL IOCTL`
|
||
* **Out:**
|
||
* Y,A = ...
|
||
*\--------------------------------------
|
||
K.IOCTL jsr IO.SELECT
|
||
bcs .9
|
||
|
||
ldy #S.FD.DEV.DRVPTR
|
||
lda (pFD),y
|
||
sta .8+1
|
||
iny
|
||
lda (pFD),y
|
||
sta .8+2
|
||
|
||
>PULLA
|
||
tax request
|
||
|
||
>PULLYA param
|
||
|
||
|
||
.8 jmp $ffff SELF MODIFIED x = op
|
||
|
||
.9 >RET 3
|
||
*/--------------------------------------
|
||
* # pipe
|
||
* ## C
|
||
* `int pipe(int pipefd[2]);`
|
||
* ## ASM
|
||
* **In:**
|
||
*\--------------------------------------
|
||
IO.SELECT cmp DevMgr.DevCnt
|
||
bcs .9
|
||
|
||
tax
|
||
|
||
ldy FD.Table.PTRLO,x
|
||
lda FD.Table.PTRHI,x
|
||
>STYA pFD
|
||
rts
|
||
|
||
.9 lda #MLI.E.NODEV
|
||
rts
|
||
*--------------------------------------
|
||
IO.PullMLIPath >PULLYA
|
||
IO.SetMLIPathYA >STYA .1+1
|
||
|
||
ldx #0
|
||
|
||
.1 lda $ffff,x Self Modified
|
||
beq .8
|
||
inx
|
||
sta K.MLI.PATH,x
|
||
cpx #MLI.MAXPATH
|
||
bne .1
|
||
|
||
.8 stx K.MLI.PATH
|
||
inx
|
||
stz K.MLI.PATH,x
|
||
|
||
rts
|
||
*--------------------------------------
|
||
IO.DEVDIR >PSTR "/DEV/"
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SYS/KERNEL.S.IO
|
||
LOAD /A2OSX.SRC/SYS/KERNEL.S
|
||
ASM
|