apple2_print_uint16/print_uint16_sans_zp.s

84 lines
2.2 KiB
ArmAsm
Raw Permalink Normal View History

2017-07-06 02:38:09 +00:00
; Michael Pohoreski
2017-07-06 14:58:22 +00:00
; https://github.com/Michaelangel007/apple2_print_uint16
2017-07-06 02:38:09 +00:00
; Optimized from printm
; Thanks to qkumba for optimizations
2017-07-06 19:45:49 +00:00
; Thanks to Gids for nudging a zero-page version
2017-07-06 14:58:22 +00:00
2017-07-06 02:38:09 +00:00
; F8 ROM Entry Points
2017-07-06 22:28:28 +00:00
PRHEXZ = $FDE5
2017-07-06 01:50:13 +00:00
SCRN2 = $F879
2017-07-05 23:42:22 +00:00
; Print unsigned 16-bit integer
; A=High byte
; X=Low byte
; Also see: Applesoft LINPRT @ ED24
2017-07-05 23:42:22 +00:00
; ======================================================================
PrintUint16
2017-07-06 06:08:47 +00:00
STX _temp
2017-07-05 23:42:22 +00:00
2017-07-06 22:41:49 +00:00
LDX #0 ; Optional 65C02 version
STX _bcd+0 ; STZ _bcd+0
STX _bcd+1 ; STZ _bcd+1
STX _bcd+2 ; STZ _bcd+2
2017-07-05 23:42:22 +00:00
Dec2BCD
LDX #16 ; 16 bits
SED ; "Double Dabble"
_Dec2BCD ; https://en.wikipedia.org/wiki/Double_dabble
2017-07-06 06:08:47 +00:00
ASL _temp+0 ; abcd efgh | ijkl mnop |
; ROL _temp+1 ; C=a bcde fghi | jklm nop0 |
; ; Bit 7654_3210 | 7654_3210 |
ROL
2017-07-06 22:41:49 +00:00
PHA ; Optimized: STA _temp+1
2017-07-05 23:42:22 +00:00
LDY #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3]
_DoubleDabble ; Y=FD Y=FE Y=FF Y=00
LDA _bcd-$FD,Y
ADC _bcd-$FD,Y
STA _bcd-$FD,Y
INY
BNE _DoubleDabble
2017-07-06 22:41:49 +00:00
PLA
2017-07-05 23:42:22 +00:00
DEX
BNE _Dec2BCD
2017-07-06 06:08:47 +00:00
2017-07-06 01:50:13 +00:00
CLD ; X=0 = output length
2017-07-05 23:42:22 +00:00
DecWidth
2017-07-06 03:28:10 +00:00
LDY #3 ; maximum 6 digits output
2017-07-05 23:42:22 +00:00
BCD2Chars
2017-07-06 02:38:09 +00:00
LDA _bcd-1,Y
2017-07-06 03:28:10 +00:00
JSR HexA ; print 0, 1, or 2 hex digits
2017-07-05 23:42:22 +00:00
DEY
2017-07-06 02:38:09 +00:00
BNE BCD2Chars
2017-07-05 23:42:22 +00:00
2017-07-06 06:08:47 +00:00
TXA ; Handle special case input = $0000 of no output
2017-07-06 14:58:22 +00:00
BEQ _HaveLeadingDigit
2017-07-06 01:50:13 +00:00
2017-07-05 23:42:22 +00:00
_PrintDone
RTS
2017-07-06 03:32:41 +00:00
; Converts A to high ASCII digits, prints as they become available
2017-07-06 02:45:51 +00:00
; @return: A will be bottom nibble in high ASCII
2017-07-05 23:42:22 +00:00
HexA
PHA
2017-07-06 01:50:13 +00:00
JSR SCRN2+2 ; LSR x4 == 0>> 4
2017-07-05 23:42:22 +00:00
JSR _HexNib
PLA
2017-07-06 01:50:13 +00:00
AND #$F
2017-07-05 23:42:22 +00:00
_HexNib
2017-07-06 02:38:09 +00:00
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
2017-07-06 22:08:39 +00:00
DEX ; ... then skip storing it
2017-07-06 02:38:09 +00:00
_HaveLeadingDigit
2017-07-06 22:08:39 +00:00
INX ; X = flag to specify non-zero leading digit was seen
BEQ _PrintDone
2017-07-06 22:28:28 +00:00
JMP PRHEXZ
2017-07-05 23:42:22 +00:00
_bcd BRK ; 6 chars for printing dec
BRK
BRK
_temp BRK
2017-07-05 23:42:22 +00:00