Jump to content
IGNORED

Displaying larger decimal values / converttobcd()


BydoEmpire

Recommended Posts

From the 7800basic manual:

Quote

The non-BCD variable should be in the range between 0-99, or else it will start to display incorrect values.

 

Is there a cheap way around this?  I'd *like* to repurpose a bcd variable to show numbers in a range beyond 100.

 

I could just do a loop like "for i=0 to dec_value ;  bcdval=bcdval+$1 ; next i" ... seems kind of wasteful. Better way?

 

Link to comment
Share on other sites

BCD numbers are basically hex numbers. i.e. When you convert the decimal value "13" to BCD, it becomes $13. Since a byte's max value is $FF in hex, those 2 hex digits only allow for representing a BCD value up to "99".

 

Yes, there could be a routine developed to return 2 bytes, but I try not to add a lot of functions that will go unused by a large number of games.

 

How's your number generated in the first place, and what's it's max value? If it's updated with addition and subtraction, you could also use an extra score variable to track it in BCD. Or if we're just talking about a value with a max of 255, you could just do some iterative subtraction to pull out the 100's place.

Link to comment
Share on other sites

7 hours ago, RevEng said:

BCD numbers are basically hex numbers. i.e. When you convert the decimal value "13" to BCD, it becomes $13. Since a byte's max value is $FF in hex, those 2 hex digits only allow for representing a BCD value up to "99".

 

Yes, there could be a routine developed to return 2 bytes, but I try not to add a lot of functions that will go unused by a large number of games.

 

How's your number generated in the first place, and what's it's max value? If it's updated with addition and subtraction, you could also use an extra score variable to track it in BCD. Or if we're just talking about a value with a max of 255, you could just do some iterative subtraction to pull out the 100's place.

That makes sense.  It's just incremented every time you enter a room, and caps at 256 (in the end of game display, if the value is 0 I display "perfect" instead, since you can never visit 0 rooms and finish teh game I can assume you hit all 256 and it just wrapped).  I use the extra score value for health, but along the way I capped out health at 50 so I don't really need it.  I was thinking of using score1 for this instead, that might be the way to go.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...