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