Make properties editable

This commit is contained in:
2025-02-15 18:33:18 -05:00
parent 7356287030
commit b888d1140a
6 changed files with 136 additions and 90 deletions
+16 -9
View File
@@ -1,7 +1,7 @@
use std::{
collections::HashMap,
fmt::Debug,
sync::{atomic::AtomicU64, Arc, RwLock, RwLockReadGuard, TryLockError, Weak},
sync::{atomic::AtomicU64, Arc, Mutex, RwLock, RwLockReadGuard, TryLockError, Weak},
};
use bytemuck::BoxBytes;
@@ -10,34 +10,41 @@ use tracing::warn;
use crate::emulator::{EmulatorClient, EmulatorCommand, SimId};
pub struct MemoryMonitor {
pub struct MemoryClient {
client: EmulatorClient,
regions: HashMap<MemoryRange, Weak<MemoryRegion>>,
regions: Mutex<HashMap<MemoryRange, Weak<MemoryRegion>>>,
}
impl MemoryMonitor {
impl MemoryClient {
pub fn new(client: EmulatorClient) -> Self {
Self {
client,
regions: HashMap::new(),
regions: Mutex::new(HashMap::new()),
}
}
pub fn view(&mut self, sim: SimId, start: u32, length: usize) -> MemoryView {
pub fn watch(&self, sim: SimId, start: u32, length: usize) -> MemoryView {
let range = MemoryRange { sim, start, length };
let region = self
.regions
let mut regions = self.regions.lock().unwrap_or_else(|e| e.into_inner());
let region = regions
.get(&range)
.and_then(|r| r.upgrade())
.unwrap_or_else(|| {
let region = Arc::new(MemoryRegion::new(start, length));
self.regions.insert(range, Arc::downgrade(&region));
regions.insert(range, Arc::downgrade(&region));
self.client
.send_command(EmulatorCommand::WatchMemory(range, Arc::downgrade(&region)));
region
});
MemoryView { region }
}
pub fn write<T: bytemuck::NoUninit>(&self, sim: SimId, address: u32, data: &T) {
let data = bytemuck::bytes_of(data).to_vec();
let (tx, _) = oneshot::channel();
self.client
.send_command(EmulatorCommand::WriteMemory(sim, address, data, tx));
}
}
fn aligned_memory(start: u32, length: usize) -> BoxBytes {