How to display DEC numbers ???
Moderator: BigEvilCorporation
-
- Very interested
- Posts: 2440
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
How to display DEC numbers ???
GBMD is practically finished, but there's one thing missing: routine that can display decimal numbers. I have almost no idea how to display them, one thought I have is to separate 1, 10, 100, 1000.... and display them somehow. Is there any better methods ??? I do NOT want to copy anyone else code.
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
I myself just display the hexa héhé it is easier funnier and super faster if it applies to your game concept though
I have two tricks: the first one is while counting
-> i do one variable per digit : digit1 digit10 digit100 digit1000
then i do digit1++; if(digit1>9){digit1=0;digit10++;if(digit10>9){ ....
This have the advantage to be not so time consuming and it is super fast to display the number later
The second trick i use also, is to store (into a table of 4bytes per entry named table[256*4] for exemple) the strings (its just the idea, i did not deal with negative) from "+000" to "-127" (256 entries total)
Imagine that my value is (8bit) named blob
to get the strings to display, i just do:
table[blob*4+0]
table[blob*4+1]
table[blob*4+2]
table[blob*4+3]
Well, this method limits you to 8bit values... else it start to be a bit ROM space consuming
There are certainely better methods
I have two tricks: the first one is while counting
-> i do one variable per digit : digit1 digit10 digit100 digit1000
then i do digit1++; if(digit1>9){digit1=0;digit10++;if(digit10>9){ ....
This have the advantage to be not so time consuming and it is super fast to display the number later
The second trick i use also, is to store (into a table of 4bytes per entry named table[256*4] for exemple) the strings (its just the idea, i did not deal with negative) from "+000" to "-127" (256 entries total)
Imagine that my value is (8bit) named blob
to get the strings to display, i just do:
table[blob*4+0]
table[blob*4+1]
table[blob*4+2]
table[blob*4+3]
Well, this method limits you to 8bit values... else it start to be a bit ROM space consuming
There are certainely better methods
in 68k assembly, you can use the binary coded decimal arithmetic for your score, to my memory, all numbers are represented by 4 bits. check the operand ABCD & SBCD. So for example you have
a variable MyNumber=0x09
if i do MyNumber++ in packed decimal (abcd) the value become (0x10) instead of (0xA) in normal
and after it's straight forward to display
a variable MyNumber=0x09
if i do MyNumber++ in packed decimal (abcd) the value become (0x10) instead of (0xA) in normal
and after it's straight forward to display
-
- Very interested
- Posts: 2440
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
I didn't understand your C example (I don't know C) and I'm not going to use BCD. My hex number print routines are ok. I forgot to mention that I do stuff in ASM.
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
my 2 cents,
if you know how much number you want to draw (for scoring for example)
for (i=0; i< scoresize;i++)
{
number = score%10;
score/=10;
draw number at (scoresize-i);
}
but i'm pretty sure it is easy to optimize this on asm;
do draw it, look at the ascii table to help you
number 3 is 51 so, according the way you load your charset, it's easy to find the link between the number you want to draw and the index of the tile to use
(don't know if I'm clear but it's the way I use)
if you know how much number you want to draw (for scoring for example)
for (i=0; i< scoresize;i++)
{
number = score%10;
score/=10;
draw number at (scoresize-i);
}
but i'm pretty sure it is easy to optimize this on asm;
do draw it, look at the ascii table to help you
number 3 is 51 so, according the way you load your charset, it's easy to find the link between the number you want to draw and the index of the tile to use
(don't know if I'm clear but it's the way I use)
-
- Very interested
- Posts: 2440
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
one thing: I DO NOT UNDERSTAND C (only I/O stuff, kind of). Maybe after 2 years when I graduate 12th grade and go to IT college. However, if write it in QB, MD style I would understand it i.e :
I would like to know different other METHODs
Code: Select all
'print HEX number (byte size) using ASCII charset
'this does not resemble my ASM routine in any way
Num1% = (Number% AND &hF) + 48 'isolate first nibble from the Number%
Num2% = ((Number% AND &hF0) \ 16) + 48 'isolate next nibble
IF Num1% > 10 then Num1% = Num1% + 7 'below 10 are numbers and
IF Num2% > 10 then Num2% = Num2% + 7 'above are letters
poke CtrlPort&, TextPos& 'TextPos& is location in VRAM
poke DataPort&, Num1%
poke DataPort&, Num2%
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
-
- Very interested
- Posts: 159
- Joined: Sat Feb 24, 2007 11:35 pm
- Location: San Antonio, TX
Here's one I've been using:
Code: Select all
;-----------------------------------------------------------------------
; Convert a number from binary to ASCII decimal with leading zero suppression
;
; ENTRY: D0.W = number to convert
; A0 = 6 byte buffer
; USES: D1 = loop counter
; D2 = leading zero counter
; D3 = current digit
;-----------------------------------------------------------------------
DecAsc2
MOVEM.L D0-D3/A0-A1,-(A7)
LEA DecTbl(PC),A1 ; get powers of ten table
MOVEQ #5,D1 ; five digits to convert
MOVEQ #4+1,D2 ; four digits to check for leading zero
.10
MOVEQ #'0'-1,D3 ; start with digit = 0
.20
ADDQ.B #1,D3 ; increment digit
SUB.W (A1),D0 ; subtract power of ten
BCC.B .20 ; loop until borrow
ADD.W (A1)+,D0 ; add back power of ten
CMPI.B #'0',D3 ; is current digit a zero?
BEQ.B .30
MOVEQ #0,D2 ; if not, clear leading zero counter
.30
SUBQ.W #1,D2 ; decrement leading zero counter
BGT.B .40 ; branch if skipping leading zeros
MOVE.B D3,(A0)+ ; store digit in buffer
.40
SUBQ.W #1,D1 ; loop for rest of powers of ten table
BNE.B .10
MOVE.B #0,(A0) ; store terminaing null in buffer
MOVEM.L (A7)+,D0-D3/A0-A1
RTS
DecTbl DC.W 10000,1000,100,10,1 ; powers of ten
-
- Very interested
- Posts: 2440
- Joined: Tue Dec 05, 2006 1:37 pm
- Location: Estonia, Rapla City
- Contact:
Thanks a lot !!!
Mida sa loed ? Nagunii aru ei saa
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen