Skip to content
Snippets Groups Projects
Verified Commit 9ec5b38d authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: support for tile set storage

parent 096a4019
No related branches found
No related tags found
No related merge requests found
...@@ -113,6 +113,9 @@ impl Mmu { ...@@ -113,6 +113,9 @@ impl Mmu {
0x8000 | 0x9000 => { 0x8000 | 0x9000 => {
println!("WRITING TO VRAM"); println!("WRITING TO VRAM");
self.ppu.vram[(addr & 0x1fff) as usize] = value; self.ppu.vram[(addr & 0x1fff) as usize] = value;
if addr < 0x9800 {
self.ppu.update_tile(addr, value);
}
} }
// External RAM (8k) // External RAM (8k)
0xa000 | 0xb000 => { 0xa000 | 0xb000 => {
......
...@@ -2,7 +2,15 @@ pub const VRAM_SIZE: usize = 8192; ...@@ -2,7 +2,15 @@ pub const VRAM_SIZE: usize = 8192;
pub const HRAM_SIZE: usize = 128; pub const HRAM_SIZE: usize = 128;
pub const PALETTE_SIZE: usize = 4; pub const PALETTE_SIZE: usize = 4;
pub const RGBA_SIZE: usize = 4; pub const RGBA_SIZE: usize = 4;
/// The number of tiles that can be store in Game Boy's
/// VRAM memory according to specifications.
pub const TILE_COUNT: usize = 384;
/// The width of the Game Boy screen in pixels.
pub const SCREEN_WIDTH: usize = 160; pub const SCREEN_WIDTH: usize = 160;
/// The height of the Game Boy screen in pixels.
pub const SCREEN_HEIGHT: usize = 154; pub const SCREEN_HEIGHT: usize = 154;
/// Represents the Game Boy PPU (Pixel Processing Unit) and controls /// Represents the Game Boy PPU (Pixel Processing Unit) and controls
...@@ -24,6 +32,10 @@ pub struct Ppu { ...@@ -24,6 +32,10 @@ pub struct Ppu {
/// the sprites are going to be stored. /// the sprites are going to be stored.
pub vram: [u8; VRAM_SIZE], pub vram: [u8; VRAM_SIZE],
pub hram: [u8; HRAM_SIZE], pub hram: [u8; HRAM_SIZE],
/// The current set of processed tiles that are store in the
/// PPU related structures.
tiles: [[[u8; 8]; 8]; TILE_COUNT],
/// The palette of colors that is currently loaded in Game Boy.
palette: [[u8; RGBA_SIZE]; PALETTE_SIZE], palette: [[u8; RGBA_SIZE]; PALETTE_SIZE],
/// The scroll Y register that controls the Y offset /// The scroll Y register that controls the Y offset
/// of the background. /// of the background.
...@@ -60,6 +72,7 @@ impl Ppu { ...@@ -60,6 +72,7 @@ impl Ppu {
frame_buffer: [0u8; SCREEN_WIDTH * SCREEN_HEIGHT], frame_buffer: [0u8; SCREEN_WIDTH * SCREEN_HEIGHT],
vram: [0u8; VRAM_SIZE], vram: [0u8; VRAM_SIZE],
hram: [0u8; HRAM_SIZE], hram: [0u8; HRAM_SIZE],
tiles: [[[0u8; 8]; 8]; TILE_COUNT],
palette: [[0u8; RGBA_SIZE]; PALETTE_SIZE], palette: [[0u8; RGBA_SIZE]; PALETTE_SIZE],
scy: 0x0, scy: 0x0,
scx: 0x0, scx: 0x0,
...@@ -165,6 +178,28 @@ impl Ppu { ...@@ -165,6 +178,28 @@ impl Ppu {
} }
} }
pub fn update_tile(&mut self, addr: u16, _value: u8) {
let addr = addr & 0x1ffe;
let tile_index = (addr >> 4) & 0x01ff;
let y = (addr >> 1) & 0x0007;
let mut mask;
for x in 0..8 {
mask = 1 << (7 - x);
self.tiles[tile_index as usize][y as usize][x as usize] =
if self.vram[addr as usize] & mask > 0 {
0x1
} else {
0x0
} | if self.vram[(addr + 1) as usize] & mask > 0 {
0x2
} else {
0x0
}
}
}
fn render_line(&self) { fn render_line(&self) {
//@todo implement the rendering of a line //@todo implement the rendering of a line
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment