+Gemintronic Posted May 15 Share Posted May 15 Thank you in advance for any suggestions. Having trouble wrestling with separating the tens part of a variable and the ones part into two different variables. I'm trying to let players buy items. I have a display that only has two digits. I'd like to show that it takes, say, 87 gold to purchase. So, the "8" part would be in one variable for display and the "7" part in another variable for display. I've worked around a similar problem by manually adding nybbles. But, I feel I'm doing it wrong. If y'all have any experience with this kind of problem I'd love to hear it. Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted May 15 Author Share Posted May 15 I think I got it by hacking at the high score code from bogax: f = 124 temp1 = f rem JUST 1s PLACE temp2= 0 if temp1 > 99 then temp2= temp2+ 0 : temp1 = temp1 - 100 if temp1 > 99 then temp2= temp2+ 0 : temp1 = temp1 - 100 if temp1 > 49 then temp2= temp2+ 0 : temp1 = temp1 - 50 if temp1 > 29 then temp2= temp2+ 0 : temp1 = temp1 - 30 if temp1 > 19 then temp2= temp2+ 0 : temp1 = temp1 - 20 if temp1 > 9 then temp2= temp2+ 0 : temp1 = temp1 - 10 c = temp1 temp1 = f rem JUST 10s PLACE temp2= 0 if temp1 > 99 then temp2= temp2+ 0 : temp1 = temp1 - 100 if temp1 > 99 then temp2= temp2+ 0 : temp1 = temp1 - 100 if temp1 > 49 then temp2= temp2+ 5 : temp1 = temp1 - 50 if temp1 > 29 then temp2= temp2+ 3 : temp1 = temp1 - 30 if temp1 > 19 then temp2= temp2+ 2 : temp1 = temp1 - 20 if temp1 > 9 then temp2= temp2+ 1 : temp1 = temp1 - 10 b = temp2 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted May 15 Share Posted May 15 The first idea I had was using a variation of this: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#ex_score_digit_check ; Tens digit ........... _sc3 & $F0 (00 00 X0) ; Ones digit ........... _sc3 & $0F (00 00 0X) 1 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted May 15 Author Share Posted May 15 1 hour ago, Random Terrain said: The first idea I had was using a variation of this: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#ex_score_digit_check ; Tens digit ........... _sc3 & $F0 (00 00 X0) ; Ones digit ........... _sc3 & $0F (00 00 0X) I'll take a look. Thanks for checking this topic (and others too!) I think the butchered bogax high score code might be the most "optimal" since dividing by 10 is hard. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted May 19 Share Posted May 19 What you want to do is subtract the 10's frome temp1 and add them to temp2 so you end up with the 10's in temp2 and the 1's in temp1 so the if statements would be like if temp1 > 99 then temp2 = temp2 + 10 : temp1 = temp1 - 100 ; temp2 gets the 10's ie 100 = 10 10's 1 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted May 19 Author Share Posted May 19 12 hours ago, bogax said: What you want to do is subtract the 10's frome temp1 and add them to temp2 so you end up with the 10's in temp2 and the 1's in temp1 so the if statements would be like if temp1 > 99 then temp2 = temp2 + 10 : temp1 = temp1 - 100 ; temp2 gets the 10's ie 100 = 10 10's Thanks again! Yeah. I decided to use your high score code including the 100s place so I could filter it out if I got a whacky condition like an unexpected number greater than 99. I may have switched around the rem statements remarking which was dealing with 10s and 1s. Quote Link to comment Share on other sites More sharing options...
bogax Posted May 20 Share Posted May 20 I was thinking something like this ; d3 = 100's, d2 = 10's, d1 = 1's d3 = 0 : d2 = 0 : d1 = temp1 if d1 >= 100 then d3 = d3 + 1 : d1 = d1 - 100 if d1 >= 100 then d3 = d3 + 1 : d1 = d1 - 100 if d1 >= 50 then d2 = d2 + 5 : d1 = d1 - 50 if d1 >= 30 then d2 = d2 + 3 : d1 = d1 - 30 if d1 >= 20 then d2 = d2 + 2 : d1 = d1 - 20 if d1 >= 10 then d2 = d2 + 1 : d1 = d1 - 10 Quote Link to comment Share on other sites More sharing options...
Darkhog Posted Friday at 08:25 AM Share Posted Friday at 08:25 AM (edited) Does bB have modulo and the integer division (basically, division where the decimal part is dropped, so with it 10 / 2 = 5, but also 11 / 2 = 5)? Because that would significantly make easier to split variable into 100s, 10s, and 1s. //edit: If it does have both, the basic gist is this: For your ones digit, it's value % 10. For your tens digit, it's (value/10)%10. For your hundreds digit, it's (value/100)%10 Where / is the integer division operator and % is modulo operator. Edited Friday at 08:32 AM by Darkhog Quote Link to comment Share on other sites More sharing options...
+Karl G Posted Friday at 11:49 PM Share Posted Friday at 11:49 PM 15 hours ago, Darkhog said: Does bB have modulo and the integer division (basically, division where the decimal part is dropped, so with it 10 / 2 = 5, but also 11 / 2 = 5)? Because that would significantly make easier to split variable into 100s, 10s, and 1s. //edit: If it does have both, the basic gist is this: For your ones digit, it's value % 10. For your tens digit, it's (value/10)%10. For your hundreds digit, it's (value/100)%10 Where / is the integer division operator and % is modulo operator. bB does have integer division and a modulo operator. The double slash // is used for modulus. However, almost always you will want to find a way to avoid doing normal multiplication and division operations in a game, as these take up a whole lot of the very limited available cycles on the Atari. Multiplying and dividing by powers of two is an exception, since these translate to quick bit-shifting operations under the hood. 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.