From 76e54acfebdd3056587543c671d3e82eab64b5af Mon Sep 17 00:00:00 2001 From: pjht Date: Fri, 25 Nov 2022 08:51:19 -0600 Subject: [PATCH] Switch to 16-bit card IDs --- src/ram.rs | 6 ++++-- src/rom.rs | 8 +++++--- src/storage.rs | 6 ++++-- src/term.rs | 11 +++++++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ram.rs b/src/ram.rs index feef26c..afd1475 100644 --- a/src/ram.rs +++ b/src/ram.rs @@ -7,11 +7,13 @@ use toml::Value; use crate::{ backplane::DMAHandler, - card::{u32_get_be_byte, Card}, + card::{u16_get_be_byte, u32_get_be_byte, Card}, m68k::BusError, register, }; +const ID: u16 = 2; + #[derive(Deserialize)] struct Config { size: u32, @@ -79,7 +81,7 @@ impl Card for Ram { 2 => NullableResult::Ok((self.start >> 8) as u8), 3 => NullableResult::Ok((self.start as u8) | u8::from(self.enabled)), (4..=7) => NullableResult::Ok(u32_get_be_byte(self.data.len() as u32, address - 4)), - 0xFF => NullableResult::Ok(2), + (0xFE..=0xFF) => NullableResult::Ok(u16_get_be_byte(ID, address - 0xFE)), _ => NullableResult::Null, } } diff --git a/src/rom.rs b/src/rom.rs index e0fc968..ef5c2f8 100644 --- a/src/rom.rs +++ b/src/rom.rs @@ -13,6 +13,8 @@ use crate::{ register, }; +const ID: u16 = 1; + #[derive(Deserialize)] struct Config { image: Option, @@ -79,8 +81,8 @@ impl Card for Rom { match address { (0..=0xEF) => NullableResult::Ok(self.ram[address as usize]), (0xF0..=0xF1) => NullableResult::Ok(u16_get_be_byte(self.start, address - 0xF0)), - 0xFE => NullableResult::Ok(self.enabled as u8), - 0xFF => NullableResult::Ok(1), + 0xF2 => NullableResult::Ok(self.enabled as u8), + (0xFE..=0xFF) => NullableResult::Ok(u16_get_be_byte(ID, address - 0xFE)), _ => NullableResult::Null, } } @@ -93,7 +95,7 @@ impl Card for Rom { (0xF0..=0xF1) => { self.start = u16_set_be_byte(self.start, address - 0xF0, data); } - 0xFE => { + 0xF2 => { self.enabled = data > 0; } _ => (), diff --git a/src/storage.rs b/src/storage.rs index e9c6bb0..255de5a 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -17,6 +17,7 @@ use std::{ }; use toml::Value; +const ID: u16 = 4; const SECTOR_SIZE: u64 = 512; #[derive(Deserialize)] @@ -86,7 +87,7 @@ impl Card for Storage { NullableResult::Ok(self.read_data.pop_front().unwrap_or(0)) } 0xC..=0x10 => NullableResult::Ok(u32_get_be_byte(self.start_addresss, address - 0xD)), - 0xFF => NullableResult::Ok(4), + (0xFE..=0xFF) => NullableResult::Ok(u16_get_be_byte(ID, address - 0xFE)), _ => NullableResult::Null, } } @@ -172,7 +173,8 @@ impl DMAHandler for Dma { if card_accessor.get().transfer { let mut address = card_accessor.get().start_addresss; #[allow(clippy::redundant_closure_call)] - // Closure is used to drop the mutex guard between pop calls to prevent deadlock + // Closure is used to drop the mutex guard + // between pop calls to prevent deadlock while let Some(data) = (|| card_accessor.get().read_data.pop_front())() { backplane.write_byte(address, data).unwrap(); address += 1; diff --git a/src/term.rs b/src/term.rs index df2b6ae..7b5633c 100644 --- a/src/term.rs +++ b/src/term.rs @@ -3,7 +3,14 @@ use std::fmt::Display; use nullable_result::NullableResult; use toml::Value; -use crate::{backplane::DMAHandler, card::Card, m68k::BusError, register}; +use crate::{ + backplane::DMAHandler, + card::{u16_get_be_byte, Card}, + m68k::BusError, + register, +}; + +const ID: u16 = 3; #[derive(Debug)] pub struct Term; @@ -24,7 +31,7 @@ impl Card for Term { fn read_byte_io(&mut self, address: u8) -> NullableResult { match address { - 0xFF => NullableResult::Ok(3), + (0xFE..=0xFF) => NullableResult::Ok(u16_get_be_byte(ID, address - 0xFE)), _ => NullableResult::Null, } }