change from inline to where for generics
This commit is contained in:
parent
bf1b8f0ebc
commit
5de448917a
|
@ -71,7 +71,11 @@ pub trait PocketCamera {
|
|||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
pub struct EmulatorOptions<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
||||
pub struct EmulatorOptions<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub(crate) window: R,
|
||||
pub(crate) tile_window: Option<R>,
|
||||
pub(crate) rom: RomFile,
|
||||
|
@ -84,8 +88,10 @@ pub struct EmulatorOptions<ColourFormat: From<Colour> + Clone, R: Renderer<Colou
|
|||
pub(crate) spooky: PhantomData<ColourFormat>,
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>>
|
||||
EmulatorOptions<ColourFormat, R>
|
||||
impl<ColourFormat, R> EmulatorOptions<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn new(window: R, rom: RomFile, output: AudioOutput) -> Self {
|
||||
Self {
|
||||
|
|
|
@ -30,12 +30,20 @@ static VERBOSE: OnceCell<bool> = OnceCell::new();
|
|||
pub const WIDTH: usize = 160;
|
||||
pub const HEIGHT: usize = 144;
|
||||
|
||||
pub struct EmulatorCore<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
||||
pub struct EmulatorCore<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
receiver: Receiver<EmulatorMessage>,
|
||||
cpu: Cpu<ColourFormat, R>,
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> EmulatorCore<ColourFormat, R> {
|
||||
impl<ColourFormat, R> EmulatorCore<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn init(
|
||||
receiver: Receiver<EmulatorMessage>,
|
||||
mut options: EmulatorOptions<ColourFormat, R>,
|
||||
|
@ -153,7 +161,11 @@ impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> EmulatorCore
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_save_state(&self) -> CpuSaveState<ColourFormat, R> {
|
||||
pub fn get_save_state(&self) -> CpuSaveState<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
CpuSaveState::create(&self.cpu)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,11 @@ use crate::{
|
|||
util::{clear_bit, get_bit, set_bit},
|
||||
};
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Cpu<ColourFormat, R> {
|
||||
impl<ColourFormat, R> Cpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub(crate) fn and(&mut self, first: u8, second: u8) -> u8 {
|
||||
let result = first & second;
|
||||
self.set_or_clear_flag(Flags::Zero, result == 0x0);
|
||||
|
|
|
@ -5,7 +5,11 @@ use crate::{
|
|||
};
|
||||
use std::ops::{BitAnd, BitOr};
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Cpu<ColourFormat, R> {
|
||||
impl<ColourFormat, R> Cpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub(crate) fn pop_word(&mut self) -> u16 {
|
||||
let mut word: u16 = 0x0;
|
||||
word.set_low(self.memory.get(self.reg.sp));
|
||||
|
|
|
@ -22,7 +22,11 @@ pub(crate) mod rom;
|
|||
|
||||
pub(crate) type Address = u16;
|
||||
|
||||
pub struct Memory<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
||||
pub struct Memory<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
bootrom: Option<Vec<u8>>,
|
||||
rom: Rom,
|
||||
ram: [u8; 8192],
|
||||
|
@ -40,7 +44,11 @@ pub struct Memory<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>>
|
|||
|
||||
#[serde_with::serde_as]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MemorySaveState<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
||||
pub struct MemorySaveState<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
rom: RomSaveState,
|
||||
#[serde_as(as = "[_; 8192]")]
|
||||
ram: [u8; 8192],
|
||||
|
@ -57,8 +65,10 @@ pub struct MemorySaveState<ColourFormat: From<Colour> + Clone, R: Renderer<Colou
|
|||
timers: Timer,
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>>
|
||||
MemorySaveState<ColourFormat, R>
|
||||
impl<ColourFormat, R> MemorySaveState<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn create(memory: &Memory<ColourFormat, R>) -> Self {
|
||||
Self {
|
||||
|
@ -78,7 +88,11 @@ impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>>
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Memory<ColourFormat, R> {
|
||||
impl<ColourFormat, R> Memory<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn init(
|
||||
bootrom: Option<Vec<u8>>,
|
||||
rom: Rom,
|
||||
|
@ -300,7 +314,11 @@ impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Memory<Colou
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Cpu<ColourFormat, R> {
|
||||
impl<ColourFormat, R> Cpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn increment_timers(&mut self, machine_cycles: u8) {
|
||||
let steps = (machine_cycles as usize) * 4;
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ mod types;
|
|||
const TILE_WINDOW_WIDTH: usize = 16 * 8;
|
||||
const TILE_WINDOW_HEIGHT: usize = 24 * 8;
|
||||
|
||||
pub struct Gpu<Format: From<Colour>, R: Renderer<Format>> {
|
||||
pub buffer: Vec<Format>,
|
||||
pub struct Gpu<ColourFormat: From<Colour>, R: Renderer<ColourFormat>> {
|
||||
pub buffer: Vec<ColourFormat>,
|
||||
pub vram: Vram,
|
||||
pub oam: Oam,
|
||||
pub window: R,
|
||||
|
@ -34,7 +34,7 @@ pub struct Gpu<Format: From<Colour>, R: Renderer<Format>> {
|
|||
mode_clock: usize,
|
||||
scanline: u8,
|
||||
lyc: u8,
|
||||
tile_window: Option<TileWindow<Format, R>>,
|
||||
tile_window: Option<TileWindow<ColourFormat, R>>,
|
||||
window_lc: u8,
|
||||
has_window_been_enabled: bool,
|
||||
bg_palette: Palette,
|
||||
|
@ -48,8 +48,8 @@ pub struct Gpu<Format: From<Colour>, R: Renderer<Format>> {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct GpuSaveState<Format: From<Colour>, R: Renderer<Format>> {
|
||||
buffer: Vec<Format>,
|
||||
pub struct GpuSaveState<ColourFormat: From<Colour>, R: Renderer<ColourFormat>> {
|
||||
buffer: Vec<ColourFormat>,
|
||||
vram: Vram,
|
||||
oam: Oam,
|
||||
is_bg_zero: Vec<bool>,
|
||||
|
@ -72,8 +72,12 @@ pub struct GpuSaveState<Format: From<Colour>, R: Renderer<Format>> {
|
|||
spooky: PhantomData<R>,
|
||||
}
|
||||
|
||||
impl<Format: From<Colour> + Clone, R: Renderer<Format>> GpuSaveState<Format, R> {
|
||||
pub fn create(gpu: &Gpu<Format, R>) -> Self {
|
||||
impl<ColourFormat, R> GpuSaveState<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn create(gpu: &Gpu<ColourFormat, R>) -> Self {
|
||||
Self {
|
||||
buffer: gpu.buffer.clone(),
|
||||
vram: gpu.vram,
|
||||
|
@ -99,7 +103,11 @@ impl<Format: From<Colour> + Clone, R: Renderer<Format>> GpuSaveState<Format, R>
|
|||
}
|
||||
}
|
||||
|
||||
impl<Format: From<Colour> + Clone, R: Renderer<Format>> Gpu<Format, R> {
|
||||
impl<ColourFormat, R> Gpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn new(window: R, tile_window_renderer: Option<R>) -> Self {
|
||||
let tile_window = if let Some(mut tile_window_renderer) = tile_window_renderer {
|
||||
tile_window_renderer.prepare(TILE_WINDOW_WIDTH, TILE_WINDOW_HEIGHT);
|
||||
|
@ -135,7 +143,7 @@ impl<Format: From<Colour> + Clone, R: Renderer<Format>> Gpu<Format, R> {
|
|||
}
|
||||
|
||||
pub fn from_save_state(
|
||||
state: GpuSaveState<Format, R>,
|
||||
state: GpuSaveState<ColourFormat, R>,
|
||||
window: R,
|
||||
tile_window_renderer: Option<R>,
|
||||
) -> Self {
|
||||
|
|
|
@ -23,7 +23,11 @@ pub(crate) enum Direction {
|
|||
Right,
|
||||
}
|
||||
|
||||
pub struct Cpu<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
||||
pub struct Cpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub memory: Memory<ColourFormat, R>,
|
||||
pub reg: Registers,
|
||||
pub last_instruction: u8,
|
||||
|
@ -33,7 +37,11 @@ pub struct Cpu<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CpuSaveState<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> {
|
||||
pub struct CpuSaveState<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
memory: MemorySaveState<ColourFormat, R>,
|
||||
reg: Registers,
|
||||
last_instruction: u8,
|
||||
|
@ -42,7 +50,11 @@ pub struct CpuSaveState<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFo
|
|||
should_halt_bug: bool,
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> CpuSaveState<ColourFormat, R> {
|
||||
impl<ColourFormat, R> CpuSaveState<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn create(cpu: &Cpu<ColourFormat, R>) -> Self {
|
||||
Self {
|
||||
memory: MemorySaveState::create(&cpu.memory),
|
||||
|
@ -55,7 +67,11 @@ impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> CpuSaveState
|
|||
}
|
||||
}
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Cpu<ColourFormat, R> {
|
||||
impl<ColourFormat, R> Cpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn new(mut memory: Memory<ColourFormat, R>, run_bootrom: bool) -> Self {
|
||||
if !run_bootrom {
|
||||
memory.cpu_ram_init();
|
||||
|
|
|
@ -9,7 +9,11 @@ use crate::{
|
|||
|
||||
use super::memory::mmio::gpu::Colour;
|
||||
|
||||
impl<ColourFormat: From<Colour> + Clone, R: Renderer<ColourFormat>> Cpu<ColourFormat, R> {
|
||||
impl<ColourFormat, R> Cpu<ColourFormat, R>
|
||||
where
|
||||
ColourFormat: From<Colour> + Clone,
|
||||
R: Renderer<ColourFormat>,
|
||||
{
|
||||
pub fn run_opcode(&mut self, opcode: u8) -> u8 {
|
||||
match opcode {
|
||||
0x00 => {
|
||||
|
|
Loading…
Reference in a new issue