diff --git a/README.md b/README.md index e5cfeb9..1d19a69 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Print unsigned 16-bit -6502 assembly code to print an unsigned 16-bit in 95 bytes ($5F). +6502 assembly code to print an unsigned 16-bit in 91 bytes ($5B). Features: @@ -14,18 +14,18 @@ Copy/Paste into your favorite emulator. ```asm 0800:A9 12 A2 34 4C 07 08 8E -0808:64 08 8D 65 08 A9 00 8D -0810:60 08 8D 61 08 8D 62 08 -0818:A2 10 F8 0E 64 08 2E 65 -0820:08 A0 FD B9 63 07 79 63 -0828:07 99 63 07 C8 D0 F4 CA -0830:D0 E9 D8 A0 03 B9 5F 08 -0838:20 44 08 88 D0 F7 8A E0 -0840:00 F0 11 60 48 20 7B F8 -0848:20 4E 08 68 29 0F D0 04 -0850:E0 00 F0 EF C9 0A 90 02 -0858:69 06 69 B0 E8 4C ED FD -0860:00 00 00 00 00 00 +0808:61 08 48 A2 00 8E 5D 08 +0810:8E 5E 08 8E 5F 08 A2 10 +0818:F8 0E 61 08 68 2A 48 A0 +0820:FD B9 60 07 79 60 07 99 +0828:60 07 C8 D0 F4 CA D0 E9 +0830:68 D8 A0 03 B9 5C 08 20 +0838:41 08 88 D0 F7 8A F0 11 +0840:60 48 20 7B F8 20 4B 08 +0848:68 29 0F D0 04 E0 00 F0 +0850:EF C9 0A 90 02 69 06 69 +0858:B0 E8 4C ED FD 00 00 00 +0860:00 00 ``` diff --git a/print_uint16 b/print_uint16 index a05da9f..8bdc163 100644 Binary files a/print_uint16 and b/print_uint16 differ diff --git a/print_uint16.s b/print_uint16.s index 7fc7af0..9be865b 100644 --- a/print_uint16.s +++ b/print_uint16.s @@ -17,20 +17,24 @@ SCRN2 = $F879 ; Also see: Applesoft LINPRT @ ED24 ; ====================================================================== PrintUint16 - STX _temp+0 - STA _temp+1 + STX _temp + PHA ; Optimized: STA _temp+1 - LDA #0 - STA _bcd+0 - STA _bcd+1 - STA _bcd+2 + LDX #0 + STX _bcd+0 + STX _bcd+1 + STX _bcd+2 Dec2BCD LDX #16 ; 16 bits SED ; "Double Dabble" _Dec2BCD ; https://en.wikipedia.org/wiki/Double_dabble - ASL _temp+0 - ROL _temp+1 + ASL _temp+0 ; abcd efgh | ijkl mnop | +; ROL _temp+1 ; C=a bcde fghi | jklm nop0 | +; ; Bit 7654_3210 | 7654_3210 | + PLA + ROL + PHA LDY #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3] _DoubleDabble ; Y=FD Y=FE Y=FF Y=00 @@ -39,9 +43,10 @@ _DoubleDabble ; Y=FD Y=FE Y=FF Y=00 STA _bcd-$FD,Y INY BNE _DoubleDabble - DEX BNE _Dec2BCD + + PLA ; keep stack CLD ; X=0 = output length DecWidth @@ -52,8 +57,7 @@ BCD2Chars DEY BNE BCD2Chars - TXA - CPX #0 ; Handle special case input = $0000 of no output + TXA ; Handle special case input = $0000 of no output BEQ _HaveLeadingDigit _PrintDone @@ -84,5 +88,5 @@ PutChar JMP COUT _bcd ds 4 ; 6 chars for printing dec -_temp db 0,0 +_temp db 0