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

fix: initial support for tetris tile screen

parent ef26d544
No related branches found
No related tags found
No related merge requests found
Pipeline #905 failed
...@@ -49,7 +49,7 @@ const KEYS: Record<string, number> = { ...@@ -49,7 +49,7 @@ const KEYS: Record<string, number> = {
}; };
// @ts-ignore: ts(2580) // @ts-ignore: ts(2580)
const ROM_PATH = require("../../res/roms/firstwhite.gb"); const ROM_PATH = require("../../res/roms.prop/tetris.gb");
// Enumeration that describes the multiple pixel // Enumeration that describes the multiple pixel
// formats and the associated byte size. // formats and the associated byte size.
......
...@@ -113,8 +113,8 @@ impl Cpu { ...@@ -113,8 +113,8 @@ impl Cpu {
if self.ime { if self.ime {
// @todo aggregate all of this interrupts in the MMU // @todo aggregate all of this interrupts in the MMU
if self.mmu.ppu().int_vblank() { if (self.mmu.ie & 0x01 == 0x01) && self.mmu.ppu().int_vblank() {
println!("VAI FAZER HANDLING VBLANK"); println!("Going to run V-Blank interrupt handler");
let pc = self.pc; let pc = self.pc;
self.disable_int(); self.disable_int();
self.push_word(pc); self.push_word(pc);
......
...@@ -13,6 +13,10 @@ pub struct Mmu { ...@@ -13,6 +13,10 @@ pub struct Mmu {
rom: [u8; ROM_SIZE], rom: [u8; ROM_SIZE],
ram: [u8; RAM_SIZE], ram: [u8; RAM_SIZE],
eram: [u8; RAM_SIZE], eram: [u8; RAM_SIZE],
/// Registers that controls the interrupts that are considered
/// to be enabled and should be triggered.
pub ie: u8,
} }
impl Mmu { impl Mmu {
...@@ -25,6 +29,7 @@ impl Mmu { ...@@ -25,6 +29,7 @@ impl Mmu {
rom: [0u8; ROM_SIZE], rom: [0u8; ROM_SIZE],
ram: [0u8; RAM_SIZE], ram: [0u8; RAM_SIZE],
eram: [0u8; ERAM_SIZE], eram: [0u8; ERAM_SIZE],
ie: 0x0,
} }
} }
...@@ -77,12 +82,11 @@ impl Mmu { ...@@ -77,12 +82,11 @@ impl Mmu {
0xf000 => match addr & 0x0f00 { 0xf000 => match addr & 0x0f00 {
0x000 | 0x100 | 0x200 | 0x300 | 0x400 | 0x500 | 0x600 | 0x700 | 0x800 | 0x900 0x000 | 0x100 | 0x200 | 0x300 | 0x400 | 0x500 | 0x600 | 0x700 | 0x800 | 0x900
| 0xa00 | 0xb00 | 0xc00 | 0xd00 => self.ram[(addr & 0x1fff) as usize], | 0xa00 | 0xb00 | 0xc00 | 0xd00 => self.ram[(addr & 0x1fff) as usize],
0xe00 => { 0xe00 => self.ppu.oam[(addr & 0x009f) as usize],
println!("Reading from PPU OAM - NOT IMPLEMENTED");
0x00
}
0xf00 => { 0xf00 => {
if addr >= 0xff80 { if addr == 0xffff {
self.ie
} else if addr >= 0xff80 {
self.ppu.hram[(addr & 0x007f) as usize] self.ppu.hram[(addr & 0x007f) as usize]
} else { } else {
match addr & 0x00f0 { match addr & 0x00f0 {
...@@ -147,11 +151,11 @@ impl Mmu { ...@@ -147,11 +151,11 @@ impl Mmu {
| 0xa00 | 0xb00 | 0xc00 | 0xd00 => { | 0xa00 | 0xb00 | 0xc00 | 0xd00 => {
self.ram[(addr & 0x1fff) as usize] = value; self.ram[(addr & 0x1fff) as usize] = value;
} }
0xe00 => { 0xe00 => self.ppu.oam[(addr & 0x009f) as usize] = value,
println!("Writing to PPU OAM at 0x{:04x}", addr);
}
0xf00 => { 0xf00 => {
if addr >= 0xff80 { if addr == 0xffff {
self.ie = value;
} else if addr >= 0xff80 {
self.ppu.hram[(addr & 0x007f) as usize] = value; self.ppu.hram[(addr & 0x007f) as usize] = value;
} else { } else {
match addr & 0x00f0 { match addr & 0x00f0 {
......
...@@ -37,26 +37,26 @@ impl Pad { ...@@ -37,26 +37,26 @@ impl Pad {
let mut value; let mut value;
match self.selection { match self.selection {
PadSelection::Action => { PadSelection::Action => {
value = if self.a { 0x01 } else { 0x00 } value = if self.a { 0x00 } else { 0x01 }
| if self.b { 0x02 } else { 0x00 } | if self.b { 0x00 } else { 0x02 }
| if self.select { 0x04 } else { 0x00 } | if self.select { 0x00 } else { 0x04 }
| if self.start { 0x08 } else { 0x00 } | if self.start { 0x00 } else { 0x08 }
} }
PadSelection::Direction => { PadSelection::Direction => {
value = if self.right { 0x01 } else { 0x00 } value = if self.right { 0x00 } else { 0x01 }
| if self.left { 0x02 } else { 0x00 } | if self.left { 0x00 } else { 0x02 }
| if self.up { 0x04 } else { 0x00 } | if self.up { 0x00 } else { 0x04 }
| if self.down { 0x08 } else { 0x00 } | if self.down { 0x00 } else { 0x08 }
} }
} }
value |= if self.selection == PadSelection::Direction { value |= if self.selection == PadSelection::Direction {
0x00
} else {
0x10 0x10
} | if self.selection == PadSelection::Action {
0x00
} else { } else {
0x00
} | if self.selection == PadSelection::Action {
0x20 0x20
} else {
0x00
}; };
value value
} }
......
...@@ -9,6 +9,7 @@ use wasm_bindgen::prelude::*; ...@@ -9,6 +9,7 @@ use wasm_bindgen::prelude::*;
pub const VRAM_SIZE: usize = 8192; pub const VRAM_SIZE: usize = 8192;
pub const HRAM_SIZE: usize = 128; pub const HRAM_SIZE: usize = 128;
pub const OAM_SIZE: usize = 260;
pub const PALETTE_SIZE: usize = 4; pub const PALETTE_SIZE: usize = 4;
pub const RGB_SIZE: usize = 3; pub const RGB_SIZE: usize = 3;
...@@ -99,6 +100,9 @@ pub struct Ppu { ...@@ -99,6 +100,9 @@ pub struct Ppu {
/// High RAM memory that should provide extra speed for regular /// High RAM memory that should provide extra speed for regular
/// operations. /// operations.
pub hram: [u8; HRAM_SIZE], pub hram: [u8; HRAM_SIZE],
/// OAM RAM (Sprite Attribute Table ) used for the storage of the
/// sprite attributes for each of the 40 sprites of the Game Boy.
pub oam: [u8; OAM_SIZE],
/// The current set of processed tiles that are store in the /// The current set of processed tiles that are store in the
/// PPU related structures. /// PPU related structures.
tiles: [Tile; TILE_COUNT], tiles: [Tile; TILE_COUNT],
...@@ -172,6 +176,7 @@ impl Ppu { ...@@ -172,6 +176,7 @@ impl Ppu {
frame_buffer: Box::new([0u8; DISPLAY_WIDTH * DISPLAY_HEIGHT * RGB_SIZE]), frame_buffer: Box::new([0u8; DISPLAY_WIDTH * DISPLAY_HEIGHT * RGB_SIZE]),
vram: [0u8; VRAM_SIZE], vram: [0u8; VRAM_SIZE],
hram: [0u8; HRAM_SIZE], hram: [0u8; HRAM_SIZE],
oam: [0u8; OAM_SIZE],
tiles: [Tile { buffer: [0u8; 64] }; TILE_COUNT], tiles: [Tile { buffer: [0u8; 64] }; TILE_COUNT],
palette: [[0u8; RGB_SIZE]; PALETTE_SIZE], palette: [[0u8; RGB_SIZE]; PALETTE_SIZE],
palette_obj_0: [[0u8; RGB_SIZE]; PALETTE_SIZE], palette_obj_0: [[0u8; RGB_SIZE]; PALETTE_SIZE],
......
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