Move creation of arm7tdmi core into the GameBoyAdvance

Former-commit-id: d4a43df2ea3d737cc8284b84cea0285c8818ef32
This commit is contained in:
Michel Heily 2020-02-10 23:45:53 +02:00
parent 1a46bec3f9
commit c7a484fda5
3 changed files with 11 additions and 15 deletions

View file

@ -5,7 +5,7 @@ use std::rc::Rc;
use bincode; use bincode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::arm7tdmi::Core; use super::arm7tdmi;
use super::cartridge::Cartridge; use super::cartridge::Cartridge;
use super::gpu::*; use super::gpu::*;
use super::interrupt::*; use super::interrupt::*;
@ -17,7 +17,7 @@ use super::super::{AudioInterface, InputInterface, VideoInterface};
pub struct GameBoyAdvance { pub struct GameBoyAdvance {
pub sysbus: Box<SysBus>, pub sysbus: Box<SysBus>,
pub cpu: Core, pub cpu: arm7tdmi::Core,
video_device: Rc<RefCell<dyn VideoInterface>>, video_device: Rc<RefCell<dyn VideoInterface>>,
audio_device: Rc<RefCell<dyn AudioInterface>>, audio_device: Rc<RefCell<dyn AudioInterface>>,
@ -29,12 +29,11 @@ pub struct GameBoyAdvance {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct SaveState { struct SaveState {
sysbus: Box<SysBus>, sysbus: Box<SysBus>,
cpu: Core, cpu: arm7tdmi::Core,
} }
impl GameBoyAdvance { impl GameBoyAdvance {
pub fn new( pub fn new(
cpu: Core,
bios_rom: Vec<u8>, bios_rom: Vec<u8>,
gamepak: Cartridge, gamepak: Cartridge,
video_device: Rc<RefCell<dyn VideoInterface>>, video_device: Rc<RefCell<dyn VideoInterface>>,
@ -46,9 +45,12 @@ impl GameBoyAdvance {
audio_device.borrow().get_sample_rate() as f32, audio_device.borrow().get_sample_rate() as f32,
)); ));
let io = IoDevices::new(gpu, sound_controller); let io = IoDevices::new(gpu, sound_controller);
let sysbus = Box::new(SysBus::new(io, bios_rom, gamepak));
let cpu = arm7tdmi::Core::new();
GameBoyAdvance { GameBoyAdvance {
cpu: cpu, cpu: cpu,
sysbus: Box::new(SysBus::new(io, bios_rom, gamepak)), sysbus: sysbus,
video_device: video_device, video_device: video_device,
audio_device: audio_device, audio_device: audio_device,
@ -206,7 +208,6 @@ mod tests {
fn make_mock_gba(rom: &[u8]) -> GameBoyAdvance { fn make_mock_gba(rom: &[u8]) -> GameBoyAdvance {
let bios = vec![0; 0x4000]; let bios = vec![0; 0x4000];
let cpu = arm7tdmi::Core::new();
let cartridge = GamepakBuilder::new() let cartridge = GamepakBuilder::new()
.buffer(rom) .buffer(rom)
.with_sram() .with_sram()
@ -215,7 +216,6 @@ mod tests {
.unwrap(); .unwrap();
let dummy = Rc::new(RefCell::new(DummyInterface::new())); let dummy = Rc::new(RefCell::new(DummyInterface::new()));
let mut gba = GameBoyAdvance::new( let mut gba = GameBoyAdvance::new(
cpu,
bios, bios,
cartridge, cartridge,
dummy.clone(), dummy.clone(),

View file

@ -91,11 +91,6 @@ fn main() {
let bios_bin = read_bin_file(bios_path).unwrap(); let bios_bin = read_bin_file(bios_path).unwrap();
let cart = GamepakBuilder::new().file(rom_path).build().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 { let minifb = Rc::new(RefCell::new(MiniFb {
window: Window::new( window: Window::new(
@ -113,7 +108,6 @@ fn main() {
let mut fps_counter = FpsCounter::default(); let mut fps_counter = FpsCounter::default();
let mut gba = GameBoyAdvance::new( let mut gba = GameBoyAdvance::new(
cpu,
bios_bin, bios_bin,
cart, cart,
minifb.clone(), minifb.clone(),
@ -121,6 +115,10 @@ fn main() {
minifb.clone(), minifb.clone(),
); );
if skip_bios {
gba.skip_bios();
}
let frame_time = time::Duration::new(0, 1_000_000_000u32 / 60); let frame_time = time::Duration::new(0, 1_000_000_000u32 / 60);
loop { loop {
let start_time = time::Instant::now(); let start_time = time::Instant::now();

View file

@ -135,7 +135,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.build()?; .build()?;
let mut gba = GameBoyAdvance::new( let mut gba = GameBoyAdvance::new(
arm7tdmi::Core::new(),
bios_bin, bios_bin,
gamepak, gamepak,
video.clone(), video.clone(),
@ -243,7 +242,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// create a new emulator - TODO, export to a function // create a new emulator - TODO, export to a function
gba = GameBoyAdvance::new( gba = GameBoyAdvance::new(
arm7tdmi::Core::new(),
bios_bin, bios_bin,
gamepak, gamepak,
video.clone(), video.clone(),