mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 10:51:30 +11:00
Fix rustfmt to get things a little more compact
This commit is contained in:
parent
e95bcb7ed2
commit
2ca888b572
|
@ -133,9 +133,8 @@ when the `hello_magic` demo says
|
|||
We could re-write that more sensibly like this
|
||||
|
||||
```rust
|
||||
const SETTING: DisplayControlSetting = DisplayControlSetting::new()
|
||||
.with_mode(DisplayMode::Mode3)
|
||||
.with_bg2(true);
|
||||
const SETTING: DisplayControlSetting =
|
||||
DisplayControlSetting::new().with_mode(DisplayMode::Mode3).with_bg2(true);
|
||||
DISPCNT.write(SETTING);
|
||||
```
|
||||
|
||||
|
|
|
@ -15,9 +15,8 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
|||
|
||||
#[start]
|
||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
const SETTING: DisplayControlSetting = DisplayControlSetting::new()
|
||||
.with_mode(DisplayMode::Mode3)
|
||||
.with_bg2(true);
|
||||
const SETTING: DisplayControlSetting =
|
||||
DisplayControlSetting::new().with_mode(DisplayMode::Mode3).with_bg2(true);
|
||||
DISPCNT.write(SETTING);
|
||||
Mode3::write_pixel(120, 80, Color::from_rgb(31, 0, 0));
|
||||
Mode3::write_pixel(136, 80, Color::from_rgb(0, 31, 0));
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
color = "Never"
|
||||
error_on_line_overflow = false
|
||||
fn_args_density = "Compressed"
|
||||
merge_imports = true
|
||||
reorder_imports = true
|
||||
use_try_shorthand = true
|
||||
tab_spaces = 2
|
||||
max_width = 120
|
||||
color = "Never"
|
||||
max_width = 100
|
||||
use_small_heuristics = "Max"
|
||||
|
|
|
@ -19,10 +19,7 @@ pub struct Fx<T, F: Unsigned> {
|
|||
impl<T, F: Unsigned> Fx<T, F> {
|
||||
/// Uses the provided value directly.
|
||||
pub fn from_raw(r: T) -> Self {
|
||||
Fx {
|
||||
num: r,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: r, phantom: PhantomData }
|
||||
}
|
||||
|
||||
/// Unwraps the inner value.
|
||||
|
@ -32,60 +29,42 @@ impl<T, F: Unsigned> Fx<T, F> {
|
|||
|
||||
/// Casts the base type, keeping the fractional bit quantity the same.
|
||||
pub fn cast_inner<Z, C: Fn(T) -> Z>(self, op: C) -> Fx<Z, F> {
|
||||
Fx {
|
||||
num: op(self.num),
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: op(self.num), phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Add<Output = T>, F: Unsigned> Add for Fx<T, F> {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Fx<T, F>) -> Self::Output {
|
||||
Fx {
|
||||
num: self.num + rhs.num,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: self.num + rhs.num, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Sub<Output = T>, F: Unsigned> Sub for Fx<T, F> {
|
||||
type Output = Self;
|
||||
fn sub(self, rhs: Fx<T, F>) -> Self::Output {
|
||||
Fx {
|
||||
num: self.num - rhs.num,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: self.num - rhs.num, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Shl<u32, Output = T>, F: Unsigned> Shl<u32> for Fx<T, F> {
|
||||
type Output = Self;
|
||||
fn shl(self, rhs: u32) -> Self::Output {
|
||||
Fx {
|
||||
num: self.num << rhs,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: self.num << rhs, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Shr<u32, Output = T>, F: Unsigned> Shr<u32> for Fx<T, F> {
|
||||
type Output = Self;
|
||||
fn shr(self, rhs: u32) -> Self::Output {
|
||||
Fx {
|
||||
num: self.num >> rhs,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: self.num >> rhs, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Neg<Output = T>, F: Unsigned> Neg for Fx<T, F> {
|
||||
type Output = Self;
|
||||
fn neg(self) -> Self::Output {
|
||||
Fx {
|
||||
num: -self.num,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: -self.num, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,18 +73,12 @@ macro_rules! fixed_point_methods {
|
|||
impl<F: Unsigned> Fx<$t, F> {
|
||||
/// Gives the smallest positive non-zero value.
|
||||
pub fn precision() -> Self {
|
||||
Fx {
|
||||
num: 1,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: 1, phantom: PhantomData }
|
||||
}
|
||||
|
||||
/// Makes a value with the integer part shifted into place.
|
||||
pub fn from_int_part(i: $t) -> Self {
|
||||
Fx {
|
||||
num: i << F::U8,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: i << F::U8, phantom: PhantomData }
|
||||
}
|
||||
|
||||
/// Changes the fractional bit quantity, keeping the base type the same.
|
||||
|
@ -140,21 +113,12 @@ macro_rules! fixed_point_signed_multiply {
|
|||
let pre_shift = (self.num as i32).wrapping_mul(rhs.num as i32);
|
||||
if pre_shift < 0 {
|
||||
if pre_shift == core::i32::MIN {
|
||||
Fx {
|
||||
num: core::$t::MIN,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: core::$t::MIN, phantom: PhantomData }
|
||||
} else {
|
||||
Fx {
|
||||
num: (-((-pre_shift) >> F::U8)) as $t,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: (-((-pre_shift) >> F::U8)) as $t, phantom: PhantomData }
|
||||
}
|
||||
} else {
|
||||
Fx {
|
||||
num: (pre_shift >> F::U8) as $t,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: (pre_shift >> F::U8) as $t, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,10 +156,7 @@ macro_rules! fixed_point_signed_division {
|
|||
fn div(self, rhs: Fx<$t, F>) -> Self::Output {
|
||||
let mul_output: i32 = (self.num as i32).wrapping_mul(1 << F::U8);
|
||||
let divide_result: i32 = crate::bios::div(mul_output, rhs.num as i32);
|
||||
Fx {
|
||||
num: divide_result as $t,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: divide_result as $t, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -213,10 +174,7 @@ macro_rules! fixed_point_unsigned_division {
|
|||
fn div(self, rhs: Fx<$t, F>) -> Self::Output {
|
||||
let mul_output: i32 = (self.num as i32).wrapping_mul(1 << F::U8);
|
||||
let divide_result: i32 = crate::bios::div(mul_output, rhs.num as i32);
|
||||
Fx {
|
||||
num: divide_result as $t,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
Fx { num: divide_result as $t, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -60,7 +60,8 @@ pub const SOUND2CNT_L: VolAddress<DutyLenEnvelopeSetting> = unsafe { VolAddress:
|
|||
pub const SOUND2CNT_H: VolAddress<FrequencyControlSetting> = unsafe { VolAddress::new(0x400_006C) };
|
||||
|
||||
/// Sound Channel 3 Stop/Wave RAM select (`NR23`, `NR24`). Read/Write.
|
||||
pub const SOUND3CNT_L: VolAddress<StopWaveRAMSelectSetting> = unsafe { VolAddress::new(0x400_0070) };
|
||||
pub const SOUND3CNT_L: VolAddress<StopWaveRAMSelectSetting> =
|
||||
unsafe { VolAddress::new(0x400_0070) };
|
||||
|
||||
newtype! {
|
||||
StopWaveRAMSelectSetting, u16
|
||||
|
@ -158,7 +159,8 @@ pub const FIFO_B_L: VolAddress<u16> = unsafe { VolAddress::new(0x400_00A4) };
|
|||
pub const FIFO_B_H: VolAddress<u16> = unsafe { VolAddress::new(0x400_00A6) };
|
||||
|
||||
/// Channel L/R Volume/Enable (`NR50`, `NR51`). Read/Write.
|
||||
pub const SOUNDCNT_L: VolAddress<NonWaveVolumeEnableSetting> = unsafe { VolAddress::new(0x400_0080) };
|
||||
pub const SOUNDCNT_L: VolAddress<NonWaveVolumeEnableSetting> =
|
||||
unsafe { VolAddress::new(0x400_0080) };
|
||||
|
||||
newtype! {
|
||||
NonWaveVolumeEnableSetting, u16
|
||||
|
|
|
@ -33,7 +33,8 @@ pub const VRAM_BASE_USIZE: usize = 0x600_0000;
|
|||
pub const CHAR_BASE_BLOCKS: VolBlock<[u8; 0x4000], U6> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
|
||||
/// The screen entry base blocks.
|
||||
pub const SCREEN_BASE_BLOCKS: VolBlock<[u8; 0x800], U32> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
pub const SCREEN_BASE_BLOCKS: VolBlock<[u8; 0x800], U32> =
|
||||
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
|
||||
newtype! {
|
||||
/// An 8x8 tile with 4bpp, packed as `u32` values for proper alignment.
|
||||
|
|
|
@ -30,7 +30,8 @@ impl Mode3 {
|
|||
///
|
||||
/// Use `col + row * SCREEN_WIDTH` to get the address of an individual pixel,
|
||||
/// or use the helpers provided in this module.
|
||||
pub const VRAM: VolBlock<Color, <U256 as Mul<U160>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
pub const VRAM: VolBlock<Color, <U256 as Mul<U160>>::Output> =
|
||||
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
|
||||
/// private iterator over the pixels, two at a time
|
||||
const VRAM_BULK: VolBlock<u32, <<U256 as Mul<U160>>::Output as Div<U2>>::Output> =
|
||||
|
@ -70,11 +71,7 @@ impl Mode3 {
|
|||
let color32 = color.0 as u32;
|
||||
let bulk_color = color32 << 16 | color32;
|
||||
unsafe {
|
||||
DMA3::fill32(
|
||||
&bulk_color,
|
||||
VRAM_BASE_USIZE as *mut u32,
|
||||
(Self::SCREEN_PIXEL_COUNT / 2) as u16,
|
||||
)
|
||||
DMA3::fill32(&bulk_color, VRAM_BASE_USIZE as *mut u32, (Self::SCREEN_PIXEL_COUNT / 2) as u16)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -109,10 +106,12 @@ impl Mode4 {
|
|||
const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 4;
|
||||
|
||||
// TODO: newtype this?
|
||||
const PAGE0_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
const PAGE0_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> =
|
||||
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
|
||||
// TODO: newtype this?
|
||||
const PAGE1_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
|
||||
const PAGE1_BLOCK8: VolBlock<u8, <U256 as Mul<U160>>::Output> =
|
||||
unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
|
||||
|
||||
// TODO: newtype this?
|
||||
const PAGE0_BLOCK16: VolBlock<u16, <<U256 as Mul<U160>>::Output as Div<U2>>::Output> =
|
||||
|
@ -138,13 +137,9 @@ impl Mode4 {
|
|||
pub fn read_pixel(page1: bool, col: usize, row: usize) -> Option<u8> {
|
||||
// Note(Lokathor): byte _reads_ from VRAM are okay.
|
||||
if page1 {
|
||||
Self::PAGE1_BLOCK8
|
||||
.get(col + row * Self::SCREEN_WIDTH)
|
||||
.map(VolAddress::read)
|
||||
Self::PAGE1_BLOCK8.get(col + row * Self::SCREEN_WIDTH).map(VolAddress::read)
|
||||
} else {
|
||||
Self::PAGE0_BLOCK8
|
||||
.get(col + row * Self::SCREEN_WIDTH)
|
||||
.map(VolAddress::read)
|
||||
Self::PAGE0_BLOCK8.get(col + row * Self::SCREEN_WIDTH).map(VolAddress::read)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +181,9 @@ impl Mode4 {
|
|||
/// The page is imagined to be a series of `u16` values rather than `u8`
|
||||
/// values, allowing you to write two palette entries side by side as a single
|
||||
/// write operation.
|
||||
pub fn write_wide_pixel(page1: bool, wide_col: usize, row: usize, wide_pal8bpp: u16) -> Option<()> {
|
||||
pub fn write_wide_pixel(
|
||||
page1: bool, wide_col: usize, row: usize, wide_pal8bpp: u16,
|
||||
) -> Option<()> {
|
||||
if wide_col < Self::SCREEN_WIDTH / 2 && row < Self::SCREEN_HEIGHT {
|
||||
let wide_index = wide_col + row * Self::SCREEN_WIDTH / 2;
|
||||
let address: VolAddress<u16> = if page1 {
|
||||
|
@ -215,11 +212,8 @@ impl Mode4 {
|
|||
|
||||
let pal8bpp_32 = pal8bpp as u32;
|
||||
let bulk_color = (pal8bpp_32 << 24) | (pal8bpp_32 << 16) | (pal8bpp_32 << 8) | pal8bpp_32;
|
||||
let write_target = if page1 {
|
||||
VRAM_BASE_USIZE as *mut u32
|
||||
} else {
|
||||
(VRAM_BASE_USIZE + 0xA000) as *mut u32
|
||||
};
|
||||
let write_target =
|
||||
if page1 { VRAM_BASE_USIZE as *mut u32 } else { (VRAM_BASE_USIZE + 0xA000) as *mut u32 };
|
||||
unsafe { DMA3::fill32(&bulk_color, write_target, Self::SCREEN_U32_COUNT as u16) };
|
||||
}
|
||||
}
|
||||
|
@ -252,10 +246,12 @@ impl Mode5 {
|
|||
const SCREEN_U32_COUNT: usize = Self::SCREEN_PIXEL_COUNT / 2;
|
||||
|
||||
// TODO: newtype this?
|
||||
const PAGE0_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
const PAGE0_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> =
|
||||
unsafe { VolBlock::new(VRAM_BASE_USIZE) };
|
||||
|
||||
// TODO: newtype this?
|
||||
const PAGE1_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> = unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
|
||||
const PAGE1_BLOCK: VolBlock<Color, <U160 as Mul<U128>>::Output> =
|
||||
unsafe { VolBlock::new(VRAM_BASE_USIZE + 0xA000) };
|
||||
|
||||
/// private iterator over the page0 pixels, four at a time
|
||||
const PAGE0_BULK32: VolBlock<u32, <<U160 as Mul<U128>>::Output as Div<U2>>::Output> =
|
||||
|
@ -272,13 +268,9 @@ impl Mode5 {
|
|||
/// Gives `None` if out of bounds.
|
||||
pub fn read_pixel(page1: bool, col: usize, row: usize) -> Option<Color> {
|
||||
if page1 {
|
||||
Self::PAGE1_BLOCK
|
||||
.get(col + row * Self::SCREEN_WIDTH)
|
||||
.map(VolAddress::read)
|
||||
Self::PAGE1_BLOCK.get(col + row * Self::SCREEN_WIDTH).map(VolAddress::read)
|
||||
} else {
|
||||
Self::PAGE0_BLOCK
|
||||
.get(col + row * Self::SCREEN_WIDTH)
|
||||
.map(VolAddress::read)
|
||||
Self::PAGE0_BLOCK.get(col + row * Self::SCREEN_WIDTH).map(VolAddress::read)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,13 +281,9 @@ impl Mode5 {
|
|||
/// Gives `None` if out of bounds.
|
||||
pub fn write_pixel(page1: bool, col: usize, row: usize, color: Color) -> Option<()> {
|
||||
if page1 {
|
||||
Self::PAGE1_BLOCK
|
||||
.get(col + row * Self::SCREEN_WIDTH)
|
||||
.map(|va| va.write(color))
|
||||
Self::PAGE1_BLOCK.get(col + row * Self::SCREEN_WIDTH).map(|va| va.write(color))
|
||||
} else {
|
||||
Self::PAGE0_BLOCK
|
||||
.get(col + row * Self::SCREEN_WIDTH)
|
||||
.map(|va| va.write(color))
|
||||
Self::PAGE0_BLOCK.get(col + row * Self::SCREEN_WIDTH).map(|va| va.write(color))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,11 +302,8 @@ impl Mode5 {
|
|||
|
||||
let color32 = color.0 as u32;
|
||||
let bulk_color = color32 << 16 | color32;
|
||||
let write_target = if page1 {
|
||||
VRAM_BASE_USIZE as *mut u32
|
||||
} else {
|
||||
(VRAM_BASE_USIZE + 0xA000) as *mut u32
|
||||
};
|
||||
let write_target =
|
||||
if page1 { VRAM_BASE_USIZE as *mut u32 } else { (VRAM_BASE_USIZE + 0xA000) as *mut u32 };
|
||||
unsafe { DMA3::fill32(&bulk_color, write_target, Self::SCREEN_U32_COUNT as u16) };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue