mirror of
https://github.com/gopher64/gopher64.git
synced 2026-07-11 01:25:20 +02:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 421d533479 | |||
| ab5ef57106 | |||
| 37b41c0f66 | |||
| 4c50203ad3 | |||
| 271e4be68c | |||
| a9afd6bb5c | |||
| cd2b3dd143 | |||
| ab31b44aac | |||
| 58eaad1742 | |||
| a8e7c3c136 | |||
| f4099cfcce | |||
| 5b3e2a25de | |||
| 55ab1cb60b | |||
| 778a0a4015 | |||
| 96d2a72850 | |||
| 4c7361f963 | |||
| 80fc5f8ea2 | |||
| f0eb5764c8 | |||
| 480af8d36e | |||
| ad4eddb408 | |||
| 166b7daa9d |
@@ -3,10 +3,6 @@
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
|
||||
Generated
+5146
File diff suppressed because it is too large
Load Diff
+5
-8
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "gopher64"
|
||||
version = "1.0.2"
|
||||
version = "1.0.4"
|
||||
edition = "2021"
|
||||
rust-version = "1.82"
|
||||
|
||||
@@ -14,11 +14,12 @@ sevenz-rust = "0.6"
|
||||
chrono = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
eframe = "0.30"
|
||||
eframe = { version = "0.31", default-features = false, features = ["wayland", "x11", "wgpu"] }
|
||||
sha2 = "0.10"
|
||||
rusttype = "0.9"
|
||||
sdl3-sys = { version = "0.4", features = ["build-from-source-static"] }
|
||||
rfd = "0.15"
|
||||
rfd = { version = "0.15", default-features = false, features = ["xdg-portal", "tokio"] }
|
||||
tokio = {version = "1.43", features = ["rt-multi-thread", "macros"] }
|
||||
spin_sleep = "1.3"
|
||||
encoding_rs = "0.8"
|
||||
mimalloc = "0.1"
|
||||
@@ -28,11 +29,7 @@ socket2 = "0.5"
|
||||
fatfs = "0.3"
|
||||
postcard = { version = "1.1", features = ["use-std"] }
|
||||
clap = { version = "4.4", features = ["derive"] }
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "0.12"
|
||||
default-features = false
|
||||
features = ["http2","rustls-tls","charset","json","blocking"]
|
||||
reqwest = { version = "0.12", default-features = false, features = ["http2","rustls-tls","charset","json"] }
|
||||
|
||||
[build-dependencies]
|
||||
winres = "0.1"
|
||||
|
||||
@@ -330,40 +330,29 @@ bool rdp_update_screen()
|
||||
return emu_running;
|
||||
}
|
||||
|
||||
static uint32_t viCalculateHorizonalWidth(uint32_t hstart, uint32_t xscale, uint32_t width)
|
||||
static uint32_t viCalculateHorizonalWidth(uint32_t hstart, uint32_t xscale)
|
||||
{
|
||||
if (xscale == 0)
|
||||
return 320;
|
||||
|
||||
uint32_t start = ((hstart & 0x03FF0000) >> 16) & 0x3FF;
|
||||
uint32_t start = (hstart >> 16) & 0x3FF;
|
||||
uint32_t end = (hstart & 0x3FF);
|
||||
uint32_t delta;
|
||||
if (end > start)
|
||||
delta = end - start;
|
||||
else
|
||||
delta = start - end;
|
||||
delta = 0;
|
||||
uint32_t scale = (xscale & 0xFFF);
|
||||
|
||||
if (delta == 0)
|
||||
{
|
||||
delta = width;
|
||||
}
|
||||
|
||||
return (delta * scale) / 0x400;
|
||||
}
|
||||
|
||||
static uint32_t viCalculateVerticalHeight(uint32_t vstart, uint32_t yscale)
|
||||
{
|
||||
if (yscale == 0)
|
||||
return 240;
|
||||
|
||||
uint32_t start = ((vstart & 0x03FF0000) >> 16) & 0x3FF;
|
||||
uint32_t start = (vstart >> 16) & 0x3FF;
|
||||
uint32_t end = (vstart & 0x3FF);
|
||||
uint32_t delta;
|
||||
if (end > start)
|
||||
delta = end - start;
|
||||
else
|
||||
delta = start - end;
|
||||
delta = 0;
|
||||
uint32_t scale = (yscale & 0xFFF);
|
||||
|
||||
return (delta * scale) / 0x800;
|
||||
@@ -433,7 +422,7 @@ uint64_t rdp_process_commands()
|
||||
{
|
||||
processor->wait_for_timeline(processor->signal_timeline());
|
||||
|
||||
uint32_t width = viCalculateHorizonalWidth(*gfx_info.VI_H_START_REG, *gfx_info.VI_X_SCALE_REG, *gfx_info.VI_WIDTH_REG);
|
||||
uint32_t width = viCalculateHorizonalWidth(*gfx_info.VI_H_START_REG, *gfx_info.VI_X_SCALE_REG);
|
||||
if (width == 0)
|
||||
{
|
||||
width = 320;
|
||||
@@ -443,7 +432,7 @@ uint64_t rdp_process_commands()
|
||||
{
|
||||
height = 240;
|
||||
}
|
||||
interrupt_timer = width * height * 4;
|
||||
interrupt_timer = width * height;
|
||||
}
|
||||
|
||||
cmd_cur += cmd_length;
|
||||
|
||||
@@ -20,7 +20,6 @@ extern "C"
|
||||
uint32_t *VI_V_START_REG;
|
||||
uint32_t *VI_X_SCALE_REG;
|
||||
uint32_t *VI_Y_SCALE_REG;
|
||||
uint32_t *VI_WIDTH_REG;
|
||||
} GFX_INFO;
|
||||
|
||||
void rdp_init(void *_window, GFX_INFO _gfx_info, bool _upscale, bool _integer_scaling, bool _fullscreen);
|
||||
|
||||
@@ -381,6 +381,7 @@ impl Device {
|
||||
regs_dpc: [0; rdp::DPC_REGS_COUNT as usize],
|
||||
regs_dps: [0; rdp::DPS_REGS_COUNT as usize],
|
||||
wait_frozen: false,
|
||||
last_status_value: 0,
|
||||
},
|
||||
mi: mi::Mi {
|
||||
regs: [0; mi::MI_REGS_COUNT as usize],
|
||||
|
||||
+36
-13
@@ -56,7 +56,25 @@ pub fn read_mem(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_mem(device: &mut device::Device, _address: u64, value: u32, mask: u32) {
|
||||
pub fn write_mem(device: &mut device::Device, address: u64, value: u32, mask: u32) {
|
||||
if device.sc64.cfg[device::cart::sc64::SC64_ROM_WRITE_ENABLE as usize] != 0 {
|
||||
let masked_address = address as usize & CART_MASK;
|
||||
let mut data = u32::from_be_bytes(
|
||||
device.cart.rom[masked_address..masked_address + 4]
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
);
|
||||
device::memory::masked_write_32(&mut data, value, mask);
|
||||
device.cart.rom[masked_address..masked_address + 4].copy_from_slice(&data.to_be_bytes());
|
||||
for i in 0..4 {
|
||||
device.ui.saves.romsave.0.insert(
|
||||
(masked_address + i) as u32,
|
||||
device.cart.rom[masked_address + i],
|
||||
);
|
||||
}
|
||||
device.ui.saves.romsave.1 = true;
|
||||
}
|
||||
|
||||
device.cart.latch = value & mask;
|
||||
|
||||
device.pi.regs[device::pi::PI_STATUS_REG as usize] |= device::pi::PI_STATUS_IO_BUSY;
|
||||
@@ -76,23 +94,27 @@ pub fn dma_read(
|
||||
mut dram_addr: u32,
|
||||
length: u32,
|
||||
) -> u64 {
|
||||
dram_addr &= device::rdram::RDRAM_MASK as u32;
|
||||
cart_addr &= CART_MASK as u32;
|
||||
if device.sc64.cfg[device::cart::sc64::SC64_ROM_WRITE_ENABLE as usize] != 0 {
|
||||
dram_addr &= device::rdram::RDRAM_MASK as u32;
|
||||
cart_addr &= CART_MASK as u32;
|
||||
|
||||
for i in 0..length {
|
||||
if cart_addr + i < device.cart.rom.len() as u32 {
|
||||
device.cart.rom[(cart_addr + i) as usize] =
|
||||
device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap];
|
||||
for i in 0..length {
|
||||
if cart_addr + i < device.cart.rom.len() as u32 {
|
||||
device.cart.rom[(cart_addr + i) as usize] =
|
||||
device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap];
|
||||
|
||||
device.ui.saves.romsave.0.insert(
|
||||
cart_addr + i,
|
||||
device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap],
|
||||
);
|
||||
device
|
||||
.ui
|
||||
.saves
|
||||
.romsave
|
||||
.0
|
||||
.insert(cart_addr + i, device.cart.rom[(cart_addr + i) as usize]);
|
||||
|
||||
device.ui.saves.romsave.1 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
device.ui.saves.romsave.1 = true;
|
||||
|
||||
device::pi::calculate_cycles(device, 1, length)
|
||||
}
|
||||
|
||||
@@ -183,6 +205,7 @@ fn set_cic(device: &mut device::Device) {
|
||||
device.cart.cic_type = CicType::CicNus5167;
|
||||
device.cart.cic_seed = 0xdd;
|
||||
device.cart.rdram_size_offset = 0x318;
|
||||
device.sc64.cfg[device::cart::sc64::SC64_ROM_WRITE_ENABLE as usize] = 1;
|
||||
}
|
||||
_ => {
|
||||
device.cart.cic_type = CicType::CicNus6102;
|
||||
|
||||
+11
-6
@@ -11,6 +11,7 @@ const SC64_KEY_REG: u32 = 4;
|
||||
//const SC64_AUX_REG: u32 = 6;
|
||||
pub const SC64_REGS_COUNT: u32 = 7;
|
||||
|
||||
pub const SC64_ROM_WRITE_ENABLE: u32 = 1;
|
||||
pub const SC64_CFG_COUNT: u32 = 15;
|
||||
|
||||
const SC64_BUFFER_MASK: usize = 0x1FFF;
|
||||
@@ -43,7 +44,7 @@ pub fn read_regs(
|
||||
match reg as u32 {
|
||||
SC64_SCR_REG | SC64_DATA0_REG | SC64_DATA1_REG => device.sc64.regs[reg as usize],
|
||||
SC64_IDENTIFIER_REG => 0x53437632,
|
||||
_ => panic!("unknown read reg {} address {:x}", reg, address),
|
||||
_ => panic!("unknown read reg {} address {:#x}", reg, address),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u
|
||||
's' => {
|
||||
format_sdcard(device);
|
||||
// read sd card
|
||||
let address = device.sc64.regs[SC64_DATA0_REG as usize] as u64;
|
||||
let address = device.sc64.regs[SC64_DATA0_REG as usize] as u64 & 0x1FFFFFFF;
|
||||
let offset = (device.sc64.sector * 512) as usize;
|
||||
let length = (device.sc64.regs[SC64_DATA1_REG as usize] * 512) as usize;
|
||||
let mut i = 0;
|
||||
@@ -114,11 +115,12 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
device.memory.memory_map_write[(address >> 16) as usize](
|
||||
device::memory::data_write(
|
||||
device,
|
||||
address + i as u64,
|
||||
data,
|
||||
0xFFFFFFFF,
|
||||
false,
|
||||
);
|
||||
} else {
|
||||
panic!("sd card read out of bounds")
|
||||
@@ -129,17 +131,18 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u
|
||||
'S' => {
|
||||
format_sdcard(device);
|
||||
// write sd card
|
||||
let address = device.sc64.regs[SC64_DATA0_REG as usize] as u64;
|
||||
let address = device.sc64.regs[SC64_DATA0_REG as usize] as u64 & 0x1FFFFFFF;
|
||||
let offset = (device.sc64.sector * 512) as usize;
|
||||
let length = (device.sc64.regs[SC64_DATA1_REG as usize] * 512) as usize;
|
||||
let mut i = 0;
|
||||
|
||||
while i < length {
|
||||
if offset + i < device.ui.saves.sdcard.0.len() {
|
||||
let data = device.memory.memory_map_read[(address >> 16) as usize](
|
||||
let data = device::memory::data_read(
|
||||
device,
|
||||
address + i as u64,
|
||||
device::memory::AccessSize::Word,
|
||||
false,
|
||||
)
|
||||
.to_be_bytes();
|
||||
device.ui.saves.sdcard.0[(offset + i)..(offset + i + 4)]
|
||||
@@ -151,6 +154,8 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u
|
||||
}
|
||||
device.ui.saves.sdcard.1 = true;
|
||||
}
|
||||
'U' => {} // USB_WRITE_STATUS, ignored
|
||||
'M' => {} // USB_WRITE, ignored
|
||||
_ => {
|
||||
panic!(
|
||||
"unknown sc64 command: {}",
|
||||
@@ -161,7 +166,7 @@ pub fn write_regs(device: &mut device::Device, address: u64, value: u32, mask: u
|
||||
}
|
||||
}
|
||||
_ => panic!(
|
||||
"unknown write reg {} address {:x} value {}",
|
||||
"unknown write reg {} address {:#x} value {}",
|
||||
reg,
|
||||
address,
|
||||
char::from_u32(value & mask).unwrap()
|
||||
|
||||
@@ -26,8 +26,8 @@ pub struct Vru {
|
||||
pub words: Vec<String>,
|
||||
pub talking: bool,
|
||||
pub word_mappings: HashMap<String, String>,
|
||||
pub window_notifier: Option<std::sync::mpsc::Sender<Vec<String>>>,
|
||||
pub word_receiver: Option<std::sync::mpsc::Receiver<String>>,
|
||||
pub window_notifier: Option<tokio::sync::mpsc::Sender<Vec<String>>>,
|
||||
pub word_receiver: Option<tokio::sync::mpsc::Receiver<String>>,
|
||||
pub gui_ctx: Option<egui::Context>,
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ pub fn process(device: &mut device::Device, channel: usize) {
|
||||
ui::vru::prompt_for_match(
|
||||
&device.vru.words,
|
||||
device.vru.window_notifier.as_ref().unwrap(),
|
||||
device.vru.word_receiver.as_ref().unwrap(),
|
||||
device.vru.word_receiver.as_mut().unwrap(),
|
||||
device.vru.gui_ctx.as_ref().unwrap(),
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,7 @@ const MM_SI_REGS: usize = 0x04800000;
|
||||
//const MM_DOM2_ADDR1: usize = 0x05000000;
|
||||
pub const MM_DOM2_ADDR2: usize = 0x08000000;
|
||||
pub const MM_CART_ROM: usize = 0x10000000;
|
||||
const MM_PIF_MEM: usize = 0x1fc00000;
|
||||
pub const MM_PIF_MEM: usize = 0x1fc00000;
|
||||
//const MM_DOM1_ADDR3: usize = 0x1fd00000;
|
||||
const MM_IS_VIEWER: usize = 0x13ff0000;
|
||||
pub const MM_SC64_BUFFER: usize = 0x1ffe0000;
|
||||
|
||||
+34
-4
@@ -117,17 +117,24 @@ fn get_handler(address: u32) -> PiHandler {
|
||||
read: device::cart::rom::dma_read,
|
||||
write: device::cart::rom::dma_write,
|
||||
};
|
||||
if address >= device::memory::MM_SC64_BUFFER as u32 {
|
||||
if address >= device::memory::MM_SC64_BUFFER as u32
|
||||
&& address < (device::memory::MM_SC64_BUFFER + 0x2000) as u32
|
||||
{
|
||||
handler.read = device::cart::sc64::dma_read;
|
||||
handler.write = device::cart::sc64::dma_write;
|
||||
} else if address >= device::memory::MM_CART_ROM as u32 {
|
||||
} else if address >= device::memory::MM_CART_ROM as u32
|
||||
&& address < device::memory::MM_PIF_MEM as u32
|
||||
{
|
||||
handler.read = device::cart::rom::dma_read;
|
||||
handler.write = device::cart::rom::dma_write;
|
||||
} else if address >= device::memory::MM_DOM2_ADDR2 as u32 {
|
||||
} else if address >= device::memory::MM_DOM2_ADDR2 as u32
|
||||
&& address < device::memory::MM_CART_ROM as u32
|
||||
{
|
||||
handler.read = device::cart::sram::dma_read;
|
||||
handler.write = device::cart::sram::dma_write;
|
||||
} else {
|
||||
panic!("unknown pi handler")
|
||||
handler.read = unknown_dma_read;
|
||||
handler.write = unknown_dma_write;
|
||||
}
|
||||
handler
|
||||
}
|
||||
@@ -197,3 +204,26 @@ pub fn dma_event(device: &mut device::Device) {
|
||||
|
||||
device::mi::set_rcp_interrupt(device, device::mi::MI_INTR_PI)
|
||||
}
|
||||
|
||||
fn unknown_dma_read(
|
||||
device: &mut device::Device,
|
||||
mut _cart_addr: u32,
|
||||
mut _dram_addr: u32,
|
||||
length: u32,
|
||||
) -> u64 {
|
||||
device::pi::calculate_cycles(device, 1, length)
|
||||
}
|
||||
|
||||
fn unknown_dma_write(
|
||||
device: &mut device::Device,
|
||||
mut _cart_addr: u32,
|
||||
mut dram_addr: u32,
|
||||
length: u32,
|
||||
) -> u64 {
|
||||
dram_addr &= device::rdram::RDRAM_MASK as u32;
|
||||
|
||||
for i in 0..length {
|
||||
device.rdram.mem[(dram_addr + i) as usize ^ device.byte_swap] = 0;
|
||||
}
|
||||
device::pi::calculate_cycles(device, 1, length)
|
||||
}
|
||||
|
||||
+14
-2
@@ -45,6 +45,7 @@ pub struct Rdp {
|
||||
pub regs_dpc: [u32; DPC_REGS_COUNT as usize],
|
||||
pub regs_dps: [u32; DPS_REGS_COUNT as usize],
|
||||
pub wait_frozen: bool,
|
||||
pub last_status_value: u32,
|
||||
}
|
||||
|
||||
pub fn read_regs_dpc(
|
||||
@@ -54,6 +55,15 @@ pub fn read_regs_dpc(
|
||||
) -> u32 {
|
||||
let reg = (address & 0xFFFF) >> 2;
|
||||
match reg as u32 {
|
||||
DPC_STATUS_REG => {
|
||||
let value =
|
||||
device.rdp.regs_dpc[reg as usize] & (DPC_STATUS_PIPE_BUSY | DPC_STATUS_CMD_BUSY);
|
||||
if value == device.rdp.last_status_value && value != 0 {
|
||||
device.rsp.cpu.sync_point = true;
|
||||
}
|
||||
device.rdp.last_status_value = value;
|
||||
device.rdp.regs_dpc[reg as usize]
|
||||
}
|
||||
DPC_CLOCK_REG => 0xFFFFFF, // needed for JFG
|
||||
DPC_CURRENT_REG => {
|
||||
if device.rdp.wait_frozen {
|
||||
@@ -103,7 +113,8 @@ pub fn write_regs_dpc(device: &mut device::Device, address: u64, value: u32, mas
|
||||
|
||||
fn run_rdp(device: &mut device::Device) {
|
||||
let timer = ui::video::process_rdp_list();
|
||||
device.rdp.regs_dpc[DPC_STATUS_REG as usize] |= DPC_STATUS_START_GCLK | DPC_STATUS_PIPE_BUSY;
|
||||
device.rdp.regs_dpc[DPC_STATUS_REG as usize] |=
|
||||
DPC_STATUS_START_GCLK | DPC_STATUS_PIPE_BUSY | DPC_STATUS_CMD_BUSY;
|
||||
|
||||
if timer != 0 {
|
||||
device::events::create_event(
|
||||
@@ -185,7 +196,8 @@ pub fn init(device: &mut device::Device) {
|
||||
}
|
||||
|
||||
fn rdp_interrupt_event(device: &mut device::Device) {
|
||||
device.rdp.regs_dpc[DPC_STATUS_REG as usize] &= !(DPC_STATUS_START_GCLK | DPC_STATUS_PIPE_BUSY);
|
||||
device.rdp.regs_dpc[DPC_STATUS_REG as usize] &=
|
||||
!(DPC_STATUS_START_GCLK | DPC_STATUS_PIPE_BUSY | DPC_STATUS_CMD_BUSY);
|
||||
|
||||
device::mi::set_rcp_interrupt(device, device::mi::MI_INTR_DP)
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ use governor::clock::Clock;
|
||||
|
||||
const VI_STATUS_REG: u32 = 0;
|
||||
//const VI_ORIGIN_REG: u32 = 1;
|
||||
pub const VI_WIDTH_REG: u32 = 2;
|
||||
//const VI_WIDTH_REG: u32 = 2;
|
||||
//const VI_V_INTR_REG: u32 = 3;
|
||||
const VI_CURRENT_REG: u32 = 4;
|
||||
//const VI_BURST_REG: u32 = 5;
|
||||
|
||||
+2
-1
@@ -64,7 +64,8 @@ struct Args {
|
||||
clear_input_bindings: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let dirs = ui::get_dirs();
|
||||
|
||||
let mut result = std::fs::create_dir_all(dirs.config_dir);
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ pub struct Netplay {
|
||||
status: u8,
|
||||
buffer_target: u8,
|
||||
pub fast_forward: bool,
|
||||
pub error_notifier: std::sync::mpsc::Sender<String>,
|
||||
pub error_notifier: tokio::sync::mpsc::Sender<String>,
|
||||
pub gui_ctx: egui::Context,
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ struct InputEvent {
|
||||
}
|
||||
|
||||
fn send_error(netplay: &mut Netplay, error: String) {
|
||||
netplay.error_notifier.send(error).unwrap();
|
||||
netplay.error_notifier.try_send(error).unwrap();
|
||||
|
||||
netplay.gui_ctx.request_repaint(); // this is so the window pops up right away
|
||||
}
|
||||
@@ -219,7 +219,7 @@ pub fn init(
|
||||
mut peer_addr: std::net::SocketAddr,
|
||||
session: ui::gui::gui_netplay::NetplayRoom,
|
||||
player_number: u8,
|
||||
error_notifier: std::sync::mpsc::Sender<String>,
|
||||
error_notifier: tokio::sync::mpsc::Sender<String>,
|
||||
gui_ctx: egui::Context,
|
||||
) -> Netplay {
|
||||
peer_addr.set_port(session.port.unwrap() as u16);
|
||||
|
||||
+109
-89
@@ -21,9 +21,9 @@ pub struct GopherEguiApp {
|
||||
emulate_vru: bool,
|
||||
dinput: bool,
|
||||
show_vru_dialog: bool,
|
||||
vru_window_receiver: Option<std::sync::mpsc::Receiver<Vec<String>>>,
|
||||
netplay_error_receiver: Option<std::sync::mpsc::Receiver<String>>,
|
||||
vru_word_notifier: Option<std::sync::mpsc::Sender<String>>,
|
||||
vru_window_receiver: Option<tokio::sync::mpsc::Receiver<Vec<String>>>,
|
||||
netplay_error_receiver: Option<tokio::sync::mpsc::Receiver<String>>,
|
||||
vru_word_notifier: Option<tokio::sync::mpsc::Sender<String>>,
|
||||
vru_word_list: Vec<String>,
|
||||
pub netplay: gui_netplay::GuiNetplay,
|
||||
}
|
||||
@@ -84,7 +84,7 @@ impl GopherEguiApp {
|
||||
controller_paths: Vec<String>,
|
||||
controller_names: Vec<String>,
|
||||
) -> GopherEguiApp {
|
||||
add_japanese_font(&cc.egui_ctx);
|
||||
add_fonts(&cc.egui_ctx);
|
||||
let config = ui::config::Config::new();
|
||||
|
||||
let mut selected_controller = [-1, -1, -1, -1];
|
||||
@@ -236,7 +236,7 @@ fn show_vru_dialog(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
app.vru_word_notifier
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(v.clone())
|
||||
.try_send(v.clone())
|
||||
.unwrap();
|
||||
app.show_vru_dialog = false;
|
||||
}
|
||||
@@ -248,7 +248,7 @@ fn show_vru_dialog(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
app.vru_word_notifier
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(String::from(""))
|
||||
.try_send(String::from(""))
|
||||
.unwrap();
|
||||
app.show_vru_dialog = false;
|
||||
}
|
||||
@@ -285,19 +285,19 @@ pub fn open_rom(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
let (netplay_error_notifier, netplay_error_receiver): (
|
||||
std::sync::mpsc::Sender<String>,
|
||||
std::sync::mpsc::Receiver<String>,
|
||||
) = std::sync::mpsc::channel();
|
||||
tokio::sync::mpsc::Sender<String>,
|
||||
tokio::sync::mpsc::Receiver<String>,
|
||||
) = tokio::sync::mpsc::channel(1);
|
||||
|
||||
let (vru_window_notifier, vru_window_receiver): (
|
||||
std::sync::mpsc::Sender<Vec<String>>,
|
||||
std::sync::mpsc::Receiver<Vec<String>>,
|
||||
) = std::sync::mpsc::channel();
|
||||
tokio::sync::mpsc::Sender<Vec<String>>,
|
||||
tokio::sync::mpsc::Receiver<Vec<String>>,
|
||||
) = tokio::sync::mpsc::channel(1);
|
||||
|
||||
let (vru_word_notifier, vru_word_receiver): (
|
||||
std::sync::mpsc::Sender<String>,
|
||||
std::sync::mpsc::Receiver<String>,
|
||||
) = std::sync::mpsc::channel();
|
||||
tokio::sync::mpsc::Sender<String>,
|
||||
tokio::sync::mpsc::Receiver<String>,
|
||||
) = tokio::sync::mpsc::channel(1);
|
||||
|
||||
if netplay {
|
||||
app.netplay_error_receiver = Some(netplay_error_receiver);
|
||||
@@ -312,83 +312,89 @@ pub fn open_rom(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
|
||||
let rom_contents = app.netplay.rom_contents.clone();
|
||||
let gui_ctx = ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let file = if !netplay {
|
||||
rfd::FileDialog::new().pick_file()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let save_config_items = SaveConfig {
|
||||
selected_controller,
|
||||
selected_profile,
|
||||
controller_enabled,
|
||||
upscale,
|
||||
integer_scaling,
|
||||
fullscreen,
|
||||
emulate_vru,
|
||||
};
|
||||
let mut task = None;
|
||||
if !netplay {
|
||||
task = Some(rfd::AsyncFileDialog::new().pick_file());
|
||||
}
|
||||
tokio::spawn(async move {
|
||||
let file = if !netplay { task.unwrap().await } else { None };
|
||||
|
||||
if cfg!(target_os = "macos") && file.is_some() {
|
||||
// mac os requires the process to be started on the main thread
|
||||
// this means that netplay and VRU emulation will not work on mac os
|
||||
{
|
||||
let mut config = ui::config::Config::new();
|
||||
save_config(&mut config, controller_paths, save_config_items);
|
||||
}
|
||||
let mut command = std::process::Command::new(std::env::current_exe().unwrap());
|
||||
if fullscreen {
|
||||
command.arg("--fullscreen");
|
||||
}
|
||||
command.arg(file.unwrap().as_path());
|
||||
std::thread::Builder::new()
|
||||
.name("n64".to_string())
|
||||
.spawn(move || {
|
||||
let save_config_items = SaveConfig {
|
||||
selected_controller,
|
||||
selected_profile,
|
||||
controller_enabled,
|
||||
upscale,
|
||||
integer_scaling,
|
||||
fullscreen,
|
||||
emulate_vru,
|
||||
};
|
||||
|
||||
let status = command.status().expect("failed to execute process");
|
||||
if !status.success() {
|
||||
panic!("process exited with: {}", status);
|
||||
}
|
||||
} else if file.is_some() || netplay {
|
||||
let running_file = cache_dir.join("game_running");
|
||||
if running_file.exists() {
|
||||
println!("Game already running");
|
||||
return;
|
||||
}
|
||||
let result = std::fs::File::create(running_file.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not create running file: {}", result.err().unwrap())
|
||||
}
|
||||
if cfg!(target_os = "macos") && file.is_some() {
|
||||
// mac os requires the process to be started on the main thread
|
||||
// this means that netplay and VRU emulation will not work on mac os
|
||||
{
|
||||
let mut config = ui::config::Config::new();
|
||||
save_config(&mut config, controller_paths, save_config_items);
|
||||
}
|
||||
let mut command = std::process::Command::new(std::env::current_exe().unwrap());
|
||||
if fullscreen {
|
||||
command.arg("--fullscreen");
|
||||
}
|
||||
command.arg(file.unwrap().path());
|
||||
|
||||
let mut device = device::Device::new();
|
||||
save_config(&mut device.ui.config, controller_paths, save_config_items);
|
||||
let status = command.status().expect("failed to execute process");
|
||||
if !status.success() {
|
||||
panic!("process exited with: {}", status);
|
||||
}
|
||||
} else if file.is_some() || netplay {
|
||||
let running_file = cache_dir.join("game_running");
|
||||
if running_file.exists() {
|
||||
println!("Game already running");
|
||||
return;
|
||||
}
|
||||
let result = std::fs::File::create(running_file.clone());
|
||||
if result.is_err() {
|
||||
panic!("could not create running file: {}", result.err().unwrap())
|
||||
}
|
||||
|
||||
if netplay {
|
||||
device.netplay = Some(netplay::init(
|
||||
peer_addr.unwrap(),
|
||||
session.unwrap(),
|
||||
player_number.unwrap(),
|
||||
netplay_error_notifier,
|
||||
gui_ctx,
|
||||
));
|
||||
device::run_game(rom_contents, &mut device, fullscreen);
|
||||
netplay::close(&mut device);
|
||||
} else {
|
||||
if emulate_vru {
|
||||
device.vru.window_notifier = Some(vru_window_notifier);
|
||||
device.vru.word_receiver = Some(vru_word_receiver);
|
||||
device.vru.gui_ctx = Some(gui_ctx);
|
||||
let mut device = device::Device::new();
|
||||
save_config(&mut device.ui.config, controller_paths, save_config_items);
|
||||
|
||||
if netplay {
|
||||
device.netplay = Some(netplay::init(
|
||||
peer_addr.unwrap(),
|
||||
session.unwrap(),
|
||||
player_number.unwrap(),
|
||||
netplay_error_notifier,
|
||||
gui_ctx,
|
||||
));
|
||||
device::run_game(rom_contents, &mut device, fullscreen);
|
||||
netplay::close(&mut device);
|
||||
} else {
|
||||
if emulate_vru {
|
||||
device.vru.window_notifier = Some(vru_window_notifier);
|
||||
device.vru.word_receiver = Some(vru_word_receiver);
|
||||
device.vru.gui_ctx = Some(gui_ctx);
|
||||
}
|
||||
|
||||
let rom_contents = device::get_rom_contents(file.unwrap().path());
|
||||
if rom_contents.is_empty() {
|
||||
println!("Could not read rom file");
|
||||
} else {
|
||||
device::run_game(rom_contents, &mut device, fullscreen);
|
||||
}
|
||||
}
|
||||
let result = std::fs::remove_file(running_file);
|
||||
if result.is_err() {
|
||||
panic!("could not remove running file: {}", result.err().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
let rom_contents = device::get_rom_contents(file.unwrap().as_path());
|
||||
if rom_contents.is_empty() {
|
||||
println!("Could not read rom file");
|
||||
} else {
|
||||
device::run_game(rom_contents, &mut device, fullscreen);
|
||||
}
|
||||
}
|
||||
let result = std::fs::remove_file(running_file);
|
||||
if result.is_err() {
|
||||
panic!("could not remove running file: {}", result.err().unwrap())
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -407,7 +413,7 @@ impl eframe::App for GopherEguiApp {
|
||||
}
|
||||
|
||||
if self.netplay_error_receiver.is_some() {
|
||||
let result = self.netplay_error_receiver.as_ref().unwrap().try_recv();
|
||||
let result = self.netplay_error_receiver.as_mut().unwrap().try_recv();
|
||||
if result.is_ok() {
|
||||
self.netplay.error = result.unwrap();
|
||||
}
|
||||
@@ -518,7 +524,7 @@ impl eframe::App for GopherEguiApp {
|
||||
});
|
||||
|
||||
if self.emulate_vru && self.vru_window_receiver.is_some() {
|
||||
let result = self.vru_window_receiver.as_ref().unwrap().try_recv();
|
||||
let result = self.vru_window_receiver.as_mut().unwrap().try_recv();
|
||||
if result.is_ok() {
|
||||
self.show_vru_dialog = true;
|
||||
self.vru_word_list = result.unwrap();
|
||||
@@ -531,7 +537,21 @@ impl eframe::App for GopherEguiApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_japanese_font(ctx: &egui::Context) {
|
||||
fn add_fonts(ctx: &egui::Context) {
|
||||
ctx.add_font(eframe::epaint::text::FontInsert::new(
|
||||
"regular_font",
|
||||
egui::FontData::from_static(include_bytes!("../../data/Roboto-Regular.ttf")),
|
||||
vec![
|
||||
eframe::epaint::text::InsertFontFamily {
|
||||
family: egui::FontFamily::Proportional,
|
||||
priority: egui::epaint::text::FontPriority::Highest,
|
||||
},
|
||||
eframe::epaint::text::InsertFontFamily {
|
||||
family: egui::FontFamily::Monospace,
|
||||
priority: egui::epaint::text::FontPriority::Highest,
|
||||
},
|
||||
],
|
||||
));
|
||||
ctx.add_font(eframe::epaint::text::FontInsert::new(
|
||||
"japanese_font",
|
||||
egui::FontData::from_static(include_bytes!("../../data/NotoSansJP-Regular.ttf")),
|
||||
|
||||
+32
-35
@@ -1,6 +1,6 @@
|
||||
use crate::device;
|
||||
use crate::ui::gui;
|
||||
use crate::ui::gui::GopherEguiApp;
|
||||
use crate::ui::{self, gui};
|
||||
use eframe::egui;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
@@ -41,8 +41,8 @@ pub struct GuiNetplay {
|
||||
pub socket:
|
||||
Option<tungstenite::WebSocket<tungstenite::stream::MaybeTlsStream<std::net::TcpStream>>>,
|
||||
pub server_receiver:
|
||||
Option<std::sync::mpsc::Receiver<std::collections::HashMap<String, String>>>,
|
||||
pub game_info_receiver: Option<std::sync::mpsc::Receiver<GameInfo>>,
|
||||
Option<tokio::sync::mpsc::Receiver<std::collections::HashMap<String, String>>>,
|
||||
pub game_info_receiver: Option<tokio::sync::mpsc::Receiver<GameInfo>>,
|
||||
pub broadcast_socket: Option<std::net::UdpSocket>,
|
||||
pub broadcast_timer: Option<std::time::Instant>,
|
||||
}
|
||||
@@ -99,16 +99,14 @@ fn get_servers(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
if app.netplay.server_receiver.is_none() {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(1);
|
||||
app.netplay.server_receiver = Some(rx);
|
||||
let gui_ctx = ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
if let Ok(response) =
|
||||
reqwest::blocking::get("https://m64p.s3.amazonaws.com/servers.json")
|
||||
.unwrap()
|
||||
.json::<std::collections::HashMap<String, String>>()
|
||||
{
|
||||
tx.send(response).unwrap();
|
||||
let task = reqwest::get("https://m64p.s3.amazonaws.com/servers.json");
|
||||
tokio::spawn(async move {
|
||||
let response = task.await;
|
||||
if let Ok(response) = response {
|
||||
tx.send(response.json().await.unwrap()).await.unwrap();
|
||||
gui_ctx.request_repaint();
|
||||
}
|
||||
});
|
||||
@@ -143,7 +141,7 @@ fn get_servers(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
if app.netplay.server_receiver.is_some() {
|
||||
let result = app.netplay.server_receiver.as_ref().unwrap().try_recv();
|
||||
let result = app.netplay.server_receiver.as_mut().unwrap().try_recv();
|
||||
if result.is_ok() {
|
||||
app.netplay.servers.extend(result.unwrap());
|
||||
app.netplay.server_receiver = None;
|
||||
@@ -181,15 +179,16 @@ pub fn netplay_create(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
app.netplay.create_rom_label = "Open ROM".to_string();
|
||||
}
|
||||
if ui.button(&app.netplay.create_rom_label).clicked() {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(1);
|
||||
app.netplay.game_info_receiver = Some(rx);
|
||||
let gui_ctx = ctx.clone();
|
||||
app.netplay.create_rom_label = "Inspecting ROM".to_string();
|
||||
std::thread::spawn(move || {
|
||||
let file = rfd::FileDialog::new().pick_file();
|
||||
let task = rfd::AsyncFileDialog::new().pick_file();
|
||||
tokio::spawn(async move {
|
||||
let file = task.await;
|
||||
|
||||
if let Some(file) = file {
|
||||
parse_rom_file(file, tx);
|
||||
parse_rom_file(file, tx).await;
|
||||
} else {
|
||||
tx.send((
|
||||
"".to_string(),
|
||||
@@ -197,6 +196,7 @@ pub fn netplay_create(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
"Open ROM".to_string(),
|
||||
vec![],
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
gui_ctx.request_repaint();
|
||||
@@ -217,7 +217,7 @@ pub fn netplay_create(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
get_servers(app, ctx);
|
||||
|
||||
if app.netplay.game_info_receiver.is_some() {
|
||||
let result = app.netplay.game_info_receiver.as_ref().unwrap().try_recv();
|
||||
let result = app.netplay.game_info_receiver.as_mut().unwrap().try_recv();
|
||||
if result.is_ok() {
|
||||
app.netplay.game_info_receiver = None;
|
||||
let data = result.unwrap();
|
||||
@@ -391,21 +391,15 @@ fn get_sessions(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_rom_file(file: std::path::PathBuf, tx: std::sync::mpsc::Sender<GameInfo>) {
|
||||
let rom_contents = device::get_rom_contents(file.as_path());
|
||||
async fn parse_rom_file(file: rfd::FileHandle, tx: tokio::sync::mpsc::Sender<GameInfo>) {
|
||||
let rom_contents = device::get_rom_contents(file.path());
|
||||
if !rom_contents.is_empty() {
|
||||
let hash = device::cart::rom::calculate_hash(&rom_contents);
|
||||
let game_name = std::str::from_utf8(&rom_contents[0x20..0x20 + 0x14])
|
||||
.unwrap()
|
||||
.trim()
|
||||
.replace('\0', "");
|
||||
tx.send((
|
||||
hash,
|
||||
game_name,
|
||||
file.file_name().unwrap().to_string_lossy().to_string(),
|
||||
rom_contents,
|
||||
))
|
||||
.unwrap();
|
||||
let game_name = ui::storage::get_game_name(&rom_contents);
|
||||
|
||||
tx.send((hash, game_name, file.file_name(), rom_contents))
|
||||
.await
|
||||
.unwrap();
|
||||
} else {
|
||||
tx.send((
|
||||
"".to_string(),
|
||||
@@ -413,6 +407,7 @@ fn parse_rom_file(file: std::path::PathBuf, tx: std::sync::mpsc::Sender<GameInfo
|
||||
"Invalid ROM".to_string(),
|
||||
vec![],
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -443,7 +438,7 @@ pub fn netplay_join(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
if app.netplay.game_info_receiver.is_some() {
|
||||
let result = app.netplay.game_info_receiver.as_ref().unwrap().try_recv();
|
||||
let result = app.netplay.game_info_receiver.as_mut().unwrap().try_recv();
|
||||
if result.is_ok() {
|
||||
app.netplay.game_info_receiver = None;
|
||||
let data = result.unwrap();
|
||||
@@ -584,15 +579,16 @@ pub fn netplay_join(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
{
|
||||
app.netplay.error = "Session requires a password".to_string();
|
||||
} else {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(1);
|
||||
app.netplay.game_info_receiver = Some(rx);
|
||||
let gui_ctx = ctx.clone();
|
||||
app.netplay.join_rom_label = "Inspecting ROM".to_string();
|
||||
std::thread::spawn(move || {
|
||||
let file = rfd::FileDialog::new().pick_file();
|
||||
let task = rfd::AsyncFileDialog::new().pick_file();
|
||||
tokio::spawn(async move {
|
||||
let file = task.await;
|
||||
|
||||
if let Some(file) = file {
|
||||
parse_rom_file(file, tx);
|
||||
parse_rom_file(file, tx).await;
|
||||
} else {
|
||||
tx.send((
|
||||
"".to_string(),
|
||||
@@ -600,6 +596,7 @@ pub fn netplay_join(app: &mut GopherEguiApp, ctx: &egui::Context) {
|
||||
"No ROM selected".to_string(),
|
||||
vec![],
|
||||
))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
gui_ctx.request_repaint();
|
||||
|
||||
+69
-17
@@ -1,5 +1,7 @@
|
||||
use crate::netplay;
|
||||
use crate::ui;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum SaveTypes {
|
||||
@@ -41,10 +43,10 @@ fn get_save_type(rom: &[u8], game_id: &str) -> Vec<SaveTypes> {
|
||||
1 => return vec![SaveTypes::Eeprom4k],
|
||||
2 => return vec![SaveTypes::Eeprom16k],
|
||||
3 => return vec![SaveTypes::Sram],
|
||||
4 => panic!("Unsupported save type: {:X}", save_type),
|
||||
4 => panic!("Unsupported save type: {}", save_type),
|
||||
5 => return vec![SaveTypes::Flash],
|
||||
6 => panic!("Unsupported save type: {:X}", save_type),
|
||||
_ => panic!("Unknown save type: {:X}", save_type),
|
||||
6 => panic!("Unsupported save type: {}", save_type),
|
||||
_ => panic!("Unknown save type: {}", save_type),
|
||||
}
|
||||
}
|
||||
match game_id {
|
||||
@@ -104,15 +106,25 @@ fn get_save_type(rom: &[u8], game_id: &str) -> Vec<SaveTypes> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_game_name(rom: &[u8]) -> String {
|
||||
let mut game_name = "".to_owned();
|
||||
let header_value = std::str::from_utf8(&rom[0x20..0x34]);
|
||||
if header_value.is_ok() {
|
||||
let re = regex::Regex::new(r"[^a-zA-Z0-9_ -]").unwrap();
|
||||
game_name = re
|
||||
.replace_all(header_value.unwrap(), "")
|
||||
.trim()
|
||||
.replace('\0', "");
|
||||
}
|
||||
game_name
|
||||
}
|
||||
|
||||
pub fn init(ui: &mut ui::Ui, rom: &[u8]) {
|
||||
ui.save_type = get_save_type(rom, &ui.game_id);
|
||||
|
||||
let base_path = ui.dirs.data_dir.join("saves");
|
||||
|
||||
let game_name = std::str::from_utf8(&rom[0x20..0x20 + 0x14])
|
||||
.unwrap()
|
||||
.trim()
|
||||
.replace('\0', "");
|
||||
let game_name = get_game_name(rom);
|
||||
|
||||
let prefix = if game_name.is_empty() {
|
||||
&ui.game_id
|
||||
@@ -205,37 +217,77 @@ pub fn load_saves(ui: &mut ui::Ui, netplay: &mut Option<netplay::Netplay>) {
|
||||
&ui.saves.mempak.0,
|
||||
ui.saves.mempak.0.len(),
|
||||
);
|
||||
|
||||
let mut compressed_sd = Vec::new();
|
||||
if !ui.saves.sdcard.0.is_empty() {
|
||||
compressed_sd = compress_file(&ui.saves.sdcard.0);
|
||||
}
|
||||
netplay::send_save(
|
||||
netplay.as_mut().unwrap(),
|
||||
"img",
|
||||
&ui.saves.sdcard.0,
|
||||
ui.saves.sdcard.0.len(),
|
||||
&compressed_sd,
|
||||
compressed_sd.len(),
|
||||
);
|
||||
let mut romsave_bytes: Vec<u8> = vec![];
|
||||
|
||||
let mut compressed_romsave = Vec::new();
|
||||
if !ui.saves.romsave.0.is_empty() {
|
||||
romsave_bytes = postcard::to_stdvec(&ui.saves.romsave.0).unwrap();
|
||||
compressed_romsave =
|
||||
compress_file(&postcard::to_stdvec(&ui.saves.romsave.0).unwrap());
|
||||
}
|
||||
netplay::send_save(
|
||||
netplay.as_mut().unwrap(),
|
||||
"rom",
|
||||
&romsave_bytes,
|
||||
romsave_bytes.len(),
|
||||
&compressed_romsave,
|
||||
compressed_romsave.len(),
|
||||
);
|
||||
} else {
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "eep", &mut ui.saves.eeprom.0);
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "sra", &mut ui.saves.sram.0);
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "fla", &mut ui.saves.flash.0);
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "mpk", &mut ui.saves.mempak.0);
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "img", &mut ui.saves.sdcard.0);
|
||||
let mut romsave_bytes: Vec<u8> = vec![];
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "rom", &mut romsave_bytes);
|
||||
if !romsave_bytes.is_empty() {
|
||||
|
||||
let mut compressed_sd = Vec::new();
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "img", &mut compressed_sd);
|
||||
if !compressed_sd.is_empty() {
|
||||
ui.saves.sdcard.0 = decompress_file(&compressed_sd);
|
||||
}
|
||||
|
||||
let mut compressed_romsave = Vec::new();
|
||||
netplay::receive_save(netplay.as_mut().unwrap(), "rom", &mut compressed_romsave);
|
||||
if !compressed_romsave.is_empty() {
|
||||
let romsave_bytes = decompress_file(&compressed_romsave);
|
||||
ui.saves.romsave.0 = postcard::from_bytes(&romsave_bytes).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn decompress_file(input: &[u8]) -> Vec<u8> {
|
||||
let mut decompressed_file = Vec::new();
|
||||
{
|
||||
let mut reader = zip::ZipArchive::new(std::io::Cursor::new(input)).unwrap();
|
||||
let mut file = reader.by_index(0).unwrap();
|
||||
file.read_to_end(&mut decompressed_file).unwrap();
|
||||
}
|
||||
decompressed_file
|
||||
}
|
||||
|
||||
fn compress_file(input: &[u8]) -> Vec<u8> {
|
||||
let mut compressed_file = Vec::new();
|
||||
{
|
||||
let mut writer = zip::ZipWriter::new(std::io::Cursor::new(&mut compressed_file));
|
||||
writer
|
||||
.start_file(
|
||||
"save",
|
||||
zip::write::SimpleFileOptions::default()
|
||||
.compression_method(zip::CompressionMethod::Deflated),
|
||||
)
|
||||
.unwrap();
|
||||
writer.write_all(input).unwrap();
|
||||
}
|
||||
compressed_file
|
||||
}
|
||||
|
||||
fn write_rom_save(ui: &ui::Ui) {
|
||||
let data = postcard::to_stdvec(&ui.saves.romsave.0).unwrap();
|
||||
std::fs::write(ui.paths.romsave_file_path.clone(), data).unwrap();
|
||||
|
||||
@@ -37,7 +37,6 @@ pub fn init(device: &mut device::Device, fullscreen: bool) {
|
||||
VI_V_START_REG: &mut device.vi.regs[device::vi::VI_V_START_REG as usize],
|
||||
VI_X_SCALE_REG: &mut device.vi.regs[device::vi::VI_X_SCALE_REG as usize],
|
||||
VI_Y_SCALE_REG: &mut device.vi.regs[device::vi::VI_Y_SCALE_REG as usize],
|
||||
VI_WIDTH_REG: &mut device.vi.regs[device::vi::VI_WIDTH_REG as usize],
|
||||
};
|
||||
|
||||
unsafe {
|
||||
|
||||
+3
-3
@@ -4,14 +4,14 @@ use crate::ui;
|
||||
|
||||
pub fn prompt_for_match(
|
||||
words: &[String],
|
||||
window_notifier: &std::sync::mpsc::Sender<Vec<String>>,
|
||||
word_index_receiver: &std::sync::mpsc::Receiver<String>,
|
||||
window_notifier: &tokio::sync::mpsc::Sender<Vec<String>>,
|
||||
word_index_receiver: &mut tokio::sync::mpsc::Receiver<String>,
|
||||
gui_ctx: &egui::Context,
|
||||
) -> u16 {
|
||||
let mut dedup_words = words.to_owned();
|
||||
dedup_words.sort();
|
||||
dedup_words.dedup();
|
||||
window_notifier.send(dedup_words).unwrap();
|
||||
window_notifier.try_send(dedup_words).unwrap();
|
||||
gui_ctx.request_repaint(); // this is so the window pops up right away
|
||||
let mut result = word_index_receiver.try_recv();
|
||||
while result.is_err() {
|
||||
|
||||
Reference in New Issue
Block a user