This commit is contained in:
Michaelangel007 2016-02-18 12:48:00 -08:00
parent 45bc1fa32d
commit 2400ba50e0

View File

@ -1,9 +1,10 @@
; Version 12
; ca65 ; ca65
.feature c_comments .feature c_comments
/* /* Version 13
printm - a printf replacement for 6502
Michael Pohroeski
Problem: Problem:
We want to print this: We want to print this:
@ -61,8 +62,6 @@ ENABLE_PTR = 1 ; requires ENABLE_HEX
ENABLE_STR = 1 ENABLE_STR = 1
.feature labels_without_colons .feature labels_without_colons
.feature leading_dot_in_identifiers .feature leading_dot_in_identifiers
; 65C02 ; 65C02
@ -166,18 +165,23 @@ _HgrAddr
JSR ReverseByte JSR ReverseByte
STA DATA+12 STA DATA+12
.if ENABLE_BIN || ENABLE_DEC || ENABLE_HEX
LDY #0 LDY #0
JSR VTABY JSR VTABY
LDX #<DATA ; Low Byte of Address LDX #<DATA ; Low Byte of Address
LDY #>DATA ; High Byte of Address LDY #>DATA ; High Byte of Address
JSR PrintM JSR PrintM
.endif
.if ENABLE_BYTE
LDY #2 LDY #2
JSR VTABY JSR VTABY
LDX #<DATA2 LDX #<DATA2
LDY #>DATA2 LDY #>DATA2
JSR PrintM JSR PrintM
.endif ; ENABLE_BYTE
.if ENABLE_STR
LDY #4 LDY #4
JSR VTABY JSR VTABY
LDX #<DATA3 LDX #<DATA3
@ -189,6 +193,7 @@ _HgrAddr
LDX #<DATA4 LDX #<DATA4
LDY #>DATA4 LDY #>DATA4
JSR PrintM JSR PrintM
.endif ; ENABLE_STR
LDA #8 LDA #8
JMP TABV JMP TABV
@ -322,7 +327,7 @@ DATA4
ds 256 - <* ds 256 - <*
; Self-Modifying variable aliases ; self-modifying variable aliases
_pScreen = PutChar +1 _pScreen = PutChar +1
_pFormat = GetFormat +1 _pFormat = GetFormat +1
@ -421,7 +426,7 @@ _PrintPtr
JSR NxtArgToTemp JSR NxtArgToTemp
; JSR NxtArgYX ; JSR NxtArgYX
; 13 bytes - zero page version ; 13 bytes: zero page version
; STX _temp+0 ; zero-page for (ZP),Y ; STX _temp+0 ; zero-page for (ZP),Y
; STY _temp+1 ; STY _temp+1
LDY #$0 LDY #$0
@ -431,7 +436,7 @@ _PrintPtr
LDA (_temp),Y LDA (_temp),Y
TAY TAY
; 20 bytes - self modifying code version if zero-page not available ; 20 bytes: self-modifying code version if zero-page not available
; STX PtrVal+1 ; STX PtrVal+1
; STY PtrVal+2 ; STY PtrVal+2
; LDY #0 ; 0: A->X ; LDY #0 ; 0: A->X
@ -463,6 +468,7 @@ GetFormat
LDA $C0DE ; _pFormat NOTE: self-modifying! LDA $C0DE ; _pFormat NOTE: self-modifying!
BEQ _Done BEQ _Done
BMI Print ; neg = literal BMI Print ; neg = literal
; NOTE: If all features are turned off, will get a ca65 Range Error
LDX #NumMeta-1 ; pos = meta LDX #NumMeta-1 ; pos = meta
FindMeta FindMeta
CMP MetaChar,X CMP MetaChar,X
@ -552,7 +558,7 @@ _BCD2Char
BPL _BCD2Char BPL _BCD2Char
DecWidth DecWidth
LDX #0 ; _nDecDigits NOTE: self modifying! LDX #0 ; _nDecDigits NOTE: self-modifying!
JMP PrintReverseBCD JMP PrintReverseBCD
.endif ; ENABLE_DEC .endif ; ENABLE_DEC
@ -676,7 +682,7 @@ _PrintCharA
; ====================================================================== ; ======================================================================
PutChar PutChar
STA $400 ; NOTE: self-modifying! STA $C0DE ; _pScreen NOTE: self-modifying!
INC PutChar+1 ; inc lo INC PutChar+1 ; inc lo
RTS RTS