base:making_a_counter
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:making_a_counter [2015-04-17 04:32] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | A quite nifty example of how to make an increasing decimal counter with a flexible amount of digits. | ||
+ | It's possible to create a counter with up to 255 digits. | ||
+ | Useful for counting scores in games, for example. | ||
+ | |||
+ | < | ||
+ | ; Counter code | ||
+ | ; [c]2007 Scout/ | ||
+ | |||
+ | numdigits = 6 | ||
+ | |||
+ | |||
+ | *=$c000 | ||
+ | |||
+ | ldx #0 | ||
+ | txa ; A=X=0 | ||
+ | - | ||
+ | sta tellertabel, | ||
+ | inx | ||
+ | cpx # | ||
+ | bne - | ||
+ | |||
+ | loop | ||
+ | |||
+ | ldx #0 | ||
+ | - | ||
+ | lda tellertabel+1, | ||
+ | clc | ||
+ | adc #$30 ; add 48(decimal) -> in petscii, 48=0, 49=1 etc | ||
+ | sta $0400, | ||
+ | inx | ||
+ | cpx #numdigits | ||
+ | bne - | ||
+ | |||
+ | jsr teller | ||
+ | |||
+ | jmp loop ; do the loop | ||
+ | |||
+ | ; | ||
+ | |||
+ | teller | ||
+ | ldx # | ||
+ | - | ||
+ | lda tellertabel, | ||
+ | cmp #9 ; is the current digit 9? | ||
+ | beq + ; yes, jump to the + branch | ||
+ | inc tellertabel, | ||
+ | rts ; back to the mainroutine | ||
+ | + | ||
+ | lda #0 ; put current digit to 0 | ||
+ | sta tellertabel, | ||
+ | dex ; go 1 back in the table | ||
+ | bne - ; and do the rest of the remaining digits | ||
+ | rts ; back to the main routine | ||
+ | ; | ||
+ | |||
+ | .align 256 | ||
+ | tellertabel | ||
+ | </ |
base/making_a_counter.txt · Last modified: 2015-04-17 04:32 by 127.0.0.1