BUGFIX GEMMARAT: fixes input bug with frequent drops of inputs from 2 input loops
CLEANUP: remove unused imports, _ unused variables
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use ratatui::prelude::*;
|
||||
use std::time::Duration;
|
||||
use color_eyre::{eyre::Context, Result};
|
||||
@@ -8,12 +7,11 @@ use ratatui::{
|
||||
widgets::Paragraph,
|
||||
DefaultTerminal, Frame,
|
||||
};
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::layout::{Constraint, Direction};
|
||||
use ratatui::prelude::Layout;
|
||||
use ratatui::widgets::{Block, Borders};
|
||||
use gemma::chip8::computer::Chip8Computer;
|
||||
use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
use gemma::chip8::quirk_modes::QuirkMode::Chip8;
|
||||
use gemmarat::register_widget::RegisterWidget;
|
||||
use gemmarat::timer_widget::TimerWidget;
|
||||
use gemmarat::video_widget::VideoWidget;
|
||||
@@ -42,14 +40,15 @@ fn main() -> Result<()> {
|
||||
fn run(mut terminal: DefaultTerminal) -> Result<()> {
|
||||
let mut manager = Chip8ComputerManager::default();
|
||||
manager.load_new_program_from_disk_to_system_memory(Path::new("/home/tmerritt/Projects/trevors_chip8_toy/resources/roms/2-ibm-logo.ch8"));
|
||||
for _ in 0..30 {
|
||||
manager.tick();
|
||||
}
|
||||
// for _ in 0..30 {
|
||||
// manager.tick();
|
||||
// }
|
||||
loop {
|
||||
manager.tick();
|
||||
terminal.draw(|frame| {
|
||||
do_draw(frame, &mut manager);
|
||||
}).expect("unable to render display.");
|
||||
if should_quit()? {
|
||||
if handle_keyboard(&mut manager)? {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -117,19 +116,37 @@ fn do_draw(frame: &mut Frame, draw_with: &mut Chip8ComputerManager) {
|
||||
|
||||
// Footer Bar
|
||||
frame.render_widget(
|
||||
Paragraph::new("F1 - Step | F2 - Run | F3 - Stop | Q - Quit")
|
||||
Paragraph::new("F1 - Step | F2 - Run | F3 - Stop | F4 - Reset | Q - Quit")
|
||||
.centered()
|
||||
.block(Block::new().borders(Borders::ALL)), main_layout[1]);
|
||||
|
||||
}
|
||||
|
||||
fn should_quit() -> Result<bool> {
|
||||
if event::poll(Duration::from_millis(250)).context("event poll failed")? {
|
||||
if let Event::Key(key) = event::read().context("event read failed")? {
|
||||
return Ok(KeyCode::Char('q') == key.code);
|
||||
fn handle_keyboard(state: &mut Chip8ComputerManager) -> Result<bool> {
|
||||
let mut die_time = false;
|
||||
if event::poll(Duration::from_millis(100)).context("Unable to poll Keyboard")? {
|
||||
if let Event::Key(key) = event::read().context("Event Read Failed")? {
|
||||
match key.code {
|
||||
KeyCode::F(1) => {
|
||||
state.tick();
|
||||
},
|
||||
KeyCode::F(2) => {
|
||||
state.core_should_run = true;
|
||||
},
|
||||
KeyCode::F(3) => {
|
||||
state.core_should_run = false;
|
||||
}
|
||||
KeyCode::F(4) => {
|
||||
state.reset(Chip8);
|
||||
}
|
||||
KeyCode::Char('q') | KeyCode::Char('Q') => {
|
||||
die_time = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
|
||||
Ok(die_time)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user