Post by qkumbaYes, something like that, but you can't use the "ZP,X" access because it won't extend into the stack page, so it might not save anything.
Yeah, we lose the ZP,X and are forced to use a 16-bit,X addressing mode. :-/
Plus the over-head of having to manage the stack means we don't win here.
Maybe you can edge out a few more bytes? :-)
0900:A9 12 A2 34 4C 07 09 A0
0908:00 48 DA 5A 5A 5A A0 10
0910:F8 BA 8E 30 09 1E 04 01
0918:3E 05 01 20 3C 09 20 3C
0920:09 20 3C 09 88 D0 EA D8
0928:BD 00 01 20 47 09 CA E0
0930:00 D0 F5 8A 69 04 AA 9A
0938:98 F0 1C 60 BD 01 01 7D
0940:01 01 9D 01 01 E8 60 48
0948:20 7B F8 20 51 09 68 29
0950:0F D0 04 C0 00 F0 E4 C9
0958:0A 90 02 69 06 69 B0 C8
0960:4C ED FD
- - - 8< print_uint16_sp.s - - -
; Michael Pohoreski
; https://github.com/Michaelangel007/apple2_print_uint16
; Optimized from printm
; Thanks to qkumba for optimizations
; Thanks to gid for nudging a zero-page version
; F8 ROM Entry Points
COUT = $FDED
SCRN2 = $F879
; Zero-Page Version - 4 locations used
;_temp = $fc
;bcd = $fd ; NOTE: MUST be at $FD for ZP,X addressing in _DoubleDabble
ORG $900 ; Intentionally different from sans-zero-page version for testing both
LDA #$12
LDX #$34
JMP PrintUint16
; Print unsigned 16-bit integer
; A=High byte
; X=Low byte
; Also see: Applesoft LINPRT @ ED24
; ======================================================================
PrintUint16
LDY #0 ; S=F3
PHA ; S+5 = _temp+1 = $105,X S=F1
PHX ; S+4 = _temp+0 = $104,X S=F2
PHY ; S+3 = _bcd[2] = $103,X S=F0
PHY ; S+2 = _bcd[1] = $102,X S=EF
PHY ; S+1 = _bcd[0] = $101,X S=EE
Dec2BCD
LDY #16 ; 16 bits
SED ; "Double Dabble"
_Dec2BCD ; https://en.wikipedia.org/wiki/Double_dabble
TSX ; X=EE
STX _BCDbegin+1 ; *** SELF-MODIFYING
; ASL _temp+0 ; abcd efgh | ijkl mnop |
; ROL _temp+1 ; C=a bcde fghi | jklm nop0 |
; ; Bit 7654_3210 | 7654_3210 |
ASL $104,X ; _temp+0
ROL $105,X ; _temp+1
; LDX #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3]
_DoubleDabble ; Y=FD Y=FE Y=FF Y=00
JSR Dabble ; X=EF
JSR Dabble ; X=F0
JSR Dabble ; X=F1
DEY
BNE _Dec2BCD
CLD ; Y=0 = output length
BCD2Chars
LDA $100,X ; X=F1, 1F1 -> bcd[2]
JSR HexA ; print 0, 1, or 2 hex digits
DEX
_BCDbegin
CPX #00 ; *** SELF-MODIFIED X == EE ?
BNE BCD2Chars
; Safe to restore stack now since we are done with vars
TXA
ADC #$04 ; C=1 from CPX #EE
TAX
TXS
TYA ; Handle special case input = $0000 of no output
BEQ _HaveLeadingDigit
_PrintDone
RTS
Dabble
LDA $101,X ; bcd,X
ADC $101,X
STA $101,X
INX
RTS
; Converts A to high ASCII digits, prints as they become available
; @return: A will be bottom nibble in high ASCII
HexA
PHA
JSR SCRN2+2 ; LSR x4 == 0>> 4
JSR _HexNib
PLA
AND #$F
_HexNib
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
CPY #0 ; ... then skip storing it
BEQ _PrintDone
_HaveLeadingDigit
CMP #$A ; n < 10 ?
BCC _Hex2Asc
ADC #6 ; n += 6 $A -> +6 + (C=1) = $11
_Hex2Asc
ADC #'0' + $80 ; inverse=remove #$80
PutChar
INY ; Y = output string length
JMP COUT