attempt chatgpt emulator for display

This commit is contained in:
2025-07-03 11:41:54 -04:00
parent 8509b20109
commit e4405cc225
2 changed files with 42 additions and 10 deletions
+37 -6
View File
@@ -1,3 +1,4 @@
use log::trace;
use crate::address_mode::AddressMode;
use crate::constants::constants_isa_op::ISA_OP_NOP;
use crate::instruction::Instruction;
@@ -218,7 +219,7 @@ impl Mos6502Cpu {
}
_ => { 0x00 }
};
println!("READING FROM MEMORY AT 0x{offset:04x}");
trace!("READING FROM MEMORY AT 0x{offset:04x}");
self.memory[offset as usize]
// self.peek(offset);
}
@@ -299,7 +300,10 @@ impl Mos6502Cpu {
_ => {}
}
}
Operation::JSR => {}
Operation::JSR => {
// push pc to stack.
// jump to the subroutine.
}
Operation::LDA => {
match self.oi.mode {
AddressMode::Immediate => {
@@ -329,7 +333,6 @@ impl Mos6502Cpu {
_ => {}
}
}
AddressMode::ZeroPageY => {}
AddressMode::Absolute => {
if let Operand::Word(offset) = self.ir.operand {
println!("Loading from absolute address 0x{offset:04x}");
@@ -342,7 +345,11 @@ impl Mos6502Cpu {
self.a = self.memory[(offset + self.x as u16) as usize];
}
}
AddressMode::AbsoluteY => {}
AddressMode::AbsoluteY => {
if let Operand::Word(offset) = self.ir.operand {
self.a = self.memory[(offset + self.y as u16) as usize];
}
}
AddressMode::Indirect => {}
AddressMode::IndirectX => {}
AddressMode::IndirectY => {}
@@ -430,7 +437,16 @@ impl Mos6502Cpu {
}
}
}
AddressMode::AbsoluteY => {}
AddressMode::AbsoluteY => {
match self.ir.operand {
Operand::Word(offset) => {
self.memory[(offset + self.y as u16) as usize] = self.a;
}
_ => {
// Invalid Parameter
}
}
}
AddressMode::IndirectX => {}
AddressMode::IndirectY => {}
_ => {
@@ -600,7 +616,22 @@ mod test {
cpu.memory[0xbef0] = 0xab;
cpu.pc = 0x6000;
for _ in 0..=INSTRUCTION_CYCLES(ISA_OP_LDA_ABS) { cpu.tick(); }
for _ in 0..=INSTRUCTION_CYCLES(ISA_OP_LDA_ABSX) { cpu.tick(); }
assert_eq!(cpu.a, 0xab);
}
#[test]
fn lda_absolutey() {
let mut cpu = Mos6502Cpu::default();
cpu.memory[0x6000] = ISA_OP_LDA_ABSY;
cpu.memory[0x6001] = 0xef;
cpu.memory[0x6002] = 0xbe;
cpu.poke_y(0x01);
cpu.memory[0xbef0] = 0xab;
cpu.pc = 0x6000;
for _ in 0..=INSTRUCTION_CYCLES(ISA_OP_LDA_ABSY) { cpu.tick(); }
assert_eq!(cpu.a, 0xab);
}