diff --git a/src/cpu/mod.rs b/src/cpu/mod.rs index 61fb2e7f..639411f0 100644 --- a/src/cpu/mod.rs +++ b/src/cpu/mod.rs @@ -1 +1,11 @@ pub mod mos6502; + +pub trait Cpu { + fn reset(&mut self); + + /// Return the number of cycles elapsed since the system last reset. + fn get_cycle_count(&self) -> u64; + + /// Execute a single instruction. Return the number of cycles elapsed. + fn tick(&mut self) -> u8; +} diff --git a/src/cpu/mos6502/mod.rs b/src/cpu/mos6502/mod.rs index 616ac7d9..347aa38b 100644 --- a/src/cpu/mos6502/mod.rs +++ b/src/cpu/mos6502/mod.rs @@ -1,12 +1,14 @@ mod execute; mod fetch; mod registers; -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory}; use execute::Execute; use fetch::Fetch; use registers::{flags, Registers}; -const CLOCKS_PER_POLL: u32 = 100; +use super::Cpu; + +const CLOCKS_PER_POLL: u64 = 100; #[derive(Copy, Clone, PartialEq)] pub enum Mos6502Variant { @@ -21,7 +23,7 @@ pub struct Mos6502 { pub registers: Registers, pub memory: Box, cycle_count: u64, - cycles_since_poll: u32, + cycles_since_poll: u64, variant: Mos6502Variant, } @@ -144,8 +146,10 @@ impl Mos6502 { variant, } } +} - pub fn reset(&mut self) { +impl Cpu for Mos6502 { + fn reset(&mut self) { self.memory.reset(); self.registers.reset(); let pc_address = self.read_word(0xFFFC); @@ -153,24 +157,22 @@ impl Mos6502 { } /// Return a SystemInfo struct containing the current system status. - pub fn get_info(&self) -> SystemInfo { - SystemInfo { - cycle_count: self.cycle_count, - } + fn get_cycle_count(&self) -> u64 { + self.cycle_count } /// Execute a single instruction. - pub fn tick(&mut self) -> u8 { + fn tick(&mut self) -> u8 { let opcode = self.fetch(); match self.execute(opcode) { Ok(cycles) => { self.cycle_count += cycles as u64; - self.cycles_since_poll += cycles as u32; + self.cycles_since_poll += cycles as u64; if self.cycles_since_poll >= CLOCKS_PER_POLL { - let info = self.get_info(); + let total_cycle_count = self.get_cycle_count(); - match self.memory.poll(self.cycles_since_poll, &info) { + match self.memory.poll(self.cycles_since_poll, total_cycle_count) { ActiveInterrupt::None => (), ActiveInterrupt::NMI => self.interrupt(false, false), ActiveInterrupt::IRQ => self.interrupt(true, false), diff --git a/src/memory/banked.rs b/src/memory/banked.rs index d3a108e4..e965ec3e 100644 --- a/src/memory/banked.rs +++ b/src/memory/banked.rs @@ -1,6 +1,6 @@ use std::{cell::Cell, rc::Rc}; -use super::{ActiveInterrupt, Memory, SystemInfo}; +use super::{ActiveInterrupt, Memory}; /// Represents the memory banking features found in the Commodore 64 and other /// devices. Multiple memory implementations are all mapped to the same @@ -48,11 +48,11 @@ impl Memory for BankedMemory { } } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { let mut highest = ActiveInterrupt::None; for mapped in &mut self.banks { - let interrupt = mapped.poll(cycles, info); + let interrupt = mapped.poll(cycles_since_poll, total_cycle_count); match interrupt { ActiveInterrupt::None => (), diff --git a/src/memory/block.rs b/src/memory/block.rs index 95e90353..4de9b01d 100644 --- a/src/memory/block.rs +++ b/src/memory/block.rs @@ -1,4 +1,4 @@ -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory}; use crate::roms::RomFile; /// Represents a simple block of contiguous memory, with no additional hardware. @@ -85,7 +85,7 @@ impl Memory for BlockMemory { } } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> ActiveInterrupt { ActiveInterrupt::None } } diff --git a/src/memory/branch.rs b/src/memory/branch.rs index 64f120f0..71222919 100644 --- a/src/memory/branch.rs +++ b/src/memory/branch.rs @@ -1,4 +1,4 @@ -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory}; /// Maps several Memory objects into a single contiguous address space. /// Each mapped object is assigned a starting address, and reads and writes @@ -66,11 +66,11 @@ impl Memory for BranchMemory { } } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { let mut highest = ActiveInterrupt::None; for (_, mapped) in &mut self.mapping { - let interrupt = mapped.poll(cycles, info); + let interrupt = mapped.poll(cycles_since_poll, total_cycle_count); match interrupt { ActiveInterrupt::None => (), diff --git a/src/memory/logging.rs b/src/memory/logging.rs index e7b841eb..b60f4622 100644 --- a/src/memory/logging.rs +++ b/src/memory/logging.rs @@ -1,4 +1,4 @@ -use super::{ActiveInterrupt, Memory, SystemInfo}; +use super::{ActiveInterrupt, Memory}; pub struct LoggingMemory { backing: Box, @@ -43,8 +43,8 @@ impl Memory for LoggingMemory { println!("[Memory Reset]: {}", self.message); } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { // println!("[Memory Poll]: {}", self.message); - self.backing.poll(cycles, info) + self.backing.poll(cycles_since_poll, total_cycle_count) } } diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 9b8e44c3..ce76cd8c 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -27,13 +27,6 @@ pub enum ActiveInterrupt { IRQ, } -/// Information about the system that Memory implementations can use to -/// determine if an interrupt should be triggered. -#[derive(Debug, Default)] -pub struct SystemInfo { - pub cycle_count: u64, -} - /// Represents a contiguous block of memory which can be read, written, /// reset, and polled to see if an interrupt has been triggered. pub trait Memory { @@ -52,5 +45,5 @@ pub trait Memory { /// Poll this memory to see if an interrupt has been triggered. /// Implementations may trigger an NMI or IRQ for any /// implementation-dependent reason. - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt; + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt; } diff --git a/src/memory/mos6510.rs b/src/memory/mos6510.rs index 16ae7d96..ec2b17bb 100644 --- a/src/memory/mos6510.rs +++ b/src/memory/mos6510.rs @@ -1,4 +1,4 @@ -use super::{ActiveInterrupt, Memory, Port, SystemInfo}; +use super::{ActiveInterrupt, Memory, Port}; /// Represents the port built into a MOS 6510 processor, mapped to memory addresses 0x0000 (for the DDR) and 0x0001 (for the port itself). pub struct Mos6510Port { @@ -50,8 +50,8 @@ impl Memory for Mos6510Port { self.port.reset(); } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { - match self.port.poll(cycles, info) { + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { + match self.port.poll(cycles_since_poll, total_cycle_count) { true => ActiveInterrupt::IRQ, false => ActiveInterrupt::None, } diff --git a/src/memory/mos652x/cia.rs b/src/memory/mos652x/cia.rs index 03de9bef..973c4899 100644 --- a/src/memory/mos652x/cia.rs +++ b/src/memory/mos652x/cia.rs @@ -1,6 +1,6 @@ use crate::memory::{ mos652x::{InterruptRegister, PortRegisters, ShiftRegister, Timer}, - ActiveInterrupt, Memory, Port, SystemInfo, + ActiveInterrupt, Memory, Port, }; struct TimeRegisters { @@ -208,20 +208,22 @@ impl Memory for Cia { self.interrupts.reset(); } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { - if self.timer_a.poll(cycles, info) + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { + if self.timer_a.poll(cycles_since_poll, total_cycle_count) && (self.interrupts.interrupt_enable & interrupt_bits::TIMER_A) != 0 { return ActiveInterrupt::IRQ; } - if self.timer_b.poll(cycles, info) + if self.timer_b.poll(cycles_since_poll, total_cycle_count) && (self.interrupts.interrupt_enable & interrupt_bits::TIMER_B) != 0 { return ActiveInterrupt::IRQ; } - if self.a.poll(cycles, info) || self.b.poll(cycles, info) { + if self.a.poll(cycles_since_poll, total_cycle_count) + || self.b.poll(cycles_since_poll, total_cycle_count) + { return ActiveInterrupt::IRQ; } @@ -276,14 +278,14 @@ mod tests { cia.write(0x0E, 0b0000_1001); for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); // polling again shouldn't do anything for _ in 0..0x20 { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } } @@ -302,10 +304,10 @@ mod tests { cia.write(0x0F, 0b0000_1001); for _ in 0..0x1233 { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); } #[test] @@ -322,19 +324,13 @@ mod tests { // start the timer, and enable continuous operation cia.write(0x0E, 0b0000_0001); - assert_eq!( - ActiveInterrupt::None, - cia.poll(0x0F, &SystemInfo::default()) - ); + assert_eq!(ActiveInterrupt::None, cia.poll(0x0F, 0)); - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); - assert_eq!( - ActiveInterrupt::None, - cia.poll(0x0F, &SystemInfo::default()) - ); + assert_eq!(ActiveInterrupt::None, cia.poll(0x0F, 0)); - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); } #[test] @@ -358,10 +354,10 @@ mod tests { // timer 1 should interrupt first for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); } #[test] @@ -384,7 +380,7 @@ mod tests { // timer 2 shouldn't trigger an interrupt for _ in 0..0x08 { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } // ...but the flag register should be set @@ -395,9 +391,9 @@ mod tests { // timer 1 should then trigger an interrupt for _ in 0..0x07 { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); // ...and set the corresponding flag, plus the master bit assert_eq!( @@ -410,8 +406,8 @@ mod tests { // if we let timer 1 run again, it should set the flag again for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, cia.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, cia.poll(1, 0)); } } diff --git a/src/memory/mos652x/mod.rs b/src/memory/mos652x/mod.rs index c8048af6..792a63e1 100644 --- a/src/memory/mos652x/mod.rs +++ b/src/memory/mos652x/mod.rs @@ -6,7 +6,7 @@ pub use cia::Cia; pub use pia::Pia; pub use via::Via; -use crate::memory::{Port, SystemInfo}; +use crate::memory::Port; /// A port and its associated registers on the MOS 6522 VIA or MOS 6526 CIA. pub struct PortRegisters { @@ -45,8 +45,8 @@ impl PortRegisters { } /// Poll the underlying port for interrupts. - pub fn poll(&mut self, cycles: u32, info: &SystemInfo) -> bool { - self.port.poll(cycles, info) + pub fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> bool { + self.port.poll(cycles_since_poll, total_cycle_count) } /// Reset the port to its initial state. @@ -127,7 +127,7 @@ impl Timer { } /// Poll the timer (decrement the counter, fire the interrupt if necessary). - pub fn poll(&mut self, cycles: u32, _info: &SystemInfo) -> bool { + pub fn poll(&mut self, cycles_since_poll: u64, _total_cycle_count: u64) -> bool { if self.counter <= 0 { if self.continuous { self.counter += self.latch as i32; @@ -138,7 +138,7 @@ impl Timer { } if self.running { - self.counter -= cycles as i32; + self.counter -= cycles_since_poll as i32; if self.counter <= 0 { // The counter underflowed diff --git a/src/memory/mos652x/pia.rs b/src/memory/mos652x/pia.rs index 9b10cb8b..a112b5ff 100644 --- a/src/memory/mos652x/pia.rs +++ b/src/memory/mos652x/pia.rs @@ -1,4 +1,4 @@ -use crate::memory::{ActiveInterrupt, Memory, Port, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory, Port}; // MOS 6520 @@ -55,8 +55,8 @@ impl PiaPortRegisters { } /// Poll the underlying port for interrupts. - pub fn poll(&mut self, cycles: u32, info: &SystemInfo) -> bool { - self.port.poll(cycles, info) + pub fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> bool { + self.port.poll(cycles_since_poll, total_cycle_count) } /// Reset the DDR, control register, and underlying port. @@ -122,9 +122,9 @@ impl Memory for Pia { self.b.reset(); } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { - let a = self.a.poll(cycles, info); - let b = self.b.poll(cycles, info); + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { + let a = self.a.poll(cycles_since_poll, total_cycle_count); + let b = self.b.poll(cycles_since_poll, total_cycle_count); if a || b { ActiveInterrupt::IRQ diff --git a/src/memory/mos652x/via.rs b/src/memory/mos652x/via.rs index fc864c81..3e5ab2e5 100644 --- a/src/memory/mos652x/via.rs +++ b/src/memory/mos652x/via.rs @@ -1,6 +1,6 @@ use crate::memory::{ mos652x::{InterruptRegister, PortRegisters, ShiftRegister, Timer, TimerOutput}, - ActiveInterrupt, Memory, Port, SystemInfo, + ActiveInterrupt, Memory, Port, }; #[allow(dead_code)] @@ -183,16 +183,22 @@ impl Memory for Via { self.b.reset(); } - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> ActiveInterrupt { - if self.t1.poll(cycles, info) && self.interrupts.is_enabled(interrupt_bits::T1_ENABLE) { + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { + if self.t1.poll(cycles_since_poll, total_cycle_count) + && self.interrupts.is_enabled(interrupt_bits::T1_ENABLE) + { return ActiveInterrupt::IRQ; } - if self.t2.poll(cycles, info) && self.interrupts.is_enabled(interrupt_bits::T2_ENABLE) { + if self.t2.poll(cycles_since_poll, total_cycle_count) + && self.interrupts.is_enabled(interrupt_bits::T2_ENABLE) + { return ActiveInterrupt::IRQ; } - if self.a.poll(cycles, info) || self.b.poll(cycles, info) { + if self.a.poll(cycles_since_poll, total_cycle_count) + || self.b.poll(cycles_since_poll, total_cycle_count) + { return ActiveInterrupt::IRQ; } @@ -244,14 +250,14 @@ mod tests { via.write(0x05, 0x00); for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); // polling again shouldn't do anything for _ in 0..0x20 { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } } @@ -266,16 +272,16 @@ mod tests { via.write(0x08, 0x34); // polling now shouldn't do anything - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); // timer begins when the high byte is written via.write(0x09, 0x12); for _ in 0..0x1233 { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); } #[test] @@ -293,16 +299,16 @@ mod tests { via.write(0x05, 0x00); for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); } #[test] @@ -353,10 +359,10 @@ mod tests { // timer 1 should interrupt first for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); } #[test] @@ -379,7 +385,7 @@ mod tests { // timer 2 shouldn't trigger an interrupt for _ in 0..0x08 { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } // ...but the flag register should be set @@ -387,9 +393,9 @@ mod tests { // timer 1 should then trigger an interrupt for _ in 0..0x07 { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); // ...and set the corresponding flag, plus the master bit assert_eq!( @@ -414,8 +420,8 @@ mod tests { // if we let timer 1 run again, it should set the flag again for _ in 0..0x0F { - assert_eq!(ActiveInterrupt::None, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::None, via.poll(1, 0)); } - assert_eq!(ActiveInterrupt::IRQ, via.poll(1, &SystemInfo::default())); + assert_eq!(ActiveInterrupt::IRQ, via.poll(1, 0)); } } diff --git a/src/memory/null.rs b/src/memory/null.rs index f5066739..9e6fe05b 100644 --- a/src/memory/null.rs +++ b/src/memory/null.rs @@ -1,4 +1,4 @@ -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory}; /// Memory that does nothing when read or written to. #[derive(Default)] @@ -36,7 +36,7 @@ impl Memory for NullMemory { fn reset(&mut self) {} - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> ActiveInterrupt { ActiveInterrupt::None } } diff --git a/src/memory/ports.rs b/src/memory/ports.rs index 5fc99dc7..1df290f8 100644 --- a/src/memory/ports.rs +++ b/src/memory/ports.rs @@ -1,5 +1,3 @@ -use crate::memory::SystemInfo; - /// A Port that can be read from, written to, reset, or polled for interrupts. /// Used in the MOS 6520 PIA and the 6522 VIA. pub trait Port { @@ -12,7 +10,7 @@ pub trait Port { /// Poll the port for interrupts. A port may trigger an interrupt for any /// implementation-defined reason. - fn poll(&mut self, cycles: u32, info: &SystemInfo) -> bool; + fn poll(&mut self, cycles_since_poll: u64, total_cycle_count: u64) -> bool; /// Reset the port to its initial state, analogous to a system reboot. fn reset(&mut self); @@ -52,7 +50,7 @@ impl Port for NullPort { } } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } diff --git a/src/systems/basic.rs b/src/systems/basic.rs index 462e7961..b5fc1cdb 100644 --- a/src/systems/basic.rs +++ b/src/systems/basic.rs @@ -1,7 +1,10 @@ use instant::Duration; -use crate::cpu::mos6502::{Mos6502, Mos6502Variant}; -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::cpu::{ + mos6502::{Mos6502, Mos6502Variant}, + Cpu, +}; +use crate::memory::{ActiveInterrupt, Memory}; use crate::memory::{BlockMemory, BranchMemory}; use crate::platform::{PlatformProvider, WindowConfig}; use crate::roms::RomFile; @@ -60,7 +63,7 @@ impl Memory for MappedStdIO { fn reset(&mut self) {} - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> ActiveInterrupt { ActiveInterrupt::None } } diff --git a/src/systems/c64/mod.rs b/src/systems/c64/mod.rs index a13d6458..b49ed032 100644 --- a/src/systems/c64/mod.rs +++ b/src/systems/c64/mod.rs @@ -6,13 +6,13 @@ use std::{ use crate::{ cpu::mos6502::{Mos6502, Mos6502Variant}, + cpu::Cpu, keyboard::{ commodore::{C64KeyboardAdapter, C64SymbolAdapter, C64VirtualAdapter}, KeyAdapter, KeyMappingStrategy, SymbolAdapter, }, memory::{ mos652x::Cia, BankedMemory, BlockMemory, BranchMemory, Mos6510Port, NullMemory, NullPort, Port, - SystemInfo, }, platform::{PlatformProvider, WindowConfig}, systems::System, @@ -59,7 +59,7 @@ impl Port for C64Cia1PortA { self.keyboard_row.set(value); } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } @@ -119,7 +119,7 @@ impl Port for C64Cia1PortB { panic!("Tried to write to keyboard row"); } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } @@ -188,7 +188,7 @@ impl Port for C64BankSwitching { self.selectors[5].set(if !self.hiram { 1 } else { 0 }); } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } diff --git a/src/systems/c64/vic_ii.rs b/src/systems/c64/vic_ii.rs index 653cfc5b..d9d807bf 100644 --- a/src/systems/c64/vic_ii.rs +++ b/src/systems/c64/vic_ii.rs @@ -1,4 +1,4 @@ -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory}; use crate::platform::{Color, WindowConfig}; use std::cell::RefCell; use std::rc::Rc; @@ -450,8 +450,8 @@ impl Memory for VicIIChipIO { self.chip.borrow_mut().reset(); } - fn poll(&mut self, _cycles: u32, info: &SystemInfo) -> ActiveInterrupt { - self.chip.borrow_mut().raster_counter = ((info.cycle_count / 83) % 312) as u16; + fn poll(&mut self, _cycles_since_poll: u64, total_cycle_count: u64) -> ActiveInterrupt { + self.chip.borrow_mut().raster_counter = ((total_cycle_count / 83) % 312) as u16; ActiveInterrupt::None } diff --git a/src/systems/easy.rs b/src/systems/easy.rs index dff58e58..2652d84e 100644 --- a/src/systems/easy.rs +++ b/src/systems/easy.rs @@ -1,8 +1,11 @@ use instant::Duration; -use crate::cpu::mos6502::{MemoryIO, Mos6502, Mos6502Variant}; +use crate::cpu::{ + mos6502::{MemoryIO, Mos6502, Mos6502Variant}, + Cpu, +}; use crate::keyboard::KeyPosition; -use crate::memory::{ActiveInterrupt, BlockMemory, BranchMemory, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, BlockMemory, BranchMemory, Memory}; use crate::platform::{Color, PlatformProvider, WindowConfig}; use crate::roms::RomFile; use crate::systems::{System, SystemBuilder}; @@ -52,7 +55,7 @@ impl Memory for EasyIO { fn reset(&mut self) {} - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> ActiveInterrupt { ActiveInterrupt::None } } diff --git a/src/systems/klaus.rs b/src/systems/klaus.rs index ff136243..9e8a9d60 100644 --- a/src/systems/klaus.rs +++ b/src/systems/klaus.rs @@ -1,6 +1,9 @@ use instant::Duration; -use crate::cpu::mos6502::{Mos6502, Mos6502Variant}; +use crate::cpu::{ + mos6502::{Mos6502, Mos6502Variant}, + Cpu, +}; use crate::memory::BlockMemory; use crate::platform::{PlatformProvider, WindowConfig}; use crate::roms::RomFile; diff --git a/src/systems/pet/mod.rs b/src/systems/pet/mod.rs index efaadf83..b07371c4 100644 --- a/src/systems/pet/mod.rs +++ b/src/systems/pet/mod.rs @@ -1,7 +1,10 @@ -use crate::cpu::mos6502::{MemoryIO, Mos6502, Mos6502Variant}; +use crate::cpu::{ + mos6502::{MemoryIO, Mos6502, Mos6502Variant}, + Cpu, +}; use crate::keyboard::{KeyAdapter, KeyMappingStrategy, SymbolAdapter}; use crate::memory::mos652x::{Pia, Via}; -use crate::memory::{BlockMemory, BranchMemory, NullMemory, NullPort, Port, SystemInfo}; +use crate::memory::{BlockMemory, BranchMemory, NullMemory, NullPort, Port}; use crate::platform::{Color, PlatformProvider, WindowConfig}; use crate::systems::{System, SystemBuilder}; use instant::Instant; @@ -60,16 +63,16 @@ impl Port for PetPia1PortA { self.keyboard_row.set(value & 0b1111); } - fn poll(&mut self, _cycles: u32, info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, total_cycle_count: u64) -> bool { // let min_elapsed = ((info.cycles_per_second as f64 / 60.0) * (2.0 / 3.0)) as u64; let min_elapsed = 0; // TODO: fix match self.last_draw_instant { Some(last_draw) => { if (last_draw.elapsed() > Duration::from_millis(17)) - && (info.cycle_count > self.last_draw_cycle + min_elapsed) + && (total_cycle_count > self.last_draw_cycle + min_elapsed) { - self.last_draw_cycle = info.cycle_count; + self.last_draw_cycle = total_cycle_count; self.last_draw_instant = Some(Instant::now()); true // false @@ -136,7 +139,7 @@ impl Port for PetPia1PortB { fn write(&mut self, _value: u8) {} - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } diff --git a/src/systems/vic/chip.rs b/src/systems/vic/chip.rs index dd3d3861..d5bd598b 100644 --- a/src/systems/vic/chip.rs +++ b/src/systems/vic/chip.rs @@ -1,4 +1,4 @@ -use crate::memory::{ActiveInterrupt, Memory, SystemInfo}; +use crate::memory::{ActiveInterrupt, Memory}; use crate::platform::{Color, PlatformProvider, WindowConfig}; use std::cell::RefCell; use std::rc::Rc; @@ -493,7 +493,7 @@ impl Memory for VicChipIO { self.chip.borrow_mut().reset(); } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> ActiveInterrupt { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> ActiveInterrupt { ActiveInterrupt::None } } diff --git a/src/systems/vic/mod.rs b/src/systems/vic/mod.rs index 94879687..f0aca798 100644 --- a/src/systems/vic/mod.rs +++ b/src/systems/vic/mod.rs @@ -1,11 +1,14 @@ -use crate::cpu::mos6502::{Mos6502, Mos6502Variant}; +use crate::cpu::{ + mos6502::{Mos6502, Mos6502Variant}, + Cpu, +}; use crate::keyboard::commodore::C64VirtualAdapter; use crate::keyboard::{ commodore::{C64KeyboardAdapter, C64SymbolAdapter}, KeyAdapter, KeyMappingStrategy, SymbolAdapter, }; use crate::memory::mos652x::Via; -use crate::memory::{BlockMemory, BranchMemory, NullMemory, NullPort, Port, SystemInfo}; +use crate::memory::{BlockMemory, BranchMemory, NullMemory, NullPort, Port}; use crate::platform::{PlatformProvider, WindowConfig}; use crate::roms::RomFile; use crate::systems::System; @@ -137,7 +140,7 @@ impl Port for VicVia1PortA { fn write(&mut self, _value: u8) {} - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } @@ -175,7 +178,7 @@ impl Port for VicVia2PortB { self.keyboard_col.set(value); } - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false } @@ -234,7 +237,7 @@ impl Port for VicVia2PortA { fn write(&mut self, _value: u8) {} - fn poll(&mut self, _cycles: u32, _info: &SystemInfo) -> bool { + fn poll(&mut self, _cycles_since_poll: u64, _total_cycle_count: u64) -> bool { false }