From c2c4cab19ec434232bed2101b2e9f58a336db8fb Mon Sep 17 00:00:00 2001 From: Franco Colmenarez Date: Sat, 10 Dec 2022 19:06:26 -0500 Subject: [PATCH] Basic file loading --- snes-frontend/Cargo.toml | 2 ++ snes-frontend/src/main.rs | 35 ++++++++++++++++++++++++++++++++++- snes-frontend/src/state.rs | 16 ++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/snes-frontend/Cargo.toml b/snes-frontend/Cargo.toml index 77e2036..c30145b 100644 --- a/snes-frontend/Cargo.toml +++ b/snes-frontend/Cargo.toml @@ -6,11 +6,13 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +snes-core = { path = "../snes-core" } winit = "0.26.1" imgui = "0.8.2" wgpu = "0.12.0" imgui-wgpu = "0.19.0" pollster = "0.2.5" +rfd = "0.10.0" [dependencies.imgui-winit-support] version = "0.8.2" features = ["winit-26"] diff --git a/snes-frontend/src/main.rs b/snes-frontend/src/main.rs index 21a46f4..1e851f2 100644 --- a/snes-frontend/src/main.rs +++ b/snes-frontend/src/main.rs @@ -1,5 +1,6 @@ extern crate imgui_winit_support; +use rfd::FileDialog; use imgui::*; use imgui_wgpu::{Renderer, RendererConfig}; use pollster::block_on; @@ -13,10 +14,13 @@ use winit::{ }; use snes_frontend::state::State; +extern crate snes_core; +use snes_core::emulator::Emulator; fn main() { // Windowing state let mut state = State::new(); + let mut emulator = Emulator::new(); // Set up window and GPU @@ -203,6 +207,19 @@ fn main() { if imgui::MenuItem::new("Load ROM") .build(&ui) { + if let Some(path) = FileDialog::new() + .pick_file() + { + match emulator.rom.load(&String::from(path.to_str().unwrap())) { + Ok(_) => {}, + Err(err) => { + state.error_message.show = true; + state.error_message.message = format!( + "Could not load rom: {}", err, + ); + } + } + } } ui.separator(); }); @@ -227,18 +244,34 @@ fn main() { ); }); } + + // Render emulator framebuffer { let tex = renderer.textures.get_mut(texture_id).unwrap(); tex.write(&queue, &vec![0xAA; 400 * 400 * 4], 400, 400); let game_window = imgui::Window::new("Game"); game_window - .size([400.0, 400.0], Condition::FirstUseEver) + .size([600.0, 600.0], Condition::FirstUseEver) .collapsible(false) .build(&ui, || { let game_image = imgui::Image::new(texture_id, [400.0, 400.0]); game_image.build(&ui); }); } + + if state.error_message.show { + let window = imgui::Window::new("Error"); + window + .size([300.0, 100.0], Condition::Always) + .collapsible(false) + .build(&ui, || { + ui.text(&state.error_message.message); + if ui.button("Ok") { + state.error_message.show = false + } + }); + } + } let mut encoder: wgpu::CommandEncoder = diff --git a/snes-frontend/src/state.rs b/snes-frontend/src/state.rs index f5c349a..f69cd3c 100644 --- a/snes-frontend/src/state.rs +++ b/snes-frontend/src/state.rs @@ -16,14 +16,30 @@ impl DebugOptions { } } +pub struct ErrorMessage { + pub show: bool, + pub message: String, +} + +impl ErrorMessage { + pub fn new() -> Self { + Self { + show: false, + message: String::from(""), + } + } +} + pub struct State { pub debug_options: DebugOptions, + pub error_message: ErrorMessage, } impl State { pub fn new() -> Self { Self { debug_options: DebugOptions::new(), + error_message: ErrorMessage::new(), } } } \ No newline at end of file