Changed the Addressable trait's len() to size()

This is to avoid the need for the clippy override
This commit is contained in:
transistor 2023-06-07 19:56:00 -07:00
parent 4d6e3af567
commit 3db52cbef6
16 changed files with 37 additions and 38 deletions

View File

@ -27,9 +27,8 @@ pub trait Interruptable {
}
/// A device that can be addressed to read data from or write data to the device.
#[allow(clippy::len_without_is_empty)]
pub trait Addressable {
fn len(&self) -> usize;
fn size(&self) -> usize;
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error>;
fn write(&mut self, clock: ClockTime, addr: Address, data: &[u8]) -> Result<(), Error>;

View File

@ -51,7 +51,7 @@ impl MemoryBlock {
}
impl Addressable for MemoryBlock {
fn len(&self) -> usize {
fn size(&self) -> usize {
self.contents.len()
}
@ -92,9 +92,9 @@ impl AddressRightShifter {
}
impl Addressable for AddressRightShifter {
fn len(&self) -> usize {
let len = self.subdevice.borrow_mut().as_addressable().unwrap().len();
len << self.shift
fn size(&self) -> usize {
let size = self.subdevice.borrow_mut().as_addressable().unwrap().size();
size << self.shift
}
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
@ -128,18 +128,18 @@ impl AddressRepeater {
}
impl Addressable for AddressRepeater {
fn len(&self) -> usize {
fn size(&self) -> usize {
self.range as usize
}
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
let len = self.subdevice.borrow_mut().as_addressable().unwrap().len() as Address;
self.subdevice.borrow_mut().as_addressable().unwrap().read(clock, addr % len, data)
let size = self.subdevice.borrow_mut().as_addressable().unwrap().size() as Address;
self.subdevice.borrow_mut().as_addressable().unwrap().read(clock, addr % size, data)
}
fn write(&mut self, clock: ClockTime, addr: Address, data: &[u8]) -> Result<(), Error> {
let len = self.subdevice.borrow_mut().as_addressable().unwrap().len() as Address;
self.subdevice.borrow_mut().as_addressable().unwrap().write(clock, addr % len, data)
let size = self.subdevice.borrow_mut().as_addressable().unwrap().size() as Address;
self.subdevice.borrow_mut().as_addressable().unwrap().write(clock, addr % size, data)
}
}
@ -153,7 +153,7 @@ impl Transmutable for AddressRepeater {
#[derive(Clone)]
pub struct Block {
pub base: Address,
pub length: usize,
pub size: usize,
pub dev: TransmutableBox,
}
@ -175,17 +175,17 @@ impl Bus {
}
pub fn insert(&mut self, base: Address, dev: TransmutableBox) {
let length = dev.borrow_mut().as_addressable().unwrap().len();
let block = Block { base, length, dev };
let size = dev.borrow_mut().as_addressable().unwrap().size();
let block = Block { base, size, dev };
let i = self.blocks.iter().position(|cur| cur.base > block.base).unwrap_or(self.blocks.len());
self.blocks.insert(i, block);
}
pub fn get_device_at(&self, addr: Address, count: usize) -> Result<(TransmutableBox, Address), Error> {
for block in &self.blocks {
if addr >= block.base && addr < (block.base + block.length as Address) {
if addr >= block.base && addr < (block.base + block.size as Address) {
let relative_addr = addr - block.base;
if relative_addr as usize + count <= block.length {
if relative_addr as usize + count <= block.size {
return Ok((block.dev.clone(), relative_addr));
} else {
return Err(Error::new(&format!("Error reading address {:#010x}", addr)));
@ -233,9 +233,9 @@ impl Bus {
}
impl Addressable for Bus {
fn len(&self) -> usize {
fn size(&self) -> usize {
let block = &self.blocks[self.blocks.len() - 1];
(block.base as usize) + block.length
(block.base as usize) + block.size
}
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
@ -304,8 +304,8 @@ impl BusPort {
}
impl Addressable for BusPort {
fn len(&self) -> usize {
self.subdevice.borrow().len()
fn size(&self) -> usize {
self.subdevice.borrow().size()
}
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {

View File

@ -2,7 +2,7 @@
use moa_core::{Error, ClockTime, Address, Addressable, BusPort};
use crate::state::{M68k, Exceptions};
use crate::instructions::{Target, Size};
use crate::instructions::Size;
#[repr(u8)]
#[allow(dead_code)]

View File

@ -53,7 +53,7 @@ impl AtaDevice {
}
impl Addressable for AtaDevice {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x30
}

View File

@ -53,7 +53,7 @@ impl Default for Mos6522 {
}
impl Addressable for Mos6522 {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x10
}

View File

@ -246,7 +246,7 @@ impl Steppable for MC68681 {
}
impl Addressable for MC68681 {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x30
}

View File

@ -135,7 +135,7 @@ impl Steppable for Sn76489 {
}
impl Addressable for Sn76489 {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x01
}

View File

@ -1016,7 +1016,7 @@ fn get_ch(bank: u8, reg: u8) -> usize {
}
impl Addressable for Ym2612 {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x04
}

View File

@ -9,7 +9,7 @@ pub struct Z8530 {
}
impl Addressable for Z8530 {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x10
}

View File

@ -142,7 +142,7 @@ impl GenesisControllers {
}
impl Addressable for GenesisControllers {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x30
}

View File

@ -24,7 +24,7 @@ impl CoprocessorCoordinator {
}
impl Addressable for CoprocessorCoordinator {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x4000
}
@ -75,7 +75,7 @@ impl CoprocessorBankRegister {
}
impl Addressable for CoprocessorBankRegister {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x01
}
@ -114,7 +114,7 @@ impl CoprocessorBankArea {
}
impl Addressable for CoprocessorBankArea {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x8000
}

View File

@ -804,7 +804,7 @@ fn decode_scroll_size(size: u8) -> usize {
}
impl Addressable for Ym7101 {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x20
}

View File

@ -57,7 +57,7 @@ pub fn build_genesis<H: Host>(host: &mut H, mut options: SegaGenesisOptions) ->
//let mut rom = MemoryBlock::load("binaries/genesis/Ghostbusters (REV 00) (JUE).bin").unwrap();
//let mut rom = MemoryBlock::load("binaries/genesis/Teenage Mutant Ninja Turtles - The Hyperstone Heist (U) [!].bin").unwrap();
//rom.read_only();
let rom_end = rom.len();
let rom_end = rom.size();
system.add_addressable_device(0x00000000, wrap_transmutable(rom)).unwrap();
let cartridge_nvram = MemoryBlock::new(vec![0; 0x400000 - rom_end]);

View File

@ -34,7 +34,7 @@ impl IWM {
}
impl Addressable for IWM {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x10
}

View File

@ -65,7 +65,7 @@ impl Mainboard {
}
impl Addressable for Mainboard {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x01000000
}
@ -142,7 +142,7 @@ pub struct PhaseRead {
}
impl Addressable for PhaseRead {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x80000
}

View File

@ -28,7 +28,7 @@ impl Model1Keyboard {
}
impl Addressable for Model1Keyboard {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x420
}
@ -113,7 +113,7 @@ impl Steppable for Model1Video {
}
impl Addressable for Model1Video {
fn len(&self) -> usize {
fn size(&self) -> usize {
0x400
}