ram / rom switch for debugger

This commit is contained in:
kirjavascript 2023-03-11 18:33:50 +00:00
parent fc9a54122b
commit fbd4c4149a
3 changed files with 28 additions and 26 deletions

View file

@ -1,11 +1,11 @@
[package]
name = "frontend"
default-run = "frontend_bin"
default-run = "trueLMAO"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "frontend_bin"
name = "trueLMAO"
path = "src/main.rs"
[lib]

View file

@ -32,16 +32,6 @@ impl App {
..egui::Visuals::default()
});
// let mut fonts = egui::FontDefinitions::default();
// fonts
// .families
// .entry(egui::FontFamily::Proportional)
// .or_default()
// .push("Hack".to_string());
// cc.egui_ctx.set_fonts(fonts);
// Load previous app state (if any).
// Note that you must enable the `persistence` feature for this to work.
// if let Some(storage) = cc.storage {

View file

@ -6,12 +6,14 @@ use vram::VRAM;
pub struct Debug {
pub vram: VRAM,
tab_index: usize,
}
impl Default for Debug {
fn default() -> Self {
Self {
vram: Default::default(),
tab_index: 0,
}
}
}
@ -22,20 +24,32 @@ impl Debug {
palette::palette_window(&ctx, &emu);
self.vram.render(&ctx, &emu);
const ASCII: &str = r##"................................ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~................................. ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ"##;
const ASCII: &str = r##"................................ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~................................. ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ"##;
egui::Window::new("memory")
.show(ctx, |ui| {
// TODO: difference accessors
let tabs: [(&str, usize, Box<dyn Fn(usize) -> u8>); 2] = [
("RAM", 0x10000, Box::new(|offset: usize|
emu.core.mem.ram[offset])),
("ROM", emu.core.mem.rom.size(), Box::new(|offset: usize|
emu.core.mem.rom.read_byte(offset as _))),
];
// let tabs = [
// (0xFFFF, &emu.core.mem.ram),
// ];
let (selected_name, total_bytes, accessor) = &tabs[self.tab_index];
ui.horizontal(|ui| {
for (i, (name, _, _)) in tabs.iter().enumerate() {
if ui
.selectable_label(selected_name == name, *name)
.clicked()
{
self.tab_index = i;
}
}
});
// emu.core.mem.ram
let bytes_row = 16;
let total_bytes = 0xFFFF;
let rows = total_bytes / bytes_row;
egui::ScrollArea::vertical()
@ -44,17 +58,15 @@ impl Debug {
for i in row_range {
let offset = i * bytes_row;
let bytes = (offset..offset+bytes_row)
.enumerate()
.map(|(idx, offset)| {
format!(" {:02X}", emu.core.mem.ram[idx + offset])
.map(|offset| {
format!(" {:02X}", accessor(offset))
}).collect::<String>();
let ascii = (offset..offset+bytes_row)
.enumerate()
.map(|(idx, offset)| {
format!("{}", ASCII.chars().nth(emu.core.mem.ram[idx + offset] as _).unwrap_or('.'))
.map(|offset| {
format!("{}", ASCII.chars().nth(accessor(offset) as _).unwrap_or('.'))
}).collect::<String>();
ui.monospace(format!("{:04X} {} {}", i, bytes, ascii));
ui.monospace(format!("{:04X} {} {}", i * 16, bytes, ascii));
}
});