more chips
more docs
This commit is contained in:
@@ -1,88 +1,91 @@
|
||||
use eframe::egui;
|
||||
use core::periph::at28c256::At28C256;
|
||||
use core::computers::rom_only::RomOnlyComputer;
|
||||
struct MyApp {
|
||||
address: String,
|
||||
data: String,
|
||||
cpu_read: bool,
|
||||
computer: RomOnlyComputer
|
||||
use macroquad::prelude::*;
|
||||
use core::traits::backplane::Backplane;
|
||||
|
||||
#[macroquad::main("RomOnlyComputer GUI")]
|
||||
async fn main() {
|
||||
let mut computer = RomOnlyComputer {
|
||||
rom: At28C256::new(0x0000, 0x3fff, [0xea; 0x4000].to_vec()),
|
||||
data_bus: 0x00,
|
||||
address_bus: 0x0000,
|
||||
read_mode: true,
|
||||
};
|
||||
|
||||
let mut input_addr = String::new();
|
||||
let mut input_data = String::new();
|
||||
|
||||
loop {
|
||||
clear_background(GRAY);
|
||||
let mut y = 20.0;
|
||||
|
||||
draw_text("RomOnlyComputer", 20.0, y, 30.0, WHITE);
|
||||
y += 40.0;
|
||||
|
||||
// Address input
|
||||
draw_text("Address Bus (hex):", 20.0, y, 24.0, WHITE);
|
||||
y += 30.0;
|
||||
draw_input_box(&mut input_addr, 20.0, y, 100.0, 30.0);
|
||||
y += 40.0;
|
||||
|
||||
// Data input
|
||||
draw_text("Data Bus (hex):", 20.0, y, 24.0, WHITE);
|
||||
y += 30.0;
|
||||
draw_input_box(&mut input_data, 20.0, y, 100.0, 30.0);
|
||||
y += 40.0;
|
||||
|
||||
// Read mode checkbox
|
||||
let read_mode_rect = Rect::new(20.0, y, 20.0, 20.0);
|
||||
draw_rectangle_lines(read_mode_rect.x, read_mode_rect.y, read_mode_rect.w, read_mode_rect.h, 2.0, WHITE);
|
||||
if computer.read_mode() {
|
||||
draw_text("✔", read_mode_rect.x + 2.0, read_mode_rect.y + 18.0, 20.0, GREEN);
|
||||
}
|
||||
draw_text("Read Mode", read_mode_rect.x + 30.0, read_mode_rect.y + 18.0, 20.0, WHITE);
|
||||
if is_mouse_button_pressed(MouseButton::Left) && read_mode_rect.contains(mouse_position().into()) {
|
||||
computer.set_read_mode(!computer.read_mode());
|
||||
}
|
||||
y += 40.0;
|
||||
|
||||
// Tick button
|
||||
let button_rect = Rect::new(20.0, y, 100.0, 40.0);
|
||||
draw_rectangle(button_rect.x, button_rect.y, button_rect.w, button_rect.h, DARKGRAY);
|
||||
draw_text("Tick", button_rect.x + 25.0, button_rect.y + 28.0, 24.0, WHITE);
|
||||
if is_mouse_button_pressed(MouseButton::Left) && button_rect.contains(mouse_position().into()) {
|
||||
if let (Ok(addr), Ok(data)) = (
|
||||
u16::from_str_radix(&input_addr.trim_start_matches("0x"), 16),
|
||||
u8::from_str_radix(&input_data.trim_start_matches("0x"), 16),
|
||||
) {
|
||||
computer.set_address_bus(addr);
|
||||
computer.set_data_bus(data);
|
||||
// let result = computer.rom.tick(addr, data, computer.read_mode);
|
||||
println!(
|
||||
"Tick: A=${:04X} D=${:02X} R={} -> ", // ${:02X}",
|
||||
addr, data, computer.read_mode, // result
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
next_frame().await;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for MyApp {
|
||||
fn default() -> Self {
|
||||
let rom_data = vec![0x01, 0x02, 0x03, 0x04];
|
||||
Self {
|
||||
address: String::new(),
|
||||
data: String::new(),
|
||||
cpu_read: false,
|
||||
computer: RomOnlyComputer::program(rom_data), // Example memory: 0x00 to 0xFF
|
||||
fn draw_input_box(value: &mut String, x: f32, y: f32, w: f32, h: f32) {
|
||||
draw_rectangle(x, y, w, h, DARKGRAY);
|
||||
let mut display = value.clone();
|
||||
if get_time() as u64 % 2 == 0 {
|
||||
display.push('_');
|
||||
}
|
||||
draw_text(&display, x + 5.0, y + 22.0, 20.0, WHITE);
|
||||
|
||||
let rect = Rect::new(x, y, w, h);
|
||||
if is_mouse_button_pressed(MouseButton::Left) && rect.contains(mouse_position().into()) {
|
||||
if let Some(chr) = get_char_pressed() {
|
||||
if chr.is_ascii_hexdigit() && value.len() < 4 {
|
||||
value.push(chr.to_ascii_uppercase());
|
||||
}
|
||||
}
|
||||
if is_key_pressed(KeyCode::Backspace) {
|
||||
value.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Memory Inspector");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Address:");
|
||||
ui.text_edit_singleline(&mut self.address);
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Data:");
|
||||
ui.text_edit_singleline(&mut self.data);
|
||||
});
|
||||
|
||||
ui.checkbox(&mut self.cpu_read, "CPU Read");
|
||||
|
||||
if ui.button("Tick").clicked() {
|
||||
println!(
|
||||
"Ticked with Address: {}, Data: {}, CPU Read: {}",
|
||||
self.address, self.data, self.cpu_read
|
||||
);
|
||||
}
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(format!("Address Bus ${:?}", self.address).as_str());
|
||||
ui.label(format!("Data Bus ${:?}", self.data).as_str());
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
ui.label("Memory View (Hex Dump):");
|
||||
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
let bytes_per_row = 16;
|
||||
for (i, chunk) in self.computer.rom_chunks(bytes_per_row).enumerate() {
|
||||
let address = i * bytes_per_row;
|
||||
let hex_values: String = chunk
|
||||
.iter()
|
||||
.map(|b| format!("{:02X} ", b))
|
||||
.collect();
|
||||
|
||||
let ascii_values: String = chunk
|
||||
.iter()
|
||||
.map(|b| {
|
||||
if b.is_ascii_graphic() {
|
||||
*b as char
|
||||
} else {
|
||||
'.'
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
ui.monospace(format!("{:08X}: {:<48} {}", address, hex_values, ascii_values));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> eframe::Result<()> {
|
||||
let options = eframe::NativeOptions::default();
|
||||
eframe::run_native(
|
||||
"Memory Inspector",
|
||||
options,
|
||||
Box::new(|_cc| Box::new(MyApp::default())),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user