Jump to content
IGNORED

Converting to BCD


Karl G

Recommended Posts

I'm trying to convert a two-digit number in a variable to BCD to assign to a score variable, but it's not working as expected. I'm using the // operator to divide by 10, and multiply the result of that by 16, then add the contents of temp1, which should contain the remainder of the division operation. I've put this in a simple "hello world" skeleton where the fire button increments the variable, and tries to convert it and put it on one of the score variables. Does anyone know why this isn't working as I'm expecting it to? Thanks in advance for any advice.

 

helloworld.bas

Link to comment
Share on other sites

Link to comment
Share on other sites

The easiest way to deal with conversion to BCD is to keep the number in BCD format from the start. i.e., when you add and subtract, use the "dec" keyword in front of the assignment. (Just keep in mind that the 6502/7 doesn't handle BCD division or multiplication)

 

   MyScore=$10 ; BCD version of "10"
   [...]
   dec MyScore=Myscore+1

If really need to convert to BCD, Omegamatrix has a cool routine in assembly.

Link to comment
Share on other sites

Thanks! I'm using my variable as a wave counter in a space game, and using the score to display the wave number at the beginning of the wave (blanking out the unneeded digits). The question as to whether I should keep it in BCD format from the start or not depends on whether or not I want more than 100 waves then, I suppose. That routine will be quite handy if I choose to allow for more than 100 waves, then. Much appreciated.

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...