cargo fmt everywhere

This commit is contained in:
Gwilym Inzani 2023-03-23 21:47:44 +00:00
parent 85defe8e2b
commit ec3e43da56
10 changed files with 86 additions and 38 deletions

View file

@ -28,9 +28,7 @@ impl FromStr for Colour {
fn from_str(colour: &str) -> Result<Self, Self::Err> {
if colour.len() != 6 {
return Err(format!(
"Expected colour to be 6 characters, got {colour}"
));
return Err(format!("Expected colour to be 6 characters, got {colour}"));
}
let r = u8::from_str_radix(&colour[0..2], 16).unwrap();

View file

@ -385,8 +385,7 @@ fn add_image_to_tile_data(
for j in inner_y * 8..inner_y * 8 + 8 {
for i in inner_x * 8..inner_x * 8 + 8 {
let colour = image.colour(x * tile_size + i, y * tile_size + j);
tile_data
.push(palette.colour_index(colour));
tile_data.push(palette.colour_index(colour));
}
}
}

View file

@ -6,13 +6,10 @@ use agb::sync::Static;
#[agb::entry]
fn main(_gba: agb::Gba) -> ! {
let count = Static::new(0);
let _a = agb::interrupt::add_interrupt_handler(
agb::interrupt::Interrupt::VBlank,
|_| {
let cur_count = count.read();
agb::println!("Hello, world, frame = {}", cur_count);
count.write(cur_count + 1);
},
);
let _a = agb::interrupt::add_interrupt_handler(agb::interrupt::Interrupt::VBlank, |_| {
let cur_count = count.read();
agb::println!("Hello, world, frame = {}", cur_count);
count.write(cur_count + 1);
});
loop {}
}

View file

@ -49,4 +49,4 @@ pub(crate) fn dma3_exclusive<R>(f: impl FnOnce() -> R) -> R {
// returns the return value
ret
})
}
}

View file

@ -3,8 +3,8 @@
//! EEPROM requires using DMA to issue commands for both reading and writing.
use crate::memory_mapped::MemoryMapped;
use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess};
use crate::save::utils::Timeout;
use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess};
use core::cmp;
const PORT: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0DFFFF00) };
@ -41,7 +41,10 @@ union BufferContents {
}
impl BufferData {
fn new() -> Self {
BufferData { idx: 0, data: BufferContents { uninit: () } }
BufferData {
idx: 0,
data: BufferContents { uninit: () },
}
}
/// Writes a bit to the output buffer.
@ -120,7 +123,10 @@ impl EepromProperties {
/// Writes a sector directly.
#[allow(clippy::needless_range_loop)]
fn write_sector_raw(
&self, word: usize, block: &[u8], timeout: &mut Timeout,
&self,
word: usize,
block: &[u8],
timeout: &mut Timeout,
) -> Result<(), Error> {
// Write sector command. The command is a one bit, followed by a
// zero bit, followed by the address, followed by 64 bits of data.
@ -150,7 +156,11 @@ impl EepromProperties {
/// Writes a sector to the EEPROM, keeping any current contents outside the
/// buffer's range.
fn write_sector_safe(
&self, word: usize, data: &[u8], start: usize, timeout: &mut Timeout,
&self,
word: usize,
data: &[u8],
start: usize,
timeout: &mut Timeout,
) -> Result<(), Error> {
let mut buf = self.read_sector(word);
buf[start..start + data.len()].copy_from_slice(data);
@ -159,7 +169,11 @@ impl EepromProperties {
/// Writes a sector to the EEPROM.
fn write_sector(
&self, word: usize, data: &[u8], start: usize, timeout: &mut Timeout,
&self,
word: usize,
data: &[u8],
start: usize,
timeout: &mut Timeout,
) -> Result<(), Error> {
if data.len() == 8 && start == 0 {
self.write_sector_raw(word, data, timeout)
@ -219,8 +233,14 @@ impl EepromProperties {
Ok(())
}
}
const PROPS_512B: EepromProperties = EepromProperties { addr_bits: 6, byte_len: 512 };
const PROPS_8K: EepromProperties = EepromProperties { addr_bits: 14, byte_len: 8 * 1024 };
const PROPS_512B: EepromProperties = EepromProperties {
addr_bits: 6,
byte_len: 512,
};
const PROPS_8K: EepromProperties = EepromProperties {
addr_bits: 14,
byte_len: 8 * 1024,
};
/// The [`RawSaveAccess`] used for 512 byte EEPROM.
pub struct Eeprom512B;

View file

@ -6,11 +6,11 @@
// TODO: Setup cartridge read timings for faster Flash access.
use crate::memory_mapped::{MemoryMapped, MemoryMapped1DArray};
use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess};
use crate::save::asm_utils::*;
use crate::save::utils::Timeout;
use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess};
use crate::sync::{InitOnce, Static};
use core::cmp;
use crate::save::utils::Timeout;
// Volatile address ports for flash
const FLASH_PORT_BANK: MemoryMapped<u8> = unsafe { MemoryMapped::new(0x0E000000) };
@ -314,7 +314,11 @@ impl ChipInfo {
/// Waits for a timeout, or an operation to complete.
fn wait_for_timeout(
&self, offset: usize, val: u8, ms: u16, timeout: &mut Timeout,
&self,
offset: usize,
val: u8,
ms: u16,
timeout: &mut Timeout,
) -> Result<(), Error> {
timeout.start();
let offset = 0x0E000000 + offset;
@ -371,7 +375,10 @@ impl ChipInfo {
/// Erases and writes an entire 128b sector on Atmel devices.
#[allow(clippy::needless_range_loop)]
fn write_atmel_sector_raw(
&self, offset: usize, buf: &[u8], timeout: &mut Timeout,
&self,
offset: usize,
buf: &[u8],
timeout: &mut Timeout,
) -> Result<(), Error> {
crate::interrupt::free(|_| {
issue_flash_command(CMD_WRITE);
@ -387,12 +394,19 @@ impl ChipInfo {
/// case of non-sector aligned writes.
#[inline(never)] // avoid allocating the 128 byte buffer for no reason.
fn write_atmel_sector_safe(
&self, offset: usize, buf: &[u8], start: usize, timeout: &mut Timeout,
&self,
offset: usize,
buf: &[u8],
start: usize,
timeout: &mut Timeout,
) -> Result<(), Error> {
let mut sector = [0u8; 128];
self.read_buffer(offset, &mut sector[0..start])?;
sector[start..start + buf.len()].copy_from_slice(buf);
self.read_buffer(offset + start + buf.len(), &mut sector[start + buf.len()..128])?;
self.read_buffer(
offset + start + buf.len(),
&mut sector[start + buf.len()..128],
)?;
self.write_atmel_sector_raw(offset, &sector, timeout)
}
@ -401,7 +415,11 @@ impl ChipInfo {
///
/// This avoids allocating stack if there is no need to.
fn write_atmel_sector(
&self, offset: usize, buf: &[u8], start: usize, timeout: &mut Timeout,
&self,
offset: usize,
buf: &[u8],
start: usize,
timeout: &mut Timeout,
) -> Result<(), Error> {
if start == 0 && buf.len() == 128 {
self.write_atmel_sector_raw(offset, buf, timeout)
@ -433,7 +451,10 @@ impl RawSaveAccess for FlashAccess {
}
fn prepare_write(
&self, sector: usize, count: usize, timeout: &mut Timeout,
&self,
sector: usize,
count: usize,
timeout: &mut Timeout,
) -> Result<(), Error> {
let chip = cached_chip_info()?;
chip.check_sector_len(sector, count)?;

View file

@ -3,9 +3,9 @@
//! SRAM acts as ordinary memory mapped into the memory space, and as such
//! is accessed using normal memory read/write commands.
use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess};
use crate::save::asm_utils::*;
use crate::save::utils::Timeout;
use crate::save::{Error, MediaInfo, MediaType, RawSaveAccess};
const SRAM_SIZE: usize = 32 * 1024; // 32 KiB

View file

@ -2,7 +2,7 @@
use super::Error;
use crate::sync::{RawMutex, RawMutexGuard};
use crate::timer::{Timer, Divider};
use crate::timer::{Divider, Timer};
/// A timeout type used to prevent hardware errors in save media from hanging
/// the game.

View file

@ -81,7 +81,10 @@ impl<T> Mutex<T> {
/// Creates a new lock containing a given value.
#[must_use]
pub const fn new(t: T) -> Self {
Mutex { raw: RawMutex::new(), data: UnsafeCell::new(t) }
Mutex {
raw: RawMutex::new(),
data: UnsafeCell::new(t),
}
}
/// Returns a guard for this lock, or panics if there is another lock active.
@ -92,7 +95,10 @@ impl<T> Mutex<T> {
/// Returns a guard for this lock or `None` if there is another lock active.
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
if self.raw.raw_lock() {
Some(MutexGuard { underlying: self, ptr: self.data.get() })
Some(MutexGuard {
underlying: self,
ptr: self.data.get(),
})
} else {
None
}

View file

@ -1,6 +1,6 @@
use core::cmp;
use agb::save::{Error, MediaInfo};
use agb::sync::InitOnce;
use core::cmp;
fn init_sram(gba: &mut agb::Gba) -> &'static MediaInfo {
static ONCE: InitOnce<MediaInfo> = InitOnce::new();
@ -31,7 +31,11 @@ const MAX_BLOCK_SIZE: usize = 4 * 1024;
#[allow(clippy::needless_range_loop)]
fn do_test(
gba: &mut agb::Gba, seed: Rng, offset: usize, len: usize, block_size: usize,
gba: &mut agb::Gba,
seed: Rng,
offset: usize,
len: usize,
block_size: usize,
) -> Result<(), Error> {
let mut buffer = [0; MAX_BLOCK_SIZE];
@ -61,9 +65,12 @@ fn do_test(
for i in 0..cur_len {
let cur_byte = rng.next_u8();
assert_eq!(
buffer[i], cur_byte,
buffer[i],
cur_byte,
"Read does not match earlier write: {} != {} @ 0x{:05x}",
buffer[i], cur_byte, current + i,
buffer[i],
cur_byte,
current + i,
);
}
current += cur_len;
@ -102,4 +109,4 @@ fn test_partial_writes(gba: &mut agb::Gba) {
do_test(gba, Rng(i * 10000), rand_offset, rand_length, block_size)
.expect("Test encountered error");
}
}
}