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

fix: more fixes and better VRAM debug

parent 0be484ac
No related branches found
No related tags found
No related merge requests found
Pipeline #904 passed
...@@ -87,7 +87,7 @@ fn main() { ...@@ -87,7 +87,7 @@ fn main() {
//game_boy.load_rom_file("../../res/roms.prop/alleyway.gb"); //game_boy.load_rom_file("../../res/roms.prop/alleyway.gb");
//game_boy.load_rom_file("../../res/roms/firstwhite.gb"); //game_boy.load_rom_file("../../res/roms/firstwhite.gb");
game_boy.load_rom_file("../../res/roms/opus5.gb"); //game_boy.load_rom_file("../../res/roms/opus5.gb");
//game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED
//game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); // NO FINISH //game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); // NO FINISH
......
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
</span> </span>
<span id="button-upload" class="tiny-button border padded file"> <span id="button-upload" class="tiny-button border padded file">
<img src="res/upload.svg" alt="upload" /><span>Load ROM</span> <img src="res/upload.svg" alt="upload" /><span>Load ROM</span>
<input type="file" id="button-upload-file" name="button-upload-file" accept=".ch8"> <input type="file" id="button-upload-file" name="button-upload-file" accept=".gb">
</span> </span>
</div> </div>
</div> </div>
......
...@@ -544,9 +544,7 @@ const registerButtons = () => { ...@@ -544,9 +544,7 @@ const registerButtons = () => {
const pixels = state.gameBoy.get_tile_buffer(index); const pixels = state.gameBoy.get_tile_buffer(index);
const line = Math.floor(index / 16); const line = Math.floor(index / 16);
const column = index % 16; const column = index % 16;
console.info(`${canvasTiles.width}`);
let offset = ((line * canvasTiles.width * 8) + (column * 8)) * PixelFormat.RGBA; let offset = ((line * canvasTiles.width * 8) + (column * 8)) * PixelFormat.RGBA;
console.info(`${offset}`);
let counter = 0; let counter = 0;
for (let index = 0; index < pixels.length; index += format) { for (let index = 0; index < pixels.length; index += format) {
const color = const color =
...@@ -570,6 +568,16 @@ const registerButtons = () => { ...@@ -570,6 +568,16 @@ const registerButtons = () => {
for (let index = 0; index < 256; index++) { for (let index = 0; index < 256; index++) {
drawSprite(index); drawSprite(index);
} }
const vram = state.gameBoy.vram_eager();
const step = 16;
for (let index = 0; index < vram.length; index += step) {
let line = `${(index + 0x8000).toString(16).padStart(4, "0")}`;
for (let j = 0; j < step; j++) {
line += ` ${vram[index + j].toString(16).padStart(2, "0")}`;
}
console.info(line);
}
} }
}); });
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"sourceMap": true, "sourceMap": true,
"outDir": ".", "outDir": ".",
"baseUrl": ".", "baseUrl": ".",
"lib": ["es2015", "dom"], "lib": ["es2017", "dom"],
"paths": { "paths": {
"*": ["node_modules/*", "src/types/*"] "*": ["node_modules/*", "src/types/*"]
} }
......
...@@ -111,6 +111,14 @@ impl GameBoy { ...@@ -111,6 +111,14 @@ impl GameBoy {
self.load_boot_dmg_bootix(); self.load_boot_dmg_bootix();
} }
pub fn vram_eager(&mut self) -> Vec<u8> {
self.ppu().vram().to_vec()
}
pub fn hram_eager(&mut self) -> Vec<u8> {
self.ppu().vram().to_vec()
}
pub fn frame_buffer_eager(&mut self) -> Vec<u8> { pub fn frame_buffer_eager(&mut self) -> Vec<u8> {
self.frame_buffer().to_vec() self.frame_buffer().to_vec()
} }
......
...@@ -73,7 +73,7 @@ impl Pad { ...@@ -73,7 +73,7 @@ impl Pad {
PadSelection::Action PadSelection::Action
} }
} }
addr => panic!("Reading from unknown Pad location 0x{:04x}", addr), addr => panic!("Writing to unknown Pad location 0x{:04x}", addr),
} }
} }
} }
use core::fmt; use core::fmt;
use std::fmt::{Display, Formatter}; use std::{
borrow::BorrowMut,
fmt::{Display, Formatter},
};
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
...@@ -381,8 +384,16 @@ impl Ppu { ...@@ -381,8 +384,16 @@ impl Ppu {
} }
} }
pub fn tiles(&self) -> [Tile; TILE_COUNT] { pub fn vram(&self) -> &[u8; VRAM_SIZE] {
self.tiles &self.vram
}
pub fn hram(&self) -> &[u8; HRAM_SIZE] {
&self.hram
}
pub fn tiles(&self) -> &[Tile; TILE_COUNT] {
&self.tiles
} }
pub fn palette(&self) -> Palette { pub fn palette(&self) -> Palette {
...@@ -428,13 +439,14 @@ impl Ppu { ...@@ -428,13 +439,14 @@ impl Ppu {
pub fn update_tile(&mut self, addr: u16, _value: u8) { pub fn update_tile(&mut self, addr: u16, _value: u8) {
let addr = (addr & 0x1ffe) as usize; let addr = (addr & 0x1ffe) as usize;
let tile_index = ((addr >> 4) & 0x01ff) as usize; let tile_index = ((addr >> 4) & 0x01ff) as usize;
let tile = self.tiles[tile_index].borrow_mut();
let y = ((addr >> 1) & 0x0007) as usize; let y = ((addr >> 1) & 0x0007) as usize;
let mut mask; let mut mask;
for x in 0..8 { for x in 0..8 {
mask = 1 << (7 - x); mask = 1 << (7 - x);
self.tiles[tile_index].set( tile.set(
x, x,
y, y,
if self.vram[addr] & mask > 0 { 0x1 } else { 0x0 } if self.vram[addr] & mask > 0 { 0x1 } else { 0x0 }
......
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