+Cafeman Posted July 5, 2002 Share Posted July 5, 2002 ; ****************** 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? Quote Link to comment Share on other sites More sharing options...
Sheddy Posted July 5, 2002 Share Posted July 5, 2002 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. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted July 5, 2002 Share Posted July 5, 2002 BTW since you are working in decimal mode, the carry flag will be set when #$99 (not #$FF) rolls over to #$00. Are the scores that are being added ($pointslo/hi) in decimal format? i.e. in decimal mode, #$99 = 99. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted July 5, 2002 Share Posted July 5, 2002 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. Quote Link to comment Share on other sites More sharing options...
+Cafeman Posted July 6, 2002 Author Share Posted July 6, 2002 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. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted July 6, 2002 Share Posted July 6, 2002 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. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 6, 2002 Share Posted July 6, 2002 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! Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted July 7, 2002 Share Posted July 7, 2002 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. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted July 7, 2002 Share Posted July 7, 2002 BCC 03 ;(02 if ScoreHi2 is in zero page)INC $ScoreHi2 CLD RTS That doesn't work, because only ADC and SBC work in BCD mode. With ADC, after $09 follows $10, but with INC it's $0A. Quote Link to comment Share on other sites More sharing options...
KAZ Posted July 7, 2002 Share Posted July 7, 2002 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. 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.