A2osX/SYS/KERNEL.S.STDIO.txt

1403 lines
26 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-12 20:45:11 +00:00
AUTO 3,1
*/--------------------------------------
2021-05-14 20:58:20 +00:00
* # fputc (BLOCKING)
* Print A (char) to hFILE
2018-06-18 06:22:50 +00:00
* ## C
2021-05-14 20:58:20 +00:00
* `int fputc ( hFILE stream , short int character );`
2018-06-18 06:22:50 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2021-05-14 20:58:20 +00:00
* `>PUSHB stream`
* `>PUSHB character`
* `>SYSCALL fputc`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
2018-06-18 06:22:50 +00:00
* CC = success
*\--------------------------------------
2021-05-14 20:58:20 +00:00
K.FPutC lda (pStack) character
sta K.IOBuf
2021-05-14 20:58:20 +00:00
ldy #1
lda (pStack),y hFile
>PUSHA
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
jsr STDIO.Put1
bcc .8
2021-06-19 17:46:36 +00:00
2020-08-25 10:56:00 +00:00
tay
2021-05-14 20:58:20 +00:00
beq .9 BLOCKING, keep parms on stack
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
.8 >POP 2
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
.9 rts
2018-11-16 16:04:20 +00:00
*/--------------------------------------
2021-05-14 20:58:20 +00:00
* # putchar (BLOCKING)
* Print A (char) to StdOut
2018-11-16 16:04:20 +00:00
* ## C
2021-05-14 20:58:20 +00:00
* `int putchar ( short int character );`
2018-11-16 16:04:20 +00:00
* ## ASM
* **In:**
2021-05-14 20:58:20 +00:00
* `lda character`
* `>SYSCALL putchar`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
2018-11-16 16:04:20 +00:00
* CC = success
*\--------------------------------------
2021-05-14 20:58:20 +00:00
K.PutChar sta K.IOBuf character
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
ldy #S.PS.hStdOut
lda (pPS),y
>PUSHA
*--------------------------------------
STDIO.Put1 >PUSHWI K.IOBuf buf
2018-08-08 15:13:37 +00:00
2019-05-12 20:45:11 +00:00
lda #0
>PUSHA
inc write 1 byte
>PUSHA
2021-05-19 12:44:47 +00:00
STDIO.Write jsr K.FWrite
2021-05-14 20:58:20 +00:00
bcc .9
2020-08-25 10:56:00 +00:00
2021-05-14 20:58:20 +00:00
tay
bne .9
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
>POP 5
2020-08-25 10:56:00 +00:00
2021-05-14 20:58:20 +00:00
.9 rts
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # puts (BLOCKING)
* Write Str to StdOut, appends '\r\n'
2018-06-18 06:22:50 +00:00
* ## C
* `int puts ( const char * str );`
2018-06-14 15:31:36 +00:00
* **In:**
2018-07-27 13:34:34 +00:00
* ## ASM
* `>LDYAI str`
2020-02-28 07:21:46 +00:00
* `>SYSCALL PutS`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
2018-06-18 06:22:50 +00:00
* CC = success
*\--------------------------------------
2020-08-25 10:56:00 +00:00
K.PutS >STYA .1+1
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
ldx #0
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
.1 lda $FFFF,x SELF MODIFIED
2019-05-12 20:45:11 +00:00
beq .2
2020-08-25 10:56:00 +00:00
2021-05-14 20:58:20 +00:00
sta K.IOBuf,x
inx
2019-05-12 20:45:11 +00:00
bne .1
.9 lda #E.BUF
sec
rts
.2 lda #C.CR
2021-05-14 20:58:20 +00:00
sta K.IOBuf,x
inx
2019-05-12 20:45:11 +00:00
beq .9
lda #C.LF
2021-05-14 20:58:20 +00:00
sta K.IOBuf,x
inx
2019-05-12 20:45:11 +00:00
beq .9
ldy #S.PS.hStdOut
2020-02-28 07:21:46 +00:00
lda (pPS),y
2020-08-25 10:56:00 +00:00
>PUSHA
>PUSHWI K.IOBuf
2021-05-14 20:58:20 +00:00
>PUSHBI 0
txa
>PUSHA
2020-08-25 10:56:00 +00:00
2021-05-19 12:44:47 +00:00
bra STDIO.Write
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # fputs (BLOCKING)
2019-05-12 20:45:11 +00:00
* Write Str to hFILE
2018-06-18 06:22:50 +00:00
* ## C
2018-07-26 15:26:39 +00:00
* `int fputs (hFILE stream, const char * str );`
2018-07-27 13:34:34 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2020-08-25 10:56:00 +00:00
* `>PUSHB stream`
2018-07-27 13:34:34 +00:00
* `>PUSHW str`
* `>SYSCALL fputs`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
2018-06-18 06:22:50 +00:00
* CC = success
*\--------------------------------------
2021-05-14 20:58:20 +00:00
K.FPutS lda (pStack)
sta ZPPtr1 Get String
sta ZPPtr2
2021-06-19 17:46:36 +00:00
2019-05-12 20:45:11 +00:00
ldy #1
lda (pStack),y
2021-05-14 20:58:20 +00:00
sta ZPPtr1+1
2019-05-12 20:45:11 +00:00
sta ZPPtr2+1
2021-06-19 17:46:36 +00:00
2020-08-25 10:56:00 +00:00
ldy #0
2019-05-12 20:45:11 +00:00
ldx #0
2020-03-04 16:38:32 +00:00
2021-05-14 20:58:20 +00:00
.1 lda (ZPPtr1),y
2019-05-12 20:45:11 +00:00
beq .2
2020-08-25 10:56:00 +00:00
2019-05-12 20:45:11 +00:00
iny
bne .1
2020-08-25 10:56:00 +00:00
2019-05-12 20:45:11 +00:00
inx
2021-05-14 20:58:20 +00:00
inc ZPPtr1+1
2019-05-12 20:45:11 +00:00
bra .1
2020-08-25 10:56:00 +00:00
2021-05-14 20:58:20 +00:00
.2 phy
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
ldy #2
lda (pStack),y
>PUSHA
2019-05-12 20:45:11 +00:00
>PUSHW ZPPtr2
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
txa
>PUSHA push len HI
2020-08-25 10:56:00 +00:00
2021-05-14 20:58:20 +00:00
pla
>PUSHA push len LO
2021-05-19 12:44:47 +00:00
jsr STDIO.Write
bcs K.FPutS.RTS
2021-06-19 17:46:36 +00:00
.8 >POP 2
2020-08-25 10:56:00 +00:00
K.FPutS.RTS rts
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # fgets (BLOCKING)
2018-07-27 13:34:34 +00:00
* 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:**
2020-12-23 14:54:57 +00:00
* `>PUSHB hFILE`
2018-07-27 13:34:34 +00:00
* `>PUSHW s`
2020-12-23 14:54:57 +00:00
* `>PUSHW n`
2018-07-27 13:34:34 +00:00
* `>SYSCALL fgets`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
* Y,A: s
2018-07-27 13:34:34 +00:00
* CC = success
*\--------------------------------------
2020-12-23 14:54:57 +00:00
* (pStack)+4 h
* (pStack)+2 s -> ZPPtr2
* (pStack)+0 n -> ZPPtr1
2019-02-25 14:47:31 +00:00
*--------------------------------------
2021-05-14 20:58:20 +00:00
K.FGetS ldy #3
2019-05-07 15:39:35 +00:00
2020-12-23 14:54:57 +00:00
.1 lda (pStack),y
sta ZPPtr1,y
dey
bpl .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
lda ZPPtr1+1
bmi .4 already something in buffer
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
.2 ldy #4
lda (pStack),y
jsr STDIO.Get1
bcs .9
2020-06-30 05:59:37 +00:00
2021-05-14 20:58:20 +00:00
* BLOCKING > POP 5 FREAD parms
* EOF or IOERR.... > POP 5 FGETS parms
2020-03-11 16:41:45 +00:00
2020-12-23 14:54:57 +00:00
.3 lda K.IOBuf
2020-12-15 13:23:22 +00:00
cmp #C.LF Discard any leading LF from a prev CR/LF
2020-12-23 14:54:57 +00:00
beq .2
2019-05-31 07:31:41 +00:00
2020-12-23 14:54:57 +00:00
clc set n = !n + 1
2019-05-31 07:31:41 +00:00
lda ZPPtr1
eor #$ff
2020-12-23 14:54:57 +00:00
adc #1
2019-05-31 07:31:41 +00:00
sta ZPPtr1
lda ZPPtr1+1
eor #$ff
2020-12-23 14:54:57 +00:00
adc #0
2019-05-31 07:31:41 +00:00
sta ZPPtr1+1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
bra .5
2020-12-15 13:23:22 +00:00
*--------------------------------------
2021-05-14 20:58:20 +00:00
.4 ldy #4
lda (pStack),y
jsr STDIO.Get1
2020-12-23 14:54:57 +00:00
bcs .6
2019-05-12 20:45:11 +00:00
2020-12-23 14:54:57 +00:00
.5 lda K.IOBuf
2019-05-31 07:31:41 +00:00
cmp #C.CR
2019-05-22 15:46:20 +00:00
beq .8
2021-06-19 17:46:36 +00:00
2021-05-04 17:31:21 +00:00
jsr SHARED.PutCP2
2020-12-23 14:54:57 +00:00
inc ZPPtr1
bne .4
inc ZPPtr1+1
bne .4
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
beq .8 Buffer full
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
.6 tay
beq .70
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
cmp #MLI.E.EOF
2019-05-31 07:31:41 +00:00
beq .8 String terminated by EOF
2020-06-30 05:59:37 +00:00
2021-05-14 20:58:20 +00:00
bra .9 I/O error > POP 5 FGETS parms
.70 jsr .9 > POP 5 FREAD parms
2019-05-12 20:45:11 +00:00
2020-12-23 14:54:57 +00:00
ldy #3
2019-05-12 20:45:11 +00:00
2020-12-23 14:54:57 +00:00
.7 lda ZPPtr1,y NO DATA, but string not yet terminated
sta (pStack),y
dey
bpl .7
2019-05-12 20:45:11 +00:00
lda #0 BLOCKING
2020-06-30 10:40:19 +00:00
* sec
2019-05-07 15:39:35 +00:00
rts
2019-05-12 20:45:11 +00:00
2019-05-07 15:39:35 +00:00
.8 lda #0
2019-02-25 14:47:31 +00:00
sta (ZPPtr2) terminate string
2019-05-07 15:39:35 +00:00
clc
2020-12-23 14:54:57 +00:00
.9 >RET 5
2018-07-27 13:34:34 +00:00
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # getchar (BLOCKING)
* Get char from StdIn
2018-10-04 06:13:44 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `short int getchar ( );`
2018-10-04 06:13:44 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-04 06:13:44 +00:00
* `>SYSCALL getchar`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
* CC = success
* A = char
*\--------------------------------------
K.GetChar ldy #S.PS.hStdIn
2021-06-19 17:46:36 +00:00
lda (pPS),y
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # getc (BLOCKING)
* Get char from Node
2018-06-18 06:22:50 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `short int getc ( short int stream );`
2018-06-18 06:22:50 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-04 06:13:44 +00:00
* `lda stream`
* `>SYSCALL getc`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
* CC = success
* A = char
2018-10-05 14:58:38 +00:00
*\--------------------------------------
2021-05-14 20:58:20 +00:00
K.GetC jsr STDIO.Get1
2019-02-22 16:08:37 +00:00
bcc .8
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
tay
2021-05-04 17:31:21 +00:00
bne .9 I/O error
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
>POP 5 BLOCKING
2019-05-12 20:45:11 +00:00
rts
2019-02-22 16:08:37 +00:00
.8 lda K.IOBuf
2019-05-04 21:13:50 +00:00
2021-05-04 17:31:21 +00:00
.9 rts
2019-07-15 06:41:12 +00:00
*--------------------------------------
2021-05-14 20:58:20 +00:00
STDIO.Get1 >PUSHA
>PUSHWI K.IOBuf
lda #0
2019-07-15 06:41:12 +00:00
>PUSHA
inc read 1 byte
>PUSHA
2021-06-17 17:38:34 +00:00
ldx #SYS.FRead
2021-05-14 20:58:20 +00:00
jmp K.FRead
*/--------------------------------------
2020-07-01 05:48:31 +00:00
* # ungetc
* push byte back into input stream
* ## C
2020-08-02 12:19:43 +00:00
* `short int ungetc(short int c, short int stream);`
2020-07-01 05:48:31 +00:00
* ## ASM
* `>PUSHB c`
* `>PUSHB stream`
* `>SYSCALL ungetc`
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
2020-07-01 05:48:31 +00:00
* CC = success
* A = char
*\--------------------------------------
K.UngetC clc
rts
*/--------------------------------------
* # FOpen
* Open a file
2018-06-18 15:48:00 +00:00
* ## C
2020-02-14 07:21:56 +00:00
* `short int fopen ( const char *filename, short int flags, short int ftype, int auxtype );`
2018-06-18 08:44:02 +00:00
* **In:**
2018-06-18 15:48:00 +00:00
* ## ASM
2020-02-14 07:21:56 +00:00
* `>PUSHW filename`
* `>PUSHB flags`
2018-10-02 15:52:30 +00:00
* + O.RDONLY : if R and !exists -> ERROR
* + O.WRONLY : if W and !exists -> CREATE
2018-10-03 15:25:03 +00:00
* + O.TRUNC : Reset Size To 0
2018-10-02 15:52:30 +00:00
* + O.APPEND : Append
* + O.TEXT : Open/Append in Text mode
* + O.CREATE : Create if not exists
2020-02-14 07:21:56 +00:00
* `>PUSHB ftype`
* `>PUSHW auxtype`
2018-10-04 15:30:14 +00:00
* TODO: replace flags/ftype/auxtype with mode="w+,t=TYP,x=AUXTYPE"
2018-10-03 15:25:03 +00:00
* + r = O_RDONLY
* + r+ = O_RDWR
* + w = O_WRONLY | O_CREAT | O_TRUNC
* + w+ = O_RDWR | O_CREAT | O_TRUNC
* + a = O_WRONLY | O_CREAT | O_APPEND
* + a+ = O_RDWR | O_CREAT | O_APPEND
* + ,t=123 or t=$ff or t=TXT
* + ,x=12345 or x=$ffff
2021-06-19 17:46:36 +00:00
* ## RETURN VALUE
* CC : A = hFILE
* CS : A = EC
*\--------------------------------------
2020-02-14 07:21:56 +00:00
K.FOpen jsr PFT.CheckPath4
2020-03-11 16:41:45 +00:00
bcs .9
2021-06-19 17:46:36 +00:00
2019-07-27 20:51:39 +00:00
>PULLW IO.Open.AUXTYPE
2020-02-14 07:21:56 +00:00
>PULLB IO.Open.TYPE
>PULLB IO.Open.FLAGS
2021-06-19 17:46:36 +00:00
2020-02-14 07:21:56 +00:00
inc pStack discard filename
inc pStack
2021-06-19 17:46:36 +00:00
2021-05-19 12:44:47 +00:00
jmp UNISTD.Open
2018-11-16 16:04:20 +00:00
2020-03-11 16:41:45 +00:00
.9 >POP 6
2021-05-19 12:44:47 +00:00
rts
*/--------------------------------------
2018-06-22 06:24:35 +00:00
* # FClose
* Close a file
2018-07-10 15:33:13 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int fclose ( short int stream );`
2018-07-10 15:33:13 +00:00
* ## ASM
2018-06-18 08:44:02 +00:00
* **In:**
2018-10-04 06:13:44 +00:00
* `lda stream`
2020-02-28 07:21:46 +00:00
* `>SYSCALL FClose`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2018-06-22 06:24:35 +00:00
K.FClose jsr PFT.CheckNodeA
2020-12-15 13:23:22 +00:00
bcs K.FRead.RTS
2019-05-12 20:45:11 +00:00
2021-05-19 12:44:47 +00:00
jmp UNISTD.Close
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # FRead (BLOCKING)
* Read bytes from file
2018-10-04 15:30:14 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int fread (short int stream, void * ptr, int count );`
2018-10-04 15:30:14 +00:00
* ## ASM
2018-06-18 08:44:02 +00:00
* **In:**
2021-05-14 20:58:20 +00:00
* `>PUSHB stream`
2018-07-24 16:00:24 +00:00
* `>PUSHW ptr`
2021-05-14 20:58:20 +00:00
* `>PUSHW count`
2018-07-24 16:00:24 +00:00
* `>SYSCALL fread`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Y,A = Bytes Read
*\--------------------------------------
2021-05-14 20:58:20 +00:00
K.FRead jsr PFT.CheckNode4
bcs K.FWrite.RET5
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
jsr UNISTD.Read
2019-05-21 15:52:52 +00:00
bcs K.FWrite.9
2019-05-12 20:45:11 +00:00
2021-06-19 17:46:36 +00:00
K.FRead.RTS rts
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # FWrite (BLOCKING)
* Write bytes to file
2018-06-19 15:08:22 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int fwrite ( short int stream, const void * ptr, int count );`
2018-06-19 15:08:22 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2021-05-14 20:58:20 +00:00
* `>PUSHB stream`
2018-07-24 16:00:24 +00:00
* `>PUSHW ptr`
2021-05-14 20:58:20 +00:00
* `>PUSHW count`
2018-07-24 16:00:24 +00:00
* `>SYSCALL fwrite`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Y,A = Bytes Written
*\--------------------------------------
2021-05-14 20:58:20 +00:00
K.FWrite jsr PFT.CheckNode4
bcs K.FWrite.RET5
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
jsr UNISTD.Write
bcc K.FRead.RTS
2019-05-12 20:45:11 +00:00
2020-06-30 05:59:37 +00:00
K.FWrite.9 cmp #E.NODATA
2020-06-30 10:40:19 +00:00
sec
2021-05-14 20:58:20 +00:00
bne K.FRead.RTS IO Error
2019-05-12 20:45:11 +00:00
2019-05-21 15:52:52 +00:00
dec pStack FF = NODATA
dec pStack
dec pStack
2021-05-14 20:58:20 +00:00
dec pStack
dec pStack keep stream, ptr & count on stack
2019-05-12 20:45:11 +00:00
inc 0 = BLOCKING
2020-06-30 10:40:19 +00:00
* sec
2021-05-14 20:58:20 +00:00
rts
2020-03-10 16:42:07 +00:00
2021-05-14 20:58:20 +00:00
K.FWrite.RET5 >RET 5
*/--------------------------------------
2018-06-22 06:24:35 +00:00
* # FFlush
2018-07-25 15:26:14 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int fflush( short int stream );`
2018-07-25 15:26:14 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-04 06:13:44 +00:00
* `lda stream`
* `>SYSCALL fflush`
*\--------------------------------------
2018-06-22 06:24:35 +00:00
K.FFlush jsr PFT.CheckNodeA
2018-10-04 06:13:44 +00:00
bcs .9
2019-05-12 20:45:11 +00:00
lda (pFD)
bne STDIO.IOERR
>MLICALL MLIFLUSH
2018-10-04 06:13:44 +00:00
.9 rts
2019-05-12 20:45:11 +00:00
*--------------------------------------
STDIO.IOERR lda #MLI.E.IO
sec
rts
*/-------------------------------------
* # FSeek
* Set the file-position indicator for hFILE
2018-07-25 15:26:14 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int fseek( short int stream, long offset, short int whence );`
2018-07-25 15:26:14 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2021-05-14 20:58:20 +00:00
* `>PUSHB stream`
2018-08-08 15:13:37 +00:00
* `>PUSHL offset`
2021-05-14 20:58:20 +00:00
* `>PUSHB whence`
2018-08-08 15:13:37 +00:00
* `>SYSCALL fseek`
*\-------------------------------------
2021-05-14 20:58:20 +00:00
K.FSeek ldy #5
jsr PFT.CheckNodeY
2018-11-16 16:04:20 +00:00
bcc .11
2019-05-12 20:45:11 +00:00
>RET 5
2019-07-26 06:28:52 +00:00
.11 lda (pFD)
bne STDIO.IOERR
2021-06-19 17:46:36 +00:00
2019-09-24 15:25:07 +00:00
>PULLA whence
2021-05-14 20:58:20 +00:00
tax
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
>PULLL ACC32
cpx #SEEK.END
2019-07-27 20:51:39 +00:00
beq .30
2021-05-14 20:58:20 +00:00
bcs .98
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
dex
2019-07-27 20:51:39 +00:00
beq .20
2019-05-12 20:45:11 +00:00
2019-07-27 20:51:39 +00:00
stz K.MLI.PARAMS+2
stz K.MLI.PARAMS+3
stz K.MLI.PARAMS+4
2018-05-22 06:01:05 +00:00
bra .8
2018-10-02 15:52:30 +00:00
* SEEK.CUR
.20 >MLICALL MLIGETMARK
bcc .8
rts
2018-10-02 15:52:30 +00:00
* SEEK.END
.30 >MLICALL MLIGETEOF
bcs .9
.8 ldy #0
2019-05-12 20:45:11 +00:00
clc
2019-05-12 20:45:11 +00:00
.81 lda K.MLI.PARAMS+2,y
2019-07-27 20:51:39 +00:00
adc ACC32,y
sta K.MLI.PARAMS+2,y
iny
2019-07-27 20:51:39 +00:00
tya 3 bytes, 24 bits!!!
eor #3
bne .81
2019-05-12 20:45:11 +00:00
2021-06-19 17:46:36 +00:00
bcs .99 Offset out of range!
.82 >MLICALL MLISETMARK
bcc .9
cmp #MLI.E.BEYEOF
bne .9
>MLICALL MLISETEOF
bcc .82
.9 rts
2018-11-20 15:54:49 +00:00
.98 lda #E.BADARG
.HS 2C bit abs
2018-10-21 20:54:07 +00:00
.99 lda #E.FTB
2019-07-25 15:10:59 +00:00
* sec
2019-10-03 06:25:27 +00:00
K.FSeek.RTS rts
*/--------------------------------------
2018-06-22 06:24:35 +00:00
* # FEOF
* Test the end-of-file indicator for hFILE
2018-10-04 06:13:44 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int feof( short int stream );`
2018-10-04 06:13:44 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-04 06:13:44 +00:00
* `lda stream`
* `>SYSCALL feof`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2021-06-19 17:46:36 +00:00
* CC :
2019-05-02 09:52:32 +00:00
* A = $ff EOF
* A = 0 NOT EOF
* CS :
*\--------------------------------------
2018-06-22 06:24:35 +00:00
K.FEOF jsr PFT.CheckNodeA
2019-06-28 15:15:58 +00:00
bcs K.FSeek.RTS
2019-05-12 20:45:11 +00:00
2021-05-14 20:58:20 +00:00
lda (pFD)
2019-07-31 15:10:59 +00:00
tax
jmp (.1,x)
2020-09-09 12:47:18 +00:00
.1 .DA FS.EOF.REG
2019-07-31 15:10:59 +00:00
.DA STDIO.IOERR DIR
2021-05-14 20:58:20 +00:00
.DA DEV.EOF
2019-07-31 15:10:59 +00:00
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
2021-05-19 12:44:47 +00:00
.DA SOCK.EOF
2021-05-14 20:58:20 +00:00
.DA PIPE.EOF
*/--------------------------------------
* # FTell
* Return the current value of the file-position indicator
2018-07-25 15:26:14 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `long ftell( short int stream );`
2018-07-25 15:26:14 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-08-08 15:13:37 +00:00
* `lda stream`
* `>SYSCALL ftell`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-08-08 15:13:37 +00:00
* On stack (long)
*\--------------------------------------
2018-08-08 15:13:37 +00:00
K.FTell jsr PFT.CheckNodeA
2018-11-16 16:04:20 +00:00
bcs .9
>MLICALL MLIGETMARK
bcs .9
2019-05-12 20:45:11 +00:00
lda #0
2018-08-08 15:13:37 +00:00
>PUSHA
2019-05-12 20:45:11 +00:00
2018-08-08 15:13:37 +00:00
ldy #2
2019-05-12 20:45:11 +00:00
.1 lda K.MLI.PARAMS+2,y
2018-08-08 15:13:37 +00:00
>PUSHA
dey
bpl .1
2019-05-12 20:45:11 +00:00
.9 rts
*/--------------------------------------
2018-06-22 06:24:35 +00:00
* # Remove
2018-10-04 06:13:44 +00:00
* Remove a file or directory
* ## C
2020-08-02 12:19:43 +00:00
* `int remove ( const char *pathname );`
2018-10-04 06:13:44 +00:00
* ## ASM
* **In:**
2020-05-20 13:14:28 +00:00
* `>LDYA pathname`
2018-10-04 06:13:44 +00:00
* `>SYSCALL remove`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2020-05-20 13:14:28 +00:00
K.Remove jsr PFT.CheckPathYA
2018-11-16 16:04:20 +00:00
bcs .9
2019-05-12 20:45:11 +00:00
>MLICALL MLIDESTROY
2020-05-20 13:14:28 +00:00
.9 rts
*/--------------------------------------
* # Rename
* Rename a file
2018-08-08 15:13:37 +00:00
* ## C
2020-08-02 12:19:43 +00:00
* `int rename ( const char * oldpath, const char * newpath );`
2018-08-08 15:13:37 +00:00
* ## ASM
2018-06-18 08:44:02 +00:00
* **In:**
2020-02-14 07:21:56 +00:00
* `>PUSHW oldpath`
2018-08-08 15:13:37 +00:00
* `>PUSHW newpath`
* `>SYSCALL rename`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2020-02-14 07:21:56 +00:00
K.Rename jsr PFT.CheckPath2
2018-11-16 16:04:20 +00:00
bcs .9
2020-03-10 16:42:07 +00:00
lda (pStack)
sta ZPPtr1
2021-06-19 17:46:36 +00:00
2020-03-10 16:42:07 +00:00
ldy #1
lda (pStack),y
sta ZPPtr1+1
2021-06-19 17:46:36 +00:00
2020-03-10 16:42:07 +00:00
dey ldy #0
2019-05-12 20:45:11 +00:00
2019-10-10 10:23:02 +00:00
.1 lda (ZPPtr1),y
beq .8
2019-10-10 10:23:02 +00:00
iny
sta K.Buf256,y
cpy #MLI.MAXPATH
bne .1
2019-05-12 20:45:11 +00:00
.8 sty K.Buf256
>LDYAI K.Buf256
>STYA K.MLI.PARAMS+3
>MLICALL MLIRENAME
2020-03-10 16:42:07 +00:00
.9 >RET 4
2020-12-23 14:54:57 +00:00
*/--------------------------------------
* # PrintF (BLOCKING)
* # FPrintF (BLOCKING)
* # SPrintF
* Prints C-Style String
* ## C
* `int printf ( const char *format, ... );`
* `int fprintf ( short int stream, const char *format, ... );`
* `int sprintf ( char *str, const char *format, ... );`
* ## ASM
* **In:**
2021-06-19 17:46:36 +00:00
* PrintF : (example is for printing Y,A as integer : format="%I", 2 bytes)
2020-12-23 14:54:57 +00:00
* `>PUSHW format`
* `>PUSHW i`
* `...`
* `>PUSHBI 2` #bytecount
* `>SYSCALL PrintF`
2021-06-19 17:46:36 +00:00
* FPrintF :
2020-12-23 14:54:57 +00:00
* `>PUSHB hFILE`
* `>PUSHW format`
* `>PUSHW i`
* `...`
* `>PUSHBI 2` #bytecount
* `>SYSCALL fprintf`
2021-06-19 17:46:36 +00:00
* SPrintF :
2020-12-23 14:54:57 +00:00
* `>PUSHW str`
* `>PUSHW format`
* `>PUSHW i`
* `...`
* `>PUSHBI 2` #bytecount
* `>SYSCALL sprintf`
* ## RETURN VALUE
* CC : success, Y,A = bytes sent
* CS : error, A = code from Output
* Specifiers :
2021-06-19 17:46:36 +00:00
* + %b : pull 1 byte to Print BIN
2020-12-23 14:54:57 +00:00
* + %d : pull 1 byte unsigned DEC 0..255
* + %D : pull 2 bytes unsigned DEC 0..65535
* + %u : pull 4 bytes long unsigned DEC 0..4294967295
* + %e : pull 5 Bytes float (-)1.23456789e+12
* + %f : pull 5 Bytes float (-)3.1415
* + %h : pull 1 byte to Print HEX
* + %H : pull 2 bytes to Print HEX
* + %i : pull 1 byte to Print signed DEC -128..127
* + %I : pull 2 bytes to Print signed DEC -32768..32767
* + %L : pull 4 bytes signed DEC -2147483648..2147483647
* + %s : pull 2 bytes ptr to C-Style String
* + %S : pull 2 bytes ptr to P-Style String
* + \b : Print 'BS' (08)
* + \e : Print 'ESC' ($1B,27)
* + \f : Print 'FF' ($0C,12)
* + \n : Print 'LF' ($0A,10)
* + \r : Print 'CR' ($0D,13)
* + \t : Print 'TAB' ($09,09)
* + \v : Print 'VT' ($0B,11)
* + \xHH : Print byte with hexadecimal value HH (1 to 2 digits)
* + \\\\ : Print \
* + \\% : Print %
2021-06-19 17:46:36 +00:00
* Modifiers for len and padding :
2020-12-23 14:54:57 +00:00
* + %d : '9' '12'
* + %2d : ' 9' '12'
* + %02d : '09' '12'
2021-06-19 17:46:36 +00:00
* + %11s : 'ABCDEFGH '
2020-12-23 14:54:57 +00:00
* + %011s : 'ABCDEFGH000'
* + %2f : '3.14'
*\--------------------------------------
.DUMMY ZPTMP+5,5 Used by : STDIO2
.OR ZPTMP+5 5 Bytes
PrintF.Cnt .BS 2
PrintF.hFILE .BS 1
2021-05-04 17:31:21 +00:00
STDIO.iStkB .BS 1
STDIO.PopCnt .BS 1
2020-12-23 14:54:57 +00:00
.ED
*--------------------------------------
K.PrintF.PadL .EQ FAC+5
K.PrintF.PadC .EQ ARG.SIGN
*--------------------------------------
K.PrintF ldy #S.PS.hStdOut
lda (pPS),y
sta PrintF.hFILE
ldx #1
.HS 2C BIT ABS
*--------------------------------------
K.FPrintf ldx #2
.HS 2C BIT ABS
*--------------------------------------
K.SPrintf ldx #3
*--------------------------------------
K.PrintF.1 sec format string->ptr2
jsr STDIO.GetParams
stx pIOBuf
sta pIOBuf+1 Output buffer->pIOBuf
2021-05-04 17:31:21 +00:00
sty STDIO.PopCnt Total bytes to POP
2020-12-23 14:54:57 +00:00
2021-05-04 17:31:21 +00:00
.1 jsr SHARED.GetCP2
2020-12-23 14:54:57 +00:00
bne .22
jmp .8 end of format..
.22 cmp #'%'
bne .10
stz K.PrintF.PadL
stz K.PrintF.PadC
lda (ZPPtr2)
beq .7 end of format... print % and exit
jsr ZP.IsDigit
bcs .6 no digit....go check specifier
cmp #'0' ...a 0...mmm... padding char?
bne .4
sta K.PrintF.PadC
2021-05-04 17:31:21 +00:00
jsr SHARED.NextCP2 skip 0 ...
2020-12-23 14:54:57 +00:00
lda (ZPPtr2)
beq .7
jsr ZP.IsDigit
bcs .6 %0x ??????
2021-04-29 11:56:34 +00:00
.4 jsr MATH.Dec2ACC32
2020-12-23 14:54:57 +00:00
bcs .99
lda ACC32
sta K.PrintF.PadL
lda K.PrintF.PadC
bne .5
lda #C.SPACE
sta K.PrintF.PadC
2021-05-04 17:31:21 +00:00
.5 jsr SHARED.AddY2P2 skip all processed chars
2020-12-23 14:54:57 +00:00
lda (ZPPtr2)
beq .7
.6 ldx #PrintFTBL1.Cnt-1 do we have a %x command?
.61 cmp PrintFTBL1,x
beq .62
dex
bpl .61
bra .20 unknown ...
2021-05-04 17:31:21 +00:00
.62 jsr SHARED.NextCP2
2020-12-23 14:54:57 +00:00
txa yes, jmp to it!
asl
tax
jsr PrintF.ESC
.11 bcc .1
bra .99
.7 lda #'%'
bra .20
2021-06-19 17:46:36 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
.10 cmp #'\'
bne .20
2021-05-04 17:31:21 +00:00
jsr SHARED.GetCP2
2020-12-23 14:54:57 +00:00
beq .99
ldx #PrintFTBL2.Cnt-1
.12 cmp PrintFTBL2,x
beq .19
dex
bpl .12
cmp #'x' \xHH
bne .1
2021-04-29 11:56:34 +00:00
jsr MATH.Hex2ACC32
2020-12-23 14:54:57 +00:00
bcs .99
2021-05-04 17:31:21 +00:00
jsr SHARED.AddY2P2
2020-12-23 14:54:57 +00:00
.14 lda ACC32
bra .20
.19 lda PrintFTBL2.OUT,x
.20 jsr PrintF.PutC
bcc .11
*--------------------------------------
.99 lda #E.BADARG
sec
jmp STDIO.Exit
*--------------------------------------
2021-05-14 20:58:20 +00:00
.8 lda PrintF.hFILE
2020-12-23 14:54:57 +00:00
beq .80 Writing to buffer, append \0
2021-05-14 20:58:20 +00:00
>PUSHA
2020-12-23 14:54:57 +00:00
>PUSHWI K.IOBuf
2021-05-14 20:58:20 +00:00
>PUSHW PrintF.Cnt Writing to File/dev...
2021-06-17 17:38:34 +00:00
ldx #SYS.FWrite Needed by PFT
2020-12-23 14:54:57 +00:00
jsr K.FWrite
bcc .81
tay
bne .9
2021-06-19 17:46:36 +00:00
2021-05-14 20:58:20 +00:00
>RET 5 0=BLOCKING
2020-12-23 14:54:57 +00:00
.80 ldy PrintF.Cnt A=0, Writing to buffer, append \0
sta (pIOBuf),y
clc
2021-05-04 17:31:21 +00:00
2020-12-23 14:54:57 +00:00
.81 >LDYA PrintF.Cnt
* clc
.9 jmp STDIO.Exit
*--------------------------------------
PrintFTBL1 .AS "bdDuefhHiILsS"
PrintFTBL1.Cnt .EQ *-PrintFTBL1
PrintFTBL2 .AS "abefnrtv\%"
PrintFTBL2.Cnt .EQ *-PrintFTBL2
PrintFTBL2.OUT .HS 07.08.1B.0C.0A.0D.09.0B \a\b\e\f\n\r\t\v
.DA #'\' \\
.DA #'%' \%
*--------------------------------------
PrintF.ESC jmp (.1,x)
.1 .DA PrintF.B
.DA PrintF.D,PrintF.DD,PrintF.U
.DA PrintF.E,PrintF.F
.DA PrintF.H,PrintF.HH
.DA PrintF.I,PrintF.II,PrintF.L
.DA PrintF.S,PrintF.SS
*--------------------------------------
2021-05-04 17:31:21 +00:00
PrintF.B jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
bcs PrintF.B.RTS
ldy #8
.1 asl
pha
lda #'0'/2
rol
jsr PrintF.PutC
bcs .9
pla
dey
bne .1
rts
.9 ply
PrintF.B.RTS
rts
*--------------------------------------
PrintF.I sec signed short
.HS 90 BCC
PrintF.D clc unsigned short (BYTE)
ldy #1
bra PrintF.NUM
PrintF.II sec signed int
.HS 90 BCC
PrintF.DD clc unsigned int (WORD)
ldy #2
bra PrintF.NUM
PrintF.L sec signed long
.HS 90 BCC
PrintF.U clc unsigned long (DWORD)
ldy #4
PrintF.NUM sty .2+1
ror ACC32.Sign save signed/unsigned flag
2021-04-29 11:56:34 +00:00
jsr M32.ACC32Z
2020-12-23 14:54:57 +00:00
2021-05-04 17:31:21 +00:00
.1 jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
bcs PrintF.B.RTS
sta ACC32-1,y PULL 4,2 or 1
dey
bne .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
bit ACC32.Sign
bpl .4
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.2 ldy #$ff SELF MODIFIED
lda ACC32-1,y Get highest Byte
bpl .4 positive....
lda #$ff
.3 cpy #4
beq .4
iny
sta ACC32-1,y
bra .3
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.4 ldx K.PrintF.PadL
ldy K.PrintF.PadC
rol ACC32.Sign get back signed/unsigned flag
2021-04-29 11:56:34 +00:00
jsr MATH.ACC322STR10
2020-12-23 14:54:57 +00:00
bra PrintF.StrNum
2021-06-19 17:46:36 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
* EXP(8) 1(s) 1significants(31)
* http://apple2.org.za/gswv/a2zine/GS.WorldView/Resources/GS.TECH.INFO/AppleSoft/
2021-06-19 17:46:36 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
PrintF.E sec Force "E+12"
.HS 90 BCC
PrintF.F clc
lda (pStack) get current stack Ptr
sec at least 5 bytes remaining ?
sbc #5
bcc PrintF.StrNum.Err
sta (pStack)
* sec
adc pStack
ldy pStack+1 A,Y = float
ldx #FPU.SETFAC
jsr GP.ROMCALL
2021-05-04 17:31:21 +00:00
ldy #FOUTBuf+1 FOUT.1 will do a DEY
2020-12-23 14:54:57 +00:00
ldx #FPU.FOUT
jsr GP.ROMCALL
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
PrintF.StrNum ldy #0
2021-05-04 17:31:21 +00:00
.2 lda FOUTBuf,y
2020-12-23 14:54:57 +00:00
beq .8
iny
jsr PrintF.PutC
bcc .2
.9 rts
.8 clc
rts
PrintF.StrNum.Err
lda #E.STACK
sec
rts
*--------------------------------------
PrintF.S ldy #$ff CSTR
.HS 2C bit abs
PrintF.SS ldy #$00 PSTR
sty .1+1
2021-06-19 17:46:36 +00:00
2021-05-04 17:31:21 +00:00
jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
bcs .9
sta ZPPtr1+1
2021-05-04 17:31:21 +00:00
jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
bcs .9
sta ZPPtr1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
lda (ZPPtr1) if CSTR:last char=0, if PSTR:len=0
beq .8
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
ldy .1+1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.1 lda #$ff Self Modified
bne .11 CSTR
tya PSTR
cmp (ZPPtr1) len check
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
beq .2
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.11 iny
lda (ZPPtr1),y
beq .2
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
jsr PrintF.PutC
bcs .9
lda K.PrintF.PadL
beq .1
cpy K.PrintF.PadL
bne .1
.8 clc
rts
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.2 lda K.PrintF.PadL
beq .8
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.3 cpy K.PrintF.PadL
beq .8
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
lda K.PrintF.PadC
jsr PrintF.PutC
bcs .9
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
iny
bne .3
* clc
.9 rts
*--------------------------------------
2021-05-04 17:31:21 +00:00
PrintF.HH jsr STDIO.GetStkB
bcs STDIO.RTS
2020-12-23 14:54:57 +00:00
pha LO byte
2021-05-04 17:31:21 +00:00
jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
plx
2021-05-04 17:31:21 +00:00
bcs STDIO.RTS
2020-12-23 14:54:57 +00:00
pha
txa
jsr PrintF.H.1
plx
2021-05-04 17:31:21 +00:00
bcs STDIO.RTS
2020-12-23 14:54:57 +00:00
txa
bra PrintF.H.1
*--------------------------------------
2021-05-04 17:31:21 +00:00
PrintF.H jsr STDIO.GetStkB
bcs STDIO.RTS
2021-04-29 11:56:34 +00:00
PrintF.H.1 jsr STDIO.A2HexAX
2020-12-23 14:54:57 +00:00
jsr PrintF.PutC
2021-05-04 17:31:21 +00:00
bcs STDIO.RTS
2020-12-23 14:54:57 +00:00
txa
*--------------------------------------
PrintF.PutC phy
ldy PrintF.Cnt
sta (pIOBuf),y
ply
inc PrintF.Cnt
bne .8
2021-05-14 20:58:20 +00:00
2020-12-23 14:54:57 +00:00
lda PrintF.hFILE
bne .9
inc pIOBuf+1
inc PrintF.Cnt+1
.8 clc
rts
.9 lda #E.BUF
sec
2021-06-19 17:46:36 +00:00
STDIO.RTS rts
2020-12-23 14:54:57 +00:00
*/--------------------------------------
* # ScanF (BLOCKING)
* # FScanF (BLOCKING)
* # SScanF
* Read formatted data from string
* ## C
* `int scanf( const char *format, ... );`
* `int fscanf( short int stream, const char *format, ... );`
* `int sscanf ( const char *s, const char *format, ... );`
* ## ASM
* **In:**
* ScanF :
* `>PUSHW format`
* `>PUSHW ptr`
* `...`
* `>PUSHB bytecount`
* `>SYSCALL scanf`
* FScanF :
* `>PUSHB stream`
* `>PUSHW format`
* `>PUSHW ptr`
* `...`
* `>PUSHB bytecount`
* `>SYSCALL fscanf`
* SScanF :
* `>PUSHW s`
* `>PUSHW format`
* `>PUSHW ptr`
* `...`
* `>PUSHB bytecount`
* `>SYSCALL sscanf`
* Specifiers :
* + %i : short int
* + %d : byte
* + %I : int
* + %D : word
* + %L : long int
* + %U : dword
* + %h : HEX byte
* + %H : HEX word
* + %s : string
* TODO : %10s
* ## RETURN VALUE
* A = Number of arguments filled.
*\--------------------------------------
K.ScanF ldy #S.PS.hStdIn
lda (pPS),y
sta PrintF.hFILE
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
ldx #1
.HS 2C BIT ABS
*--------------------------------------
K.FScanF ldx #2
.HS 2C BIT ABS
*--------------------------------------
K.SScanF ldx #3
*--------------------------------------
K.SScanF.1 clc format string->ptr1
jsr STDIO.GetParams
stx ZPPtr2
sta ZPPtr2+1 Output buffer->ZPPtr2
2021-05-04 17:31:21 +00:00
sty STDIO.PopCnt Total bytes to POP
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
ldx PrintF.hFILE
beq .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
txa
>PUSHA
>PUSHW pIOBuf
2021-06-19 17:46:36 +00:00
>PUSHWI 256
2020-12-23 14:54:57 +00:00
jsr K.FGetS
bcc .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
tax
2021-05-04 17:31:21 +00:00
bne STDIO.RTS
2020-12-23 14:54:57 +00:00
>RET 4
2021-06-19 17:46:36 +00:00
2021-05-04 17:31:21 +00:00
.1 jsr SHARED.GetCP1 End Of format?
2020-12-23 14:54:57 +00:00
beq .8
cmp #'%' Escape ?
beq .2
cmp #C.SPACE Space ?
beq .12
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
sta .11+1
2021-06-19 17:46:36 +00:00
2021-05-04 17:31:21 +00:00
jsr SHARED.GetCP2
2020-12-23 14:54:57 +00:00
beq .9
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.11 cmp #$ff Same char in string?
beq .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
bra .9
2021-05-04 17:31:21 +00:00
.12 jsr SHARED.GetCP2
2020-12-23 14:54:57 +00:00
beq .9
cmp #C.SPACE
bne .9
2021-06-19 17:46:36 +00:00
2021-05-04 17:31:21 +00:00
.13 jsr SHARED.GetCP2
2020-12-23 14:54:57 +00:00
cmp #C.SPACE another space ?
beq .13
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
bra .1
2021-05-04 17:31:21 +00:00
.2 jsr SHARED.GetCP1 Get specifier after %
2020-12-23 14:54:57 +00:00
beq .9 unexpected End of format after "%" ?
ldx #K.SScanFJMP-K.SScanFTBL-2
.3 cmp K.SScanFTBL,x
beq .4
dex
dex
bpl .3
.9 lda #MLI.E.EOF
sec
jmp STDIO.Exit
2021-05-04 17:31:21 +00:00
.4 jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
bcs .9
sta ZPPtr3+1
2021-05-04 17:31:21 +00:00
jsr STDIO.GetStkB
2020-12-23 14:54:57 +00:00
bcs .9
sta ZPPtr3
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
jsr .5
bcs .9 out of Ptr on stack
inc .8+1 parsed one more arg!
bra .1
.8 lda #$ff SELF MODIFIED Arg processed
clc
jmp STDIO.Exit
*--------------------------------------
.5 jmp (K.SScanFJMP,x)
*--------------------------------------
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
.DA K.SScanF.DD
.DA K.SScanF.L
.DA K.SScanF.U
.DA K.SScanF.H
.DA K.SScanF.HH
.DA K.SScanF.S
*--------------------------------------
2021-06-19 17:46:36 +00:00
K.SScanF.I
K.SScanF.D
2020-12-23 14:54:57 +00:00
K.SScanF.II
K.SScanF.DD
K.SScanF.L
K.SScanF.U lda K.SScanFTBL+1,x Get VAR size
pha Save VAL size
2021-04-29 11:56:34 +00:00
jsr MATH.Dec2ACC32
2020-12-23 14:54:57 +00:00
bra K.SScanF.GetVAL
*--------------------------------------
K.SScanF.HH
K.SScanF.H lda K.SScanFTBL+1,x Get VAR size
pha
2021-04-29 11:56:34 +00:00
jsr MATH.Hex2ACC32
2020-12-23 14:54:57 +00:00
2021-05-04 17:31:21 +00:00
K.SScanF.GetVAL jsr SHARED.AddY2P2 Y=char count parsed
2020-12-23 14:54:57 +00:00
2021-06-19 17:46:36 +00:00
.1 ply get back VAL size
2020-12-23 14:54:57 +00:00
.2 lda ACC32-1,y
dey
sta (ZPPtr3),y
bne .2
.9 rts
*--------------------------------------
K.SScanF.S ldy #$ff
.1 iny
lda (ZPPtr2),y Get char in string to scan
sta (ZPPtr3),y store in param ptr
beq K.SScanF.Fwd end of string to scan ?
2021-06-19 17:46:36 +00:00
cmp (ZPPtr1) match format next char ?
2020-12-23 14:54:57 +00:00
beq .2
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
cmp #C.SPACE is it a space ?
bne .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.2 lda #0 add \0 to param ptr
sta (ZPPtr3),y
2021-05-04 17:31:21 +00:00
K.SScanF.Fwd jmp SHARED.AddY2P2 Y=char count parsed
2020-12-23 14:54:57 +00:00
*--------------------------------------
* IN:
* CC : format in ZPPtr1
* CS : format in ZPPtr2
* X = 3 : get format & buffer
* X = 2 : get format & hFile
* X = 1 : get format only
* OUT:
* X = Buf LO
* A = Buf HI
* format on stack
* Y = BytePtr
*--------------------------------------
STDIO.GetParams stz PrintF.Cnt
stz PrintF.Cnt+1
lda (pStack) Bytecount
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
tay
2021-05-04 17:31:21 +00:00
sty STDIO.iStkB
2020-12-23 14:54:57 +00:00
iny
lda (pStack),y format LO
pha
iny
lda (pStack),y format HI
bcs .10
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
sta ZPPtr1+1
pla
sta ZPPtr1
bra .11
.10 sta ZPPtr2+1
pla
sta ZPPtr2
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.11 dex
beq .1
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
dex
beq .2
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
.3 stz PrintF.hFILE
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
iny
lda (pStack),y str LO
tax
iny
lda (pStack),y str HI
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
rts
.2 iny
lda (pStack),y hFILE
sta PrintF.hFILE
.1 ldx #K.IOBuf
lda /K.IOBuf
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
rts
*--------------------------------------
2021-05-04 17:31:21 +00:00
STDIO.GetStkB phy
2020-12-23 14:54:57 +00:00
2021-05-04 17:31:21 +00:00
ldy STDIO.iStkB
2020-12-23 14:54:57 +00:00
beq .9
lda (pStack),y
2021-05-04 17:31:21 +00:00
dec STDIO.iStkB
2020-12-23 14:54:57 +00:00
ply
clc
rts
.9 lda #E.STACK
ply
sec
rts
*--------------------------------------
STDIO.Exit php
pha
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
lda pStack
sec
2021-05-04 17:31:21 +00:00
adc STDIO.PopCnt
2020-12-23 14:54:57 +00:00
sta pStack
2021-06-19 17:46:36 +00:00
2020-12-23 14:54:57 +00:00
pla
plp
rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
* Convert A to 2 hex digits in AX
*--------------------------------------
STDIO.A2HexAX pha
and #$0F
jsr .8
tax
pla
lsr
lsr
lsr
lsr
.8 ora #$30
cmp #'9'+1
bcc .9
adc #6
.9 rts
*--------------------------------------
MAN
2020-05-26 14:23:09 +00:00
SAVE usr/src/sys/kernel.s.stdio
LOAD usr/src/sys/kernel.s
ASM