mirror of
https://github.com/Michaelangel007/apple2_print_uint16.git
synced 2024-06-10 05:29:34 +00:00
Add stack page version 1
This commit is contained in:
parent
ecc4942ece
commit
18b00381cd
10
Makefile
10
Makefile
|
@ -1,7 +1,7 @@
|
|||
TARGETS=print_uint16 print_uint16_zp
|
||||
TARGETS=print_uint16 print_uint16_zp print_uint16_sp
|
||||
all: $(TARGETS)
|
||||
.phony: dump
|
||||
|
||||
.PHONY: clean dump
|
||||
clean:
|
||||
rm $(TARGETS)
|
||||
|
||||
|
@ -11,7 +11,11 @@ print_uint16: print_uint16.s
|
|||
print_uint16_zp: print_uint16_zp.s
|
||||
merlin32 print_uint16_zp.s
|
||||
|
||||
dump: print_uint16 print_uint16_zp
|
||||
print_uint16_sp: print_uint16_sp.s
|
||||
merlin32 print_uint16_sp.s
|
||||
|
||||
dump: $(TARGETS)
|
||||
hexdump8 print_uint16 800
|
||||
hexdump8 print_uint16_zp 900
|
||||
hexdump8 print_uint16_sp 900
|
||||
|
||||
|
|
19
README.md
19
README.md
|
@ -7,6 +7,7 @@ Features:
|
|||
* Highly optimized for space
|
||||
* No zero-page usage [version](print_uint16.s) 90 ($5A) bytes
|
||||
* With zero-page usage [version](print_uint16_zp.s) 78 ($4E) bytes
|
||||
* With stack var usage [version](print_uint16_sp.s) 92 ($5C) bytes
|
||||
* Only 2 ROM entry points: COUT, SCRN2
|
||||
* Includes 7 byte demo
|
||||
|
||||
|
@ -48,6 +49,24 @@ With-Zero-Page version:
|
|||
0950:B0 E8 4C ED FD
|
||||
```
|
||||
|
||||
With-Stack-Page version:
|
||||
|
||||
```asm
|
||||
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
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
[WTFPL](http://www.wtfpl.net/)
|
||||
|
|
BIN
print_uint16_sp
Normal file
BIN
print_uint16_sp
Normal file
Binary file not shown.
100
print_uint16_sp.s
Normal file
100
print_uint16_sp.s
Normal file
|
@ -0,0 +1,100 @@
|
|||
; 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
|
||||
|
||||
ORG $A00 ; Intentionally different from sans-zero-page & with-zero-page
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user