Jump to content



1

Keeping Score Routine


7 replies to this topic

#1 tschak909 OFFLINE  

tschak909

    Chopper Commander

  • 161 posts
  • Location:USA

Posted Tue Jun 13, 2006 11:05 PM

How does everybody here keep and display score for a nice 8, 9 or 10 digit display? I am busting my butt trying to do the math on 32 bit numbers, and i am still unsure how to convert that to a displayable form, or if there is a more efficient way to do so.

-Thom

#2 Heaven/TQA OFFLINE  

Heaven/TQA

    Quadrunner

  • 8,111 posts
  • Location:Baden-Württemberg, Germany

Posted Wed Jun 14, 2006 2:47 AM

use BCD numbers instead.

later i'll post the routine from venus & co.

#3 Wrathchild OFFLINE  

Wrathchild

    Stargunner

  • 1,373 posts
  • Location:Reading, UK.

Posted Wed Jun 14, 2006 2:48 AM

Why not use the 6502's binary coded decimal mode to do the math for you?
By setting the flag (SED,CLD mnemonics) then any math performed will work in decimal mode. In this each nibble of a byte has the value 0-9 and, for example, adding 0x04 and 0x09 will give 0x13.
So, when it come to displaying the score, you pick half of the byte and then add that the character '0' (zero) and display that, e.g.
LDA score
LSR A
LSR A
LSR A
LSR A
CLC
ADC #'0'
JSR DisplayA
LDA score
AND #$0F
CLC
ADC #'0'
JSR DisplayA
Repeat for however many bytes of you need, e.g. 8 digits = 4 bytes

Routines to turn, for example, a 'word' to text typically work by trying to subtract the highest divisor, e.g. 10000 to count how many there are and then displaying that as a digit, then step down to 1000s and so on.

In both cases you can be fancy and add the ability to strip leading zeros.

Plenty of example code should exist out there for this, maybe check in the 2600 programming threads too.

Mark

#4 Rybags ONLINE  

Rybags

    Quadrunner

  • 10,323 posts
  • Location:Australia

Posted Wed Jun 14, 2006 4:45 AM

Go one better. A countup score display like on Slime.

Wouldn't be too much effort to implemtent, but maybe not best suited to a Space Invaders type game.

#5 tschak909 OFFLINE  

tschak909

    Chopper Commander

  • 161 posts
  • Location:USA

Posted Wed Jun 14, 2006 10:37 AM

awesome.. I've been reading up on BCD and yeah, that makes much more sense. I will mess around with some stuff in a separate file to get the hang of it. But yeah, this helps a ton.

This is so much easier, thanks.
-Thom

#6 Heaven/TQA OFFLINE  

Heaven/TQA

    Quadrunner

  • 8,111 posts
  • Location:Baden-Württemberg, Germany

Posted Wed Jun 14, 2006 11:47 AM

here is the routine from Venus, modified for usage on Atari

-----  Write two digits BCD

WriteBCD
		pha		;1st digit
		lsr @
		lsr @
		lsr @
		lsr @
		sty	 temp	;save y-reg
		jsr	 WriteNumber
		pla		;2nd digit
		and #$0f
		ldy	 temp		
		iny		;next position
	   ;

; Atari specific - write directly into status bar
WriteNumber
	clc
	adc #16		;offset for font
		tax 
		lda	 #$33
		sta	 $01
	txa

_wrlp
		sta	 status_bar,y
		iny
		lda	 #$35
	   sta	 $01
		rts

status_bar dta  d"  00000 C:00 T:00   2   "
status_bar2 dta d"						"
status1	dta d"	   PRESS  fire	 "
status2 dta d"		game",d" OVER	 "*
status3 dta d"	   YOU CRASHED	 "
status4 dta d"	GET all ",d"CAPSULES  "*
status5 dta d"	  NOW fly",d" BACK	 "*
status_tabl dta <status_bar2,<status1,<status2,<status3,<status4,<status5
status_tabh dta >status_bar2,>status1,>status2,>status3,>status4,>status5

dlist 	dta $50,$a0,$40,$46,a(status_bar),$c0
dlist2	dta $74,a(vram)
	dta $74,a(vram+1*256)
	dta $74,a(vram+2*256)
	dta $74,a(vram+3*256)
	dta $74,a(vram+4*256)
	dta $74,a(vram+5*256)
	dta $74,a(vram+6*256)
	dta $74,a(vram+7*256)
	dta $74,a(vram+8*256)
	dta $74,a(vram+9*256)
	dta $74,a(vram+10*256)
	dta $74,a(vram+11*256)
	dta $74,a(vram+12*256)
	dta $74,a(vram+13*256)
	dta $74,a(vram+14*256)
	dta $74,a(vram+15*256)
	dta $74,a(vram+16*256)
	dta $74,a(vram+17*256)
	dta $74,a(vram+18*256)
	dta $74,a(vram+19*256)
	dta $74,a(vram+20*256)
	dta $74,a(vram+21*256)
	dta $74,a(vram+22*256)
	dta $54,a(vram+23*256)
	dta $c0
dlist3	dta $46,a(status_bar2)
	dta $41,a(dlist)


#7 tschak909 OFFLINE  

tschak909

    Chopper Commander

  • 161 posts
  • Location:USA

Posted Wed Jun 14, 2006 11:52 AM

Thanks! :-D

#8 Heaven/TQA OFFLINE  

Heaven/TQA

    Quadrunner

  • 8,111 posts
  • Location:Baden-Württemberg, Germany

Posted Wed Jun 14, 2006 11:53 AM

and here the add-routine
;-----  Add A to a BCD number
AddBCD
		sed
		clc
_bcdc
		adc	 $00,x
		sta	 $00,x
		lda	 #$00
		inx
		bcs	 _bcdc
		cld
		rts

for example here we add 10 points to the score, A holds the value and X-reg points to the correct score var.

sco10	equ $0e					; score
sco1000 equ $0f
...	   
ldx	 #sco10
		lda	 #$10
		jsr	 AddBCD

once you get used to it, its really straight forward... i needed 20 years to have a "real" handy score routine...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users