Compare commits

...
6 Commits
15 changed files with 100 additions and 43 deletions
Generated
+1 -1
View File
@@ -2029,7 +2029,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "lemur"
version = "0.12.4"
version = "0.13.1"
dependencies = [
"anyhow",
"atoi",
+1 -1
View File
@@ -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.12.4"
version = "0.13.1"
edition = "2024"
[dependencies]
+5 -1
View File
@@ -265,7 +265,8 @@ impl Emulator {
} else if let Some(cart) = self.carts[index].as_mut()
&& cart.is_watching()
{
cart.restart_watching();
cart.reload()?;
sim.load_cart(cart.rom.clone(), cart.sram.clone())?;
}
let mut profiling = false;
if let Some(profiler) = self.profilers[sim_id.to_index()].as_ref()
@@ -946,6 +947,9 @@ pub struct EmulatorClient {
}
impl EmulatorClient {
pub fn has_player_2(&self) -> bool {
self.sim_state(SimId::Player2) != SimState::Uninitialized
}
pub fn sim_state(&self, sim_id: SimId) -> SimState {
self.sim_state[sim_id.to_index()].load(Ordering::Acquire)
}
+19 -4
View File
@@ -22,10 +22,7 @@ pub struct Cart {
impl Cart {
pub fn load(file_path: &Path, sim_id: SimId, watch: bool) -> Result<Self> {
let rom = fs::read(file_path)?;
let (rom, info) = try_parse_isx(file_path, &rom)
.or_else(|| try_parse_elf(file_path, &rom))
.unwrap_or_else(|| (rom, GameInfo::empty(file_path)));
let (rom, info) = Self::read_rom(file_path)?;
let mut sram_file = File::options()
.read(true)
@@ -66,6 +63,16 @@ impl Cart {
})
}
pub fn reload(&mut self) -> Result<()> {
let (rom, info) = Self::read_rom(&self.file_path)?;
self.rom = rom;
self.info = Arc::new(info);
if self.is_watching() {
self.restart_watching();
}
Ok(())
}
pub fn save_sram(&mut self) -> Result<()> {
self.sram_file.seek(SeekFrom::Start(0))?;
self.sram_file.write_all(&self.sram)?;
@@ -92,6 +99,14 @@ impl Cart {
self.changed = Arc::new(AtomicBool::new(false));
self.watcher = None;
}
fn read_rom(file_path: &Path) -> Result<(Vec<u8>, GameInfo)> {
let rom = fs::read(file_path)?;
let (rom, info) = try_parse_isx(file_path, &rom)
.or_else(|| try_parse_elf(file_path, &rom))
.unwrap_or_else(|| (rom, GameInfo::empty(file_path)));
Ok((rom, info))
}
}
fn build_watcher(file_path: &Path, changed: Arc<AtomicBool>) -> Option<notify::RecommendedWatcher> {
+3 -3
View File
@@ -28,11 +28,11 @@ mod utils;
mod vip;
pub trait AppWindow {
fn sim_id(&self) -> SimId {
SimId::Player1
fn sim_id(&self) -> Option<SimId> {
None
}
fn image_url(&self, name: &str) -> String {
format!("vip://{}/{name}", self.sim_id())
format!("vip://{}/{name}", self.sim_id().unwrap_or(SimId::Player1))
}
fn initial_viewport(&self) -> ViewportBuilder;
fn show(&mut self, ui: &mut Ui);
+44 -6
View File
@@ -53,6 +53,7 @@ pub struct GameWindow {
children: ViewportIdMap<ChildWindowWrapper>,
child_states: UiData<ViewportIdMap<ChildState>>,
queued_children: Vec<ChildWindow>,
show_player_name: bool,
}
impl GameWindow {
@@ -94,6 +95,7 @@ impl GameWindow {
children: ViewportIdMap::default(),
child_states: UiData::new(),
queued_children: vec![],
show_player_name: false,
}
}
@@ -176,6 +178,11 @@ impl GameWindow {
};
let mut viewport = child.initial_viewport();
let title = viewport.title.clone().unwrap();
let sim_id = child.sim_id();
if let Some(sim_id) = sim_id && self.show_player_name {
viewport.title = Some(format!("{title} ({sim_id})"));
}
if let Some(state) = self.child_states.get(&viewport_id) {
viewport.position = Some(state.position);
viewport.inner_size = Some(state.size);
@@ -184,6 +191,8 @@ impl GameWindow {
viewport_id,
ChildWindowWrapper {
app: Arc::new(Mutex::new(child)),
title,
sim_id,
updates: Some(viewport),
close_requested: Arc::new(AtomicBool::new(false)),
},
@@ -371,7 +380,7 @@ impl GameWindow {
});
ui.menu_button("Options", |ui| self.show_options_menu(ui));
ui.menu_button("Multiplayer", |ui| {
let has_player_2 = self.client.sim_state(SimId::Player2) != SimState::Uninitialized;
let has_player_2 = self.client.has_player_2();
if self.sim_id == SimId::Player1
&& !has_player_2
&& ui.button("Open Player 2").clicked()
@@ -623,8 +632,8 @@ impl GameWindow {
}
impl AppWindow for GameWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
@@ -639,6 +648,30 @@ impl AppWindow for GameWindow {
}
fn show(&mut self, ui: &mut Ui) {
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)));
for (viewport_id, child) in &self.children {
if let Some(sim_id) = child.sim_id {
ui.send_viewport_cmd_to(
*viewport_id,
ViewportCommand::Title(format!("{} ({sim_id})", child.title)),
);
}
}
self.show_player_name = true;
} else if self.show_player_name && !has_player_2 {
ui.send_viewport_cmd(ViewportCommand::Title("Lemur".to_string()));
for (viewport_id, child) in &self.children {
if child.sim_id.is_some() {
ui.send_viewport_cmd_to(
*viewport_id,
ViewportCommand::Title(child.title.clone()),
);
}
}
self.show_player_name = false;
}
self.child_states.load(ui);
let dimensions = {
let bounds = ui.content_rect();
@@ -690,12 +723,15 @@ impl AppWindow for GameWindow {
let app = child.app.clone();
let viewport_builder = child.updates.take().unwrap_or_default();
let close_requested = child.close_requested.clone();
if let Some(rect) = ui.input_for(*id, |inp| inp.viewport().outer_rect) {
if let (Some(outer), Some(inner)) = ui.input_for(*id, |inp| {
let viewport = inp.viewport();
(viewport.outer_rect, viewport.inner_rect)
}) {
self.child_states.insert(
*id,
ChildState {
position: rect.min,
size: rect.size(),
position: outer.min,
size: inner.size(),
},
);
}
@@ -742,6 +778,8 @@ struct ColorPickerState {
struct ChildWindowWrapper {
app: Arc<Mutex<AppWrapper>>,
title: String,
sim_id: Option<SimId>,
updates: Option<ViewportBuilder>,
close_requested: Arc<AtomicBool>,
}
+3 -3
View File
@@ -42,13 +42,13 @@ impl GdbServerWindow {
}
impl AppWindow for GdbServerWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("GDB Server ({})", self.sim_id))
.with_title("GDB Server")
.with_inner_size((300.0, 200.0))
}
+3 -3
View File
@@ -82,13 +82,13 @@ impl ProfileWindow {
}
impl AppWindow for ProfileWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Profiler ({})", self.sim_id))
.with_title("Profiler")
.with_inner_size((300.0, 200.0))
}
+3 -3
View File
@@ -29,13 +29,13 @@ impl TerminalWindow {
}
impl AppWindow for TerminalWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Terminal ({})", self.sim_id))
.with_title("Terminal")
.with_inner_size((640.0, 480.0))
}
+3 -3
View File
@@ -191,13 +191,13 @@ impl BgMapWindow {
}
impl AppWindow for BgMapWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("BG Map Data ({})", self.sim_id))
.with_title("BG Map Data")
.with_inner_size((640.0, 480.0))
}
+3 -3
View File
@@ -251,13 +251,13 @@ impl CharacterDataWindow {
}
impl AppWindow for CharacterDataWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Character Data ({})", self.sim_id))
.with_title("Character Data")
.with_inner_size((640.0, 480.0))
}
+3 -3
View File
@@ -151,13 +151,13 @@ impl FrameBufferWindow {
}
impl AppWindow for FrameBufferWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Frame Buffers ({})", self.sim_id))
.with_title("Frame Buffers")
.with_inner_size((640.0, 480.0))
}
+3 -3
View File
@@ -207,13 +207,13 @@ impl ObjectWindow {
}
impl AppWindow for ObjectWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Object Data ({})", self.sim_id))
.with_title("Object Data")
.with_inner_size((640.0, 500.0))
}
+3 -3
View File
@@ -630,13 +630,13 @@ fn read_address<T: MemoryValue>(registers: &MemoryRef, address: usize) -> T {
}
impl AppWindow for RegisterWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Registers ({})", self.sim_id))
.with_title("Registers")
.with_inner_size((800.0, 480.0))
}
+3 -3
View File
@@ -527,13 +527,13 @@ impl WorldWindow {
}
impl AppWindow for WorldWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
Some(self.sim_id)
}
fn initial_viewport(&self) -> ViewportBuilder {
ViewportBuilder::default()
.with_title(format!("Worlds ({})", self.sim_id))
.with_title("Worlds")
.with_inner_size((640.0, 520.0))
}