From c7a484fda5cb2c4f9bae92fbd1d87e396114a0a2 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Mon, 10 Feb 2020 23:45:53 +0200 Subject: [PATCH] Move creation of arm7tdmi core into the GameBoyAdvance Former-commit-id: d4a43df2ea3d737cc8284b84cea0285c8818ef32 --- src/core/gba.rs | 14 +++++++------- src/plat/minifb/main.rs | 10 ++++------ src/plat/sdl2/main.rs | 2 -- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/core/gba.rs b/src/core/gba.rs index fd4d51f..409d023 100644 --- a/src/core/gba.rs +++ b/src/core/gba.rs @@ -5,7 +5,7 @@ use std::rc::Rc; use bincode; use serde::{Deserialize, Serialize}; -use super::arm7tdmi::Core; +use super::arm7tdmi; use super::cartridge::Cartridge; use super::gpu::*; use super::interrupt::*; @@ -17,7 +17,7 @@ use super::super::{AudioInterface, InputInterface, VideoInterface}; pub struct GameBoyAdvance { pub sysbus: Box, - pub cpu: Core, + pub cpu: arm7tdmi::Core, video_device: Rc>, audio_device: Rc>, @@ -29,12 +29,11 @@ pub struct GameBoyAdvance { #[derive(Serialize, Deserialize)] struct SaveState { sysbus: Box, - cpu: Core, + cpu: arm7tdmi::Core, } impl GameBoyAdvance { pub fn new( - cpu: Core, bios_rom: Vec, gamepak: Cartridge, video_device: Rc>, @@ -46,9 +45,12 @@ impl GameBoyAdvance { audio_device.borrow().get_sample_rate() as f32, )); let io = IoDevices::new(gpu, sound_controller); + let sysbus = Box::new(SysBus::new(io, bios_rom, gamepak)); + let cpu = arm7tdmi::Core::new(); + GameBoyAdvance { cpu: cpu, - sysbus: Box::new(SysBus::new(io, bios_rom, gamepak)), + sysbus: sysbus, video_device: video_device, audio_device: audio_device, @@ -206,7 +208,6 @@ mod tests { fn make_mock_gba(rom: &[u8]) -> GameBoyAdvance { let bios = vec![0; 0x4000]; - let cpu = arm7tdmi::Core::new(); let cartridge = GamepakBuilder::new() .buffer(rom) .with_sram() @@ -215,7 +216,6 @@ mod tests { .unwrap(); let dummy = Rc::new(RefCell::new(DummyInterface::new())); let mut gba = GameBoyAdvance::new( - cpu, bios, cartridge, dummy.clone(), diff --git a/src/plat/minifb/main.rs b/src/plat/minifb/main.rs index 8e72076..6152734 100644 --- a/src/plat/minifb/main.rs +++ b/src/plat/minifb/main.rs @@ -91,11 +91,6 @@ fn main() { let bios_bin = read_bin_file(bios_path).unwrap(); let cart = GamepakBuilder::new().file(rom_path).build().unwrap(); - let mut cpu = arm7tdmi::Core::new(); - if skip_bios { - cpu.skip_bios(); - } - let cpu = cpu; let minifb = Rc::new(RefCell::new(MiniFb { window: Window::new( @@ -113,7 +108,6 @@ fn main() { let mut fps_counter = FpsCounter::default(); let mut gba = GameBoyAdvance::new( - cpu, bios_bin, cart, minifb.clone(), @@ -121,6 +115,10 @@ fn main() { minifb.clone(), ); + if skip_bios { + gba.skip_bios(); + } + let frame_time = time::Duration::new(0, 1_000_000_000u32 / 60); loop { let start_time = time::Instant::now(); diff --git a/src/plat/sdl2/main.rs b/src/plat/sdl2/main.rs index 1f94153..22bb6bc 100644 --- a/src/plat/sdl2/main.rs +++ b/src/plat/sdl2/main.rs @@ -135,7 +135,6 @@ fn main() -> Result<(), Box> { .build()?; let mut gba = GameBoyAdvance::new( - arm7tdmi::Core::new(), bios_bin, gamepak, video.clone(), @@ -243,7 +242,6 @@ fn main() -> Result<(), Box> { // create a new emulator - TODO, export to a function gba = GameBoyAdvance::new( - arm7tdmi::Core::new(), bios_bin, gamepak, video.clone(),