71 lines
2.0 KiB
Rust
71 lines
2.0 KiB
Rust
use crate::constants::constants_system::SIZE_32KB;
|
|
use crate::periph::at28c256::At28C256;
|
|
use crate::periph::hm62256::Hm62256;
|
|
|
|
impl At28C256 {
|
|
fn talking_to_me(&self, address: u16) -> bool {
|
|
//println!("Checking on {address:04x} in range of {:04x} {:04x}", self.offset, self.max_offset);
|
|
address >= self.offset && address < self.max_offset
|
|
}
|
|
|
|
|
|
|
|
pub fn tick(&mut self, address_bus: u16, data_bus: u8, read_mode: bool) -> (u16, u8) {
|
|
println!("At28C256: Tick starting for A${address_bus:04x} D${data_bus:02x} R{read_mode}");
|
|
|
|
// we aren't being addressed
|
|
// OR
|
|
// we arent reading from the ROM...
|
|
if !self.talking_to_me(address_bus) ||
|
|
!read_mode {
|
|
// ...go away.
|
|
return (address_bus, data_bus)
|
|
}
|
|
|
|
// print!("At28C256 tick for me.");
|
|
let effective = address_bus - self.offset;
|
|
if effective < self.max_offset {
|
|
if effective < self.data.len() as u16 {
|
|
self.data_bus = self.data[effective as usize];
|
|
} else {
|
|
self.data_bus = 0x00;
|
|
}
|
|
} else {
|
|
println!("At28C256: OUTSIDE RANGE. :(");
|
|
return (address_bus, data_bus)
|
|
}
|
|
|
|
// print!("At28C256: Read... {:02x}", self.data_bus);
|
|
(address_bus, self.data_bus)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use std::fs;
|
|
use crate::traits::rom_chip::RomChip;
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn smoke() { assert!(true); }
|
|
|
|
#[test]
|
|
fn checksum_binary_loads() {
|
|
let path = "/home/tmerritt/Projects/mos6502/resources/test/periph/at28c256/checksum.bin";
|
|
let bytes = match fs::read(path) {
|
|
Ok(bytes) => {
|
|
println!("Read {} bytes.", bytes.len());
|
|
bytes
|
|
},
|
|
Err(e) => {
|
|
eprintln!("FAIL to read rom.");
|
|
panic!("No rom no run.");
|
|
vec![]
|
|
}
|
|
};
|
|
|
|
let mut rom = At28C256::new(0x0000, 0x3fff, bytes);
|
|
|
|
assert_eq!(rom.checksum(), 0x58);
|
|
}
|
|
} |