Jump to content
IGNORED

asm question


Recommended Posts

Hi folks. Well, I have a situation where I need to switch between, say, 2 banks of status variables.

 

status_reg_1: .res 2

count_reg_1: .res 2

...

status_reg_2: .res 2

count_reg_2: .res 2

.. etc

 

I need to be able to switch code accessing these variables from one to the other depending on another setting, without having to have separate code. The only way I could figure out was to set up a zero page 'base' register and use (indirect),y to access the variables. When I want block 1 I put block 1's address in there, when I want block 2 I put block 2's. Is this really the only choice?

 

Link to comment
Share on other sites

Option 1: lda/sta (zp),y

Option 2: lda/sta abs,x with x=<what you want>+0 or x=<what you want>+offset, where offset is the difference [status_reg_2-status_reg_1].

Option 3: lda/sta abs,x with x=<what you want> and modify the "abs" address directly (like you would modify the zp address) directly in the code (self-modifying code) to point to the start of block1/block2.

Edited by JAC!
Link to comment
Share on other sites

Might be helpful to know what the ultimate goal is. Quicker execution? There is nothing faster than 100% dedicated routines. Self-modifying code would only be slightly slower than that. The example above could be even faster if the self-modifying lines are using immediate mode rather than X/Y indexed (2 vs. 4 cycles in each instance)...but even that could be counter-productive if you are altering too many lines (effectively losing any time savings in the process).

Link to comment
Share on other sites

What about a temp ram approach? Save $abs,X or ($ind),Y to scratch ram, deal with a block of code (or an entire frame), and throw the values back from scratch ram to their actual locations (if the routines are modifying them)? That's 3 cycles for each instance. But also counter-productive if the amount of scratch ram needed is too great.

Link to comment
Share on other sites

Just use indexing, by far the easiest way.

 

Then either have the 2 data structures interleaved byte by byte or bundled - if bundled then you have to restrict the size to 128 bytes or less.

 

So, e.g. for a game where 2 player's stats are kept, references would be like:

 

ldx #$80 ; reference player 2

lda energy,x

 

Most games will do such array processing in similar fashion. In some cases they use an interleaved approach where the index is 0 or 1. You can do it any way you want. Even mix it up a bit, it's not like everything has to be stored in the 1 block of data.

Link to comment
Share on other sites

Ok. Indexed it is.

Self modifying stuff I hadn't thought of...thats pretty cool but I doubt I could pull it off. I had thought of the 'scratch ram' ( if i understand what you mean ) approach but I don't want to spend the time copying a bunch of bytes everytime I need to switch.

Thanks folks.

Edited by danwinslow
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...