Posted Wed Feb 18, 2009 7:07 PM
Posted Wed Feb 18, 2009 8:33 PM
sed clc adc score sta score lda #0;contains carry adc score+1 sta score+1 lda #0;contains carry adc score+2 sta score+2 cld
sed clc adc score sta score txa adc score+1;also adds carry sta score+1 tya adc score+2;also adds carry sta score+2 cld
sed clc ldx #3; # of score variables loop: tya adc score-1,x sta score-1,x ldy #0 dex bne loop cld
Posted Wed Feb 18, 2009 8:55 PM
ldx #1 ; add 5 to the ones place ldy #0 ; hundreds/thousands place not used lda #0 ; ten & hundred thousands place not used sed clc adc score sta score txa adc score+1;also adds carry sta score+1 tya adc score+2;also adds carry sta score+2 cld
Edited by Primordial Ooze, Wed Feb 18, 2009 9:54 PM.
Posted Wed Feb 18, 2009 10:06 PM
ScoreSubroutine: sed;set decimal mode clc;clear carry status adc score;Add the accumulator to the score's low digits. ;NOTE: At this point, the carry flag will be set if the value ;wrapped at 99. Ex: 95 + 10 = 5 with carry set (=1). ;If no wrap occured, carry will still be clear (=0). sta score;Store the updated low digits. txa;Transfer the X register amount to A adc score+1;Add the accumulator to the score's middle digits. ;Also adds the carry, if set by the previous ADC. ;In other words, if carry was set, an additional 1 ;would be added here and the carry flag will be ;clear again (unless this amount also wraps). sta score+1;Store the updated middle digits tya;Transfer the Y register amount to A adc score+2;The same thing happens here for the high digits. ;Any carry set by the previous ADC will be sent ;to this amount leaving the carry status updated ;yet again. sta score+2;Store the last 2 digits cld;...clear decimal mode rts;...and return to the program line that called this routine.
Update_Low_Score_Digits: sed;set decimal mode clc;clear carry status adc score;Add accumulator to score's low digits w/carry. sta score;Store the updated low digits. ;NOTE: Here's where a triple-NOP comes into play. We need ;a seperate entrypoint to this subroutine for cases where the ;low digits are ignored (like adding 100, for example). But ;carry status and BCD mode need to have been setup. So, ;place the triple-NOP opcode here to skip over them... ;with A reset at zero so that only carry affects the score: lda #0;reset the accumulator... .byte $0C;...and skip over the next 2 bytes Update_Middle_Score_Digits: sed;set decimal mode clc;clear carry status adc score+1;Add accumulator to score's middle digits w/carry. sta score+1;Store the updated middle digits ;Here we do the same thing (in case the game needs to add 10,000... ;or 100,000 increments to a score (ignoring all the lower ones) ;Again, A is reset at zero so that only carry affects the score: lda #0;reset the accumulator... .byte $0C;...and skip over the next 2 bytes Update_High_Score_Digits: sed;set decimal mode clc;clear carry status adc score+1;Add accumulator to score's high digits w/carry. sta score+2;Store the last 2 digits ;With the score updated, clear BCD mode and exit via RTS: cld;...clear decimal mode rts;...and return to the program line that called this routine.
Edited by Nukey Shay, Wed Feb 18, 2009 10:27 PM.
Posted Wed Feb 18, 2009 10:29 PM
Posted Thu Feb 19, 2009 4:43 AM
Posted Thu Feb 19, 2009 7:43 AM
Primordial Ooze, on Wed Feb 18, 2009 9:33 PM, said:
Posted Tue Mar 10, 2009 9:04 PM
Posted Tue Mar 10, 2009 10:20 PM
;NOTE: Stack should be clear before entering. LDX #2;# of BCD variables to convert to vectors-1 ConvertDigits: ;first, convert the high nybble into a 2-byte vector... LDA #>Digit_Bitmaps;the page where bitmaps exist PHA;push it to the end-of-ram stack ( = MSB address) LDA Score,X;get the digit pair AND #$F0;keep the high nybble only LSR;divide by 2 (= LSB address) PHA;push the bitmap LSB ;Now convert the low nybble into a 2-byte vector... LDA #>Digit_Bitmaps;the page where bitmaps exist PHA;push it to the end-of-ram stack ( = MSB address) LDA Score,X;get the digit pair again AND #$0F;keep the low nybble only ASL;multiply by 8... ASL;... ASL;...(= LSB address) PHA;push the bitmap LSB DEX;reduce the index BPL ConvertDigits;...and loop for all 3 digit pairs
LDY #7;the number of scanlines to be drawn -1 Display2digits: STA WSYNC;new scanline LDA ($F8),Y;get the bitmap from vector+Y STA GRP0;store it to sprite 0 LDA ($FA),Y;get the bitmap from vector+Y STA GRP1;store it to sprite 1 DEY;count down the index BPL Display2digits;loop for all 8 scanlines
Edited by Nukey Shay, Tue Mar 10, 2009 10:23 PM.
Posted Tue Mar 10, 2009 11:21 PM
Nukey Shay, on Tue Mar 10, 2009 11:20 PM, said:
;NOTE: Stack should be clear before entering. LDX #2;# of BCD variables to convert to vectors-1 ConvertDigits: ;first, convert the high nybble into a 2-byte vector... LDA #>Digit_Bitmaps;the page where bitmaps exist PHA;push it to the end-of-ram stack ( = MSB address) LDA Score,X;get the digit pair AND #$F0;keep the high nybble only LSR;divide by 2 (= LSB address) PHA;push the bitmap LSB ;Now convert the low nybble into a 2-byte vector... LDA #>Digit_Bitmaps;the page where bitmaps exist PHA;push it to the end-of-ram stack ( = MSB address) LDA Score,X;get the digit pair again AND #$0F;keep the low nybble only ASL;multiply by 8... ASL;... ASL;...(= LSB address) PHA;push the bitmap LSB DEX;reduce the index BPL ConvertDigits;...and loop for all 3 digit pairs
LDY #7;the number of scanlines to be drawn -1 Display2digits: STA WSYNC;new scanline LDA ($F8),Y;get the bitmap from vector+Y STA GRP0;store it to sprite 0 LDA ($FA),Y;get the bitmap from vector+Y STA GRP1;store it to sprite 1 DEY;count down the index BPL Display2digits;loop for all 8 scanlines
Posted Tue Mar 10, 2009 11:53 PM
Posted Wed Mar 11, 2009 2:58 PM
Quote
Posted Wed Mar 11, 2009 4:50 PM
Nukey Shay, on Tue Mar 10, 2009 11:53 PM, said:
0 members, 1 guests, 0 anonymous users