get rid of camera type parameters propagating everywhere
This commit is contained in:
parent
9c2cbbd05a
commit
1eb9552615
|
@ -6,15 +6,15 @@ use camera::Webcam;
|
|||
use gb_emu_lib::{
|
||||
config::{NamedConfig, CONFIG_MANAGER},
|
||||
connect::{
|
||||
AudioOutput, CameraWrapper, CgbRomType, EmulatorMessage, EmulatorOptions, NoCamera, Rom,
|
||||
RomFile, SerialTarget, SramType,
|
||||
AudioOutput, CgbRomType, EmulatorMessage, EmulatorOptions, Rom, RomFile, SerialTarget,
|
||||
SramType,
|
||||
},
|
||||
EmulatorCore,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{mpsc::Receiver, Arc, Mutex, OnceLock},
|
||||
sync::{mpsc::Receiver, OnceLock},
|
||||
};
|
||||
use window::{RendererChannel, WindowManager, WindowType};
|
||||
|
||||
|
@ -94,16 +94,12 @@ impl RunOptions {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct PreparedEmulator<C>
|
||||
where
|
||||
C: gb_emu_lib::connect::PocketCamera,
|
||||
{
|
||||
pub struct PreparedEmulator {
|
||||
scale_override: usize,
|
||||
shader_path: Option<PathBuf>,
|
||||
resizable: bool,
|
||||
rom: Rom<C>,
|
||||
rom: Rom,
|
||||
receiver: Receiver<EmulatorMessage<[u8; 4]>>,
|
||||
camera: Arc<Mutex<CameraWrapper<C>>>,
|
||||
serial: SerialTarget,
|
||||
tile_window: bool,
|
||||
layer_window: bool,
|
||||
|
@ -112,15 +108,13 @@ where
|
|||
pub fn prepare(
|
||||
options: RunOptions,
|
||||
receiver: Receiver<EmulatorMessage<[u8; 4]>>,
|
||||
) -> PreparedEmulator<NoCamera> {
|
||||
) -> PreparedEmulator {
|
||||
let config = CONFIG_MANAGER.load_or_create_base_config();
|
||||
let standalone_config: StandaloneConfig = CONFIG_MANAGER.load_or_create_config();
|
||||
|
||||
let rom_file = RomFile::Path(options.rom);
|
||||
|
||||
let (rom, camera) = rom_file
|
||||
.load(options.save, NoCamera::default())
|
||||
.expect("Error parsing rom");
|
||||
let rom = rom_file.load(options.save).expect("Error parsing rom");
|
||||
|
||||
let configs = CONFIGS.get_or_init(|| Configs {
|
||||
standalone_config,
|
||||
|
@ -161,7 +155,6 @@ pub fn prepare(
|
|||
resizable,
|
||||
rom,
|
||||
receiver,
|
||||
camera,
|
||||
serial: options.serial,
|
||||
tile_window: options.tile_window,
|
||||
layer_window: options.layer_window,
|
||||
|
@ -169,10 +162,10 @@ pub fn prepare(
|
|||
}
|
||||
|
||||
pub fn run<W>(
|
||||
prepared: PreparedEmulator<NoCamera>,
|
||||
prepared: PreparedEmulator,
|
||||
window_manager: &mut W,
|
||||
output: AudioOutput,
|
||||
) -> EmulatorCore<[u8; 4], NoCamera>
|
||||
) -> EmulatorCore<[u8; 4]>
|
||||
where
|
||||
W: WindowManager,
|
||||
{
|
||||
|
@ -226,7 +219,7 @@ where
|
|||
// EmulatorTypes::Normal(core)
|
||||
// };
|
||||
|
||||
EmulatorCore::init(true, prepared.receiver, emulator_options, prepared.camera)
|
||||
EmulatorCore::init(true, prepared.receiver, emulator_options)
|
||||
}
|
||||
|
||||
pub fn new_tile_window<W>(window_manager: &mut W) -> RendererChannel
|
||||
|
|
|
@ -5,7 +5,7 @@ use gb_emu_lib::{
|
|||
config::CONFIG_MANAGER,
|
||||
connect::{
|
||||
AudioOutput, CgbRomType, DownsampleType, EmulatorCoreTrait, EmulatorMessage,
|
||||
EmulatorOptions, NoCamera, RendererMessage, RomFile, SerialTarget,
|
||||
EmulatorOptions, RendererMessage, RomFile, SerialTarget,
|
||||
},
|
||||
EmulatorCore, HEIGHT, WIDTH,
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ struct EmuParams {
|
|||
|
||||
struct EmuVars {
|
||||
rx: AsyncHeapConsumer<[f32; 2]>,
|
||||
emulator_core: EmulatorCore<[u8; 4], NoCamera>,
|
||||
emulator_core: EmulatorCore<[u8; 4]>,
|
||||
serial_tx: Sender<u8>,
|
||||
}
|
||||
|
||||
|
@ -276,11 +276,11 @@ impl Plugin for GameboyEmu {
|
|||
let configs = access_config();
|
||||
let rom_path = configs.config_dir.join(configs.vst_config.rom.clone());
|
||||
|
||||
let (rom, camera) = RomFile::Path(rom_path)
|
||||
.load(gb_emu_lib::connect::SramType::None, NoCamera::default())
|
||||
let rom = RomFile::Path(rom_path)
|
||||
.load(gb_emu_lib::connect::SramType::None)
|
||||
.unwrap_or_else(|_v| {
|
||||
RomFile::Raw(include_bytes!("../error.gb").to_vec())
|
||||
.load(gb_emu_lib::connect::SramType::None, NoCamera::default())
|
||||
.load(gb_emu_lib::connect::SramType::None)
|
||||
.expect("Couldn't load built-in fallback rom")
|
||||
});
|
||||
|
||||
|
@ -323,7 +323,7 @@ impl Plugin for GameboyEmu {
|
|||
.with_sram_buffer(self.params.sram_save.state.clone())
|
||||
.with_show_bootrom(!will_skip_bootrom);
|
||||
|
||||
EmulatorCore::init(false, receiver, options, camera)
|
||||
EmulatorCore::init(false, receiver, options)
|
||||
};
|
||||
|
||||
emulator_core.run_until_buffer_full();
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use std::fs;
|
||||
use std::marker::PhantomData;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
pub use crate::processor::memory::mmio::gpu::Colour;
|
||||
pub use crate::processor::memory::mmio::joypad::{JoypadButtons, JoypadState};
|
||||
|
@ -38,17 +37,7 @@ pub enum RomFile {
|
|||
}
|
||||
|
||||
impl RomFile {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn load<C>(
|
||||
self,
|
||||
save: SramType,
|
||||
camera: C,
|
||||
) -> Result<(Rom<C>, Arc<Mutex<CameraWrapper<C>>>), std::io::Error>
|
||||
where
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
let camera: CameraWrapperRef<C> = Arc::new(Mutex::new(CameraWrapper::new(camera)));
|
||||
|
||||
pub fn load(self, save: SramType) -> Result<Rom, std::io::Error> {
|
||||
match self {
|
||||
RomFile::Path(path) => {
|
||||
let save_location = match save {
|
||||
|
@ -58,7 +47,7 @@ impl RomFile {
|
|||
SramType::None => None,
|
||||
};
|
||||
|
||||
fs::read(path).map(|data| Rom::load(data, save_location, camera.clone()))
|
||||
fs::read(path).map(|data| Rom::load(data, save_location))
|
||||
}
|
||||
RomFile::Raw(data) => {
|
||||
let save_location = match save {
|
||||
|
@ -67,10 +56,9 @@ impl RomFile {
|
|||
SramType::Auto => None,
|
||||
SramType::None => None,
|
||||
};
|
||||
Ok(Rom::load(data, save_location, camera.clone()))
|
||||
Ok(Rom::load(data, save_location))
|
||||
}
|
||||
}
|
||||
.map(|v| (v, camera))
|
||||
}
|
||||
|
||||
pub fn load_data(self) -> Result<Vec<u8>, std::io::Error> {
|
||||
|
@ -168,8 +156,6 @@ impl PocketCamera for NoCamera {
|
|||
fn init(&mut self) {}
|
||||
}
|
||||
|
||||
pub(crate) type CameraWrapperRef<C> = Arc<Mutex<CameraWrapper<C>>>;
|
||||
|
||||
pub struct CameraWrapper<C>
|
||||
where
|
||||
C: PocketCamera,
|
||||
|
@ -183,6 +169,7 @@ impl<C> CameraWrapper<C>
|
|||
where
|
||||
C: PocketCamera,
|
||||
{
|
||||
#[allow(unused)]
|
||||
pub(crate) fn new(camera: C) -> Self {
|
||||
Self {
|
||||
inner: camera,
|
||||
|
@ -195,6 +182,7 @@ where
|
|||
self.counter > 0
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn tick(&mut self, steps: usize) {
|
||||
if self.counter > 0 {
|
||||
self.counter = match self.counter.checked_sub(steps) {
|
||||
|
@ -226,15 +214,14 @@ pub enum SramType {
|
|||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
pub struct EmulatorOptions<ColourFormat, C>
|
||||
pub struct EmulatorOptions<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
pub(crate) tile_window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
pub(crate) layer_window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
pub(crate) rom: Rom<C>,
|
||||
pub(crate) rom: Rom,
|
||||
pub(crate) output: AudioOutput,
|
||||
pub(crate) save: Option<SramType>,
|
||||
|
||||
|
@ -244,17 +231,15 @@ where
|
|||
pub(crate) no_output: bool,
|
||||
pub(crate) serial_target: SerialTarget,
|
||||
pub(crate) cgb_mode: bool,
|
||||
_spooky: PhantomData<ColourFormat>,
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> EmulatorOptions<ColourFormat, C>
|
||||
impl<ColourFormat> EmulatorOptions<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub fn new(
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
rom: Rom<C>,
|
||||
rom: Rom,
|
||||
output: AudioOutput,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -270,7 +255,6 @@ where
|
|||
no_output: false,
|
||||
serial_target: SerialTarget::None,
|
||||
cgb_mode: true,
|
||||
_spooky: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +263,7 @@ where
|
|||
config: crate::config::Config,
|
||||
config_dir: PathBuf,
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
rom: Rom<C>,
|
||||
rom: Rom,
|
||||
output: AudioOutput,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -301,7 +285,6 @@ where
|
|||
no_output: false,
|
||||
serial_target: SerialTarget::None,
|
||||
cgb_mode: config.prefer_cgb,
|
||||
_spooky: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
#![feature(exclusive_range_pattern, let_chains, bigint_helper_methods)]
|
||||
|
||||
use crate::processor::{memory::Memory, Flags};
|
||||
use connect::{
|
||||
AudioOutput, CameraWrapper, EmulatorCoreTrait, EmulatorMessage, EmulatorOptions, PocketCamera,
|
||||
RomFile,
|
||||
};
|
||||
use connect::{AudioOutput, EmulatorCoreTrait, EmulatorMessage, EmulatorOptions, RomFile};
|
||||
use processor::{
|
||||
memory::{mmio::gpu::Colour, rom::CgbRomType, OutputTargets},
|
||||
Cpu,
|
||||
};
|
||||
use std::{
|
||||
marker::PhantomData,
|
||||
sync::{mpsc::Receiver, Arc, Mutex},
|
||||
};
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
#[cfg(all(feature = "vulkan", feature = "pixels"))]
|
||||
compile_error!("select only one rendering backend!");
|
||||
|
@ -33,27 +27,23 @@ pub mod util;
|
|||
pub const WIDTH: usize = 160;
|
||||
pub const HEIGHT: usize = 144;
|
||||
|
||||
pub struct EmulatorCore<ColourFormat, C>
|
||||
pub struct EmulatorCore<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
receiver: Receiver<EmulatorMessage<ColourFormat>>,
|
||||
cpu: Cpu<ColourFormat, C>,
|
||||
cpu: Cpu<ColourFormat>,
|
||||
paused: bool,
|
||||
spooky: PhantomData<C>,
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> EmulatorCore<ColourFormat, C>
|
||||
impl<ColourFormat> EmulatorCore<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub fn init(
|
||||
paused: bool,
|
||||
receiver: Receiver<EmulatorMessage<ColourFormat>>,
|
||||
options: EmulatorOptions<ColourFormat, C>,
|
||||
camera: Arc<Mutex<CameraWrapper<C>>>,
|
||||
options: EmulatorOptions<ColourFormat>,
|
||||
) -> Self {
|
||||
let rom = options.rom;
|
||||
|
||||
|
@ -103,7 +93,6 @@ where
|
|||
options.serial_target,
|
||||
options.tile_window,
|
||||
options.layer_window,
|
||||
camera,
|
||||
),
|
||||
),
|
||||
options.show_bootrom,
|
||||
|
@ -115,13 +104,12 @@ where
|
|||
fn new(
|
||||
paused: bool,
|
||||
receiver: Receiver<EmulatorMessage<ColourFormat>>,
|
||||
cpu: Cpu<ColourFormat, C>,
|
||||
cpu: Cpu<ColourFormat>,
|
||||
) -> Self {
|
||||
Self {
|
||||
receiver,
|
||||
cpu,
|
||||
paused,
|
||||
spooky: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,10 +180,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> EmulatorCoreTrait for EmulatorCore<ColourFormat, C>
|
||||
impl<ColourFormat> EmulatorCoreTrait for EmulatorCore<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
fn replace_output(&mut self, new: AudioOutput) {
|
||||
self.cpu.memory.replace_output(new);
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
pub mod primitives;
|
||||
|
||||
use crate::{
|
||||
connect::PocketCamera,
|
||||
processor::{memory::mmio::gpu::Colour, Cpu, Direction, Flags, Reg8, SplitRegister},
|
||||
util::{clear_bit, get_bit, set_bit},
|
||||
};
|
||||
|
||||
impl<ColourFormat, C> Cpu<ColourFormat, C>
|
||||
impl<ColourFormat> Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn and(&mut self, first: u8, second: u8) -> u8 {
|
||||
let result = first & second;
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use crate::{
|
||||
connect::PocketCamera,
|
||||
processor::{memory::mmio::gpu::Colour, Cpu, Direction, Flags, SplitRegister},
|
||||
util::{as_signed, get_bit, get_rotation_carry, rotate, Nibbles},
|
||||
};
|
||||
use std::ops::{BitAnd, BitOr};
|
||||
|
||||
impl<ColourFormat, C> Cpu<ColourFormat, C>
|
||||
impl<ColourFormat> Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn pop_word(&mut self) -> u16 {
|
||||
let mut word: u16 = 0x0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{marker::PhantomData, sync::mpsc::Sender};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub use self::rom::Rom;
|
||||
use self::{
|
||||
|
@ -10,9 +10,7 @@ use self::{
|
|||
},
|
||||
};
|
||||
use crate::{
|
||||
connect::{
|
||||
AudioOutput, CameraWrapperRef, JoypadState, PocketCamera, RendererMessage, SerialTarget,
|
||||
},
|
||||
connect::{AudioOutput, JoypadState, RendererMessage, SerialTarget},
|
||||
Cpu,
|
||||
};
|
||||
|
||||
|
@ -87,13 +85,12 @@ struct CgbPeripherals {
|
|||
double_speed: DoubleSpeed,
|
||||
}
|
||||
|
||||
pub struct Memory<ColourFormat, C>
|
||||
pub struct Memory<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
bootrom: Option<Vec<u8>>,
|
||||
rom: Rom<C>,
|
||||
rom: Rom,
|
||||
ram: Wram,
|
||||
cpu_ram: [u8; 128],
|
||||
pub(super) interrupts: Interrupts,
|
||||
|
@ -106,28 +103,23 @@ where
|
|||
apu: Apu,
|
||||
serial: Serial,
|
||||
timers: Timer,
|
||||
camera: CameraWrapperRef<C>,
|
||||
cgb_peripherals: Option<CgbPeripherals>,
|
||||
}
|
||||
|
||||
pub(crate) struct OutputTargets<ColourFormat, C>
|
||||
pub(crate) struct OutputTargets<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
audio: AudioOutput,
|
||||
serial_target: SerialTarget,
|
||||
tile_window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
layer_window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
camera: CameraWrapperRef<C>,
|
||||
_phantom: PhantomData<ColourFormat>,
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> OutputTargets<ColourFormat, C>
|
||||
impl<ColourFormat> OutputTargets<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn new(
|
||||
window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
|
@ -135,7 +127,6 @@ where
|
|||
serial_target: SerialTarget,
|
||||
tile_window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
layer_window: Option<Sender<RendererMessage<ColourFormat>>>,
|
||||
camera: CameraWrapperRef<C>,
|
||||
) -> Self {
|
||||
Self {
|
||||
window,
|
||||
|
@ -143,22 +134,19 @@ where
|
|||
serial_target,
|
||||
tile_window,
|
||||
layer_window,
|
||||
camera,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> Memory<ColourFormat, C>
|
||||
impl<ColourFormat> Memory<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn init(
|
||||
cgb: bool,
|
||||
bootrom: Vec<u8>,
|
||||
rom: Rom<C>,
|
||||
output: OutputTargets<ColourFormat, C>,
|
||||
rom: Rom,
|
||||
output: OutputTargets<ColourFormat>,
|
||||
) -> Self {
|
||||
Self {
|
||||
bootrom: Some(bootrom),
|
||||
|
@ -175,7 +163,6 @@ where
|
|||
apu: Apu::new(output.audio),
|
||||
serial: Serial::new(output.serial_target),
|
||||
timers: Timer::init(),
|
||||
camera: output.camera,
|
||||
cgb_peripherals: if cgb {
|
||||
Some(CgbPeripherals::default())
|
||||
} else {
|
||||
|
@ -428,10 +415,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> Cpu<ColourFormat, C>
|
||||
impl<ColourFormat> Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub fn increment_timers(&mut self, machine_cycles: usize) {
|
||||
self.increment_timers_div_optional(machine_cycles, true);
|
||||
|
@ -448,8 +434,6 @@ where
|
|||
|
||||
self.memory.oam_dma_tick(steps);
|
||||
|
||||
self.memory.camera.lock().unwrap().tick(steps);
|
||||
|
||||
let timer_return = self
|
||||
.memory
|
||||
.timers
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
use crate::{
|
||||
connect::PocketCamera,
|
||||
processor::memory::{mmio::gpu::Colour, Memory},
|
||||
};
|
||||
use crate::processor::memory::{mmio::gpu::Colour, Memory};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Clone, Copy)]
|
||||
|
@ -20,10 +17,9 @@ impl DoubleSpeed {
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> Memory<ColourFormat, C>
|
||||
impl<ColourFormat> Memory<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn is_double_speed(&self) -> bool {
|
||||
self.cgb_peripherals
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{
|
||||
connect::PocketCamera,
|
||||
processor::{
|
||||
memory::{
|
||||
addresses::{AddressMarker, VramDmaAddress},
|
||||
|
@ -80,10 +79,9 @@ impl VramDma {
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> Memory<ColourFormat, C>
|
||||
impl<ColourFormat> Memory<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn vram_dma_tick(&mut self) -> usize {
|
||||
let mut copy = None;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
use super::gpu::Colour;
|
||||
use crate::{
|
||||
connect::PocketCamera,
|
||||
processor::{memory::Memory, SplitRegister},
|
||||
};
|
||||
use crate::processor::{memory::Memory, SplitRegister};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy)]
|
||||
|
@ -35,10 +32,9 @@ impl OamDma {
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> Memory<ColourFormat, C>
|
||||
impl<ColourFormat> Memory<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn oam_dma_tick(&mut self, steps: usize) {
|
||||
for _ in 0..steps {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use self::{
|
||||
mbcs::{Mbc, Mbc1, Mbc2, Mbc3, Mbc5, None, PocketCamera},
|
||||
mbcs::{Mbc, Mbc1, Mbc2, Mbc3, Mbc5, None},
|
||||
sram_save::SaveDataLocation,
|
||||
};
|
||||
use crate::connect::{CameraWrapperRef, PocketCamera as PocketCameraTrait};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{marker::PhantomData, str::from_utf8};
|
||||
use std::str::from_utf8;
|
||||
|
||||
use super::addresses::{CartRamAddress, RomAddress};
|
||||
|
||||
|
@ -18,25 +17,14 @@ pub enum CgbRomType {
|
|||
CgbOnly,
|
||||
}
|
||||
|
||||
pub struct Rom<C>
|
||||
where
|
||||
C: PocketCameraTrait,
|
||||
{
|
||||
pub struct Rom {
|
||||
title: String,
|
||||
mbc: Box<dyn Mbc>,
|
||||
pub rom_type: CgbRomType,
|
||||
spooky: PhantomData<C>,
|
||||
}
|
||||
|
||||
impl<C> Rom<C>
|
||||
where
|
||||
C: PocketCameraTrait + Send + 'static,
|
||||
{
|
||||
pub(crate) fn load(
|
||||
data: Vec<u8>,
|
||||
sram_location: Option<SaveDataLocation>,
|
||||
camera: CameraWrapperRef<C>,
|
||||
) -> Self {
|
||||
impl Rom {
|
||||
pub(crate) fn load(data: Vec<u8>, sram_location: Option<SaveDataLocation>) -> Self {
|
||||
let mut title_length = 0x143;
|
||||
for (i, val) in data.iter().enumerate().take(0x143).skip(0x134) {
|
||||
title_length = i;
|
||||
|
@ -71,20 +59,13 @@ where
|
|||
0x1C => Box::new(Mbc5::init(data, rom_size, 0, true, None)),
|
||||
0x1D => Box::new(Mbc5::init(data, rom_size, ram_size, true, None)),
|
||||
0x1E => Box::new(Mbc5::init(data, rom_size, ram_size, true, sram_location)),
|
||||
0xFC => Box::new(PocketCamera::init(
|
||||
data,
|
||||
rom_size,
|
||||
ram_size,
|
||||
sram_location,
|
||||
camera,
|
||||
)),
|
||||
0xFC => todo!(),
|
||||
_ => panic!("unimplemented mbc: {:#X}", data[0x147]),
|
||||
};
|
||||
Self {
|
||||
title,
|
||||
mbc,
|
||||
rom_type,
|
||||
spooky: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ pub use mbc2::Mbc2;
|
|||
pub use mbc3::Mbc3;
|
||||
pub use mbc5::Mbc5;
|
||||
pub use none::None;
|
||||
pub use pocketcamera::PocketCamera;
|
||||
|
||||
pub(super) const KB: usize = 1024;
|
||||
const ROM_BANK_SIZE: usize = 16 * KB;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::{ram_size_kb, rom_banks, Mbc, KB, RAM_BANK_SIZE, ROM_BANK_SIZE};
|
||||
use crate::{
|
||||
connect::{CameraWrapperRef, PocketCamera as PocketCameraTrait},
|
||||
connect::{CameraWrapper, PocketCamera as PocketCameraTrait},
|
||||
processor::memory::{
|
||||
addresses::{AddressMarker, CartRamAddress, RomAddress},
|
||||
rom::sram_save::{BufferedSramTrait, MaybeBufferedSram, SaveDataLocation},
|
||||
|
@ -23,7 +23,7 @@ where
|
|||
ram_bank: RamBank,
|
||||
ram_size: usize,
|
||||
ram_enabled: bool,
|
||||
camera: CameraWrapperRef<C>,
|
||||
camera: CameraWrapper<C>,
|
||||
extra_bits_a000: u8,
|
||||
camera_ram: [u8; 53],
|
||||
}
|
||||
|
@ -32,15 +32,16 @@ impl<C> PocketCamera<C>
|
|||
where
|
||||
C: PocketCameraTrait,
|
||||
{
|
||||
#[allow(unused)]
|
||||
pub(crate) fn init(
|
||||
data: Vec<u8>,
|
||||
rom_size: u8,
|
||||
ram_size: u8,
|
||||
save_file: Option<SaveDataLocation>,
|
||||
camera: CameraWrapperRef<C>,
|
||||
mut camera: CameraWrapper<C>,
|
||||
) -> Self {
|
||||
let ram = ram_size_kb(ram_size).map(|s| MaybeBufferedSram::new(save_file, s * KB));
|
||||
camera.lock().unwrap().inner.init();
|
||||
camera.inner.init();
|
||||
Self {
|
||||
data,
|
||||
rom_bank: 1,
|
||||
|
@ -71,13 +72,7 @@ where
|
|||
|
||||
fn get_cam_reg(&self, address: CartRamAddress) -> u8 {
|
||||
match address.inner() {
|
||||
0xA000 => {
|
||||
(if self.camera.lock().unwrap().is_capturing() {
|
||||
0x1
|
||||
} else {
|
||||
0x0
|
||||
}) | self.extra_bits_a000
|
||||
}
|
||||
0xA000 => (if self.camera.is_capturing() { 0x1 } else { 0x0 }) | self.extra_bits_a000,
|
||||
0xA001..=0xA035 => self.camera_ram[(address.inner() - 0xA001) as usize],
|
||||
_ => 0x00,
|
||||
}
|
||||
|
@ -87,7 +82,7 @@ where
|
|||
match address.inner() {
|
||||
0xA000 => {
|
||||
if data & 0x1 == 0x1 {
|
||||
self.camera.lock().unwrap().begin_capture();
|
||||
self.camera.begin_capture();
|
||||
}
|
||||
self.extra_bits_a000 = data & 0b110;
|
||||
}
|
||||
|
@ -99,7 +94,7 @@ where
|
|||
}
|
||||
|
||||
fn check_for_new_image(&mut self) {
|
||||
if let Some(image) = self.camera.lock().unwrap().get_next() {
|
||||
if let Some(image) = self.camera.get_next() {
|
||||
if let Some(ram) = &mut self.ram {
|
||||
for (i, v) in image.iter().enumerate() {
|
||||
ram.set(0x100 + i, *v);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use self::memory::{mmio::gpu::Colour, Interrupt, Memory};
|
||||
use crate::connect::{JoypadState, PocketCamera};
|
||||
use crate::connect::JoypadState;
|
||||
|
||||
mod instructions;
|
||||
pub mod memory;
|
||||
|
@ -20,12 +20,11 @@ pub(crate) enum Direction {
|
|||
Right,
|
||||
}
|
||||
|
||||
pub struct Cpu<ColourFormat, C>
|
||||
pub struct Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub memory: Memory<ColourFormat, C>,
|
||||
pub memory: Memory<ColourFormat>,
|
||||
pub reg: Registers,
|
||||
pub last_instruction: u8,
|
||||
pub last_instruction_addr: u16,
|
||||
|
@ -37,12 +36,11 @@ where
|
|||
pub(super) next_joypad_state: Option<JoypadState>,
|
||||
}
|
||||
|
||||
impl<ColourFormat, C> Cpu<ColourFormat, C>
|
||||
impl<ColourFormat> Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub(crate) fn new(memory: Memory<ColourFormat, C>, run_bootrom: bool, no_output: bool) -> Self {
|
||||
pub(crate) fn new(memory: Memory<ColourFormat>, run_bootrom: bool, no_output: bool) -> Self {
|
||||
Self {
|
||||
memory,
|
||||
reg: Registers::init(),
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{
|
||||
connect::PocketCamera,
|
||||
processor::{
|
||||
instructions::{res, set},
|
||||
Cpu, Flags, Reg8, SplitRegister,
|
||||
|
@ -9,10 +8,9 @@ use crate::{
|
|||
|
||||
use super::memory::mmio::gpu::Colour;
|
||||
|
||||
impl<ColourFormat, C> Cpu<ColourFormat, C>
|
||||
impl<ColourFormat> Cpu<ColourFormat>
|
||||
where
|
||||
ColourFormat: From<Colour> + Copy,
|
||||
C: PocketCamera + Send + 'static,
|
||||
{
|
||||
pub fn run_opcode(&mut self, opcode: u8) -> usize {
|
||||
match opcode {
|
||||
|
|
|
@ -2,12 +2,12 @@ use std::sync::mpsc::{channel, Receiver, Sender};
|
|||
|
||||
use async_ringbuf::AsyncHeapConsumer;
|
||||
use gb_emu_lib::{
|
||||
connect::{AudioOutput, EmulatorMessage, EmulatorOptions, NoCamera, RomFile},
|
||||
connect::{AudioOutput, EmulatorMessage, EmulatorOptions, RomFile},
|
||||
EmulatorCore,
|
||||
};
|
||||
|
||||
pub struct TestEmulator {
|
||||
pub core: EmulatorCore<[u8; 4], NoCamera>,
|
||||
pub core: EmulatorCore<[u8; 4]>,
|
||||
pub sender: Sender<EmulatorMessage<[u8; 4]>>,
|
||||
pub audio_rx: AsyncHeapConsumer<[f32; 2]>,
|
||||
pub serial_rx: Receiver<u8>,
|
||||
|
@ -15,8 +15,8 @@ pub struct TestEmulator {
|
|||
|
||||
pub fn emulator_setup(rom_file: RomFile) -> Result<TestEmulator, String> {
|
||||
let (sender, receiver) = channel::<EmulatorMessage<[u8; 4]>>();
|
||||
let (rom, camera) = rom_file
|
||||
.load(gb_emu_lib::connect::SramType::None, NoCamera::default())
|
||||
let rom = rom_file
|
||||
.load(gb_emu_lib::connect::SramType::None)
|
||||
.map_err(|_e| String::from("Error reading ROM: {_e:?}"))?;
|
||||
let (audio_output, audio_rx) = AudioOutput::new(
|
||||
48000.,
|
||||
|
@ -40,7 +40,7 @@ pub fn emulator_setup(rom_file: RomFile) -> Result<TestEmulator, String> {
|
|||
include_bytes!("../../../sameboy-bootroms/dmg_boot.bin").to_vec(),
|
||||
)));
|
||||
|
||||
let core = EmulatorCore::init(true, receiver, options, camera);
|
||||
let core = EmulatorCore::init(true, receiver, options);
|
||||
sender
|
||||
.send(EmulatorMessage::Start)
|
||||
.map_err(|_e| String::from("Error sending message: {_e:?}"))?;
|
||||
|
|
Loading…
Reference in a new issue