Compare commits
13
Commits
a6c12a986c
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55d3cf737d | ||
|
|
36cfd961da | ||
|
|
9bcd99e437 | ||
|
|
f17d62876b | ||
|
|
4004047d68 | ||
|
|
e8fb942896 | ||
|
|
53cda2e515 | ||
|
|
1935d116ca | ||
|
|
fe766efcdc | ||
|
|
acb8856dd0 | ||
|
|
e2c25cbae5 | ||
|
|
7d517e932e | ||
|
|
ec7a89d9da |
Generated
+674
-618
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.14.0"
|
||||
version = "0.15.2"
|
||||
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"] }
|
||||
|
||||
|
||||
+13
-13
@@ -10,30 +10,30 @@ RUN apt-get update && \
|
||||
apt-get install -y ca-certificates
|
||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||
RUN apt-get update && \
|
||||
apt-get install -y bash bzip2 clang-22 git lld-22 llvm-22 make patch xz-utils && \
|
||||
ln -s $(which clang-22) /usr/bin/clang && \
|
||||
ln -s $(which clang++-22) /usr/bin/clang++ && \
|
||||
ln -s $(which ld64.lld-22) /usr/bin/ld64.lld && \
|
||||
apt-get install -y bash bzip2 clang-23 git lld-23 llvm-23 make patch xz-utils && \
|
||||
ln -s $(which clang-23) /usr/bin/clang && \
|
||||
ln -s $(which clang++-23) /usr/bin/clang++ && \
|
||||
ln -s $(which ld64.lld-23) /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.99-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 && \
|
||||
rustup target add x86_64-apple-darwin && \
|
||||
rustup target add aarch64-apple-darwin && \
|
||||
apt-get update && \
|
||||
apt-get install -y clang-22 lld-22 libc6-dev libasound2-dev libudev-dev genisoimage mingw-w64 && \
|
||||
apt-get install -y clang-23 lld-23 libc6-dev libasound2-dev libudev-dev genisoimage mingw-w64 && \
|
||||
cargo install cargo-bundle xwin && \
|
||||
xwin --accept-license splat --output xwin && \
|
||||
rm -rf .xwin-cache && \
|
||||
ln -s $(which clang-22) /usr/bin/clang && \
|
||||
ln -s $(which clang++-22) /usr/bin/clang++
|
||||
ln -s $(which clang-23) /usr/bin/clang && \
|
||||
ln -s $(which clang++-23) /usr/bin/clang++
|
||||
COPY --from=osxcross /osxcross /osxcross
|
||||
|
||||
ENV PATH="/osxcross/bin:$PATH" \
|
||||
LD_LIBRARY_PATH="/osxcross/lib" \
|
||||
CC="clang-22" CXX="clang++-22" AR="llvm-ar-22" \
|
||||
CC="clang-23" CXX="clang++-23" AR="llvm-ar-23" \
|
||||
CC_x86_64-apple-darwin="o64-clang" \
|
||||
CXX_x86_64-apple-darwin="o64-clang++" \
|
||||
CC_aarch64-apple-darwin="oa64-clang" \
|
||||
@@ -43,11 +43,11 @@ ENV PATH="/osxcross/bin:$PATH" \
|
||||
SHROOMS_CFLAGS_x86_64-pc-windows-msvc="-flto" \
|
||||
CFLAGS_x86_64-pc-windows-msvc="-I/xwin/crt/include -I/xwin/sdk/include/ucrt -I/xwin/sdk/include/um -I/xwin/sdk/include/shared" \
|
||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-Lnative=/xwin/crt/lib/x86_64 -Lnative=/xwin/sdk/lib/um/x86_64 -Lnative=/xwin/sdk/lib/ucrt/x86_64 -Clinker-plugin-lto -Clink-arg=-fuse-ld=lld" \
|
||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link-22" \
|
||||
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link-23" \
|
||||
CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="o64-clang" \
|
||||
CARGO_TARGET_X86_64_APPLE_DARWIN_AR="llvm-ar-22" \
|
||||
CARGO_TARGET_X86_64_APPLE_DARWIN_AR="llvm-ar-23" \
|
||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER="oa64-clang" \
|
||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-22" \
|
||||
RC_PATH="llvm-rc-22" \
|
||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-23" \
|
||||
RC_PATH="llvm-rc-23" \
|
||||
MACOSX_DEPLOYMENT_TARGET="14.5"
|
||||
ENTRYPOINT ["bash"]
|
||||
|
||||
@@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.define("VB_DIRECT_FRAME", "on_frame")
|
||||
.define("VB_DIRECT_READ", "on_read")
|
||||
.define("VB_DIRECT_WRITE", "on_write")
|
||||
.define("VBU_REALLOC", "vbu_realloc_shim")
|
||||
.define("VBU_MEMMGR", "VBU_MEMMGR")
|
||||
.file(Path::new("shrooms-vb-core/core/vb.c"))
|
||||
.file(Path::new("shrooms-vb-core/util/isx.c"))
|
||||
.file(Path::new("shrooms-vb-core/util/vbu.c"))
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
Types: deb deb-src
|
||||
URIs: http://apt.llvm.org/trixie/
|
||||
Suites: llvm-toolchain-trixie-22
|
||||
Suites: llvm-toolchain-trixie-23
|
||||
Components: main
|
||||
|
||||
+1
-1
Submodule shrooms-vb-core updated: 31b7403252...6e9b727b31
+11
-8
@@ -23,13 +23,13 @@ use winit::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::{AppConfig, CliArgs},
|
||||
config::{AppConfig, CliArgs, Config},
|
||||
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()
|
||||
};
|
||||
@@ -94,7 +94,7 @@ impl Application {
|
||||
handle: OwnedDisplayHandle,
|
||||
persistence: Persistence,
|
||||
args: CliArgs,
|
||||
config: AppConfig,
|
||||
config: Config<AppConfig>,
|
||||
) -> Self {
|
||||
let wgpu = WgpuState::new(handle, config);
|
||||
let icon = load_icon().ok().map(Arc::new);
|
||||
@@ -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();
|
||||
@@ -503,11 +504,11 @@ impl ApplicationHandler<UserEvent> for Application {
|
||||
struct WgpuState {
|
||||
instance: wgpu::Instance,
|
||||
device_descriptor: Arc<dyn Fn(&wgpu::Adapter) -> wgpu::DeviceDescriptor<'static> + Send + Sync>,
|
||||
config: AppConfig,
|
||||
config: Config<AppConfig>,
|
||||
}
|
||||
|
||||
impl WgpuState {
|
||||
fn new(handle: OwnedDisplayHandle, config: AppConfig) -> Self {
|
||||
fn new(handle: OwnedDisplayHandle, config: Config<AppConfig>) -> Self {
|
||||
#[allow(unused_variables)]
|
||||
let egui_wgpu::WgpuSetupCreateNew {
|
||||
instance_descriptor: wgpu::InstanceDescriptor { backends, .. },
|
||||
@@ -530,6 +531,7 @@ impl WgpuState {
|
||||
}
|
||||
|
||||
fn init(&mut self, window: &Window) -> egui_wgpu::WgpuSetupExisting {
|
||||
self.config.refresh();
|
||||
let power_preference =
|
||||
wgpu::PowerPreference::from_env().unwrap_or(self.config.power_preference);
|
||||
debug!("power preference: {power_preference:?}");
|
||||
@@ -550,6 +552,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());
|
||||
|
||||
+40
-25
@@ -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};
|
||||
pub use crate::filesystem::Config;
|
||||
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,40 +94,53 @@ 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 {
|
||||
pub fn load(persistence: &Persistence) -> Self {
|
||||
if let Ok(config) = persistence.load_config(APP_CONFIG_FILENAME) {
|
||||
return config;
|
||||
}
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
power_preference: default_power_preference(),
|
||||
force_fallback: false,
|
||||
save_data_location: default_save_data_location(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load(persistence: &Persistence) -> Config<Self> {
|
||||
persistence.config(APP_CONFIG_FILENAME)
|
||||
}
|
||||
|
||||
pub fn save(&self, persistence: &Persistence) -> Result<()> {
|
||||
persistence.save_config(APP_CONFIG_FILENAME, &self)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, args: &CliArgs) -> bool {
|
||||
let mut updated = false;
|
||||
pub fn apply_updates(&mut self, args: &CliArgs) {
|
||||
if let Some(pref) = args.wgpu_power_preference {
|
||||
self.power_preference = pref.into();
|
||||
updated = true;
|
||||
}
|
||||
if let Some(force_fallback) = args.wgpu_force_fallback {
|
||||
self.force_fallback = force_fallback;
|
||||
updated = true;
|
||||
}
|
||||
updated
|
||||
if let Some(save_data_location) = args.save_data_location {
|
||||
self.save_data_location = save_data_location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,12 +164,8 @@ pub struct SimConfig {
|
||||
#[serde(default)]
|
||||
pub position: Option<Pos2>,
|
||||
}
|
||||
|
||||
impl SimConfig {
|
||||
pub fn load(persistence: &Persistence, sim_id: SimId) -> Self {
|
||||
if let Ok(config) = persistence.load_config(sim_config_filename(sim_id)) {
|
||||
return config;
|
||||
}
|
||||
impl Default for SimConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
display_mode: DisplayMode::Anaglyph,
|
||||
colors: COLOR_PRESETS[0],
|
||||
@@ -163,9 +176,11 @@ impl SimConfig {
|
||||
position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&self, persistence: &Persistence, sim_id: SimId) -> Result<()> {
|
||||
persistence.save_config(sim_config_filename(sim_id), self)
|
||||
impl SimConfig {
|
||||
pub fn load(persistence: &Persistence, sim_id: SimId) -> Config<Self> {
|
||||
persistence.config(sim_config_filename(sim_id))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+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)
|
||||
}
|
||||
}
|
||||
|
||||
+102
-11
@@ -1,13 +1,104 @@
|
||||
use std::ffi::c_void;
|
||||
use std::{
|
||||
ffi::c_void,
|
||||
sync::{LazyLock, Mutex},
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
struct Reallocator {
|
||||
allocations: Vec<Allocation>,
|
||||
}
|
||||
|
||||
unsafe impl Send for Reallocator {}
|
||||
|
||||
struct Allocation {
|
||||
ptr: *mut u8,
|
||||
size: usize,
|
||||
}
|
||||
impl Allocation {
|
||||
fn new(size: usize) -> Self {
|
||||
let layout = Self::layout(size);
|
||||
// SAFETY: our layout is not zero, not too big, and properly aligned
|
||||
let ptr = unsafe { std::alloc::alloc_zeroed(layout) };
|
||||
if ptr.is_null() {
|
||||
std::alloc::handle_alloc_error(layout);
|
||||
}
|
||||
Self { ptr, size }
|
||||
}
|
||||
|
||||
fn layout(size: usize) -> std::alloc::Layout {
|
||||
assert!(size != 0);
|
||||
std::alloc::Layout::from_size_align(size, 8).expect("far too large an allocation")
|
||||
}
|
||||
|
||||
fn as_slice(&self) -> &[u8] {
|
||||
// SAFETY: we allocated this ourselves, it's safe
|
||||
unsafe { std::slice::from_raw_parts(self.ptr, self.size) }
|
||||
}
|
||||
|
||||
fn as_mut_slice(&mut self) -> &mut [u8] {
|
||||
// SAFETY: we allocated this ourselves, it's safe
|
||||
unsafe { std::slice::from_raw_parts_mut(self.ptr, self.size) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Allocation {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: we allocated this ourselves with this layout, and it hasn't been freed
|
||||
unsafe { std::alloc::dealloc(self.ptr, Self::layout(self.size)) };
|
||||
}
|
||||
}
|
||||
|
||||
impl Reallocator {
|
||||
fn realloc(&mut self, ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
||||
if let Some(old_data) = self.load_allocation(ptr) {
|
||||
if new_size == 0 {
|
||||
// free
|
||||
std::ptr::null_mut()
|
||||
} else {
|
||||
// actually reallocate and copy the data over
|
||||
let mut new_data = Allocation::new(new_size);
|
||||
let bytes_to_copy = old_data.size.min(new_size);
|
||||
new_data.as_mut_slice()[..bytes_to_copy]
|
||||
.copy_from_slice(&old_data.as_slice()[..bytes_to_copy]);
|
||||
self.store_allocation(new_data)
|
||||
}
|
||||
} else if new_size > 0 {
|
||||
// fresh allocation
|
||||
let allocation = Allocation::new(new_size);
|
||||
self.store_allocation(allocation)
|
||||
} else {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
}
|
||||
|
||||
fn load_allocation(&mut self, ptr: *mut c_void) -> Option<Allocation> {
|
||||
if ptr.is_null() {
|
||||
return None;
|
||||
}
|
||||
let index = self
|
||||
.allocations
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(i, alloc)| std::ptr::addr_eq(alloc.ptr, ptr).then_some(i))?;
|
||||
let allocation = self.allocations.remove(index);
|
||||
Some(allocation)
|
||||
}
|
||||
|
||||
fn store_allocation(&mut self, allocation: Allocation) -> *mut c_void {
|
||||
let ptr = allocation.ptr;
|
||||
self.allocations.push(allocation);
|
||||
ptr.cast()
|
||||
}
|
||||
}
|
||||
|
||||
static VBU_ALLOC: LazyLock<Mutex<Reallocator>> =
|
||||
LazyLock::new(|| Mutex::new(Reallocator::default()));
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
unsafe fn vbu_realloc_shim(ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
||||
if !ptr.is_null() {
|
||||
// not supporting proper realloc because it needs bookkeeping and it's unnecessary
|
||||
return std::ptr::null_mut();
|
||||
}
|
||||
let allocation = vec![0u8; new_size].into_boxed_slice();
|
||||
Box::into_raw(allocation).cast()
|
||||
#[allow(nonstandard_style)]
|
||||
unsafe fn VBU_MEMMGR(ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
||||
let mut allocator = VBU_ALLOC.lock().unwrap();
|
||||
allocator.realloc(ptr, new_size)
|
||||
}
|
||||
|
||||
#[link(name = "vb")]
|
||||
@@ -25,7 +116,7 @@ pub fn rom_from_isx(bytes: &[u8]) -> Option<Vec<u8>> {
|
||||
if raw_rom.is_null() {
|
||||
return None;
|
||||
}
|
||||
// SAFETY: the rom was allocated by vbu_realloc_shim, which created it from a Vec<u8>.
|
||||
let rom = unsafe { Vec::from_raw_parts(raw_rom.cast(), rom_length, rom_length) };
|
||||
Some(rom)
|
||||
let bytes = VBU_ALLOC.lock().unwrap().load_allocation(raw_rom)?;
|
||||
assert_eq!(bytes.size, rom_length);
|
||||
Some(bytes.as_slice().to_vec())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
ops::Deref,
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use directories::ProjectDirs;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Persistence {
|
||||
config_dir: Option<PathBuf>,
|
||||
versions: Arc<Mutex<HashMap<String, Arc<AtomicU64>>>>,
|
||||
}
|
||||
|
||||
impl Persistence {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
config_dir: init_config_dir(),
|
||||
versions: Arc::new(Mutex::new(HashMap::new())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn config<T: ConfigCompatible>(&self, file: &str) -> Config<T> {
|
||||
let latest_version = self
|
||||
.versions
|
||||
.lock()
|
||||
.unwrap()
|
||||
.entry(file.to_string())
|
||||
.or_default()
|
||||
.clone();
|
||||
let path = self
|
||||
.config_dir
|
||||
.as_ref()
|
||||
.map(|p| p.join(file).with_extension("json"));
|
||||
let value = if let Some(p) = path.as_ref()
|
||||
&& let Ok(bytes) = fs::read(p)
|
||||
&& let Ok(v) = serde_json::from_slice(&bytes)
|
||||
{
|
||||
v
|
||||
} else {
|
||||
T::default()
|
||||
};
|
||||
Config {
|
||||
value,
|
||||
version: latest_version.load(Ordering::Relaxed),
|
||||
latest_version,
|
||||
path,
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
pub trait ConfigCompatible: Clone + Default + Eq + Serialize + for<'a> Deserialize<'a> {}
|
||||
impl<T: Clone + Default + Eq + Serialize + for<'a> Deserialize<'a>> ConfigCompatible for T {}
|
||||
|
||||
// A wrapper for a T (probably) stored on the filesystem.
|
||||
// Cheap to dereference, easy to sync changes to all copies.
|
||||
pub struct Config<T> {
|
||||
value: T,
|
||||
version: u64,
|
||||
latest_version: Arc<AtomicU64>,
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl<T> Deref for Config<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ConfigCompatible> Config<T> {
|
||||
pub fn refresh(&mut self) {
|
||||
let version = self.latest_version.load(Ordering::Relaxed);
|
||||
if self.version == version {
|
||||
return;
|
||||
}
|
||||
if let Some(path) = &self.path
|
||||
&& let Ok(bytes) = fs::read(path)
|
||||
&& let Ok(latest) = serde_json::from_slice(&bytes)
|
||||
{
|
||||
self.value = latest;
|
||||
}
|
||||
self.version = version;
|
||||
}
|
||||
|
||||
pub fn update(&mut self, update: impl FnOnce(&mut T)) {
|
||||
let mut new_value = self.value.clone();
|
||||
update(&mut new_value);
|
||||
if self.value == new_value {
|
||||
return;
|
||||
}
|
||||
if let Some(path) = &self.path
|
||||
&& let Ok(bytes) = serde_json::to_vec(&new_value)
|
||||
{
|
||||
let _ = fs::write(path, bytes);
|
||||
}
|
||||
let version = self.latest_version.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
self.value = new_value.clone();
|
||||
self.version = version;
|
||||
}
|
||||
}
|
||||
+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)]
|
||||
|
||||
+10
-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,13 @@ fn main() -> Result<()> {
|
||||
|
||||
let persistence = Persistence::new();
|
||||
|
||||
let (mut builder, client) = EmulatorBuilder::new();
|
||||
let mut config = AppConfig::load(&persistence);
|
||||
config.update(|c| c.apply_updates(&args));
|
||||
|
||||
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 +112,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")));
|
||||
|
||||
+68
-35
@@ -7,13 +7,13 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
app::UserEvent,
|
||||
config::{COLOR_PRESETS, SimConfig},
|
||||
config::{AppConfig, COLOR_PRESETS, Config, 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,
|
||||
@@ -42,7 +42,7 @@ pub struct GameWindow {
|
||||
persistence: Persistence,
|
||||
shortcuts: ShortcutProvider,
|
||||
sim_id: SimId,
|
||||
config: SimConfig,
|
||||
config: Config<SimConfig>,
|
||||
toasts: Toasts,
|
||||
screen: Option<GameScreen>,
|
||||
messages: mpsc::Receiver<Toast>,
|
||||
@@ -124,25 +124,38 @@ impl GameWindow {
|
||||
ChildWindow::CharacterData => AppWrapper::of_dyn(CharacterDataWindow::new(
|
||||
self.sim_id,
|
||||
&self.memory,
|
||||
&self.persistence,
|
||||
&self.images,
|
||||
)),
|
||||
ChildWindow::BgMap => AppWrapper::of_dyn(BgMapWindow::new(
|
||||
self.sim_id,
|
||||
&self.memory,
|
||||
&self.persistence,
|
||||
&self.images,
|
||||
)),
|
||||
ChildWindow::Objects => AppWrapper::of_dyn(ObjectWindow::new(
|
||||
self.sim_id,
|
||||
&self.memory,
|
||||
&self.persistence,
|
||||
&self.images,
|
||||
)),
|
||||
ChildWindow::Worlds => AppWrapper::of_dyn(WorldWindow::new(
|
||||
self.sim_id,
|
||||
&self.memory,
|
||||
&self.persistence,
|
||||
&self.images,
|
||||
)),
|
||||
ChildWindow::BgMap => {
|
||||
AppWrapper::of_dyn(BgMapWindow::new(self.sim_id, &self.memory, &self.images))
|
||||
}
|
||||
ChildWindow::Objects => {
|
||||
AppWrapper::of_dyn(ObjectWindow::new(self.sim_id, &self.memory, &self.images))
|
||||
}
|
||||
ChildWindow::Worlds => {
|
||||
AppWrapper::of_dyn(WorldWindow::new(self.sim_id, &self.memory, &self.images))
|
||||
}
|
||||
ChildWindow::FrameBuffers => AppWrapper::of_dyn(FrameBufferWindow::new(
|
||||
self.sim_id,
|
||||
&self.memory,
|
||||
&self.persistence,
|
||||
&self.images,
|
||||
)),
|
||||
ChildWindow::Registers => {
|
||||
AppWrapper::of_dyn(RegisterWindow::new(self.sim_id, &self.memory))
|
||||
}
|
||||
ChildWindow::Registers => AppWrapper::of_dyn(RegisterWindow::new(
|
||||
self.sim_id,
|
||||
&self.memory,
|
||||
&self.persistence,
|
||||
)),
|
||||
ChildWindow::Terminal => {
|
||||
AppWrapper::of_dyn(TerminalWindow::new(self.sim_id, &self.client))
|
||||
}
|
||||
@@ -334,7 +347,7 @@ impl GameWindow {
|
||||
}
|
||||
let watch_rom = self.client.is_rom_watched(self.sim_id);
|
||||
if ui.selectable_button(watch_rom, "Watch ROM").clicked() {
|
||||
self.update_config(|c| c.watch_rom = !watch_rom);
|
||||
self.config.update(|c| c.watch_rom = !watch_rom);
|
||||
self.client
|
||||
.send_command(EmulatorCommand::WatchRom(self.sim_id, !watch_rom));
|
||||
}
|
||||
@@ -395,7 +408,7 @@ impl GameWindow {
|
||||
ui.separator();
|
||||
let low_battery = self.config.low_battery;
|
||||
if ui.selectable_button(low_battery, "Low Battery").clicked() {
|
||||
self.update_config(|c| c.low_battery = !low_battery);
|
||||
self.config.update(|c| c.low_battery = !low_battery);
|
||||
let _ = self
|
||||
.proxy
|
||||
.send_event(UserEvent::LowBattery(self.sim_id, !low_battery));
|
||||
@@ -551,7 +564,7 @@ impl GameWindow {
|
||||
ui.send_viewport_cmd(ViewportCommand::InnerSize(current_dims * scale));
|
||||
}
|
||||
|
||||
self.update_config(|c| {
|
||||
self.config.update(|c| {
|
||||
c.display_mode = display_mode;
|
||||
c.dimensions = current_dims * scale;
|
||||
});
|
||||
@@ -559,7 +572,7 @@ impl GameWindow {
|
||||
ui.menu_button("Colors", |ui| {
|
||||
for preset in COLOR_PRESETS {
|
||||
if ui.color_pair_button(preset[0], preset[1]).clicked() {
|
||||
self.update_config(|c| c.colors = preset);
|
||||
self.config.update(|c| c.colors = preset);
|
||||
}
|
||||
}
|
||||
ui.with_layout(ui.layout().with_cross_align(egui::Align::Center), |ui| {
|
||||
@@ -589,7 +602,7 @@ impl GameWindow {
|
||||
.selectable_button(self.config.audio_enabled, "Enabled")
|
||||
.clicked()
|
||||
{
|
||||
self.update_config(|c| c.audio_enabled = !c.audio_enabled);
|
||||
self.config.update(|c| c.audio_enabled = !c.audio_enabled);
|
||||
self.client.send_command(EmulatorCommand::SetAudioEnabled(
|
||||
self.sim_id,
|
||||
self.config.audio_enabled,
|
||||
@@ -604,6 +617,36 @@ 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.update(|c| c.save_data_location = new_location);
|
||||
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) {
|
||||
@@ -631,19 +674,10 @@ impl GameWindow {
|
||||
self.color_picker = None;
|
||||
}
|
||||
if updated {
|
||||
self.update_config(|c| c.colors = colors);
|
||||
self.config.update(|c| c.colors = colors);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_config(&mut self, update: impl FnOnce(&mut SimConfig)) {
|
||||
let mut new_config = self.config.clone();
|
||||
update(&mut new_config);
|
||||
if self.config != new_config {
|
||||
let _ = new_config.save(&self.persistence, self.sim_id);
|
||||
}
|
||||
self.config = new_config;
|
||||
}
|
||||
|
||||
fn button_for(&self, ctx: &Context, text: &str, command: Command) -> Button<'_> {
|
||||
let button = Button::new(text);
|
||||
match self.shortcuts.shortcut_for(command) {
|
||||
@@ -670,6 +704,7 @@ impl AppWindow for GameWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.config.refresh();
|
||||
let has_player_2 = self.client.has_player_2();
|
||||
if !self.show_player_name && has_player_2 {
|
||||
ui.send_viewport_cmd(ViewportCommand::Title(format!("Lemur ({})", self.sim_id)));
|
||||
@@ -700,7 +735,7 @@ impl AppWindow for GameWindow {
|
||||
bounds.max - bounds.min
|
||||
};
|
||||
let position = ui.input(|i| i.viewport().outer_rect.map(|r| r.min));
|
||||
self.update_config(|c| {
|
||||
self.config.update(|c| {
|
||||
c.dimensions = dimensions;
|
||||
c.position = position;
|
||||
});
|
||||
@@ -708,9 +743,7 @@ 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| {
|
||||
Panel::top("menubar").exact_size(22.0).show(ui, |ui| {
|
||||
MenuBar::new().ui(ui, |ui| {
|
||||
self.show_menu(ui);
|
||||
});
|
||||
@@ -725,7 +758,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])
|
||||
|
||||
+24
-10
@@ -1,14 +1,16 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::{
|
||||
Align, CentralPanel, Checkbox, Color32, ComboBox, Image, ScrollArea, Slider, TextEdit,
|
||||
TextureOptions, Ui, ViewportBuilder,
|
||||
Align, CentralPanel, Checkbox, ComboBox, Image, ScrollArea, Slider, TextEdit, TextureOptions,
|
||||
Ui, ViewportBuilder,
|
||||
};
|
||||
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::{Config, SimConfig},
|
||||
emulator::SimId,
|
||||
filesystem::Persistence,
|
||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||
memory::{MemoryClient, MemoryView},
|
||||
window::{
|
||||
@@ -46,9 +48,14 @@ pub struct BgMapWindow {
|
||||
}
|
||||
|
||||
impl BgMapWindow {
|
||||
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>, images: &ImageTextureLoader) -> Self {
|
||||
pub fn new(
|
||||
sim_id: SimId,
|
||||
memory: &Arc<MemoryClient>,
|
||||
persistence: &Persistence,
|
||||
images: &ImageTextureLoader,
|
||||
) -> Self {
|
||||
let state: UiData<State> = UiData::new();
|
||||
let renderer = BgMapRenderer::new(sim_id, memory);
|
||||
let renderer = BgMapRenderer::new(sim_id, persistence, memory);
|
||||
let params = images.add(
|
||||
sim_id,
|
||||
renderer,
|
||||
@@ -203,7 +210,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))
|
||||
@@ -229,6 +236,7 @@ struct BgMapParams {
|
||||
}
|
||||
|
||||
struct BgMapRenderer {
|
||||
config: Config<SimConfig>,
|
||||
chardata: MemoryView,
|
||||
bgmaps: MemoryView,
|
||||
brightness: MemoryView,
|
||||
@@ -236,8 +244,9 @@ struct BgMapRenderer {
|
||||
}
|
||||
|
||||
impl BgMapRenderer {
|
||||
pub fn new(sim_id: SimId, memory: &MemoryClient) -> Self {
|
||||
pub fn new(sim_id: SimId, persistence: &Persistence, memory: &MemoryClient) -> Self {
|
||||
Self {
|
||||
config: SimConfig::load(persistence, sim_id),
|
||||
chardata: memory.watch(sim_id, 0x00078000, 0x8000),
|
||||
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
|
||||
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
||||
@@ -246,6 +255,8 @@ impl BgMapRenderer {
|
||||
}
|
||||
|
||||
fn render_bgmap(&self, image: &mut ImageBuffer, bgmap_index: usize, generic_palette: bool) {
|
||||
let color = self.config.colors[0];
|
||||
|
||||
let chardata = self.chardata.borrow();
|
||||
let bgmaps = self.bgmaps.borrow();
|
||||
let brightness = self.brightness.borrow();
|
||||
@@ -253,9 +264,9 @@ impl BgMapRenderer {
|
||||
|
||||
let brts = brightness.read::<[u8; 8]>(0);
|
||||
let colors = if generic_palette {
|
||||
[utils::generic_palette(Color32::RED); 4]
|
||||
[utils::generic_palette(color); 4]
|
||||
} else {
|
||||
[0, 2, 4, 6].map(|i| utils::palette_colors(palettes.read(i), &brts, Color32::RED))
|
||||
[0, 2, 4, 6].map(|i| utils::palette_colors(palettes.read(i), &brts, color))
|
||||
};
|
||||
|
||||
for (i, cell) in bgmaps.range::<u16>(bgmap_index * 4096, 4096).enumerate() {
|
||||
@@ -279,6 +290,8 @@ impl BgMapRenderer {
|
||||
}
|
||||
|
||||
fn render_bgmap_cell(&self, image: &mut ImageBuffer, index: usize, generic_palette: bool) {
|
||||
let color = self.config.colors[0];
|
||||
|
||||
let chardata = self.chardata.borrow();
|
||||
let bgmaps = self.bgmaps.borrow();
|
||||
let brightness = self.brightness.borrow();
|
||||
@@ -296,9 +309,9 @@ impl BgMapRenderer {
|
||||
} = CellData::parse(cell);
|
||||
let char = chardata.read::<[u16; 8]>(char_index);
|
||||
let palette = if generic_palette {
|
||||
utils::generic_palette(Color32::RED)
|
||||
utils::generic_palette(color)
|
||||
} else {
|
||||
utils::palette_colors(palettes.read(palette_index * 2), &brts, Color32::RED)
|
||||
utils::palette_colors(palettes.read(palette_index * 2), &brts, color)
|
||||
};
|
||||
|
||||
for row in 0..8 {
|
||||
@@ -321,6 +334,7 @@ impl ImageRenderer<2> for BgMapRenderer {
|
||||
}
|
||||
|
||||
fn render(&mut self, params: &Self::Params, images: &mut [ImageBuffer; 2]) {
|
||||
self.config.refresh();
|
||||
self.render_bgmap_cell(&mut images[0], params.cell_index, params.generic_palette);
|
||||
self.render_bgmap(
|
||||
&mut images[1],
|
||||
|
||||
+34
-14
@@ -8,7 +8,9 @@ use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::{Config, SimConfig},
|
||||
emulator::SimId,
|
||||
filesystem::Persistence,
|
||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||
memory::{MemoryClient, MemoryView},
|
||||
window::{
|
||||
@@ -99,6 +101,7 @@ impl Default for State {
|
||||
|
||||
pub struct CharacterDataWindow {
|
||||
sim_id: SimId,
|
||||
config: Config<SimConfig>,
|
||||
brightness: MemoryView,
|
||||
palettes: MemoryView,
|
||||
params: ImageParams<CharDataParams>,
|
||||
@@ -106,7 +109,13 @@ pub struct CharacterDataWindow {
|
||||
}
|
||||
|
||||
impl CharacterDataWindow {
|
||||
pub fn new(sim_id: SimId, memory: &MemoryClient, images: &ImageTextureLoader) -> Self {
|
||||
pub fn new(
|
||||
sim_id: SimId,
|
||||
memory: &MemoryClient,
|
||||
persistence: &Persistence,
|
||||
images: &ImageTextureLoader,
|
||||
) -> Self {
|
||||
let config = SimConfig::load(persistence, sim_id);
|
||||
let state: UiData<State> = UiData::new();
|
||||
let renderer = CharDataRenderer::new(sim_id, memory);
|
||||
let params = images.add(
|
||||
@@ -115,10 +124,12 @@ impl CharacterDataWindow {
|
||||
CharDataParams {
|
||||
palette: state.palette,
|
||||
index: state.index,
|
||||
color: config.colors[0],
|
||||
},
|
||||
);
|
||||
Self {
|
||||
sim_id,
|
||||
config,
|
||||
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
||||
palettes: memory.watch(sim_id, 0x0005f860, 16),
|
||||
params,
|
||||
@@ -226,17 +237,19 @@ impl CharacterDataWindow {
|
||||
self.params.write(CharDataParams {
|
||||
palette: self.state.palette,
|
||||
index: self.state.index,
|
||||
color: self.config.colors[0],
|
||||
});
|
||||
}
|
||||
|
||||
fn load_palette_colors(&self) -> [Color32; 4] {
|
||||
let color = self.config.colors[0];
|
||||
let Some(offset) = self.state.palette.offset() else {
|
||||
return utils::generic_palette(Color32::RED);
|
||||
return utils::generic_palette(color);
|
||||
};
|
||||
let palette = self.palettes.borrow().read(offset);
|
||||
let brightnesses = self.brightness.borrow();
|
||||
let brts = brightnesses.read(0);
|
||||
utils::palette_colors(palette, &brts, Color32::RED)
|
||||
utils::palette_colors(palette, &brts, color)
|
||||
}
|
||||
|
||||
fn show_chardata(&mut self, ui: &mut Ui) {
|
||||
@@ -262,8 +275,9 @@ impl AppWindow for CharacterDataWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.config.refresh();
|
||||
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))
|
||||
@@ -286,8 +300,8 @@ impl AppWindow for CharacterDataWindow {
|
||||
struct CharDataParams {
|
||||
palette: Palette,
|
||||
index: usize,
|
||||
color: Color32,
|
||||
}
|
||||
|
||||
struct CharDataRenderer {
|
||||
chardata: MemoryView,
|
||||
brightness: MemoryView,
|
||||
@@ -306,8 +320,8 @@ impl ImageRenderer<2> for CharDataRenderer {
|
||||
}
|
||||
|
||||
fn render(&mut self, params: &Self::Params, image: &mut [ImageBuffer; 2]) {
|
||||
self.render_character(&mut image[0], params.palette, params.index);
|
||||
self.render_character_data(&mut image[1], params.palette);
|
||||
self.render_character(&mut image[0], params.palette, params.index, params.color);
|
||||
self.render_character_data(&mut image[1], params.palette, params.color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,11 +334,17 @@ impl CharDataRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_character(&self, image: &mut ImageBuffer, palette: Palette, index: usize) {
|
||||
fn render_character(
|
||||
&self,
|
||||
image: &mut ImageBuffer,
|
||||
palette: Palette,
|
||||
index: usize,
|
||||
color: Color32,
|
||||
) {
|
||||
if index >= 2048 {
|
||||
return;
|
||||
}
|
||||
let palette = self.load_palette(palette);
|
||||
let palette = self.load_palette(palette, color);
|
||||
let chardata = self.chardata.borrow();
|
||||
let character = chardata.range::<u16>(index * 8, 8);
|
||||
for (row, pixels) in character.enumerate() {
|
||||
@@ -335,8 +355,8 @@ impl CharDataRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_character_data(&self, image: &mut ImageBuffer, palette: Palette) {
|
||||
let palette = self.load_palette(palette);
|
||||
fn render_character_data(&self, image: &mut ImageBuffer, palette: Palette, color: Color32) {
|
||||
let palette = self.load_palette(palette, color);
|
||||
let chardata = self.chardata.borrow();
|
||||
for (row, pixels) in chardata.range::<u16>(0, 8 * 2048).enumerate() {
|
||||
let char_index = row / 8;
|
||||
@@ -350,13 +370,13 @@ impl CharDataRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_palette(&self, palette: Palette) -> [Color32; 4] {
|
||||
fn load_palette(&self, palette: Palette, color: Color32) -> [Color32; 4] {
|
||||
let Some(offset) = palette.offset() else {
|
||||
return utils::GENERIC_PALETTE.map(|p| utils::shade(p, Color32::RED));
|
||||
return utils::GENERIC_PALETTE.map(|p| utils::shade(p, color));
|
||||
};
|
||||
let palette = self.palettes.borrow().read(offset);
|
||||
let brightnesses = self.brightness.borrow();
|
||||
let brts = brightnesses.read(0);
|
||||
utils::palette_colors(palette, &brts, Color32::RED)
|
||||
utils::palette_colors(palette, &brts, color)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::{Config, SimConfig},
|
||||
emulator::SimId,
|
||||
filesystem::Persistence,
|
||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||
memory::{MemoryClient, MemoryView},
|
||||
window::{
|
||||
@@ -44,9 +46,14 @@ pub struct FrameBufferWindow {
|
||||
}
|
||||
|
||||
impl FrameBufferWindow {
|
||||
pub fn new(sim_id: SimId, memory: &MemoryClient, images: &ImageTextureLoader) -> Self {
|
||||
pub fn new(
|
||||
sim_id: SimId,
|
||||
memory: &MemoryClient,
|
||||
persistence: &Persistence,
|
||||
images: &ImageTextureLoader,
|
||||
) -> Self {
|
||||
let state: UiData<State> = UiData::new();
|
||||
let renderer = FrameBufferRenderer::new(sim_id, memory);
|
||||
let renderer = FrameBufferRenderer::new(sim_id, memory, persistence);
|
||||
let params = images.add(
|
||||
sim_id,
|
||||
renderer,
|
||||
@@ -55,8 +62,6 @@ impl FrameBufferWindow {
|
||||
left: state.left,
|
||||
right: state.right,
|
||||
generic_palette: state.generic_palette,
|
||||
left_color: Color32::from_rgb(0xff, 0x00, 0x00),
|
||||
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
|
||||
},
|
||||
);
|
||||
Self {
|
||||
@@ -138,7 +143,6 @@ impl FrameBufferWindow {
|
||||
left: self.state.left,
|
||||
right: self.state.right,
|
||||
generic_palette: self.state.generic_palette,
|
||||
..*self.params
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,7 +167,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))
|
||||
@@ -188,18 +192,18 @@ struct FrameBufferParams {
|
||||
left: bool,
|
||||
right: bool,
|
||||
generic_palette: bool,
|
||||
left_color: Color32,
|
||||
right_color: Color32,
|
||||
}
|
||||
|
||||
struct FrameBufferRenderer {
|
||||
config: Config<SimConfig>,
|
||||
buffers: [MemoryView; 4],
|
||||
brightness: MemoryView,
|
||||
}
|
||||
|
||||
impl FrameBufferRenderer {
|
||||
fn new(sim_id: SimId, memory: &MemoryClient) -> Self {
|
||||
fn new(sim_id: SimId, memory: &MemoryClient, persistence: &Persistence) -> Self {
|
||||
Self {
|
||||
config: SimConfig::load(persistence, sim_id),
|
||||
buffers: [
|
||||
memory.watch(sim_id, 0x00000000, 0x6000),
|
||||
memory.watch(sim_id, 0x00008000, 0x6000),
|
||||
@@ -223,6 +227,7 @@ impl ImageRenderer<1> for FrameBufferRenderer {
|
||||
}
|
||||
|
||||
fn render(&mut self, params: &Self::Params, images: &mut [ImageBuffer; 1]) {
|
||||
self.config.refresh();
|
||||
let image = &mut images[0];
|
||||
|
||||
let left_buffer = self.buffers[params.index].borrow();
|
||||
@@ -230,15 +235,15 @@ impl ImageRenderer<1> for FrameBufferRenderer {
|
||||
|
||||
let colors = if params.generic_palette {
|
||||
[
|
||||
utils::generic_palette(params.left_color),
|
||||
utils::generic_palette(params.right_color),
|
||||
utils::generic_palette(self.config.colors[0]),
|
||||
utils::generic_palette(self.config.colors[1]),
|
||||
]
|
||||
} else {
|
||||
let brts = self.brightness.borrow().read::<[u8; 8]>(0);
|
||||
let shades = utils::parse_shades(&brts);
|
||||
[
|
||||
shades.map(|s| utils::shade(s, params.left_color)),
|
||||
shades.map(|s| utils::shade(s, params.right_color)),
|
||||
shades.map(|s| utils::shade(s, self.config.colors[0])),
|
||||
shades.map(|s| utils::shade(s, self.config.colors[1])),
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
+18
-13
@@ -1,14 +1,16 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::{
|
||||
Align, CentralPanel, Checkbox, Color32, ComboBox, Image, ScrollArea, Slider, TextEdit,
|
||||
TextureOptions, Ui, ViewportBuilder,
|
||||
Align, CentralPanel, Checkbox, ComboBox, Image, ScrollArea, Slider, TextEdit, TextureOptions,
|
||||
Ui, ViewportBuilder,
|
||||
};
|
||||
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::{Config, SimConfig},
|
||||
emulator::SimId,
|
||||
filesystem::Persistence,
|
||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||
memory::{MemoryClient, MemoryView},
|
||||
window::{
|
||||
@@ -44,17 +46,20 @@ pub struct ObjectWindow {
|
||||
}
|
||||
|
||||
impl ObjectWindow {
|
||||
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>, images: &ImageTextureLoader) -> Self {
|
||||
pub fn new(
|
||||
sim_id: SimId,
|
||||
memory: &Arc<MemoryClient>,
|
||||
persistence: &Persistence,
|
||||
images: &ImageTextureLoader,
|
||||
) -> Self {
|
||||
let state: UiData<State> = UiData::new();
|
||||
let renderer = ObjectRenderer::new(sim_id, memory);
|
||||
let renderer = ObjectRenderer::new(sim_id, memory, persistence);
|
||||
let params = images.add(
|
||||
sim_id,
|
||||
renderer,
|
||||
ObjectParams {
|
||||
index: state.index,
|
||||
generic_palette: state.generic_palette,
|
||||
left_color: Color32::from_rgb(0xff, 0x00, 0x00),
|
||||
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
|
||||
},
|
||||
);
|
||||
Self {
|
||||
@@ -194,7 +199,6 @@ impl ObjectWindow {
|
||||
self.params.write(ObjectParams {
|
||||
index: self.state.index,
|
||||
generic_palette: self.state.generic_palette,
|
||||
..*self.params
|
||||
});
|
||||
}
|
||||
|
||||
@@ -219,7 +223,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))
|
||||
@@ -242,8 +246,6 @@ impl AppWindow for ObjectWindow {
|
||||
struct ObjectParams {
|
||||
index: usize,
|
||||
generic_palette: bool,
|
||||
left_color: Color32,
|
||||
right_color: Color32,
|
||||
}
|
||||
|
||||
enum Eye {
|
||||
@@ -252,6 +254,7 @@ enum Eye {
|
||||
}
|
||||
|
||||
struct ObjectRenderer {
|
||||
config: Config<SimConfig>,
|
||||
chardata: MemoryView,
|
||||
objects: MemoryView,
|
||||
brightness: MemoryView,
|
||||
@@ -259,8 +262,9 @@ struct ObjectRenderer {
|
||||
}
|
||||
|
||||
impl ObjectRenderer {
|
||||
pub fn new(sim_id: SimId, memory: &MemoryClient) -> Self {
|
||||
pub fn new(sim_id: SimId, memory: &MemoryClient, persistence: &Persistence) -> Self {
|
||||
Self {
|
||||
config: SimConfig::load(persistence, sim_id),
|
||||
chardata: memory.watch(sim_id, 0x00078000, 0x8000),
|
||||
objects: memory.watch(sim_id, 0x0003e000, 0x2000),
|
||||
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
||||
@@ -302,8 +306,8 @@ impl ObjectRenderer {
|
||||
};
|
||||
|
||||
let color = match eye {
|
||||
Eye::Left => params.left_color,
|
||||
Eye::Right => params.right_color,
|
||||
Eye::Left => self.config.colors[0],
|
||||
Eye::Right => self.config.colors[1],
|
||||
};
|
||||
|
||||
let char = chardata.read::<[u16; 8]>(obj.data.char_index);
|
||||
@@ -343,6 +347,7 @@ impl ImageRenderer<2> for ObjectRenderer {
|
||||
}
|
||||
|
||||
fn render(&mut self, params: &Self::Params, images: &mut [ImageBuffer; 2]) {
|
||||
self.config.refresh();
|
||||
images[0].clear();
|
||||
self.render_object(&mut images[0], params, false, Eye::Left);
|
||||
self.render_object(&mut images[0], params, false, Eye::Right);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::{
|
||||
Align, Button, CentralPanel, Checkbox, Color32, Direction, Label, Layout, ScrollArea, TextEdit,
|
||||
Ui, ViewportBuilder,
|
||||
Align, Button, CentralPanel, Checkbox, Direction, Label, Layout, ScrollArea, TextEdit, Ui,
|
||||
ViewportBuilder,
|
||||
};
|
||||
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||
|
||||
use crate::{
|
||||
config::{Config, SimConfig},
|
||||
emulator::SimId,
|
||||
filesystem::Persistence,
|
||||
memory::{MemoryClient, MemoryRef, MemoryValue, MemoryView},
|
||||
window::{
|
||||
AppWindow,
|
||||
@@ -19,14 +21,16 @@ use super::utils;
|
||||
|
||||
pub struct RegisterWindow {
|
||||
sim_id: SimId,
|
||||
config: Config<SimConfig>,
|
||||
memory: Arc<MemoryClient>,
|
||||
registers: MemoryView,
|
||||
}
|
||||
|
||||
impl RegisterWindow {
|
||||
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>) -> Self {
|
||||
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>, persistence: &Persistence) -> Self {
|
||||
Self {
|
||||
sim_id,
|
||||
config: SimConfig::load(persistence, sim_id),
|
||||
memory: memory.clone(),
|
||||
registers: memory.watch(sim_id, 0x0005f800, 0x72),
|
||||
}
|
||||
@@ -366,7 +370,7 @@ impl RegisterWindow {
|
||||
});
|
||||
body.row(row_height, |mut row| {
|
||||
row.col(|_ui| {});
|
||||
for shade in utils::parse_brts(&brts, Color32::RED) {
|
||||
for shade in utils::parse_brts(&brts, self.config.colors[0]) {
|
||||
row.col(|ui| {
|
||||
ui.painter().rect_filled(
|
||||
ui.available_rect_before_wrap(),
|
||||
@@ -641,7 +645,8 @@ impl AppWindow for RegisterWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
CentralPanel::default().show_inside(ui, |ui| {
|
||||
self.config.refresh();
|
||||
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 {
|
||||
|
||||
+21
-5
@@ -14,7 +14,9 @@ use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::{Config, SimConfig},
|
||||
emulator::SimId,
|
||||
filesystem::Persistence,
|
||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||
memory::{MemoryClient, MemoryRef, MemoryView},
|
||||
window::{
|
||||
@@ -47,6 +49,7 @@ impl Default for State {
|
||||
|
||||
pub struct WorldWindow {
|
||||
sim_id: SimId,
|
||||
config: Config<SimConfig>,
|
||||
memory: Arc<MemoryClient>,
|
||||
worlds: MemoryView,
|
||||
bgmaps: MemoryView,
|
||||
@@ -55,7 +58,13 @@ pub struct WorldWindow {
|
||||
}
|
||||
|
||||
impl WorldWindow {
|
||||
pub fn new(sim_id: SimId, memory: &Arc<MemoryClient>, images: &ImageTextureLoader) -> Self {
|
||||
pub fn new(
|
||||
sim_id: SimId,
|
||||
memory: &Arc<MemoryClient>,
|
||||
persistence: &Persistence,
|
||||
images: &ImageTextureLoader,
|
||||
) -> Self {
|
||||
let config = SimConfig::load(persistence, sim_id);
|
||||
let state: UiData<State> = UiData::new();
|
||||
let renderer = WorldRenderer::new(sim_id, memory);
|
||||
let params = images.add(
|
||||
@@ -64,12 +73,13 @@ impl WorldWindow {
|
||||
WorldParams {
|
||||
index: state.index,
|
||||
generic_palette: state.generic_palette,
|
||||
left_color: Color32::from_rgb(0xff, 0x00, 0x00),
|
||||
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
|
||||
left_color: config.colors[0],
|
||||
right_color: config.colors[1],
|
||||
},
|
||||
);
|
||||
Self {
|
||||
sim_id,
|
||||
config,
|
||||
memory: memory.clone(),
|
||||
worlds: memory.watch(sim_id, 0x0003d800, 0x400),
|
||||
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
|
||||
@@ -538,8 +548,14 @@ impl AppWindow for WorldWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.config.refresh();
|
||||
self.params.write(WorldParams {
|
||||
left_color: self.config.colors[0],
|
||||
right_color: self.config.colors[1],
|
||||
..*self.params
|
||||
});
|
||||
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))
|
||||
@@ -944,7 +960,7 @@ impl WorldHeader {
|
||||
let ron = data & 0x4000 != 0;
|
||||
let mode = WorldMode::from_u16((data >> 12) & 0x3).unwrap();
|
||||
let scx = (data >> 10) as u32 & 0x03;
|
||||
let scy = (data >> 10) as u32 & 0x03;
|
||||
let scy = (data >> 8) as u32 & 0x03;
|
||||
let over = data & 0x0080 != 0;
|
||||
let end = data & 0x0040 != 0;
|
||||
let base = (data & 0x000f) as usize;
|
||||
|
||||
Reference in New Issue
Block a user