Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
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: 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.
2006-04-10 12:33
Oswald

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

Registered: Apr 2002
Posts: 5094
must be a pinball game for 24 bit high scores :D
2006-04-10 13:31
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..
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
Urban Space Cowboy
E$G/HF ⭐ 7
Guests online: 134
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

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