Update before heading home
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Failing after 26s
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Failing after 26s
This commit is contained in:
113
src/ppu.rs
113
src/ppu.rs
@@ -98,13 +98,76 @@ pub struct Mask {
|
||||
em_blue: bool,
|
||||
}
|
||||
|
||||
const COLORS: &'static [Color; 0b11_1111] = &[
|
||||
Color { r: 0, g: 0, b: 0}; 0b11_1111
|
||||
const COLORS: &'static [Color; 0b100_0000] = &[
|
||||
Color { r: 0x66, g: 0x66, b: 0x66 }, // 00
|
||||
Color { r: 0x00, g: 0x2A, b: 0x88 }, // 01
|
||||
Color { r: 0x14, g: 0x12, b: 0xA7 }, // 02
|
||||
Color { r: 0x3B, g: 0x00, b: 0xA4 }, // 03
|
||||
Color { r: 0x5C, g: 0x00, b: 0x7E }, // 04
|
||||
Color { r: 0x6E, g: 0x00, b: 0x40 }, // 05
|
||||
Color { r: 0x6C, g: 0x06, b: 0x00 }, // 06
|
||||
Color { r: 0x56, g: 0x1D, b: 0x00 }, // 07
|
||||
Color { r: 0x33, g: 0x35, b: 0x00 }, // 08
|
||||
Color { r: 0x0B, g: 0x48, b: 0x00 }, // 09
|
||||
Color { r: 0x00, g: 0x52, b: 0x00 }, // 0A
|
||||
Color { r: 0x00, g: 0x4F, b: 0x08 }, // 0B
|
||||
Color { r: 0x00, g: 0x40, b: 0x4D }, // 0C
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 0D
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 0E
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 0F
|
||||
Color { r: 0xAD, g: 0xAD, b: 0xAD }, // 10
|
||||
Color { r: 0x15, g: 0x5F, b: 0xD9 }, // 11
|
||||
Color { r: 0x42, g: 0x40, b: 0xFF }, // 12
|
||||
Color { r: 0x75, g: 0x27, b: 0xFE }, // 13
|
||||
Color { r: 0xA0, g: 0x1A, b: 0xCC }, // 14
|
||||
Color { r: 0xB7, g: 0x1E, b: 0x7B }, // 15
|
||||
Color { r: 0xB5, g: 0x31, b: 0x20 }, // 16
|
||||
Color { r: 0x99, g: 0x4E, b: 0x00 }, // 17
|
||||
Color { r: 0x6B, g: 0x6D, b: 0x00 }, // 18
|
||||
Color { r: 0x38, g: 0x87, b: 0x00 }, // 19
|
||||
Color { r: 0x0C, g: 0x93, b: 0x00 }, // 1A
|
||||
Color { r: 0x00, g: 0x8F, b: 0x32 }, // 1B
|
||||
Color { r: 0x00, g: 0x7C, b: 0x8D }, // 1C
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 1D
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 1E
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 1F
|
||||
Color { r: 0xFF, g: 0xFE, b: 0xFF }, // 20
|
||||
Color { r: 0x64, g: 0xB0, b: 0xFF }, // 21
|
||||
Color { r: 0x92, g: 0x90, b: 0xFF }, // 22
|
||||
Color { r: 0xC6, g: 0x76, b: 0xFF }, // 23
|
||||
Color { r: 0xF3, g: 0x6A, b: 0xFF }, // 24
|
||||
Color { r: 0xFE, g: 0x6E, b: 0xCC }, // 25
|
||||
Color { r: 0xFE, g: 0x81, b: 0x70 }, // 26
|
||||
Color { r: 0xEA, g: 0x9E, b: 0x22 }, // 27
|
||||
Color { r: 0xBC, g: 0xBE, b: 0x00 }, // 28
|
||||
Color { r: 0x88, g: 0xD8, b: 0x00 }, // 29
|
||||
Color { r: 0x5C, g: 0xE4, b: 0x30 }, // 2A
|
||||
Color { r: 0x45, g: 0xE0, b: 0x82 }, // 2B
|
||||
Color { r: 0x48, g: 0xCD, b: 0xDE }, // 2C
|
||||
Color { r: 0x4F, g: 0x4F, b: 0x4F }, // 2D
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 2E
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 2F
|
||||
Color { r: 0xFF, g: 0xFE, b: 0xFF }, // 30
|
||||
Color { r: 0xC0, g: 0xDF, b: 0xFF }, // 31
|
||||
Color { r: 0xD3, g: 0xD2, b: 0xFF }, // 32
|
||||
Color { r: 0xE8, g: 0xC8, b: 0xFF }, // 33
|
||||
Color { r: 0xFB, g: 0xC2, b: 0xFF }, // 34
|
||||
Color { r: 0xFE, g: 0xC4, b: 0xEA }, // 35
|
||||
Color { r: 0xFE, g: 0xCC, b: 0xC5 }, // 36
|
||||
Color { r: 0xF7, g: 0xD8, b: 0xA5 }, // 37
|
||||
Color { r: 0xE4, g: 0xE5, b: 0x94 }, // 38
|
||||
Color { r: 0xCF, g: 0xEF, b: 0x96 }, // 39
|
||||
Color { r: 0xBD, g: 0xF4, b: 0xAB }, // 3A
|
||||
Color { r: 0xB3, g: 0xF3, b: 0xCC }, // 3B
|
||||
Color { r: 0xB5, g: 0xEB, b: 0xF2 }, // 3C
|
||||
Color { r: 0xB8, g: 0xB8, b: 0xB8 }, // 3D
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 3E
|
||||
Color { r: 0x00, g: 0x00, b: 0x00 }, // 3F
|
||||
];
|
||||
|
||||
pub struct Palette {
|
||||
colors: &'static [Color; 0b11_1111],
|
||||
ram: [u8; 0x20]
|
||||
colors: &'static [Color; 0x40],
|
||||
ram: [u8; 0x20],
|
||||
}
|
||||
|
||||
pub struct PPU {
|
||||
@@ -162,7 +225,19 @@ impl PPU {
|
||||
em_green: false,
|
||||
em_blue: false,
|
||||
},
|
||||
palette: Palette { colors: COLORS, ram: [0; _] },
|
||||
palette: Palette {
|
||||
colors: COLORS,
|
||||
ram: [
|
||||
0x20, 0x21, 0x22, 0x23,
|
||||
0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2A, 0x2B,
|
||||
0x2C, 0x2D, 0x2E, 0x2F,
|
||||
0x30, 0x31, 0x32, 0x33,
|
||||
0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3A, 0x3B,
|
||||
0x3C, 0x3D, 0x3E, 0x3F,
|
||||
],
|
||||
},
|
||||
vblank: false,
|
||||
frame_count: 0,
|
||||
nmi_enabled: false,
|
||||
@@ -220,9 +295,12 @@ impl PPU {
|
||||
5 => panic!("ppuscroll is write-only"),
|
||||
6 => panic!("ppuaddr is write-only"),
|
||||
7 => {
|
||||
let val = self.memory.read(self.background.v).reg_map(|a, _| match a {
|
||||
PPUMMRegisters::Palette => todo!(),
|
||||
});
|
||||
let val = self
|
||||
.memory
|
||||
.read(self.background.v)
|
||||
.reg_map(|a, off| match a {
|
||||
PPUMMRegisters::Palette => self.palette.ram[off as usize],
|
||||
});
|
||||
// if self.background
|
||||
self.background.v = self
|
||||
.background
|
||||
@@ -513,16 +591,17 @@ impl PPU {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_palette<R: Renderer>(&self, frame: &mut Frame<R>) {
|
||||
frame.fill_rectangle(
|
||||
Point::new(0., 0.),
|
||||
Size::new(10., 10.),
|
||||
Color {
|
||||
r: todo!(),
|
||||
g: todo!(),
|
||||
b: todo!(),
|
||||
},
|
||||
);
|
||||
for y in 0..8 {
|
||||
for x in 0..4 {
|
||||
frame.fill_rectangle(
|
||||
Point::new(x as f32 * 10., y as f32 * 10.),
|
||||
Size::new(10., 10.),
|
||||
self.palette.colors[(self.palette.ram[x + y * 4] & 0x3F) as usize]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user