Kernel 0.93+

This commit is contained in:
Rémy GIBERT 2019-07-27 22:51:39 +02:00
parent 68807d8ceb
commit 0a0c267939
9 changed files with 578 additions and 576 deletions

Binary file not shown.

View File

@ -153,8 +153,8 @@ O.TEXT .EQ %01000000
O.CREATE .EQ %10000000
*--------------------------------------
SEEK.SET .EQ $00
SEEK.CUR .EQ $02
SEEK.END .EQ $04
SEEK.CUR .EQ $01
SEEK.END .EQ $02
*--------------------------------------
* A2osX.SYSCALL Functions Indexes
*--------------------------------------

View File

@ -1,111 +1,16 @@
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 9 Bytes
K.Open.FLAGS .BS 1
K.Open.TYPE .BS 1
K.Open.AUXTYPE .BS 2
IO.hDev .BS 1
IO.hFD .BS 1
IO.hFILE .BS 1
IO.Counter .BS 2
.ED
*--------------------------------------
K.Open jsr PFT.YAToMLIPATH
>PULLB K.Open.FLAGS
lda #S.FI.T.TXT
sta K.Open.TYPE
stz K.Open.AUXTYPE
stz K.Open.AUXTYPE+1
IO.Open.I ldx #5 /DEV/
cpx K.MLI.PATH
bcs IO.OPEN.REG
.1 lda K.MLI.PATH,x
cmp IO.DEVDIR-1,x
bne IO.OPEN.REG
dex
bne .1
*--------------------------------------
* /DEV/xxxxxx (CDEV,BDEV,LNK,DSOCK,SSOCK,PIPE)
*--------------------------------------
>LDYAI K.MLI.PATH+6 skip $/DEV/
jsr K.GetDevByName
bcc .7
ldx #2
.10 lda Nod.Table.hPath-2,x
beq .3
jsr K.GetMemPtr
>STYA ZPPtr1
ldy #0
.2 lda (ZPPtr1),y
iny
cmp K.MLI.PATH,y
bne .3
cmp #0 end of string ?
bne .2
lda Nod.Table.hFD-2,x return hFD
jsr IO.GetPFD
bra .71
.3 inx
cpx #K.NOD.MAX+2
bne .10
lda #MLI.E.NODEV
* sec
rts no OF found
.7 stx IO.hDev
>STYA pFD
.71 lda (pFD) #S.FD.T
tax
jmp (.8,x)
.8 .DA STDIO.IOERR REG
.DA STDIO.IOERR DIR
.DA IO.OPEN.CDEV
.DA IO.OPEN.BDEV
.DA STDIO.IOERR LNK
.DA IO.OPEN.DSOCK
.DA IO.OPEN.SSOCK
.DA IO.OPEN.PIPE
IO.OPEN.RTS rts
*--------------------------------------
IO.OPEN.REG >MLICALL MLIGETFILEINFO
bcc IO.OPEN.REG.E Already Exists
bit K.Open.FLAGS Create if not exists ?
bit IO.Open.FLAGS Create if not exists ?
bpl IO.OPEN.RTS No, return MLI error
ldx #2 Yes, Create...
.1 lda K.Open.TYPE,x
.1 lda IO.Open.TYPE,x
sta K.MLI.PARAMS+4,x File type,Aux type
dex
bpl .1
@ -122,7 +27,7 @@ IO.OPEN.REG.E ldx #0
jsr IO.MLI.OPEN
bcs IO.OPEN.ERR
lda K.Open.FLAGS
lda IO.Open.FLAGS
bit #O.WRONLY
beq .20 Write mode ?
@ -141,7 +46,7 @@ IO.OPEN.REG.E ldx #0
>MLICALL MLISETMARK
.21 bcs IO.OPEN.ERR
.20 lda K.Open.FLAGS
.20 lda IO.Open.FLAGS
and #O.TEXT Text Mode ?
beq .8
@ -153,7 +58,7 @@ IO.OPEN.REG.E ldx #0
bcs IO.OPEN.ERR
.8 lda IO.hFD
rts
IO.OPEN.RTS rts
IO.OPEN.ERR pha Save Error Code
lda IO.hFD
@ -174,39 +79,11 @@ IO.OPEN.BDEV jsr K.IOCTL.GetPDrv
.9 rts
*--------------------------------------
IO.OPEN.PIPE ldy #S.FD.PIPE.S
lda (pFD),y
inc
sta (pFD),y
*--------------------------------------
IO.OPEN.DSOCK
*--------------------------------------
IO.OPEN.SSOCK lda IO.hFD
clc
rts
*/--------------------------------------
* # close
* ## C
* `int close(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>SYSCALL close`
*\--------------------------------------
K.Close jsr IO.GetPFD
IO.Close.I 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
*--------------------------------------
IO.CLOSE.REG
IO.CLOSE.DIR ldy #S.FD.REG.REF
@ -244,33 +121,6 @@ IO.CLOSE.SSOCK
.1 jmp $FFFF SELF MODIFIED
*--------------------------------------
IO.CLOSE.PIPE ldy #S.FD.PIPE.S
lda (pFD),y
bmi .1 remote PS closed its end
lda #$80
sta (pFD),y
clc
rts
.1 jsr IO.CLOSE.NOD
ldy #S.FD.PIPE.hMem
lda (pFD),y
beq .2
.DO AUXPIPE=1
ldx #SYS.FreeStkObj
jsr K.SYSCALL2.AUX
.ELSE
jsr K.FreeMem
.FIN
.2 lda IO.hFD
jmp K.FreeMem
*--------------------------------------
IO.CLOSE.NOD ldx #2
lda IO.hFD
@ -291,62 +141,6 @@ IO.CLOSE.NOD ldx #2
lda #E.INVH
* sec
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 IO.GetPFD
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 IO.GetPFD
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
@ -399,301 +193,6 @@ IO.READ.SSOCK ldy #S.FD.SSOCK.READ
.1 jmp $FFFF SELF MODIFIED
*--------------------------------------
IO.READ.PIPE ldy #S.FD.PIPE.Used+1
lda (pFD),y Data ?
dey
ora (pFD),y
bne .10 yes...
ldy #S.FD.PIPE.S
lda (pFD),y
bpl .11
jmp IO.READ.PIPE.EOF Remote PS closed the Pipe
.11 jmp IO.READ.PIPE.NODATA
.10 >PULLW .3+1 get buf
>PULLA get cnt lo
pha
ldy #S.FD.PIPE.Used
cmp (pFD),y
>PULLA get cnt hi
tax
iny
sbc (pFD),y
pla A,X = cnt
bcc .12 cnt < Used
lda (pFD),y
tax
dey
lda (pFD),y A,X = Used
.12 sta .80+1
stx .81+1
eor #$ff
sta IO.Counter
txa
eor #$ff
sta IO.Counter+1
ldy #S.FD.PIPE.Free
clc
lda (pFD),y
adc .80+1
sta (pFD),y
iny
lda (pFD),y
adc .81+1
sta (pFD),y
iny #S.FD.PIPE.Used
sec
lda (pFD),y
sbc .80+1
sta (pFD),y
iny
lda (pFD),y
sbc .81+1
sta (pFD),y
ldy #S.FD.PIPE.Size+1
lda (pFD),y
sta .5+1 Page Count
ldy #S.FD.PIPE.hMem
lda (pFD),y
.DO AUXPIPE=1
ldx #SYS.GetStkObjPtr
jsr K.SYSCALL2.AUX
.ELSE
jsr K.GetMemPtr
.FIN
sty .2+1
sta .7+1 Pipe Buffer Base
ldy #S.FD.PIPE.Tail+1
clc
adc (pFD),y
sta .2+2
dey S.FD.PIPE.Tail
lda (pFD),y
tay
ldx #0
.13 .DO AUXPIPE=1
sta SETREADAUX
.FIN
.1 inc IO.Counter
bne .2
inc IO.Counter+1
beq .8
.2 lda $ffff,y SELF MODIFIED
.3 sta $ffff,x SELF MODIFIED
inx
bne .4
inc .3+2
.4 iny
bne .1
.DO AUXPIPE=1
sta CLRREADAUX
.FIN
ldy #S.FD.PIPE.Tail+1
lda (pFD),y
inc
.5 cmp #$ff SELF MODIFIED
beq .6
sta (pFD),y
inc .2+2
ldy #0
bra .13
.6 lda #0
sta (pFD),y
.7 lda #$ff SELF MODIFIED
sta .2+2 Restore Pipe Buf base
ldy #0
bra .13
.8 .DO AUXPIPE=1
sta CLRREADAUX
.FIN
tya
ldy #S.FD.PIPE.Tail
sta (pFD),y
.80 ldy #$ff SELF MODIFIED
.81 lda #$ff Y,A = bytes read
clc
rts
IO.READ.PIPE.EOF
lda #MLI.E.EOF
.HS 2C BIT ABS
IO.READ.PIPE.NODATA
lda #E.NODATA
sec
>RET 4
*--------------------------------------
* (pStack)+2 count
* (pStack)+0 buf
*--------------------------------------
IO.WRITE.PIPE ldy #S.FD.PIPE.S
lda (pFD),y
bmi IO.READ.PIPE.EOF Remote PS closed the Pipe
ldy #S.FD.PIPE.Free
lda (pFD),y
ldy #2
sec
sbc (pStack),y
tax
ldy #S.FD.PIPE.Free+1
lda (pFD),y
ldy #3
sbc (pStack),y
bcc IO.READ.PIPE.NODATA not enough room in PIPE
ldy #S.FD.PIPE.Free+1
sta (pFD),y
dey
txa
sta (pFD),y store new Free
>PULLW .2+1 get dst buf
>PULLA get cnt lo
sta .80+1
pha
eor #$ff
sta IO.Counter
pla
ldy #S.FD.PIPE.Used
clc
adc (pFD),y
sta (pFD),y
>PULLA get cnt hi
sta .81+1
pha
eor #$ff
sta IO.Counter+1
pla
iny #S.FD.PIPE.Used+1
adc (pFD),y
sta (pFD),y
ldy #S.FD.PIPE.Size+1
lda (pFD),y
sta .5+1 Page Count
ldy #S.FD.PIPE.hMem
lda (pFD),y
.DO AUXPIPE=1
ldx #SYS.GetStkObjPtr
jsr K.SYSCALL2.AUX
.ELSE
jsr K.GetMemPtr get src buf
.FIN
sty .3+1
sta .7+1 Pipe Buffer Base
ldy #S.FD.PIPE.Head+1
clc
adc (pFD),y
sta .3+2
dey
lda (pFD),y
tay S.FD.PIPE.Head
ldx #0
.10 .DO AUXPIPE=1
sta SETWRITEAUX
.FIN
.1 inc IO.Counter
bne .2
inc IO.Counter+1
beq .8
.2 lda $ffff,x SELF MODIFIED
.3 sta $ffff,y SELF MODIFIED
inx
bne .4
inc .2+2
.4 iny
bne .1
.DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
ldy #S.FD.PIPE.Head+1
lda (pFD),y
inc
.5 cmp #$ff SELF MODIFIED
beq .6
sta (pFD),y
inc .3+2
ldy #0
bra .10
.6 lda #0
sta (pFD),y
.7 lda #$ff SELF MODIFIED
sta .3+2
ldy #0
bra .10
.8 .DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
tya
ldy #S.FD.PIPE.Head
sta (pFD),y
.80 ldy #$ff SELF MODIFIED
.81 lda #$ff SELF MODIFIED
clc Y,A = bytes written
rts
*/--------------------------------------
* # IOCTL
* ## C
@ -709,10 +208,9 @@ IO.WRITE.PIPE ldy #S.FD.PIPE.S
K.IOCTL tax
lda Dev.Table,x
beq K.IOCTL.9
sta pFD+1
lda Dev.Table-1,x
sta pFD
ldy Dev.Table-1,x
>STYA pFD
jsr K.IOCTL.GetPDrv
@ -769,7 +267,7 @@ IO.EOF.REG >MLICALL MLIGETMARK
dey
bpl .2
IO.EOF.TRUE lda #$ff
lda #$ff
* clc
IO.EOF.REG.RTS rts
*--------------------------------------
@ -790,13 +288,6 @@ IO.EOF.SSOCK ldy #S.FD.SSOCK.EOF
.1 jmp $FFFF SELF MODIFIED
*--------------------------------------
IO.EOF.PIPE clc
ldy #S.FD.PIPE.Used
lda (pFD),y
iny
ora (pFD),y
beq IO.EOF.TRUE
IO.EOF.FALSE lda #0
* clc
rts

View File

@ -632,6 +632,39 @@ MEM.GetKrnlBuf pha
.99 lda #E.OOM
* sec
rts
*/--------------------------------------
* # GetMemStat
* **In:**
* Y,A = Ptr to 24 bytes buffer
* ## RETURN VALUE
* Buffer filled with memory stats
*\--------------------------------------
K.GetMemStat >STYA ZPPtr1
ldy #23
ldx #7
.1 lda DevMgr.Stat,x
sta (ZPPtr1),y
dey
dex
bpl .1
sta SETREADAUX
jsr .2
sta CLRREADAUX
.2 ldx #7
.3 lda Mem.Table,x
sta (ZPPtr1),y
dey
dex
bpl .3
rts
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.MEM

331
SYS/KERNEL.S.PIPE.txt Normal file
View File

@ -0,0 +1,331 @@
NEW
AUTO 3,1
*--------------------------------------
IO.PIPE.SRCBUF .EQ ZPDRV
IO.PIPE.DSTBUF .EQ ZPDRV+2
IO.PIPE.CNT .EQ ZPDRV+4
IO.PIPE.BASEH .EQ ZPDRV+6
IO.PIPE.BUFH .EQ ZPDRV+7
IO.PIPE.SIZEH .EQ ZPDRV+8
*--------------------------------------
IO.OPEN.PIPE ldy #S.FD.PIPE.S
lda (pFD),y
inc
sta (pFD),y
lda IO.hFD
clc
rts
*--------------------------------------
IO.CLOSE.PIPE ldy #S.FD.PIPE.S
lda (pFD),y
bmi .1 remote PS closed its end
lda #$80
sta (pFD),y
clc
rts
.1 jsr IO.CLOSE.NOD
ldy #S.FD.PIPE.hMem
lda (pFD),y
beq .2
.DO AUXPIPE=1
ldx #SYS.FreeStkObj
jsr K.SYSCALL2.AUX
.ELSE
jsr K.FreeMem
.FIN
.2 lda IO.hFD
jmp K.FreeMem
*--------------------------------------
* (pStack)+2 count
* (pStack)+0 buf
*--------------------------------------
IO.WRITE.PIPE ldy #S.FD.PIPE.S
lda (pFD),y
bpl .10
jmp IO.READ.PIPE.EOF Remote PS closed the Pipe
.10 ldy #S.FD.PIPE.Free
lda (pFD),y
ldy #2
cmp (pStack),y
ldy #S.FD.PIPE.Free+1
lda (pFD),y
ldy #3
sbc (pStack),y
bcc IO.READ.PIPE.NODATA not enough room in PIPE
>PULLW IO.PIPE.SRCBUF
ldy #S.FD.PIPE.Head+1
jsr IO.PIPE.GET.BUF
>STYA IO.PIPE.DSTBUF
>PULLA get cnt lo
sta IO.PIPE.CNT
eor #$ff
tax
>PULLA get cnt hi
sta IO.PIPE.CNT+1
eor #$ff
pha
ldy #S.FD.PIPE.Head
lda (pFD),y
tay
.DO AUXPIPE=1
sta SETWRITEAUX
.FIN
.1 inx
bne .2
pla
inc
beq .8
pha
.2 lda (IO.PIPE.SRCBUF)
sta (IO.PIPE.DSTBUF),y
inc IO.PIPE.SRCBUF
bne .4
inc IO.PIPE.SRCBUF+1
.4 iny
bne .1
lda IO.PIPE.BUFH
inc
cmp IO.PIPE.SIZEH
beq .6
sta IO.PIPE.BUFH
inc IO.PIPE.DSTBUF+1
bra .1
.6 stz IO.PIPE.BUFH
lda IO.PIPE.BASEH Pipe Buffer Base
sta IO.PIPE.DSTBUF+1
bra .1
.8 .DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
tya
ldy #S.FD.PIPE.Head
sta (pFD),y
iny
lda IO.PIPE.BUFH
sta (pFD),y
ldy #S.FD.PIPE.Free
jsr IO.PIPE.SUB.CNT
iny #S.FD.PIPE.Used
jsr IO.PIPE.ADD.CNT
jmp IO.READ.PIPE.EXIT
IO.READ.PIPE.EOF
lda #MLI.E.EOF
.HS 2C BIT ABS
IO.READ.PIPE.NODATA
lda #E.NODATA
sec
>RET 4
*--------------------------------------
IO.READ.PIPE ldy #S.FD.PIPE.Used+1
lda (pFD),y Data ?
dey
ora (pFD),y
bne .10 yes...
ldy #S.FD.PIPE.S
lda (pFD),y
bmi IO.READ.PIPE.EOF Remote PS closed the Pipe
bpl IO.READ.PIPE.NODATA
.10 >PULLW IO.PIPE.DSTBUF get dest buf
ldy #S.FD.PIPE.Tail+1
jsr IO.PIPE.GET.BUF
>STYA IO.PIPE.SRCBUF
>PULLA get cnt lo
tax
ldy #S.FD.PIPE.Used
cmp (pFD),y
>PULLA get cnt hi
pha
iny #S.FD.PIPE.Used+1
sbc (pFD),y
pla
bcc .12 cnt < Used
dey
lda (pFD),y
tax
iny
lda (pFD),y X,A = Used
.12 stx IO.PIPE.CNT
sta IO.PIPE.CNT+1
eor #$ff
pha
txa
eor #$ff
tax
ldy #S.FD.PIPE.Tail
lda (pFD),y
tay
.DO AUXPIPE=1
sta SETREADAUX
.FIN
.1 inx
bne .2
pla
inc
beq .8
pha
.2 lda (IO.PIPE.SRCBUF),y
sta (IO.PIPE.DSTBUF)
inc IO.PIPE.DSTBUF
bne .4
inc IO.PIPE.DSTBUF+1
.4 iny
bne .1
lda IO.PIPE.BUFH
inc
cmp IO.PIPE.SIZEH
beq .6
sta IO.PIPE.BUFH
inc IO.PIPE.SRCBUF+1
bra .1
.6 stz IO.PIPE.BUFH
lda IO.PIPE.BASEH
sta IO.PIPE.SRCBUF+1 Restore Pipe Buf base
bra .1
.8 .DO AUXPIPE=1
sta CLRREADAUX
.FIN
tya
ldy #S.FD.PIPE.Tail
sta (pFD),y
iny
lda IO.PIPE.BUFH
sta (pFD),y
ldy #S.FD.PIPE.Free
jsr IO.PIPE.ADD.CNT
iny #S.FD.PIPE.Used
jsr IO.PIPE.SUB.CNT
IO.READ.PIPE.EXIT
>LDYA IO.PIPE.CNT Y,A = bytes written
clc
rts
*--------------------------------------
IO.PIPE.GET.BUF lda (pFD),y
sta IO.PIPE.BUFH
ldy #S.FD.PIPE.Size+1
lda (pFD),y
sta IO.PIPE.SIZEH
ldy #S.FD.PIPE.hMem
lda (pFD),y
.DO AUXPIPE=1
ldx #SYS.GetStkObjPtr
jsr K.SYSCALL2.AUX
.ELSE
jsr K.GetMemPtr get src buf
.FIN
sta IO.PIPE.BASEH Pipe Buffer Base
* clc
adc IO.PIPE.BUFH
rts
*--------------------------------------
IO.PIPE.ADD.CNT clc
lda (pFD),y
adc IO.PIPE.CNT
sta (pFD),y
iny
lda (pFD),y
adc IO.PIPE.CNT+1
sta (pFD),y
rts
*--------------------------------------
IO.PIPE.SUB.CNT sec
lda (pFD),y
sbc IO.PIPE.CNT
sta (pFD),y
iny
lda (pFD),y
sbc IO.PIPE.CNT+1
sta (pFD),y
rts
*--------------------------------------
IO.EOF.PIPE clc
ldy #S.FD.PIPE.Used
lda (pFD),y
iny
ora (pFD),y
beq .8
lda #0
* clc
rts
.8 lda #$ff
* clc
rts
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.PIPE
LOAD USR/SRC/SYS/KERNEL.S
ASM

