Jump to content
IGNORED

DPC+ Memory push and pulling not working


Sprybug

Recommended Posts

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.

 

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • 5 months later...

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 by Sprybug
  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

  • Like 2
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...