65816: Interrupting a Block Move ... and doing another block move?

Started by assassin, September 12, 2013, 07:00:19 AM

Previous topic - Next topic


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?



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.


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


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.


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