removes sccache
updates display of ben eater pc doesnt blow up when creating a rom chip anymore doesnt blow up when creating a pc anymore
This commit is contained in:
+17
-7
@@ -5,7 +5,8 @@ pub const SIZE_32KB: usize = SIZE_1KB * 32;
|
||||
pub const SIZE_64KB: usize = SIZE_1KB * 64;
|
||||
|
||||
pub struct Mos6502Cpu {
|
||||
memory: [u8; SIZE_64KB],
|
||||
// this is public for rendering quickly.
|
||||
pub memory: Box<[u8]>,
|
||||
a: u8,
|
||||
x: u8,
|
||||
y: u8,
|
||||
@@ -13,20 +14,24 @@ pub struct Mos6502Cpu {
|
||||
pc: u16,
|
||||
s: u8,
|
||||
pub microcode_step: u8,
|
||||
address_bus: u16,
|
||||
data_bus: u8,
|
||||
pub address_bus: u16,
|
||||
pub data_bus: u8,
|
||||
ir: u8 // Instruction Register
|
||||
}
|
||||
|
||||
impl Default for Mos6502Cpu {
|
||||
fn default() -> Self {
|
||||
let vec = vec![0x00; SIZE_64KB];
|
||||
let boxed_slize: Box<[u8]> = vec.into_boxed_slice();
|
||||
let boxed_array: Box<[u8; SIZE_64KB]> = boxed_slize.try_into().expect("Failed to allocate system memory");
|
||||
|
||||
Mos6502Cpu {
|
||||
memory: [0x00; SIZE_64KB],
|
||||
memory: boxed_array,
|
||||
a: 0,
|
||||
x: 0,
|
||||
y: 0,
|
||||
flags: Default::default(),
|
||||
pc: 0,
|
||||
pc: 0xfffd,
|
||||
s: 0,
|
||||
microcode_step: 0,
|
||||
address_bus: 0,
|
||||
@@ -38,8 +43,11 @@ impl Default for Mos6502Cpu {
|
||||
|
||||
impl Mos6502Cpu {
|
||||
pub fn new() -> Mos6502Cpu {
|
||||
let vec = vec![0x00; SIZE_64KB];
|
||||
let boxed_slize: Box<[u8]> = vec.into_boxed_slice();
|
||||
let boxed_array: Box<[u8; SIZE_64KB]> = boxed_slize.try_into().expect("Failed to allocate system memory");
|
||||
Mos6502Cpu {
|
||||
memory: [0; SIZE_64KB],
|
||||
memory: boxed_array,
|
||||
a: 0,
|
||||
x: 0,
|
||||
y: 0,
|
||||
@@ -103,5 +111,7 @@ impl Mos6502Cpu {
|
||||
self.pc, self.a, self.x, self.y, self.address_bus, self.data_bus);
|
||||
}
|
||||
|
||||
|
||||
pub fn dump_data(&self) -> ( u16, u8, u8, u8, u16, u8) {
|
||||
(self.pc, self.a, self.x, self.y, self.address_bus, self.data_bus)
|
||||
}
|
||||
}
|
||||
|
||||
+25
-10
@@ -1,4 +1,4 @@
|
||||
use crate::mos6502cpu::SIZE_32KB;
|
||||
use crate::mos6502cpu::{SIZE_32KB, SIZE_64KB};
|
||||
use crate::periph::rom_chip::RomChip;
|
||||
|
||||
/// At28C256
|
||||
@@ -8,24 +8,37 @@ use crate::periph::rom_chip::RomChip;
|
||||
/// 256kbit storage
|
||||
/// 32kbyte storage
|
||||
pub struct At28C256 {
|
||||
data: [u8; SIZE_32KB]
|
||||
data: Box<[u8; SIZE_32KB]>,
|
||||
}
|
||||
|
||||
impl Default for At28C256 {
|
||||
fn default() -> Self {
|
||||
let vec = vec![0x00; SIZE_32KB];
|
||||
let boxed_slice: Box<[u8]> = vec.into_boxed_slice();
|
||||
let boxed_array: Box<[u8; SIZE_32KB]> = boxed_slice.try_into().expect("Failed to convert Vec to boxed array");
|
||||
At28C256 {
|
||||
data: boxed_array,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RomChip for At28C256 {
|
||||
|
||||
fn read(&self, offset: &u16) -> u8 {
|
||||
self.data[*offset as usize]
|
||||
}
|
||||
|
||||
fn program(new_data: &[u8; SIZE_32KB]) -> Self {
|
||||
fn program(new_data: Box<[u8; 33554432]>) -> Box<At28C256> {
|
||||
println!("Writing new chip.");
|
||||
At28C256 {
|
||||
data: *new_data
|
||||
}
|
||||
let mut working = At28C256::default();
|
||||
working.data = Box::new(*new_data);
|
||||
working.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::mos6502cpu::SIZE_1KB;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@@ -36,16 +49,18 @@ mod test {
|
||||
#[test]
|
||||
fn programmed_data_reads_back_same() {
|
||||
print!("Starting test...");
|
||||
let data_to_write = [0xea; SIZE_32KB];
|
||||
let mut data = At28C256::default();
|
||||
for i in 0..SIZE_32KB {
|
||||
data.data[i] = 0xea;
|
||||
}
|
||||
print!("allocated data for rom...");
|
||||
let chip: At28C256 = At28C256::program(&data_to_write);
|
||||
println!("programmed chip...");
|
||||
print!("testing");
|
||||
for offset in 0..SIZE_32KB {
|
||||
if offset.is_multiple_of(1000) {
|
||||
if offset.is_multiple_of(SIZE_1KB) {
|
||||
print!(".");
|
||||
};
|
||||
assert_eq!(0xea, chip.read(&(offset as u16)));
|
||||
assert_eq!(0xea, data.read(&(offset as u16)));
|
||||
}
|
||||
println!("passed!");
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@ pub trait RomChip {
|
||||
/// Program
|
||||
///
|
||||
/// Replaces all data in the ROM chip
|
||||
fn program(new_data: &[u8; SIZE_32KB]) -> Self;
|
||||
fn program(new_data: Box<[u8; SIZE_32KB]>) -> Box<Self>;
|
||||
}
|
||||
|
||||
pub trait RamChip: RomChip {
|
||||
fn write(&mut self, offset: &u16, value: &u8);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user