R_Leo_1 Posted December 28, 2019 Share Posted December 28, 2019 In the 7800basic guide it says that modulus can be performed on variables using "//" but I have been unable to get it to work, it doesn't seem to have any effect on the variable at all. I've tried to write the code in different ways but no such luck. I would appreciate any help with this, thanks. Here's a snippet of the code: scrollskip2 count1 = count1+1 if ((count1 // 4)=0) then count2 = count2+1 if count2 = 255 then goto introduction goto TitleScreenLoop ...and the entire bas file if needed LL.bas 1 Quote Link to comment Share on other sites More sharing options...
+Karl G Posted December 28, 2019 Share Posted December 28, 2019 I don't know why the modulus isn't working, but I know another way to achieve the same thing that I think would also take less CPU cycles. If you do a bitwise AND of count1 with 3, then you are only looking at the last two bits, so it will equal 0 every 4 iterations like I think you are intending here: scrollskip2 count1 = count1+1 if ((count1&3)=0) then count2 = count2+1 if count2 = 255 then goto introduction goto TitleScreenLoop 2 Quote Link to comment Share on other sites More sharing options...
R_Leo_1 Posted December 28, 2019 Author Share Posted December 28, 2019 Oh okay, this will work great! Thanks for the help 1 Quote Link to comment Share on other sites More sharing options...
+Karl G Posted December 29, 2019 Share Posted December 29, 2019 Looking into it a bit more, the 7800basic documentation doesn't say much about modulus. Batari Basic implements it by putting the modulus value in the temp1 variable. I tested this, and it appears that either modulus isn't currently implemented in 7800basic, or it is implemented differently and not yet documented in the version of the docs that I saw. Temp2 = 10 // 3 Temp1 = temp1 plotvalue scoredigits_8_wide 2 Temp1 2 56 11 plotvalue scoredigits_8_wide 2 Temp2 2 56 10 1 Quote Link to comment Share on other sites More sharing options...
+Karl G Posted January 2, 2020 Share Posted January 2, 2020 @RevEng - just making sure you saw this one. Quote Link to comment Share on other sites More sharing options...
RevEng Posted January 2, 2020 Share Posted January 2, 2020 Thanks Karl. It's on my radar now. 1 Quote Link to comment Share on other sites More sharing options...
RevEng Posted January 15, 2020 Share Posted January 15, 2020 Just a heads up that it looks like // is broken in bB too, which is where 7800basic got the operator. I'll need to study the 16-bit divide routine to understand it better, and see where it's going off the rails. Quote Link to comment Share on other sites More sharing options...
RevEng Posted January 15, 2020 Share Posted January 15, 2020 I've fixed this in my private builds for 7800basic and bB. The original div16 routine came from here and I don't think it was ever put through it's paces. I've replaced it with the one here and the results for // are correct now. (except remainders are wrong if you use a constant power-of-two divisor, due to power-of-two optimisations, which I'll document) I'll get some new releases out once I spend some time on incorporating both 32-bit and 64-bit binaries. (thanks Apple) All of that said, using masks as Karl advised is the preferred method for that sort of thing. I've honestly never liked the idea of the remainder operator, since it's wasteful compared to masks. 3 Quote Link to comment Share on other sites More sharing options...
Bradsco Posted May 21, 2021 Share Posted May 21, 2021 Looking for a way to find an arbitrary remainder (not guaranteed to be power of 2) and still seeing an issue where modulus doesn't work as expected. RevEng, did your changes make it into the release builds? I'm using Atari Dev Studio 0.7.1, so it should be 7800basic 0.18. Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 21, 2021 Share Posted May 21, 2021 The new routine should definitely be in there, though it's entirely possible you've run into some other issue. When I get a chance, I'll write up an exhaustive test. Quote Link to comment Share on other sites More sharing options...
SlidellMan Posted May 21, 2021 Share Posted May 21, 2021 It should have been said that // is used to comment out code a la C/C++ and Javascript. Quote Link to comment Share on other sites More sharing options...
Bradsco Posted May 21, 2021 Share Posted May 21, 2021 1 hour ago, RevEng said: The new routine should definitely be in there, though it's entirely possible you've run into some other issue. When I get a chance, I'll write up an exhaustive test. I think it might be. The case I've found is when the dividend is less than the divisor, the result is always zero. Quote Link to comment Share on other sites More sharing options...
RevEng Posted May 21, 2021 Share Posted May 21, 2021 1 hour ago, Bradsco said: I think it might be. The case I've found is when the dividend is less than the divisor, the result is always zero. Ah, looking at how the routine runs, I think that's an overlooked case. I'll add a comparison check to the beginning of the routine to cover it. Until the next release, I'd recommend you just add an if...then test for this case to your code. Quote Link to comment Share on other sites More sharing options...
Bradsco Posted May 21, 2021 Share Posted May 21, 2021 32 minutes ago, RevEng said: Ah, looking at how the routine runs, I think that's an overlooked case. I'll add a comparison check to the beginning of the routine to cover it. Until the next release, I'd recommend you just add an if...then test for this case to your code. It's not time critical, but I'm glad we know what it is. Plenty more stuff get my head around still. 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.