A2osX/SYS/KERNEL.S.UNISTD.txt

463 lines
9.3 KiB
Plaintext
Raw Normal View History

2019-07-27 20:51:39 +00:00
NEW
AUTO 3,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
*\--------------------------------------
.DUMMY
.OR ZPTMP+20 7 Bytes
IO.Open.FLAGS .BS 1
IO.Open.TYPE .BS 1
IO.Open.AUXTYPE .BS 2
IO.hFD .BS 1
.ED
*--------------------------------------
K.Open jsr PFT.YAToMLIPATH
>PULLB IO.Open.FLAGS
lda #S.FI.T.TXT
sta IO.Open.TYPE
stz IO.Open.AUXTYPE
stz IO.Open.AUXTYPE+1
*--------------------------------------
2020-03-16 06:50:15 +00:00
UNISTD.Open jsr UNISTD.CheckDev
2019-07-29 20:59:00 +00:00
bcs IO.OPEN.REG
2019-07-27 20:51:39 +00:00
*--------------------------------------
2020-03-16 06:50:15 +00:00
* /DEV/xxxxxx (CDEV,BDEV,DSOCK,SSOCK,PIPE)
2019-07-27 20:51:39 +00:00
*--------------------------------------
>LDYAI K.MLI.PATH+6 skip $/DEV/
2020-03-13 16:10:36 +00:00
jsr K.GetDevByName
2019-07-27 20:51:39 +00:00
bcc .7
2020-03-11 16:41:45 +00:00
2019-07-27 20:51:39 +00:00
ldx #2
.10 lda Nod.Table.hPath-2,x
beq .3
jsr K.GetMemPtr
>STYA ZPPtr1
2020-03-13 16:10:36 +00:00
2019-07-27 20:51:39 +00:00
ldy #0
2020-03-13 16:10:36 +00:00
2019-07-27 20:51:39 +00:00
.2 lda (ZPPtr1),y
iny
cmp K.MLI.PATH,y
bne .3
2020-03-13 16:10:36 +00:00
2019-07-27 20:51:39 +00:00
cmp #0 end of string ?
2020-03-13 16:10:36 +00:00
2019-07-27 20:51:39 +00:00
bne .2
2020-03-13 16:10:36 +00:00
2019-07-27 20:51:39 +00:00
lda Nod.Table.hFD-2,x return hFD
2019-07-31 15:10:59 +00:00
jsr UNISTD.GetPFD
2019-07-27 20:51:39 +00:00
bra .71
2020-03-10 16:42:07 +00:00
2019-07-27 20:51:39 +00:00
.3 inx
cpx #K.NOD.MAX+2
bne .10
2020-03-10 16:42:07 +00:00
2019-07-27 20:51:39 +00:00
lda #MLI.E.NODEV
2019-10-03 06:25:27 +00:00
* sec
2019-07-27 20:51:39 +00:00
rts no OF found
2020-03-11 16:41:45 +00:00
*--------------------------------------
.7 stx IO.hFD
2019-07-27 20:51:39 +00:00
>STYA pFD
2020-03-10 16:42:07 +00:00
2019-07-27 20:51:39 +00:00
.71 lda (pFD) #S.FD.T
tax
2020-05-04 20:46:21 +00:00
2020-03-16 06:50:15 +00:00
jmp (.8-2,x)
2019-10-03 06:25:27 +00:00
.8
2019-07-29 15:38:55 +00:00
* .DA STDIO.IOERR REG
2020-03-16 06:50:15 +00:00
.DA STDIO.IOERR DIR
2019-07-27 20:51:39 +00:00
.DA IO.OPEN.CDEV
.DA IO.OPEN.BDEV
.DA STDIO.IOERR LNK
.DA IO.OPEN.DSOCK
.DA IO.OPEN.SSOCK
.DA IO.OPEN.PIPE
2019-07-29 15:38:55 +00:00
*--------------------------------------
IO.OPEN.REG >MLICALL MLIGETFILEINFO
bcc IO.OPEN.REG.E Already Exists
2020-03-13 16:10:36 +00:00
2019-07-29 15:38:55 +00:00
bit IO.Open.FLAGS Create if not exists ?
bpl IO.OPEN.RTS No, return MLI error
2019-10-29 14:47:25 +00:00
2019-07-29 15:38:55 +00:00
ldx #2 Yes, Create...
2020-03-13 16:10:36 +00:00
2019-07-29 15:38:55 +00:00
.1 lda IO.Open.TYPE,x
sta K.MLI.PARAMS+4,x File type,Aux type
dex
bpl .1
lda #S.FI.ST.STD
jsr IO.MLI.CREATE
bcs IO.OPEN.RTS
IO.OPEN.REG.E ldx #0
jsr IO.MkFD
bcs IO.OPEN.RTS
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
jsr IO.MLI.OPEN
2020-03-10 16:42:07 +00:00
bcs UNISTD.Open.ERR
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
lda IO.Open.FLAGS
bit #O.WRONLY
beq .20 Write mode ?
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
and #O.APPEND Append ?
bne .11 yes, go to end of file
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
stz K.MLI.PARAMS+2
stz K.MLI.PARAMS+3
stz K.MLI.PARAMS+4
>MLICALL MLISETEOF no, reset size to 0
bra .21
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
.11 >MLICALL MLIGETEOF
2020-03-10 16:42:07 +00:00
bcs UNISTD.Open.ERR
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
>MLICALL MLISETMARK
2020-03-10 16:42:07 +00:00
.21 bcs UNISTD.Open.ERR
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
.20 lda IO.Open.FLAGS
and #O.TEXT Text Mode ?
beq .8
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
lda #$FF
sta K.MLI.PARAMS+2
lda #C.CR
sta K.MLI.PARAMS+3
>MLICALL MLINEWLINE
2020-03-10 16:42:07 +00:00
bcs UNISTD.Open.ERR
2020-03-11 16:41:45 +00:00
2019-07-29 15:38:55 +00:00
.8 lda IO.hFD
IO.OPEN.RTS rts
2020-03-10 16:42:07 +00:00
UNISTD.Open.ERR pha Save Error Code
2019-07-29 15:38:55 +00:00
lda IO.hFD
jsr K.Close
pla
sec
rts
2019-07-27 20:51:39 +00:00
*/--------------------------------------
* # close
* ## C
* `int close(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>SYSCALL close`
*\--------------------------------------
2019-07-31 15:10:59 +00:00
K.Close jsr UNISTD.GetPFD
2019-07-27 20:51:39 +00:00
UNISTD.Close 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
*/--------------------------------------
* # 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
*\--------------------------------------
2019-07-31 15:10:59 +00:00
K.Read jsr UNISTD.GetPFD
2020-02-16 20:45:16 +00:00
2019-07-27 20:51:39 +00:00
UNISTD.Read 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
*\--------------------------------------
2019-07-31 15:10:59 +00:00
K.Write jsr UNISTD.GetPFD
2019-07-27 20:51:39 +00:00
UNISTD.Write 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
*--------------------------------------
2019-07-31 15:10:59 +00:00
UNISTD.GetPFD sta IO.hFD
jsr K.GetMemPtr
>STYA pFD
rts
*--------------------------------------
2020-03-16 06:50:15 +00:00
UNISTD.CheckDev ldx #5 /DEV/
cpx K.MLI.PATH
bcs .99
.1 lda K.MLI.PATH,x
cmp DEV.FIFO-1,x
bne .9
dex
bne .1
clc
rts
.9 sec
.99 rts
*--------------------------------------
2020-03-17 06:23:07 +00:00
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.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
IO.WRITE.REG.RTS
rts
*--------------------------------------
IO.OPEN.CDEV
IO.OPEN.BDEV jsr SHARED.GetPDrv
ldx #IOCTL.OPEN
lda IO.hFD
jsr SHARED.pDrvJmp
bcs IO.WRITE.REG.RTS
2020-05-04 20:46:21 +00:00
*--------------------------------------
IO.OPEN.DSOCK
*--------------------------------------
IO.OPEN.SSOCK
2020-03-17 06:23:07 +00:00
lda IO.hFD
*--------------------------------------
IO.CLOSE.CDEV
IO.CLOSE.BDEV
clc
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
2020-05-04 20:46:21 +00:00
jsr SHARED.GetPDrv
2020-03-17 06:23:07 +00:00
>LDYAI K.S.IOCTL
jsr SHARED.pDrvJmp
bcs .9
>LDYA K.S.IOCTL+S.IOCTL.BYTECNT
.9 rts
*--------------------------------------
IO.CLOSE.DSOCK
IO.CLOSE.SSOCK
ldy #S.FD.SSOCK.CLOSE
.HS 2C BIT ABS
*--------------------------------------
IO.EOF.SSOCK ldy #S.FD.SSOCK.EOF
.HS 2C BIT ABS
*--------------------------------------
IO.READ.SSOCK ldy #S.FD.SSOCK.READ
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.SSOCK ldy #S.FD.SSOCK.WRITE
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.EOF.REG >MLICALL MLIGETMARK
bcs .9
ldy #2
.1 lda K.MLI.PARAMS+2,y
sta ACC32,y
dey
bpl .1
>MLICALL MLIGETEOF
bcs .9
ldy #2
.2 lda K.MLI.PARAMS+2,y
eor ACC32,y
bne .8 FALSE
dey
bpl .2
lda #$ff TRUE
* clc
rts
.8 lda #0
* clc
.9 rts
*--------------------------------------
IO.EOF.CDEV lda #S.IOCTL.STATCODE.EOF
jmp SHARED.GetDevStatus
*--------------------------------------
* X = 0 > REG
* X = 1 > DIR
* X = 2 > PIPE
*--------------------------------------
IO.MkFD stx .8+1
ldy IO.MkFD.Y,x
lda #0
ldx #S.MEM.F.INIT0+S.MEM.F.FD
jsr MEM.GetMem.YAX
bcs .9
>STYA pFD
stx IO.hFD
.8 ldx #$ff SELF MODIFIED
lda IO.MkFD.T,x
sta (pFD) X = hFD, A = T
* clc
.9 rts
IO.MkFD.Y .DA #S.FD.REG,#S.FD.DIR,#S.FD.PIPE
IO.MkFD.T .DA #S.FD.T.REG,#S.FD.T.DIR,#S.FD.T.PIPE
*--------------------------------------
IO.MLI.CREATE sta K.MLI.PARAMS+7 Storage Type
ldx #3
.1 lda DATELO,x
sta K.MLI.PARAMS+8,x Create Date/Time
dex
bpl .1
lda #S.FI.A.FULL
sta K.MLI.PARAMS+3 Access
>MLICALL MLICREATE
rts
*--------------------------------------
IO.MLI.OPEN >LDYAI 1024 get a ProDOS IOBUF
ldx #S.MEM.F.ALIGN
jsr MEM.GetMem.YAX
bcs .9
>STYA K.MLI.PARAMS+3 Save Ptr to IOBUF for MLIOPEN call
txa
ldy #S.FD.REG.IOBUF
sta (pFD),y
>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
* clc
.9 rts
*--------------------------------------
IO.CLOSE.NOD ldx #2
lda IO.hFD
.1 cmp Nod.Table.hFD-2,x
bne .2
stz Nod.Table.hFD-2,x
lda Nod.Table.hPath-2,x
stz Nod.Table.hPath-2,x
jmp K.FreeMem
.2 inx
cpx #K.Nod.MAX+2
bne .1
lda #E.INVH
* sec
rts
2020-03-11 06:40:01 +00:00
*/--------------------------------------
* # ChOwn
* ## C
* `short int chown(const char *pathname, short int owner, short int group);`
* ## ASM
* **In:**
* `>PUSHW pathname`
* `>PUSHB owner`
* `>PUSHB group`
* `>SYSCALL chown`
* ## RETURN VALUE
*\--------------------------------------
K.ChOwn clc
rts
2020-02-16 20:45:16 +00:00
*--------------------------------------
2019-07-27 20:51:39 +00:00
MAN
SAVE USR/SRC/SYS/KERNEL.S.UNISTD
LOAD USR/SRC/SYS/KERNEL.S
ASM