I am using big evil corporations framework for the sega genesis to create my game and got static text and sprites working fine. I am trying to draw arbitrary text such as the player's score, level counters etc. which change over time. I tried using the same functions for static text but they don't work as they require pointers to memory address where the static text is. Here is a link to my source code which also has the framework code. Any assistance in this matter would be greatly appreciated.
Sincerely,
You're going to need some ram to store the text in, there are a couple of ways you can do it.
1. Just store the score in ASCII.
dc.b "000000"
And have your update score method do the maths necessary to update the score. Each digit needs an add, compare, branch, subtract/carry to next digit.
2. Keep the score in a dc.l and then convert that to ASCII (either in some work ram or on the stack) using div instructions. Each digit requires a div instruction and they are slow.
A lot of developers use method 1, the code is faster and the score can be as many digits as you want (method 2 is limited to approximately 4 billion). For bonus points only store the score in screen memory (I don't know how practical that is on the genesis).
* I say ASCII but there is no reason that "0" has to be tile 48, you could make "0" be tile 0 for code simplicity.
I've replied to your similar post on SpritesMind but here is my hex word version for completion, hopefully it'll help others too.
Code:
ItoA_Hex_w:
; Converts a word to hex ASCII
; a0 --- In/Out: String address
; d0 (w) In: Number to convert
; 4 nybbles + 0x + terminator, working backwards
add.l #0x7, a0
; Zero terminate
move.b #0x0, -(a0)
move.w #0x0, d1 ; Char ptr
move.w #0x3, d2 ; 4 nybbles in a word
@NybbleLp:
move.b d0, d3 ; Byte to d3
andi.b #0x0F, d3 ; Bottom nybble
cmp.b #0x9, d3
ble @Numeric ; Branch if in numeric range
add.b #(ASCIIAlphaOffset-0xA), d3 ; In alpha range (A - F)
move.b d3, -(a0) ; Back to string
lsr.w #0x4, d0 ; Next nybble
dbra d2, @NybbleLp ; Loop
bra @End
@Numeric:
add.b #ASCIINumericOffset, d3 ; In numeric range (0 - 9)
move.b d3, -(a0) ; Back to string
lsr.w #0x4, d0 ; Next nybble
dbra d2, @NybbleLp ; Loop
@End:
;0X
move.b #'X', -(a0)
move.b #'0', -(a0)
rts
As mentioned above, for 10-base decimal you'll need to use divs instead of offsets, and I like the idea of storing '000000' and nudging the count up/down better than all of this anyway. I'll be using that myself