Kernel version 0.8 : Merging LIBSTR into Kernel

This commit is contained in:
Rémy GIBERT 2016-10-11 17:30:19 +02:00
parent 9d5aede8f7
commit 8822685ee4

View File

@ -4,6 +4,160 @@ NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
* K.PrintFYA :
* Prints C-Style String
* Y,A = PTR to Sting,Last Byte negative
* %a pull 2 bytes to Print Access right String drwxrwxrwx
* %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 2 bytes PTR to 4 bytes long unsigned DEC 0..4294967295
* %e pull 2 bytes PTR to 6 Bytes Real +1.23456789e+12
* %f pull 2 bytes PTR to 6 Bytes Real 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 2 bytes PTR to Print 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
* \e Print 'ESC' ($1B,27)
* \n Print CR=13
* \\ Print \
* \% Print %
* len/padding :
* %d '9' '12'
* %2d ' 9' '12'
* %02d '09' '12'
* %11s 'ABCDEFGH '
* %011s 'ABCDEFGH000'
* %2f '3.14'
*--------------------------------------
K.PrintFYA >STYA ZPQuickPtr1
ldy #0
.1 lda (ZPQuickPtr1),y
beq .99
cmp #'%'
bne .10
stz PADLEN
lda #' '
sta PADCHAR
.2 ldx #PrintFTBL1.END-PrintFTBL1-1
iny
lda (ZPQuickPtr1),y
beq .99
.3 cmp PrintFTBL1,x do we have a %x command?
beq .8 yes, jmp to it!
dex
bpl .3 no valid letter...
cmp #'0' ...a 0...mmm... padding char?
bne .4
ldx PADLEN PADLEN is not nul, so this 0 is second digit
bne .5
lda #'0'
sta PADCHAR no, this is the first 0, so make it PADCHAR
bra .2
.4 bcc .99 less than '0'....error
cmp #'9'+1
bcs .99 more than '9' ....error
.5 and #$0F we have a digit
pha save it...
lda PADLEN starts PADLEN * 10
asl
asl A=times 4
adc PADLEN CC by ASL, A=times 5
asl times 10
sta PADLEN
pla get back digit
adc PADLEN
sta PADLEN
bra .2 go get next char...
.8 phy
txa
asl
tax
jsr PrintFESC
ply
iny
bne .1
rts
.10 cmp #'\'
bne .20
ldx #PrintFTBL2.END-PrintFTBL2-1
iny
lda (ZPQuickPtr1),y
beq .99
.12 cmp PrintFTBL2,x
beq .13
dex
bpl .12
bra .80
.13 lda PrintFTBL2.OUT,x
.20 jsr K.COutA
.80 iny
bne .1
.99 rts
*--------------------------------------
PrintFESC jmp (PrintFJMP,x)
*--------------------------------------
PrintFTBL1 .AS "abBdDuefhHiILnNsS"
PrintFTBL1.END
PrintFTBL2 .AS "en\%"
PrintFTBL2.END
PrintFTBL2.OUT .HS 1B.0D \e\n
.DA #'\' \\
.DA #'%' \%
PrintFJMP .DA PrintF.D,PrintF.DD,PrintF.U
PADLEN .BS 1
PADCHAR .BS 1
DWORDBUF .BS 4
*--------------------------------------
PrintF.D >PULLA DWORDBUF
stz DWORDBUF+1
bra PrintF.DD.1
PrintF.DD >PULLYA DWORDBUF
PrintF.DD.1 stz DWORDBUF+2
stz DWORDBUF+3
bra PrintF.U.1
PrintF.U >PULLW ZPQuickPtr2
ldy #3
.1 lda (ZPQuickPtr2),y
sta DWORDBUF,y
dey
bpl .1
PrintF.U.1 rts
*--------------------------------------
K.DecOutA tay
lda #0