Jump to content
IGNORED

6 digit scoring help needed


Cafeman

Recommended Posts

; ****************** A D D P O I N T S *********
;NOTE : score is high byte first
;treat score like a variable
;routine can also add values >255
;put point value in POINTHI/POINTLO

AddPointsRoutine

SED

CLC

LDA ScoreLo ;(SCOREHI+1)         

ADC PointsLo

STA ScoreLo

LDA ScoreHi

ADC PointsHi

STA ScoreHi

lda #$00

adc ScoreHi2;doesn't work -- fix! it rolls at 9,999! 4/24

CLD

rts

 

There's my code. But the adc SchoreHi2 doesn't work, as though the carry isn't still set. You see I'm adding to PointsLo, then adding with carry to PointsHi. That works. But then I try to add 0 to ScoreHi2 (digits 5 and 6 in the score), hoping that the AddWithCarry will in fact add 1 to it when the prior add crosses FF to 00. It doesn't work!

 

Any ideas?

Link to comment
Share on other sites

Not used BCD much, but, apart from the obvious that you are not storing Scorehi2 in this example, it should work. Where is Scorehi2 in memory - Maybe it's getting overwritten by something else? Just try moving it somewhere else, see what happens.

 

:)

Link to comment
Share on other sites

Duuh! My bad...you are not actually saving ScoreHi2 before the CLD is called. Try this...

 

SED

CLC

LDA ScoreLo ;(SCOREHI+1)

ADC PointsLo ;Add lower 2 digits of points

STA ScoreLo

LDA ScoreHi

ADC PointsHi ;Add upper 2 digits of points + carry from previous

STA ScoreHi

LDA ScoreHi2

ADC #$00 ;this will contain only the carry from the above, if any

STA ScoreHi2

CLD

RTS

 

BTW where is ScoreHi2 located? ScoreHi-1? A short routine can be made to contain the addition and display of the score in one go by using the X register as an offset.

Link to comment
Share on other sites

LOL.

 

BTW another solution is to forgo variables for the score altogether and add digits directly to the numbers in screen memory. You can use AND to test the bits for a carry and to strip invalid values away. In this manner you would not use decimal mode.

Link to comment
Share on other sites

BTW another solution is to forgo variables for the score altogether and add digits directly to the numbers in screen memory.  You can use AND to test the bits for a carry and to strip invalid values away.  In this manner you would not use decimal mode.

Yup! If you need an example, look into my disassembly of River Raid at The Dig!

Link to comment
Share on other sites

Since #points is limited to 4 digits, you could also replace the last 5 lines of that routine with this slightly shorter version:

 

Previous:

LDA ScoreHi2

ADC #$00 ;this will contain only the carry from the above, if any

STA ScoreHi2

CLD

RTS

 

Alternate:

BCC 03 ;(02 if ScoreHi2 is in zero page)

INC $ScoreHi2

CLD

RTS

 

This alternate method will also fit into the same amount of space originally used.

Link to comment
Share on other sites

OH MYYYY...  

 

I cannot believe that I stared at that for so long and didn't realize the obvious -- I wasn't storing the accumulator back into HiScore2. DUHHHHHHHHHHHHHHHHHHHHHH....  

 

I may just delete this thread to cover my tracks.

 

 :ponder:

 

Yes, for shame, how could you miss such a thing! I know the accumulator is the same thing as the A register at least :) 0100 is a nibble :)

have a grand $E7 .BYTE day!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...