gpu: refactor: Give the Gpu a handle to the video device.

Use it to render to the screen instead of doing it in the outer Gba


Former-commit-id: ea1ed5f4d7b00d1542ce1130f96ccb1bdb87cb3e
This commit is contained in:
Michel Heily 2019-12-29 21:30:33 +02:00
parent 118beeb4b7
commit 885bce2aa4
3 changed files with 17 additions and 9 deletions

View file

@ -29,8 +29,9 @@ impl GameBoyAdvance {
audio_device: Rc<RefCell<dyn AudioInterface>>, audio_device: Rc<RefCell<dyn AudioInterface>>,
input_device: Rc<RefCell<dyn InputInterface>>, input_device: Rc<RefCell<dyn InputInterface>>,
) -> GameBoyAdvance { ) -> GameBoyAdvance {
let gpu = Gpu::new(video_device.clone());
let sound_controller = SoundController::new(audio_device.clone()); let sound_controller = SoundController::new(audio_device.clone());
let io = IoDevices::new(sound_controller); let io = IoDevices::new(gpu, sound_controller);
GameBoyAdvance { GameBoyAdvance {
cpu: cpu, cpu: cpu,
sysbus: Box::new(SysBus::new(io, bios_rom, gamepak)), sysbus: Box::new(SysBus::new(io, bios_rom, gamepak)),
@ -47,13 +48,10 @@ impl GameBoyAdvance {
pub fn frame(&mut self) { pub fn frame(&mut self) {
self.key_poll(); self.key_poll();
while self.sysbus.io.gpu.state != GpuState::VBlank { while self.sysbus.io.gpu.vcount != DISPLAY_HEIGHT {
self.step(); self.step();
} }
self.video_device while self.sysbus.io.gpu.vcount == DISPLAY_HEIGHT {
.borrow_mut()
.render(self.sysbus.io.gpu.get_framebuffer());
while self.sysbus.io.gpu.state == GpuState::VBlank {
self.step(); self.step();
} }
} }

View file

@ -1,7 +1,10 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::fmt; use std::fmt;
use super::arm7tdmi::{Addr, Bus}; use super::arm7tdmi::{Addr, Bus};
use super::*; use super::*;
use crate::VideoInterface;
use crate::bitfield::Bit; use crate::bitfield::Bit;
use crate::num::FromPrimitive; use crate::num::FromPrimitive;
@ -143,8 +146,12 @@ pub struct BgAffine {
pub y: i32, pub y: i32,
} }
type VideoDeviceRcRefCell = Rc<RefCell<dyn VideoInterface>>;
#[derive(DebugStub)] #[derive(DebugStub)]
pub struct Gpu { pub struct Gpu {
#[debug_stub = "video handle"]
video_device: VideoDeviceRcRefCell,
pub state: GpuState, pub state: GpuState,
cycles: usize, cycles: usize,
@ -174,8 +181,10 @@ pub struct Gpu {
} }
impl Gpu { impl Gpu {
pub fn new() -> Gpu { pub fn new(video_device: VideoDeviceRcRefCell) -> Gpu {
Gpu { Gpu {
video_device: video_device,
dispcnt: DisplayControl(0x80), dispcnt: DisplayControl(0x80),
dispstat: DisplayStatus(0), dispstat: DisplayStatus(0),
bg: [Background::default(); 4], bg: [Background::default(); 4],
@ -443,6 +452,7 @@ impl Gpu {
irqs.set_LCD_VBlank(true); irqs.set_LCD_VBlank(true);
}; };
sb.io.dmac.notify_vblank(); sb.io.dmac.notify_vblank();
self.video_device.borrow_mut().render(&self.frame_buffer);
} }
} }
} }

View file

@ -32,9 +32,9 @@ pub struct IoDevices {
} }
impl IoDevices { impl IoDevices {
pub fn new(sound_controller: SoundController) -> IoDevices { pub fn new(gpu: Gpu, sound_controller: SoundController) -> IoDevices {
IoDevices { IoDevices {
gpu: Gpu::new(), gpu: gpu,
sound: sound_controller, sound: sound_controller,
timers: Timers::new(), timers: Timers::new(),
dmac: DmaController::new(), dmac: DmaController::new(),