// SPDX-License-Identifier: MIT //! Bit instructions: SET1 CLR1 on `d.b`; TSET1 TCLR1 on `!a`; the carry-bit //! group on `m.b` (`_bit.py`). //! //! Differences forced by Rust: none beyond the integer types. use crate::core::{Bus, Spc700}; use crate::flags::FLAG_C; impl Spc700 { /// SET1/CLR1 d.b -- read, modify, write a direct-page bit (timing.md RMW direct). pub(crate) fn op_set1_clr1(&mut self, op: u8) { let target = self.fetch() as u32; let value = self.load(target); let mask = 1u8 << (op >> 5); self.store( target, if op & 0x10 != 0 { value & !mask } else { value | mask }, ); } /// TSET1 !a -- N Z as CMP A,(a) from the first read; the address is read twice (U6). pub(crate) fn op_tset1(&mut self, _op: u8) { let address = self.fetch_word(); let value = self.read(address); self.set_nz(self.a.wrapping_sub(value)); self.read_dummy(address); self.write(address, value | self.a); } /// TCLR1 !a -- N Z as CMP A,(a) from the first read; the address is read twice (U6). pub(crate) fn op_tclr1(&mut self, _op: u8) { let address = self.fetch_word(); let value = self.read(address); self.set_nz(self.a.wrapping_sub(value)); self.read_dummy(address); self.write(address, value & !self.a); } /// OR1 C -- C |= m.b, or its complement in the /m.b form $2A (timing.md OR1, U15). pub(crate) fn op_or1(&mut self, op: u8) { let (address, bit) = self.absolute_bit(); let mut value = self.read(address) >> bit & 1; self.idle(); // anomie 23: "cycle 5 only in EOR1 and OR1" if op == 0x2A { value ^= 1; } self.psw |= value; } /// AND1 C -- C &= m.b, or its complement in the /m.b form $6A (timing.md AND1, U15). pub(crate) fn op_and1(&mut self, op: u8) { let (address, bit) = self.absolute_bit(); let mut value = self.read(address) >> bit & 1; if op == 0x6A { value ^= 1; } if value == 0 { self.psw &= !FLAG_C; } } /// EOR1 C -- C ^= m.b (timing.md EOR1, U15). pub(crate) fn op_eor1(&mut self, _op: u8) { let (address, bit) = self.absolute_bit(); let value = self.read(address) >> bit & 1; self.idle(); // anomie 23 self.psw ^= value; } /// MOV1 C,m.b -- C = m.b (timing.md MOV1, U15). pub(crate) fn op_mov1_c_bit(&mut self, _op: u8) { let (address, bit) = self.absolute_bit(); let value = self.read(address) >> bit & 1; self.psw = self.psw & !FLAG_C | value; } /// MOV1 m.b,C -- m.b = C, an internal cycle before the write (timing.md MOV1, U15). pub(crate) fn op_mov1_bit_c(&mut self, _op: u8) { let (address, bit) = self.absolute_bit(); let value = self.read(address); self.idle(); let mask = 1u8 << bit; self.write( address, if self.psw & FLAG_C != 0 { value | mask } else { value & !mask }, ); } /// NOT1 m.b -- complement a bit; C stays (timing.md NOT1, U15). pub(crate) fn op_not1(&mut self, _op: u8) { let (address, bit) = self.absolute_bit(); let value = self.read(address); self.write(address, value ^ 1 << bit); } }