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' | ||
+ | mode. | ||
+ | |||
+ | Example for six digits: | ||
+ | |||
+ | < | ||
+ | sed //set decimal mode | ||
+ | clc | ||
+ | lda #$50 //50 points scored | ||
+ | adc score1 // | ||
+ | sta score1 | ||
+ | lda score2 // | ||
+ | adc #00 | ||
+ | sta score2 | ||
+ | lda score3 // | ||
+ | adc #00 | ||
+ | sta score | ||
+ | cld // | ||
+ | </ | ||
+ | |||
+ | The score can now be printed on screen: | ||
+ | |||
+ | < | ||
+ | lda score3 | ||
+ | and #$f0 // | ||
+ | lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | lsr | ||
+ | ora #$30 // -->ascii | ||
+ | sta screenposition // | ||
+ | lda score3 | ||
+ | and # | ||
+ | ora #$30 // -->ascii | ||
+ | sta screenposition+1 // | ||
+ | |||
+ | lda score2 // | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | 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, | ||
+ | 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: | ||
+ | |||
+ | |||
+ | ===== 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: | ||
+ | |||
+ | < | ||
+ | ldx #$05 | ||
+ | lda #$00 | ||
+ | !: sta carry, | ||
+ | dex | ||
+ | bpl !- | ||
+ | |||
+ | ldx #$05 //6 digits | ||
+ | !: lda figure1, | ||
+ | clc | ||
+ | adc figure2, | ||
+ | adc carry,x | ||
+ | and # | ||
+ | cmp #$0a //if >=10 | ||
+ | bcc nocarry | ||
+ | inc carry-1, | ||
+ | sec | ||
+ | sbc #$0a //... -10 for correct ascii | ||
+ | nocarry: | ||
+ | sta sum,x | ||
+ | dex | ||
+ | bpl !- | ||
+ | rts | ||
+ | |||
+ | figure1: | ||
+ | figure2: | ||
+ | carry: | ||
+ | sum: | ||
+ | </ | ||
+ | |||
+ | |||
base/scoring_points.txt · Last modified: 2020-01-11 12:23 by maze