News: 11 March 2016 - Forum Rules

Author Topic: 65816: Interrupting a Block Move ... and doing another block move?  (Read 3380 times)

assassin

  • Full Member
  • ***
  • Posts: 154
    • View Profile
    • My Barren Webpage
65816: Interrupting a Block Move ... and doing another block move?
« on: September 12, 2013, 07:00:19 am »
Per the documentation, it's safe for a Block Move instruction (MVN or MVP) to be interrupted, provided the relevant registers (A, X, and Y) are restored before the RTI.  This leads me to two questions:

1) What if the interrupt routine itself performs another block move?  Is there anything in the "internal state" of a block move that can be overwritten?  For instance, I read in one forum that while the Destination Bank is kept in the Data Bank register, the Source Bank has its own internal, temporary variable.  Will an intervening MVP/MVN with a different source bank clobber this?  Or does each iteration of the byte copy restore this bank to what it should be?

2) More generally, does a routine that potentially interrupts a MVN/MVP need to preserve the Data Bank register alongside X, Y, and A, or is the destination bank reestablished with each iteration of the byte copy?

Thanks

STARWIN

  • Sr. Member
  • ****
  • Posts: 454
    • View Profile
Re: 65816: Interrupting a Block Move ... and doing another block move?
« Reply #1 on: September 13, 2013, 08:37:19 pm »
Based on the nocash documentation, I can't imagine it being unsafe in any case, as long as you save A X Y. After all, the opcode jumps to itself and contains destination and source as parameters. Whatever happens internally during the opcode execution should be irrelevant after it is executed, and I assume interrupts would only execute between opcodes. Setting DB seems to be more of a side-effect or a bonus than permanent storage... if it cared about DB, you would assume it required DB to be set manually before the first execution of the opcode.

Unless someone has used such setup already and can confirm, your best bet is to write a test program, if you doubt the accuracy of the documentation.

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5792
    • View Profile
    • Nightcrawler's Translation Corporation
Re: 65816: Interrupting a Block Move ... and doing another block move?
« Reply #2 on: September 14, 2013, 10:03:24 am »
Agreed. It should be OK to do this and it should work fine. As mentioned, the banks are operands of the instruction and the instruction merely executes and jumps back to itself to execute again until complete.

So, it's no different than any other opcode as far as being interrupted and using the same instruction within your interrupt handler.
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations

assassin

  • Full Member
  • ***
  • Posts: 154
    • View Profile
    • My Barren Webpage
Re: 65816: Interrupting a Block Move ... and doing another block move?
« Reply #3 on: September 14, 2013, 11:12:41 am »
thanks both for the replies.  i wasn't sure whether each iteration of the MVN/MVP was the same, or if it did some initial setup that wasn't repeated on later iterations.

your posts and reasoning convince me it's safe.

the functions i'm editing are SRAM loading and saving, so it's highly unlikely they would ever be called from interrupts anyways.  but i just wanted to cover all bases, since i'm not familiar with most of the innards of the game in question.  and curiosity, more than anything.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7183
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: 65816: Interrupting a Block Move ... and doing another block move?
« Reply #4 on: September 14, 2013, 09:41:03 pm »
I'd say to ask byuu (.org).
If he doesn't already know, he could probably find out pretty easily. :)
"My watch says 30 chickens" Google, 2018