mirror of
https://github.com/gopher64/gopher64.git
synced 2026-11-12 17:19:00 +01:00
Fix GB reading on android (#1328)
This commit is contained in:
1 parent
7523c6afa8
commit
3df67a4a8e
2 files changed
+20
-3
No files matched your search
@@ -1,6 +1,8 @@
|
||||
use crate::device;
|
||||
#[cfg(target_os = "android")]
|
||||
use crate::ui;
|
||||
|
||||
use std::io::Write;
|
||||
use std::io::{Read, Write};
|
||||
const MBC3_RTC_SECONDS: usize = 0;
|
||||
const MBC3_RTC_MINUTES: usize = 1;
|
||||
const MBC3_RTC_HOURS: usize = 2;
|
||||
@@ -34,6 +36,17 @@ pub enum CartType {
|
||||
MBC5RamBatt,
|
||||
}
|
||||
|
||||
pub fn read_file(path: &str) -> Option<Vec<u8>> {
|
||||
#[cfg(target_os = "android")]
|
||||
let mut file = ui::android::get_file_from_uri(&std::path::PathBuf::from(path))?;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let mut file = std::fs::File::open(path).ok()?;
|
||||
|
||||
let mut contents = vec![];
|
||||
file.read_to_end(&mut contents).ok()?;
|
||||
Some(contents)
|
||||
}
|
||||
|
||||
pub fn init(gb_cart: &mut device::controller::gbcart::GbCart, rom: &[u8], ram: &[u8]) {
|
||||
gb_cart.rom = rom.to_vec();
|
||||
let offset = match ram.len() % 8192 {
|
||||
|
||||
+6
-2
@@ -194,8 +194,12 @@ pub fn run(args: Args, arg_count: usize) -> std::io::Result<()> {
|
||||
if device.ui.config.input.transfer_pak[i]
|
||||
&& !device.ui.config.input.gb_rom_path[i].is_empty()
|
||||
&& !device.ui.config.input.gb_ram_path[i].is_empty()
|
||||
&& let Ok(rom) = std::fs::read(&device.ui.config.input.gb_rom_path[i])
|
||||
&& let Ok(ram) = std::fs::read(&device.ui.config.input.gb_ram_path[i])
|
||||
&& let Some(rom) = device::controller::gbcart::read_file(
|
||||
&device.ui.config.input.gb_rom_path[i],
|
||||
)
|
||||
&& let Some(ram) = device::controller::gbcart::read_file(
|
||||
&device.ui.config.input.gb_ram_path[i],
|
||||
)
|
||||
{
|
||||
device::controller::gbcart::init(&mut device.transferpaks[i].cart, &rom, &ram);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user