mirror of
https://github.com/A2osX/A2osX.git
synced 2024-08-15 04:29:35 +00:00
252 lines
5.1 KiB
Plaintext
252 lines
5.1 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
|
||
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
|
||
*--------------------------------------
|
||
* int read(int fd, void *buf, size_t count);
|
||
*--------------------------------------
|
||
K.Read
|
||
*--------------------------------------
|
||
* 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
|
||
|
||
K.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.WRITE.REG >PUSHW K.S.IOCTL+S.IOCTL.BUFPTR
|
||
>PUSHW K.S.IOCTL+S.IOCTL.BYTECNT
|
||
ldy #S.FD.REG.REF
|
||
>PUSHB (pFD),y
|
||
|
||
jmp K.FWrite
|
||
*--------------------------------------
|
||
IO.WRITE.CDEV ldy #S.FD.DEV.DRVPTR
|
||
lda (pFD),y
|
||
sta .1+1
|
||
iny
|
||
lda (pFD),y
|
||
sta .1+2
|
||
|
||
>LDYAI K.S.IOCTL
|
||
ldx #IOCTL.WRITE
|
||
.1 jmp $ffff
|
||
*--------------------------------------
|
||
IO.WRITE.SSOCK lda (pFD) #S.FD.HANDLER
|
||
jsr K.GetMemPtr
|
||
>STYA .1
|
||
|
||
ldy #S.FD.SSOCK.HSKT
|
||
>PUSHB (pFD),y
|
||
>PUSHB K.IOBuf
|
||
|
||
ldy #S.FD.SSOCK.WRITE
|
||
lda (pFD),y
|
||
tax Function Offset for write
|
||
.1 jmp $ffff
|
||
*--------------------------------------
|
||
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 fd, unsigned long request, void * param );`
|
||
* ## ASM
|
||
* **In:**
|
||
* `PUSHWI param`
|
||
* `lda #request`
|
||
* `ldy fd`
|
||
* `>SYSCALL IOCTL`
|
||
* **Out:**
|
||
* Y,A = ...
|
||
*\--------------------------------------
|
||
K.IOCTL tax op
|
||
>PULLB .1+1 param LO
|
||
>PULLB .2+1 param HI
|
||
|
||
tya id
|
||
|
||
jsr K.GetDevByID
|
||
bcs K.IOCTL.9
|
||
|
||
>STYA pFD
|
||
|
||
.1 ldy #$ff SELF MODIFIED
|
||
.2 lda #$ff SELF MODIFIED
|
||
|
||
jmp (pFD) x = op
|
||
|
||
K.IOCTL.9 rts
|
||
*/--------------------------------------
|
||
* # 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
|