mirror of
https://github.com/FranLMSP/rultra64.git
synced 2026-01-01 07:51:34 -05:00
ROM loading
This commit is contained in:
816
Cargo.lock
generated
816
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,4 +6,5 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
eframe = "0.16.0"
|
||||
eframe = "0.16.0"
|
||||
rfd = "0.7"
|
||||
@@ -17,10 +17,20 @@ impl Emulator {
|
||||
pub fn new_hle() -> Self {
|
||||
Self {
|
||||
cpu: CPU::new_hle(),
|
||||
mmu: MMU::new_hle(),
|
||||
mmu: MMU::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reload(&mut self) {
|
||||
self.cpu = CPU::new();
|
||||
self.mmu = MMU::new();
|
||||
}
|
||||
|
||||
pub fn reload_hle(&mut self) {
|
||||
self.cpu = CPU::new_hle();
|
||||
self.mmu = MMU::new();
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
self.cpu.fetch_and_exec_opcode(&mut self.mmu);
|
||||
}
|
||||
@@ -28,4 +38,8 @@ impl Emulator {
|
||||
pub fn cpu(&self) -> &CPU {
|
||||
&self.cpu
|
||||
}
|
||||
|
||||
pub fn mut_mmu(&mut self) -> &mut MMU {
|
||||
&mut self.mmu
|
||||
}
|
||||
}
|
||||
12
src/gui.rs
12
src/gui.rs
@@ -24,7 +24,7 @@ pub struct EmulatorApp {
|
||||
impl Default for EmulatorApp {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
core: Emulator::new(),
|
||||
core: Emulator::new_hle(),
|
||||
selected_register: Register::CPU,
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,16 @@ impl epi::App for EmulatorApp {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
ui.menu_button("File", |ui| {
|
||||
if ui.button("Load ROM").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
let picked_path = path.display().to_string();
|
||||
if let Ok(rom) = crate::rom::ROM::new_from_filename(&picked_path) {
|
||||
let mut emulator_core = emulator_core.borrow_mut();
|
||||
emulator_core.reload_hle();
|
||||
emulator_core.mut_mmu().set_rom(rom);
|
||||
emulator_core.mut_mmu().hle_ipl();
|
||||
println!("ROM loaded!");
|
||||
}
|
||||
}
|
||||
}
|
||||
if ui.button("Quit").clicked() {
|
||||
frame.quit();
|
||||
|
||||
15
src/mmu.rs
15
src/mmu.rs
@@ -52,20 +52,21 @@ impl MMU {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_hle() -> Self {
|
||||
let mut mmu = Self::new();
|
||||
pub fn hle_ipl(&mut self) {
|
||||
// Skip IPL1 and IPL2
|
||||
for i in 0..0x1000 {
|
||||
let byte = mmu.read_virtual(0xB0000000 + i, 1);
|
||||
mmu.write_virtual(0xA4000000 + i, &byte);
|
||||
let byte = self.read_virtual(0xB0000000 + i, 1);
|
||||
self.write_virtual(0xA4000000 + i, &byte);
|
||||
}
|
||||
// Skip IPL3
|
||||
for i in 0..0x100000 {
|
||||
let byte = mmu.read_physical_byte(0x10001000 + i);
|
||||
mmu.write_physical_byte(0x00001000 + i, byte);
|
||||
let byte = self.read_physical_byte(0x10001000 + i);
|
||||
self.write_physical_byte(0x00001000 + i, byte);
|
||||
}
|
||||
}
|
||||
|
||||
mmu
|
||||
pub fn set_rom(&mut self, rom: ROM) {
|
||||
self.rom = rom;
|
||||
}
|
||||
|
||||
pub fn convert(address: i64) -> i64 {
|
||||
|
||||
Reference in New Issue
Block a user