Sprybug Posted December 29, 2016 Share Posted December 29, 2016 Hey guys, Using RevEng's latest 64k Batari BASIC mod. Having an issue with DPC+ and memory pushing and pulling. No matter what I push into memory, I always get back 0's when pulling it out. I've run a few test programs and the stuff I am storing rather never gets stored, or is lost. In my game I have multiple enemies and objects on screen and the only way to be able to keep track of all the info is to push and pull values for these objects into the ARM's memory using the stack, push, and pull commands. For example I do something like: main a=a+1 if a>100 then a=0 stack 0 ' have tried other values, same results push a c r j a=0:c=0:r=0:j=0 more code stack 0 pull a c r j score=score+a ' Just to see what the a variable's doing drawscreen goto main Always 0. I first noticed this in my main game program whenever I tried to do anything with the enemy players, everything always reset to 0. Is this just a thing with Stella, something wrong with Batari, or something I am doing wrong? Thanks for any help you can give so I can continue with Robot Zed. I am really liking what I am getting with DPC+ so far. 1 Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted December 29, 2016 Share Posted December 29, 2016 Have you seen this topic by Random Terrain? I created some Get/SetValue functions that are posted in that topic. They'll allow you to easily access up to 768 bytes of DPC+ RAM for variable use. You'll want to read through that topic then use the routines in reply #20 and reply 26. I posted a more detailed example on using them in reply 27. I also show how to see them in action in Stella's debugger in reply 22. Quote Link to comment Share on other sites More sharing options...
Sprybug Posted December 29, 2016 Author Share Posted December 29, 2016 Thanks Darrell! I'll check it out for sure. If it doesn't work out or have any other questions, I'll be sure to let you guys know. 1 Quote Link to comment Share on other sites More sharing options...
RevEng Posted December 30, 2016 Share Posted December 30, 2016 There aren't problems with stella or bB. Stacks just don't work the way your code assumes they do. Take the example of when the stack pointer is set to position 255, and then you push 4 values to the stack. The new top of stack (and the top of these 4 new elements) is at stack position 251. (the bB DPC+ stack grows toward 0, which is why it went from 255 to 251 when stuff was added) When you want to pull these 4 items off the stack, you'll want to ensure the stack pointer is pointing to the top of these 4 items... at position 251. If you try substituting "stack 255" and "stack 251" in your example, and it should work as expected. If this still doesn't make sense, try a bit of general research on stacks, and come back and re-read what I've said. (and none of this is meant to say you shouldn't use Darrell's method) Quote Link to comment Share on other sites More sharing options...
Sprybug Posted December 30, 2016 Author Share Posted December 30, 2016 OOOOH. I had no idea it worked that way. Did I not read Random Terrain's section of it correctly, or is it not properly documented? Because I completely forgot how a stack works. Thanks for the reminder. I will definitely give this a go first and if it doesn't work out, I'll give Darrell's a shot. I probably only need 50 bytes of this stack at most, since every object only needs about 4 bytes when they are on the screen being transferred to Riot RAM and back for each one. I always appreciate the geniuses here at AtariAge. Without you guys, none of my games would have ever been completed. 1 Quote Link to comment Share on other sites More sharing options...
RevEng Posted December 30, 2016 Share Posted December 30, 2016 You're welcome. Random Terrain's section on the DPC+ stack is correct, but it presently only provides an example for 1 item being pushed. You probably missed that the stack location pulled from was -1 from the location the value was pushed to. Quote Link to comment Share on other sites More sharing options...
Sprybug Posted June 11, 2017 Author Share Posted June 11, 2017 (edited) Okay, new question for the DPC+ stack! So doing things like Stack 255 Push a b c d Stack 251 Pull a b c d Stack 250 Push a b c d Stack 246 Pull a b c d etc Works fine and dandy, but what if I just want to mess with one of those variables? I'm doing that right now to deduct enemy life, which is the 2nd variable in the list. Now of course I don't need to push and pull all 4 variables. Just the one. I'm kind of lost however on where the stack pointer is actually pointing to. For example if I just want to get "b" out of that first stack, would I use: stack 253 push b to write and stack 252 pull b to read? I've tried a couple different values and it's locked up the game no matter what I have tried. The reason why I'm 1 off, is because from what I gather stack 255 on the 4 variable to push goes (255,254,253,252) Yet, in order to read you seem to have to subtract 1, since we're using 251 to read those same 4 variables (251,252,253,254) I think you can see why I'm kind of confused here. Edited June 11, 2017 by Sprybug 1 Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 11, 2017 Share Posted June 11, 2017 Most of your notions and understanding above are correct. But you've assumed the wrong order. Starting with a base of 255, the order of "a b c d" looks something like this... 251D252C253B254A255 So to retrieve B individually, set the stack point above it at 253, and pull. To set it individually, set the stack pointer under it at 254, and push. Quote Link to comment Share on other sites More sharing options...
Sprybug Posted June 11, 2017 Author Share Posted June 11, 2017 Most of your notions and understanding above are correct. But you've assumed the wrong order. Starting with a base of 255, the order of "a b c d" looks something like this... 251 D 252 C 253 B 254 A 255 So to retrieve B individually, set the stack point above it at 253, and pull. To set it individually, set the stack pointer under it at 254, and push. This helps prove that I'm more of a visual learner. This makes so much sense now! Thank you! 2 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.