A2osX/SYS/KERNEL.S.STDIO.txt

1260 lines
24 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
2018-08-22 15:23:27 +00:00
*--------------------------------------
2019-07-03 15:25:07 +00:00
K.PrintF.PadL .EQ FAC+5
K.PrintF.PadC .EQ ARG.SIGN
*/--------------------------------------
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
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`
* `>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
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
2019-05-21 15:52:52 +00:00
rts
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # PrintF (BLOCKING)
* # FPrintF (BLOCKING)
* # SPrintF
* Prints C-Style String
2018-06-18 06:22:50 +00:00
* ## C
* `int printf ( const char * format, ... );`
2018-06-18 08:44:02 +00:00
* `int fprintf ( hFILE stream, const char * format, ... );`
2018-11-16 16:04:20 +00:00
* `int sprintf ( char * str, const char * format, ... );`
2018-06-18 06:22:50 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-05 06:25:15 +00:00
* PrintF : (example is for printing Y,A as integer : format="%I", 2 bytes)
2019-02-24 22:11:52 +00:00
* `>PUSHYA` #I
* `>PUSHBI 2` #bytecount
2018-07-24 06:24:23 +00:00
* `...`
2018-06-18 08:44:02 +00:00
* `>LDYAI format`
* `>SYSCALL printf`
2018-06-18 06:22:50 +00:00
* FPrintF :
2019-02-24 22:11:52 +00:00
* `>PUSHYA` #I
* `>PUSHBI 2` #bytecount
2018-07-24 06:24:23 +00:00
* `...`
2018-06-18 08:44:02 +00:00
* `>PUSHWI format`
* `lda hFILE`
* `>SYSCALL fprintf`
2019-02-24 22:11:52 +00:00
* SPrintF :
* `>PUSHYA` #I
* `>PUSHBI 2` #bytecount
* `...`
* `>PUSHWI format`
* `>LDYAI str`
* `>SYSCALL sprintf`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-06-18 08:44:02 +00:00
* CC : success, Y,A = bytes sent
* CS : error, A = code from Output
* Specifiers :
2018-06-18 06:22:50 +00:00
* + %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)
2019-02-14 14:51:24 +00:00
* + \t : Print 'TAB' ($09,09)
* + \v : Print 'VT' ($0B,11)
* + \xHH : Print byte with hexadecimal value HH (1 to 2 digits)
2018-06-18 06:22:50 +00:00
* + \\\\ : Print \
* + \\% : Print %
* Modifiers for len and padding :
2018-06-18 06:22:50 +00:00
* + %d : '9' '12'
2019-10-03 06:25:27 +00:00
* + %2d : ' 9' '12'
2018-06-18 06:22:50 +00:00
* + %02d : '09' '12'
* + %11s : 'ABCDEFGH '
* + %011s : 'ABCDEFGH000'
* + %2f : '3.14'
*\--------------------------------------
2019-07-26 14:23:07 +00:00
.DUMMY
.OR ZPTMP+5 3 Bytes
2019-01-04 13:17:31 +00:00
PrintF.Cnt .BS 2
2019-02-24 22:11:52 +00:00
PrintF.hFILE .BS 1
2019-07-26 14:23:07 +00:00
.ED
2019-01-04 13:17:31 +00:00
*--------------------------------------
2019-05-17 14:57:14 +00:00
K.SPrintF stz PrintF.hFILE
>STYA pIOBuf str
2019-02-24 22:11:52 +00:00
jsr K.PrintF.GetFormat
bra K.PrintF.1
2019-02-24 22:11:52 +00:00
K.FPrintF sta PrintF.hFILE
jsr K.PrintF.GetFormat
bra K.PrintF.0
2019-07-11 15:51:24 +00:00
K.PrintF >STYA ZPPtr2 format
2019-02-24 22:11:52 +00:00
lda pStack
sta pLocal
ldy #S.PS.hStdOut
lda (pPs),y
2019-02-24 22:11:52 +00:00
sta PrintF.hFILE
2019-02-24 22:11:52 +00:00
K.PrintF.0 >LDYAI K.IOBuf
>STYA pIOBuf
2018-10-04 15:30:14 +00:00
K.PrintF.1 stz PrintF.Cnt
stz PrintF.Cnt+1
2018-07-13 14:38:24 +00:00
2019-07-15 15:43:17 +00:00
stz PrintF.LocalGetByte+1
2018-12-21 14:32:45 +00:00
2019-07-28 20:39:30 +00:00
.1 jsr SHARED.GetCharPtr2
2019-02-24 22:11:52 +00:00
bne .22
2019-07-15 15:43:17 +00:00
2019-02-24 22:11:52 +00:00
jmp .8 end of format..
2018-12-21 14:32:45 +00:00
2019-02-14 14:51:24 +00:00
.22 cmp #'%'
bne .10
stz K.PrintF.PadL
2019-07-03 15:25:07 +00:00
stz K.PrintF.PadC
2019-07-15 06:41:12 +00:00
lda (ZPPtr2)
beq .7 end of format... print % and exit
2019-07-28 20:39:30 +00:00
jsr ZP.IsDigit
2019-07-15 06:41:12 +00:00
bcs .6 no digit....go check specifier
cmp #'0' ...a 0...mmm... padding char?
bne .4
2019-07-15 06:41:12 +00:00
sta K.PrintF.PadC
2019-07-28 20:39:30 +00:00
jsr SHARED.NextCharPtr2 skip 0 ...
2019-07-15 06:41:12 +00:00
lda (ZPPtr2)
beq .7
2019-07-15 15:43:17 +00:00
2019-07-28 20:39:30 +00:00
jsr ZP.IsDigit
2019-07-15 06:41:12 +00:00
bcs .6 %0x ??????
2019-07-15 06:41:12 +00:00
.4 jsr MATH.Dec2ACC32
bcs .99
lda ACC32
sta K.PrintF.PadL
2019-07-15 06:41:12 +00:00
lda K.PrintF.PadC
2019-07-15 15:43:17 +00:00
bne .5
2019-07-15 06:41:12 +00:00
lda #C.SPACE
sta K.PrintF.PadC
2019-07-28 20:39:30 +00:00
.5 jsr SHARED.AddYToPtr2 skip all processed chars
2019-07-15 06:41:12 +00:00
lda (ZPPtr2)
2019-03-25 21:18:50 +00:00
beq .7
2019-07-16 15:42:36 +00:00
.6 ldx #PrintFTBL1.Cnt-1 do we have a %x command?
.61 cmp PrintFTBL1,x
beq .62
dex
bpl .61
bra .20 unknown ...
2019-03-25 21:18:50 +00:00
2019-07-28 20:39:30 +00:00
.62 jsr SHARED.NextCharPtr2
2019-07-15 06:41:12 +00:00
txa yes, jmp to it!
asl
tax
jsr PrintF.ESC
2019-07-15 15:43:17 +00:00
.11 bcc .1
2019-07-15 06:41:12 +00:00
bra .99
2019-03-25 21:18:50 +00:00
.7 lda #'%'
bra .20
2019-02-24 22:11:52 +00:00
*--------------------------------------
.10 cmp #'\'
bne .20
2019-07-15 06:41:12 +00:00
2019-07-28 20:39:30 +00:00
jsr SHARED.GetCharPtr2
beq .99
2019-02-14 14:51:24 +00:00
ldx #PrintFTBL2.Cnt-1
.12 cmp PrintFTBL2,x
2019-02-14 14:51:24 +00:00
beq .19
dex
bpl .12
2019-02-14 14:51:24 +00:00
2019-07-15 15:43:17 +00:00
cmp #'x' \xHH
2019-02-14 14:51:24 +00:00
bne .1
2019-07-10 15:39:02 +00:00
jsr MATH.Hex2ACC32
2019-02-14 14:51:24 +00:00
bcs .99
2019-07-28 20:39:30 +00:00
jsr SHARED.AddYToPtr2
2019-07-03 15:25:07 +00:00
.14 lda ACC32
2019-02-14 14:51:24 +00:00
bra .20
.19 lda PrintFTBL2.OUT,x
.20 jsr PrintF.COut
2019-07-15 15:43:17 +00:00
bcc .11
2019-10-03 06:25:27 +00:00
*--------------------------------------
2019-07-15 15:43:17 +00:00
.99 bra PrintF.LocalCleanUp
2019-10-03 06:25:27 +00:00
*--------------------------------------
2019-06-28 15:15:58 +00:00
.8 ldx PrintF.hFILE
2019-05-17 14:57:14 +00:00
beq .80 Writing to buffer, append \0
2019-02-24 22:11:52 +00:00
>PUSHW PrintF.Cnt Writing to File/dev...
>PUSHWI K.IOBuf
2019-06-28 15:15:58 +00:00
txa
2019-02-24 22:11:52 +00:00
jsr K.FWrite
bcc .81
2019-05-17 14:57:14 +00:00
2019-02-24 22:11:52 +00:00
tay
2019-05-17 14:57:14 +00:00
bne .99
>RET 4 0=BLOCKING
.80 ldy PrintF.Cnt A=0, Writing to buffer, append \0
2019-02-24 22:11:52 +00:00
sta (pIOBuf),y
2019-07-15 15:43:17 +00:00
.81 >LDYA PrintF.Cnt
* clc
*--------------------------------------
PrintF.LocalCleanUp
php
pha
lda pLocal
2019-02-24 22:11:52 +00:00
sec ByteCnt byte
adc (pLocal) ... ByteCnt
sta pStack CC
2019-07-15 15:43:17 +00:00
pla
plp
2019-10-03 06:25:27 +00:00
PrintF.LocalCleanUp.RTS
2019-07-15 15:43:17 +00:00
rts
*--------------------------------------
PrintF.LocalGetPtr
jsr PrintF.LocalGetByte
bcs PrintF.LocalCleanUp.RTS
2019-07-15 20:31:25 +00:00
tay
2019-07-15 15:43:17 +00:00
*--------------------------------------
PrintF.LocalGetByte
lda #$FF SELF MODIFIED LStack Ptr
cmp (pLocal)
beq .9 CS
phy
tay
iny
lda (pLocal),y
sty PrintF.LocalGetByte+1
ply
2019-07-15 06:41:12 +00:00
* clc
2019-02-24 22:11:52 +00:00
rts
2019-07-15 15:43:17 +00:00
.9 lda #E.STACK
* sec
rts
2019-02-24 22:11:52 +00:00
*--------------------------------------
2019-03-29 16:21:30 +00:00
PrintF.ESC jmp (.1,x)
2019-07-16 15:42:36 +00:00
.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
*--------------------------------------
2019-07-16 15:42:36 +00:00
PrintFTBL1 .AS "bdDuefhHiILsS"
2019-02-14 14:51:24 +00:00
PrintFTBL1.Cnt .EQ *-PrintFTBL1
PrintFTBL2 .AS "befnrtv\%"
PrintFTBL2.Cnt .EQ *-PrintFTBL2
PrintFTBL2.OUT .HS 08.1B.0C.0A.0D.09.0B \b\e\f\n\r\t\v
.DA #'\' \\
.DA #'%' \%
*--------------------------------------
2019-07-15 15:43:17 +00:00
PrintF.B jsr PrintF.LocalGetByte
2019-07-15 06:41:12 +00:00
bcs PrintF.B.RTS
2019-07-16 15:42:36 +00:00
ldy #8
2019-05-22 15:46:20 +00:00
.1 asl
2019-07-15 06:41:12 +00:00
pha
2019-05-17 14:57:14 +00:00
lda #'0'/2
2019-05-22 15:46:20 +00:00
rol
jsr PrintF.COut
2019-05-17 14:57:14 +00:00
bcs .9
2019-07-15 06:41:12 +00:00
pla
dey
bne .1
2019-07-18 15:55:43 +00:00
rts
2019-07-15 06:41:12 +00:00
.9 ply
PrintF.B.RTS
rts
*--------------------------------------
PrintF.I sec signed short
.HS 90 BCC
PrintF.D clc unsigned short (BYTE)
2018-11-30 16:00:36 +00:00
2019-07-15 15:43:17 +00:00
ldy #1
2019-07-15 06:41:12 +00:00
bra PrintF.NUM
PrintF.II sec signed int
.HS 90 BCC
PrintF.DD clc unsigned int (WORD)
2018-11-30 16:00:36 +00:00
2019-07-15 15:43:17 +00:00
ldy #2
2019-07-03 15:25:07 +00:00
bra PrintF.NUM
PrintF.L sec signed long
.HS 90 BCC
PrintF.U clc unsigned long (DWORD)
2018-08-22 15:23:27 +00:00
2019-07-15 15:43:17 +00:00
ldy #4
2018-11-30 16:00:36 +00:00
2019-07-15 15:43:17 +00:00
PrintF.NUM ror ACC32.Sign
2019-07-15 06:41:12 +00:00
ldx #0
2019-07-15 15:43:17 +00:00
.1 jsr PrintF.LocalGetByte
2019-07-15 06:41:12 +00:00
bcs PrintF.B.RTS
2019-07-03 15:25:07 +00:00
sta ACC32,x
2019-07-15 06:41:12 +00:00
inx
2019-07-15 15:43:17 +00:00
dey
2018-08-22 15:23:27 +00:00
bne .1
2019-07-15 15:43:17 +00:00
.2 cpx #4
beq .3
stz ACC32,x
inx
bra .2
.3 ldx K.PrintF.PadL
2019-07-03 15:25:07 +00:00
ldy K.PrintF.PadC
rol ACC32.Sign
2019-07-10 15:39:02 +00:00
jsr MATH.ACC322STR10
2019-07-03 15:25:07 +00:00
bra PrintF.StrNum
*--------------------------------------
2018-06-18 06:22:50 +00:00
* 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
2018-08-22 15:23:27 +00:00
2019-07-15 15:43:17 +00:00
lda PrintF.LocalGetByte+1 get current stack Ptr
2018-08-23 15:16:20 +00:00
tay
clc at least 5 bytes remaining ?
adc #5
cmp (pStack)
bcc .1
2019-07-03 15:25:07 +00:00
bne PrintF.StrNum.RTS
2019-09-02 15:34:10 +00:00
.1 sta PrintF.LocalGetByte+1
tya
sec +1 for bytecount byte
2018-08-23 15:16:20 +00:00
adc pStack
2019-09-02 15:34:10 +00:00
ldy pStack+1 A,Y = float
2019-07-10 15:39:02 +00:00
ldx #FPU.SETFAC
2018-06-13 15:18:08 +00:00
jsr GP.ROMCALL
2019-09-02 15:34:10 +00:00
ldy #A2osX.NumStrBuf+1 FOUT.1 will do a DEY
2019-07-10 15:39:02 +00:00
ldx #FPU.FOUT
2018-06-13 15:18:08 +00:00
jsr GP.ROMCALL
2019-09-02 15:34:10 +00:00
2019-07-03 15:25:07 +00:00
PrintF.StrNum ldy #0
.2 lda A2osX.NumStrBuf,y
beq .8
iny
2019-06-24 15:32:22 +00:00
jsr PrintF.COut
bcc .2
.9 rts
.8 clc
2019-07-03 15:25:07 +00:00
PrintF.StrNum.RTS
2018-08-23 15:16:20 +00:00
rts
*--------------------------------------
PrintF.S ldy #$ff CSTR
.HS 2C bit abs
PrintF.SS ldy #$00 PSTR
2019-07-15 20:31:25 +00:00
sty .1+1
2019-07-15 15:43:17 +00:00
jsr PrintF.LocalGetPtr
2018-08-22 15:23:27 +00:00
bcs .9
2019-07-15 20:31:25 +00:00
sty ZPPtr1
2019-07-11 15:51:24 +00:00
sta ZPPtr1+1
2019-07-11 15:51:24 +00:00
lda (ZPPtr1) if CSTR:last char=0, if PSTR:len=0
beq .8
2019-07-15 20:31:25 +00:00
ldy .1+1
.1 lda #$ff Self Modified
bne .11 CSTR
tya PSTR
2019-07-11 15:51:24 +00:00
cmp (ZPPtr1) len check
beq .2
.11 iny
2019-07-11 15:51:24 +00:00
lda (ZPPtr1),y
beq .2
jsr PrintF.COut
bcs .9
lda K.PrintF.PadL
beq .1
cpy K.PrintF.PadL
bne .1
2019-07-12 06:22:32 +00:00
.8 clc
rts
.2 lda K.PrintF.PadL
beq .8
.3 cpy K.PrintF.PadL
beq .8
2019-10-03 06:25:27 +00:00
lda K.PrintF.PadC
jsr PrintF.COut
bcs .9
iny
bne .3
2019-07-12 06:22:32 +00:00
* clc
.9 rts
*--------------------------------------
2019-07-15 15:43:17 +00:00
PrintF.HH jsr PrintF.LocalGetByte
2019-05-17 14:57:14 +00:00
bcs PrintF.COut.RTS
2019-07-12 06:22:32 +00:00
pha LO byte
2019-05-17 14:57:14 +00:00
jsr PrintF.H
2019-07-12 06:22:32 +00:00
plx
2019-05-17 14:57:14 +00:00
bcs PrintF.COut.RTS
txa
bra PrintF.H.1
*--------------------------------------
2019-07-15 15:43:17 +00:00
PrintF.H jsr PrintF.LocalGetByte
2019-05-17 14:57:14 +00:00
bcs PrintF.COut.RTS
2019-07-12 06:22:32 +00:00
PrintF.H.1 jsr MATH.AToHexAX
jsr PrintF.COut
2019-05-17 14:57:14 +00:00
bcs PrintF.COut.RTS
2019-07-12 06:22:32 +00:00
txa
2019-05-17 14:57:14 +00:00
*--------------------------------------
PrintF.COut 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.COut.RTS rts
2019-09-02 06:09:28 +00:00
*--------------------------------------
K.PrintF.GetFormat
lda (pStack)
sta ZPPtr2
ldy #1
lda (pStack),y
sta ZPPtr2+1
lda pStack
inc
inc
sta pLocal
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
2019-07-15 15:43:17 +00:00
bcs PrintF.COut.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
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
*/--------------------------------------
2018-06-18 06:22:50 +00:00
* # SScanF
* Read formatted data from string
* ## C
2018-07-23 06:28:47 +00:00
* `int sscanf ( const char * s, const char * format, ... );`
2018-06-18 06:22:50 +00:00
* ## ASM
2018-06-14 15:31:36 +00:00
* **In:**
2018-08-08 15:13:37 +00:00
* `>PUSHW ptr`
* `...`
* `>PUSHBI bytecount`
* `>PUSHWI format`
2018-06-18 06:22:50 +00:00
* + %i : short int
* + %d : byte
* + %I : int
* + %D : word
* + %L : long int
* + %U : dword
* + %h : HEX byte
* + %H : HEX word
2018-07-26 15:26:39 +00:00
* + %s : string
2018-08-08 15:13:37 +00:00
* TODO : %10s
2018-06-18 06:22:50 +00:00
* `>LDYA s`
2018-08-22 15:23:27 +00:00
* `>SYSCALL sscanf`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-08-08 15:13:37 +00:00
* A = Number of arguments filled.
*\--------------------------------------
2019-07-28 20:39:30 +00:00
K.SScanF jsr SHARED.SPtr2PPtr1 ptr2=String to Scan,Ptr1=format
2019-05-12 20:45:11 +00:00
2019-07-15 15:43:17 +00:00
lda pStack
sta pLocal
stz .8+1 rest Arg processed
stz PrintF.LocalGetByte+1
2018-08-08 15:13:37 +00:00
2019-07-28 20:39:30 +00:00
.1 jsr SHARED.GetCharPtr1 End Of format?
beq .8
2018-12-20 21:56:44 +00:00
cmp #'%' Escape ?
beq .2
2019-05-12 20:45:11 +00:00
2018-08-08 15:13:37 +00:00
cmp #' ' Space ?
beq .12
2019-05-12 20:45:11 +00:00
cmp (ZPPtr2) Same char in string?
bne .9
2019-05-12 20:45:11 +00:00
2019-07-28 20:39:30 +00:00
jsr SHARED.NextCharPtr2
bra .1
2019-05-12 20:45:11 +00:00
2019-07-28 20:39:30 +00:00
.12 jsr SHARED.NextCharPtr2 Space....
2019-06-24 15:32:22 +00:00
cmp (ZPPtr2) another one ?
2018-08-08 15:13:37 +00:00
beq .12
bne .1
2019-05-12 20:45:11 +00:00
2019-07-28 20:39:30 +00:00
.2 jsr SHARED.GetCharPtr1 Get specifier after %
2018-06-18 06:22:50 +00:00
beq .9 unexpected End of format after "%" ?
2018-12-20 21:56:44 +00:00
ldx #K.SScanFJMP-K.SScanFTBL-2
2019-05-12 20:45:11 +00:00
.3 cmp K.SScanFTBL,x
beq .4
dex
2018-07-27 13:34:34 +00:00
dex
bpl .3
2019-05-12 20:45:11 +00:00
2019-07-15 15:43:17 +00:00
.9 lda #MLI.E.EOF
sec
2019-07-15 15:43:17 +00:00
jmp PrintF.LocalCleanUp
2019-05-12 20:45:11 +00:00
2019-07-15 15:43:17 +00:00
.4 jsr PrintF.LocalGetPtr
bcs .9
2019-07-15 20:31:25 +00:00
sty ZPPtr3
2019-07-15 15:43:17 +00:00
sta ZPPtr3+1
jsr .5
2018-07-27 13:34:34 +00:00
bcs .9 out of Ptr on stack
2019-05-12 20:45:11 +00:00
2019-07-15 15:43:17 +00:00
inc .8+1 parsed one more arg!
bra .1
2019-05-12 20:45:11 +00:00
2019-07-15 15:43:17 +00:00
.8 lda #$ff SELF MODIFIED Arg processed
clc
jmp PrintF.LocalCleanUp
*--------------------------------------
2019-07-15 15:43:17 +00:00
.5 jmp (K.SScanFJMP,x)
*--------------------------------------
2018-07-27 13:34:34 +00:00
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
2018-07-26 15:26:39 +00:00
.DA K.SScanF.S
*--------------------------------------
K.SScanF.I
K.SScanF.D
K.SScanF.II
K.SScanF.DD
K.SScanF.L
2018-07-26 15:26:39 +00:00
K.SScanF.U lda K.SScanFTBL+1,x Get VAR size
pha Save VAL size
2019-07-10 15:39:02 +00:00
jsr MATH.Dec2ACC32
bra K.SScanF.GetVAL
*--------------------------------------
K.SScanF.HH
2018-07-26 15:26:39 +00:00
K.SScanF.H lda K.SScanFTBL+1,x Get VAR size
pha
2019-07-10 15:39:02 +00:00
jsr MATH.Hex2ACC32
2019-05-12 20:45:11 +00:00
2019-07-28 20:39:30 +00:00
K.SScanF.GetVAL jsr SHARED.AddYToPtr2 Y=char count parsed
2019-05-12 20:45:11 +00:00
.1 ply get back VAL size
2019-05-12 20:45:11 +00:00
2019-07-03 15:25:07 +00:00
.2 lda ACC32-1,y
dey
sta (ZPPtr3),y
bne .2
.9 rts
2018-07-26 15:26:39 +00:00
*--------------------------------------
K.SScanF.S ldy #$ff
.1 iny
2018-09-07 14:12:42 +00:00
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 #' ' is it a space ?
2018-07-26 15:26:39 +00:00
bne .1
2018-09-07 14:12:42 +00:00
.2 lda #0 add \0 to param ptr
2018-08-08 15:13:37 +00:00
sta (ZPPtr3),y
2019-05-12 20:45:11 +00:00
2019-07-28 20:39:30 +00:00
K.SScanF.Fwd jmp SHARED.AddYToPtr2 Y=char count parsed
*/--------------------------------------
* # FOpen
* Open a file
2018-06-18 15:48:00 +00:00
* ## C
2018-10-04 15:30:14 +00:00
* `hFILE 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
* `>PUSHWI auxtype`
* `>PUSHBI ftype`
2018-10-04 15:30:14 +00:00
* `>PUSHBI 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
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-06-18 15:48:00 +00:00
* `>LDYAI filename`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* CC : A = hFILE
* CS : A = EC
*\--------------------------------------
2018-12-03 13:56:52 +00:00
K.FOpen jsr PFT.CheckPathYA
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
>PULLB IO.Open.FLAGS
>PULLB IO.Open.TYPE
>PULLW IO.Open.AUXTYPE
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`
* `>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:**
* `>LDYA pathname`
* `>SYSCALL remove`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2018-06-22 06:24:35 +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
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:**
2018-08-08 15:13:37 +00:00
* `>PUSHW newpath`
* `>LDYA oldpath`
* `>SYSCALL rename`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2018-08-08 15:13:37 +00:00
K.Rename jsr PFT.CheckPathYA
2018-11-16 16:04:20 +00:00
bcs .9
>PULLW .1+1
2019-05-12 20:45:11 +00:00
ldy #0
2019-05-12 20:45:11 +00:00
.1 lda $ffff,y Self Modified
beq .8
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