View File

@ -1,38 +1,5 @@
NEW
AUTO 3,1
*/--------------------------------------
* # GetMemStat
* **In:**
* Y,A = Ptr to 24 bytes buffer
* ## RETURN VALUE
* Buffer filled with memory stats
*\--------------------------------------
K.GetMemStat >STYA ZPPtr1
ldy #23
ldx #7
.1 lda DevMgr.Stat,x
sta (ZPPtr1),y
dey
dex
bpl .1
sta SETREADAUX
jsr .2
sta CLRREADAUX
.2 ldx #7
.3 lda Mem.Table,x
sta (ZPPtr1),y
dey
dex
bpl .3
rts
*--------------------------------------
* # ChMod
* change permissions of a file

View File

@ -55,7 +55,7 @@ K.FPutC jsr PFT.CheckNodeA
>PUSHA
>PUSHWI K.IOBuf buf
jsr IO.Write.I
jsr UNISTD.Write
bcc K.PutChar.RET1 pop char...
tay E.NODATA
bpl K.PutChar.RET1
@ -158,7 +158,7 @@ K.FPutS jsr PFT.CheckNodeA set IO.hFD
>PUSHW ZPPtr2
jsr IO.Write.I
jsr UNISTD.Write
bcc K.PutS.RET2
tay
bpl K.PutS.RET2 IO Erorr
@ -821,7 +821,7 @@ STDIO.Read.1 lda #0
inc read 1 byte
>PUSHA
>PUSHWI K.IOBuf
jmp IO.READ.I
jmp UNISTD.READ
*/--------------------------------------
* # SScanF
* Read formatted data from string
@ -995,11 +995,11 @@ K.SScanF.Fwd jmp MEM.AddYToPtr2 Y=char count parsed
K.FOpen jsr PFT.CheckPathYA
bcs K.FOpen.RET4
>PULLB K.Open.FLAGS
>PULLB K.Open.TYPE
>PULLW K.Open.AUXTYPE
>PULLB IO.Open.FLAGS
>PULLB IO.Open.TYPE
>PULLW IO.Open.AUXTYPE
jsr IO.Open.I
jsr UNISTD.Open
bcs K.FClose.RTS
jsr STDIO.NewHFile
@ -1024,7 +1024,7 @@ K.FClose jsr PFT.CheckNodeA
sta .1+1 store hFile
jsr IO.Close.I
jsr UNISTD.Close
bcs K.FClose.RTS
.1 ldx #$ff SELF MODIFIED
@ -1052,7 +1052,7 @@ K.FClose jsr PFT.CheckNodeA
K.FRead jsr PFT.CheckNodeA
bcs K.FOpen.RET4
jsr IO.Read.I
jsr UNISTD.Read
bcs K.FWrite.9
K.FClose.RTS rts
@ -1073,7 +1073,7 @@ K.FClose.RTS rts
K.FWrite jsr PFT.CheckNodeA
bcs K.FOpen.RET4
jsr IO.Write.I
jsr UNISTD.Write
bcc K.FWrite.RTS
K.FWrite.9 tay
@ -1128,18 +1128,16 @@ K.FSeek jsr PFT.CheckNodeA
>PULLA whence
tax
>PULLW ZPPtr1 offset LW
>PULLW ZPPtr2 offset HW
cpx #SEEK.END+1
>PULLL ACC32
cpx #SEEK.END
beq .30
bcs .98
jmp (.1,x)
dex
beq .20
.1 .DA .10
.DA .20
.DA .30
* SEEK.SET
.10 stz K.MLI.PARAMS+2
stz K.MLI.PARAMS+2
stz K.MLI.PARAMS+3
stz K.MLI.PARAMS+4
bra .8
@ -1154,16 +1152,16 @@ K.FSeek jsr PFT.CheckNodeA
bcs .9
.8 ldy #0
ldx #3 3 bytes, 24 bits!!!
clc
.81 lda K.MLI.PARAMS+2,y
adc ZPPtr1,y
adc ACC32,y
sta K.MLI.PARAMS+2,y
iny
dex
tya 3 bytes, 24 bits!!!
eor #3
bne .81
bcs .99 Offset out of range!

