| |
Trifox Account closed
Registered: Mar 2006 Posts: 108 |
fast number output ?
hi, i am using this function to print a score in a game :
clc
lda punkte+1
adc #1
sta punkte+1
lda punkte
adc #0
sta punkte
ldx #24
ldy #34
clc
jsr $fff0 ; set cursor position
ldx punkte+1 ; dezimalzahl ausgeben...
lda punkte
jsr $bdcd
the problem i now have is that it takes up half of a raster period, arent there faster ways to print a decimal number on screen ?!?!?
|
|
| |
tlr
Registered: Sep 2003 Posts: 1790 |
The fastest way is probably to keep the counter as separate digits in the first place. A neat way to do this is to use the decimal-mode of the cpu (SED/CLD). It will treat each nybble of the byte as a separate digit, i.e binary coded decimal (BCD).
You could also store each digit as a separate byte. |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
rather 2 digits / byte |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
or display the score in hex :) |
| |
cadaver
Registered: Feb 2002 Posts: 1160 |
It's also not terribly slow to convert a value to BCD for displaying, this way doing arithmetic is less restricted.
The example below converts a 24bit value (temp1-temp3 in low to high order) to 32bit BCD representation (temp4-temp7)
convert24bits: ldx #24
sed
lda #$00
sta temp4
sta temp5
sta temp6
sta temp7
convertloop: asl temp1 ;Rotate binary number to left
rol temp2 ;and add decimal number to
rol temp3 ;itself to convert
lda temp4
adc temp4
sta temp4
lda temp5
adc temp5
sta temp5
lda temp6
adc temp6
sta temp6
lda temp7
adc temp7
sta temp7
dex
bne convertloop
cld
rts |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
must be a pinball game for 24 bit high scores :D |
| |
cadaver
Registered: Feb 2002 Posts: 1160 |
Actually I'd think 24bit is still quite little for serious hardcore SEU or something. :) That piece of code was from MW4 and there player is not expected to score above 16 million (the display is 7 digits only also), otherwise I'd have used 32bit just to be certain.. |
| |
TNT Account closed
Registered: Oct 2004 Posts: 189 |
Quoting cadaverIt's also not terribly slow to convert a value to BCD for displaying, this way doing arithmetic is less restricted.
You rarely need mul/div with score, so keeping it in BCD from the beginning is easier. Dividing BCD is pain in the ass, I ended up doing repeated sub instead for hit accuracy as it was max. 100 loops and done when there was no hurry. Six-digit counters :) |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
A divide-by-10 is only a few opcodes, why have the trouble with BCD then? |
| |
hannenz Account closed
Registered: Nov 2002 Posts: 24 |
Quote: hi, i am using this function to print a score in a game :
clc
lda punkte+1
adc #1
sta punkte+1
lda punkte
adc #0
sta punkte
ldx #24
ldy #34
clc
jsr $fff0 ; set cursor position
ldx punkte+1 ; dezimalzahl ausgeben...
lda punkte
jsr $bdcd
the problem i now have is that it takes up half of a raster period, arent there faster ways to print a decimal number on screen ?!?!?
@trifox: btw, you should first add the low bytes (with carry clear) and then add the hi-bytes to have correct 16-bit-addition...
to output the number, have a look at my source codes at
http://people.freenet.de/hannenz/sources.htm
don't use that basic $bdcd, it is faaaaar too slow!
|