fox32: Restructure Memory a little bit, and print sizes on startup

This commit is contained in:
ry755 2022-01-27 17:17:11 -08:00 committed by Ry
parent abee6efc82
commit 06f69b322b
2 changed files with 31 additions and 17 deletions

View File

@ -68,11 +68,23 @@ fn main() {
let shared_memory = Arc::new(Mutex::new(vec![0u8; 0x0200000F]));
let mut cpu = {
// 32 MiB of fast memory
let cpu_fast_memory = vec![0; 0x02000000];
let cpu_shared_memory = Arc::clone(&shared_memory);
let cpu_overlays = Arc::clone(&display.overlays);
let cpu_read_only_memory = read_rom();
// 32 MiB of CPU-only memory
let memory = Memory::new(0x02000000, cpu_shared_memory, cpu_overlays, cpu_read_only_memory);
let fast_size = cpu_fast_memory.len();
let fast_bottom_address = 0x00000000;
let fast_top_address = fast_bottom_address + fast_size - 1;
println!("Fast memory: {:.2}MB mapped at {:#010X}-{:#010X}", fast_size / 1048576, fast_bottom_address, fast_top_address);
let shared_size = { cpu_shared_memory.lock().unwrap().len() };
let shared_bottom_address = 0x02000000;
let shared_top_address = shared_bottom_address + shared_size - 1;
println!("Shared memory: {:.2}MB mapped at {:#010X}-{:#010X}", shared_size / 1048576, shared_bottom_address, shared_top_address);
let memory = Memory::new(cpu_fast_memory, cpu_shared_memory, cpu_overlays, cpu_read_only_memory);
let cpu_mouse = Arc::clone(&mouse);

View File

@ -5,25 +5,27 @@ use crate::{Overlay};
use std::sync::{Arc, Mutex};
pub struct Memory {
ram: Vec<u8>,
rom: Vec<u8>,
fast_memory: Vec<u8>,
pub shared_memory: Arc<Mutex<Vec<u8>>>,
pub overlays: Arc<Mutex<Vec<Overlay>>>,
rom: Vec<u8>,
}
impl Memory {
pub fn new(size: u32, shared_memory: Arc<Mutex<Vec<u8>>>, overlays: Arc<Mutex<Vec<Overlay>>>, read_only_memory: Vec<u8>) -> Self {
pub fn new(fast_memory: Vec<u8>, shared_memory: Arc<Mutex<Vec<u8>>>, overlays: Arc<Mutex<Vec<Overlay>>>, rom: Vec<u8>) -> Self {
Memory {
ram: vec![0; size as usize],
rom: read_only_memory,
fast_memory,
shared_memory,
overlays,
rom,
}
}
pub fn read_8(&self, address: u32) -> u8 {
let address = address as usize;
if address < 0x02000000 {
self.ram[address]
self.fast_memory[address]
} else if address >= 0xF0000000 {
let address = address - 0xF0000000;
self.rom[address]
@ -40,10 +42,10 @@ impl Memory {
pub fn read_32(&self, address: u32) -> u32 {
let address = address as usize;
if address < 0x02000000 {
(self.ram[address + 3] as u32) << 24 |
(self.ram[address + 2] as u32) << 16 |
(self.ram[address + 1] as u32) << 8 |
(self.ram[address] as u32)
(self.fast_memory[address + 3] as u32) << 24 |
(self.fast_memory[address + 2] as u32) << 16 |
(self.fast_memory[address + 1] as u32) << 8 |
(self.fast_memory[address] as u32)
} else if address >= 0xF0000000 {
let address = address - 0xF0000000;
(self.rom[address + 3] as u32) << 24 |
@ -62,7 +64,7 @@ impl Memory {
pub fn write_8(&mut self, address: u32, byte: u8) {
let address = address as usize;
if address < 0x02000000 {
self.ram[address] = byte;
self.fast_memory[address] = byte;
} else {
let address = address - 0x02000000;
let mut shared_memory_lock = self.shared_memory.lock().unwrap();
@ -76,10 +78,10 @@ impl Memory {
pub fn write_32(&mut self, address: u32, word: u32) {
let address = address as usize;
if address < 0x02000000 {
self.ram[address] = (word & 0x000000FF) as u8;
self.ram[address + 1] = ((word & 0x0000FF00) >> 8) as u8;
self.ram[address + 2] = ((word & 0x00FF0000) >> 16) as u8;
self.ram[address + 3] = ((word & 0xFF000000) >> 24) as u8;
self.fast_memory[address] = (word & 0x000000FF) as u8;
self.fast_memory[address + 1] = ((word & 0x0000FF00) >> 8) as u8;
self.fast_memory[address + 2] = ((word & 0x00FF0000) >> 16) as u8;
self.fast_memory[address + 3] = ((word & 0xFF000000) >> 24) as u8;
} else {
let address = address - 0x02000000;
let mut shared_memory_lock = self.shared_memory.lock().unwrap();