34 lines
787 B
Rust
34 lines
787 B
Rust
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
use simplelog::info;
|
|
use crate::cpu::Cpu;
|
|
use crate::mappers::get_mapper;
|
|
use crate::memory::MemoryBus;
|
|
use crate::rom::{Rom, RomReadError};
|
|
|
|
pub struct System {
|
|
cpu: Cpu,
|
|
memory_bus: Rc<RefCell<MemoryBus>>,
|
|
}
|
|
|
|
impl System {
|
|
pub fn new() -> Self {
|
|
let memory_bus = Rc::new(RefCell::new(MemoryBus::new()));
|
|
let cpu = Cpu::new(Rc::clone(&memory_bus));
|
|
|
|
Self {
|
|
cpu,
|
|
memory_bus
|
|
}
|
|
}
|
|
|
|
pub fn insert_rom(&self, path: &str) -> Result<(), RomReadError> {
|
|
let rom = Rom::read(path)?;
|
|
let mapper = get_mapper(rom);
|
|
|
|
self.memory_bus.borrow_mut().register_mapper(mapper);
|
|
|
|
info!("Successfully inserted ROM into system");
|
|
Ok(())
|
|
}
|
|
} |