pub enum AddressingMode {
Show 13 variants
Implied,
Accumulator,
Immediate,
ZeroPage,
ZeroPageX,
ZeroPageY,
Absolute,
AbsoluteX,
AbsoluteY,
Indirect,
IndexedIndirectX,
IndirectIndexedY,
Relative,
}Expand description
CPU Addressing Modes
Defines how an instruction’s operand is accessed.
Variants§
Implied
No operand (instruction operates on CPU state)
Example: NOP, CLC, DEX
Accumulator
Operand is the accumulator register
Example: ASL A, ROL A
Immediate
Operand is the next byte after the opcode
Example: LDA #$42 loads the value $42
ZeroPage
Operand is in zero page ($00-$FF)
Example: LDA $80 reads from address $0080
ZeroPageX
Zero page address + X register (wraps within zero page)
Example: LDA $80,X with X=$05 reads from $0085
ZeroPageY
Zero page address + Y register (wraps within zero page)
Example: LDX $80,Y with Y=$05 reads from $0085
Absolute
Operand is a 16-bit absolute address
Example: LDA $1234 reads from address $1234
AbsoluteX
Absolute address + X register
Example: LDA $1234,X with X=$10 reads from $1244
AbsoluteY
Absolute address + Y register
Example: LDA $1234,Y with Y=$10 reads from $1244
Indirect
Indirect addressing (JMP only)
Example: JMP ($1234) reads target address from $1234-$1235
IndexedIndirectX
Indexed Indirect: (Zero Page + X), then dereference
Example: LDA ($80,X) with X=$05:
- Calculate pointer address: $80 + $05 = $85
- Read pointer: [$85] = $20, [$86] = $30
- Read from $3020
IndirectIndexedY
Indirect Indexed: Dereference Zero Page, then + Y
Example: LDA ($80),Y with Y=$10:
- Read pointer: [$80] = $20, [$81] = $30
- Add Y: $3020 + $10 = $3030
- Read from $3030
Relative
Relative offset for branch instructions
Example: BNE $02 branches PC + 2 bytes forward
Implementations§
Source§impl AddressingMode
impl AddressingMode
Sourcepub const fn operand_bytes(self) -> u8
pub const fn operand_bytes(self) -> u8
Get the number of operand bytes for this addressing mode
§Returns
- 0 bytes: Implied, Accumulator
- 1 byte: Immediate, Zero Page variants, Indexed Indirect, Indirect Indexed, Relative
- 2 bytes: Absolute variants, Indirect
Sourcepub const fn can_page_cross(self) -> bool
pub const fn can_page_cross(self) -> bool
Check if this addressing mode can have a page crossing penalty
§Returns
true for:
- Absolute,X
- Absolute,Y
- (Indirect),Y
- Relative (branches)
Source§impl AddressingMode
Addressing mode implementations
impl AddressingMode
Addressing mode implementations
These methods are called during instruction execution to resolve operand addresses.
Sourcepub fn resolve(self, pc: u16, x: u8, y: u8, bus: &mut impl Bus) -> AddressResult
pub fn resolve(self, pc: u16, x: u8, y: u8, bus: &mut impl Bus) -> AddressResult
Resolve the effective address for this addressing mode
§Arguments
pc- Current program counter (AFTER opcode fetch)x- X register valuey- Y register valuebus- Memory bus for reading operands
§Returns
AddressResult containing the effective address and page crossing status
§Notes
- For
Immediate,addris the value itself - For
AccumulatorandImplied,addris unused - PC should point to the first operand byte
Trait Implementations§
Source§impl Clone for AddressingMode
impl Clone for AddressingMode
Source§fn clone(&self) -> AddressingMode
fn clone(&self) -> AddressingMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more