2019-07-06 23:33:54 +01:00
|
|
|
/// Struct containing everything
|
|
|
|
///
|
2019-07-06 13:53:36 +01:00
|
|
|
use super::arm7tdmi::{Core, DecodedInstruction};
|
|
|
|
use super::cartridge::Cartridge;
|
2019-07-06 23:33:54 +01:00
|
|
|
use super::dma::DmaChannel;
|
|
|
|
use super::ioregs::consts::*;
|
2019-07-06 13:53:36 +01:00
|
|
|
use super::lcd::Lcd;
|
|
|
|
use super::sysbus::SysBus;
|
2019-07-06 23:33:54 +01:00
|
|
|
|
2019-07-06 13:53:36 +01:00
|
|
|
use super::{EmuIoDev, GBAResult};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct GameBoyAdvance {
|
|
|
|
pub cpu: Core,
|
|
|
|
pub sysbus: SysBus,
|
|
|
|
|
|
|
|
// io devices
|
|
|
|
lcd: Lcd,
|
2019-07-06 23:33:54 +01:00
|
|
|
dma0: DmaChannel,
|
|
|
|
dma1: DmaChannel,
|
|
|
|
dma2: DmaChannel,
|
|
|
|
dma3: DmaChannel,
|
2019-07-06 13:53:36 +01:00
|
|
|
|
|
|
|
post_bool_flags: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GameBoyAdvance {
|
|
|
|
pub fn new(cpu: Core, bios_rom: Vec<u8>, gamepak: Cartridge) -> GameBoyAdvance {
|
|
|
|
let sysbus = SysBus::new(bios_rom, gamepak);
|
|
|
|
|
|
|
|
GameBoyAdvance {
|
|
|
|
cpu: cpu,
|
|
|
|
sysbus: sysbus,
|
|
|
|
|
|
|
|
lcd: Lcd::new(),
|
2019-07-06 23:33:54 +01:00
|
|
|
dma0: DmaChannel::new(REG_DMA0SAD, REG_DMA0DAD, REG_DMA0DAD),
|
|
|
|
dma1: DmaChannel::new(REG_DMA1SAD, REG_DMA1DAD, REG_DMA1DAD),
|
|
|
|
dma2: DmaChannel::new(REG_DMA2SAD, REG_DMA2DAD, REG_DMA2DAD),
|
|
|
|
dma3: DmaChannel::new(REG_DMA3SAD, REG_DMA3DAD, REG_DMA3DAD),
|
2019-07-06 13:53:36 +01:00
|
|
|
|
|
|
|
post_bool_flags: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn step(&mut self) -> GBAResult<DecodedInstruction> {
|
|
|
|
let previous_cycles = self.cpu.cycles;
|
|
|
|
let decoded = self.cpu.step_one(&mut self.sysbus)?;
|
2019-07-06 23:33:54 +01:00
|
|
|
|
|
|
|
// drop interrupts at the moment
|
|
|
|
let cycles = self.cpu.cycles - previous_cycles;
|
|
|
|
let (dma_cycles, _) = self.dma0.step(cycles, &mut self.sysbus);
|
|
|
|
let cycles = cycles + dma_cycles;
|
|
|
|
|
|
|
|
let cycles = self.cpu.cycles - previous_cycles;
|
|
|
|
let (dma_cycles, _) = self.dma1.step(cycles, &mut self.sysbus);
|
|
|
|
let cycles = cycles + dma_cycles;
|
|
|
|
|
|
|
|
let cycles = self.cpu.cycles - previous_cycles;
|
|
|
|
let (dma_cycles, _) = self.dma2.step(cycles, &mut self.sysbus);
|
|
|
|
let cycles = cycles + dma_cycles;
|
|
|
|
|
2019-07-06 13:53:36 +01:00
|
|
|
let cycles = self.cpu.cycles - previous_cycles;
|
2019-07-06 23:33:54 +01:00
|
|
|
let (dma_cycles, _) = self.dma3.step(cycles, &mut self.sysbus);
|
|
|
|
let cycles = cycles + dma_cycles;
|
2019-07-06 13:53:36 +01:00
|
|
|
|
2019-07-06 23:33:54 +01:00
|
|
|
let (lcd_cycles, _) = self.lcd.step(cycles, &mut self.sysbus);
|
2019-07-06 13:53:36 +01:00
|
|
|
|
|
|
|
Ok(decoded) // return the decoded instruction for the debugger
|
|
|
|
}
|
|
|
|
}
|