diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index a6133ff775e3da1bb1e2dbb4f8e530c4171a409f..965230e0d64150d2b87907dd290b1cbab3501b61 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -87,7 +87,7 @@ fn main() { //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/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/02-interrupts.gb"); // NO FINISH diff --git a/examples/web/index.html b/examples/web/index.html index 521cf0df8970077317fb0151a51f42de4fc56718..17dc820243ee7c67e3fce5a7ebfdbad9676ab8df 100644 --- a/examples/web/index.html +++ b/examples/web/index.html @@ -119,7 +119,7 @@ </span> <span id="button-upload" class="tiny-button border padded file"> <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> </div> </div> diff --git a/examples/web/index.ts b/examples/web/index.ts index c2b983a88ba011715b67405f5f8841d93932e7be..5f20f7c039382d72f9115ee48b66821a10a25c1b 100644 --- a/examples/web/index.ts +++ b/examples/web/index.ts @@ -544,9 +544,7 @@ const registerButtons = () => { const pixels = state.gameBoy.get_tile_buffer(index); const line = Math.floor(index / 16); const column = index % 16; - console.info(`${canvasTiles.width}`); let offset = ((line * canvasTiles.width * 8) + (column * 8)) * PixelFormat.RGBA; - console.info(`${offset}`); let counter = 0; for (let index = 0; index < pixels.length; index += format) { const color = @@ -570,6 +568,16 @@ const registerButtons = () => { for (let index = 0; index < 256; 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); + } } }); diff --git a/examples/web/tsconfig.json b/examples/web/tsconfig.json index 0bc8cec0b5a82f53019127e9adb2821060aaa7dd..54b8f23f78f97da010f950ac602328134bcce54a 100644 --- a/examples/web/tsconfig.json +++ b/examples/web/tsconfig.json @@ -9,7 +9,7 @@ "sourceMap": true, "outDir": ".", "baseUrl": ".", - "lib": ["es2015", "dom"], + "lib": ["es2017", "dom"], "paths": { "*": ["node_modules/*", "src/types/*"] } diff --git a/src/gb.rs b/src/gb.rs index 4ef33166161da136d1fe657f1d25d227fb14c793..b8fb338da93ddc2f0161604ff23335a3d174148e 100644 --- a/src/gb.rs +++ b/src/gb.rs @@ -111,6 +111,14 @@ impl GameBoy { 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> { self.frame_buffer().to_vec() } diff --git a/src/pad.rs b/src/pad.rs index 62ad7ad3eedf1dbd9084d231dcc860a57583846b..1b7e54124cd0e37f5eff00ff7ec56335473343b6 100644 --- a/src/pad.rs +++ b/src/pad.rs @@ -73,7 +73,7 @@ impl Pad { PadSelection::Action } } - addr => panic!("Reading from unknown Pad location 0x{:04x}", addr), + addr => panic!("Writing to unknown Pad location 0x{:04x}", addr), } } } diff --git a/src/ppu.rs b/src/ppu.rs index 8159ad45a56187d2e79aa0d20eab1e5c4400e146..d0e97be233c5dbb3649b94805a76de921a390108 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -1,5 +1,8 @@ use core::fmt; -use std::fmt::{Display, Formatter}; +use std::{ + borrow::BorrowMut, + fmt::{Display, Formatter}, +}; #[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; @@ -381,8 +384,16 @@ impl Ppu { } } - pub fn tiles(&self) -> [Tile; TILE_COUNT] { - self.tiles + pub fn vram(&self) -> &[u8; VRAM_SIZE] { + &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 { @@ -428,13 +439,14 @@ impl Ppu { pub fn update_tile(&mut self, addr: u16, _value: u8) { let addr = (addr & 0x1ffe) 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 mut mask; for x in 0..8 { mask = 1 << (7 - x); - self.tiles[tile_index].set( + tile.set( x, y, if self.vram[addr] & mask > 0 { 0x1 } else { 0x0 }