More small size optimizations for (f)printf.

This commit is contained in:
Stephen Heumann 2023-04-18 22:27:49 -05:00
parent 78a9e1d93b
commit afff478793
1 changed files with 33 additions and 44 deletions

View File

@ -1322,11 +1322,10 @@ fprintf start
sta stream+2 sta stream+2
phy restore return address/data bank phy restore return address/data bank
phx phx
ldx stream
plb plb
lda >stream+2 verify that stream exists pha verify that stream exists
pha phx
lda >stream
pha
jsl ~VerifyStream jsl ~VerifyStream
bcc lb1 bcc lb1
lda #EIO lda #EIO
@ -3327,11 +3326,10 @@ vfprintf start
sta stream+2 sta stream+2
phy restore return address/data bank phy restore return address/data bank
phx phx
ldx stream
plb plb
lda >stream+2 verify that stream exists pha verify that stream exists
pha phx
lda >stream
pha
jsl ~VerifyStream jsl ~VerifyStream
bcc lb1 bcc lb1
lda #EIO lda #EIO
@ -4165,10 +4163,13 @@ argp equ 7 argument pointer
; ;
; For signed numbers, if the value is negative, use the sign flag ; For signed numbers, if the value is negative, use the sign flag
; ;
lda ~isLongLong handle long long values lda ~isLong handle long and long long values
beq sn0a
ldy #2
lda ~isLongLong
beq sn0 beq sn0
ldy #6 ldy #6
lda [argp],Y sn0 lda [argp],Y
bpl cn0 bpl cn0
sec sec
ldx #0 ldx #0
@ -4179,6 +4180,8 @@ argp equ 7 argument pointer
txa txa
sbc [argp],Y sbc [argp],Y
sta [argp],Y sta [argp],Y
lda ~isLongLong
beq sn2
iny iny
iny iny
txa txa
@ -4190,19 +4193,6 @@ argp equ 7 argument pointer
sbc [argp],Y sbc [argp],Y
sta [argp],Y sta [argp],Y
bra sn2 bra sn2
sn0 lda ~isLong handle long values
beq sn0a
ldy #2
lda [argp],Y
bpl cn0
sec
lda #0
sbc [argp]
sta [argp]
lda #0
sbc [argp],Y
sta [argp],Y
bra sn2
sn0a lda ~isByte handle (originally) byte-size values sn0a lda ~isByte handle (originally) byte-size values
beq sn1 beq sn1
lda [argp] lda [argp]
@ -4249,13 +4239,12 @@ cn1 lda [argp] push an int value
cn1a pha cn1a pha
cn2 ph4 #~str push the string addr cn2 ph4 #~str push the string addr
ph2 #l:~str push the string buffer length ph2 #l:~str push the string buffer length
ph2 #0 do an unsigned conversion
lda ~isLongLong do the proper conversion lda ~isLongLong do the proper conversion
beq cn2a beq cn2a
pla
jsr ~ULongLong2Dec jsr ~ULongLong2Dec
bra pd1 bra pd1
cn2a lda ~isLong cn2a ph2 #0 do an unsigned conversion
lda ~isLong
beq cn3 beq cn3
_Long2Dec _Long2Dec
bra pd1 bra pd1
@ -4669,36 +4658,36 @@ bitsPerChar ds 2 bits per output character
using ~printfCommon using ~printfCommon
argp equ 7 argument pointer argp equ 7 argument pointer
ph4 <argp save the original argp sec set flag for c-string
ldy #2 dereference argp bra lb0
lda [argp],Y
tax
lda [argp]
sta argp
stx argp+2
short M determine the length of the string
ldy #-1
lb1 iny
lda [argp],Y
bne lb1
long M
tya
bra lb1a
~Format_b entry ~Format_b entry
~Format_P entry ~Format_P entry
ph4 <argp save the original argp clc set flag for p-string
lb0 ph4 <argp save the original argp
ldy #2 dereference argp ldy #2 dereference argp
lda [argp],Y lda [argp],Y
tax tax
lda [argp] lda [argp]
sta argp sta argp
stx argp+2 stx argp+2
lda [argp] get the length of the string
bcs lb1 if formatting a p-string then
lda [argp] get the length of the string
and #$00FF and #$00FF
inc4 argp inc4 argp
bra lb1x else if formatting a c-string then
lb1 short M compute the length of the string
ldy #-1
lb1a iny
lda [argp],Y
bne lb1a
long M
tya
lb1a ldx ~precisionSpecified if the precision is specified then lb1x ldx ~precisionSpecified if the precision is specified then
beq lb2 beq lb2
cmp ~precision if the precision is smaller then cmp ~precision if the precision is smaller then
blt lb2 blt lb2