180
SYS/KERNEL.S.UNISTD.txt Normal file
View File

@ -0,0 +1,180 @@
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.hDev .BS 1
IO.hFD .BS 1
IO.hFILE .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
*--------------------------------------
UNISTD.Open ldx #5 /DEV/
cpx K.MLI.PATH
bcs .9
.1 lda K.MLI.PATH,x
cmp IO.DEVDIR-1,x
bne .9
dex
bne .1
*--------------------------------------
* /DEV/xxxxxx (CDEV,BDEV,LNK,DSOCK,SSOCK,PIPE)
*--------------------------------------
>LDYAI K.MLI.PATH+6 skip $/DEV/
jsr K.GetDevByName
bcc .7
ldx #2
.10 lda Nod.Table.hPath-2,x
beq .3
jsr K.GetMemPtr
>STYA ZPPtr1
ldy #0
.2 lda (ZPPtr1),y
iny
cmp K.MLI.PATH,y
bne .3
cmp #0 end of string ?
bne .2
lda Nod.Table.hFD-2,x return hFD
jsr IO.GetPFD
bra .71
.3 inx
cpx #K.NOD.MAX+2
bne .10
lda #MLI.E.NODEV
* sec
rts no OF found
.7 stx IO.hDev
>STYA pFD
.71 lda (pFD) #S.FD.T
tax
jmp (.8,x)
.8 .DA STDIO.IOERR REG
.DA STDIO.IOERR DIR
.DA IO.OPEN.CDEV
.DA IO.OPEN.BDEV
.DA STDIO.IOERR LNK
.DA IO.OPEN.DSOCK
.DA IO.OPEN.SSOCK
.DA IO.OPEN.PIPE
.9 jmp IO.OPEN.REG
*/--------------------------------------
* # close
* ## C
* `int close(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>SYSCALL close`
*\--------------------------------------
K.Close jsr IO.GetPFD
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
*\--------------------------------------
K.Read jsr IO.GetPFD
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
*\--------------------------------------
K.Write jsr IO.GetPFD
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
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.UNISTD
LOAD USR/SRC/SYS/KERNEL.S
ASM

View File

@ -43,6 +43,7 @@ A2osX.D1 .PH $D000
.DA #RRAMWRAMBNK1
.INB USR/SRC/SYS/KERNEL.S.STAT
.INB USR/SRC/SYS/KERNEL.S.DIRENT
.INB USR/SRC/SYS/KERNEL.S.UNISTD
.INB USR/SRC/SYS/KERNEL.S.STDIO
.INB USR/SRC/SYS/KERNEL.S.STDLIB
.INB USR/SRC/SYS/KERNEL.S.DEV
@ -68,6 +69,7 @@ A2osX.E0 .PH $E000
.INB USR/SRC/SYS/KERNEL.S.SHARED
********* TMP ***** go to A2osX.D1
.INB USR/SRC/SYS/KERNEL.S.IO
.INB USR/SRC/SYS/KERNEL.S.PIPE
********* TMP ***** go to A2osX.D2
*--------------------------------------
PWD.bDirty .BS 1