emma now has ability to decode an instruction and to display video and system memory
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct App;
|
||||
|
||||
impl UiBuilder for App {
|
||||
fn do_ui(&mut self, ui: &Ui<Self>) {
|
||||
#[cfg(feature = "docking")]
|
||||
{
|
||||
ui.dock_space_over_viewport(0, imgui::DockNodeFlags::None);
|
||||
}
|
||||
ui.show_demo_window(None);
|
||||
|
||||
}
|
||||
}*/
|
||||
@@ -1,8 +1,6 @@
|
||||
use easy_imgui::{Ui, UiBuilder};
|
||||
use easy_imgui_window::{MainWindow, MainWindowWithRenderer};
|
||||
use winit::{application::ApplicationHandler, event_loop::ActiveEventLoop, window::{Window, WindowAttributes}};
|
||||
|
||||
|
||||
/*
|
||||
pub struct Chip8Display {
|
||||
pub window: MainWindowWithRenderer,
|
||||
}
|
||||
@@ -54,15 +52,6 @@ impl ApplicationHandler for Chip8AppHandler {
|
||||
if window.main_window().window().id() != window_id {
|
||||
continue;
|
||||
}
|
||||
let res = window.window_event(
|
||||
&mut self,
|
||||
&event,
|
||||
easy_imgui_window::EventFlags::empty(),
|
||||
);
|
||||
if res.window_closed {
|
||||
event_loop.exit();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fn new_events(&mut self, _event_loop: &ActiveEventLoop, _cause: winit::event::StartCause) {
|
||||
@@ -77,3 +66,4 @@ impl ApplicationHandler for Chip8AppHandler {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -1,3 +1,7 @@
|
||||
pub mod app;
|
||||
|
||||
pub mod gui {
|
||||
pub mod display;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod support;
|
||||
+117
-68
@@ -1,87 +1,128 @@
|
||||
use easy_imgui_window::{
|
||||
easy_imgui as imgui,
|
||||
easy_imgui_renderer::Renderer,
|
||||
winit::{
|
||||
event_loop::{ActiveEventLoop, EventLoop},
|
||||
window::Window,
|
||||
},
|
||||
MainWindow, MainWindowWithRenderer,
|
||||
};
|
||||
use trevors_chip8_toy::gui::display::{Chip8App, Chip8AppHandler};
|
||||
use std::rc::Rc;
|
||||
use trevors_chip8_core::parts::CPU::fill_chip8_instructions;
|
||||
use trevors_chip8_toy::support;
|
||||
use winit::{event::WindowEvent, event_loop::EventLoop};
|
||||
|
||||
use imgui::*;
|
||||
/*
|
||||
pub fn display_instruction_table(current_index: u32, ui: &Ui<App>) -> u32 {
|
||||
let to_display = fill_chip8_instructions();
|
||||
let mut return_index = current_index;
|
||||
let current_instruction = to_display.get(return_index as usize).unwrap();
|
||||
ui.text("Instructions");
|
||||
ui.set_next_item_width(100f32);
|
||||
ui.with_group(|| {
|
||||
ui.text(format!("{}", current_instruction.description).as_str());
|
||||
if current_instruction.arguments.is_empty() {
|
||||
ui.text("No Parameters");
|
||||
} else {
|
||||
for current_parameter in current_instruction.arguments {
|
||||
ui.text(format!("{}", current_parameter.mask).as_str());
|
||||
}
|
||||
}
|
||||
ui.text(format!("{:#}", current_instruction.arguments).as_str());
|
||||
ui.text("This is where cool stuff happens part 2");
|
||||
});
|
||||
ui.same_line();
|
||||
ui.with_group(|| {
|
||||
for (index, current) in to_display.iter().enumerate() {
|
||||
if ui
|
||||
.selectable_config(current.id.clone())
|
||||
.selected(index == return_index as usize)
|
||||
.build()
|
||||
{
|
||||
return_index = index as u32;
|
||||
}
|
||||
}
|
||||
});
|
||||
return_index
|
||||
}
|
||||
*/
|
||||
|
||||
fn chip8_instructions(initial_index: u32, ui: &mut Ui) -> u32 {
|
||||
let to_display = fill_chip8_instructions();
|
||||
let mut return_index = initial_index;
|
||||
let instruction_to_display = to_display.get(return_index as usize).unwrap();
|
||||
let instruction_window = ui
|
||||
.window("Instructions")
|
||||
.size([400.0, 400.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text("This should be my current instruction example");
|
||||
ui.same_line();
|
||||
ui.set_next_item_width(-1.0f32);
|
||||
for (index, instruction) in to_display.iter().enumerate() {
|
||||
if ui
|
||||
.selectable_config(instruction.id.to_string())
|
||||
.selected(index as u32 == return_index)
|
||||
.build()
|
||||
{
|
||||
return_index = index as u32;
|
||||
println!("RETURN INDEX {return_index}");
|
||||
}
|
||||
}
|
||||
});
|
||||
return_index
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut value = 0;
|
||||
let choices = ["test test this is 1", "test test this is 2"];
|
||||
|
||||
let mut selected_instruction = 0;
|
||||
|
||||
support::simple_init(file!(), move |_, ui| {
|
||||
selected_instruction = chip8_instructions(selected_instruction, ui);
|
||||
|
||||
ui.window("Hello world")
|
||||
.size([300.0, 110.0], Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text_wrapped("Hello world!");
|
||||
if ui.button(choices[value]) {
|
||||
value += 1;
|
||||
value %= 2;
|
||||
}
|
||||
|
||||
ui.button("This...is...imgui-rs!");
|
||||
ui.separator();
|
||||
let mouse_pos = ui.io().mouse_pos;
|
||||
ui.text(format!(
|
||||
"Mouse Position: ({:.1},{:.1})",
|
||||
mouse_pos[0], mouse_pos[1]
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
/*
|
||||
fn main() {
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
|
||||
let mut main = Chip8AppHandler {
|
||||
windows: vec![],
|
||||
app: Chip8App,
|
||||
};
|
||||
|
||||
let mut main = AppHandler::<App>::default();
|
||||
main.attributes().title = String::from("Example-420");
|
||||
|
||||
event_loop.run_app(&mut main).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct AppHandler {
|
||||
windows: Vec<MainWindowWithRenderer>,
|
||||
app: App,
|
||||
pub struct App {
|
||||
pub selected_instruction_index: u32,
|
||||
}
|
||||
|
||||
impl winit::application::ApplicationHandler for AppHandler {
|
||||
fn suspended(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
self.windows.clear();
|
||||
}
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let wattr_1 = Window::default_attributes().with_title("Example #1");
|
||||
let main_window_1 = MainWindow::new::<()>(&event_loop, wattr_1).unwrap();
|
||||
let mut window_1 = MainWindowWithRenderer::new(main_window_1);
|
||||
impl App {}
|
||||
|
||||
let wattr_2 = Window::default_attributes().with_title("Example #2");
|
||||
let main_window_2 = MainWindow::new::<()>(&event_loop, wattr_2).unwrap();
|
||||
// The GL context can be reused, but the imgui context cannot
|
||||
let mut renderer_2 = Renderer::new(Rc::clone(window_1.renderer().gl_context())).unwrap();
|
||||
renderer_2.set_background_color(Some(imgui::Color::GREEN));
|
||||
let window_2 = MainWindowWithRenderer::new_with_renderer(main_window_2, renderer_2);
|
||||
|
||||
self.windows.push(window_1);
|
||||
self.windows.push(window_2);
|
||||
}
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &ActiveEventLoop,
|
||||
window_id: winit::window::WindowId,
|
||||
event: winit::event::WindowEvent,
|
||||
) {
|
||||
for window in &mut self.windows {
|
||||
if window.main_window().window().id() != window_id {
|
||||
continue;
|
||||
}
|
||||
let res = window.window_event(
|
||||
&mut self.app,
|
||||
&event,
|
||||
easy_imgui_window::EventFlags::empty(),
|
||||
);
|
||||
if res.window_closed {
|
||||
event_loop.exit();
|
||||
}
|
||||
break;
|
||||
impl Application for App {
|
||||
type UserEvent = ();
|
||||
type Data = ();
|
||||
fn new(_: Args<()>) -> App {
|
||||
App {
|
||||
selected_instruction_index: 0,
|
||||
}
|
||||
}
|
||||
fn new_events(&mut self, _event_loop: &ActiveEventLoop, _cause: winit::event::StartCause) {
|
||||
for window in &mut self.windows {
|
||||
window.new_events();
|
||||
}
|
||||
}
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
for window in &mut self.windows {
|
||||
window.about_to_wait();
|
||||
fn window_event(&mut self, args: Args<()>, _event: WindowEvent, res: EventResult) {
|
||||
if res.window_closed {
|
||||
args.event_loop.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct App;
|
||||
|
||||
impl imgui::UiBuilder for App {
|
||||
fn do_ui(&mut self, ui: &imgui::Ui<Self>) {
|
||||
#[cfg(feature = "docking")]
|
||||
@@ -89,6 +130,14 @@ impl imgui::UiBuilder for App {
|
||||
ui.dock_space_over_viewport(0, imgui::DockNodeFlags::None);
|
||||
}
|
||||
|
||||
let x = ui.collapsing_header_config("collapsing header");
|
||||
|
||||
ui.with_group(|| {
|
||||
self.selected_instruction_index =
|
||||
display_instruction_table(self.selected_instruction_index, ui);
|
||||
});
|
||||
|
||||
ui.show_demo_window(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use copypasta::{ClipboardContext, ClipboardProvider};
|
||||
use imgui::ClipboardBackend;
|
||||
|
||||
pub struct ClipboardSupport(pub ClipboardContext);
|
||||
|
||||
pub fn init() -> Option<ClipboardSupport> {
|
||||
ClipboardContext::new().ok().map(ClipboardSupport)
|
||||
}
|
||||
|
||||
impl ClipboardBackend for ClipboardSupport {
|
||||
fn get(&mut self) -> Option<String> {
|
||||
self.0.get_contents().ok()
|
||||
}
|
||||
fn set(&mut self, text: &str) {
|
||||
// ignore errors?
|
||||
let _ = self.0.set_contents(text.to_owned());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
use glium::glutin::surface::WindowSurface;
|
||||
use glium::{Display, Surface};
|
||||
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
|
||||
use imgui_glium_renderer::Renderer;
|
||||
use imgui_winit_support::winit::dpi::LogicalSize;
|
||||
use imgui_winit_support::winit::event::{Event, WindowEvent};
|
||||
use imgui_winit_support::winit::event_loop::EventLoop;
|
||||
use imgui_winit_support::winit::window::WindowBuilder;
|
||||
use imgui_winit_support::{HiDpiMode, WinitPlatform};
|
||||
use std::path::Path;
|
||||
use std::time::Instant;
|
||||
|
||||
mod clipboard;
|
||||
|
||||
pub const FONT_SIZE: f32 = 13.0;
|
||||
|
||||
#[allow(dead_code)] // annoyingly, RA yells that this is unusued
|
||||
pub fn simple_init<F: FnMut(&mut bool, &mut Ui) + 'static>(title: &str, run_ui: F) {
|
||||
init_with_startup(title, |_, _, _| {}, run_ui);
|
||||
}
|
||||
|
||||
pub fn init_with_startup<FInit, FUi>(title: &str, mut startup: FInit, mut run_ui: FUi)
|
||||
where
|
||||
FInit: FnMut(&mut Context, &mut Renderer, &Display<WindowSurface>) + 'static,
|
||||
FUi: FnMut(&mut bool, &mut Ui) + 'static,
|
||||
{
|
||||
let mut imgui = create_context();
|
||||
|
||||
let title = match Path::new(&title).file_name() {
|
||||
Some(file_name) => file_name.to_str().unwrap(),
|
||||
None => title,
|
||||
};
|
||||
let event_loop = EventLoop::new().expect("Failed to create EventLoop");
|
||||
|
||||
let builder = WindowBuilder::new()
|
||||
.with_title(title)
|
||||
.with_inner_size(LogicalSize::new(1024, 768));
|
||||
let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
|
||||
.set_window_builder(builder)
|
||||
.build(&event_loop);
|
||||
let mut renderer = Renderer::init(&mut imgui, &display).expect("Failed to initialize renderer");
|
||||
|
||||
if let Some(backend) = clipboard::init() {
|
||||
imgui.set_clipboard_backend(backend);
|
||||
} else {
|
||||
eprintln!("Failed to initialize clipboard");
|
||||
}
|
||||
|
||||
let mut platform = WinitPlatform::init(&mut imgui);
|
||||
{
|
||||
let dpi_mode = if let Ok(factor) = std::env::var("IMGUI_EXAMPLE_FORCE_DPI_FACTOR") {
|
||||
// Allow forcing of HiDPI factor for debugging purposes
|
||||
match factor.parse::<f64>() {
|
||||
Ok(f) => HiDpiMode::Locked(f),
|
||||
Err(e) => panic!("Invalid scaling factor: {}", e),
|
||||
}
|
||||
} else {
|
||||
HiDpiMode::Default
|
||||
};
|
||||
|
||||
platform.attach_window(imgui.io_mut(), &window, dpi_mode);
|
||||
}
|
||||
|
||||
let mut last_frame = Instant::now();
|
||||
|
||||
startup(&mut imgui, &mut renderer, &display);
|
||||
|
||||
event_loop
|
||||
.run(move |event, window_target| match event {
|
||||
Event::NewEvents(_) => {
|
||||
let now = Instant::now();
|
||||
imgui.io_mut().update_delta_time(now - last_frame);
|
||||
last_frame = now;
|
||||
}
|
||||
Event::AboutToWait => {
|
||||
platform
|
||||
.prepare_frame(imgui.io_mut(), &window)
|
||||
.expect("Failed to prepare frame");
|
||||
window.request_redraw();
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::RedrawRequested,
|
||||
..
|
||||
} => {
|
||||
let ui = imgui.frame();
|
||||
|
||||
let mut run = true;
|
||||
run_ui(&mut run, ui);
|
||||
if !run {
|
||||
window_target.exit();
|
||||
}
|
||||
|
||||
let mut target = display.draw();
|
||||
target.clear_color_srgb(1.0, 1.0, 1.0, 1.0);
|
||||
platform.prepare_render(ui, &window);
|
||||
let draw_data = imgui.render();
|
||||
renderer
|
||||
.render(&mut target, draw_data)
|
||||
.expect("Rendering failed");
|
||||
target.finish().expect("Failed to swap buffers");
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::Resized(new_size),
|
||||
..
|
||||
} => {
|
||||
if new_size.width > 0 && new_size.height > 0 {
|
||||
display.resize((new_size.width, new_size.height));
|
||||
}
|
||||
platform.handle_event(imgui.io_mut(), &window, &event);
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
..
|
||||
} => window_target.exit(),
|
||||
event => {
|
||||
platform.handle_event(imgui.io_mut(), &window, &event);
|
||||
}
|
||||
})
|
||||
.expect("EventLoop error");
|
||||
}
|
||||
|
||||
/// Creates the imgui context
|
||||
pub fn create_context() -> imgui::Context {
|
||||
let mut imgui = Context::create();
|
||||
// Fixed font size. Note imgui_winit_support uses "logical
|
||||
// pixels", which are physical pixels scaled by the devices
|
||||
// scaling factor. Meaning, 13.0 pixels should look the same size
|
||||
// on two different screens, and thus we do not need to scale this
|
||||
// value (as the scaling is handled by winit)
|
||||
imgui.fonts().add_font(&[
|
||||
FontSource::TtfData {
|
||||
data: include_bytes!("../../../resources/Roboto-Regular.ttf"),
|
||||
size_pixels: FONT_SIZE,
|
||||
config: Some(FontConfig {
|
||||
// As imgui-glium-renderer isn't gamma-correct with
|
||||
// it's font rendering, we apply an arbitrary
|
||||
// multiplier to make the font a bit "heavier". With
|
||||
// default imgui-glow-renderer this is unnecessary.
|
||||
rasterizer_multiply: 1.5,
|
||||
// Oversampling font helps improve text rendering at
|
||||
// expense of larger font atlas texture.
|
||||
oversample_h: 4,
|
||||
oversample_v: 4,
|
||||
..FontConfig::default()
|
||||
}),
|
||||
},
|
||||
FontSource::TtfData {
|
||||
data: include_bytes!("../../../resources/mplus-1p-regular.ttf"),
|
||||
size_pixels: FONT_SIZE,
|
||||
config: Some(FontConfig {
|
||||
// Oversampling font helps improve text rendering at
|
||||
// expense of larger font atlas texture.
|
||||
oversample_h: 4,
|
||||
oversample_v: 4,
|
||||
// Range of glyphs to rasterize
|
||||
glyph_ranges: FontGlyphRanges::japanese(),
|
||||
..FontConfig::default()
|
||||
}),
|
||||
},
|
||||
]);
|
||||
imgui.set_ini_filename(None);
|
||||
|
||||
imgui
|
||||
}
|
||||
Reference in New Issue
Block a user