Compare commits
9
Commits
acb8856dd0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55d3cf737d | ||
|
|
36cfd961da | ||
|
|
9bcd99e437 | ||
|
|
f17d62876b | ||
|
|
4004047d68 | ||
|
|
e8fb942896 | ||
|
|
53cda2e515 | ||
|
|
1935d116ca | ||
|
|
fe766efcdc |
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"
|
repository = "https://git.virtual-boy.com/PVB/lemur"
|
||||||
publish = false
|
publish = false
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
version = "0.15.0"
|
version = "0.15.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
+13
-13
@@ -10,30 +10,30 @@ RUN apt-get update && \
|
|||||||
apt-get install -y ca-certificates
|
apt-get install -y ca-certificates
|
||||||
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y bash bzip2 clang-22 git lld-22 llvm-22 make patch xz-utils && \
|
apt-get install -y bash bzip2 clang-23 git lld-23 llvm-23 make patch xz-utils && \
|
||||||
ln -s $(which clang-22) /usr/bin/clang && \
|
ln -s $(which clang-23) /usr/bin/clang && \
|
||||||
ln -s $(which clang++-22) /usr/bin/clang++ && \
|
ln -s $(which clang++-23) /usr/bin/clang++ && \
|
||||||
ln -s $(which ld64.lld-22) /usr/bin/ld64.lld && \
|
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
|
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
|
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
|
COPY llvm.sources /etc/apt/sources.list.d/llvm.sources
|
||||||
RUN rustup target add x86_64-pc-windows-msvc && \
|
RUN rustup target add x86_64-pc-windows-msvc && \
|
||||||
rustup target add x86_64-apple-darwin && \
|
rustup target add x86_64-apple-darwin && \
|
||||||
rustup target add aarch64-apple-darwin && \
|
rustup target add aarch64-apple-darwin && \
|
||||||
apt-get update && \
|
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 && \
|
cargo install cargo-bundle xwin && \
|
||||||
xwin --accept-license splat --output xwin && \
|
xwin --accept-license splat --output xwin && \
|
||||||
rm -rf .xwin-cache && \
|
rm -rf .xwin-cache && \
|
||||||
ln -s $(which clang-22) /usr/bin/clang && \
|
ln -s $(which clang-23) /usr/bin/clang && \
|
||||||
ln -s $(which clang++-22) /usr/bin/clang++
|
ln -s $(which clang++-23) /usr/bin/clang++
|
||||||
COPY --from=osxcross /osxcross /osxcross
|
COPY --from=osxcross /osxcross /osxcross
|
||||||
|
|
||||||
ENV PATH="/osxcross/bin:$PATH" \
|
ENV PATH="/osxcross/bin:$PATH" \
|
||||||
LD_LIBRARY_PATH="/osxcross/lib" \
|
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" \
|
CC_x86_64-apple-darwin="o64-clang" \
|
||||||
CXX_x86_64-apple-darwin="o64-clang++" \
|
CXX_x86_64-apple-darwin="o64-clang++" \
|
||||||
CC_aarch64-apple-darwin="oa64-clang" \
|
CC_aarch64-apple-darwin="oa64-clang" \
|
||||||
@@ -43,11 +43,11 @@ ENV PATH="/osxcross/bin:$PATH" \
|
|||||||
SHROOMS_CFLAGS_x86_64-pc-windows-msvc="-flto" \
|
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" \
|
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_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_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_LINKER="oa64-clang" \
|
||||||
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-22" \
|
CARGO_TARGET_AARCH64_APPLE_DARWIN_AR="llvm-ar-23" \
|
||||||
RC_PATH="llvm-rc-22" \
|
RC_PATH="llvm-rc-23" \
|
||||||
MACOSX_DEPLOYMENT_TARGET="14.5"
|
MACOSX_DEPLOYMENT_TARGET="14.5"
|
||||||
ENTRYPOINT ["bash"]
|
ENTRYPOINT ["bash"]
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
.define("VB_DIRECT_FRAME", "on_frame")
|
.define("VB_DIRECT_FRAME", "on_frame")
|
||||||
.define("VB_DIRECT_READ", "on_read")
|
.define("VB_DIRECT_READ", "on_read")
|
||||||
.define("VB_DIRECT_WRITE", "on_write")
|
.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/core/vb.c"))
|
||||||
.file(Path::new("shrooms-vb-core/util/isx.c"))
|
.file(Path::new("shrooms-vb-core/util/isx.c"))
|
||||||
.file(Path::new("shrooms-vb-core/util/vbu.c"))
|
.file(Path::new("shrooms-vb-core/util/vbu.c"))
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
Types: deb deb-src
|
Types: deb deb-src
|
||||||
URIs: http://apt.llvm.org/trixie/
|
URIs: http://apt.llvm.org/trixie/
|
||||||
Suites: llvm-toolchain-trixie-22
|
Suites: llvm-toolchain-trixie-23
|
||||||
Components: main
|
Components: main
|
||||||
|
|||||||
+1
-1
Submodule shrooms-vb-core updated: 31b7403252...6e9b727b31
+5
-4
@@ -23,7 +23,7 @@ use winit::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{AppConfig, CliArgs},
|
config::{AppConfig, CliArgs, Config},
|
||||||
controller::ControllerManager,
|
controller::ControllerManager,
|
||||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||||
filesystem::Persistence,
|
filesystem::Persistence,
|
||||||
@@ -94,7 +94,7 @@ impl Application {
|
|||||||
handle: OwnedDisplayHandle,
|
handle: OwnedDisplayHandle,
|
||||||
persistence: Persistence,
|
persistence: Persistence,
|
||||||
args: CliArgs,
|
args: CliArgs,
|
||||||
config: AppConfig,
|
config: Config<AppConfig>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let wgpu = WgpuState::new(handle, config);
|
let wgpu = WgpuState::new(handle, config);
|
||||||
let icon = load_icon().ok().map(Arc::new);
|
let icon = load_icon().ok().map(Arc::new);
|
||||||
@@ -504,11 +504,11 @@ impl ApplicationHandler<UserEvent> for Application {
|
|||||||
struct WgpuState {
|
struct WgpuState {
|
||||||
instance: wgpu::Instance,
|
instance: wgpu::Instance,
|
||||||
device_descriptor: Arc<dyn Fn(&wgpu::Adapter) -> wgpu::DeviceDescriptor<'static> + Send + Sync>,
|
device_descriptor: Arc<dyn Fn(&wgpu::Adapter) -> wgpu::DeviceDescriptor<'static> + Send + Sync>,
|
||||||
config: AppConfig,
|
config: Config<AppConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WgpuState {
|
impl WgpuState {
|
||||||
fn new(handle: OwnedDisplayHandle, config: AppConfig) -> Self {
|
fn new(handle: OwnedDisplayHandle, config: Config<AppConfig>) -> Self {
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
let egui_wgpu::WgpuSetupCreateNew {
|
let egui_wgpu::WgpuSetupCreateNew {
|
||||||
instance_descriptor: wgpu::InstanceDescriptor { backends, .. },
|
instance_descriptor: wgpu::InstanceDescriptor { backends, .. },
|
||||||
@@ -531,6 +531,7 @@ impl WgpuState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init(&mut self, window: &Window) -> egui_wgpu::WgpuSetupExisting {
|
fn init(&mut self, window: &Window) -> egui_wgpu::WgpuSetupExisting {
|
||||||
|
self.config.refresh();
|
||||||
let power_preference =
|
let power_preference =
|
||||||
wgpu::PowerPreference::from_env().unwrap_or(self.config.power_preference);
|
wgpu::PowerPreference::from_env().unwrap_or(self.config.power_preference);
|
||||||
debug!("power preference: {power_preference:?}");
|
debug!("power preference: {power_preference:?}");
|
||||||
|
|||||||
+14
-23
@@ -1,9 +1,9 @@
|
|||||||
use anyhow::Result;
|
|
||||||
use bytemuck::NoUninit;
|
use bytemuck::NoUninit;
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use egui::{Color32, Pos2, Vec2};
|
use egui::{Color32, Pos2, Vec2};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub use crate::filesystem::Config;
|
||||||
use crate::{emulator::SimId, filesystem::Persistence, window::DisplayMode};
|
use crate::{emulator::SimId, filesystem::Persistence, window::DisplayMode};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -116,38 +116,31 @@ pub struct AppConfig {
|
|||||||
#[serde(default = "default_save_data_location")]
|
#[serde(default = "default_save_data_location")]
|
||||||
pub save_data_location: SaveDataLocation,
|
pub save_data_location: SaveDataLocation,
|
||||||
}
|
}
|
||||||
|
impl Default for AppConfig {
|
||||||
impl AppConfig {
|
fn default() -> Self {
|
||||||
pub fn load(persistence: &Persistence) -> Self {
|
|
||||||
if let Ok(config) = persistence.load_config(APP_CONFIG_FILENAME) {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
Self {
|
Self {
|
||||||
power_preference: default_power_preference(),
|
power_preference: default_power_preference(),
|
||||||
force_fallback: false,
|
force_fallback: false,
|
||||||
save_data_location: default_save_data_location(),
|
save_data_location: default_save_data_location(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save(&self, persistence: &Persistence) -> Result<()> {
|
impl AppConfig {
|
||||||
persistence.save_config(APP_CONFIG_FILENAME, &self)
|
pub fn load(persistence: &Persistence) -> Config<Self> {
|
||||||
|
persistence.config(APP_CONFIG_FILENAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, args: &CliArgs) -> bool {
|
pub fn apply_updates(&mut self, args: &CliArgs) {
|
||||||
let mut updated = false;
|
|
||||||
if let Some(pref) = args.wgpu_power_preference {
|
if let Some(pref) = args.wgpu_power_preference {
|
||||||
self.power_preference = pref.into();
|
self.power_preference = pref.into();
|
||||||
updated = true;
|
|
||||||
}
|
}
|
||||||
if let Some(force_fallback) = args.wgpu_force_fallback {
|
if let Some(force_fallback) = args.wgpu_force_fallback {
|
||||||
self.force_fallback = force_fallback;
|
self.force_fallback = force_fallback;
|
||||||
updated = true;
|
|
||||||
}
|
}
|
||||||
if let Some(save_data_location) = args.save_data_location {
|
if let Some(save_data_location) = args.save_data_location {
|
||||||
self.save_data_location = save_data_location;
|
self.save_data_location = save_data_location;
|
||||||
updated = true;
|
|
||||||
}
|
}
|
||||||
updated
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,12 +164,8 @@ pub struct SimConfig {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub position: Option<Pos2>,
|
pub position: Option<Pos2>,
|
||||||
}
|
}
|
||||||
|
impl Default for SimConfig {
|
||||||
impl SimConfig {
|
fn default() -> Self {
|
||||||
pub fn load(persistence: &Persistence, sim_id: SimId) -> Self {
|
|
||||||
if let Ok(config) = persistence.load_config(sim_config_filename(sim_id)) {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
Self {
|
Self {
|
||||||
display_mode: DisplayMode::Anaglyph,
|
display_mode: DisplayMode::Anaglyph,
|
||||||
colors: COLOR_PRESETS[0],
|
colors: COLOR_PRESETS[0],
|
||||||
@@ -187,9 +176,11 @@ impl SimConfig {
|
|||||||
position: None,
|
position: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save(&self, persistence: &Persistence, sim_id: SimId) -> Result<()> {
|
impl SimConfig {
|
||||||
persistence.save_config(sim_config_filename(sim_id), self)
|
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(no_mangle)]
|
||||||
unsafe fn vbu_realloc_shim(ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
#[allow(nonstandard_style)]
|
||||||
if !ptr.is_null() {
|
unsafe fn VBU_MEMMGR(ptr: *mut c_void, new_size: usize) -> *mut c_void {
|
||||||
// not supporting proper realloc because it needs bookkeeping and it's unnecessary
|
let mut allocator = VBU_ALLOC.lock().unwrap();
|
||||||
return std::ptr::null_mut();
|
allocator.realloc(ptr, new_size)
|
||||||
}
|
|
||||||
let allocation = vec![0u8; new_size].into_boxed_slice();
|
|
||||||
Box::into_raw(allocation).cast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[link(name = "vb")]
|
#[link(name = "vb")]
|
||||||
@@ -25,7 +116,7 @@ pub fn rom_from_isx(bytes: &[u8]) -> Option<Vec<u8>> {
|
|||||||
if raw_rom.is_null() {
|
if raw_rom.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
// SAFETY: the rom was allocated by vbu_realloc_shim, which created it from a Vec<u8>.
|
let bytes = VBU_ALLOC.lock().unwrap().load_allocation(raw_rom)?;
|
||||||
let rom = unsafe { Vec::from_raw_parts(raw_rom.cast(), rom_length, rom_length) };
|
assert_eq!(bytes.size, rom_length);
|
||||||
Some(rom)
|
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 anyhow::{Result, bail};
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
@@ -7,12 +16,42 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Persistence {
|
pub struct Persistence {
|
||||||
config_dir: Option<PathBuf>,
|
config_dir: Option<PathBuf>,
|
||||||
|
versions: Arc<Mutex<HashMap<String, Arc<AtomicU64>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Persistence {
|
impl Persistence {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
config_dir: init_config_dir(),
|
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> {
|
fn project_dirs() -> Option<ProjectDirs> {
|
||||||
ProjectDirs::from("com", "virtual-boy", "Lemur")
|
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 persistence = Persistence::new();
|
||||||
|
|
||||||
let mut config = AppConfig::load(&persistence);
|
let mut config = AppConfig::load(&persistence);
|
||||||
if config.update(&args) {
|
config.update(|c| c.apply_updates(&args));
|
||||||
let _ = config.save(&persistence);
|
|
||||||
}
|
|
||||||
let p1 = SimConfig::load(&persistence, SimId::Player1);
|
let p1 = SimConfig::load(&persistence, SimId::Player1);
|
||||||
let p2 = SimConfig::load(&persistence, SimId::Player2);
|
let p2 = SimConfig::load(&persistence, SimId::Player2);
|
||||||
|
|
||||||
|
|||||||
+36
-32
@@ -7,7 +7,7 @@ use std::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::UserEvent,
|
app::UserEvent,
|
||||||
config::{AppConfig, COLOR_PRESETS, SaveDataLocation, SimConfig},
|
config::{AppConfig, COLOR_PRESETS, Config, SaveDataLocation, SimConfig},
|
||||||
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId, SimState},
|
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId, SimState},
|
||||||
filepicker::FilePicker,
|
filepicker::FilePicker,
|
||||||
filesystem::Persistence,
|
filesystem::Persistence,
|
||||||
@@ -42,7 +42,7 @@ pub struct GameWindow {
|
|||||||
persistence: Persistence,
|
persistence: Persistence,
|
||||||
shortcuts: ShortcutProvider,
|
shortcuts: ShortcutProvider,
|
||||||
sim_id: SimId,
|
sim_id: SimId,
|
||||||
config: SimConfig,
|
config: Config<SimConfig>,
|
||||||
toasts: Toasts,
|
toasts: Toasts,
|
||||||
screen: Option<GameScreen>,
|
screen: Option<GameScreen>,
|
||||||
messages: mpsc::Receiver<Toast>,
|
messages: mpsc::Receiver<Toast>,
|
||||||
@@ -124,25 +124,38 @@ impl GameWindow {
|
|||||||
ChildWindow::CharacterData => AppWrapper::of_dyn(CharacterDataWindow::new(
|
ChildWindow::CharacterData => AppWrapper::of_dyn(CharacterDataWindow::new(
|
||||||
self.sim_id,
|
self.sim_id,
|
||||||
&self.memory,
|
&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,
|
&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(
|
ChildWindow::FrameBuffers => AppWrapper::of_dyn(FrameBufferWindow::new(
|
||||||
self.sim_id,
|
self.sim_id,
|
||||||
&self.memory,
|
&self.memory,
|
||||||
|
&self.persistence,
|
||||||
&self.images,
|
&self.images,
|
||||||
)),
|
)),
|
||||||
ChildWindow::Registers => {
|
ChildWindow::Registers => AppWrapper::of_dyn(RegisterWindow::new(
|
||||||
AppWrapper::of_dyn(RegisterWindow::new(self.sim_id, &self.memory))
|
self.sim_id,
|
||||||
}
|
&self.memory,
|
||||||
|
&self.persistence,
|
||||||
|
)),
|
||||||
ChildWindow::Terminal => {
|
ChildWindow::Terminal => {
|
||||||
AppWrapper::of_dyn(TerminalWindow::new(self.sim_id, &self.client))
|
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);
|
let watch_rom = self.client.is_rom_watched(self.sim_id);
|
||||||
if ui.selectable_button(watch_rom, "Watch ROM").clicked() {
|
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
|
self.client
|
||||||
.send_command(EmulatorCommand::WatchRom(self.sim_id, !watch_rom));
|
.send_command(EmulatorCommand::WatchRom(self.sim_id, !watch_rom));
|
||||||
}
|
}
|
||||||
@@ -395,7 +408,7 @@ impl GameWindow {
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
let low_battery = self.config.low_battery;
|
let low_battery = self.config.low_battery;
|
||||||
if ui.selectable_button(low_battery, "Low Battery").clicked() {
|
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
|
let _ = self
|
||||||
.proxy
|
.proxy
|
||||||
.send_event(UserEvent::LowBattery(self.sim_id, !low_battery));
|
.send_event(UserEvent::LowBattery(self.sim_id, !low_battery));
|
||||||
@@ -551,7 +564,7 @@ impl GameWindow {
|
|||||||
ui.send_viewport_cmd(ViewportCommand::InnerSize(current_dims * scale));
|
ui.send_viewport_cmd(ViewportCommand::InnerSize(current_dims * scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_config(|c| {
|
self.config.update(|c| {
|
||||||
c.display_mode = display_mode;
|
c.display_mode = display_mode;
|
||||||
c.dimensions = current_dims * scale;
|
c.dimensions = current_dims * scale;
|
||||||
});
|
});
|
||||||
@@ -559,7 +572,7 @@ impl GameWindow {
|
|||||||
ui.menu_button("Colors", |ui| {
|
ui.menu_button("Colors", |ui| {
|
||||||
for preset in COLOR_PRESETS {
|
for preset in COLOR_PRESETS {
|
||||||
if ui.color_pair_button(preset[0], preset[1]).clicked() {
|
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| {
|
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")
|
.selectable_button(self.config.audio_enabled, "Enabled")
|
||||||
.clicked()
|
.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.client.send_command(EmulatorCommand::SetAudioEnabled(
|
||||||
self.sim_id,
|
self.sim_id,
|
||||||
self.config.audio_enabled,
|
self.config.audio_enabled,
|
||||||
@@ -611,8 +624,7 @@ impl GameWindow {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let mut app_config = AppConfig::load(&self.persistence);
|
let mut app_config = AppConfig::load(&self.persistence);
|
||||||
app_config.save_data_location = new_location;
|
app_config.update(|c| c.save_data_location = new_location);
|
||||||
let _ = app_config.save(&self.persistence);
|
|
||||||
self.client
|
self.client
|
||||||
.send_command(EmulatorCommand::SetSaveDataLocation(new_location));
|
.send_command(EmulatorCommand::SetSaveDataLocation(new_location));
|
||||||
};
|
};
|
||||||
@@ -662,19 +674,10 @@ impl GameWindow {
|
|||||||
self.color_picker = None;
|
self.color_picker = None;
|
||||||
}
|
}
|
||||||
if updated {
|
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<'_> {
|
fn button_for(&self, ctx: &Context, text: &str, command: Command) -> Button<'_> {
|
||||||
let button = Button::new(text);
|
let button = Button::new(text);
|
||||||
match self.shortcuts.shortcut_for(command) {
|
match self.shortcuts.shortcut_for(command) {
|
||||||
@@ -701,6 +704,7 @@ impl AppWindow for GameWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, ui: &mut Ui) {
|
fn show(&mut self, ui: &mut Ui) {
|
||||||
|
self.config.refresh();
|
||||||
let has_player_2 = self.client.has_player_2();
|
let has_player_2 = self.client.has_player_2();
|
||||||
if !self.show_player_name && has_player_2 {
|
if !self.show_player_name && has_player_2 {
|
||||||
ui.send_viewport_cmd(ViewportCommand::Title(format!("Lemur ({})", self.sim_id)));
|
ui.send_viewport_cmd(ViewportCommand::Title(format!("Lemur ({})", self.sim_id)));
|
||||||
@@ -731,7 +735,7 @@ impl AppWindow for GameWindow {
|
|||||||
bounds.max - bounds.min
|
bounds.max - bounds.min
|
||||||
};
|
};
|
||||||
let position = ui.input(|i| i.viewport().outer_rect.map(|r| r.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.dimensions = dimensions;
|
||||||
c.position = position;
|
c.position = position;
|
||||||
});
|
});
|
||||||
|
|||||||
+23
-9
@@ -1,14 +1,16 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, CentralPanel, Checkbox, Color32, ComboBox, Image, ScrollArea, Slider, TextEdit,
|
Align, CentralPanel, Checkbox, ComboBox, Image, ScrollArea, Slider, TextEdit, TextureOptions,
|
||||||
TextureOptions, Ui, ViewportBuilder,
|
Ui, ViewportBuilder,
|
||||||
};
|
};
|
||||||
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::{Config, SimConfig},
|
||||||
emulator::SimId,
|
emulator::SimId,
|
||||||
|
filesystem::Persistence,
|
||||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||||
memory::{MemoryClient, MemoryView},
|
memory::{MemoryClient, MemoryView},
|
||||||
window::{
|
window::{
|
||||||
@@ -46,9 +48,14 @@ pub struct BgMapWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 state: UiData<State> = UiData::new();
|
||||||
let renderer = BgMapRenderer::new(sim_id, memory);
|
let renderer = BgMapRenderer::new(sim_id, persistence, memory);
|
||||||
let params = images.add(
|
let params = images.add(
|
||||||
sim_id,
|
sim_id,
|
||||||
renderer,
|
renderer,
|
||||||
@@ -229,6 +236,7 @@ struct BgMapParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct BgMapRenderer {
|
struct BgMapRenderer {
|
||||||
|
config: Config<SimConfig>,
|
||||||
chardata: MemoryView,
|
chardata: MemoryView,
|
||||||
bgmaps: MemoryView,
|
bgmaps: MemoryView,
|
||||||
brightness: MemoryView,
|
brightness: MemoryView,
|
||||||
@@ -236,8 +244,9 @@ struct BgMapRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BgMapRenderer {
|
impl BgMapRenderer {
|
||||||
pub fn new(sim_id: SimId, memory: &MemoryClient) -> Self {
|
pub fn new(sim_id: SimId, persistence: &Persistence, memory: &MemoryClient) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
config: SimConfig::load(persistence, sim_id),
|
||||||
chardata: memory.watch(sim_id, 0x00078000, 0x8000),
|
chardata: memory.watch(sim_id, 0x00078000, 0x8000),
|
||||||
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
|
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
|
||||||
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
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) {
|
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 chardata = self.chardata.borrow();
|
||||||
let bgmaps = self.bgmaps.borrow();
|
let bgmaps = self.bgmaps.borrow();
|
||||||
let brightness = self.brightness.borrow();
|
let brightness = self.brightness.borrow();
|
||||||
@@ -253,9 +264,9 @@ impl BgMapRenderer {
|
|||||||
|
|
||||||
let brts = brightness.read::<[u8; 8]>(0);
|
let brts = brightness.read::<[u8; 8]>(0);
|
||||||
let colors = if generic_palette {
|
let colors = if generic_palette {
|
||||||
[utils::generic_palette(Color32::RED); 4]
|
[utils::generic_palette(color); 4]
|
||||||
} else {
|
} 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() {
|
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) {
|
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 chardata = self.chardata.borrow();
|
||||||
let bgmaps = self.bgmaps.borrow();
|
let bgmaps = self.bgmaps.borrow();
|
||||||
let brightness = self.brightness.borrow();
|
let brightness = self.brightness.borrow();
|
||||||
@@ -296,9 +309,9 @@ impl BgMapRenderer {
|
|||||||
} = CellData::parse(cell);
|
} = CellData::parse(cell);
|
||||||
let char = chardata.read::<[u16; 8]>(char_index);
|
let char = chardata.read::<[u16; 8]>(char_index);
|
||||||
let palette = if generic_palette {
|
let palette = if generic_palette {
|
||||||
utils::generic_palette(Color32::RED)
|
utils::generic_palette(color)
|
||||||
} else {
|
} 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 {
|
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]) {
|
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_cell(&mut images[0], params.cell_index, params.generic_palette);
|
||||||
self.render_bgmap(
|
self.render_bgmap(
|
||||||
&mut images[1],
|
&mut images[1],
|
||||||
|
|||||||
+33
-13
@@ -8,7 +8,9 @@ use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::{Config, SimConfig},
|
||||||
emulator::SimId,
|
emulator::SimId,
|
||||||
|
filesystem::Persistence,
|
||||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||||
memory::{MemoryClient, MemoryView},
|
memory::{MemoryClient, MemoryView},
|
||||||
window::{
|
window::{
|
||||||
@@ -99,6 +101,7 @@ impl Default for State {
|
|||||||
|
|
||||||
pub struct CharacterDataWindow {
|
pub struct CharacterDataWindow {
|
||||||
sim_id: SimId,
|
sim_id: SimId,
|
||||||
|
config: Config<SimConfig>,
|
||||||
brightness: MemoryView,
|
brightness: MemoryView,
|
||||||
palettes: MemoryView,
|
palettes: MemoryView,
|
||||||
params: ImageParams<CharDataParams>,
|
params: ImageParams<CharDataParams>,
|
||||||
@@ -106,7 +109,13 @@ pub struct CharacterDataWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 state: UiData<State> = UiData::new();
|
||||||
let renderer = CharDataRenderer::new(sim_id, memory);
|
let renderer = CharDataRenderer::new(sim_id, memory);
|
||||||
let params = images.add(
|
let params = images.add(
|
||||||
@@ -115,10 +124,12 @@ impl CharacterDataWindow {
|
|||||||
CharDataParams {
|
CharDataParams {
|
||||||
palette: state.palette,
|
palette: state.palette,
|
||||||
index: state.index,
|
index: state.index,
|
||||||
|
color: config.colors[0],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
sim_id,
|
sim_id,
|
||||||
|
config,
|
||||||
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
||||||
palettes: memory.watch(sim_id, 0x0005f860, 16),
|
palettes: memory.watch(sim_id, 0x0005f860, 16),
|
||||||
params,
|
params,
|
||||||
@@ -226,17 +237,19 @@ impl CharacterDataWindow {
|
|||||||
self.params.write(CharDataParams {
|
self.params.write(CharDataParams {
|
||||||
palette: self.state.palette,
|
palette: self.state.palette,
|
||||||
index: self.state.index,
|
index: self.state.index,
|
||||||
|
color: self.config.colors[0],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_palette_colors(&self) -> [Color32; 4] {
|
fn load_palette_colors(&self) -> [Color32; 4] {
|
||||||
|
let color = self.config.colors[0];
|
||||||
let Some(offset) = self.state.palette.offset() else {
|
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 palette = self.palettes.borrow().read(offset);
|
||||||
let brightnesses = self.brightness.borrow();
|
let brightnesses = self.brightness.borrow();
|
||||||
let brts = brightnesses.read(0);
|
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) {
|
fn show_chardata(&mut self, ui: &mut Ui) {
|
||||||
@@ -262,6 +275,7 @@ impl AppWindow for CharacterDataWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, ui: &mut Ui) {
|
fn show(&mut self, ui: &mut Ui) {
|
||||||
|
self.config.refresh();
|
||||||
self.state.load(ui);
|
self.state.load(ui);
|
||||||
CentralPanel::default().show(ui, |ui| {
|
CentralPanel::default().show(ui, |ui| {
|
||||||
ui.horizontal_top(|ui| {
|
ui.horizontal_top(|ui| {
|
||||||
@@ -286,8 +300,8 @@ impl AppWindow for CharacterDataWindow {
|
|||||||
struct CharDataParams {
|
struct CharDataParams {
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
index: usize,
|
index: usize,
|
||||||
|
color: Color32,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CharDataRenderer {
|
struct CharDataRenderer {
|
||||||
chardata: MemoryView,
|
chardata: MemoryView,
|
||||||
brightness: MemoryView,
|
brightness: MemoryView,
|
||||||
@@ -306,8 +320,8 @@ impl ImageRenderer<2> for CharDataRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, params: &Self::Params, image: &mut [ImageBuffer; 2]) {
|
fn render(&mut self, params: &Self::Params, image: &mut [ImageBuffer; 2]) {
|
||||||
self.render_character(&mut image[0], params.palette, params.index);
|
self.render_character(&mut image[0], params.palette, params.index, params.color);
|
||||||
self.render_character_data(&mut image[1], params.palette);
|
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 {
|
if index >= 2048 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let palette = self.load_palette(palette);
|
let palette = self.load_palette(palette, color);
|
||||||
let chardata = self.chardata.borrow();
|
let chardata = self.chardata.borrow();
|
||||||
let character = chardata.range::<u16>(index * 8, 8);
|
let character = chardata.range::<u16>(index * 8, 8);
|
||||||
for (row, pixels) in character.enumerate() {
|
for (row, pixels) in character.enumerate() {
|
||||||
@@ -335,8 +355,8 @@ impl CharDataRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_character_data(&self, image: &mut ImageBuffer, palette: Palette) {
|
fn render_character_data(&self, image: &mut ImageBuffer, palette: Palette, color: Color32) {
|
||||||
let palette = self.load_palette(palette);
|
let palette = self.load_palette(palette, color);
|
||||||
let chardata = self.chardata.borrow();
|
let chardata = self.chardata.borrow();
|
||||||
for (row, pixels) in chardata.range::<u16>(0, 8 * 2048).enumerate() {
|
for (row, pixels) in chardata.range::<u16>(0, 8 * 2048).enumerate() {
|
||||||
let char_index = row / 8;
|
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 {
|
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 palette = self.palettes.borrow().read(offset);
|
||||||
let brightnesses = self.brightness.borrow();
|
let brightnesses = self.brightness.borrow();
|
||||||
let brts = brightnesses.read(0);
|
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 serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::{Config, SimConfig},
|
||||||
emulator::SimId,
|
emulator::SimId,
|
||||||
|
filesystem::Persistence,
|
||||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||||
memory::{MemoryClient, MemoryView},
|
memory::{MemoryClient, MemoryView},
|
||||||
window::{
|
window::{
|
||||||
@@ -44,9 +46,14 @@ pub struct FrameBufferWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 state: UiData<State> = UiData::new();
|
||||||
let renderer = FrameBufferRenderer::new(sim_id, memory);
|
let renderer = FrameBufferRenderer::new(sim_id, memory, persistence);
|
||||||
let params = images.add(
|
let params = images.add(
|
||||||
sim_id,
|
sim_id,
|
||||||
renderer,
|
renderer,
|
||||||
@@ -55,8 +62,6 @@ impl FrameBufferWindow {
|
|||||||
left: state.left,
|
left: state.left,
|
||||||
right: state.right,
|
right: state.right,
|
||||||
generic_palette: state.generic_palette,
|
generic_palette: state.generic_palette,
|
||||||
left_color: Color32::from_rgb(0xff, 0x00, 0x00),
|
|
||||||
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
@@ -138,7 +143,6 @@ impl FrameBufferWindow {
|
|||||||
left: self.state.left,
|
left: self.state.left,
|
||||||
right: self.state.right,
|
right: self.state.right,
|
||||||
generic_palette: self.state.generic_palette,
|
generic_palette: self.state.generic_palette,
|
||||||
..*self.params
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,18 +192,18 @@ struct FrameBufferParams {
|
|||||||
left: bool,
|
left: bool,
|
||||||
right: bool,
|
right: bool,
|
||||||
generic_palette: bool,
|
generic_palette: bool,
|
||||||
left_color: Color32,
|
|
||||||
right_color: Color32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FrameBufferRenderer {
|
struct FrameBufferRenderer {
|
||||||
|
config: Config<SimConfig>,
|
||||||
buffers: [MemoryView; 4],
|
buffers: [MemoryView; 4],
|
||||||
brightness: MemoryView,
|
brightness: MemoryView,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FrameBufferRenderer {
|
impl FrameBufferRenderer {
|
||||||
fn new(sim_id: SimId, memory: &MemoryClient) -> Self {
|
fn new(sim_id: SimId, memory: &MemoryClient, persistence: &Persistence) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
config: SimConfig::load(persistence, sim_id),
|
||||||
buffers: [
|
buffers: [
|
||||||
memory.watch(sim_id, 0x00000000, 0x6000),
|
memory.watch(sim_id, 0x00000000, 0x6000),
|
||||||
memory.watch(sim_id, 0x00008000, 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]) {
|
fn render(&mut self, params: &Self::Params, images: &mut [ImageBuffer; 1]) {
|
||||||
|
self.config.refresh();
|
||||||
let image = &mut images[0];
|
let image = &mut images[0];
|
||||||
|
|
||||||
let left_buffer = self.buffers[params.index].borrow();
|
let left_buffer = self.buffers[params.index].borrow();
|
||||||
@@ -230,15 +235,15 @@ impl ImageRenderer<1> for FrameBufferRenderer {
|
|||||||
|
|
||||||
let colors = if params.generic_palette {
|
let colors = if params.generic_palette {
|
||||||
[
|
[
|
||||||
utils::generic_palette(params.left_color),
|
utils::generic_palette(self.config.colors[0]),
|
||||||
utils::generic_palette(params.right_color),
|
utils::generic_palette(self.config.colors[1]),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
let brts = self.brightness.borrow().read::<[u8; 8]>(0);
|
let brts = self.brightness.borrow().read::<[u8; 8]>(0);
|
||||||
let shades = utils::parse_shades(&brts);
|
let shades = utils::parse_shades(&brts);
|
||||||
[
|
[
|
||||||
shades.map(|s| utils::shade(s, params.left_color)),
|
shades.map(|s| utils::shade(s, self.config.colors[0])),
|
||||||
shades.map(|s| utils::shade(s, params.right_color)),
|
shades.map(|s| utils::shade(s, self.config.colors[1])),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+17
-12
@@ -1,14 +1,16 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, CentralPanel, Checkbox, Color32, ComboBox, Image, ScrollArea, Slider, TextEdit,
|
Align, CentralPanel, Checkbox, ComboBox, Image, ScrollArea, Slider, TextEdit, TextureOptions,
|
||||||
TextureOptions, Ui, ViewportBuilder,
|
Ui, ViewportBuilder,
|
||||||
};
|
};
|
||||||
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::{Config, SimConfig},
|
||||||
emulator::SimId,
|
emulator::SimId,
|
||||||
|
filesystem::Persistence,
|
||||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||||
memory::{MemoryClient, MemoryView},
|
memory::{MemoryClient, MemoryView},
|
||||||
window::{
|
window::{
|
||||||
@@ -44,17 +46,20 @@ pub struct ObjectWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 state: UiData<State> = UiData::new();
|
||||||
let renderer = ObjectRenderer::new(sim_id, memory);
|
let renderer = ObjectRenderer::new(sim_id, memory, persistence);
|
||||||
let params = images.add(
|
let params = images.add(
|
||||||
sim_id,
|
sim_id,
|
||||||
renderer,
|
renderer,
|
||||||
ObjectParams {
|
ObjectParams {
|
||||||
index: state.index,
|
index: state.index,
|
||||||
generic_palette: state.generic_palette,
|
generic_palette: state.generic_palette,
|
||||||
left_color: Color32::from_rgb(0xff, 0x00, 0x00),
|
|
||||||
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
@@ -194,7 +199,6 @@ impl ObjectWindow {
|
|||||||
self.params.write(ObjectParams {
|
self.params.write(ObjectParams {
|
||||||
index: self.state.index,
|
index: self.state.index,
|
||||||
generic_palette: self.state.generic_palette,
|
generic_palette: self.state.generic_palette,
|
||||||
..*self.params
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,8 +246,6 @@ impl AppWindow for ObjectWindow {
|
|||||||
struct ObjectParams {
|
struct ObjectParams {
|
||||||
index: usize,
|
index: usize,
|
||||||
generic_palette: bool,
|
generic_palette: bool,
|
||||||
left_color: Color32,
|
|
||||||
right_color: Color32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Eye {
|
enum Eye {
|
||||||
@@ -252,6 +254,7 @@ enum Eye {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ObjectRenderer {
|
struct ObjectRenderer {
|
||||||
|
config: Config<SimConfig>,
|
||||||
chardata: MemoryView,
|
chardata: MemoryView,
|
||||||
objects: MemoryView,
|
objects: MemoryView,
|
||||||
brightness: MemoryView,
|
brightness: MemoryView,
|
||||||
@@ -259,8 +262,9 @@ struct ObjectRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectRenderer {
|
impl ObjectRenderer {
|
||||||
pub fn new(sim_id: SimId, memory: &MemoryClient) -> Self {
|
pub fn new(sim_id: SimId, memory: &MemoryClient, persistence: &Persistence) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
config: SimConfig::load(persistence, sim_id),
|
||||||
chardata: memory.watch(sim_id, 0x00078000, 0x8000),
|
chardata: memory.watch(sim_id, 0x00078000, 0x8000),
|
||||||
objects: memory.watch(sim_id, 0x0003e000, 0x2000),
|
objects: memory.watch(sim_id, 0x0003e000, 0x2000),
|
||||||
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
brightness: memory.watch(sim_id, 0x0005f824, 8),
|
||||||
@@ -302,8 +306,8 @@ impl ObjectRenderer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let color = match eye {
|
let color = match eye {
|
||||||
Eye::Left => params.left_color,
|
Eye::Left => self.config.colors[0],
|
||||||
Eye::Right => params.right_color,
|
Eye::Right => self.config.colors[1],
|
||||||
};
|
};
|
||||||
|
|
||||||
let char = chardata.read::<[u16; 8]>(obj.data.char_index);
|
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]) {
|
fn render(&mut self, params: &Self::Params, images: &mut [ImageBuffer; 2]) {
|
||||||
|
self.config.refresh();
|
||||||
images[0].clear();
|
images[0].clear();
|
||||||
self.render_object(&mut images[0], params, false, Eye::Left);
|
self.render_object(&mut images[0], params, false, Eye::Left);
|
||||||
self.render_object(&mut images[0], params, false, Eye::Right);
|
self.render_object(&mut images[0], params, false, Eye::Right);
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, Button, CentralPanel, Checkbox, Color32, Direction, Label, Layout, ScrollArea, TextEdit,
|
Align, Button, CentralPanel, Checkbox, Direction, Label, Layout, ScrollArea, TextEdit, Ui,
|
||||||
Ui, ViewportBuilder,
|
ViewportBuilder,
|
||||||
};
|
};
|
||||||
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
use egui_extras::{Column, Size, StripBuilder, TableBuilder};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::{Config, SimConfig},
|
||||||
emulator::SimId,
|
emulator::SimId,
|
||||||
|
filesystem::Persistence,
|
||||||
memory::{MemoryClient, MemoryRef, MemoryValue, MemoryView},
|
memory::{MemoryClient, MemoryRef, MemoryValue, MemoryView},
|
||||||
window::{
|
window::{
|
||||||
AppWindow,
|
AppWindow,
|
||||||
@@ -19,14 +21,16 @@ use super::utils;
|
|||||||
|
|
||||||
pub struct RegisterWindow {
|
pub struct RegisterWindow {
|
||||||
sim_id: SimId,
|
sim_id: SimId,
|
||||||
|
config: Config<SimConfig>,
|
||||||
memory: Arc<MemoryClient>,
|
memory: Arc<MemoryClient>,
|
||||||
registers: MemoryView,
|
registers: MemoryView,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegisterWindow {
|
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 {
|
Self {
|
||||||
sim_id,
|
sim_id,
|
||||||
|
config: SimConfig::load(persistence, sim_id),
|
||||||
memory: memory.clone(),
|
memory: memory.clone(),
|
||||||
registers: memory.watch(sim_id, 0x0005f800, 0x72),
|
registers: memory.watch(sim_id, 0x0005f800, 0x72),
|
||||||
}
|
}
|
||||||
@@ -366,7 +370,7 @@ impl RegisterWindow {
|
|||||||
});
|
});
|
||||||
body.row(row_height, |mut row| {
|
body.row(row_height, |mut row| {
|
||||||
row.col(|_ui| {});
|
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| {
|
row.col(|ui| {
|
||||||
ui.painter().rect_filled(
|
ui.painter().rect_filled(
|
||||||
ui.available_rect_before_wrap(),
|
ui.available_rect_before_wrap(),
|
||||||
@@ -641,6 +645,7 @@ impl AppWindow for RegisterWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, ui: &mut Ui) {
|
fn show(&mut self, ui: &mut Ui) {
|
||||||
|
self.config.refresh();
|
||||||
CentralPanel::default().show(ui, |ui| {
|
CentralPanel::default().show(ui, |ui| {
|
||||||
ScrollArea::vertical().show(ui, |ui| {
|
ScrollArea::vertical().show(ui, |ui| {
|
||||||
ui.horizontal_top(|ui| {
|
ui.horizontal_top(|ui| {
|
||||||
|
|||||||
+20
-4
@@ -14,7 +14,9 @@ use num_traits::{FromPrimitive, ToPrimitive};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::{Config, SimConfig},
|
||||||
emulator::SimId,
|
emulator::SimId,
|
||||||
|
filesystem::Persistence,
|
||||||
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
images::{ImageBuffer, ImageParams, ImageRenderer, ImageTextureLoader},
|
||||||
memory::{MemoryClient, MemoryRef, MemoryView},
|
memory::{MemoryClient, MemoryRef, MemoryView},
|
||||||
window::{
|
window::{
|
||||||
@@ -47,6 +49,7 @@ impl Default for State {
|
|||||||
|
|
||||||
pub struct WorldWindow {
|
pub struct WorldWindow {
|
||||||
sim_id: SimId,
|
sim_id: SimId,
|
||||||
|
config: Config<SimConfig>,
|
||||||
memory: Arc<MemoryClient>,
|
memory: Arc<MemoryClient>,
|
||||||
worlds: MemoryView,
|
worlds: MemoryView,
|
||||||
bgmaps: MemoryView,
|
bgmaps: MemoryView,
|
||||||
@@ -55,7 +58,13 @@ pub struct WorldWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 state: UiData<State> = UiData::new();
|
||||||
let renderer = WorldRenderer::new(sim_id, memory);
|
let renderer = WorldRenderer::new(sim_id, memory);
|
||||||
let params = images.add(
|
let params = images.add(
|
||||||
@@ -64,12 +73,13 @@ impl WorldWindow {
|
|||||||
WorldParams {
|
WorldParams {
|
||||||
index: state.index,
|
index: state.index,
|
||||||
generic_palette: state.generic_palette,
|
generic_palette: state.generic_palette,
|
||||||
left_color: Color32::from_rgb(0xff, 0x00, 0x00),
|
left_color: config.colors[0],
|
||||||
right_color: Color32::from_rgb(0x00, 0xc6, 0xf0),
|
right_color: config.colors[1],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
sim_id,
|
sim_id,
|
||||||
|
config,
|
||||||
memory: memory.clone(),
|
memory: memory.clone(),
|
||||||
worlds: memory.watch(sim_id, 0x0003d800, 0x400),
|
worlds: memory.watch(sim_id, 0x0003d800, 0x400),
|
||||||
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
|
bgmaps: memory.watch(sim_id, 0x00020000, 0x20000),
|
||||||
@@ -538,6 +548,12 @@ impl AppWindow for WorldWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, ui: &mut Ui) {
|
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);
|
self.state.load(ui);
|
||||||
CentralPanel::default().show(ui, |ui| {
|
CentralPanel::default().show(ui, |ui| {
|
||||||
ui.horizontal_top(|ui| {
|
ui.horizontal_top(|ui| {
|
||||||
@@ -944,7 +960,7 @@ impl WorldHeader {
|
|||||||
let ron = data & 0x4000 != 0;
|
let ron = data & 0x4000 != 0;
|
||||||
let mode = WorldMode::from_u16((data >> 12) & 0x3).unwrap();
|
let mode = WorldMode::from_u16((data >> 12) & 0x3).unwrap();
|
||||||
let scx = (data >> 10) as u32 & 0x03;
|
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 over = data & 0x0080 != 0;
|
||||||
let end = data & 0x0040 != 0;
|
let end = data & 0x0040 != 0;
|
||||||
let base = (data & 0x000f) as usize;
|
let base = (data & 0x000f) as usize;
|
||||||
|
|||||||
Reference in New Issue
Block a user