mirror of
https://github.com/transistorfet/moa.git
synced 2024-06-10 07:29:31 +00:00
Changed the Addressable trait's len() to size()
This is to avoid the need for the clippy override
This commit is contained in:
parent
4d6e3af567
commit
3db52cbef6
|
@ -27,9 +27,8 @@ pub trait Interruptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A device that can be addressed to read data from or write data to the device.
|
/// 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 {
|
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 read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error>;
|
||||||
fn write(&mut self, clock: ClockTime, addr: Address, data: &[u8]) -> Result<(), Error>;
|
fn write(&mut self, clock: ClockTime, addr: Address, data: &[u8]) -> Result<(), Error>;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl MemoryBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for MemoryBlock {
|
impl Addressable for MemoryBlock {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.contents.len()
|
self.contents.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +92,9 @@ impl AddressRightShifter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for AddressRightShifter {
|
impl Addressable for AddressRightShifter {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
let len = self.subdevice.borrow_mut().as_addressable().unwrap().len();
|
let size = self.subdevice.borrow_mut().as_addressable().unwrap().size();
|
||||||
len << self.shift
|
size << self.shift
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
|
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
|
||||||
|
@ -128,18 +128,18 @@ impl AddressRepeater {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for AddressRepeater {
|
impl Addressable for AddressRepeater {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.range as usize
|
self.range as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
|
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;
|
let size = self.subdevice.borrow_mut().as_addressable().unwrap().size() as Address;
|
||||||
self.subdevice.borrow_mut().as_addressable().unwrap().read(clock, addr % len, data)
|
self.subdevice.borrow_mut().as_addressable().unwrap().read(clock, addr % size, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, clock: ClockTime, addr: Address, data: &[u8]) -> Result<(), Error> {
|
fn write(&mut self, clock: ClockTime, addr: Address, data: &[u8]) -> Result<(), Error> {
|
||||||
let len = self.subdevice.borrow_mut().as_addressable().unwrap().len() as Address;
|
let size = self.subdevice.borrow_mut().as_addressable().unwrap().size() as Address;
|
||||||
self.subdevice.borrow_mut().as_addressable().unwrap().write(clock, addr % len, data)
|
self.subdevice.borrow_mut().as_addressable().unwrap().write(clock, addr % size, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ impl Transmutable for AddressRepeater {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
pub base: Address,
|
pub base: Address,
|
||||||
pub length: usize,
|
pub size: usize,
|
||||||
pub dev: TransmutableBox,
|
pub dev: TransmutableBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,17 +175,17 @@ impl Bus {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, base: Address, dev: TransmutableBox) {
|
pub fn insert(&mut self, base: Address, dev: TransmutableBox) {
|
||||||
let length = dev.borrow_mut().as_addressable().unwrap().len();
|
let size = dev.borrow_mut().as_addressable().unwrap().size();
|
||||||
let block = Block { base, length, dev };
|
let block = Block { base, size, dev };
|
||||||
let i = self.blocks.iter().position(|cur| cur.base > block.base).unwrap_or(self.blocks.len());
|
let i = self.blocks.iter().position(|cur| cur.base > block.base).unwrap_or(self.blocks.len());
|
||||||
self.blocks.insert(i, block);
|
self.blocks.insert(i, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_device_at(&self, addr: Address, count: usize) -> Result<(TransmutableBox, Address), Error> {
|
pub fn get_device_at(&self, addr: Address, count: usize) -> Result<(TransmutableBox, Address), Error> {
|
||||||
for block in &self.blocks {
|
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;
|
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));
|
return Ok((block.dev.clone(), relative_addr));
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::new(&format!("Error reading address {:#010x}", addr)));
|
return Err(Error::new(&format!("Error reading address {:#010x}", addr)));
|
||||||
|
@ -233,9 +233,9 @@ impl Bus {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Bus {
|
impl Addressable for Bus {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
let block = &self.blocks[self.blocks.len() - 1];
|
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> {
|
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
|
||||||
|
@ -304,8 +304,8 @@ impl BusPort {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for BusPort {
|
impl Addressable for BusPort {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
self.subdevice.borrow().len()
|
self.subdevice.borrow().size()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
|
fn read(&mut self, clock: ClockTime, addr: Address, data: &mut [u8]) -> Result<(), Error> {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use moa_core::{Error, ClockTime, Address, Addressable, BusPort};
|
use moa_core::{Error, ClockTime, Address, Addressable, BusPort};
|
||||||
|
|
||||||
use crate::state::{M68k, Exceptions};
|
use crate::state::{M68k, Exceptions};
|
||||||
use crate::instructions::{Target, Size};
|
use crate::instructions::Size;
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl AtaDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for AtaDevice {
|
impl Addressable for AtaDevice {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x30
|
0x30
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl Default for Mos6522 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Mos6522 {
|
impl Addressable for Mos6522 {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x10
|
0x10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl Steppable for MC68681 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for MC68681 {
|
impl Addressable for MC68681 {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x30
|
0x30
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl Steppable for Sn76489 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Sn76489 {
|
impl Addressable for Sn76489 {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x01
|
0x01
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1016,7 +1016,7 @@ fn get_ch(bank: u8, reg: u8) -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Ym2612 {
|
impl Addressable for Ym2612 {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x04
|
0x04
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct Z8530 {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Z8530 {
|
impl Addressable for Z8530 {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x10
|
0x10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ impl GenesisControllers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for GenesisControllers {
|
impl Addressable for GenesisControllers {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x30
|
0x30
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ impl CoprocessorCoordinator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for CoprocessorCoordinator {
|
impl Addressable for CoprocessorCoordinator {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x4000
|
0x4000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ impl CoprocessorBankRegister {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for CoprocessorBankRegister {
|
impl Addressable for CoprocessorBankRegister {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x01
|
0x01
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ impl CoprocessorBankArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for CoprocessorBankArea {
|
impl Addressable for CoprocessorBankArea {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x8000
|
0x8000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -804,7 +804,7 @@ fn decode_scroll_size(size: u8) -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Ym7101 {
|
impl Addressable for Ym7101 {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x20
|
0x20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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/Ghostbusters (REV 00) (JUE).bin").unwrap();
|
||||||
//let mut rom = MemoryBlock::load("binaries/genesis/Teenage Mutant Ninja Turtles - The Hyperstone Heist (U) [!].bin").unwrap();
|
//let mut rom = MemoryBlock::load("binaries/genesis/Teenage Mutant Ninja Turtles - The Hyperstone Heist (U) [!].bin").unwrap();
|
||||||
//rom.read_only();
|
//rom.read_only();
|
||||||
let rom_end = rom.len();
|
let rom_end = rom.size();
|
||||||
system.add_addressable_device(0x00000000, wrap_transmutable(rom)).unwrap();
|
system.add_addressable_device(0x00000000, wrap_transmutable(rom)).unwrap();
|
||||||
|
|
||||||
let cartridge_nvram = MemoryBlock::new(vec![0; 0x400000 - rom_end]);
|
let cartridge_nvram = MemoryBlock::new(vec![0; 0x400000 - rom_end]);
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl IWM {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for IWM {
|
impl Addressable for IWM {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x10
|
0x10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl Mainboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Mainboard {
|
impl Addressable for Mainboard {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x01000000
|
0x01000000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ pub struct PhaseRead {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for PhaseRead {
|
impl Addressable for PhaseRead {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x80000
|
0x80000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl Model1Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Model1Keyboard {
|
impl Addressable for Model1Keyboard {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x420
|
0x420
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ impl Steppable for Model1Video {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addressable for Model1Video {
|
impl Addressable for Model1Video {
|
||||||
fn len(&self) -> usize {
|
fn size(&self) -> usize {
|
||||||
0x400
|
0x400
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user