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] [package]
name = "frontend" name = "frontend"
default-run = "frontend_bin" default-run = "trueLMAO"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[[bin]] [[bin]]
name = "frontend_bin" name = "trueLMAO"
path = "src/main.rs" path = "src/main.rs"
[lib] [lib]

View file

@ -32,16 +32,6 @@ impl App {
..egui::Visuals::default() ..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). // Load previous app state (if any).
// Note that you must enable the `persistence` feature for this to work. // Note that you must enable the `persistence` feature for this to work.
// if let Some(storage) = cc.storage { // if let Some(storage) = cc.storage {

View file

@ -6,12 +6,14 @@ use vram::VRAM;
pub struct Debug { pub struct Debug {
pub vram: VRAM, pub vram: VRAM,
tab_index: usize,
} }
impl Default for Debug { impl Default for Debug {
fn default() -> Self { fn default() -> Self {
Self { Self {
vram: Default::default(), vram: Default::default(),
tab_index: 0,
} }
} }
} }
@ -22,20 +24,32 @@ impl Debug {
palette::palette_window(&ctx, &emu); palette::palette_window(&ctx, &emu);
self.vram.render(&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") egui::Window::new("memory")
.show(ctx, |ui| { .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 = [ let (selected_name, total_bytes, accessor) = &tabs[self.tab_index];
// (0xFFFF, &emu.core.mem.ram),
// ]; 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 bytes_row = 16;
let total_bytes = 0xFFFF;
let rows = total_bytes / bytes_row; let rows = total_bytes / bytes_row;
egui::ScrollArea::vertical() egui::ScrollArea::vertical()
@ -44,17 +58,15 @@ impl Debug {
for i in row_range { for i in row_range {
let offset = i * bytes_row; let offset = i * bytes_row;
let bytes = (offset..offset+bytes_row) let bytes = (offset..offset+bytes_row)
.enumerate() .map(|offset| {
.map(|(idx, offset)| { format!(" {:02X}", accessor(offset))
format!(" {:02X}", emu.core.mem.ram[idx + offset])
}).collect::<String>(); }).collect::<String>();
let ascii = (offset..offset+bytes_row) let ascii = (offset..offset+bytes_row)
.enumerate() .map(|offset| {
.map(|(idx, offset)| { format!("{}", ASCII.chars().nth(accessor(offset) as _).unwrap_or('.'))
format!("{}", ASCII.chars().nth(emu.core.mem.ram[idx + offset] as _).unwrap_or('.'))
}).collect::<String>(); }).collect::<String>();
ui.monospace(format!("{:04X} {} {}", i, bytes, ascii)); ui.monospace(format!("{:04X} {} {}", i * 16, bytes, ascii));
} }
}); });