Skip to content

Commit

Permalink
fix cartridge problem on web
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Sep 11, 2023
1 parent 47c6d46 commit 42a1135
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 110 deletions.
6 changes: 3 additions & 3 deletions docs/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/gameboy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum RenderMode {
#[cfg(not(target_arch = "wasm32"))]
Terminal,
#[cfg(target_arch = "wasm32")]
#[default]
WebAssembly,
}

Expand Down
1 change: 1 addition & 0 deletions src/mbc/mbc1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl MBC1 {
res.loadram().map(|_| res)
}

#[allow(dead_code)]
pub fn new_without_save(data: Vec<u8>) -> StrResult<MBC1> {
let (svpath, rambanks) = match data[0x147] {
0x02 => (None, ram_banks(data[0x149])),
Expand Down
32 changes: 32 additions & 0 deletions src/mbc/mbc3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,38 @@ impl MBC3 {
res.loadram().map(|_| res)
}

pub fn new_without_save(data: Vec<u8>) -> StrResult<MBC3> {
let subtype = data[0x147];
let svpath = match subtype {
// 0x0F | 0x10 | 0x13 => Some(file.with_extension("gbsave")),
_ => None,
};
let rambanks = match subtype {
0x10 | 0x12 | 0x13 => ram_banks(data[0x149]),
_ => 0,
};
let ramsize = rambanks * 0x2000;
let rtc = match subtype {
0x0F | 0x10 => Some(0),
_ => None,
};

let mut res = MBC3 {
rom: data,
ram: ::std::iter::repeat(0u8).take(ramsize).collect(),
rombank: 1,
rambank: 0,
rambanks,
selectrtc: false,
ram_on: false,
savepath: svpath,
rtc_ram: [0u8; 5],
rtc_ram_latch: [0u8; 5],
rtc_zero: rtc,
};
res.loadram().map(|_| res)
}

fn loadram(&mut self) -> StrResult<()> {
match self.savepath {
None => Ok(()),
Expand Down
3 changes: 2 additions & 1 deletion src/mbc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn get_mbc(
filepath: Option<path::PathBuf>,
) -> StrResult<Box<dyn MBC + 'static>> {
if filepath.is_none() {
return mbc1::MBC1::new_without_save(data).map(|v| Box::new(v) as Box<dyn MBC>);
return mbc3::MBC3::new_without_save(data).map(|v| Box::new(v) as Box<dyn MBC>);
}

let file = filepath.unwrap();
Expand Down Expand Up @@ -81,6 +81,7 @@ fn rom_banks(v: u8) -> usize {
}
}

#[allow(dead_code)]
fn check_checksum(data: &[u8]) -> StrResult<()> {
let mut value: u8 = 0;
for i in 0x134..0x14D {
Expand Down
1 change: 1 addition & 0 deletions src/mmu/mmu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn fill_random(slice: &mut [u8], start: u32) {
impl<'a> MMU<'a> {
pub fn new(data: Vec<u8>, file: Option<path::PathBuf>) -> StrResult<MMU<'a>> {
let mmu_mbc = mbc::get_mbc(data, file)?;

let serial = Serial::new();
let mut res = MMU {
wram: [0; WRAM_SIZE],
Expand Down
1 change: 0 additions & 1 deletion src/mmu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod mmu;
mod rtc;
mod serial;
mod timer;
105 changes: 0 additions & 105 deletions src/mmu/rtc.rs

This file was deleted.

8 changes: 8 additions & 0 deletions src/screen/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ use gl::types::*;
use glutin::event::{ElementState, VirtualKeyCode};

pub struct Glcx {
#[allow(unused)]
tex: GLuint,
#[allow(unused)]
program: GLuint,
#[allow(unused)]
frag: GLuint,
#[allow(unused)]
vert: GLuint,
#[allow(unused)]
ebo: GLuint,
#[allow(unused)]
vbo: GLuint,
#[allow(unused)]
vao: GLuint,
}

Expand Down Expand Up @@ -271,6 +278,7 @@ impl Glcx {
}
}

#[allow(dead_code)]
unsafe fn check_program_link(_gl: &Glcx, program: GLuint) {
let mut status = gl::FALSE as GLint;
gl::GetProgramiv(program, gl::LINK_STATUS, &mut status);
Expand Down
1 change: 1 addition & 0 deletions src/screen/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn window() -> web_sys::Window {
web_sys::window().expect("no global `window` exists")
}

#[allow(unused)]
fn add_event_listener(listener: &str, f: &Closure<dyn FnMut(web_sys::KeyboardEvent)>) {
window()
.add_event_listener_with_callback(listener, f.as_ref().unchecked_ref())
Expand Down

0 comments on commit 42a1135

Please sign in to comment.