"""Block moves: MVN and MVP, one byte per step (rows 9a, 9b). Each byte is a whole pass: the opcode, both bank operands, a read at source,X, a write at destination,Y, two IO cycles at destination,Y; then X and Y step (8 bits when X = 1), C counts down in all 16 bits whatever M says, and while C has not wrapped to $FFFF the PC goes back to the opcode, so the next step refetches it and an interrupt can come between bytes (U6). DBR becomes the destination bank. """ from w65c816._core import DATA, X class BlockMixin: """Private block-move implementation.""" def _move(self, step: int) -> None: destination = self._fetch() source = self._fetch() self.dbr = destination value = self._cycle_read(source << 16 | self.x, DATA) target = destination << 16 | self.y self._cycle_write(target, value) self._io(target) self._io(target) mask = 0xFF if self.p & X else 0xFFFF self.x = (self.x + step) & mask self.y = (self.y + step) & mask count = self.a self.a = (count - 1) & 0xFFFF if count: self.pc = (self.pc - 3) & 0xFFFF def _op_mvn(self) -> None: """MVN -- move a byte, X and Y counting up (DS Table 5-5 p. 33).""" self._move(1) def _op_mvp(self) -> None: """MVP -- move a byte, X and Y counting down (DS Table 5-5 p. 33).""" self._move(-1)