Switch to 16-bit card IDs

This commit is contained in:
pjht 2022-11-25 08:51:19 -06:00
parent 9956962089
commit 76e54acfeb
4 changed files with 22 additions and 9 deletions

View File

@ -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,
}
}

View File

@ -13,6 +13,8 @@ use crate::{
register,
};
const ID: u16 = 1;
#[derive(Deserialize)]
struct Config {
image: Option<String>,
@ -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;
}
_ => (),

View File

@ -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;

View File

@ -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<u8, BusError> {
match address {
0xFF => NullableResult::Ok(3),
(0xFE..=0xFF) => NullableResult::Ok(u16_get_be_byte(ID, address - 0xFE)),
_ => NullableResult::Null,
}
}