User Tools

Site Tools


base:scoring_points
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Last revision
base:scoring_points [2015-10-07 22:10] – Moved page to correct namespace ftc
Line 1: Line 1:
 +====== Scoring points ======
 +by Achim
 +
 +There are three ways to code scoring.
 +
 +===== 1) Decimal mode =====
 +
 +This one can be found in many games. You only have to declare
 +a couple of variables for the player's score and switch to decimal
 +mode.
 +
 +Example for six digits:
 +
 +<code>
 +sed //set decimal mode
 +clc
 +lda #$50 //50 points scored
 +adc score1 //ones and tens
 +sta score1
 +lda score2 //hundreds and thousands
 +adc #00
 +sta score2
 +lda score3 //ten-thousands and hundred-thousands
 +adc #00
 +sta score
 +cld //clear decimal mode
 +</code>
 +
 +The score can now be printed on screen:
 +
 +<code>
 +lda score3
 +and #$f0         //hundred-thousands
 +lsr
 +lsr
 +lsr
 +lsr
 +ora #$30 // -->ascii
 +sta screenposition //print on screen
 +lda score3
 +and #$0f //ten-thousands
 +ora #$30 // -->ascii
 +sta screenposition+1 //print on next screen position
 +
 +lda score2 //same procedure for all digits
 +...
 +</code>
 +
 +Switching to decimal mode can cause problems under certain conditions:
 +Let's say an irq kicks in to write sprite registers while decimal mode is set.
 +This would mess up all registers, of course.
 +This might happen with a sprite mulitplexer, because these irqs are
 +unpredictable. Idea would be to start these irqs with
 +CLD. Another would be to disable irqs while calculating.
 +
 +
 +===== 2) Hexadecimal mode =====
 +
 +Not much to explain. Declare your variables for the score. Use a standard hexadecimal addition
 +and print the result on screen (preferably with a routine like [[base:32_bit_hexadecimal_to_decimal_conversion|this]], which converts hexadecimal to decimal, then ascii).
 +
 +
 +===== 3) ASCII =====
 +
 +This one's most commonly used in games. Each ascii code on screen is treated like a digit. 
 +An addition would look like this:
 +
 +<code>
 + ldx #$05
 + lda #$00
 +!: sta carry,x //clear carry table
 + dex
 + bpl !-
 +
 + ldx #$05 //6 digits
 +!: lda figure1,          //current score, usually located in screen memory
 + clc
 + adc figure2,          //add points
 + adc carry,x
 + and #$0f //check bits0-3
 + cmp #$0a //if >=10
 + bcc nocarry
 + inc carry-1,x //then set carry for next digit...
 + sec
 + sbc #$0a //... -10 for correct ascii
 +nocarry: ora #$30 //-->ascii
 + sta sum,x
 + dex
 + bpl !-
 + rts
 +
 +figure1: .byte $31, $32, $30, $33, $37, $39 //   120379 (example)
 +figure2: .byte $32, $32, $30, $39, $32, $31 //  +220921
 +carry: .byte $00, $00, $00, $00, $00, $00 //tmp for carry
 +sum: .byte $00, $00, $00, $00, $00, $00
 +</code>
 +
 +
  
base/scoring_points.txt · Last modified: 2020-01-11 12:23 by maze