mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2024-09-29 02:54:30 +00:00
Compare commits
No commits in common. "78a9e1d93b96af13bd4eae3abd0392098a464ec6" and "80c0bbc32b60c8f10d5cd18164fca7872153ad76" have entirely different histories.
78a9e1d93b
...
80c0bbc32b
239
stdio.asm
239
stdio.asm
@ -4520,12 +4520,9 @@ lb1 clc restore the original argp+4
|
|||||||
****************************************************************
|
****************************************************************
|
||||||
*
|
*
|
||||||
* ~Format_o - format an octal number
|
* ~Format_o - format an octal number
|
||||||
* ~Format_x - format a hexadecimal number (lowercase output)
|
|
||||||
* ~Format_X - format a hexadecimal number (uppercase output)
|
|
||||||
* ~Format_p - format a pointer
|
|
||||||
*
|
*
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* ~altForm - use a leading '0' (octal) or '0x' (hex)?
|
* ~altForm - use a leading '0'?
|
||||||
* ~fieldWidth - output field width
|
* ~fieldWidth - output field width
|
||||||
* ~paddChar - padd character
|
* ~paddChar - padd character
|
||||||
* ~leftJustify - left justify the output?
|
* ~leftJustify - left justify the output?
|
||||||
@ -4539,34 +4536,15 @@ lb1 clc restore the original argp+4
|
|||||||
~Format_o private
|
~Format_o private
|
||||||
using ~printfCommon
|
using ~printfCommon
|
||||||
argp equ 7 argument pointer
|
argp equ 7 argument pointer
|
||||||
|
|
||||||
lda #3 use 3 bits per output character
|
|
||||||
bra cn0
|
|
||||||
|
|
||||||
~Format_x entry
|
|
||||||
;
|
|
||||||
; Set the "or" value; this is used to set the case of character results
|
|
||||||
;
|
|
||||||
lda #$20*256
|
|
||||||
sta ~orVal
|
|
||||||
bra hx0
|
|
||||||
|
|
||||||
~Format_p entry
|
|
||||||
inc ~isLong
|
|
||||||
~Format_X entry
|
|
||||||
stz ~orVal
|
|
||||||
hx0 lda #4 use 4 bits per output character
|
|
||||||
|
|
||||||
;
|
;
|
||||||
; Initialization
|
; Initialization
|
||||||
;
|
;
|
||||||
cn0 sta bitsPerChar
|
|
||||||
stz ~hexPrefix assume we won't lead with 0x
|
|
||||||
stz ~sign ignore the sign flag
|
stz ~sign ignore the sign flag
|
||||||
lda #' ' initialize the string to blanks
|
lda #' ' initialize the string to blanks
|
||||||
sta ~str
|
sta ~str
|
||||||
move ~str,~str+1,#l:~str-1
|
move ~str,~str+1,#l:~str-1
|
||||||
lda ~isLongLong get the value to convert
|
stz ~num+2 get the value to convert
|
||||||
|
lda ~isLongLong
|
||||||
beq cn1
|
beq cn1
|
||||||
ldy #6
|
ldy #6
|
||||||
lda [argp],Y
|
lda [argp],Y
|
||||||
@ -4577,7 +4555,7 @@ cn0 sta bitsPerChar
|
|||||||
sta ~num+4
|
sta ~num+4
|
||||||
cn1 lda ~isLong
|
cn1 lda ~isLong
|
||||||
beq cn2
|
beq cn2
|
||||||
ldy #2
|
cn1a ldy #2
|
||||||
lda [argp],Y
|
lda [argp],Y
|
||||||
sta ~num+2
|
sta ~num+2
|
||||||
cn2 lda [argp]
|
cn2 lda [argp]
|
||||||
@ -4585,71 +4563,57 @@ cn2 lda [argp]
|
|||||||
beq cn2a
|
beq cn2a
|
||||||
and #$00FF
|
and #$00FF
|
||||||
cn2a sta ~num
|
cn2a sta ~num
|
||||||
ldx bitsPerChar if doing hex format then
|
|
||||||
cpx #3
|
|
||||||
beq cn2b
|
|
||||||
ldx ~altForm if alt form has been selected then
|
|
||||||
beq cn2b
|
|
||||||
ora ~num+2 if value is not 0 then
|
|
||||||
ora ~num+4
|
|
||||||
ora ~num+6
|
|
||||||
beq cn2b
|
|
||||||
lda #'X0' set hex prefix to '0X' or '0x'
|
|
||||||
ora ~orVal
|
|
||||||
sta ~hexPrefix
|
|
||||||
;
|
;
|
||||||
; Convert the number to an ASCII string
|
; Convert the number to an ASCII string
|
||||||
;
|
;
|
||||||
cn2b ldy #l:~str-1 set up the character index
|
short I,M
|
||||||
cn3 lda #' 0' roll off 4 bits
|
ldy #l:~str-1 set up the character index
|
||||||
ldx bitsPerChar
|
cn3 lda ~num+7 quit if the number is zero
|
||||||
cn4 lsr ~num+6
|
ora ~num+6
|
||||||
|
ora ~num+5
|
||||||
|
ora ~num+4
|
||||||
|
ora ~num+3
|
||||||
|
ora ~num+2
|
||||||
|
ora ~num+1
|
||||||
|
ora ~num
|
||||||
|
beq al1
|
||||||
|
lda #0 roll off 3 bits
|
||||||
|
ldx #3
|
||||||
|
cn4 lsr ~num+7
|
||||||
|
ror ~num+6
|
||||||
|
ror ~num+5
|
||||||
ror ~num+4
|
ror ~num+4
|
||||||
|
ror ~num+3
|
||||||
ror ~num+2
|
ror ~num+2
|
||||||
|
ror ~num+1
|
||||||
ror ~num
|
ror ~num
|
||||||
ror A
|
ror A
|
||||||
dex
|
dex
|
||||||
bne cn4
|
bne cn4
|
||||||
xba form a character
|
lsr A form a character
|
||||||
ldx bitsPerChar
|
lsr A
|
||||||
cn4a asl A
|
lsr A
|
||||||
dex
|
lsr A
|
||||||
bne cn4a
|
lsr A
|
||||||
cmp #('9'+1)*256+' ' if the character should be alpha then
|
ora #'0'
|
||||||
blt cn5
|
|
||||||
clc
|
|
||||||
adc #7*256 adjust it
|
|
||||||
ora ~orVal
|
|
||||||
cn5 dey
|
|
||||||
sta ~str,Y save the character
|
sta ~str,Y save the character
|
||||||
lda ~num+6 loop if the number is not zero
|
dey
|
||||||
ora ~num+4
|
bra cn3
|
||||||
ora ~num+2
|
|
||||||
ora ~num
|
|
||||||
bne cn3
|
|
||||||
;
|
;
|
||||||
; If a leading '0x' is required, be sure we include one
|
; If a leading zero is required, be sure we include one
|
||||||
;
|
;
|
||||||
lda bitsPerChar if doing octal format then
|
al1 cpy #l:~str-1 include a zero if no characters have
|
||||||
cmp #3
|
beq al2 been placed in the string
|
||||||
bne al3
|
lda ~altForm branch if no leading zero is required
|
||||||
lda ~altForm if alt form has been selected then
|
|
||||||
beq al3
|
beq al3
|
||||||
lda ~precision make sure precision is non-zero
|
al2 lda #'0'
|
||||||
bne al2
|
sta ~str,Y
|
||||||
inc ~precision
|
al3 long I,M
|
||||||
al2 lda #'0 ' if the result is not ' 0' then
|
|
||||||
cmp ~str+l:~str-2
|
|
||||||
beq al3
|
|
||||||
sta ~str-1,Y include a zero in the string
|
|
||||||
;
|
;
|
||||||
; Piggy back off of ~Format_d for output
|
; Piggy back off of ~Format_d for output
|
||||||
;
|
;
|
||||||
al3 brl ~Format_IntOut
|
stz ~hexPrefix don't lead with 0x
|
||||||
;
|
brl ~Format_IntOut
|
||||||
; Local data
|
|
||||||
;
|
|
||||||
bitsPerChar ds 2 bits per output character
|
|
||||||
end
|
end
|
||||||
|
|
||||||
****************************************************************
|
****************************************************************
|
||||||
@ -4727,6 +4691,129 @@ lb4 clc restore and increment argp
|
|||||||
brl ~LeftJustify handle left justification
|
brl ~LeftJustify handle left justification
|
||||||
end
|
end
|
||||||
|
|
||||||
|
****************************************************************
|
||||||
|
*
|
||||||
|
* ~Format_x - format a hexadecimal number (lowercase output)
|
||||||
|
* ~Format_X - format a hexadecimal number (uppercase output)
|
||||||
|
* ~Format_p - format a pointer
|
||||||
|
*
|
||||||
|
* Inputs:
|
||||||
|
* ~altForm - use a leading '0x'?
|
||||||
|
* ~fieldWidth - output field width
|
||||||
|
* ~paddChar - padd character
|
||||||
|
* ~leftJustify - left justify the output?
|
||||||
|
* ~isLong - is the operand long?
|
||||||
|
* ~isLongLong - is the operand long long?
|
||||||
|
* ~precision - precision of output
|
||||||
|
* ~precisionSpecified - was the precision specified?
|
||||||
|
*
|
||||||
|
****************************************************************
|
||||||
|
*
|
||||||
|
~Format_x private
|
||||||
|
using ~printfCommon
|
||||||
|
argp equ 7 argument pointer
|
||||||
|
;
|
||||||
|
; Set the "or" value; this is used to set the case of character results
|
||||||
|
;
|
||||||
|
lda #$20
|
||||||
|
sta ~orVal
|
||||||
|
bra cn0
|
||||||
|
|
||||||
|
~Format_p entry
|
||||||
|
lda #1
|
||||||
|
sta ~isLong
|
||||||
|
~Format_X entry
|
||||||
|
stz ~orVal
|
||||||
|
;
|
||||||
|
; Initialization
|
||||||
|
;
|
||||||
|
cn0 stz ~sign ignore the sign flag
|
||||||
|
lda #' ' initialize the string to blanks
|
||||||
|
sta ~str
|
||||||
|
move ~str,~str+1,#l:~str-1
|
||||||
|
stz ~num+2 get the value to convert
|
||||||
|
stz ~num+4
|
||||||
|
stz ~num+6
|
||||||
|
lda ~isLongLong
|
||||||
|
beq cn1
|
||||||
|
ldy #6
|
||||||
|
lda [argp],Y
|
||||||
|
sta ~num+6
|
||||||
|
dey
|
||||||
|
dey
|
||||||
|
lda [argp],Y
|
||||||
|
sta ~num+4
|
||||||
|
cn1 lda ~isLong
|
||||||
|
beq cn2
|
||||||
|
ldy #2
|
||||||
|
lda [argp],Y
|
||||||
|
sta ~num+2
|
||||||
|
cn2 lda [argp]
|
||||||
|
ldx ~isByte
|
||||||
|
beq cn2a
|
||||||
|
and #$00FF
|
||||||
|
cn2a sta ~num
|
||||||
|
ora ~num+2
|
||||||
|
ora ~num+4
|
||||||
|
ora ~num+6
|
||||||
|
bne cn2b
|
||||||
|
stz ~altForm if value is 0, do not print hex prefix
|
||||||
|
cn2b stz ~hexPrefix assume we won't lead with 0x
|
||||||
|
;
|
||||||
|
; Convert the number to an ASCII string
|
||||||
|
;
|
||||||
|
short I,M
|
||||||
|
ldy #l:~str-1 set up the character index
|
||||||
|
cn3 lda #0 roll off 4 bits
|
||||||
|
ldx #4
|
||||||
|
cn4 lsr ~num+7
|
||||||
|
ror ~num+6
|
||||||
|
ror ~num+5
|
||||||
|
ror ~num+4
|
||||||
|
ror ~num+3
|
||||||
|
ror ~num+2
|
||||||
|
ror ~num+1
|
||||||
|
ror ~num
|
||||||
|
ror A
|
||||||
|
dex
|
||||||
|
bne cn4
|
||||||
|
lsr A form a character
|
||||||
|
lsr A
|
||||||
|
lsr A
|
||||||
|
lsr A
|
||||||
|
ora #'0'
|
||||||
|
cmp #'9'+1 if the character should be alpha,
|
||||||
|
blt cn5 adjust it
|
||||||
|
adc #6
|
||||||
|
ora ~orVal
|
||||||
|
cn5 sta ~str,Y save the character
|
||||||
|
dey
|
||||||
|
lda ~num+7 loop if the number is not zero
|
||||||
|
ora ~num+6
|
||||||
|
ora ~num+5
|
||||||
|
ora ~num+4
|
||||||
|
ora ~num+3
|
||||||
|
ora ~num+2
|
||||||
|
ora ~num+1
|
||||||
|
ora ~num
|
||||||
|
bne cn3
|
||||||
|
;
|
||||||
|
; If a leading '0x' is required, be sure we include one
|
||||||
|
;
|
||||||
|
lda ~altForm branch if no leading '0x' is required
|
||||||
|
beq al3
|
||||||
|
al2 lda #'X' insert leading '0x'
|
||||||
|
ora ~orVal
|
||||||
|
sta ~hexPrefix+1
|
||||||
|
lda #'0'
|
||||||
|
sta ~hexPrefix
|
||||||
|
al3 long I,M
|
||||||
|
;
|
||||||
|
; Piggy back off of ~Format_d for output
|
||||||
|
;
|
||||||
|
brl ~Format_IntOut
|
||||||
|
end
|
||||||
|
|
||||||
****************************************************************
|
****************************************************************
|
||||||
*
|
*
|
||||||
* ~Format_Percent - format the '%' character
|
* ~Format_Percent - format the '%' character
|
||||||
@ -5278,7 +5365,7 @@ fListEnd anop
|
|||||||
;
|
;
|
||||||
; Work buffers
|
; Work buffers
|
||||||
;
|
;
|
||||||
~num ds 8 long long integer (must be 0 after each conversion)
|
~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
|
~orVal ds 2 value to 'or' with to set case of characters
|
||||||
~str ds 83 string buffer
|
~str ds 83 string buffer
|
||||||
|
Loading…
Reference in New Issue
Block a user