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

Merge branch 'joamag/web' into 'master'

Initial web version of boytacean

Closes #1

See merge request !2
parents e3f188ab be1b7517
No related branches found
No related tags found
1 merge request!2Initial web version of boytacean
Pipeline #842 passed
<svg role="img" xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" aria-labelledby="pauseIconTitle" stroke="#ffffff" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" fill="none" color="#ffffff"> <title id="pauseIconTitle">Pause</title> <rect width="4" height="16" x="5" y="4"/> <rect width="4" height="16" x="15" y="4"/> </svg>
\ No newline at end of file
<svg role="img" xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" aria-labelledby="playIconTitle" stroke="#ffffff" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" fill="none" color="#ffffff"> <title id="playIconTitle">Play</title> <path d="M20 12L5 21V3z"/> </svg>
\ No newline at end of file
<svg role="img" xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" aria-labelledby="refreshIconTitle" stroke="#ffffff" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" fill="none" color="#ffffff"> <title id="refreshIconTitle">Refresh</title> <polyline points="22 12 19 15 16 12"/> <path d="M11,20 C6.581722,20 3,16.418278 3,12 C3,7.581722 6.581722,4 11,4 C15.418278,4 19,7.581722 19,12 L19,14"/> </svg>
\ No newline at end of file
examples/web/res/storm.png

1.84 KiB

examples/web/res/sunglasses.png

4.23 KiB

examples/web/res/thunder.png

1.61 KiB

<svg role="img" xmlns="http://www.w3.org/2000/svg" width="48px" height="48px" viewBox="0 0 24 24" aria-labelledby="uploadIconTitle" stroke="#ffffff" stroke-width="2" stroke-linecap="square" stroke-linejoin="miter" fill="none" color="#ffffff"> <title id="uploadIconTitle">Upload</title> <path d="M12,4 L12,17"/> <polyline points="7 8 12 3 17 8"/> <path d="M20,21 L4,21"/> </svg>
\ No newline at end of file
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"sourceMap": true,
"outDir": ".",
"baseUrl": ".",
"lib": ["es2015", "dom"],
"paths": {
"*": ["node_modules/*", "src/types/*"]
}
},
"include": ["**/*"],
"exclude": []
}
File added
File added
File added
File added
File added
......@@ -8,6 +8,23 @@ use crate::{
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
/// Static data corresponding to the DMG boot ROM
/// allows freely using the emulator without external dependency.
pub const BOOT_DATA: [u8; 256] = [
49, 254, 255, 175, 33, 255, 159, 50, 203, 124, 32, 251, 33, 38, 255, 14, 17, 62, 128, 50, 226,
12, 62, 243, 226, 50, 62, 119, 119, 62, 252, 224, 71, 17, 4, 1, 33, 16, 128, 26, 205, 149, 0,
205, 150, 0, 19, 123, 254, 52, 32, 243, 17, 216, 0, 6, 8, 26, 19, 34, 35, 5, 32, 249, 62, 25,
234, 16, 153, 33, 47, 153, 14, 12, 61, 40, 8, 50, 13, 32, 249, 46, 15, 24, 243, 103, 62, 100,
87, 224, 66, 62, 145, 224, 64, 4, 30, 2, 14, 12, 240, 68, 254, 144, 32, 250, 13, 32, 247, 29,
32, 242, 14, 19, 36, 124, 30, 131, 254, 98, 40, 6, 30, 193, 254, 100, 32, 6, 123, 226, 12, 62,
135, 226, 240, 66, 144, 224, 66, 21, 32, 210, 5, 32, 79, 22, 32, 24, 203, 79, 6, 4, 197, 203,
17, 23, 193, 203, 17, 23, 5, 32, 245, 34, 35, 34, 35, 201, 206, 237, 102, 102, 204, 13, 0, 11,
3, 115, 0, 131, 0, 12, 0, 13, 0, 8, 17, 31, 136, 137, 0, 14, 220, 204, 110, 230, 221, 221, 217,
153, 187, 187, 103, 99, 110, 14, 236, 204, 221, 220, 153, 159, 187, 185, 51, 62, 60, 66, 185,
165, 185, 165, 66, 60, 33, 4, 1, 17, 168, 0, 26, 19, 190, 32, 254, 35, 125, 254, 52, 32, 245,
6, 25, 120, 134, 35, 5, 32, 251, 134, 32, 254, 62, 1, 224, 80,
];
#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct GameBoy {
cpu: Cpu,
......@@ -23,6 +40,10 @@ impl GameBoy {
GameBoy { cpu: cpu }
}
pub fn pc(&self) -> u16 {
self.cpu.pc()
}
pub fn clock(&mut self) -> u8 {
let cycles = self.cpu_clock();
self.ppu_clock(cycles);
......@@ -37,18 +58,34 @@ impl GameBoy {
self.ppu().clock(cycles)
}
pub fn load_rom(&mut self, path: &str) {
pub fn load_rom(&mut self, data: &[u8]) {
self.cpu.mmu().write_rom(0x0000, data);
}
pub fn load_rom_file(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_rom(0x0000, &data);
self.load_rom(&data);
}
pub fn load_boot(&mut self, path: &str) {
pub fn load_boot(&mut self, data: &[u8]) {
self.cpu.mmu().write_boot(0x0000, data);
}
pub fn load_boot_file(&mut self, path: &str) {
let data = read_file(path);
self.cpu.mmu().write_boot(0x0000, &data);
self.load_boot(&data);
}
pub fn load_boot_default(&mut self) {
self.load_boot("./res/dmg_rom.bin");
self.load_boot_file("./res/dmg_rom.bin");
}
pub fn load_boot_static(&mut self) {
self.load_boot(&BOOT_DATA);
}
pub fn frame_buffer_eager(&mut self) -> Vec<u8> {
self.frame_buffer().to_vec()
}
}
......
......@@ -94,15 +94,16 @@ impl Mmu {
match addr & 0xf000 {
// BOOT (256 B) + ROM0 (4 KB/16 KB)
0x0000 => {
println!("Writing to BOOT")
self.rom[addr as usize] = value;
println!("Writing to BOOT at 0x{:04x}", addr)
}
// ROM0 (12 KB/16 KB)
0x1000 | 0x2000 | 0x3000 => {
println!("Writing to ROM 0");
println!("Writing to ROM 0 at 0x{:04x}", addr);
}
// ROM1 (Unbanked) (16 KB)
0x4000 | 0x5000 | 0x6000 | 0x7000 => {
println!("Writing to ROM 1");
println!("Writing to ROM 1 at 0x{:04x}", addr);
}
// Graphics: VRAM (8 KB)
0x8000 | 0x9000 => {
......
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