Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl Display {
- pub fn clear(&mut self) {
- self.vram = [0x00; SCREEN_HEIGHT * SCREEN_WIDTH * 4];
- }
- // fixme: support alpha channel
- pub unsafe fn set_pixel_greyscale(&mut self, pos: usize, val: u8) {
- // set to unsafe as it does not do any bounds checking
- self.vram
- .iter_mut()
- .skip(pos * 4)
- .take(3)
- .for_each(|pixel| *pixel = val);
- self.vram
- .iter_mut()
- .skip(pos * 4 + 3)
- .take(1)
- .for_each(|pixel| *pixel = 0xFF);
- }
- pub fn set_pixel(&mut self, x: usize, y: usize) -> Result<(), Error> {
- match (x, y) {
- (_, _) if x < 64 && y < 64 => unsafe {
- self.set_pixel_greyscale(x + (SCREEN_WIDTH * y), 0xFF)
- },
- (_, _) if x >= 64 => {
- return Err(Error::InvalidValue(
- "Value x is too large (was > 63)".to_string(),
- ))
- }
- (_, _) if y > 62 => {
- return Err(Error::InvalidValue(
- "Value y is too large (was > 31)".to_string(),
- ))
- }
- (_, _) => (),
- }
- Ok(())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement