+Karl G Posted June 26, 2017 Share Posted June 26, 2017 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 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 26, 2017 Share Posted June 26, 2017 It looks like the bB page says that you need to use BCD compliant numbers. http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#check_score http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bcd Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 27, 2017 Share Posted June 27, 2017 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. Quote Link to comment Share on other sites More sharing options...
+Karl G Posted June 27, 2017 Author Share Posted June 27, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.