A2osX/SYS/KERNEL.S.STDIO.txt

1448 lines
27 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2018-11-17 17:17:13 +00:00
PREFIX
2017-12-22 21:24:30 +00:00
AUTO 4,1
2018-08-22 15:23:27 +00:00
*--------------------------------------
*K.PrintF.PadL .BS 1
*K.PrintF.PadC .BS 1
*HEXBUF .BS 4
*BCDBUF .BS 5 5, enough to handle 10 digits (32bits)
*--------------------------------------
HEXBUF .EQ FAC
K.PrintF.PadL .EQ FAC+4
K.PrintF.PadC .EQ FAC+5
BCDBUF .EQ ARG
2018-11-30 16:00:36 +00:00
HEXBUF.Signed .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
bcc .8
tay
2019-02-25 14:47:31 +00:00
bne .8
>RET 1
2019-02-22 16:08:37 +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
* `int fputc ( hFILE stream , int character );`
* ## ASM
* **In:**
* `>PUSHB character`
* `lda stream`
* `>SYSCALL fputc`
* ## RETURN VALUE
* CC = success
*\--------------------------------------
2019-02-22 16:08:37 +00:00
* (pStack)+0 character
*--------------------------------------
2018-11-16 16:04:20 +00:00
K.FPutC jsr PFT.CheckNodeA
2019-02-25 14:47:31 +00:00
bcs .8
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-02-25 14:47:31 +00:00
ldy #1 write 1 byte
jsr K.FPutC.Y
bcc .8
2019-02-22 16:08:37 +00:00
tay
2019-02-25 14:47:31 +00:00
bne .8
rts
2019-02-22 16:08:37 +00:00
2019-02-25 14:47:31 +00:00
.8 >RET 1
*/--------------------------------------
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
*\--------------------------------------
2018-10-04 15:30:14 +00:00
K.PutS >PUSHYA
2018-06-19 15:08:22 +00:00
ldy #S.PS.hStdOut
lda (pPs),y
2018-11-16 16:04:20 +00:00
2018-10-04 15:30:14 +00:00
jsr K.FPutS
bcs K.PutS.RTS
2018-10-04 15:30:14 +00:00
lda #C.CR
2018-06-19 15:08:22 +00:00
sta K.IOBuf
2018-10-04 15:30:14 +00:00
lda #C.LF
2018-06-19 15:08:22 +00:00
sta K.IOBuf+1
2018-10-04 15:30:14 +00:00
2019-02-25 14:47:31 +00:00
ldy #2 write 2 bytes
K.FPutC.Y lda #0
>PUSHYA count
>PUSHWI K.IOBuf buf
jsr IO.Write.I
bcc K.PutS.RTS
tay
bne K.PutS.RTS
>RET 4 pop buf,count but keep char
2018-10-04 15:30:14 +00:00
K.PutS.RTS rts
*/--------------------------------------
2019-02-20 16:07:43 +00:00
* # fputs (BLOCKING)
* Write Str to FILE
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
2018-11-16 16:04:20 +00:00
bcs .9
2018-07-27 13:34:34 +00:00
2018-10-04 15:30:14 +00:00
>PULLYA Get String
>STYA ZPPtr2 Save Buffer
>SYSCALL strlen Get String len in Y,A
>PUSHYA push len
>PUSHW ZPPtr2 push buffer
2019-02-25 14:47:31 +00:00
jsr IO.Write.I
bcc .8
tay
bne .8
>RET 4
.8 rts
2018-11-16 16:04:20 +00:00
.9 >RET 2
*/--------------------------------------
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
* + %B : pull 2 bytes 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
* + %n : pull 1 byte to Print low Nibble HEX
* + %N : pull 1 byte to Print high Nibble HEX
* + %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'
* + %2d : ' 9' '12'
* + %02d : '09' '12'
* + %11s : 'ABCDEFGH '
* + %011s : 'ABCDEFGH000'
* + %2f : '3.14'
*\--------------------------------------
2019-02-24 22:11:52 +00:00
* .DUMMY
* .OR ZPTMP
2019-01-04 13:17:31 +00:00
PrintF.Cnt .BS 2
2019-02-24 22:11:52 +00:00
PrintF.hFILE .BS 1
* .ED
2019-01-04 13:17:31 +00:00
*--------------------------------------
2019-02-24 22:11:52 +00:00
K.SPrintF >STYA pIOBuf str
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
2018-06-18 06:22:50 +00:00
K.PrintF >STYA ZPPtr1 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
2018-08-22 15:23:27 +00:00
stz PrintF.GetByte+1
2018-12-21 14:32:45 +00:00
.1 jsr MEM.GetCharPtr1
2019-02-24 22:11:52 +00:00
bne .22
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
lda #' '
sta K.PrintF.PadC
2019-03-25 16:51:51 +00:00
ldy #0
.2 lda (ZPPtr1),y
2019-03-25 21:18:50 +00:00
beq .7 end of line... print % and exit
2019-03-25 16:51:51 +00:00
iny
2019-03-25 21:18:50 +00:00
jsr K.PrintF.CheckTBL1 do we have a %x command?
bcc .6 yes, jmp to it!
cmp #'0' ...a 0...mmm... padding char?
bne .4
2018-06-18 08:44:02 +00:00
ldx K.PrintF.PadL K.PrintF.PadL is not nul, so this 0 is second digit
bne .5
* lda #'0'
2018-06-18 08:44:02 +00:00
sta K.PrintF.PadC no, this is the first 0, so make it K.PrintF.PadC
bra .2
.4 jsr MEM.IsDigit
2019-03-25 21:18:50 +00:00
bcs .7 no TBL1, no digit....abort
.5 and #$0F we have a digit
2019-03-25 21:18:50 +00:00
ldx K.PrintF.PadL
bne .51 second digit...
sta K.PrintF.PadL first digit, store.
bra .2
.51 pha save it...
lda K.PrintF.PadL starts K.PrintF.PadL * 10
asl
asl A=times 4
adc K.PrintF.PadL CC by ASL, A=times 5
asl times 10
sta K.PrintF.PadL
pla get back digit
adc K.PrintF.PadL
sta K.PrintF.PadL
2019-03-25 16:51:51 +00:00
2019-03-25 21:18:50 +00:00
lda (ZPPtr1),y we have 2 digits, must get a letter, now
beq .7
2019-03-25 16:51:51 +00:00
iny
2019-03-25 21:18:50 +00:00
jsr K.PrintF.CheckTBL1
bcs .7 abort and print %
2019-03-25 21:18:50 +00:00
.6 jsr MEM.AddYToPtr1 skip all processed chars
txa
asl
tax
jsr PrintF.ESC
bcc .1
2018-08-22 15:23:27 +00:00
bcs .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
2018-12-21 14:32:45 +00:00
jsr MEM.GetCharPtr1
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
cmp #'x'
bne .1
>LDYA ZPPtr1
>STYA ZPPtr2
jsr STDLIB.GetHex
bcs .99
jsr MEM.AddYToPtr1
.14 lda HEXBUF
bra .20
2019-02-14 14:51:24 +00:00
.19 lda PrintFTBL2.OUT,x
.20 jsr PrintF.COut
2019-02-14 14:51:24 +00:00
bcs .99
jmp .1
2019-02-24 22:11:52 +00:00
*--------------------------------------
.99 pha
lda pLocal
2018-08-22 15:23:27 +00:00
sec ByteCnt byte
2019-02-24 22:11:52 +00:00
adc (pLocal) ... ByteCnt
2018-08-22 15:23:27 +00:00
sta pStack CC
pla
2019-02-24 22:11:52 +00:00
sec
rts
*--------------------------------------
.8 lda pIOBuf+1
eor /K.IOBuf
bne .80 Writing to buffer, append \0
>PUSHW PrintF.Cnt Writing to File/dev...
>PUSHWI K.IOBuf
lda PrintF.hFILE
jsr K.FWrite
bcc .81
tay
bne .99
2018-10-04 15:30:14 +00:00
2019-02-24 22:11:52 +00:00
>RET 4
.80 lda #0 Writing to buffer, append \0
ldy PrintF.Cnt
sta (pIOBuf),y
.81 lda pLocal
sec ByteCnt byte
adc (pLocal) ... ByteCnt
sta pStack CC
2018-10-04 15:30:14 +00:00
>LDYA PrintF.Cnt
2019-02-24 22:11:52 +00:00
clc
rts
*--------------------------------------
K.PrintF.GetFormat
lda (pStack)
sta ZPPtr1
ldy #1
lda (pStack),y
sta ZPPtr1+1
2018-10-04 15:30:14 +00:00
2019-02-24 22:11:52 +00:00
lda pStack
inc
inc
sta pLocal
rts
*--------------------------------------
2019-03-25 21:18:50 +00:00
K.PrintF.CheckTBL1
ldx #PrintFTBL1.Cnt-1
.1 cmp PrintFTBL1,x
beq .8
dex
bpl .1
sec no valid letter...
rts
.8 clc
rts
*--------------------------------------
2019-03-29 16:21:30 +00:00
PrintF.ESC jmp (.1,x)
.1 .DA PrintF.B,PrintF.BB
.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.N,PrintF.NN
.DA PrintF.S,PrintF.SS
*--------------------------------------
PrintFTBL1 .AS "bBdDuefhHiILnNsS"
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 #'%' \%
*--------------------------------------
2018-08-22 15:23:27 +00:00
PrintF.BB jsr PrintF.GetByte
bcs PrintF.BB.RTS
pha
jsr PrintF.B
pla
bcc PrintF.B.1
PrintF.BB.RTS rts
*--------------------------------------
2018-08-22 15:23:27 +00:00
PrintF.B jsr PrintF.GetByte
bcs PrintF.BB.RTS
PrintF.B.1 ldx #8
.1 asl
pha
lda #'0'
adc #0 add Carry
jsr PrintF.COut
pla
bcs PrintF.BB.RTS
dex
bne .1
rts
*--------------------------------------
PrintF.I sec signed short
.HS 90 BCC
PrintF.D clc unsigned short (BYTE)
2018-11-30 16:00:36 +00:00
ror HEXBUF.Signed
2018-08-22 15:23:27 +00:00
jsr PrintF.GetByte
bcs PrintF.BB.RTS
sta HEXBUF
stz HEXBUF+1
2018-11-30 16:00:36 +00:00
ldx #0 one byte
bra PrintF.DD.1
PrintF.II sec signed int
.HS 90 BCC
PrintF.DD clc unsigned int (WORD)
2018-11-30 16:00:36 +00:00
ror HEXBUF.Signed
2018-08-22 15:23:27 +00:00
jsr PrintF.GetByte
bcs PrintF.BB.RTS
sta HEXBUF
jsr PrintF.GetByte
bcs PrintF.BB.RTS
sta HEXBUF+1
2018-11-30 16:00:36 +00:00
ldx #1 two bytes
PrintF.DD.1 stz HEXBUF+2
stz HEXBUF+3
bra PrintF.U.1
PrintF.L sec signed long
.HS 90 BCC
PrintF.U clc unsigned long (DWORD)
2018-08-22 15:23:27 +00:00
2018-11-30 16:00:36 +00:00
ror HEXBUF.Signed
2018-08-22 15:23:27 +00:00
ldx #$ff
2018-08-22 15:23:27 +00:00
.1 jsr PrintF.GetByte
bcs PrintF.BB.RTS
inx
sta HEXBUF,x
cpx #3
bne .1
* ldx #3 4 bytes
2018-11-30 16:00:36 +00:00
PrintF.U.1 clc
bit HEXBUF.Signed
bpl PrintF.Hex2Dec unsigned, nothing to check
lda HEXBUF,x get sign
bpl PrintF.Hex2Dec
2018-11-30 16:00:36 +00:00
sec
ldy #0
.1 lda HEXBUF,y two's complement of X bytes
eor #$ff
adc #0
sta HEXBUF,y
iny
dex
bpl .1
sec tell to print a "-" sign....
*--------------------------------------
* Convert HEXBUF to ASCBUF decimal padded with 0
*--------------------------------------
2018-11-30 16:00:36 +00:00
PrintF.Hex2Dec ror HEXBUF.Signed
ldx #4
.1 stz BCDBUF,x Clear all 5 bytes
dex
bpl .1
sed switch to BCD mode
ldx #32 let's roll 32 bits
.2 asl HEXBUF
rol HEXBUF+1
rol HEXBUF+2
rol HEXBUF+3
ldy #4
.3 lda BCDBUF,y
adc BCDBUF,y
sta BCDBUF,y
dey
bpl .3
dex
bne .2
cld
2018-11-30 16:00:36 +00:00
bit HEXBUF.Signed
bpl .9
2018-11-30 16:00:36 +00:00
lda #'-'
jsr PrintF.COut
.9 lda K.PrintF.PadL any Len format ?
beq .4 no
lda #10
sec yes, Print only digits starting at pos 10-K.PrintF.PadL
sbc K.PrintF.PadL
.4 tax x=0 if no K.PrintF.PadL, or x=10-K.PrintF.PadL
.5 txa X range 0 to 9
lsr CS if lo nibble (1,3,5,7,9)
tay
lda BCDBUF,y
bcs .6
lsr
lsr
lsr
lsr
.6 and #$0F
ora #$30
cmp #$30
beq .7 a zero?
inc K.PrintF.PadL found a non zero, Print all digits, even if 0, next time
ldy #'0'
sty K.PrintF.PadC
bra .8
.7 cpx #9 last digit ?
beq .8 Print always
ldy K.PrintF.PadL no pad to fill, do not Print 0
beq .10
lda K.PrintF.PadC fill with K.PrintF.PadC
.8 jsr PrintF.COut
bcs .99
.10 inx
cpx #10
bne .5
clc
.99 rts
*--------------------------------------
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
2018-08-23 15:16:20 +00:00
lda PrintF.GetByte+1 get current stack Ptr
tay
clc at least 5 bytes remaining ?
adc #5
cmp (pStack)
bcc .1
bne .9
.1 tya
sec +1
adc pStack
sta INDEX
lda pStack+1
sta INDEX+1
2018-08-22 15:23:27 +00:00
2018-06-13 15:18:08 +00:00
ldx #ROM.SETFAC
jsr GP.ROMCALL
2018-08-23 15:16:20 +00:00
lda PrintF.GetByte+1
clc
adc #5
sta PrintF.GetByte+1
ldy #3 In order not to trash A2osX.SaveSM,A2osX.SaveSX
2018-06-13 15:18:08 +00:00
ldx #ROM.FOUT
jsr GP.ROMCALL
ldy #0
.2 lda $102,y
beq .8
jsr PrintF.COut
iny
bne .2
.8 clc
2018-08-23 15:16:20 +00:00
rts
.9 sec
2018-12-18 14:37:07 +00:00
PrintF.H.9 rts
*--------------------------------------
2018-08-22 15:23:27 +00:00
PrintF.HH jsr PrintF.GetByte
bcs PrintF.H.9
pha
jsr PrintF.H
pla
bra PrintF.H.1
*--------------------------------------
2018-08-22 15:23:27 +00:00
PrintF.H jsr PrintF.GetByte
bcs PrintF.H.9
PrintF.H.1 pha
jsr PrintF.NN.1
pla
bra PrintF.N.1
*--------------------------------------
2018-08-22 15:23:27 +00:00
PrintF.N jsr PrintF.GetByte
bcs PrintF.H.9
PrintF.N.1 and #$0F
bra PrintF.NN.2
2018-08-22 15:23:27 +00:00
PrintF.NN jsr PrintF.GetByte
bcs PrintF.H.9
PrintF.NN.1 lsr
lsr
lsr
lsr
PrintF.NN.2 ora #$30
cmp #$3A
bcc .1
adc #6
.1 jmp PrintF.COut
*--------------------------------------
PrintF.S ldy #$ff CSTR
.HS 2C bit abs
PrintF.SS ldy #$00 PSTR
2018-08-22 15:23:27 +00:00
jsr PrintF.GetByte
bcs .9
sta ZPPtr2
jsr PrintF.GetByte
bcs .9
sta ZPPtr2+1
lda (ZPPtr2) if CSTR:last char=0, if PSTR:len=0
beq .8
sty .1+1
.1 lda #$ff Self Modified
bne .11 CSTR
tya PSTR
cmp (ZPPtr2) len check
beq .2
.11 iny
lda (ZPPtr2),y
beq .2
jsr PrintF.COut
bcs .9
lda K.PrintF.PadL
beq .1
cpy K.PrintF.PadL
bne .1
clc
rts
.2 lda K.PrintF.PadL
beq .8
.3 cpy K.PrintF.PadL
beq .8
lda K.PrintF.PadC
jsr PrintF.COut
bcs .9
iny
bne .3
.8 clc
.9 rts
*--------------------------------------
2018-08-22 15:23:27 +00:00
PrintF.GetByte lda #$FF SELF MODIFIED LStack Ptr
2019-02-24 22:11:52 +00:00
cmp (pLocal)
2018-08-22 15:23:27 +00:00
beq .9 CS
2019-02-24 22:11:52 +00:00
2018-08-22 15:23:27 +00:00
phy
2019-02-24 22:11:52 +00:00
2018-08-22 15:23:27 +00:00
tay
iny
2019-02-24 22:11:52 +00:00
lda (pLocal),y
2018-08-22 15:23:27 +00:00
sty PrintF.GetByte+1
2019-02-24 22:11:52 +00:00
2018-08-22 15:23:27 +00:00
ply
2019-02-24 22:11:52 +00:00
2018-08-22 15:23:27 +00:00
* clc
2019-02-24 22:11:52 +00:00
2018-08-22 15:23:27 +00:00
.9 rts
*--------------------------------------
PrintF.COut phy
2018-10-04 15:30:14 +00:00
ldy PrintF.Cnt
sta (pIOBuf),y
2018-10-04 15:30:14 +00:00
inc PrintF.Cnt
bne .8
lda pIOBuf+1
eor /K.IOBuf
2019-02-24 22:11:52 +00:00
beq .9
2019-02-24 22:11:52 +00:00
inc pIOBuf+1
2018-10-04 15:30:14 +00:00
inc PrintF.Cnt+1
.8 ply
clc
rts
2019-02-24 22:11:52 +00:00
.9 ply
lda #E.BUF
sec
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-02-25 14:47:31 +00:00
bcs .9
2018-08-08 15:13:37 +00:00
2019-02-25 14:47:31 +00:00
lda (pStack)
sta ZPPtr2
ldy #1
lda (pStack),y
sta ZPPtr2+1 s
2018-08-08 15:13:37 +00:00
2019-02-25 14:47:31 +00:00
iny
lda (pStack),y
2018-07-27 13:34:34 +00:00
sec
sbc #2
eor #$ff
2018-12-20 21:56:44 +00:00
sta ZPPtr1 !n
2019-02-25 14:47:31 +00:00
iny
lda (pStack),y
2018-07-27 13:34:34 +00:00
sbc #0
eor #$ff
2018-12-20 21:56:44 +00:00
sta ZPPtr1+1 !n
2018-07-27 13:34:34 +00:00
2019-02-25 14:47:31 +00:00
.10 jsr K.GetC.I
bcc .1
tay
bne .9 I/O ERROR
rts BLOCKING I/O
.1 cmp #C.LF Discard any leading LF
beq .10
2018-07-27 13:34:34 +00:00
2019-02-25 14:47:31 +00:00
.2 cmp #C.CR
2018-07-27 13:34:34 +00:00
beq .8
2018-12-20 21:56:44 +00:00
jsr MEM.PutCharPtr2
2018-07-27 13:34:34 +00:00
2018-12-20 21:56:44 +00:00
jsr MEM.NextCharPtr1
2018-07-27 13:34:34 +00:00
beq .8
2018-12-20 21:56:44 +00:00
jsr K.GetC.I
2019-02-25 14:47:31 +00:00
bcc .2 another char...
tay BLOCKING...
bne .8
jsr .9 Cancel GetC blocking
2018-07-27 13:34:34 +00:00
.8 clc
lda #0
2019-02-25 14:47:31 +00:00
sta (ZPPtr2) terminate string
.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
2018-10-05 14:58:38 +00:00
K.GetC.I >PUSHWI 1
>PUSHWI K.IOBuf
2018-07-19 15:33:55 +00:00
jsr IO.READ.I
2019-02-22 16:08:37 +00:00
bcc .8
tay
bne K.GetC.RTS
>RET 4 BLOCKING I/O
.8 lda K.IOBuf
K.GetC.RTS rts
*/--------------------------------------
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-01-26 14:01:05 +00:00
K.SScanF jsr MEM.SPtr2PPtr1 ptr2=String to Scan,Ptr1=format
2018-07-23 06:28:47 +00:00
2018-08-08 15:13:37 +00:00
stz .5+1 reset LStack Ptr
stz .80+1 rest Arg processed
2018-12-20 21:56:44 +00:00
.1 jsr MEM.GetCharPtr1 End Of format?
beq .8
2018-12-20 21:56:44 +00:00
cmp #'%' Escape ?
beq .2
2018-08-08 15:13:37 +00:00
cmp #' ' Space ?
beq .12
cmp (ZPPtr2) Same char in string?
bne .9
inc ZPPtr2
bne .1
inc ZPPtr2+1
bra .1
2018-08-08 15:13:37 +00:00
.12 inc ZPPtr2 Space....
bne .14
inc ZPPtr2+1
.14 cmp (ZPPtr2) another one ?
beq .12
bne .1
2018-12-20 21:56:44 +00:00
.2 jsr MEM.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
.3 cmp K.SScanFTBL,x
beq .4
dex
2018-07-27 13:34:34 +00:00
dex
bpl .3
2018-06-18 06:22:50 +00:00
.9 jsr .8
lda #MLI.E.EOF
sec
rts
.4 jsr .5
2018-07-27 13:34:34 +00:00
bcs .9 out of Ptr on stack
2018-06-18 06:22:50 +00:00
bra .1
2018-06-18 06:22:50 +00:00
.8 lda pStack
2018-07-27 13:34:34 +00:00
sec ByteCnt byte
adc (pStack) ... ByteCnt
2018-06-18 06:22:50 +00:00
sta pStack CC
2018-08-08 15:13:37 +00:00
2019-02-24 22:11:52 +00:00
.80 lda #$ff SELF MODIFIED Arg processed
2018-06-18 06:22:50 +00:00
.99 rts
*--------------------------------------
2018-08-08 15:13:37 +00:00
.5 lda #$FF SELF MODIFIED LStack Ptr
2018-07-27 13:34:34 +00:00
cmp (pStack)
2018-06-18 06:22:50 +00:00
beq .99 CS
2018-07-27 13:34:34 +00:00
tay
iny
2018-06-18 06:22:50 +00:00
lda (pStack),y
sta ZPPtr3
2018-07-27 13:34:34 +00:00
2018-06-18 06:22:50 +00:00
iny
lda (pStack),y
sta ZPPtr3+1 get VAR Ptr
2018-07-27 13:34:34 +00:00
sty .5+1
2018-08-08 15:13:37 +00:00
inc .80+1 parsed one more arg!
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
jsr STDLIB.GetDec
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
jsr STDLIB.GetHex
2018-07-26 15:26:39 +00:00
K.SScanF.GetVAL jsr K.SScanF.Fwd Y=char count parsed
.1 ply get back VAL size
.2 lda STDLIB.32-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
2018-07-26 15:26:39 +00:00
K.SScanF.Fwd tya Y=char count parsed
clc
adc ZPPtr2
sta ZPPtr2
bcc .8
2018-08-08 15:13:37 +00:00
clc
2018-07-26 15:26:39 +00:00
inc ZPPtr2+1
.8 rts
*/--------------------------------------
* # 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
2018-10-04 15:30:14 +00:00
>PULLB K.Open.FLAGS
>PULLB K.Open.TYPE
>PULLW K.Open.AUXTYPE
2018-10-04 15:30:14 +00:00
jsr IO.Open.I
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
2018-10-03 15:25:03 +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-01-25 12:43:50 +00:00
sta .1+1 store hFile
jsr IO.Close.I
2019-02-28 16:45:33 +00:00
bcs K.FClose.RTS
2019-01-25 12:43:50 +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-01-25 12:43:50 +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
2018-10-03 15:25:03 +00:00
2019-02-28 16:45:33 +00:00
K.FClose.RTS rts
*/--------------------------------------
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
2018-10-03 15:25:03 +00:00
2018-10-05 14:58:38 +00:00
jmp IO.Read.I
*/--------------------------------------
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
2018-10-03 15:25:03 +00:00
2018-10-05 14:58:38 +00:00
jmp IO.Write.I
*/--------------------------------------
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
>MLICALL MLIFLUSH
2018-10-04 06:13:44 +00:00
.9 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
>RET 6
2018-10-04 06:13:44 +00:00
2018-11-16 16:04:20 +00:00
.11 >PULLA whence
tax
2018-08-08 15:13:37 +00:00
>PULLW ZPPtr1 offset LW
>PULLW ZPPtr2 offset HW
2018-10-02 15:52:30 +00:00
cpx #SEEK.END+1
bcs .98
2018-05-22 06:01:05 +00:00
jmp (.1,x)
2018-05-22 06:01:05 +00:00
.1 .DA .10
.DA .20
.DA .30
2018-10-02 15:52:30 +00:00
* SEEK.SET
.10 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
ldx #3 3 bytes, 24 bits!!!
clc
.81 lda K.MLI.PARAMS+2,y
2018-08-08 15:13:37 +00:00
adc ZPPtr1,y
sta K.MLI.PARAMS+2,y
iny
dex
bne .81
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
sec
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 :
2018-10-04 06:13:44 +00:00
* A=0 EOF
* A !=0 NOT EOF
* CS :
*\--------------------------------------
2019-01-04 13:17:31 +00:00
.DUMMY
.OR ZPTMP
K.FEOF.MARK .BS 3
.ED
*--------------------------------------
2018-06-22 06:24:35 +00:00
K.FEOF jsr PFT.CheckNodeA
2018-10-04 06:13:44 +00:00
bcs .9
2019-02-20 16:07:43 +00:00
lda (pFD)
beq .10
jmp IO.EOF
.10 >MLICALL MLIGETMARK
bcs .9
ldy #2
.1 lda K.MLI.PARAMS+2,y
2018-06-22 06:24:35 +00:00
sta K.FEOF.MARK,y
dey
bpl .1
>MLICALL MLIGETEOF
bcs .9
ldy #2
.2 lda K.MLI.PARAMS+2,y
2018-06-22 06:24:35 +00:00
eor K.FEOF.MARK,y
bne .8
dey
bpl .2
2019-01-04 13:17:31 +00:00
.8
* clc
.9 rts
*/--------------------------------------
* # 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
lda #0
2018-08-08 15:13:37 +00:00
>PUSHA
ldy #2
.1 lda K.MLI.PARAMS+2,y
2018-08-08 15:13:37 +00:00
>PUSHA
dey
bpl .1
.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
>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
ldy #0
.1 lda $ffff,y Self Modified
beq .8
iny
sta K.Buf256,y
cpy #MLI.MAXPATH
bne .1
.8 sty K.Buf256
>LDYAI K.Buf256
>STYA K.MLI.PARAMS+3
>MLICALL MLIRENAME
rts
2018-11-16 16:04:20 +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
2018-10-03 15:25:03 +00:00
2019-02-27 15:00:56 +00:00
ldx #1
2018-10-03 15:25:03 +00:00
2019-02-27 15:00:56 +00:00
.1 lda OF.Table.hFD-1,x
2018-10-03 15:25:03 +00:00
beq .2
inx
2019-02-27 15:00:56 +00:00
cpx #K.OF.MAX+1
2018-10-03 15:25:03 +00:00
bne .1
2018-10-21 20:54:07 +00:00
lda #E.OOH
2018-10-03 15:25:03 +00:00
* sec
rts
2019-02-18 06:42:17 +00:00
.2 stx .3+1 Store hFILE
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
2018-10-03 15:25:03 +00:00
2019-02-18 06:42:17 +00:00
cmp #S.FD.T.BDEV
bne .21
2019-01-13 13:10:14 +00:00
2019-02-18 06:42:17 +00:00
.20 lda #0 No hPath for DEV
bra .3
2019-01-13 13:10:14 +00:00
2019-02-18 06:42:17 +00:00
.21 >LDYAI K.buf256
2018-12-20 20:59:48 +00:00
>SYSCALL strdup
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-02-27 15:00:56 +00:00
clc
2018-10-03 15:25:03 +00:00
.9 rts
*--------------------------------------
STDIO.IOERR lda #MLI.E.IO
sec
rts
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.STDIO
LOAD USR/SRC/SYS/KERNEL.S
ASM