NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectNumber to String? new  
Posted byAnonymous
Posted on5/30/04 11:46 PM
From IP64.12.116.77  



I would like to know how to change the variables in my game to actual strings and display them on the screen. Can someone tel me how to do this? thx :-)




SubjectRe: Number to String? new  
Posted byDisch
Posted on5/31/04 00:26 AM
From IP66.82.9.67  



There's a way to do it.. but it's pretty slow.

FF1 uses a method which made a series of tables. For example... if you were making the number into a 4-character string.. you'd need:

- high byte 1000's table
- low byte 1000's table
- high byte 100's table
- low byte 100's table
- low byte 10's table

First run through the table at the 1000's... starting with 9000. Check the number to see if it's < 9000. If it isn't... check 8000.. then 7000. When the number is less than x thousand... subtract that much from it, put your first digit in the string, then run it through the hundreds table. Then the tens... etc.




SubjectRe: Number to String? new  
Posted byMemblers
Posted on5/31/04 04:58 AM
From IP68.58.99.218  



If you want to display it in hex, the way I've done it is just to have 16 characters in the pattern table (0 - F), if those were tiles $E0-$EF for example, you can do something like this:

lda var0
and #$F0
lsr
lsr
lsr
lsr
clc
adc #$E0
sta $2007

lda var0
and #$0F
clc
adc #$E0
sta $2007




SubjectRe: Number to String? new  
Posted byMemblers
Posted on5/31/04 05:06 AM
From IP68.58.99.218  



BTW, for decimal numbers, I've always done it the cheap way..

I use one byte of RAM for every digit, increment the lower one, if it's $0A or above, subtract $0A to reset it, and increment the next higher digit.

That might not work in all cases, and it can use a lot of memory, but it is pretty fast and easy to do.




SubjectRe: Number to String? new  
Posted byAnonymous
Posted on5/31/04 06:46 AM
From IP64.12.116.77  



I don't plan on using HEX #s as not all people know hexadecimal. So I'm going to use decimal, but your way of displaying the #s is way to memory costly for my game (even for the speed). I want to find a way the fastest, memory cheapest way to do this as it would be good for my game.




SubjectRe: Number to String? new  
Posted byAnonymous
Posted on5/31/04 06:48 AM
From IP64.12.116.77  



I always thought that Final Fantasy 1 was a pretty slow game (even though it was a lot of fun). I would genrally need a faster way then that. But if worst comes to worst I'll use that method. thx :-)




SubjectRe: Number to String? new  
Posted bysigma
Posted on5/31/04 4:09 PM
From IP208.181.90.67  



I have this routine that can decimalize a 16-bit number. It's potentially the fastest way to do it, but there's relatively a lot of code...




SubjectRe: Number to String? new  
Posted byAnonymous
Posted on6/1/04 00:15 AM
From IP172.172.71.171  



What about 8-bit #s? If it also could do 8-bit #s that'd be great as most of the #s in my game will be 8-bit. I like the fastness and don't mind so much the amound of ROM it takes as long I don't have to use tons of RAM for each number (as Membler does it). You don't have to give me the actual code, but could you at least tell me how you achieved it exactly so that I might be able to code it myself (that is if you don't want to give me *your* code). thx :-)




SubjectRe: Number to String? new  
Posted byRoboNes
Posted on6/1/04 08:33 AM
From IP81.77.239.235  



you should be able to do this with masking, shifting and then reflecting the number against the correct chr tile




SubjectRe: Number to String? new  
Posted byDisch
Posted on6/1/04 4:17 PM
From IP66.82.9.61  



You can't mask out base 10 numbers with a simple AND operation... not unless they're stored in BCD like Memblers was pointing out.

If the NES had division and mod operators this would be so much easier.

Anyway... if there's a faster way than the lookup table method I mentioned... I'd love to hear it as well. I'm rather curious.




SubjectRe: Number to String? new  
Posted bysigma
Posted on6/1/04 9:00 PM
From IP208.181.90.67  



I'll make the 6502. I can't really give the psudocode/derivation because it uses some kinda tricky algebra and coding. Besides, I could use the practice. (only been doing 6502 for about a week and a half now, still not totally familiar with it :)

I can have it in maybe a day or two.




SubjectRe: Number to String?  
Posted byAnonymous
Posted on6/1/04 10:58 PM
From IP64.12.116.77  



Ummmm, actually thanks Disch for the FF1 method. I'll be using a variation of that method so that it fits my game. Again thanks for your help :-)




SubjectRe: Number to String? new  
Posted byAnonymous
Posted on6/2/04 00:58 AM
From IP64.12.116.77  



I'm not really a fan of just using other people's code as I like to code it myself to get the knowledge, but I'd be happy to chack out your method. I've already decided that I'm going to use a variation of Disch's FF1 code for now. Well, then in a day or 2 I'll check your code out. Thx :-)




SubjectRe: Number to String? new  
Posted bytepples
Posted on6/3/04 5:11 PM
From IP68.54.20.186  



I use a similar technique to convert binary to BCD for printing, except with just 8000, 4000, 2000, 1000, 800, 400, ... 2, 1.




SubjectRe: Number to String? new  
Posted bysigma
Posted on6/3/04 7:09 PM
From IP208.181.90.67  



I couldn't in all conscience post over 100 lines of code, so I set up some lame Geocities account: http://www.geocities.com/sigma_zk/blitzdec.txt




SubjectRe: Number to String? new  
Posted byAnonymous
Posted on6/3/04 7:32 PM
From IP64.12.116.77  



thanks for the code. I havn't tried it out yet, but it looks good. Thx :-)




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo