Page 1 of 1

Tile# to hex# conversion (text output)

Posted: Sat Jul 05, 2014 4:55 am
by mikaelmoizt
Hi again!

Here I have a snippet of my routine for "converting" a tile into understandable hex chars and numbers.
One byte of input, in this example lets say a value of $C3, will be split up into two destination bytes with values $0C and $03.

This routine works without any customization in for example Super Mario Bros where the top row of right pattern table is in 0-F order.
So a output of these two bytes onto screen will now give the text "C3".

Code: Select all

LDA $input
ROR
ROR
ROR
ROR
AND #$0F
STA $firstbyte_output
 
LDA $input
ROL
ROR 
and #$0f 'here be black magic ;)
STA $secondbyte_output
In case the 0-F tiles where put somewhere else, lets say starting at $A0, but where in correct order, it would be simple just adding $A0 to both destinations.

So, now for the question I have.

Let's say 0-9 where in correct order - lets say starting at $00 - but letters A-F where put somewhere else - lets say $40. That would mean a great deal of comparing values (in my mind atleast).
Any ideas? I already cheated a little to make it work by changing the pattern table. But that's not how I want to do now :wink:

Edit: Saw something duplictaed in my code..
Edit 2: Added a picture to clarify ;)

Re: Tile# to hex# conversion (text output)

Posted: Sat Jul 05, 2014 6:14 am
by thefox
When you calculate "secondbyte_output", you don't need ROL and ROR, just ANDing with $F is enough.

As for your question, the easiest way (in my mind) to do it is to use a lookup table:

Code: Select all

ldx #8 ; Or whatever
lda lut, x
; ...
lut: .byte 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, $40, $41, $42, $43, $44, $45

Re: Tile# to hex# conversion (text output)

Posted: Sat Jul 05, 2014 7:18 am
by mikaelmoizt
thefox wrote:When you calculate "secondbyte_output", you don't need ROL and ROR, just ANDing with $F is enough.

As for your question, the easiest way (in my mind) to do it is to use a lookup table
Oh. Ofcourse.

Thank you! That really helped me a lot. It's funny how the most simple things seems to be the hardest to figure out sometimes.

Code: Select all

TAX
LDA $table,x '0,1,2,3,4,5,6,7,8,9,40,41 etc
STA outputbyte1 

A small change and addition with this lookup routine run twice in my snippet did the trick. Again, thanks 8-)
*back to hacking*