Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55d3cf737d | ||
|
|
36cfd961da | ||
|
|
9bcd99e437 | ||
|
|
f17d62876b | ||
|
|
4004047d68 | ||
|
|
e8fb942896 | ||
|
|
53cda2e515 | ||
|
|
1935d116ca |
Generated
+355
-359
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -4,7 +4,7 @@ description = "An emulator for the Virtual Boy."
|
||||
repository = "https://git.virtual-boy.com/PVB/lemur"
|
||||
publish = false
|
||||
license = "MIT"
|
||||
version = "0.15.1"
|
||||
version = "0.15.2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+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.98-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
+5
-4
@@ -23,7 +23,7 @@ use winit::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::{AppConfig, CliArgs},
|
||||
config::{AppConfig, CliArgs, Config},
|
||||
controller::ControllerManager,
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||
filesystem::Persistence,
|
||||
@@ -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);
|
||||
@@ -504,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, .. },
|
||||
@@ -531,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:?}");
|
||||
|
||||
+15
-24
@@ -1,9 +1,9 @@
|
||||
use anyhow::Result;
|
||||
use bytemuck::NoUninit;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use egui::{Color32, Pos2, Vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use crate::filesystem::Config;
|
||||
use crate::{emulator::SimId, filesystem::Persistence, window::DisplayMode};
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -116,38 +116,31 @@ pub struct AppConfig {
|
||||
#[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(),
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
impl AppConfig {
|
||||
pub fn load(persistence: &Persistence) -> Config<Self> {
|
||||
persistence.config(APP_CONFIG_FILENAME)
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if let Some(save_data_location) = args.save_data_location {
|
||||
self.save_data_location = save_data_location;
|
||||
updated = true;
|
||||
}
|
||||
updated
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,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],
|
||||
@@ -187,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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+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())
|
||||
}
|
||||
|
||||
+92
-1
@@ -1,4 +1,13 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
ops::Deref,
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use directories::ProjectDirs;
|
||||
@@ -7,12 +16,42 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,3 +89,55 @@ pub fn init_data_dir() -> Option<PathBuf> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -94,9 +94,8 @@ fn main() -> Result<()> {
|
||||
let persistence = Persistence::new();
|
||||
|
||||
let mut config = AppConfig::load(&persistence);
|
||||
if config.update(&args) {
|
||||
let _ = config.save(&persistence);
|
||||
}
|
||||
config.update(|c| c.apply_updates(&args));
|
||||
|
||||
let p1 = SimConfig::load(&persistence, SimId::Player1);
|
||||
let p2 = SimConfig::load(&persistence, SimId::Player2);
|
||||
|
||||
|
||||
+36
-32
@@ -7,7 +7,7 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
app::UserEvent,
|
||||
config::{AppConfig, COLOR_PRESETS, SaveDataLocation, SimConfig},
|
||||
config::{AppConfig, COLOR_PRESETS, Config, SaveDataLocation, SimConfig},
|
||||
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId, SimState},
|
||||
filepicker::FilePicker,
|
||||
filesystem::Persistence,
|
||||
@@ -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,
|
||||
@@ -611,8 +624,7 @@ impl GameWindow {
|
||||
return;
|
||||
};
|
||||
let mut app_config = AppConfig::load(&self.persistence);
|
||||
app_config.save_data_location = new_location;
|
||||
let _ = app_config.save(&self.persistence);
|
||||
app_config.update(|c| c.save_data_location = new_location);
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetSaveDataLocation(new_location));
|
||||
};
|
||||
@@ -662,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) {
|
||||
@@ -701,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)));
|
||||
@@ -731,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;
|
||||
});
|
||||
|
||||
+23
-9
@@ -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,
|
||||
@@ -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],
|
||||
|
||||
+33
-13
@@ -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,6 +275,7 @@ impl AppWindow for CharacterDataWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.config.refresh();
|
||||
self.state.load(ui);
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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])),
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
+17
-12
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,6 +645,7 @@ impl AppWindow for RegisterWindow {
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui) {
|
||||
self.config.refresh();
|
||||
CentralPanel::default().show(ui, |ui| {
|
||||
ScrollArea::vertical().show(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
|
||||
+20
-4
@@ -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,6 +548,12 @@ 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(ui, |ui| {
|
||||
ui.horizontal_top(|ui| {
|
||||
@@ -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