How to display DEC numbers ???

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

How to display DEC numbers ???

Post by TmEE co.(TM) » Thu Jan 04, 2007 12:20 am

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

Fonzie
Genny lover
Posts: 323
Joined: Tue Aug 29, 2006 11:17 am
Contact:

Post by Fonzie » Thu Jan 04, 2007 12:50 am

I myself just display the hexa :) héhé :D 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 :)

Pascal
Very interested
Posts: 200
Joined: Wed Nov 29, 2006 11:29 am
Location: Belgium
Contact:

Post by Pascal » Thu Jan 04, 2007 7:42 am

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

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Thu Jan 04, 2007 12:07 pm

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

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Thu Jan 04, 2007 1:31 pm

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)

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Fri Jan 05, 2007 1:48 am

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 :

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% 
I would like to know different other METHODs
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

8bitwizard
Very interested
Posts: 159
Joined: Sat Feb 24, 2007 11:35 pm
Location: San Antonio, TX

Post by 8bitwizard » Sat Feb 24, 2007 11:41 pm

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

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Sun Feb 25, 2007 2:12 pm

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

Post Reply