Jump to content
IGNORED

(Minefield) recursion in Z80


Recommended Posts

Does anyone have example code for a minefield explosion or similar?

 

IE you have one mine explode and if it is next to another mine then that one will explode which triggers any mines next to that one explode and so on.

 

Here is another issue I have.

Using negative numbers refuses to play ball no matter how many times I ask it.

 

I have a set of numbers in a loop that goes something like.

-33,-32,-31,-1,1,31,32,33

It works fine but when it gets to 1, 31,32,33 it goes bonkers.

But if I get rid of the - signs it works but then the negative portion is jacked.

Link to comment
Share on other sites

Recursion is dangerous on a system with limited RAM, because it pushes more than the state you're keeping track of, so you could easily be using twice the RAM just from return addresses. What you need is to make a list of just the things you're keeping track of, add to it every time you have a new one to explore, then when you finish each one, pick the last one on the list and do that next. Technically it's a stack, it's just not the CPU stack. And it's easier to know when the list is full and abort. Something may get missed, but at least you won't crash.

 

As for negative numbers, you do know how 2s-complement math works, right? Numbers can't be just anything, they're words, bytes, whatever, and you have to know how big they are. You don't just have "a set of" "numbers". It's meaningless without knowing how many bits they are.

Edited by Bruce Tomlin
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...