diff --git a/src/core/gba.rs b/src/core/gba.rs index b80fe4e..21138b7 100644 --- a/src/core/gba.rs +++ b/src/core/gba.rs @@ -29,8 +29,9 @@ impl GameBoyAdvance { audio_device: Rc>, input_device: Rc>, ) -> GameBoyAdvance { + let gpu = Gpu::new(video_device.clone()); let sound_controller = SoundController::new(audio_device.clone()); - let io = IoDevices::new(sound_controller); + let io = IoDevices::new(gpu, sound_controller); GameBoyAdvance { cpu: cpu, sysbus: Box::new(SysBus::new(io, bios_rom, gamepak)), @@ -47,13 +48,10 @@ impl GameBoyAdvance { pub fn frame(&mut self) { self.key_poll(); - while self.sysbus.io.gpu.state != GpuState::VBlank { + while self.sysbus.io.gpu.vcount != DISPLAY_HEIGHT { self.step(); } - self.video_device - .borrow_mut() - .render(self.sysbus.io.gpu.get_framebuffer()); - while self.sysbus.io.gpu.state == GpuState::VBlank { + while self.sysbus.io.gpu.vcount == DISPLAY_HEIGHT { self.step(); } } diff --git a/src/core/gpu/mod.rs b/src/core/gpu/mod.rs index 5748637..143ecf5 100644 --- a/src/core/gpu/mod.rs +++ b/src/core/gpu/mod.rs @@ -1,7 +1,10 @@ +use std::cell::RefCell; +use std::rc::Rc; use std::fmt; use super::arm7tdmi::{Addr, Bus}; use super::*; +use crate::VideoInterface; use crate::bitfield::Bit; use crate::num::FromPrimitive; @@ -143,8 +146,12 @@ pub struct BgAffine { pub y: i32, } +type VideoDeviceRcRefCell = Rc>; + #[derive(DebugStub)] pub struct Gpu { + #[debug_stub = "video handle"] + video_device: VideoDeviceRcRefCell, pub state: GpuState, cycles: usize, @@ -174,8 +181,10 @@ pub struct Gpu { } impl Gpu { - pub fn new() -> Gpu { + pub fn new(video_device: VideoDeviceRcRefCell) -> Gpu { Gpu { + video_device: video_device, + dispcnt: DisplayControl(0x80), dispstat: DisplayStatus(0), bg: [Background::default(); 4], @@ -443,6 +452,7 @@ impl Gpu { irqs.set_LCD_VBlank(true); }; sb.io.dmac.notify_vblank(); + self.video_device.borrow_mut().render(&self.frame_buffer); } } } diff --git a/src/core/iodev.rs b/src/core/iodev.rs index 683b3f4..f231239 100644 --- a/src/core/iodev.rs +++ b/src/core/iodev.rs @@ -32,9 +32,9 @@ pub struct IoDevices { } impl IoDevices { - pub fn new(sound_controller: SoundController) -> IoDevices { + pub fn new(gpu: Gpu, sound_controller: SoundController) -> IoDevices { IoDevices { - gpu: Gpu::new(), + gpu: gpu, sound: sound_controller, timers: Timers::new(), dmac: DmaController::new(),