Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe766efcdc | ||
|
|
acb8856dd0 | ||
|
|
e2c25cbae5 | ||
|
|
7d517e932e |
Generated
+540
-480
File diff suppressed because it is too large
Load Diff
+12
-12
@@ -4,24 +4,24 @@ description = "An emulator for the Virtual Boy."
|
||||
repository = "https://git.virtual-boy.com/PVB/lemur"
|
||||
publish = false
|
||||
license = "MIT"
|
||||
version = "0.15.0"
|
||||
version = "0.15.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
atoi = "3"
|
||||
audioadapter-buffers = "4"
|
||||
audioadapter-buffers = "5"
|
||||
atomic = "0.6"
|
||||
bitflags = { version = "2", features = ["serde"] }
|
||||
bytemuck = { version = "1", features = ["derive"] }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
cpal = "0.18"
|
||||
directories = "6"
|
||||
egui = { version = "0.34", features = ["persistence", "serde"] }
|
||||
egui_extras = { version = "0.34", features = ["image"] }
|
||||
egui-notify = "0.22"
|
||||
egui-winit = "0.34"
|
||||
egui-wgpu = { version = "0.34", features = ["winit"] }
|
||||
egui = { version = "0.36", features = ["persistence", "serde"] }
|
||||
egui_extras = { version = "0.36", features = ["image"] }
|
||||
egui-notify = "0.23"
|
||||
egui-winit = "0.36"
|
||||
egui-wgpu = { version = "0.36", features = ["winit"] }
|
||||
fxprof-processed-profile = "0.8"
|
||||
fixed = { version = "1.28", features = ["num-traits"] }
|
||||
gilrs = { version = "0.11", features = ["serde-serialize"] }
|
||||
@@ -31,22 +31,22 @@ image = { version = "0.25", default-features = false, features = ["png"] }
|
||||
itertools = "0.15"
|
||||
normpath = "1"
|
||||
notify = "8"
|
||||
num-derive = "0.4"
|
||||
num-derive = "0.5"
|
||||
num-traits = "0.2"
|
||||
object = "0.39"
|
||||
object = "0.40"
|
||||
oneshot = { version = "0.2", features = ["async", "std"] }
|
||||
pollster = "1"
|
||||
rand = "0.10"
|
||||
rfd = "0.17"
|
||||
rtrb = "0.3"
|
||||
rubato = "4"
|
||||
rtrb = "0.4"
|
||||
rubato = "5"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
thread-priority = "3"
|
||||
tokio = { version = "1", features = ["io-util", "macros", "net", "rt", "sync", "time"] }
|
||||
tracing = { version = "0.1", features = ["release_max_level_debug"] }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
wgpu = { version = "29", features = ["serde"] }
|
||||
wgpu = { version = "30", features = ["serde"] }
|
||||
wholesym = "0.8"
|
||||
winit = { version = "0.30", features = ["serde"] }
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ RUN apt-get update && \
|
||||
ln -s $(which ld64.lld-22) /usr/bin/ld64.lld && \
|
||||
SDK_VERSION=14.5 UNATTENDED=1 ENABLE_COMPILER_RT_INSTALL=1 TARGET_DIR=/osxcross ./build.sh
|
||||
|
||||
FROM rust:1.97-trixie
|
||||
FROM rust:1.98-trixie
|
||||
ADD --chmod=644 "https://apt.llvm.org/llvm-snapshot.gpg.key" /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||
RUN rustup target add x86_64-pc-windows-msvc && \
|
||||
|
||||
+6
-4
@@ -26,10 +26,10 @@ use crate::{
|
||||
config::{AppConfig, CliArgs},
|
||||
controller::ControllerManager,
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||
filesystem::Persistence,
|
||||
images::ImageTextureLoader,
|
||||
input::{MappingProvider, ShortcutProvider},
|
||||
memory::MemoryClient,
|
||||
persistence::Persistence,
|
||||
window::{AppWindow, ChildWindow, GameScreen, GameWindow, InitArgs},
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ impl SharedViewportState {
|
||||
fn init_painter(&mut self, ctx: &Context, window: &Window) -> &mut Painter {
|
||||
if self.painter.is_none() {
|
||||
let wgpu_config = egui_wgpu::WgpuConfiguration {
|
||||
present_mode: wgpu::PresentMode::AutoVsync,
|
||||
surface: egui_wgpu::SurfaceConfig::HIGH_THROUGHPUT,
|
||||
wgpu_setup: egui_wgpu::WgpuSetup::Existing(self.wgpu.init(window)),
|
||||
..egui_wgpu::WgpuConfiguration::default()
|
||||
};
|
||||
@@ -257,7 +257,7 @@ impl Application {
|
||||
continue;
|
||||
}
|
||||
input.viewports = self.shared.viewport_info.clone();
|
||||
let output = self.ctx.run_ui(input, |ui| {
|
||||
let mut output = self.ctx.run_ui(input, |ui| {
|
||||
if viewport.id == ViewportId::ROOT {
|
||||
self.app.show(ui);
|
||||
} else if let Some(cb) = ui.viewport(|v| v.viewport_ui_cb.clone()) {
|
||||
@@ -304,8 +304,9 @@ impl Application {
|
||||
output.pixels_per_point,
|
||||
[0.0, 0.0, 0.0, 0.0],
|
||||
&clipped_primitives,
|
||||
&output.textures_delta,
|
||||
&mut output.textures_delta,
|
||||
vec![],
|
||||
&viewport.window,
|
||||
);
|
||||
}
|
||||
let mut active_viewports = ViewportIdSet::default();
|
||||
@@ -550,6 +551,7 @@ impl WgpuState {
|
||||
power_preference,
|
||||
compatible_surface: Some(&surface),
|
||||
force_fallback_adapter,
|
||||
apply_limit_buckets: false,
|
||||
}))
|
||||
.expect("could not create adapter");
|
||||
debug!("selected adapter: {:?}", adapter.get_info());
|
||||
|
||||
+25
-1
@@ -1,9 +1,10 @@
|
||||
use anyhow::Result;
|
||||
use bytemuck::NoUninit;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use egui::{Color32, Pos2, Vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{emulator::SimId, persistence::Persistence, window::DisplayMode};
|
||||
use crate::{emulator::SimId, filesystem::Persistence, window::DisplayMode};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser)]
|
||||
@@ -53,6 +54,9 @@ pub struct CliArgs {
|
||||
/// Set a preference for whether to use a low-power or high-performance GPU adapter
|
||||
#[arg(long)]
|
||||
pub wgpu_power_preference: Option<PowerPreferenceWrapper>,
|
||||
/// Choose whether save files are kept in the rom or the data directory
|
||||
#[arg(long)]
|
||||
pub save_data_location: Option<SaveDataLocation>,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone, Copy)]
|
||||
@@ -90,12 +94,27 @@ const fn default_power_preference() -> wgpu::PowerPreference {
|
||||
wgpu::PowerPreference::LowPower
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, ValueEnum, Debug, NoUninit)]
|
||||
#[repr(usize)]
|
||||
pub enum SaveDataLocation {
|
||||
/// The same directory as the ROM
|
||||
RomDirectory,
|
||||
/// This application's data directory
|
||||
DataDirectory,
|
||||
}
|
||||
|
||||
const fn default_save_data_location() -> SaveDataLocation {
|
||||
SaveDataLocation::RomDirectory
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub struct AppConfig {
|
||||
#[serde(default = "default_power_preference")]
|
||||
pub power_preference: wgpu::PowerPreference,
|
||||
#[serde(default)]
|
||||
pub force_fallback: bool,
|
||||
#[serde(default = "default_save_data_location")]
|
||||
pub save_data_location: SaveDataLocation,
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
@@ -106,6 +125,7 @@ impl AppConfig {
|
||||
Self {
|
||||
power_preference: default_power_preference(),
|
||||
force_fallback: false,
|
||||
save_data_location: default_save_data_location(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +143,10 @@ impl AppConfig {
|
||||
self.force_fallback = force_fallback;
|
||||
updated = true;
|
||||
}
|
||||
if let Some(save_data_location) = args.save_data_location {
|
||||
self.save_data_location = save_data_location;
|
||||
updated = true;
|
||||
}
|
||||
updated
|
||||
}
|
||||
}
|
||||
|
||||
+72
-44
@@ -18,6 +18,7 @@ use tracing::{error, warn};
|
||||
|
||||
use crate::{
|
||||
audio::Audio,
|
||||
config::SaveDataLocation,
|
||||
graphics::TextureSink,
|
||||
memory::{MemoryRange, MemoryRegion},
|
||||
};
|
||||
@@ -74,12 +75,13 @@ pub struct EmulatorBuilder {
|
||||
state: Arc<Atomic<EmulatorState>>,
|
||||
audio_on: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
save_data_location: Arc<Atomic<SaveDataLocation>>,
|
||||
start_paused: bool,
|
||||
watch_rom: Arc<[AtomicBool; 2]>,
|
||||
}
|
||||
|
||||
impl EmulatorBuilder {
|
||||
pub fn new() -> (Self, EmulatorClient) {
|
||||
pub fn new(save_data_location: SaveDataLocation) -> (Self, EmulatorClient) {
|
||||
let (queue, commands) = mpsc::channel();
|
||||
let builder = Self {
|
||||
rom: None,
|
||||
@@ -91,6 +93,7 @@ impl EmulatorBuilder {
|
||||
state: Arc::new(Atomic::new(EmulatorState::Paused)),
|
||||
audio_on: Arc::new([AtomicBool::new(true), AtomicBool::new(true)]),
|
||||
linked: Arc::new(AtomicBool::new(false)),
|
||||
save_data_location: Arc::new(Atomic::new(save_data_location)),
|
||||
start_paused: false,
|
||||
watch_rom: Arc::new([AtomicBool::new(false), AtomicBool::new(false)]),
|
||||
};
|
||||
@@ -98,8 +101,9 @@ impl EmulatorBuilder {
|
||||
queue,
|
||||
sim_state: builder.sim_state.clone(),
|
||||
state: builder.state.clone(),
|
||||
watch_rom: builder.watch_rom.clone(),
|
||||
linked: builder.linked.clone(),
|
||||
save_data_location: builder.save_data_location.clone(),
|
||||
watch_rom: builder.watch_rom.clone(),
|
||||
};
|
||||
(builder, client)
|
||||
}
|
||||
@@ -131,18 +135,42 @@ impl EmulatorBuilder {
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<Emulator> {
|
||||
let mut emulator = Emulator::new(
|
||||
self.commands,
|
||||
self.sim_state,
|
||||
self.state,
|
||||
self.audio_on,
|
||||
self.watch_rom,
|
||||
self.linked,
|
||||
);
|
||||
if let Some(path) = self.rom {
|
||||
let Self {
|
||||
rom,
|
||||
commands,
|
||||
sim_state,
|
||||
state,
|
||||
audio_on,
|
||||
watch_rom,
|
||||
linked,
|
||||
save_data_location,
|
||||
start_paused,
|
||||
} = self;
|
||||
let mut emulator = Emulator {
|
||||
sims: vec![],
|
||||
carts: [None, None],
|
||||
audio: Audio::init(),
|
||||
commands,
|
||||
sim_state,
|
||||
state,
|
||||
audio_on,
|
||||
watch_rom,
|
||||
linked,
|
||||
save_data_location,
|
||||
profilers: [None, None],
|
||||
renderers: HashMap::new(),
|
||||
messages: HashMap::new(),
|
||||
debuggers: HashMap::new(),
|
||||
stdouts: HashMap::new(),
|
||||
watched_regions: HashMap::new(),
|
||||
eye_contents: [vec![0u8; 384 * 224 * 2], vec![0u8; 384 * 224 * 2]],
|
||||
audio_samples: Vec::with_capacity(EXPECTED_FRAME_SIZE),
|
||||
buffer: vec![],
|
||||
};
|
||||
if let Some(path) = rom {
|
||||
emulator.load_cart(SimId::Player1, &path)?;
|
||||
}
|
||||
if self.start_paused {
|
||||
if start_paused {
|
||||
emulator.pause_sims()?;
|
||||
}
|
||||
Ok(emulator)
|
||||
@@ -159,6 +187,7 @@ pub struct Emulator {
|
||||
audio_on: Arc<[AtomicBool; 2]>,
|
||||
watch_rom: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
save_data_location: Arc<Atomic<SaveDataLocation>>,
|
||||
profilers: [Option<ProfileSender>; 2],
|
||||
renderers: HashMap<SimId, TextureSink>,
|
||||
messages: HashMap<SimId, mpsc::Sender<Toast>>,
|
||||
@@ -171,36 +200,6 @@ pub struct Emulator {
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
fn new(
|
||||
commands: mpsc::Receiver<EmulatorCommand>,
|
||||
sim_state: Arc<[Atomic<SimState>; 2]>,
|
||||
state: Arc<Atomic<EmulatorState>>,
|
||||
audio_on: Arc<[AtomicBool; 2]>,
|
||||
watch_rom: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
) -> Self {
|
||||
Self {
|
||||
sims: vec![],
|
||||
carts: [None, None],
|
||||
audio: Audio::init(),
|
||||
commands,
|
||||
sim_state,
|
||||
state,
|
||||
audio_on,
|
||||
watch_rom,
|
||||
linked,
|
||||
profilers: [None, None],
|
||||
renderers: HashMap::new(),
|
||||
messages: HashMap::new(),
|
||||
debuggers: HashMap::new(),
|
||||
stdouts: HashMap::new(),
|
||||
watched_regions: HashMap::new(),
|
||||
eye_contents: [vec![0u8; 384 * 224 * 2], vec![0u8; 384 * 224 * 2]],
|
||||
audio_samples: Vec::with_capacity(EXPECTED_FRAME_SIZE),
|
||||
buffer: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reload_cart(&mut self, sim_id: SimId) -> Result<()> {
|
||||
let Some(cart) = &self.carts[sim_id.to_index()] else {
|
||||
return Ok(());
|
||||
@@ -211,7 +210,12 @@ impl Emulator {
|
||||
|
||||
pub fn load_cart(&mut self, sim_id: SimId, path: &Path) -> Result<()> {
|
||||
let watch = self.watch_rom[sim_id.to_index()].load(Ordering::Acquire);
|
||||
let cart = Cart::load(path, sim_id, watch)?;
|
||||
let cart = Cart::load(
|
||||
path,
|
||||
sim_id,
|
||||
self.save_data_location.load(Ordering::Acquire),
|
||||
watch,
|
||||
)?;
|
||||
self.try_reset_sim(sim_id, Some(cart))?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -224,7 +228,12 @@ impl Emulator {
|
||||
};
|
||||
let watch = self.watch_rom[SimId::Player2.to_index()].load(Ordering::Acquire);
|
||||
let cart = match file_path {
|
||||
Some(rom_path) => Some(Cart::load(&rom_path, SimId::Player2, watch)?),
|
||||
Some(rom_path) => Some(Cart::load(
|
||||
&rom_path,
|
||||
SimId::Player2,
|
||||
self.save_data_location.load(Ordering::Acquire),
|
||||
watch,
|
||||
)?),
|
||||
None => None,
|
||||
};
|
||||
self.try_reset_sim(SimId::Player2, cart)?;
|
||||
@@ -687,6 +696,20 @@ impl Emulator {
|
||||
cart.stop_watching();
|
||||
}
|
||||
}
|
||||
EmulatorCommand::SetSaveDataLocation(save_data_location) => {
|
||||
self.save_data_location
|
||||
.store(save_data_location, Ordering::Release);
|
||||
for sim_id in SimId::values() {
|
||||
if let Some(cart) = self.carts[sim_id.to_index()].as_mut()
|
||||
&& let Err(error) = cart.change_save_data_location(save_data_location)
|
||||
{
|
||||
self.report_error(
|
||||
sim_id,
|
||||
format!("Error changing save data location: {error}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
EmulatorCommand::StartSecondSim(path) => {
|
||||
if let Err(error) = self.start_second_sim(path) {
|
||||
self.report_error(
|
||||
@@ -854,6 +877,7 @@ pub enum EmulatorCommand {
|
||||
LoadGame(SimId, PathBuf),
|
||||
ReloadRom(SimId),
|
||||
WatchRom(SimId, bool),
|
||||
SetSaveDataLocation(SaveDataLocation),
|
||||
StartSecondSim(Option<PathBuf>),
|
||||
StopSecondSim,
|
||||
Pause,
|
||||
@@ -943,6 +967,7 @@ pub struct EmulatorClient {
|
||||
sim_state: Arc<[Atomic<SimState>; 2]>,
|
||||
state: Arc<Atomic<EmulatorState>>,
|
||||
linked: Arc<AtomicBool>,
|
||||
save_data_location: Arc<Atomic<SaveDataLocation>>,
|
||||
watch_rom: Arc<[AtomicBool; 2]>,
|
||||
}
|
||||
|
||||
@@ -959,6 +984,9 @@ impl EmulatorClient {
|
||||
pub fn are_sims_linked(&self) -> bool {
|
||||
self.linked.load(Ordering::Acquire)
|
||||
}
|
||||
pub fn save_data_location(&self) -> SaveDataLocation {
|
||||
self.save_data_location.load(Ordering::Acquire)
|
||||
}
|
||||
pub fn is_rom_watched(&self, sim_id: SimId) -> bool {
|
||||
self.watch_rom[sim_id.to_index()].load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
+39
-7
@@ -8,10 +8,15 @@ use std::{
|
||||
sync::{Arc, atomic::AtomicBool},
|
||||
};
|
||||
|
||||
use crate::emulator::{SimId, game_info::GameInfo, shrooms_vb_util::rom_from_isx};
|
||||
use crate::{
|
||||
config::SaveDataLocation,
|
||||
emulator::{SimId, game_info::GameInfo, shrooms_vb_util::rom_from_isx},
|
||||
filesystem,
|
||||
};
|
||||
|
||||
pub struct Cart {
|
||||
pub file_path: PathBuf,
|
||||
sim_id: SimId,
|
||||
pub rom: Vec<u8>,
|
||||
sram_file: File,
|
||||
pub sram: Vec<u8>,
|
||||
@@ -21,7 +26,12 @@ pub struct Cart {
|
||||
}
|
||||
|
||||
impl Cart {
|
||||
pub fn load(file_path: &Path, sim_id: SimId, watch: bool) -> Result<Self> {
|
||||
pub fn load(
|
||||
file_path: &Path,
|
||||
sim_id: SimId,
|
||||
save_data_location: SaveDataLocation,
|
||||
watch: bool,
|
||||
) -> Result<Self> {
|
||||
let (rom, info) = Self::read_rom(file_path)?;
|
||||
|
||||
let mut sram_file = File::options()
|
||||
@@ -29,7 +39,7 @@ impl Cart {
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(false)
|
||||
.open(sram_path(file_path, sim_id))?;
|
||||
.open(sram_path(file_path, sim_id, save_data_location))?;
|
||||
|
||||
let sram = if sram_file.metadata()?.len() == 0 {
|
||||
// new SRAM file, randomize the contents
|
||||
@@ -54,6 +64,7 @@ impl Cart {
|
||||
|
||||
Ok(Cart {
|
||||
file_path: file_path.to_path_buf(),
|
||||
sim_id,
|
||||
rom,
|
||||
sram_file,
|
||||
sram,
|
||||
@@ -73,6 +84,19 @@ impl Cart {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn change_save_data_location(
|
||||
&mut self,
|
||||
save_data_location: SaveDataLocation,
|
||||
) -> Result<()> {
|
||||
self.sram_file = File::options()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(false)
|
||||
.open(sram_path(&self.file_path, self.sim_id, save_data_location))?;
|
||||
self.save_sram()
|
||||
}
|
||||
|
||||
pub fn save_sram(&mut self) -> Result<()> {
|
||||
self.sram_file.seek(SeekFrom::Start(0))?;
|
||||
self.sram_file.write_all(&self.sram)?;
|
||||
@@ -177,9 +201,17 @@ fn parse_elf_program<Elf: object::read::elf::FileHeader<Endian = object::Endiann
|
||||
Some(bytes)
|
||||
}
|
||||
|
||||
fn sram_path(file_path: &Path, sim_id: SimId) -> PathBuf {
|
||||
match sim_id {
|
||||
SimId::Player1 => file_path.with_extension("p1.sram"),
|
||||
SimId::Player2 => file_path.with_extension("p2.sram"),
|
||||
fn sram_path(file_path: &Path, sim_id: SimId, save_data_location: SaveDataLocation) -> PathBuf {
|
||||
let extension = match sim_id {
|
||||
SimId::Player1 => "p1.sram",
|
||||
SimId::Player2 => "p2.sram",
|
||||
};
|
||||
if let SaveDataLocation::DataDirectory = save_data_location
|
||||
&& let Some(data_dir) = filesystem::init_data_dir()
|
||||
&& let Some(rom_name) = file_path.file_name()
|
||||
{
|
||||
data_dir.join(rom_name).with_extension(extension)
|
||||
} else {
|
||||
file_path.with_extension(extension)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use directories::ProjectDirs;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Persistence {
|
||||
config_dir: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Persistence {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
config_dir: init_config_dir(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_config<T: Serialize>(&self, file: &str, data: &T) -> Result<()> {
|
||||
if let Some(config_dir) = self.config_dir.as_ref() {
|
||||
let bytes = serde_json::to_vec_pretty(data)?;
|
||||
let filename = config_dir.join(file).with_extension("json");
|
||||
fs::write(&filename, bytes)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_config<T: for<'a> Deserialize<'a>>(&self, file: &str) -> Result<T> {
|
||||
let Some(config_dir) = self.config_dir.as_ref() else {
|
||||
bail!("config directory not found");
|
||||
};
|
||||
let filename = config_dir.join(file).with_extension("json");
|
||||
let bytes = fs::read(filename)?;
|
||||
Ok(serde_json::from_slice(&bytes)?)
|
||||
}
|
||||
}
|
||||
|
||||
fn init_config_dir() -> Option<PathBuf> {
|
||||
let config_dir = project_dirs()?.config_dir().to_path_buf();
|
||||
fs::create_dir_all(&config_dir).ok()?;
|
||||
Some(config_dir)
|
||||
}
|
||||
|
||||
pub fn init_data_dir() -> Option<PathBuf> {
|
||||
let data_dir = project_dirs()?.data_dir().to_path_buf();
|
||||
fs::create_dir_all(&data_dir).ok()?;
|
||||
Some(data_dir)
|
||||
}
|
||||
|
||||
fn project_dirs() -> Option<ProjectDirs> {
|
||||
ProjectDirs::from("com", "virtual-boy", "Lemur")
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
|
||||
use crate::{
|
||||
emulator::{SimId, VBKey},
|
||||
persistence::Persistence,
|
||||
filesystem::Persistence,
|
||||
};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
|
||||
+11
-15
@@ -15,7 +15,7 @@ use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use crate::{
|
||||
config::{AppConfig, CliArgs, SimConfig},
|
||||
emulator::SimId,
|
||||
persistence::Persistence,
|
||||
filesystem::Persistence,
|
||||
};
|
||||
|
||||
mod app;
|
||||
@@ -24,12 +24,12 @@ mod config;
|
||||
mod controller;
|
||||
mod emulator;
|
||||
mod filepicker;
|
||||
mod filesystem;
|
||||
mod gdbserver;
|
||||
mod graphics;
|
||||
mod images;
|
||||
mod input;
|
||||
mod memory;
|
||||
mod persistence;
|
||||
mod profiler;
|
||||
mod window;
|
||||
|
||||
@@ -60,14 +60,9 @@ fn set_panic_handler() {
|
||||
|
||||
eprint!("{message}");
|
||||
|
||||
let Some(project_dirs) = directories::ProjectDirs::from("com", "virtual-boy", "Lemur")
|
||||
else {
|
||||
let Some(data_dir) = filesystem::init_data_dir() else {
|
||||
return;
|
||||
};
|
||||
let data_dir = project_dirs.data_dir();
|
||||
if std::fs::create_dir_all(data_dir).is_err() {
|
||||
return;
|
||||
}
|
||||
let timestamp = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
@@ -98,7 +93,14 @@ fn main() -> Result<()> {
|
||||
|
||||
let persistence = Persistence::new();
|
||||
|
||||
let (mut builder, client) = EmulatorBuilder::new();
|
||||
let mut config = AppConfig::load(&persistence);
|
||||
if config.update(&args) {
|
||||
let _ = config.save(&persistence);
|
||||
}
|
||||
let p1 = SimConfig::load(&persistence, SimId::Player1);
|
||||
let p2 = SimConfig::load(&persistence, SimId::Player2);
|
||||
|
||||
let (mut builder, client) = EmulatorBuilder::new(config.save_data_location);
|
||||
if let Some(path) = &args.rom {
|
||||
builder = builder.with_rom(path);
|
||||
}
|
||||
@@ -111,12 +113,6 @@ fn main() -> Result<()> {
|
||||
if args.profile {
|
||||
builder = builder.start_paused(true)
|
||||
}
|
||||
let mut config = AppConfig::load(&persistence);
|
||||
if config.update(&args) {
|
||||
let _ = config.save(&persistence);
|
||||
}
|
||||
let p1 = SimConfig::load(&persistence, SimId::Player1);
|
||||
let p2 = SimConfig::load(&persistence, SimId::Player2);
|
||||
|
||||
let watch = args.watch;
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use directories::ProjectDirs;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Persistence {
|
||||
dirs: Option<Dirs>,
|
||||
}
|
||||
|
||||
impl Persistence {
|
||||
pub fn new() -> Self {
|
||||
Self { dirs: init_dirs() }
|
||||
}
|
||||
|
||||
pub fn save_config<T: Serialize>(&self, file: &str, data: &T) -> Result<()> {
|
||||
if let Some(dirs) = self.dirs.as_ref() {
|
||||
let bytes = serde_json::to_vec_pretty(data)?;
|
||||
let filename = dirs.config_dir.join(file).with_extension("json");
|
||||
fs::write(&filename, bytes)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_config<T: for<'a> Deserialize<'a>>(&self, file: &str) -> Result<T> {
|
||||
let Some(dirs) = self.dirs.as_ref() else {
|
||||
bail!("config directory not found");
|
||||
};
|
||||
let filename = dirs.config_dir.join(file).with_extension("json");
|
||||
let bytes = fs::read(filename)?;
|
||||
Ok(serde_json::from_slice(&bytes)?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Dirs {
|
||||
config_dir: PathBuf,
|
||||
}
|
||||
|
||||
fn init_dirs() -> Option<Dirs> {
|
||||
let dirs = ProjectDirs::from("com", "virtual-boy", "Lemur")?;
|
||||
let config_dir = dirs.config_dir().to_path_buf();
|
||||
fs::create_dir_all(&config_dir).ok()?;
|
||||
Some(Dirs { config_dir })
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ impl AppWindow for AboutWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.label("Lemur Virtual Boy Emulator");
|
||||
ui.label(format!("Version {}", env!("CARGO_PKG_VERSION")));
|
||||
|
||||
+38
-9
@@ -7,13 +7,13 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
app::UserEvent,
|
||||
config::{COLOR_PRESETS, SimConfig},
|
||||
config::{AppConfig, COLOR_PRESETS, SaveDataLocation, SimConfig},
|
||||
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId, SimState},
|
||||
filepicker::FilePicker,
|
||||
filesystem::Persistence,
|
||||
images::ImageTextureLoader,
|
||||
input::{Command, MappingProvider, ShortcutProvider},
|
||||
memory::MemoryClient,
|
||||
persistence::Persistence,
|
||||
window::{
|
||||
AboutWindow, BgMapWindow, CharacterDataWindow, FrameBufferWindow, GdbServerWindow,
|
||||
HotkeysWindow, InitArgs, InputWindow, ObjectWindow, ProfileWindow, RegisterWindow,
|
||||
@@ -604,6 +604,37 @@ impl GameWindow {
|
||||
if ui.button("Hotkeys").clicked() {
|
||||
self.open(ChildWindow::Hotkeys);
|
||||
}
|
||||
ui.menu_button("Save Data Location", |ui| {
|
||||
let save_data_location = self.client.save_data_location();
|
||||
let update_save_data_location = |new_location: SaveDataLocation| {
|
||||
if new_location == save_data_location {
|
||||
return;
|
||||
};
|
||||
let mut app_config = AppConfig::load(&self.persistence);
|
||||
app_config.save_data_location = new_location;
|
||||
let _ = app_config.save(&self.persistence);
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetSaveDataLocation(new_location));
|
||||
};
|
||||
if ui
|
||||
.selectable_button(
|
||||
save_data_location == SaveDataLocation::RomDirectory,
|
||||
"Same Directory as ROM",
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
update_save_data_location(SaveDataLocation::RomDirectory);
|
||||
}
|
||||
if ui
|
||||
.selectable_button(
|
||||
save_data_location == SaveDataLocation::DataDirectory,
|
||||
"App Data Directory",
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
update_save_data_location(SaveDataLocation::DataDirectory);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn show_color_picker(&mut self, ui: &mut Ui) {
|
||||
@@ -708,13 +739,11 @@ impl AppWindow for GameWindow {
|
||||
while let Ok(toast) = self.messages.try_recv() {
|
||||
self.toasts.add(toast);
|
||||
}
|
||||
Panel::top("menubar")
|
||||
.exact_size(22.0)
|
||||
.show_inside(ui, |ui| {
|
||||
MenuBar::new().ui(ui, |ui| {
|
||||
self.show_menu(ui);
|
||||
});
|
||||
Panel::top("menubar").exact_size(22.0).show(ui, |ui| {
|
||||
MenuBar::new().ui(ui, |ui| {
|
||||
self.show_menu(ui);
|
||||
});
|
||||
});
|
||||
if self.color_picker.is_some() {
|
||||
Window::new("Color Picker")
|
||||
.title_bar(false)
|
||||
@@ -725,7 +754,7 @@ impl AppWindow for GameWindow {
|
||||
});
|
||||
}
|
||||
let frame = Frame::central_panel(ui.style()).fill(Color32::BLACK);
|
||||
CentralPanel::default().frame(frame).show_inside(ui, |ui| {
|
||||
CentralPanel::default().frame(frame).show(ui, |ui| {
|
||||
if let Some(screen) = self.screen.as_mut() {
|
||||
screen.update(self.config.display_mode, self.config.colors);
|
||||
ui.add(screen);
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ impl AppWindow for GdbServerWindow {
|
||||
fn show(&mut self, ui: &mut egui::Ui) {
|
||||
let port_num: Option<u16> = self.port_str.parse().ok();
|
||||
let status = self.server.status();
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if port_num.is_none() {
|
||||
let style = ui.style_mut();
|
||||
|
||||
@@ -131,7 +131,7 @@ impl AppWindow for HotkeysWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Use defaults").clicked() {
|
||||
self.shortcuts.reset();
|
||||
|
||||
+3
-3
@@ -70,7 +70,7 @@ impl InputWindow {
|
||||
.column(Column::remainder())
|
||||
.cell_layout(Layout::left_to_right(egui::Align::Center))
|
||||
.body(|mut body| {
|
||||
for keys in KEY_NAMES.chunks_exact(2) {
|
||||
for keys in KEY_NAMES.as_chunks::<2>().0 {
|
||||
body.row(20.0, |mut row| {
|
||||
for (key, name) in keys {
|
||||
let binding = names.remove(key).map(|mut s| {
|
||||
@@ -167,7 +167,7 @@ impl AppWindow for InputWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
Panel::top("options").show_inside(ui, |ui| {
|
||||
Panel::top("options").show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let old_active_tab = self.active_tab;
|
||||
ui.selectable_value(&mut self.active_tab, InputTab::Player1, "Player 1");
|
||||
@@ -182,7 +182,7 @@ impl AppWindow for InputWindow {
|
||||
}
|
||||
});
|
||||
});
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
match self.active_tab {
|
||||
InputTab::Player1 => self.show_key_bindings(ui, SimId::Player1),
|
||||
InputTab::Player2 => self.show_key_bindings(ui, SimId::Player2),
|
||||
|
||||
@@ -94,7 +94,7 @@ impl AppWindow for ProfileWindow {
|
||||
fn show(&mut self, ui: &mut egui::Ui) {
|
||||
let status = self.profiler.status();
|
||||
let recording = matches!(status, ProfilerStatus::Recording);
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.add(
|
||||
|
||||
@@ -54,7 +54,7 @@ impl AppWindow for TerminalWindow {
|
||||
}
|
||||
self.lines.back_mut().unwrap().push_str(rest);
|
||||
}
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ScrollArea::vertical()
|
||||
.stick_to_bottom(true)
|
||||
.auto_shrink([false, false])
|
||||
|
||||
@@ -203,7 +203,7 @@ impl AppWindow for BgMapWindow {
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.state.load(ui);
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::relative(0.3).at_most(200.0))
|
||||
|
||||
@@ -263,7 +263,7 @@ impl AppWindow for CharacterDataWindow {
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.state.load(ui);
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::relative(0.3).at_most(200.0))
|
||||
|
||||
@@ -163,7 +163,7 @@ impl AppWindow for FrameBufferWindow {
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.state.load(ui);
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::relative(0.3).at_most(200.0))
|
||||
|
||||
@@ -219,7 +219,7 @@ impl AppWindow for ObjectWindow {
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.state.load(ui);
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::relative(0.3).at_most(200.0))
|
||||
|
||||
@@ -641,7 +641,7 @@ impl AppWindow for RegisterWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ScrollArea::vertical().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
let width = ui.available_width();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use egui::{Color32, Image, ImageSource, Response, Sense, TextureOptions, Ui, Widget};
|
||||
|
||||
pub const GENERIC_PALETTE: [u8; 4] = [0, 32, 64, 128];
|
||||
const COLOR_TRANSPARENT: Color32 = Color32::from_rgb(0x25, 0x25, 0x25);
|
||||
|
||||
pub fn shade(brt: u8, color: Color32) -> Color32 {
|
||||
let corrected = if brt > 132 {
|
||||
@@ -44,7 +45,9 @@ pub fn parse_brts(brts: &[u16; 3], color: Color32) -> [Color32; 4] {
|
||||
|
||||
pub fn palette_colors(palette: u8, brts: &[u8; 8], color: Color32) -> [Color32; 4] {
|
||||
let colors = parse_shades(brts).map(|s| shade(s, color));
|
||||
parse_palette(palette).map(|p| colors[p as usize])
|
||||
let mut palette_colors = parse_palette(palette).map(|p| colors[p as usize]);
|
||||
palette_colors[0] = COLOR_TRANSPARENT;
|
||||
palette_colors
|
||||
}
|
||||
|
||||
pub struct Object {
|
||||
|
||||
@@ -539,7 +539,7 @@ impl AppWindow for WorldWindow {
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.state.load(ui);
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
StripBuilder::new(ui)
|
||||
.size(Size::relative(0.3).at_most(200.0))
|
||||
|
||||
Reference in New Issue
Block a user