Struct PALRAM

Source
pub struct PALRAM;
Expand description

A ZST for namespacing palette ram related functionality.

The palette ram consists of 2 blocks of 256 Color values, one for backgrounds and one for objects.

When selecting a given address within either block of colors, both backgrounds and objects can use either “8-bit per pixel” mode (8bpp) or “4-bit per pixel” mode (4bpp).

  • 8bpp: Each color index within a background or object is 8 bits. The 8 bits index into the full block of colors as if it was a single set of 256 elements. Index 0 is counted as the “transparency” index.
    • base_addr + size_of::<Color>() * index
  • 4bpp: Each color index within a background or object is 4 bits. The 4 bits within the image data is an entry into a “palette bank” of 16 entries. The palette bank used for the BG or OBJ overall is determined by their control bits. Index 0 within a palbank is still considered the “transparency” index.
    • base_addr + size_of::<Color>() * (pal_bank << 4 | entry)

Index 0 of the BG palette is a special “backdrop” index. This is the color drawn to a screen pixel when no BG or OBJ is drawing to that location.

Please note that there’s only one PALRAM, the 8bpp and 4bpp modes are just two ways to index into the same region of memory. A change to one will affect the other.

Implementations§

Source§

impl PALRAM

Source

pub const fn bg_8bpp(self, index: u8) -> SimpleVolAddr<Color>

Gets the address of an 8bpp BG color.

Index 0 is used as transparent in an 8bpp BG. Instead of changing the color displayed in the BG itself, changing index 0 will change the “backdrop” color, which is the default color shown when no BG or OBJ draws to a given screen pixel.

Source

pub const fn obj_8bpp(self, index: u8) -> SimpleVolAddr<Color>

Get the address of an 8bpp OBJ color.

Index 0 in an 8bpp OBJ is transparent, and setting it will have no effect.

Source

pub const fn backdrop(self) -> SimpleVolAddr<Color>

Gets the backdrop color address.

This is identical to PALRAM.bg_8bpp(0), See bg_8bpp

Source

pub fn bg_4bpp(self, pal_bank: usize, entry: usize) -> SimpleVolAddr<Color>

Get the address of a 4bpp BG color.

§Panics

If either pal_bank or entry are 16 or more.

Source

pub fn obj_4bpp(self, pal_bank: usize, entry: usize) -> SimpleVolAddr<Color>

Get the address of a 4bpp OBJ color.

§Panics

If either pal_bank or entry are 16 or more.

Source

pub const fn bg_4bpp_wrapping( self, pal_bank: usize, entry: usize, ) -> SimpleVolAddr<Color>

Get the address of a 4bpp BG color.

Only uses the lowest 4 bits of each value given, effectively wrapping both values into the range 0..=15.

Source

pub const fn obj_4bpp_wrapping( self, pal_bank: usize, entry: usize, ) -> SimpleVolAddr<Color>

Get the address of a 4bpp OBJ color.

Only uses the lowest 4 bits of each value given, effectively wrapping both values into the range 0..=15.

Trait Implementations§

Source§

impl Clone for PALRAM

Source§

fn clone(&self) -> PALRAM

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PALRAM

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for PALRAM

Auto Trait Implementations§

§

impl Freeze for PALRAM

§

impl RefUnwindSafe for PALRAM

§

impl Send for PALRAM

§

impl Sync for PALRAM

§

impl Unpin for PALRAM

§

impl UnwindSafe for PALRAM

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.