Kernel 0.9.2

This commit is contained in:
Rémy GIBERT 2018-07-27 15:34:34 +02:00
parent dc285bcbc0
commit ea144535e5
6 changed files with 146 additions and 55 deletions

View File

@ -174,7 +174,7 @@ Load a file in memory
PUSHW = AUXTYPE (Handled by....
PUSHB = TYPE ...
PUSHB = MODE ...
PUSHW = PATH ...FOpen)
LDYA = PATH ...FOpen)
**Out:**
Y,A = File Length
X = hMem of Loaded File
@ -531,7 +531,10 @@ Write Str to StdOut, appends '\r\n'
## C
`int puts ( const char * str );`
**In:**
Y,A : str
## ASM
`>LDYAI str`
`>SYSCALL puts`
**Out:**
CC = success
@ -539,10 +542,13 @@ CC = success
Write Str to FILE
## C
`int fputs ( const char * str, hFILE stream );`
`int fputs (hFILE stream, const char * str );`
## ASM
**In:**
PUSHB : hFILE
Y,A: str
`>PUSHW str`
`lda stream`
`>SYSCALL fputs`
**Out:**
CC = success
@ -613,6 +619,25 @@ Modifiers for len and padding :
+ %2f : '3.14'
# FGetS
read bytes from stream into the array
pointed to by s, until n-1 bytes are read, or a <newline> is read and
transferred to s, or an end-of-file condition is encountered. The
string is then terminated with a null byte.
## C
`char *fgets(hFILE stream, char * s, int n);`
## ASM
**In:**
`>PUSHW n`
`>PUSHW s`
`lda hFILE`
`>SYSCALL fgets`
**Out:**
Y,A: s
CC = success
# GetChar
Get char from StdIn
**In:**
@ -651,6 +676,7 @@ Read formatted data from string
+ %U : dword
+ %h : HEX byte
+ %H : HEX word
+ %s : string
`>PUSHW ptr`
`...`
@ -729,11 +755,21 @@ Write bytes to file
Y,A = Bytes Written
# FFlush
## C
int fflush(hFILE stream);
## ASM
**In:**
A = hFILE
# FSeek
Set the file-position indicator for hFILE
## C
`int fseek(hFILE stream, long offset, int whence);`
## ASM
**In:**
PUSHW = Ptr to Offset (DWORD)
PUSHB = From
@ -751,6 +787,11 @@ Test the end-of-file indicator for hFILE
# FTell
Return the current value of the file-position indicator
## C
`long ftell(hFILE stream);`
## ASM
**In:**
PUSHW = Ptr to Offset (DWORD)
PUSHB = hFILE

Binary file not shown.

Binary file not shown.

View File

@ -290,6 +290,8 @@ S.MSTAT .EQ 24
* IOCTL device API
*--------------------------------------
C.EOF .EQ 4
C.LF .EQ 10
C.CR .EQ 13
C.DEL .EQ 127
*--------------------------------------
DEVID.NULL .EQ 0

View File

@ -30,7 +30,7 @@ K.SYSCALL.JMP .DA 0 $00
.DA K.GetChar
.DA K.FPutS
.DA K.PutS
.DA 0
.DA K.FGetS
.DA 0
.DA K.FOpen $30

View File

@ -47,7 +47,9 @@ K.PutChar.X >LDYAI K.IOBuf
* ## C
* `int puts ( const char * str );`
* **In:**
* Y,A : str
* ## ASM
* `>LDYAI str`
* `>SYSCALL puts`
* **Out:**
* CC = success
*\--------------------------------------
@ -71,19 +73,28 @@ K.PutS >STYA K.S.IOCTL+S.IOCTL.BUFPTR
* Write Str to FILE
* ## C
* `int fputs (hFILE stream, const char * str );`
* ## ASM
* **In:**
* PUSHB : hFILE
* Y,A: str
* `>PUSHW str`
* `lda stream`
* `>SYSCALL fputs`
* **Out:**
* CC = success
*\--------------------------------------
K.FPutS >STYA K.S.IOCTL+S.IOCTL.BUFPTR
>STYA ZPPtr1
K.FPutS pha
>PULLA
sta K.S.IOCTL+S.IOCTL.BUFPTR
sta ZPPtr1
>PULLA
sta K.S.IOCTL+S.IOCTL.BUFPTR+1
sta ZPPtr1+1
pla
K.FPutS.I jsr IO.SELECT
bcs *
ldy #0
ldx #0
@ -100,28 +111,6 @@ K.FPutS.I jsr IO.SELECT
stx K.S.IOCTL+S.IOCTL.BYTECNT+1
jmp IO.Write.I
*/--------------------------------------
* # FGetS
* read bytes from stream into the array
* pointed to by s, until n-1 bytes are read, or a <newline> is read and
* transferred to s, or an end-of-file condition is encountered. The
* string is then terminated with a null byte.
* ## C
* `char *fgets(hFILE stream, char * s, int n);`
* ## ASM
* **In:**
* `>PUSHW n`
* `>PUSHW s`
* `lda hFILE`
* `>SYSCALL fgets`
* **Out:**
* Y,A: s
* CC = success
*\--------------------------------------
K.FGetS
clc
rts
*/--------------------------------------
* # PrintF/SPrintF/FPrintF
* Prints C-Style String
* ## C
@ -604,6 +593,67 @@ PrintF.COut phy
*--------------------------------------
PrintF.Flush jmp IO.Write.I
*/--------------------------------------
* # FGetS
* read bytes from stream into the array
* pointed to by s, until n-1 bytes are read, or a <newline> is read and
* transferred to s, or an end-of-file condition is encountered. The
* string is then terminated with a null byte.
* ## C
* `char *fgets(hFILE stream, char * s, int n);`
* ## ASM
* **In:**
* `>PUSHW n`
* `>PUSHW s`
* `lda hFILE`
* `>SYSCALL fgets`
* **Out:**
* Y,A: s
* CC = success
*\--------------------------------------
K.FGetS pha
>PULLA
sec
sbc #2
eor #$ff
sta ZPPtr2 !n
>PULLA
sbc #0
eor #$ff
sta ZPPtr2+1 !n
>PULLW ZPPtr1 s
pla
jsr IO.SELECT
bcs .9
jsr K.GetC.I
bcs .9
.1 lda K.IOBuf
cmp #C.CR
beq .8
sta (ZPPtr1)
inc ZPPtr1
bne .2
inc ZPPtr1+1
.2 inc ZPPtr2
bne .3
inc ZPPtr2+1
beq .8
.3 jsr IO.READ.I
bcc .1
.8 clc
.9 pha
lda #0
sta (ZPPtr1)
pla
rts
*/--------------------------------------
* # GetChar
* Get char from StdIn
* **In:**
@ -625,19 +675,19 @@ K.GetChar ldy #S.PS.hStdIn
* **Out:**
* CC = success
* A = char
*\--------------------------------------
*\-----------a---------------------------
K.GetC jsr IO.SELECT
bcs .9
bcs K.GetC.9
>LDYAI K.IOBuf
K.GetC.I >LDYAI K.IOBuf
>STYA K.S.IOCTL+S.IOCTL.BUFPTR
lda #1
sta K.S.IOCTL+S.IOCTL.BYTECNT
stz K.S.IOCTL+S.IOCTL.BYTECNT+1
jsr IO.READ.I
bcs .9
bcs K.GetC.9
lda K.IOBuf
.9 rts
K.GetC.9 rts
*--------------------------------------
*K.PrintF.PadL .BS 1
*K.PrintF.PadC .BS 1
@ -675,9 +725,8 @@ BCDBUF .EQ ARG
*\--------------------------------------
K.SScanF >STYA ZPPtr2 String to Scan
>PULLW ZPPtr1 format
>PULLB K.SScanF.ByteCnt
stz K.SScanF.ByteIdx
stz .5+1
.1 lda (ZPPtr1) End Of format?
beq .8
@ -704,11 +753,12 @@ K.SScanF >STYA ZPPtr2 String to Scan
bne .21
inc ZPPtr1+1
.21 ldx #K.SScanFCNT-K.SScanFTBL-1
.21 ldx #K.SScanFJMP-K.SScanFTBL-2
.3 cmp K.SScanFTBL,x
beq .4
dex
dex
bpl .3
.9 jsr .8
@ -717,35 +767,33 @@ K.SScanF >STYA ZPPtr2 String to Scan
rts
.4 jsr .5
bcs .9
bcs .9 out of Ptr on stack
bra .1
.8 lda pStack
clc
adc K.SScanF.ByteCnt ...
sec ByteCnt byte
adc (pStack) ... ByteCnt
sta pStack CC
.99 rts
*--------------------------------------
.5 ldy K.SScanF.ByteIdx
cpy K.SScanF.ByteCnt
.5 lda #$FF SELF MODIFIED
cmp (pStack)
beq .99 CS
tay
iny
lda (pStack),y
sta ZPPtr3
iny
lda (pStack),y
sta ZPPtr3+1 get VAR Ptr
iny
sty K.SScanF.ByteIdx
sty .5+1
jmp (K.SScanFJMP,x)
*--------------------------------------
K.SScanF.ByteCnt .BS 1
K.SScanF.ByteIdx .BS 1
*--------------------------------------
K.SScanFTBL .DA #'i,#'d,#'I,#'D,#'l,#'u,#'h,#'H,#'s
K.SScanFCNT .DA #1, #1, #2, #2, #4, #4, #1, #2
K.SScanFTBL .DA #'i,#1,#'d,#1,#'I,#2,#'D,#2,#'l,#4,#'u,#4,#'h,#1,#'H,#2,#'s,#2
K.SScanFJMP .DA K.SScanF.I
.DA K.SScanF.D
.DA K.SScanF.II