mirror of
https://github.com/Michaelangel007/apple2_print_uint16.git
synced 2025-01-16 00:31:26 +00:00
Optimized 117 bytes
This commit is contained in:
parent
7baae0bc3f
commit
dbc87d60ed
33
README.md
33
README.md
@ -1,6 +1,6 @@
|
|||||||
# Print unsigned 16-bit
|
# Print unsigned 16-bit
|
||||||
|
|
||||||
6502 assembly code to print an unsigned 16-bit in 124 bytes ($7C).
|
6502 assembly code to print an unsigned 16-bit in 117 bytes ($75).
|
||||||
|
|
||||||
|
|
||||||
* No zero-page usage
|
* No zero-page usage
|
||||||
@ -13,22 +13,21 @@ Copy/Paste into your favorite emulator.
|
|||||||
|
|
||||||
```asm
|
```asm
|
||||||
0800:A9 12 A2 34 4C 07 08 8E
|
0800:A9 12 A2 34 4C 07 08 8E
|
||||||
0808:81 08 8D 82 08 A9 00 8D
|
0808:7A 08 8D 7B 08 A9 00 8D
|
||||||
0810:6F 08 8D 77 08 8D 78 08
|
0810:70 08 8D 71 08 8D 72 08
|
||||||
0818:8D 79 08 A2 10 F8 0E 81
|
0818:A2 10 F8 0E 7A 08 2E 7B
|
||||||
0820:08 2E 82 08 A0 FD B9 7A
|
0820:08 A0 FD B9 73 07 79 73
|
||||||
0828:07 79 7A 07 99 7A 07 C8
|
0828:07 99 73 07 C8 D0 F4 CA
|
||||||
0830:D0 F4 CA D0 E9 D8 A0 03
|
0830:D0 E9 D8 A0 04 A9 B0 8D
|
||||||
0838:B9 77 08 20 5B 08 88 10
|
0838:74 08 B9 6F 08 20 53 08
|
||||||
0840:F7 C8 CC 6F 08 F0 07 B9
|
0840:88 D0 F7 8E 70 08 B9 74
|
||||||
0848:7B 08 C9 B0 F0 F3 B9 7B
|
0848:08 20 ED FD C8 CC 70 08
|
||||||
0850:08 20 ED FD C8 CC 6F 08
|
0850:90 F4 60 48 20 7B F8 20
|
||||||
0858:90 F4 60 48 4A 4A 4A 4A
|
0858:5D 08 68 29 0F D0 04 E0
|
||||||
0860:20 64 08 68 29 0F C9 0A
|
0860:00 F0 0C C9 0A 90 02 69
|
||||||
0868:90 02 69 06 69 B0 A2 00
|
0868:06 69 B0 9D 74 08 E8 60
|
||||||
0870:9D 7B 08 EE 6F 08 60 00
|
0870:00 00 00 00 00 00 00 00
|
||||||
0878:00 00 00 00 00 00 00 00
|
0878:00 00 00 00
|
||||||
0880:00 00 00
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
BIN
print_uint16
BIN
print_uint16
Binary file not shown.
@ -1,3 +1,7 @@
|
|||||||
|
; Michael Pohoreski
|
||||||
|
; Optimized from printm
|
||||||
|
; Thanks to qkumba for optimizations
|
||||||
|
; F8 ROM Entry Points
|
||||||
COUT = $FDED
|
COUT = $FDED
|
||||||
SCRN2 = $F879
|
SCRN2 = $F879
|
||||||
|
|
||||||
@ -41,23 +45,19 @@ _DoubleDabble ; Y=FD Y=FE Y=FF Y=00
|
|||||||
CLD ; X=0 = output length
|
CLD ; X=0 = output length
|
||||||
|
|
||||||
DecWidth
|
DecWidth
|
||||||
LDY #3 ; intentional buffer overflow - 8 digit output for special case of $0000
|
LDY #4 ; 6 digit output for special case of $0000
|
||||||
|
|
||||||
|
LDA #'0' + $80 ; handle special case input = $0000
|
||||||
|
STA _output ; since we always print at least 1 digit
|
||||||
|
|
||||||
BCD2Chars
|
BCD2Chars
|
||||||
LDA _bcd,Y
|
LDA _bcd-1,Y
|
||||||
JSR HexA ; _output[0..7] = '?'
|
JSR HexA ; _output[0..7] = '?'
|
||||||
DEY
|
DEY
|
||||||
BPL BCD2Chars
|
BNE BCD2Chars
|
||||||
|
|
||||||
STX _len ; output buffer len = num digits to print
|
STX _len ; output buffer len = num digits to print
|
||||||
|
|
||||||
SkipLeadZero
|
|
||||||
INY
|
|
||||||
CPY _len
|
|
||||||
BEQ OutDigits
|
|
||||||
LDA _output,Y
|
|
||||||
CMP #'0' + $80 ; skip all leading zero's
|
|
||||||
BEQ SkipLeadZero
|
|
||||||
|
|
||||||
OutDigits
|
OutDigits
|
||||||
LDA _output,Y ; always print digit in "ones" place
|
LDA _output,Y ; always print digit in "ones" place
|
||||||
JSR COUT
|
JSR COUT
|
||||||
@ -77,7 +77,13 @@ HexA
|
|||||||
PLA
|
PLA
|
||||||
AND #$F
|
AND #$F
|
||||||
_HexNib
|
_HexNib
|
||||||
|
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
|
||||||
|
CPX #0 ; ... then skip storing it
|
||||||
|
BEQ _HexAsciiDone
|
||||||
|
|
||||||
|
_HaveLeadingDigit
|
||||||
CMP #$A ; n < 10 ?
|
CMP #$A ; n < 10 ?
|
||||||
|
|
||||||
BCC _Hex2Asc
|
BCC _Hex2Asc
|
||||||
ADC #6 ; n += 6 $A -> +6 + (C=1) = $11
|
ADC #6 ; n += 6 $A -> +6 + (C=1) = $11
|
||||||
_Hex2Asc
|
_Hex2Asc
|
||||||
@ -85,6 +91,7 @@ _Hex2Asc
|
|||||||
PutChar
|
PutChar
|
||||||
STA _output,X
|
STA _output,X
|
||||||
INX ; X = output string length
|
INX ; X = output string length
|
||||||
|
_HexAsciiDone
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user