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:
parent
118beeb4b7
commit
885bce2aa4
|
@ -29,8 +29,9 @@ impl GameBoyAdvance {
|
|||
audio_device: Rc<RefCell<dyn AudioInterface>>,
|
||||
input_device: Rc<RefCell<dyn InputInterface>>,
|
||||
) -> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RefCell<dyn VideoInterface>>;
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Reference in a new issue