Well, no need to make a post to say you weren't logged in, I saw it. This personally never happened to me yet, and I ask myself why this happen so often to everyone else.

That happens to me all the time. I'll be on the main index and be logged in, and can see which forums have new posts. Then I click on a forum, and suddenly I'm a 'guest'. So I log in again, and it acts like I've already read all the new posts (very annoying, because I often find myself missing some posts that way, usually only noticing it once there's another reply). It's odd though, because it never happens to me on any other forum using phpBB.

/end OT rant

This binary to decimal code sounds pretty nice. I know I'd prefer a technique that always takes the same amount of cycles, I think it's best to optimize for the worst-case.

That happens to me all the time. I'll be on the main index and be logged in, and can see which forums have new posts. Then I click on a forum, and suddenly I'm a 'guest'.

Well, I think there is a checkbox when you log in that should be thicked if you want to "automatically" log-in. Of course, you can't do this at work or something, but you can on your home computer. Else, bugs and stuff should be reported to the phpBB team.

Quote:

So I log in again, and it acts like I've already read all the new posts (very annoying, because I often find myself missing some posts that way, usually only noticing it once there's another reply). It's odd though, because it never happens to me on any other forum using phpBB.

This happens to me very often. I'm just logged in, see a new post, go to it, then read it and possibly aswer to it, but when I come back, sometimes all others new post aren't marked as new anymore, sometimes not. It's really crap, effectively.Another crap thing is that sometimes it shows a new post, but actually the new post is just mine.

Quote:

This binary to decimal code sounds pretty nice. I know I'd prefer a technique that always takes the same amount of cycles, I think it's best to optimize for the worst-case.

Well, I think it's better to be short sometimes and medium sometimes than long anyway.

_________________Life is complex: it has both real and imaginary components.

Worst-case performance is what matters most, because it's what determines whether you have slow-down in a game (unless you can guarantee that worst-case performance of one routine always occurs during the best-case performance of another). For real-time applications, you don't mind reducing best-case performance if it increases worst-case.

If anyone is curious, this is the 8-bit routine, unrolled and optimized as far as I could so far. There are no conditional branches, so execution time is constant - around 150 cycles (I say around because there is the set-up, returning and all and I'm never really sure if we should count these in when measuring cycles). I have not bothered to make it as a subroutine yet, I'm just doing things directly for now, for testing purposes.

This runs faster than the worst case of Bregalad's routine (only a little bit faster), but still much slower than it's best case.

If anyone wants to try, here it is (it is quite longer when unrolled!):

Code:

BNUM = $00 ;8-bit binary number.DNUM = $01 ;3-digit decimal number.

.ORG $8000

LDA #199 ;Test value. STA BNUM

BIN2DEC LDA #$00 ;1's start at 0, using the accumulator until the end. STA DNUM+1 ;Clear 10's. Will use memory. STA DNUM+2 ;Clear 100's. Will use memory.

ASL BNUM ;Shift 1st bit from binary number ROL ;into the 1's digit.

ASL BNUM ;Shift 2nd bit from binary number ROL ;into the 1's digit.

ASL BNUM ;Shift 3rd bit from binary number ROL ;into the 1's digit.

TAX ;This is the 1st time 1's may have gone over LDA TABLE, X ;the limit. Get the correct value from TABLE.

I'm extending it to 16 bits right now, and then things might get interesting. I'll try to optimize it further, looking for unncessary operations or faster ways to do the necessary ones... putting the lookup table on zero-page may speed up things a bit, but I don't think anyone will want to waste 10 bytes of zero-page, me included.

When a 16-bit version is ready, I'll try it against Bregalad's method, also extended to 16 bits.

There is one thing I really like about Bregalad's method, though: you could jump to the middle of the routine if you were interested in converting smaller numbers. Both methods are nice, but I'm trying hard to make this one perform faster.

Well, I think it's not that complicated. Before shifting, you have to check if the shift will override 10, and if so, you have to add 123 to the number so the Most Significan Bit will overwrite into the next one. I'm just unsure that will work for larger-than 8-bit number so easily.

No, it is not complicated at all - the way the routine works I mean. But one's got to be pretty smart to first come up with an idea like this. I alway read about these revolutionary ways to do stuff but can never seem to come up with one of those! =)

I understood HOW it worked as soon as I read about it, what I didn't understand at first was WHY it worked! Once that was also understood, I could come up with new ways to use the idea, instead of blindly using something someone else discovered and not even know what I was doing.

I love this kind of thing. Optimizing an algorithm in assembly is the most fun since it involves programming at the lowest level while thinking in terms of very pure math concepts. The discussion forum on 6502.org sometimes has some interesting threads along these lines, for example the recent "Fast CRC without tables" thread.

Yeah, I find it very interesting too! However my math skills aren't that great, and sometimes I miss many chances for optimizations.

I visit the 6502.org forum from time to time, and they do have some very interesting stuff in there. However, with this subject I wasn't very lucky. They have good ways to perform BIN to DEC conversions, ways that deserve more studying, but most use the BCD mode of the 6502, wich the NES lacks. I don't think people there care much about "modified" 6502's. =)

This runs faster than the worst case of Bregalad's routine (only a little bit faster), but still much slower than it's best case.

Mine also is much shorter and waste probably about 3 times less ROM.

Quote:

When a 16-bit version is ready, I'll try it against Bregalad's method, also extended to 16 bits.

Hey, the get number from the table thing is cool !Scince you usually don't want to converse dozens of large number in a single frame, this probably won't cause any slowdown in gamaplay when just converting the score once when the player kills a monster. If you want to keep the score refresh every frame, this will surely be negligable scince you only have one number to convert. The only case I can see where it would be significant, if you're making a RPG and if you want to keep the HP, Max HP, MP, Max MP of all characters and *all* this refreshed every frame, this may be significant (if there is 4 party member, this makes 16 16-bit numbers). Anyway, this would eat a lot of VRAM update during VBlank, so I think it's better to upload the value only when you're sure the player lost/recovered some HP or use/recovered some MP.

Quote:

There is one thing I really like about Bregalad's method, though: you could jump to the middle of the routine if you were interested in converting smaller numbers. Both methods are nice, but I'm trying hard to make this one perform faster.

Yeah, this is cool, but keep in mind this is not my method, it's also here everywhere else.

_________________Life is complex: it has both real and imaginary components.

It saves you the CMP's and make constant timing possible. And is faster than actual addition. However, the traditional method WILL SKIP some aditions, killing constant timing, but speeding up things sometimes.

Quote:

Scince you usually don't want to converse dozens of large number in a single frame, this probably won't cause any slowdown in gamaplay when just converting the score once when the player kills a monster. If you want to keep the score refresh every frame, this will surely be negligable scince you only have one number to convert. The only case I can see where it would be significant, if you're making a RPG and if you want to keep the HP, Max HP, MP, Max MP of all characters and *all* this refreshed every frame, this may be significant (if there is 4 party member, this makes 16 16-bit numbers). Anyway, this would eat a lot of VRAM update during VBlank, so I think it's better to upload the value only when you're sure the player lost/recovered some HP or use/recovered some MP.

You're probably right. I gess the best way is to update only when the numbers change, so the impact on overall speed is much smaller.

Quote:

Yeah, this is cool, but keep in mind this is not my method, it's also here everywhere else.

I know, as much as the other one isn't mine either! =) I just call it that because you presented some code for it and all, and seemed to like it and used since this thread first started. So, by "Bregalad's method" I actally mean "the method Bregalad uses". =)

Yeah, this is cool, but keep in mind this is not my method, it's also here everywhere else.

tokumaru wrote:

I know, as much as the other one isn't mine either! =) I just call it that because you presented some code for it and all, and seemed to like it and used since this thread first started. So, by "Bregalad's method" I actally mean "the method Bregalad uses". =)

I'm always careful about how I refer to things people present here, in order to avoid encouraging identification with the topics, since that leads to defensiveness. Often when people start referring to so-and-so's idea, they act as if so-and-so is stuck with that idea alone and won't try anything different (apologies to anyone named so-and-so).

I'd call it "the method Bregalad described earlier" or come up with a short descriptive phrase for the method itself (perhaps "repeated subtract-and-compare").

That's pretty much it, I'm not against the shift method, but I think the substation/comparison is much more flexible and easily implementable in a game that should convert both huge and small numbers. I'm still waiting the results for 16-bit and 24-bit version of the shift method, it may be faster and may not. And I really think unrolling the loop and stuff is worthless because you'll definitely not convert a lot of number. Optimal and constant timing is much more needed for monster AI or sprite engine implementation, or scrooling engine, and eventually the sound engine (that is typically much more slower when all chanells plays a new note, than if all of them are just disabled and ignored, heh).

_________________Life is complex: it has both real and imaginary components.

Hi, lord_Chile! I'm glad to see that you are practicing and all... very good!

Just want to say one thing you are doing wrong here. Your code starts at $0003, but so do your variables! If you look in the memory window, the beginning of the code is overwritten by the result of the routine... The simulator allows this, because the code is overwritten after it has already run, but in a real life situation that would be impossible, because you can't define code in RAM (unless you have a routine to copy code from ROM to RAM, wich isn't the case, you're using .org) and you can't have variables in ROM. So what you did there is a little paradox...!

Just make sure you separate code from the variables. In your program the variables could easily use $00, $01 and $02, and then program begins at $03, as it already does.

yes, i understand.. it's for 6502 simulator. i did implement it for nesasm, and all ok. just i keep my tables and code in rom, then i use ram for variables. see you. thanks to you for teaching me any important things

Who is online

Users browsing this forum: No registered users and 12 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum