A2osX/SYS/KERNEL.S.IO.txt

479 lines
9.5 KiB
Plaintext
Raw Normal View History

NEW
2018-11-17 17:17:13 +00:00
PREFIX
AUTO 4,1
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # open
* ## C
2018-10-04 15:30:14 +00:00
* `hFD open(const char *pathname, short int flags);`
2018-07-11 15:13:29 +00:00
* ## ASM
* **In:**
* `>PUSHB flags`
* `>LDYA pathname`
* `>SYSCALL open`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-07-11 15:13:29 +00:00
* A = hFD
2018-10-04 15:30:14 +00:00
* REG File created on ProDOS : T=TXT,X=$0000
2018-07-11 15:13:29 +00:00
*\--------------------------------------
2018-10-04 15:30:14 +00:00
K.Open.FLAGS .BS 1
K.Open.TYPE .BS 1
K.Open.AUXTYPE .BS 2
*--------------------------------------
2018-11-17 17:17:13 +00:00
K.Open jsr PFT.YAToMLIPATH
>PULLB K.Open.FLAGS
2018-10-08 05:55:28 +00:00
2018-10-04 15:30:14 +00:00
lda #S.FI.T.TXT
sta K.Open.TYPE
stz K.Open.AUXTYPE
stz K.Open.AUXTYPE+1
2018-10-08 05:55:28 +00:00
2018-11-16 16:04:20 +00:00
IO.Open.I ldx #5 $/DEV/
2018-07-11 15:13:29 +00:00
cpx K.MLI.PATH
2018-10-05 14:58:38 +00:00
bcs IO.OPEN.REG
2018-07-11 15:13:29 +00:00
.1 lda K.MLI.PATH,x
cmp IO.DEVDIR,x
2018-10-05 14:58:38 +00:00
bne IO.OPEN.REG
2018-07-11 15:13:29 +00:00
dex
bne .1
2018-09-05 15:22:46 +00:00
*--------------------------------------
2018-11-19 07:43:00 +00:00
* /DEV/xxxxxx (CDEV,BDEV,LNK,DSOCK,SSOCK,PIPE)
2018-10-04 15:30:14 +00:00
*--------------------------------------
2018-10-05 14:58:38 +00:00
>LDYAI K.MLI.PATH+6 skip $/DEV/
2018-07-11 15:13:29 +00:00
jsr K.GetDevByName
2018-11-01 08:53:47 +00:00
bcc .7
2018-07-11 15:13:29 +00:00
2018-11-01 08:53:47 +00:00
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
2018-11-19 07:43:00 +00:00
lda Nod.Table.hFD,x return hFD
2018-11-01 08:53:47 +00:00
clc
rts
.6 inx
cpx #K.NOD.MAX
bne .10
lda #MLI.E.NODEV
* sec
rts no OF found
.7 >STYA pFD
2018-11-19 07:43:00 +00:00
phx DEVID
2018-07-11 15:13:29 +00:00
2018-10-04 15:30:14 +00:00
lda (pFD) #S.FD.T
tax
2018-11-19 07:43:00 +00:00
pla hFILE
2018-11-01 08:53:47 +00:00
jmp (.8,x)
2018-10-04 15:30:14 +00:00
2018-11-01 08:53:47 +00:00
.8 .DA STDIO.IOERR REG
2018-10-04 15:30:14 +00:00
.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
2018-11-07 16:11:02 +00:00
ldx #2
.1 lda K.Open.TYPE,x
sta K.MLI.PARAMS+4,x File type,Aux type
dex
bpl .1
2018-10-04 15:30:14 +00:00
lda #S.FI.ST.STD
sta K.MLI.PARAMS+7
ldx #3
2018-11-07 16:11:02 +00:00
.2 lda DATELO,x
2018-10-04 15:30:14 +00:00
sta K.MLI.PARAMS+8,x
dex
2018-11-07 16:11:02 +00:00
bpl .2
2018-10-04 15:30:14 +00:00
>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
2018-11-07 16:11:02 +00:00
.8 lda #$ff SELF MODIFIED
2018-10-04 15:30:14 +00:00
rts
2018-11-07 16:11:02 +00:00
.9 pha Save Error Code
2018-10-04 15:30:14 +00:00
lda .8+1
2018-11-07 16:11:02 +00:00
jsr K.Close
2018-10-04 15:30:14 +00:00
pla
sec
rts
*--------------------------------------
2018-10-05 06:25:15 +00:00
IO.OPEN.CDEV sta .1+1 A=DEVID
pha
jsr K.IOCTL.GetPDrv
2018-07-12 15:20:39 +00:00
ldx #IOCTL.OPEN
2018-10-05 06:25:15 +00:00
pla pass A=DEVID To Driver
jsr K.IOCTL.pDrvJmp
2018-09-05 15:22:46 +00:00
bcs .9
2018-07-12 15:20:39 +00:00
2018-10-05 06:25:15 +00:00
.1 ldx #$ff SELF MODIFIED
2018-08-08 15:13:37 +00:00
lda Dev.Table.hFD,x
2018-09-05 15:22:46 +00:00
.9 rts
*--------------------------------------
2018-10-04 15:30:14 +00:00
IO.OPEN.DSOCK
*--------------------------------------
IO.OPEN.SSOCK
*--------------------------------------
IO.OPEN.PIPE
clc
rts
2018-08-27 15:26:01 +00:00
*/--------------------------------------
* # close
* ## C
* `int close(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>SYSCALL close`
*\--------------------------------------
2018-11-19 16:15:16 +00:00
K.Close sta IO.hFD
2018-10-04 15:30:14 +00:00
jsr K.GetMemPtr
2018-07-11 15:13:29 +00:00
>STYA pFD
2018-11-07 16:11:02 +00:00
lda (pFD) #S.FD.T
2018-07-11 15:13:29 +00:00
tax
jmp (.1,x)
.1 .DA IO.CLOSE.REG
2018-10-03 15:25:03 +00:00
.DA IO.CLOSE.DIR
2018-07-11 15:13:29 +00:00
.DA IO.CLOSE.CDEV
2018-10-04 15:30:14 +00:00
.DA IO.CLOSE.BDEV
2018-07-11 15:13:29 +00:00
.DA STDIO.IOERR LNK
2018-10-03 15:25:03 +00:00
.DA IO.CLOSE.DSOCK
2018-07-11 15:13:29 +00:00
.DA IO.CLOSE.SSOCK
2018-10-02 15:52:30 +00:00
.DA IO.CLOSE.PIPE
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
IO.CLOSE.REG
2018-11-19 16:15:16 +00:00
IO.CLOSE.DIR ldy #S.FD.REG.REF
2018-10-03 15:25:03 +00:00
lda (pFD),y
beq .1
sta K.MLI.PARAMS+1
>MLICALL MLICLOSE
.1 ldy #S.FD.REG.IOBUF
lda (pFD),y
2018-10-04 15:30:14 +00:00
beq .2
2018-10-03 15:25:03 +00:00
2018-10-04 15:30:14 +00:00
jsr K.FreeMem
2018-10-03 15:25:03 +00:00
2018-11-19 16:15:16 +00:00
.2 lda IO.hFD
2018-10-04 15:30:14 +00:00
jmp K.FreeMem
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
IO.CLOSE.CDEV
2018-10-04 15:30:14 +00:00
IO.CLOSE.BDEV
2018-07-11 15:13:29 +00:00
*--------------------------------------
2018-10-03 15:25:03 +00:00
IO.CLOSE.DSOCK
2018-07-11 15:13:29 +00:00
IO.CLOSE.SSOCK
*--------------------------------------
2018-10-02 15:52:30 +00:00
IO.CLOSE.PIPE clc
2018-07-18 15:30:42 +00:00
rts
*/--------------------------------------
* # read
* ## C
2018-08-27 15:26:01 +00:00
* `int read(hFD fd, void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHWI count`
* `>PUSHW buf`
* `lda fd`
* `>SYSCALL read`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-08-27 15:26:01 +00:00
* CC: Y,A = bytes read
* CS: A = EC
2018-07-18 15:30:42 +00:00
*\--------------------------------------
2018-11-19 16:15:16 +00:00
K.Read sta IO.hFD
2018-11-19 07:43:00 +00:00
jsr K.GetMemPtr
2018-08-08 15:13:37 +00:00
>STYA pFD
2018-07-19 15:33:55 +00:00
IO.Read.I lda (pFD) #S.FD.T
2018-07-18 15:30:42 +00:00
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
2018-10-02 15:52:30 +00:00
.DA IO.READ.PIPE
2018-08-27 15:26:01 +00:00
*/--------------------------------------
* # write
* ## C
* `int write(hFD fd, const void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHWI count`
* `>PUSHW buf`
* `lda fd`
* `>SYSCALL write`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-08-27 15:26:01 +00:00
* CC: Y,A = bytes written
* CS: A = EC
*\--------------------------------------
2018-11-19 16:15:16 +00:00
K.Write sta IO.hFD
2018-11-19 07:43:00 +00:00
jsr K.GetMemPtr
2018-08-08 15:13:37 +00:00
>STYA pFD
2018-07-19 15:33:55 +00:00
IO.Write.I lda (pFD) #S.FD.T
2018-06-19 05:55:12 +00:00
tax
jmp (.1,x)
2018-07-11 15:13:29 +00:00
2018-06-19 15:08:22 +00:00
.1 .DA IO.WRITE.REG
2018-06-19 05:55:12 +00:00
.DA STDIO.IOERR DIR
2018-06-19 15:08:22 +00:00
.DA IO.WRITE.CDEV
2018-06-19 05:55:12 +00:00
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
2018-06-19 15:08:22 +00:00
.DA IO.WRITE.SSOCK
2018-10-02 15:52:30 +00:00
.DA IO.WRITE.PIPE
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-08-08 15:13:37 +00:00
IO.READ.REG ldx #MLIREAD
.HS 2C BIT ABS
2018-07-24 16:00:24 +00:00
*--------------------------------------
2018-08-08 15:13:37 +00:00
IO.WRITE.REG ldx #MLIWRITE
2018-10-04 06:13:44 +00:00
2018-07-10 15:33:13 +00:00
ldy #S.FD.REG.REF
2018-07-24 16:00:24 +00:00
lda (pFD),y
2018-08-08 15:13:37 +00:00
sta K.MLI.PARAMS+1
2018-10-03 15:25:03 +00:00
>PULLW K.MLI.PARAMS+2
>PULLW K.MLI.PARAMS+4
2018-08-08 15:13:37 +00:00
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
jsr GP.MLICall
2018-11-08 14:23:06 +00:00
bcs .9
2018-09-06 15:36:44 +00:00
>LDYA K.MLI.PARAMS+6
2018-11-08 14:23:06 +00:00
.9 rts
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-07-24 16:00:24 +00:00
IO.READ.CDEV ldx #IOCTL.READ
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.CDEV ldx #IOCTL.WRITE
2018-10-03 15:25:03 +00:00
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
2018-09-06 15:36:44 +00:00
jsr K.IOCTL.GetPDRV
2018-06-19 05:55:12 +00:00
2018-07-13 14:38:24 +00:00
>LDYAI K.S.IOCTL
2018-07-24 16:00:24 +00:00
2018-09-06 15:36:44 +00:00
.1 jsr K.IOCTL.pDrvJmp
2018-08-27 15:26:01 +00:00
bcs .9
>LDYA K.S.IOCTL+S.IOCTL.BYTECNT
.9 rts
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-10-08 15:41:00 +00:00
IO.WRITE.SSOCK ldy #S.FD.SSOCK.WRITE
2018-07-24 16:00:24 +00:00
.HS 2C BIT ABS
*--------------------------------------
2018-11-19 16:15:16 +00:00
IO.READ.SSOCK ldy #S.FD.SSOCK.READ
2018-07-24 16:00:24 +00:00
lda (pFD),y
tax Function Offset in LIB
2018-11-19 07:43:00 +00:00
ldy #S.FD.SSOCK.IOHANDLER
2018-07-24 16:00:24 +00:00
lda (pFD),y
2018-06-21 15:12:10 +00:00
jsr K.GetMemPtr
2018-11-19 16:15:16 +00:00
>STYA .1+1
2018-06-19 05:55:12 +00:00
2018-11-19 16:15:16 +00:00
lda IO.hFD
.1 jmp $FFFF SELF MODIFIED
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-10-03 15:25:03 +00:00
IO.READ.PIPE >PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
ldy #S.FD.PIPE.S
2018-10-02 15:52:30 +00:00
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
2018-07-24 16:00:24 +00:00
clc
rts
2018-10-02 15:52:30 +00:00
.9 lda #MLI.E.VOLFULL
sec
rts
.99 lda #MLI.E.EOF
sec
rts
2018-07-24 16:00:24 +00:00
*--------------------------------------
2018-10-03 15:25:03 +00:00
IO.WRITE.PIPE >PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
ldy #S.FD.PIPE.S
2018-07-10 15:33:13 +00:00
lda (pFD),y
2018-10-02 15:52:30 +00:00
bit #S.FD.PIPE.S.ROpened
2018-06-19 05:55:12 +00:00
beq .9 Remote PS did not opened yet the pipe
2018-10-02 15:52:30 +00:00
bit #S.FD.PIPE.S.RClosed
2018-06-19 05:55:12 +00:00
beq .99 Remote PS closed the Pipe
2018-10-02 15:52:30 +00:00
ldy #S.FD.PIPE.hMem
2018-07-10 15:33:13 +00:00
lda (pFD),y
2018-06-21 15:12:10 +00:00
jsr K.GetMemPtr
2018-06-19 05:55:12 +00:00
>STYA .1+2
2018-10-02 15:52:30 +00:00
ldy #S.FD.PIPE.Head
2018-07-10 15:33:13 +00:00
lda (pFD),y
2018-06-19 05:55:12 +00:00
inc
2018-10-02 15:52:30 +00:00
dey #S.FD.PIPE.Tail
2018-07-10 15:33:13 +00:00
cmp (pFD),y
2018-10-02 15:52:30 +00:00
beq .9 PIPE is full
2018-06-19 05:55:12 +00:00
iny
2018-07-10 15:33:13 +00:00
sta (pFD),y
2018-06-19 05:55:12 +00:00
tay
lda K.IOBuf
.1 sta $ffff,y
clc
rts
.9 lda #MLI.E.VOLFULL
2018-10-02 15:52:30 +00:00
sec
rts
2018-06-19 05:55:12 +00:00
.99 lda #MLI.E.EOF
sec
rts
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # IOCTL
* ## C
2018-08-08 15:13:37 +00:00
* `int ioctl(short int hFD, int request, void * param );`
2018-07-11 15:13:29 +00:00
* ## ASM
* `PUSHWI param`
2018-07-19 15:33:55 +00:00
* `PUSHBI request`
2018-08-08 15:13:37 +00:00
* `lda hFD`
2018-07-11 15:13:29 +00:00
* `>SYSCALL IOCTL`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-07-11 15:13:29 +00:00
* Y,A = ...
*\--------------------------------------
2018-08-08 15:13:37 +00:00
K.IOCTL jsr K.GetMemPtr
2018-10-24 15:36:45 +00:00
bcs K.IOCTL.9
2018-07-11 15:13:29 +00:00
2018-08-08 15:13:37 +00:00
>STYA pFD
2018-09-07 14:12:42 +00:00
jsr K.IOCTL.GetPDrv
2018-09-06 15:36:44 +00:00
2018-07-19 15:33:55 +00:00
>PULLA
tax request
>PULLYA param
2018-10-24 15:36:45 +00:00
K.IOCTL.pDrvJmp jmp (pDrv)
2018-07-11 15:13:29 +00:00
2018-10-24 15:36:45 +00:00
K.IOCTL.9 lda #MLI.E.NODEV
2018-08-08 15:13:37 +00:00
>RET 3
2018-09-06 15:36:44 +00:00
*--------------------------------------
K.IOCTL.GetPDrv ldy #S.FD.DEV.DRVPTR
lda (pFD),y
sta pDRV
iny
lda (pFD),y
sta pDRV+1
rts
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # pipe
* ## C
* `int pipe(int pipefd[2]);`
* ## ASM
2018-08-08 15:13:37 +00:00
*\--------------------------------------
K.Pipe
.9 sec
2018-07-12 15:20:39 +00:00
rts
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
IO.DEVDIR >PSTR "/DEV/"
2018-11-19 16:15:16 +00:00
IO.hFD .BS 1
2018-07-11 15:13:29 +00:00
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.IO
LOAD USR/SRC/SYS/KERNEL.S
ASM