// SPDX-License-Identifier: MIT //! Loads, stores, register transfers and the index-register counts (`_loads.py`). //! //! LDA LDX LDY STA STX STY STZ, TAX TAY TXA TYA TSX TXS, INX INY DEX DEY. //! `STZ` is the 65C02's own (CL section 3); the rest are the 6502's, with the //! 65C02's bus cycles (the reference's docs/timing.md). //! //! Differences forced by Rust: a load receives its operand's value and a store //! its address (the dispatch has run the mode), where the Python handler //! calls `mode(self)` as its first statement; the cycles are the same. use crate::core::{Bus, Cmos65c02}; // Evidence tags (emulator-lineage docs/methodology.md): every result and flag // here is DOC (DS Table 6-4) and MEASURED (CAP: Dormann's tests, in lockstep // on both captured parts); every cycle is MEASURED (CAP). impl Cmos65c02 { /// LDA -- load A from memory (DS Table 6-4). pub(crate) fn op_lda(&mut self, operand: u8) { self.a = self.set_nz(operand); } /// LDX -- load X from memory (DS Table 6-4). pub(crate) fn op_ldx(&mut self, operand: u8) { self.x = self.set_nz(operand); } /// LDY -- load Y from memory (DS Table 6-4). pub(crate) fn op_ldy(&mut self, operand: u8) { self.y = self.set_nz(operand); } // A store computes its address first, in its own statement (see core, // "the same modes for an instruction that only reads"). /// STA -- store A in memory (DS Table 6-4). pub(crate) fn op_sta(&mut self, address: u16) { self.write(address, self.a); } /// STX -- store X in memory (DS Table 6-4). pub(crate) fn op_stx(&mut self, address: u16) { self.write(address, self.x); } /// STY -- store Y in memory (DS Table 6-4). pub(crate) fn op_sty(&mut self, address: u16) { self.write(address, self.y); } /// STZ -- store zero in memory (DS Table 6-4). pub(crate) fn op_stz(&mut self, address: u16) { self.write(address, 0x00); } // Each one-byte instruction is two cycles: the opcode, and a read of the // next byte that is dropped (CAP: 2 cycles, both reads). MEASURED. /// TAX -- transfer A to X (DS Table 6-4). pub(crate) fn op_tax(&mut self) { self.fetch_discard(); self.x = self.set_nz(self.a); } /// TAY -- transfer A to Y (DS Table 6-4). pub(crate) fn op_tay(&mut self) { self.fetch_discard(); self.y = self.set_nz(self.a); } /// TXA -- transfer X to A (DS Table 6-4). pub(crate) fn op_txa(&mut self) { self.fetch_discard(); self.a = self.set_nz(self.x); } /// TYA -- transfer Y to A (DS Table 6-4). pub(crate) fn op_tya(&mut self) { self.fetch_discard(); self.a = self.set_nz(self.y); } /// TSX -- transfer S to X (DS Table 6-4). pub(crate) fn op_tsx(&mut self) { self.fetch_discard(); self.x = self.set_nz(self.s); } /// TXS -- transfer X to S; no flag changes (DS Table 6-4). pub(crate) fn op_txs(&mut self) { self.fetch_discard(); self.s = self.x; } /// INX -- increment X (DS Table 6-4). pub(crate) fn op_inx(&mut self) { self.fetch_discard(); self.x = self.set_nz(self.x.wrapping_add(1)); } /// INY -- increment Y (DS Table 6-4). pub(crate) fn op_iny(&mut self) { self.fetch_discard(); self.y = self.set_nz(self.y.wrapping_add(1)); } /// DEX -- decrement X (DS Table 6-4). pub(crate) fn op_dex(&mut self) { self.fetch_discard(); self.x = self.set_nz(self.x.wrapping_sub(1)); } /// DEY -- decrement Y (DS Table 6-4). pub(crate) fn op_dey(&mut self) { self.fetch_discard(); self.y = self.set_nz(self.y.wrapping_sub(1)); } }