has microsteps in the UI decodes from a NOP only binary some basic instructions are starting to move data around
56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
use std::fs;
|
|
use std::fs::File;
|
|
use std::io::{BufReader, Read};
|
|
use std::path::Path;
|
|
use crate::parts::clock::Clock;
|
|
use core::mos6502cpu::Mos6502Cpu;
|
|
|
|
pub struct BenEaterPC {
|
|
clock: Clock,
|
|
// pub because i am rendering it.
|
|
// there should be a proper interface to get the data
|
|
// for ui out of this.
|
|
pub cpu: Mos6502Cpu,
|
|
}
|
|
|
|
impl BenEaterPC {
|
|
pub fn new() -> Self {
|
|
println!("New BENEATERPC");
|
|
BenEaterPC {
|
|
clock: Clock::new(),
|
|
cpu: Mos6502Cpu::default()
|
|
}
|
|
}
|
|
|
|
pub fn tick_system(&mut self) {
|
|
let (address, data, rw) = self.cpu.tick();
|
|
if self.cpu.microcode_step == 0 {
|
|
// tick the clock.
|
|
// tick the memory
|
|
// tick the VIA
|
|
} else {
|
|
self.cpu.tick();
|
|
}
|
|
}
|
|
|
|
pub fn load_rom(&mut self, rom_to_load: &str) {
|
|
println!("Preparing to load {rom_to_load}");
|
|
|
|
let file = File::open(rom_to_load).unwrap();
|
|
let mut reader = BufReader::new(file);
|
|
let mut chunks = Vec::new();
|
|
|
|
loop {
|
|
let mut buffer = vec![0u8; 1];
|
|
let bytes_read = reader.read(&mut buffer).unwrap_or(0);
|
|
if bytes_read == 0 {
|
|
break;
|
|
}
|
|
buffer.truncate(bytes_read);
|
|
chunks.push(buffer[0]);
|
|
}
|
|
println!("Loaded {}b of data.", chunks.len());
|
|
self.cpu.memory = chunks.into();
|
|
}
|
|
}
|