A2osX/SYS/KERNEL.S.STDIO.txt

1385 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
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # putchar (BLOCKING)
2018-10-04 15:30:14 +00:00
* Print A (char) to StdOut
2018-06-18 06:22:50 +00:00
* ## C
2020-03-10 16:42:07 +00:00
* `int putchar ( short int character );`
2018-06-18 06:22:50 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2019-02-22 16:08:37 +00:00
* `lda character`
2018-10-04 15:30:14 +00:00
* `>SYSCALL putchar`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-06-18 06:22:50 +00:00
* CC = success
*\--------------------------------------
2019-02-22 16:08:37 +00:00
K.PutChar >PUSHA character
ldy #S.PS.hStdOut
2020-02-28 07:21:46 +00:00
lda (pPS),y
2019-02-22 16:08:37 +00:00
jsr K.FPutC
2020-08-25 10:56:00 +00:00
bcc .8
2019-05-12 20:45:11 +00:00
2020-08-25 10:56:00 +00:00
tay
bne .8
2019-05-12 20:45:11 +00:00
2020-08-25 10:56:00 +00:00
>PULLA CS,A=0:BLOCKING, restore A
2019-05-12 20:45:11 +00:00
2020-08-25 10:56:00 +00:00
.8 rts
2018-11-16 16:04:20 +00:00
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # fputc (BLOCKING)
2018-11-16 16:04:20 +00:00
* Print A (char) to hFILE
* ## C
2020-03-10 16:42:07 +00:00
* `int fputc ( hFILE stream , short int character );`
2018-11-16 16:04:20 +00:00
* ## ASM
* **In:**
* `>PUSHB character`
* `lda stream`
* `>SYSCALL fputc`
* ## RETURN VALUE
* CC = success
*\--------------------------------------
K.FPutC jsr PFT.CheckNodeA
2020-08-25 10:56:00 +00:00
bcs .8
2019-05-12 20:45:11 +00:00
2019-02-22 16:08:37 +00:00
lda (pStack) character
2019-02-22 21:54:47 +00:00
sta K.IOBuf
2018-08-08 15:13:37 +00:00
2019-05-12 20:45:11 +00:00
lda #0
>PUSHA
inc write 1 byte
>PUSHA
>PUSHWI K.IOBuf buf
2019-07-27 20:51:39 +00:00
jsr UNISTD.Write
2020-08-25 10:56:00 +00:00
bcc .8 pop char...
2020-06-30 05:59:37 +00:00
cmp #E.NODATA
2020-06-30 10:40:19 +00:00
sec
2020-08-25 10:56:00 +00:00
bne .8
2019-05-12 20:45:11 +00:00
2020-08-25 10:56:00 +00:00
inc CS,A=0:BLOCKING
rts
.8 >POP 1
2019-02-25 14:47:31 +00:00
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`
2018-10-11 15:23:06 +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
ldy #0
2020-08-25 10:56:00 +00:00
.1 lda $FFFF,y SELF MODIFIED
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
sta K.IOBuf,y
iny
bne .1
.9 lda #E.BUF
sec
rts
.2 lda #C.CR
sta K.IOBuf,y
iny
beq .9
lda #C.LF
sta K.IOBuf,y
iny
beq .9
lda #0
sta K.IOBuf,y
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
2018-10-04 15:30:14 +00:00
jsr K.FPutS
2020-08-25 10:56:00 +00:00
2019-07-25 15:10:59 +00:00
bcc K.PutS.RTS
2020-08-25 10:56:00 +00:00
tay
2020-06-30 10:40:19 +00:00
bne K.PutS.RTS
2019-05-22 07:38:18 +00:00
2020-08-25 10:56:00 +00:00
>LDYA .1+1 CS,A=0:BLOCKING, restore Y,A
2019-07-25 15:10:59 +00:00
2020-08-25 10:56:00 +00:00
K.PutS.RET3 >POP 3 pop StdOut & buffer
2019-07-25 15:10:59 +00:00
K.PutS.RTS rts
*/--------------------------------------
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`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-06-18 06:22:50 +00:00
* CC = success
*\--------------------------------------
2020-08-25 10:56:00 +00:00
K.FPutS jsr PFT.CheckNode2 set IO.hFD
bcs K.PutS.RET3
2018-07-27 13:34:34 +00:00
2019-05-12 20:45:11 +00:00
lda (pStack)
sta ZPPtr2 Get String
ldy #1
lda (pStack),y
sta ZPPtr2+1
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
2019-05-12 20:45:11 +00:00
.1 lda (ZPPtr2),y
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
bra .1
2020-08-25 10:56:00 +00:00
2019-05-12 20:45:11 +00:00
.2 txa
>PUSHA push len HI
tya
>PUSHA push len LO
>PUSHW ZPPtr2
2019-07-27 20:51:39 +00:00
jsr UNISTD.Write
2020-08-25 10:56:00 +00:00
bcc K.PutS.RET3
2020-06-30 05:59:37 +00:00
cmp #E.NODATA
2020-06-30 10:40:19 +00:00
sec
2020-08-25 10:56:00 +00:00
bne K.PutS.RET3 IO Error
2020-03-04 16:38:32 +00:00
inc FF-> 0 = BLOCKING
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`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-07-27 13:34:34 +00:00
* Y,A: s
* 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
*--------------------------------------
2020-12-23 14:54:57 +00:00
K.FGetS jsr PFT.CheckNode4
2020-02-14 16:32:52 +00:00
bcs K.FPutS.RTS
2018-08-08 15:13:37 +00:00
2020-12-23 14:54:57 +00:00
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
lda ZPPtr1+1
bmi .4 already something in buffer
2019-05-31 07:31:41 +00:00
2020-12-23 14:54:57 +00:00
.2 jsr STDIO.Get.1
bcc .3
2020-06-30 05:59:37 +00:00
2020-12-15 13:23:22 +00:00
cmp #MLI.E.EOF
beq .9
2020-06-30 05:59:37 +00:00
cmp #E.NODATA
2020-06-30 10:40:19 +00:00
sec
2020-06-30 05:59:37 +00:00
bne .9 IO error
2020-12-15 13:23:22 +00:00
lda #0 BLOCKING
2019-05-31 07:31:41 +00:00
rts
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
2020-12-23 14:54:57 +00:00
bra .5
2020-12-15 13:23:22 +00:00
*--------------------------------------
2020-03-11 16:41:45 +00:00
.4 jsr STDIO.Get.1
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
2020-06-30 05:59:37 +00:00
2019-07-28 20:39:30 +00:00
jsr SHARED.PutCharPtr2
2020-12-23 14:54:57 +00:00
inc ZPPtr1
bne .4
inc ZPPtr1+1
bne .4
beq .8 Buffer full
2020-06-30 05:59:37 +00:00
2020-12-23 14:54:57 +00:00
.6 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
cmp #E.NODATA
2020-06-30 10:40:19 +00:00
sec
2020-06-30 05:59:37 +00:00
bne .9 I/O error
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`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* CC = success
* A = char
*\--------------------------------------
K.GetChar ldy #S.PS.hStdIn
2020-02-28 07:21:46 +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`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* CC = success
* A = char
2018-10-05 14:58:38 +00:00
*\--------------------------------------
2018-11-16 16:04:20 +00:00
K.GetC jsr PFT.CheckNodeA
2019-02-22 16:08:37 +00:00
bcs K.GetC.RTS
2019-05-12 20:45:11 +00:00
2020-03-11 16:41:45 +00:00
jsr STDIO.Get.1
2019-02-22 16:08:37 +00:00
bcc .8
2020-06-30 05:59:37 +00:00
cmp #E.NODATA
2020-06-30 10:40:19 +00:00
sec
2020-06-30 05:59:37 +00:00
bne K.GetC.RTS I/O error
2019-05-12 20:45:11 +00:00
inc 0 = BLOCKING
rts
2019-02-22 16:08:37 +00:00
.8 lda K.IOBuf
2019-05-04 21:13:50 +00:00
2019-07-15 06:41:12 +00:00
K.GetC.RTS rts
*--------------------------------------
2020-03-11 16:41:45 +00:00
STDIO.Get.1 lda #0
2019-07-15 06:41:12 +00:00
>PUSHA
inc read 1 byte
>PUSHA
>PUSHWI K.IOBuf
2019-07-27 20:51:39 +00:00
jmp UNISTD.READ
*/--------------------------------------
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`
* ## RETURN VALUE
* 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
2018-10-11 15:23:06 +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
2020-12-15 13:23:22 +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
inc pStack discard filename
inc pStack
2020-12-15 13:23:22 +00:00
jmp UNISTD.Open
2018-11-16 16:04:20 +00:00
2020-03-11 16:41:45 +00:00
.9 >POP 6
.99 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
2020-12-15 13:23:22 +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:**
2018-07-24 16:00:24 +00:00
* `>PUSHWI count`
* `>PUSHW ptr`
2018-10-04 06:13:44 +00:00
* `lda stream`
2018-07-24 16:00:24 +00:00
* `>SYSCALL fread`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Y,A = Bytes Read
*\--------------------------------------
2018-07-24 16:00:24 +00:00
K.FRead jsr PFT.CheckNodeA
2020-03-10 16:42:07 +00:00
bcs K.FWrite.RET4
2019-05-12 20:45:11 +00:00
2019-07-27 20:51:39 +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
2020-12-15 13:23:22 +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:**
2018-07-24 16:00:24 +00:00
* `>PUSHWI count`
* `>PUSHW ptr`
2018-10-04 06:13:44 +00:00
* `lda stream`
2018-07-24 16:00:24 +00:00
* `>SYSCALL fwrite`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Y,A = Bytes Written
*\--------------------------------------
2018-07-24 16:00:24 +00:00
K.FWrite jsr PFT.CheckNodeA
2020-03-10 16:42:07 +00:00
bcs K.FWrite.RET4
2020-12-15 13:23:22 +00:00
2019-07-27 20:51:39 +00:00
jsr UNISTD.Write
2019-05-21 15:52:52 +00:00
bcc K.FWrite.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
2020-06-30 05:59:37 +00:00
bne K.FWrite.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
dec pStack keep ptr & count on stack
2019-05-12 20:45:11 +00:00
inc 0 = BLOCKING
2020-06-30 10:40:19 +00:00
* sec
2019-05-21 15:52:52 +00:00
K.FWrite.RTS rts
2020-03-10 16:42:07 +00:00
K.FWrite.RET4 >RET 4
*/--------------------------------------
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:**
2018-08-08 15:13:37 +00:00
* `>PUSHBI whence`
* `>PUSHL offset`
* `lda stream`
* `>SYSCALL fseek`
*\-------------------------------------
2018-08-08 15:13:37 +00:00
K.FSeek jsr PFT.CheckNodeA
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
2019-07-27 20:51:39 +00:00
>PULLL ACC32
2019-09-24 15:25:07 +00:00
>PULLA whence
cmp #SEEK.END
2019-07-27 20:51:39 +00:00
beq .30
bcs .98
2019-05-12 20:45:11 +00:00
2019-09-24 15:25:07 +00:00
dec
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
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
* 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
2019-07-31 15:10:59 +00:00
IO.EOF lda (pFD)
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
.DA IO.EOF.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
.DA IO.EOF.SSOCK
.DA IO.EOF.PIPE
*/--------------------------------------
* # 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
ldy #1
lda (pStack),y
sta ZPPtr1+1
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:**
* PrintF : (example is for printing Y,A as integer : format="%I", 2 bytes)
* `>PUSHW format`
* `>PUSHW i`
* `...`
* `>PUSHBI 2` #bytecount
* `>SYSCALL PrintF`
* FPrintF :
* `>PUSHB hFILE`
* `>PUSHW format`
* `>PUSHW i`
* `...`
* `>PUSHBI 2` #bytecount
* `>SYSCALL fprintf`
* SPrintF :
* `>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 :
* + %b : pull 1 byte to Print BIN
* + %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 %
* Modifiers for len and padding :
* + %d : '9' '12'
* + %2d : ' 9' '12'
* + %02d : '09' '12'
* + %11s : 'ABCDEFGH '
* + %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
STDIO.StackBytePtr .BS 1
STDIO.ExitPopCnt .BS 1
.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
sty STDIO.ExitPopCnt Total bytes to POP
.1 jsr SHARED.GetCharPtr2
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
jsr SHARED.NextCharPtr2 skip 0 ...
lda (ZPPtr2)
beq .7
jsr ZP.IsDigit
bcs .6 %0x ??????
.4 jsr MATH32.Dec2ACC32
bcs .99
lda ACC32
sta K.PrintF.PadL
lda K.PrintF.PadC
bne .5
lda #C.SPACE
sta K.PrintF.PadC
.5 jsr SHARED.AddYToPtr2 skip all processed chars
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 ...
.62 jsr SHARED.NextCharPtr2
txa yes, jmp to it!
asl
tax
jsr PrintF.ESC
.11 bcc .1
bra .99
.7 lda #'%'
bra .20
*--------------------------------------
.10 cmp #'\'
bne .20
jsr SHARED.GetCharPtr2
beq .99
ldx #PrintFTBL2.Cnt-1
.12 cmp PrintFTBL2,x
beq .19
dex
bpl .12
cmp #'x' \xHH
bne .1
jsr MATH32.Hex2ACC32
bcs .99
jsr SHARED.AddYToPtr2
.14 lda ACC32
bra .20
.19 lda PrintFTBL2.OUT,x
.20 jsr PrintF.PutC
bcc .11
*--------------------------------------
.99 lda #E.BADARG
sec
jmp STDIO.Exit
*--------------------------------------
.8 ldx PrintF.hFILE
beq .80 Writing to buffer, append \0
>PUSHW PrintF.Cnt Writing to File/dev...
>PUSHWI K.IOBuf
txa
jsr K.FWrite
bcc .81
tay
bne .9
>RET 4 0=BLOCKING
.80 ldy PrintF.Cnt A=0, Writing to buffer, append \0
sta (pIOBuf),y
clc
.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
*--------------------------------------
PrintF.B jsr STDIO.GetStackByte
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
jsr MATH32.ACC32ZERO
.1 jsr STDIO.GetStackByte
bcs PrintF.B.RTS
sta ACC32-1,y PULL 4,2 or 1
dey
bne .1
bit ACC32.Sign
bpl .4
.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
.4 ldx K.PrintF.PadL
ldy K.PrintF.PadC
rol ACC32.Sign get back signed/unsigned flag
jsr MATH32.ACC322STR10
bra PrintF.StrNum
*--------------------------------------
* EXP(8) 1(s) 1significants(31)
* http://apple2.org.za/gswv/a2zine/GS.WorldView/Resources/GS.TECH.INFO/AppleSoft/
*--------------------------------------
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
ldy #A2osX.NumStrBuf+1 FOUT.1 will do a DEY
ldx #FPU.FOUT
jsr GP.ROMCALL
PrintF.StrNum ldy #0
.2 lda A2osX.NumStrBuf,y
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
jsr STDIO.GetStackByte
bcs .9
sta ZPPtr1+1
jsr STDIO.GetStackByte
bcs .9
sta ZPPtr1
lda (ZPPtr1) if CSTR:last char=0, if PSTR:len=0
beq .8
ldy .1+1
.1 lda #$ff Self Modified
bne .11 CSTR
tya PSTR
cmp (ZPPtr1) len check
beq .2
.11 iny
lda (ZPPtr1),y
beq .2
jsr PrintF.PutC
bcs .9
lda K.PrintF.PadL
beq .1
cpy K.PrintF.PadL
bne .1
.8 clc
rts
.2 lda K.PrintF.PadL
beq .8
.3 cpy K.PrintF.PadL
beq .8
lda K.PrintF.PadC
jsr PrintF.PutC
bcs .9
iny
bne .3
* clc
.9 rts
*--------------------------------------
PrintF.HH jsr STDIO.GetStackByte
bcs PrintF.PutC.RTS
pha LO byte
jsr STDIO.GetStackByte
plx
bcs PrintF.PutC.RTS
pha
txa
jsr PrintF.H.1
plx
bcs PrintF.PutC.RTS
txa
bra PrintF.H.1
*--------------------------------------
PrintF.H jsr STDIO.GetStackByte
bcs PrintF.PutC.RTS
PrintF.H.1 jsr MATH32.AToHexAX
jsr PrintF.PutC
bcs PrintF.PutC.RTS
txa
*--------------------------------------
PrintF.PutC phy
ldy PrintF.Cnt
sta (pIOBuf),y
ply
inc PrintF.Cnt
bne .8
lda PrintF.hFILE
bne .9
inc pIOBuf+1
inc PrintF.Cnt+1
.8 clc
rts
.9 lda #E.BUF
sec
PrintF.PutC.RTS rts
*/--------------------------------------
* # 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
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
sty STDIO.ExitPopCnt Total bytes to POP
ldx PrintF.hFILE
beq .1
txa
>PUSHA
>PUSHW pIOBuf
>PUSHWI 256
jsr K.FGetS
bcc .1
tax
bne PrintF.PutC.RTS
>RET 4
.1 jsr SHARED.GetCharPtr1 End Of format?
beq .8
cmp #'%' Escape ?
beq .2
cmp #C.SPACE Space ?
beq .12
sta .11+1
jsr SHARED.GetCharPtr2
beq .9
.11 cmp #$ff Same char in string?
beq .1
bra .9
.12 jsr SHARED.GetCharPtr2
beq .9
cmp #C.SPACE
bne .9
.13 jsr SHARED.GetCharPtr2
cmp #C.SPACE another space ?
beq .13
bra .1
.2 jsr SHARED.GetCharPtr1 Get specifier after %
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
.4 jsr STDIO.GetStackByte
bcs .9
sta ZPPtr3+1
jsr STDIO.GetStackByte
bcs .9
sta ZPPtr3
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
*--------------------------------------
K.SScanF.I
K.SScanF.D
K.SScanF.II
K.SScanF.DD
K.SScanF.L
K.SScanF.U lda K.SScanFTBL+1,x Get VAR size
pha Save VAL size
jsr MATH32.Dec2ACC32
bra K.SScanF.GetVAL
*--------------------------------------
K.SScanF.HH
K.SScanF.H lda K.SScanFTBL+1,x Get VAR size
pha
jsr MATH32.Hex2ACC32
K.SScanF.GetVAL jsr SHARED.AddYToPtr2 Y=char count parsed
.1 ply get back VAL size
.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 ?
cmp (ZPPtr1) match format next char ?
beq .2
cmp #C.SPACE is it a space ?
bne .1
.2 lda #0 add \0 to param ptr
sta (ZPPtr3),y
K.SScanF.Fwd jmp SHARED.AddYToPtr2 Y=char count parsed
*--------------------------------------
* 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
tay
sty STDIO.StackBytePtr
iny
lda (pStack),y format LO
pha
iny
lda (pStack),y format HI
bcs .10
sta ZPPtr1+1
pla
sta ZPPtr1
bra .11
.10 sta ZPPtr2+1
pla
sta ZPPtr2
.11 dex
beq .1
dex
beq .2
.3 stz PrintF.hFILE
iny
lda (pStack),y str LO
tax
iny
lda (pStack),y str HI
rts
.2 iny
lda (pStack),y hFILE
sta PrintF.hFILE
.1 ldx #K.IOBuf
lda /K.IOBuf
STDIO.GetParams.RTS
rts
*--------------------------------------
STDIO.GetStackPtr
jsr STDIO.GetStackByte
bcs STDIO.GetParams.RTS
tax
*--------------------------------------
STDIO.GetStackByte
phy
ldy STDIO.StackBytePtr
beq .9
lda (pStack),y
dec STDIO.StackBytePtr
ply
clc
rts
.9 lda #E.STACK
ply
sec
rts
*--------------------------------------
STDIO.Exit php
pha
lda pStack
sec
adc STDIO.ExitPopCnt
sta pStack
pla
plp
rts
*--------------------------------------
MAN
2020-05-26 14:23:09 +00:00
SAVE usr/src/sys/kernel.s.stdio
LOAD usr/src/sys/kernel.s
ASM