Page 1 of 1

Split one value into two independent Sprite digits

Posted: Thu Sep 14, 2017 12:16 pm
by sdm
I would like to break one value (a variable in RAM) so that it can be displayed in two graphical numbers on the screen. The variable in RAM will have a value of up to 64 (40hex). Two sprites will be used for this purpose.

Showing values 0-9 is easy, but I do not know how to code so that it automatically split into two digits.

Code: Select all

	LDA #$F0	;this is the starting tile number in SPR CHR ROM (F0 = 0, F1 = 1 ...- F9 = 9)
	CLC
	ADC variable	;ram byte 00-40hex)
	STA DIGIT1_T	;one of two DIGIT SPRITE TILES  (DIGIT1_X,S,T,Y and DIGIT2_X,S,T,Y)

Re: Split one value into two independent Sprite digits

Posted: Thu Sep 14, 2017 12:31 pm
by lidnariq

Re: Split one value into two independent Sprite digits

Posted: Thu Sep 14, 2017 5:38 pm
by sdm
Okay, I got it.
Now collected object (gold) increases the value in the "GOLDnumber1", which is reset upon reaching a value of 10, while increasing the value in one GOLDnumber2. The most important works ok.

Code: Select all

GOLD_Status:

	LDA #$F0
	CLC
	ADC GOLD_Number1
	STA GOLD1_T

	LDA #$F0
	CLC
	ADC GOLD_Number2
	STA GOLD2_T

	LDA GOLD_Number1
	CMP #$0A
	BEQ GOLD_Number_Reset
	RTS

GOLD_Number_Reset:
	LDA #$00
	STA GOLD_Number1
	INC GOLD_Number2
	RTS