Split one value into two independent Sprite digits

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
sdm
Posts: 410
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Split one value into two independent Sprite digits

Post 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)
sdm
Posts: 410
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Re: Split one value into two independent Sprite digits

Post 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
Post Reply