type params for camera work

This commit is contained in:
Alex Janka 2023-03-19 10:39:57 +11:00
parent db394d663a
commit efcd9877d8
3 changed files with 55 additions and 10 deletions

View file

@ -2,8 +2,8 @@ use async_ringbuf::AsyncHeapConsumer;
use futures::executor; use futures::executor;
use gb_emu_lib::{ use gb_emu_lib::{
connect::{ connect::{
AudioOutput, DownsampleType, EmulatorMessage, EmulatorOptions, JoypadButtons, RomFile, AudioOutput, DownsampleType, EmulatorMessage, EmulatorOptions, JoypadButtons, NoCamera,
SerialTarget, RomFile, SerialTarget,
}, },
EmulatorCore, EmulatorCore,
}; };
@ -52,7 +52,7 @@ struct EmuParams {
struct EmuVars { struct EmuVars {
rx: AsyncHeapConsumer<[f32; 2]>, rx: AsyncHeapConsumer<[f32; 2]>,
sender: Sender<EmulatorMessage>, sender: Sender<EmulatorMessage>,
emulator_core: EmulatorCore<[u8; 4], EmulatorRenderer>, emulator_core: EmulatorCore<[u8; 4], EmulatorRenderer, NoCamera>,
serial_tx: Sender<u8>, serial_tx: Sender<u8>,
} }

View file

@ -70,17 +70,27 @@ pub trait PocketCamera {
fn capture_greyscale(&mut self) -> [u8; 128 * 128]; fn capture_greyscale(&mut self) -> [u8; 128 * 128];
} }
pub struct NoCamera;
impl PocketCamera for NoCamera {
fn capture_greyscale(&mut self) -> [u8; 128 * 128] {
[0; 128 * 128]
}
}
#[non_exhaustive] #[non_exhaustive]
pub struct EmulatorOptions<ColourFormat, R> pub struct EmulatorOptions<ColourFormat, R, C>
where where
ColourFormat: From<Colour> + Clone, ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>, R: Renderer<ColourFormat>,
C: PocketCamera,
{ {
pub(crate) window: R, pub(crate) window: R,
pub(crate) tile_window: Option<R>, pub(crate) tile_window: Option<R>,
pub(crate) rom: RomFile, pub(crate) rom: RomFile,
pub(crate) output: AudioOutput, pub(crate) output: AudioOutput,
pub(crate) save_path: Option<String>, pub(crate) save_path: Option<String>,
pub(crate) camera: C,
pub(crate) no_save: bool, pub(crate) no_save: bool,
pub(crate) bootrom: Option<RomFile>, pub(crate) bootrom: Option<RomFile>,
pub(crate) serial_target: SerialTarget, pub(crate) serial_target: SerialTarget,
@ -88,7 +98,7 @@ where
spooky: PhantomData<ColourFormat>, spooky: PhantomData<ColourFormat>,
} }
impl<ColourFormat, R> EmulatorOptions<ColourFormat, R> impl<ColourFormat, R> EmulatorOptions<ColourFormat, R, NoCamera>
where where
ColourFormat: From<Colour> + Clone, ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>, R: Renderer<ColourFormat>,
@ -100,6 +110,30 @@ where
rom, rom,
output, output,
save_path: None, save_path: None,
camera: NoCamera,
no_save: false,
bootrom: None,
serial_target: SerialTarget::None,
verbose: false,
spooky: PhantomData,
}
}
}
impl<ColourFormat, R, C> EmulatorOptions<ColourFormat, R, C>
where
ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>,
C: PocketCamera,
{
pub fn new_with_camera(window: R, rom: RomFile, output: AudioOutput, camera: C) -> Self {
Self {
window,
tile_window: None,
rom,
output,
save_path: None,
camera,
no_save: false, no_save: false,
bootrom: None, bootrom: None,
serial_target: SerialTarget::None, serial_target: SerialTarget::None,

View file

@ -1,7 +1,9 @@
#![feature(exclusive_range_pattern, let_chains, bigint_helper_methods)] #![feature(exclusive_range_pattern, let_chains, bigint_helper_methods)]
use crate::{processor::memory::Memory, util::pause}; use crate::{processor::memory::Memory, util::pause};
use connect::{AudioOutput, EmulatorMessage, EmulatorOptions, Renderer, RomFile, SerialTarget}; use connect::{
AudioOutput, EmulatorMessage, EmulatorOptions, PocketCamera, Renderer, RomFile, SerialTarget,
};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use processor::{ use processor::{
memory::{mmio::gpu::Colour, Rom}, memory::{mmio::gpu::Colour, Rom},
@ -10,6 +12,7 @@ use processor::{
use std::{ use std::{
fs::{self}, fs::{self},
io::{stdout, Write}, io::{stdout, Write},
marker::PhantomData,
path::PathBuf, path::PathBuf,
process::exit, process::exit,
str::FromStr, str::FromStr,
@ -30,23 +33,26 @@ static VERBOSE: OnceCell<bool> = OnceCell::new();
pub const WIDTH: usize = 160; pub const WIDTH: usize = 160;
pub const HEIGHT: usize = 144; pub const HEIGHT: usize = 144;
pub struct EmulatorCore<ColourFormat, R> pub struct EmulatorCore<ColourFormat, R, C>
where where
ColourFormat: From<Colour> + Clone, ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>, R: Renderer<ColourFormat>,
C: PocketCamera,
{ {
receiver: Receiver<EmulatorMessage>, receiver: Receiver<EmulatorMessage>,
cpu: Cpu<ColourFormat, R>, cpu: Cpu<ColourFormat, R>,
spooky: PhantomData<C>,
} }
impl<ColourFormat, R> EmulatorCore<ColourFormat, R> impl<ColourFormat, R, C> EmulatorCore<ColourFormat, R, C>
where where
ColourFormat: From<Colour> + Clone, ColourFormat: From<Colour> + Clone,
R: Renderer<ColourFormat>, R: Renderer<ColourFormat>,
C: PocketCamera,
{ {
pub fn init( pub fn init(
receiver: Receiver<EmulatorMessage>, receiver: Receiver<EmulatorMessage>,
mut options: EmulatorOptions<ColourFormat, R>, mut options: EmulatorOptions<ColourFormat, R, C>,
) -> Self { ) -> Self {
if options.verbose { if options.verbose {
VERBOSE.set(true).unwrap(); VERBOSE.set(true).unwrap();
@ -109,7 +115,11 @@ where
} }
fn new(receiver: Receiver<EmulatorMessage>, cpu: Cpu<ColourFormat, R>) -> Self { fn new(receiver: Receiver<EmulatorMessage>, cpu: Cpu<ColourFormat, R>) -> Self {
Self { receiver, cpu } Self {
receiver,
cpu,
spooky: PhantomData,
}
} }
pub fn replace_output(&mut self, new: AudioOutput) { pub fn replace_output(&mut self, new: AudioOutput) {
@ -190,6 +200,7 @@ where
Self { Self {
receiver, receiver,
cpu: Cpu::from_save_state(state, data, window, output, serial_target), cpu: Cpu::from_save_state(state, data, window, output, serial_target),
spooky: PhantomData,
} }
} }
} }