Skip to content

Commit

Permalink
Add field to track NMOS or CMOS variant
Browse files Browse the repository at this point in the history
  • Loading branch information
breqdev committed Nov 23, 2023
1 parent e62f64a commit 29e65b3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
14 changes: 12 additions & 2 deletions src/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ use registers::{flags, Registers};

const CLOCKS_PER_POLL: u32 = 100;

#[derive(Copy, Clone)]
pub enum Mos6502Variant {
/// 6502
NMOS,
/// 65C02
CMOS,
}

/// The MOS 6502 CPU and its associated memory.
pub struct Mos6502 {
pub registers: Registers,
pub memory: Box<dyn Memory>,
cycle_count: u64,
cycles_since_poll: u32,
variant: Mos6502Variant,

Check failure on line 25 in src/cpu/mod.rs

View workflow job for this annotation

GitHub Actions / Desktop Build and Style Check

field `variant` is never read

Check warning on line 25 in src/cpu/mod.rs

View workflow job for this annotation

GitHub Actions / WASM Build, Docs Build, and Web Deploy

field `variant` is never read
}

/// Read and write from the system's memory.
Expand Down Expand Up @@ -122,12 +131,13 @@ impl InterruptHandler for Mos6502 {
}

impl Mos6502 {
pub fn new(memory: Box<dyn Memory>) -> Mos6502 {
pub fn new(memory: impl Memory + 'static, variant: Mos6502Variant) -> Mos6502 {
Mos6502 {
registers: Registers::new(),
memory,
memory: Box::new(memory),
cycle_count: 0,
cycles_since_poll: 0,
variant,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/systems/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use instant::Duration;

use crate::cpu::Mos6502;
use crate::cpu::{Mos6502, Mos6502Variant};
use crate::memory::{ActiveInterrupt, Memory, SystemInfo};
use crate::memory::{BlockMemory, BranchMemory};
use crate::platform::{PlatformProvider, WindowConfig};
Expand Down Expand Up @@ -79,7 +79,7 @@ impl SystemBuilder<BasicSystem, RomFile, ()> for BasicSystemBuilder {
.map(0x4000, io)
.map(0x8000, rom);

let cpu = Mos6502::new(Box::new(memory));
let cpu = Mos6502::new(memory, Mos6502Variant::NMOS);

Box::new(BasicSystem { cpu })
}
Expand Down
4 changes: 2 additions & 2 deletions src/systems/c64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use crate::{
cpu::Mos6502,
cpu::{Mos6502, Mos6502Variant},
keyboard::{
commodore::{C64KeyboardAdapter, C64SymbolAdapter, C64VirtualAdapter},
KeyAdapter, KeyMappingStrategy, SymbolAdapter,
Expand Down Expand Up @@ -303,7 +303,7 @@ impl SystemBuilder<C64System, C64SystemRoms, C64SystemConfig> for C64SystemBuild
.map(0xD000, region6)
.map(0xE000, region7);

let cpu = Mos6502::new(Box::new(memory));
let cpu = Mos6502::new(memory, Mos6502Variant::NMOS);

Box::new(C64System { cpu, vic: vic_ii })
}
Expand Down
4 changes: 2 additions & 2 deletions src/systems/easy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use instant::Duration;

use crate::cpu::{MemoryIO, Mos6502};
use crate::cpu::{MemoryIO, Mos6502, Mos6502Variant};
use crate::keyboard::KeyPosition;
use crate::memory::{ActiveInterrupt, BlockMemory, BranchMemory, Memory, SystemInfo};
use crate::platform::{Color, PlatformProvider, WindowConfig};
Expand Down Expand Up @@ -79,7 +79,7 @@ impl SystemBuilder<Easy6502System, RomFile, ()> for Easy6502SystemBuilder {
.map(0x0600, high_ram)
.map(0x8000, rom);

let cpu = Mos6502::new(Box::new(memory));
let cpu = Mos6502::new(memory, Mos6502Variant::NMOS);

Box::new(Easy6502System { cpu })
}
Expand Down
4 changes: 2 additions & 2 deletions src/systems/klaus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use instant::Duration;

use crate::cpu::Mos6502;
use crate::cpu::{Mos6502, Mos6502Variant};
use crate::memory::BlockMemory;
use crate::platform::{PlatformProvider, WindowConfig};
use crate::roms::RomFile;
Expand All @@ -21,7 +21,7 @@ impl SystemBuilder<KlausSystem, RomFile, Option<Rc<Cell<u16>>>> for KlausSystemB
_platform: Arc<dyn PlatformProvider>,
) -> Box<dyn System> {
let rom = BlockMemory::from_file(0x10000, rom).set_writeable(true);
let mut cpu = Mos6502::new(Box::new(rom));
let mut cpu = Mos6502::new(rom, Mos6502Variant::NMOS);

cpu.registers.pc.load(0x0400);

Expand Down
4 changes: 2 additions & 2 deletions src/systems/pet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cpu::{MemoryIO, Mos6502};
use crate::cpu::{MemoryIO, Mos6502, Mos6502Variant};
use crate::keyboard::{KeyAdapter, KeyMappingStrategy, SymbolAdapter};
use crate::memory::mos652x::{Pia, Via};
use crate::memory::{BlockMemory, BranchMemory, NullMemory, NullPort, Port, SystemInfo};
Expand Down Expand Up @@ -194,7 +194,7 @@ impl SystemBuilder<PetSystem, PetSystemRoms, PetSystemConfig> for PetSystemBuild
.map(0xE840, via)
.map(0xF000, kernel_rom);

let cpu = Mos6502::new(Box::new(memory));
let cpu = Mos6502::new(memory, Mos6502Variant::NMOS);

Box::new(PetSystem {
cpu,
Expand Down
4 changes: 2 additions & 2 deletions src/systems/vic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cpu::Mos6502;
use crate::cpu::{Mos6502, Mos6502Variant};
use crate::keyboard::commodore::C64VirtualAdapter;
use crate::keyboard::{
commodore::{C64KeyboardAdapter, C64SymbolAdapter},
Expand Down Expand Up @@ -298,7 +298,7 @@ impl SystemBuilder<Vic20System, Vic20SystemRoms, Vic20SystemConfig> for Vic20Sys
.map(0xC000, basic_rom)
.map(0xE000, kernel_rom);

let cpu = Mos6502::new(Box::new(memory));
let cpu = Mos6502::new(memory, Mos6502Variant::NMOS);

Box::new(Vic20System { cpu, vic: vic_chip })
}
Expand Down

0 comments on commit 29e65b3

Please sign in to comment.