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

feat: simplified boot loading

parent e6a4bcbb
No related branches found
No related tags found
No related merge requests found
Pipeline #913 passed
[package]
name = "boytacean"
description = "A Game Boy emulator that is written in Rust."
version = "0.1.0"
authors = ["João Magalhães <joamag@gmail.com>"]
description = "Game Boy in Rust"
license = "Apache"
keywords = ["gameboy", "emulator", "rust"]
edition = "2018"
......
......@@ -81,7 +81,7 @@ fn main() {
// creates a new Game Boy instance and loads both the boot ROM
// and the initial game ROM to "start the engine"
let mut game_boy = GameBoy::new();
game_boy.load_boot_static();
game_boy.load_boot_default();
game_boy.load_rom_file("../../res/roms.prop/tetris.gb");
//game_boy.load_rom_file("../../res/roms.prop/alleyway.gb");
......
import { default as wasm, GameBoy } from "./lib/boytacean.js";
import { BootRom, default as wasm, GameBoy } from "./lib/boytacean.js";
import info from "./package.json";
const PIXEL_UNSET_COLOR = 0x1b1a17ff;
......@@ -302,7 +302,7 @@ const start = async ({
// resets the Game Boy engine to restore it into
// a valid state ready to be used
state.gameBoy.reset();
state.gameBoy.load_boot_static();
state.gameBoy.load_boot_default();
state.gameBoy.load_rom(romData);
// updates the name of the currently selected engine
......@@ -534,17 +534,27 @@ const registerButtons = () => {
separatorNarrative.style.display = "none";
buttonDebug.classList.add("enabled");
const canvasTiles = document.getElementById("canvas-tiles") as HTMLCanvasElement;
const canvasTiles = document.getElementById(
"canvas-tiles"
) as HTMLCanvasElement;
const canvasTilesCtx = canvasTiles.getContext("2d");
const canvasImage = canvasTilesCtx.createImageData(canvasTiles.width, canvasTiles.height);
const canvasImage = canvasTilesCtx.createImageData(
canvasTiles.width,
canvasTiles.height
);
const videoBuff = new DataView(canvasImage.data.buffer);
const drawSprite = (index: number, format: PixelFormat = PixelFormat.RGB) => {
const drawSprite = (
index: number,
format: PixelFormat = PixelFormat.RGB
) => {
const pixels = state.gameBoy.get_tile_buffer(index);
const line = Math.floor(index / 16);
const column = index % 16;
let offset = ((line * canvasTiles.width * 8) + (column * 8)) * PixelFormat.RGBA;
let offset =
(line * canvasTiles.width * 8 + column * 8) *
PixelFormat.RGBA;
let counter = 0;
for (let index = 0; index < pixels.length; index += format) {
const color =
......@@ -553,7 +563,7 @@ const registerButtons = () => {
(pixels[index + 2] << 8) |
(format == PixelFormat.RGBA ? pixels[index + 3] : 0xff);
videoBuff.setUint32(offset, color);
counter++;
if (counter == 8) {
counter = 0;
......@@ -563,7 +573,7 @@ const registerButtons = () => {
}
}
canvasTilesCtx.putImageData(canvasImage, 0, 0);
}
};
for (let index = 0; index < 256; index++) {
drawSprite(index);
......@@ -743,7 +753,10 @@ const initCanvas = async () => {
state.videoBuff = new DataView(state.image.data.buffer);
};
const updateCanvas = (pixels: Uint8Array, format: PixelFormat = PixelFormat.RGB) => {
const updateCanvas = (
pixels: Uint8Array,
format: PixelFormat = PixelFormat.RGB
) => {
let offset = 0;
for (let index = 0; index < pixels.length; index += format) {
const color =
......
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;
#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub enum BootRom {
Dmg,
Sgb,
DmgBootix,
MgbBootix,
}
/// Static data corresponding to the DMG boot ROM
/// allows freely using the emulator without external dependency.
pub const DMG_BOOT: [u8; 256] = [
......
use crate::{
cpu::Cpu,
data::{DMG_BOOT, DMG_BOOTIX, MGB_BOOTIX, SGB_BOOT},
data::{BootRom, DMG_BOOT, DMG_BOOTIX, MGB_BOOTIX, SGB_BOOT},
mmu::Mmu,
pad::Pad,
ppu::{Ppu, Tile, FRAME_BUFFER_SIZE},
......@@ -66,49 +66,35 @@ impl GameBoy {
self.cpu.mmu().write_boot(0x0000, data);
}
pub fn load_boot_file(&mut self, path: &str) {
pub fn load_boot_path(&mut self, path: &str) {
let data = read_file(path);
self.load_boot(&data);
}
pub fn load_boot_dmg_f(&mut self) {
self.load_boot_file("./res/boot/dmg_boot.bin");
pub fn load_boot_file(&mut self, boot_rom: BootRom) {
match boot_rom {
BootRom::Dmg => self.load_boot_path("./res/boot/dmg_boot.bin"),
BootRom::Sgb => self.load_boot_path("./res/boot/sgb_boot.bin"),
BootRom::DmgBootix => self.load_boot_path("./res/boot/dmg_bootix.bin"),
BootRom::MgbBootix => self.load_boot_path("./res/boot/mgb_bootix.bin"),
}
}
pub fn load_boot_sgb_f(&mut self) {
self.load_boot_file("./res/boot/sgb_boot.bin");
pub fn load_boot_default_f(&mut self) {
self.load_boot_file(BootRom::DmgBootix);
}
pub fn load_boot_dmg_bootix_f(&mut self) {
self.load_boot_file("./res/boot/dmg_bootix.bin");
}
pub fn load_boot_mgb_bootix_f(&mut self) {
self.load_boot_file("./res/boot/mgb_bootix.bin");
pub fn load_boot_static(&mut self, boot_rom: BootRom) {
match boot_rom {
BootRom::Dmg => self.load_boot(&DMG_BOOT),
BootRom::Sgb => self.load_boot(&SGB_BOOT),
BootRom::DmgBootix => self.load_boot(&DMG_BOOTIX),
BootRom::MgbBootix => self.load_boot(&MGB_BOOTIX),
}
}
pub fn load_boot_default(&mut self) {
self.load_boot_dmg_bootix_f();
}
pub fn load_boot_dmg(&mut self) {
self.load_boot(&DMG_BOOT);
}
pub fn load_boot_sgb(&mut self) {
self.load_boot(&SGB_BOOT);
}
pub fn load_boot_dmg_bootix(&mut self) {
self.load_boot(&DMG_BOOTIX);
}
pub fn load_boot_mgb_bootix(&mut self) {
self.load_boot(&MGB_BOOTIX);
}
pub fn load_boot_static(&mut self) {
self.load_boot_dmg_bootix();
self.load_boot_static(BootRom::DmgBootix);
}
pub fn vram_eager(&mut self) -> Vec<u8> {
......
......@@ -16,6 +16,17 @@ pub enum PadSelection {
Direction,
}
pub enum PadKey {
Up,
Down,
Left,
Right,
Start,
Select,
A,
B,
}
impl Pad {
pub fn new() -> Self {
Self {
......
......@@ -290,8 +290,6 @@ impl Ppu {
if self.ly == 144 {
self.int_vblank = true;
self.mode = PpuMode::VBlank;
// self.drawData
// @todo implement this one
} else {
self.mode = PpuMode::OamRead;
}
......
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