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

feat: initial web support

parent 457bc7b1
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,25 @@
A Game Boy emulator that is written in Rust 🦀.
## Build
### WASM for Node.js
```bash
cargo install wasm-pack
wasm-pack build --release --target=nodejs -- --features wasm
```
### WASM for Web
```bash
cargo install wasm-pack
wasm-pack build --release --target=web --out-dir=examples/web/lib -- --features wasm
cd examples/web
npm install && npm run build
cd dist && python3 -m http.server
```
## Inspiration
### Documentation
......
......@@ -5,11 +5,17 @@ use crate::{
util::read_file,
};
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct GameBoy {
cpu: Cpu,
}
#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl GameBoy {
#[cfg_attr(feature = "wasm", wasm_bindgen(constructor))]
pub fn new() -> GameBoy {
let ppu = Ppu::new();
let mmu = Mmu::new(ppu);
......@@ -31,6 +37,22 @@ impl GameBoy {
self.ppu().clock(cycles)
}
pub fn load_rom(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_rom(0x0000, &data);
}
pub fn load_boot(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_boot(0x0000, &data);
}
pub fn load_boot_default(&mut self) {
self.load_boot("./res/dmg_rom.bin");
}
}
impl GameBoy {
pub fn cpu(&mut self) -> &mut Cpu {
&mut self.cpu
}
......@@ -46,18 +68,4 @@ impl GameBoy {
pub fn frame_buffer(&mut self) -> &Box<[u8; FRAME_BUFFER_SIZE]> {
&(self.ppu().frame_buffer)
}
pub fn load_rom(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_rom(0x0000, &data);
}
pub fn load_boot(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_boot(0x0000, &data);
}
pub fn load_boot_default(&mut self) {
self.load_boot("./res/dmg_rom.bin");
}
}
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