Small size optimizations in printf code.
This commit is contained in:
parent
34f78fb1f2
commit
80c0bbc32b
96
stdio.asm
96
stdio.asm
|
@ -3854,11 +3854,11 @@ argp equ 7 argument pointer
|
||||||
; Set the "or" value; this is used to set the case of character results
|
; Set the "or" value; this is used to set the case of character results
|
||||||
;
|
;
|
||||||
lda #$20
|
lda #$20
|
||||||
sta orVal
|
sta ~orVal
|
||||||
bra in1
|
bra in1
|
||||||
|
|
||||||
~Format_A entry
|
~Format_A entry
|
||||||
stz orVal
|
stz ~orVal
|
||||||
;
|
;
|
||||||
; Check for infinities or nans
|
; Check for infinities or nans
|
||||||
;
|
;
|
||||||
|
@ -3871,7 +3871,7 @@ in1 ldy #8 load exponent/sign word
|
||||||
lda #' ' do not use '0' padding
|
lda #' ' do not use '0' padding
|
||||||
sta ~paddChar
|
sta ~paddChar
|
||||||
; Always format like %e for now, because %E code messes up padding for INF/NAN.
|
; Always format like %e for now, because %E code messes up padding for INF/NAN.
|
||||||
; lda orVal if doing %A format
|
; lda ~orVal if doing %A format
|
||||||
; bne in2
|
; bne in2
|
||||||
; brl ~Format_E format like %E
|
; brl ~Format_E format like %E
|
||||||
in2 brl ~Format_e else format like %e
|
in2 brl ~Format_e else format like %e
|
||||||
|
@ -4040,19 +4040,10 @@ pn1 lda ~sign if there is a sign character then
|
||||||
pn2 pea '0' print hex prefix
|
pn2 pea '0' print hex prefix
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
lda #'X'
|
lda #'X'
|
||||||
ora orVal
|
ora ~orVal
|
||||||
pha
|
pha
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
pn3 lda ~paddChar if the number needs 0 padding then
|
jsr ~ZeroPad pad with '0's if needed
|
||||||
cmp #'0'
|
|
||||||
bne pn5
|
|
||||||
lda ~fieldWidth
|
|
||||||
bmi pn5
|
|
||||||
beq pn5
|
|
||||||
pn4 ph2 ~paddChar print padd zeros
|
|
||||||
jsl ~putchar
|
|
||||||
dec ~fieldWidth
|
|
||||||
bne pn4
|
|
||||||
|
|
||||||
pn5 lda #0 print the digits
|
pn5 lda #0 print the digits
|
||||||
ldy #4
|
ldy #4
|
||||||
|
@ -4068,7 +4059,7 @@ pn6 asl ~sig
|
||||||
cmp #'9'+1
|
cmp #'9'+1
|
||||||
blt pn7
|
blt pn7
|
||||||
adc #6
|
adc #6
|
||||||
ora orVal
|
ora ~orVal
|
||||||
pn7 pha
|
pn7 pha
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
lda ~altForm print '.' after first digit if needed
|
lda ~altForm print '.' after first digit if needed
|
||||||
|
@ -4082,7 +4073,7 @@ pn8 dec ~precision
|
||||||
; Print exponent
|
; Print exponent
|
||||||
;
|
;
|
||||||
lda #'P' print 'P' or 'p' exponent prefix
|
lda #'P' print 'P' or 'p' exponent prefix
|
||||||
ora orVal
|
ora ~orVal
|
||||||
pha
|
pha
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
|
|
||||||
|
@ -4120,11 +4111,6 @@ pe3 inx
|
||||||
; Handle left justification
|
; Handle left justification
|
||||||
;
|
;
|
||||||
brl ~LeftJustify handle left justification
|
brl ~LeftJustify handle left justification
|
||||||
|
|
||||||
;
|
|
||||||
; Local data
|
|
||||||
;
|
|
||||||
orVal ds 2 for setting the case of characters
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -4185,21 +4171,22 @@ argp equ 7 argument pointer
|
||||||
lda [argp],Y
|
lda [argp],Y
|
||||||
bpl cn0
|
bpl cn0
|
||||||
sec
|
sec
|
||||||
lda #0
|
ldx #0
|
||||||
|
txa
|
||||||
sbc [argp]
|
sbc [argp]
|
||||||
sta [argp]
|
sta [argp]
|
||||||
ldy #2
|
ldy #2
|
||||||
lda #0
|
txa
|
||||||
sbc [argp],Y
|
sbc [argp],Y
|
||||||
sta [argp],Y
|
sta [argp],Y
|
||||||
iny
|
iny
|
||||||
iny
|
iny
|
||||||
lda #0
|
txa
|
||||||
sbc [argp],Y
|
sbc [argp],Y
|
||||||
sta [argp],Y
|
sta [argp],Y
|
||||||
iny
|
iny
|
||||||
iny
|
iny
|
||||||
lda #0
|
txa
|
||||||
sbc [argp],Y
|
sbc [argp],Y
|
||||||
sta [argp],Y
|
sta [argp],Y
|
||||||
bra sn2
|
bra sn2
|
||||||
|
@ -4355,17 +4342,8 @@ pn1 lda ~hexPrefix if there is a hex prefix then
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
ph2 ~hexPrefix+1
|
ph2 ~hexPrefix+1
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
pn1a lda ~paddChar if the number needs 0 padding then
|
pn1a jsr ~ZeroPad pad with '0's if needed
|
||||||
cmp #'0'
|
lda ~precision if the number needs more padding then
|
||||||
bne pn1c
|
|
||||||
lda ~fieldWidth
|
|
||||||
bmi pn1c
|
|
||||||
beq pn1c
|
|
||||||
pn1b ph2 ~paddChar print padd zeros
|
|
||||||
jsl ~putchar
|
|
||||||
dec ~fieldWidth
|
|
||||||
bne pn1b
|
|
||||||
pn1c lda ~precision if the number needs more padding then
|
|
||||||
beq pn3
|
beq pn3
|
||||||
pn2 ph2 #'0' print padd characters
|
pn2 ph2 #'0' print padd characters
|
||||||
jsl ~putchar
|
jsl ~putchar
|
||||||
|
@ -4393,10 +4371,10 @@ pn5 cpy #l:~str quit if we're at the end of the ~str
|
||||||
;
|
;
|
||||||
rn1 lda ~isLongLong
|
rn1 lda ~isLongLong
|
||||||
beq rn2
|
beq rn2
|
||||||
inc argp
|
lda argp
|
||||||
inc argp
|
clc
|
||||||
inc argp
|
adc #4
|
||||||
inc argp
|
sta argp
|
||||||
rn2 lda ~isLong
|
rn2 lda ~isLong
|
||||||
beq rn3
|
beq rn3
|
||||||
inc argp
|
inc argp
|
||||||
|
@ -4738,14 +4716,14 @@ argp equ 7 argument pointer
|
||||||
; Set the "or" value; this is used to set the case of character results
|
; Set the "or" value; this is used to set the case of character results
|
||||||
;
|
;
|
||||||
lda #$20
|
lda #$20
|
||||||
sta orVal
|
sta ~orVal
|
||||||
bra cn0
|
bra cn0
|
||||||
|
|
||||||
~Format_p entry
|
~Format_p entry
|
||||||
lda #1
|
lda #1
|
||||||
sta ~isLong
|
sta ~isLong
|
||||||
~Format_X entry
|
~Format_X entry
|
||||||
stz orVal
|
stz ~orVal
|
||||||
;
|
;
|
||||||
; Initialization
|
; Initialization
|
||||||
;
|
;
|
||||||
|
@ -4807,7 +4785,7 @@ cn4 lsr ~num+7
|
||||||
cmp #'9'+1 if the character should be alpha,
|
cmp #'9'+1 if the character should be alpha,
|
||||||
blt cn5 adjust it
|
blt cn5 adjust it
|
||||||
adc #6
|
adc #6
|
||||||
ora orVal
|
ora ~orVal
|
||||||
cn5 sta ~str,Y save the character
|
cn5 sta ~str,Y save the character
|
||||||
dey
|
dey
|
||||||
lda ~num+7 loop if the number is not zero
|
lda ~num+7 loop if the number is not zero
|
||||||
|
@ -4825,7 +4803,7 @@ cn5 sta ~str,Y save the character
|
||||||
lda ~altForm branch if no leading '0x' is required
|
lda ~altForm branch if no leading '0x' is required
|
||||||
beq al3
|
beq al3
|
||||||
al2 lda #'X' insert leading '0x'
|
al2 lda #'X' insert leading '0x'
|
||||||
ora orVal
|
ora ~orVal
|
||||||
sta ~hexPrefix+1
|
sta ~hexPrefix+1
|
||||||
lda #'0'
|
lda #'0'
|
||||||
sta ~hexPrefix
|
sta ~hexPrefix
|
||||||
|
@ -4834,10 +4812,6 @@ al3 long I,M
|
||||||
; Piggy back off of ~Format_d for output
|
; Piggy back off of ~Format_d for output
|
||||||
;
|
;
|
||||||
brl ~Format_IntOut
|
brl ~Format_IntOut
|
||||||
;
|
|
||||||
; Local data
|
|
||||||
;
|
|
||||||
orVal ds 2 for setting the case of characters
|
|
||||||
end
|
end
|
||||||
|
|
||||||
****************************************************************
|
****************************************************************
|
||||||
|
@ -4967,10 +4941,12 @@ stream equ 3 input stream
|
||||||
*
|
*
|
||||||
* ~LeftJustify - print padd characters for left justification
|
* ~LeftJustify - print padd characters for left justification
|
||||||
* ~RightJustify - print padd characters for right justification
|
* ~RightJustify - print padd characters for right justification
|
||||||
|
* ~ZeroPad - print zeros to pad to field width
|
||||||
*
|
*
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* ~fieldWidth - # chars to print ( <= 0 prints none)
|
* ~fieldWidth - # chars to print ( <= 0 prints none)
|
||||||
* ~leftJustify - left justify the output?
|
* ~leftJustify - left justify the output?
|
||||||
|
* ~paddChar - padding character
|
||||||
*
|
*
|
||||||
****************************************************************
|
****************************************************************
|
||||||
*
|
*
|
||||||
|
@ -4993,6 +4969,19 @@ lb1 ph2 #' ' write the proper # of padd characters
|
||||||
dec ~fieldWidth
|
dec ~fieldWidth
|
||||||
bne lb1
|
bne lb1
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
~ZeroPad entry
|
||||||
|
lda ~paddChar if the number needs 0 padding then
|
||||||
|
cmp #'0'
|
||||||
|
bne zp2
|
||||||
|
lda ~fieldWidth
|
||||||
|
bmi zp2
|
||||||
|
beq zp2
|
||||||
|
zp1 ph2 ~paddChar print padd zeros
|
||||||
|
jsl ~putchar
|
||||||
|
dec ~fieldWidth
|
||||||
|
bne zp1
|
||||||
|
zp2 rts
|
||||||
end
|
end
|
||||||
|
|
||||||
****************************************************************
|
****************************************************************
|
||||||
|
@ -5240,8 +5229,7 @@ Flag lda [format] get the character
|
||||||
and #$00FF
|
and #$00FF
|
||||||
cmp #'-' if it is a '-' then
|
cmp #'-' if it is a '-' then
|
||||||
bne fl1
|
bne fl1
|
||||||
lda #1 left justify the output
|
sta ~leftJustify left justify the output
|
||||||
sta ~leftJustify
|
|
||||||
lda #' ' pad with spaces (ignore any '0' flag)
|
lda #' ' pad with spaces (ignore any '0' flag)
|
||||||
sta ~paddChar
|
sta ~paddChar
|
||||||
bra fl5
|
bra fl5
|
||||||
|
@ -5257,10 +5245,7 @@ fl2 cmp #'+' if it is a '+' or ' ' then
|
||||||
beq fl3
|
beq fl3
|
||||||
cmp #' '
|
cmp #' '
|
||||||
bne fl4
|
bne fl4
|
||||||
ldx ~sign
|
fl3 tsb ~sign set the sign flag ('+' overrides ' ')
|
||||||
cpx #'+'
|
|
||||||
beq fl5
|
|
||||||
fl3 sta ~sign set the sign flag
|
|
||||||
bra fl5
|
bra fl5
|
||||||
|
|
||||||
fl4 cmp #'#' if it is a '#' then
|
fl4 cmp #'#' if it is a '#' then
|
||||||
|
@ -5290,7 +5275,7 @@ GetSize stz val assume a value of 0
|
||||||
bne fv0
|
bne fv0
|
||||||
eor #$ffff negative field width is like
|
eor #$ffff negative field width is like
|
||||||
inc a positive with - flag
|
inc a positive with - flag
|
||||||
ldx #1
|
ldx #'-'
|
||||||
stx ~leftJustify
|
stx ~leftJustify
|
||||||
ldx #' '
|
ldx #' '
|
||||||
stx ~paddChar
|
stx ~paddChar
|
||||||
|
@ -5382,6 +5367,7 @@ fListEnd anop
|
||||||
;
|
;
|
||||||
~num ds 8 long long integer
|
~num ds 8 long long integer
|
||||||
~numChars ds 2 number of characters printed with this printf
|
~numChars ds 2 number of characters printed with this printf
|
||||||
|
~orVal ds 2 value to 'or' with to set case of characters
|
||||||
~str ds 83 string buffer
|
~str ds 83 string buffer
|
||||||
;
|
;
|
||||||
; Real formatting
|
; Real formatting
|
||||||
|
|
Loading…
Reference in New Issue