Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user tubesockor ! (Registered 2024-05-12) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > fast number output ?
2006-04-10 12:19
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 ?!?!?
2006-04-10 12:31
tlr

Registered: Sep 2003
Posts: 1723
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.
2006-04-10 12:33
Oswald

Registered: Apr 2002
Posts: 5025
rather 2 digits / byte
2006-04-10 12:45
Cruzer

Registered: Dec 2001
Posts: 1048
or display the score in hex :)
2006-04-10 13:00
cadaver

Registered: Feb 2002
Posts: 1153
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
2006-04-10 13:23
Oswald

Registered: Apr 2002
Posts: 5025
must be a pinball game for 24 bit high scores :D
2006-04-10 13:31
cadaver

Registered: Feb 2002
Posts: 1153
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..
2006-04-10 15:54
TNT
Account closed

Registered: Oct 2004
Posts: 189
Quoting cadaver
It'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 :)
2006-04-11 10:06
Graham
Account closed

Registered: Dec 2002
Posts: 990
A divide-by-10 is only a few opcodes, why have the trouble with BCD then?
2006-04-11 16:21
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!
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Total Chaos
hedning/G★P
Brataccas/HF
Fred/Channel 4
d4ng3r
DjS/Silicon Ltd
iAN CooG/HVSC
grasstust/Hoaxers
Jammer
A3/AFL
Guests online: 125
Top Demos
1 13:37  (9.9)
2 Next Level  (9.8)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 No Bounds  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Multiverse 100%  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Layers  (9.5)
5 Copper Booze  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Nostalgia  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Diskmag Editors
1 Jazzcat  (9.4)
2 Magic  (9.4)
3 hedning  (9.2)
4 Elwix  (9.1)
5 A Life in Hell  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.037 sec.