A2osX/SYS/KERNEL.S.STDIO.txt

684 lines
13 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
* `int putchar ( int character );`
* ## 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
2019-05-12 20:45:11 +00:00
bcc K.PutChar.RTS
tay E.NODATA
bpl K.PutChar.RTS
inc 0 = BLOCKING
K.PutChar.RET1 inc pStack
K.PutChar.RTS 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
* `int fputc ( hFILE stream , int character );`
* ## ASM
* **In:**
* `>PUSHB character`
* `lda stream`
* `>SYSCALL fputc`
* ## RETURN VALUE
* CC = success
*\--------------------------------------
K.FPutC jsr PFT.CheckNodeA
2019-05-12 20:45:11 +00:00
bcs K.PutChar.RET1
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
2019-05-12 20:45:11 +00:00
bcc K.PutChar.RET1 pop char...
tay E.NODATA
bpl K.PutChar.RET1
inc 0 = BLOCKING
2019-05-21 15:52:52 +00:00
* sec
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
*\--------------------------------------
2019-05-12 20:45:11 +00:00
K.PutS >STYA ZPPtr2
ldy #0
.1 lda (ZPPtr2),y
beq .2
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
>PUSHWI K.IOBuf
ldy #S.PS.hStdOut
2020-02-28 07:21:46 +00:00
lda (pPS),y
2018-10-04 15:30:14 +00:00
jsr K.FPutS
2019-07-25 15:10:59 +00:00
bcc K.PutS.RTS
2019-02-25 14:47:31 +00:00
tay
2019-07-25 15:10:59 +00:00
bne K.PutS.RTS 0 = BLOCKING
2019-05-22 07:38:18 +00:00
2019-05-12 20:45:11 +00:00
* sec
2019-07-25 15:10:59 +00:00
K.PutS.RET2 >POP 2 pop K.IOBuf
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:**
2018-07-27 13:34:34 +00:00
* `>PUSHW str`
* `lda stream`
* `>SYSCALL fputs`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-06-18 06:22:50 +00:00
* CC = success
*\--------------------------------------
2018-11-19 21:13:55 +00:00
K.FPutS jsr PFT.CheckNodeA set IO.hFD
2019-07-25 15:10:59 +00:00
bcs K.PutS.RET2
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
* ldy #0
dey
ldx #0
.1 lda (ZPPtr2),y
beq .2
iny
bne .1
inx
bra .1
.2 txa
>PUSHA push len HI
tya
>PUSHA push len LO
>PUSHW ZPPtr2
2019-07-27 20:51:39 +00:00
jsr UNISTD.Write
2019-07-25 15:10:59 +00:00
bcc K.PutS.RET2
2019-02-25 14:47:31 +00:00
tay
2019-07-25 15:10:59 +00:00
bpl K.PutS.RET2 IO Erorr
2019-05-12 20:45:11 +00:00
inc 0 = BLOCKING
2019-10-03 06:25:27 +00:00
* sec
2020-02-14 16:32:52 +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:**
* `>PUSHW n`
* `>PUSHW s`
* `lda hFILE`
* `>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
*\--------------------------------------
2019-02-25 14:47:31 +00:00
* (pStack)+2 n
* (pStack)+0 s
*--------------------------------------
2018-11-16 16:04:20 +00:00
K.FGetS jsr PFT.CheckNodeA
2020-02-14 16:32:52 +00:00
bcs K.FPutS.RTS
2018-08-08 15:13:37 +00:00
2019-05-10 14:49:53 +00:00
lda (pStack)
2019-05-31 07:31:41 +00:00
sta ZPPtr2 s LO
2019-05-07 15:39:35 +00:00
ldy #1
2019-02-25 14:47:31 +00:00
lda (pStack),y
2019-05-31 07:31:41 +00:00
sta ZPPtr2+1 s HI
2018-08-08 15:13:37 +00:00
2019-02-25 14:47:31 +00:00
iny
2019-05-31 07:31:41 +00:00
lda (pStack),y n LO
sta ZPPtr1
2019-05-07 15:39:35 +00:00
2019-02-25 14:47:31 +00:00
iny
2019-05-31 07:31:41 +00:00
lda (pStack),y n HI
sta ZPPtr1+1
bmi .3 already something in buffer
2019-07-15 06:41:12 +00:00
.1 jsr STDIO.Read.1
2019-05-31 07:31:41 +00:00
bcc .2
cmp #MLI.E.EOF
beq .9
tay
bpl .9 IO error
inc NO DATA -> BLOCKING
rts
2019-05-17 14:57:14 +00:00
.2 lda K.IOBuf
2019-05-31 07:31:41 +00:00
cmp #C.LF Discard any leading LF
beq .1
2019-05-17 14:57:14 +00:00
cmp #C.CR
2019-05-31 07:31:41 +00:00
beq .8 empty string
2019-07-28 20:39:30 +00:00
jsr SHARED.PutCharPtr2
2019-05-31 07:31:41 +00:00
lda ZPPtr1
eor #$ff
sta ZPPtr1
lda ZPPtr1+1
eor #$ff
sta ZPPtr1+1
.3 inc ZPPtr1
bne .4
2019-05-07 15:39:35 +00:00
inc ZPPtr1+1
beq .8 Buffer full
2018-12-20 21:56:44 +00:00
2019-07-15 06:41:12 +00:00
.4 jsr STDIO.Read.1
2019-05-31 07:31:41 +00:00
bcs .5
2019-05-12 20:45:11 +00:00
2019-05-31 07:31:41 +00:00
lda K.IOBuf
cmp #C.CR
2019-05-22 15:46:20 +00:00
beq .8
2019-07-28 20:39:30 +00:00
jsr SHARED.PutCharPtr2
2019-05-31 07:31:41 +00:00
bra .3
.5 cmp #MLI.E.EOF
beq .8 String terminated by EOF
2019-10-03 06:25:27 +00:00
tay
2019-05-12 20:45:11 +00:00
bpl .9 I/O error
2019-05-31 07:31:41 +00:00
lda ZPPtr2 NO DATA, but string not yet terminated
2019-05-07 15:39:35 +00:00
sta (pStack) s
2019-05-12 20:45:11 +00:00
2019-05-07 15:39:35 +00:00
ldy #1
2019-05-31 07:31:41 +00:00
lda ZPPtr2+1
2019-05-07 15:39:35 +00:00
sta (pStack),y s
2019-05-12 20:45:11 +00:00
2019-05-07 15:39:35 +00:00
iny
2019-05-31 07:31:41 +00:00
lda ZPPtr1
sta (pStack),y !n LO
2019-02-25 14:47:31 +00:00
2019-05-07 15:39:35 +00:00
iny
2019-05-31 07:31:41 +00:00
lda ZPPtr1+1
sta (pStack),y !n HI
2019-05-12 20:45:11 +00:00
lda #0 BLOCKING
2019-05-07 15:39:35 +00:00
sec
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
2019-07-25 15:10:59 +00:00
.9 >RET 4
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
* `int getchar ();`
* ## 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
2018-10-04 06:13:44 +00:00
* `int getc ( hFILE 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
2019-07-15 06:41:12 +00:00
jsr STDIO.Read.1
2019-02-22 16:08:37 +00:00
bcc .8
tay
2019-05-12 20:45:11 +00:00
bpl K.GetC.RTS I/O error
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
*--------------------------------------
STDIO.Read.1 lda #0
>PUSHA
inc read 1 byte
>PUSHA
>PUSHWI K.IOBuf
2019-07-27 20:51:39 +00:00
jmp UNISTD.READ
*/--------------------------------------
* # 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
2019-01-30 16:23:00 +00:00
bcs K.FOpen.RET4
2018-12-03 13:56:52 +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
2019-07-27 20:51:39 +00:00
jsr UNISTD.Open
2019-02-28 16:45:33 +00:00
bcs K.FClose.RTS
2018-12-03 13:56:52 +00:00
2019-01-13 13:10:14 +00:00
jsr STDIO.NewHFile
2019-02-28 16:45:33 +00:00
bcc K.FClose.RTS
2019-05-12 20:45:11 +00:00
2019-02-28 16:45:33 +00:00
jmp IO.Open.ERR
2018-11-16 16:04:20 +00:00
2019-01-30 16:23:00 +00:00
K.FOpen.RET4 >RET 4
*/--------------------------------------
2018-06-22 06:24:35 +00:00
* # FClose
* Close a file
2018-07-10 15:33:13 +00:00
* ## C
2018-09-05 15:22:46 +00:00
* int fclose ( hFILE 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
2019-02-28 16:45:33 +00:00
bcs K.FClose.RTS
2019-05-12 20:45:11 +00:00
2019-01-25 12:43:50 +00:00
sta .1+1 store hFile
2019-05-12 20:45:11 +00:00
2019-07-27 20:51:39 +00:00
jsr UNISTD.Close
2019-02-28 16:45:33 +00:00
bcs K.FClose.RTS
2019-05-12 20:45:11 +00:00
2019-10-03 06:25:27 +00:00
.1 ldx #$ff SELF MODIFIED
2019-02-27 15:00:56 +00:00
stz OF.Table.hFD-1,x
2019-02-27 15:00:56 +00:00
lda OF.Table.hPath-1,x
2019-02-28 16:45:33 +00:00
beq K.FClose.RTS special files have no path
2019-05-12 20:45:11 +00:00
2019-02-27 15:00:56 +00:00
stz OF.Table.hPath-1,x
2019-01-25 12:43:50 +00:00
jmp K.FreeMem discard filename
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # FRead (BLOCKING)
* Read bytes from file
2018-10-04 15:30:14 +00:00
* ## C
* int fread (hFILE stream, void * ptr, int count );
* ## 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
2019-01-30 16:23:00 +00:00
bcs K.FOpen.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
2019-07-25 15:10:59 +00:00
K.FClose.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
2018-07-24 16:00:24 +00:00
* `int fwrite (hFILE 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
2019-01-30 16:23:00 +00:00
bcs K.FOpen.RET4
2019-05-12 20:45:11 +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
2019-05-21 15:52:52 +00:00
K.FWrite.9 tay
bpl K.FWrite.RTS
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
2019-05-21 15:52:52 +00:00
K.FWrite.RTS rts
*/--------------------------------------
2018-06-22 06:24:35 +00:00
* # FFlush
2018-07-25 15:26:14 +00:00
* ## C
* int fflush(hFILE stream);
* ## 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
2018-08-08 15:13:37 +00:00
* `int fseek(hFILE 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
* `int feof(hFILE stream);`
* ## 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)
.1 .DA IO.EOF.REG
.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
* `long ftell(hFILE stream);`
* ## 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
* int remove(const char *pathname);
* ## ASM
* **In:**
2020-02-14 07:21:56 +00:00
* `>PUSHW pathname`
2018-10-04 06:13:44 +00:00
* `>SYSCALL remove`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2020-02-14 07:21:56 +00:00
K.Remove jsr PFT.CheckPath0
2018-11-16 16:04:20 +00:00
bcs .9
2019-05-12 20:45:11 +00:00
>MLICALL MLIDESTROY
2018-11-16 16:04:20 +00:00
.9 rts
*/--------------------------------------
* # Rename
* Rename a file
2018-08-08 15:13:37 +00:00
* ## C
* `int rename(const char *oldpath, const char *newpath);`
* ## 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
2019-10-10 10:23:02 +00:00
>PULLW ZPPtr1
2019-05-12 20:45:11 +00:00
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
rts
2019-10-03 06:25:27 +00:00
.9 >RET 2
*--------------------------------------
2019-01-13 13:10:14 +00:00
* K.Buf256 = filepath
2018-10-03 15:25:03 +00:00
* X = hFD
*--------------------------------------
2019-01-13 13:10:14 +00:00
STDIO.NewHFile sta .4+1 Store hFD
2019-02-27 15:00:56 +00:00
ldx #1
.1 lda OF.Table.hFD-1,x
2018-10-03 15:25:03 +00:00
beq .2
2019-05-12 20:45:11 +00:00
2018-10-03 15:25:03 +00:00
inx
2019-02-27 15:00:56 +00:00
cpx #K.OF.MAX+1
2018-10-03 15:25:03 +00:00
bne .1
2019-05-12 20:45:11 +00:00
2018-10-21 20:54:07 +00:00
lda #E.OOH
2019-10-03 06:25:27 +00:00
* sec
2018-10-03 15:25:03 +00:00
rts
2019-05-12 20:45:11 +00:00
2019-02-18 06:42:17 +00:00
.2 stx .3+1 Store hFILE
2019-05-12 20:45:11 +00:00
2019-02-18 06:42:17 +00:00
lda (pFD)
2019-01-13 13:10:14 +00:00
cmp #S.FD.T.CDEV
2019-02-18 06:42:17 +00:00
beq .20
2019-05-12 20:45:11 +00:00
2019-02-18 06:42:17 +00:00
cmp #S.FD.T.BDEV
bne .21
2019-05-12 20:45:11 +00:00
2019-02-18 06:42:17 +00:00
.20 lda #0 No hPath for DEV
bra .3
2019-05-12 20:45:11 +00:00
2019-02-18 06:42:17 +00:00
.21 >LDYAI K.buf256
2019-05-04 21:13:50 +00:00
ldx #SYS.strdup
2019-08-05 13:30:58 +00:00
jsr K.SYSCALL2
2018-10-03 15:25:03 +00:00
bcs .9
2019-02-18 06:42:17 +00:00
2018-10-03 15:25:03 +00:00
txa
.3 ldx #$ff SELF MODIFIED
2019-02-27 15:00:56 +00:00
sta OF.Table.hPath-1,x
2018-10-03 15:25:03 +00:00
.4 lda #$ff SELF MODIFIED
2019-02-27 15:00:56 +00:00
sta OF.Table.hFD-1,x
2018-10-03 15:25:03 +00:00
txa hFILE
2019-05-12 20:45:11 +00:00
2019-02-27 15:00:56 +00:00
clc
2018-10-03 15:25:03 +00:00
.9 rts
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.STDIO
LOAD USR/SRC/SYS/KERNEL.S
ASM