// SPDX-License-Identifier: MIT //! Block moves: MVN and MVP, one byte per step (rows 9a, 9b) (`_block.py`). //! //! 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. //! //! Differences forced by Rust: none beyond the integer widths (the step is //! +1 or -1, applied with wrapping arithmetic before the reference's mask). use crate::core::{Bus, DATA, IO, W65C816, X}; impl W65C816 { fn move_byte(&mut self, step: i32) { let destination = self.fetch(); let source = self.fetch(); self.dbr = destination; let value = self.cycle_read((source as u32) << 16 | self.x as u32, DATA); let target = (destination as u32) << 16 | self.y as u32; self.cycle_write(target, value, DATA); self.io(target, IO); self.io(target, IO); let mask: u32 = if self.p & X != 0 { 0xFF } else { 0xFFFF }; self.x = ((self.x as u32).wrapping_add(step as u32) & mask) as u16; self.y = ((self.y as u32).wrapping_add(step as u32) & mask) as u16; let count = self.a; self.a = count.wrapping_sub(1); if count != 0 { self.pc = self.pc.wrapping_sub(3); } } /// MVN -- move a byte, X and Y counting up (DS Table 5-5 p. 33). pub(crate) fn op_mvn(&mut self) { self.move_byte(1); } /// MVP -- move a byte, X and Y counting down (DS Table 5-5 p. 33). pub(crate) fn op_mvp(&mut self) { self.move_byte(-1); } }