riscii

An emulator for the RISC II
Log | Files | Refs | LICENSE

commit cbcec2d5a62981ce28ca012cdf5f4fa5cd4fa8e0
parent c5dd46ed1f6beb5ad731bce017f4bc0720e8797e
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Sun, 30 Oct 2022 21:47:18 -0700

Fix compile error and begin debugging window

Diffstat:
MCargo.toml | 4++--
MREADME.org | 12++++++------
Mriscii.org | 6+++---
Msrc/data_path.rs | 4+++-
Msrc/debug_window.rs | 40+++++++++++++++++++++++++++++++---------
Msrc/main.rs | 14+++++++++-----
Msrc/sdl.rs | 17+++++++++++++++--
Msrc/system.rs | 7++-----
8 files changed, 71 insertions(+), 33 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -15,4 +15,5 @@ serde = "1.0.137" serde_derive = "1.0.137" assert_hex = "0.2.2" [dependencies.sdl2] -version = "0.35" -\ No newline at end of file +version = "0.35" +features = ["ttf","mixer"] diff --git a/README.org b/README.org @@ -22,12 +22,12 @@ preserve knowledge on this important piece of computer history. See [[https://github.com/Ma11ock/riscii-guy][this project]] for an experimental assembler for the RISC II. ** Feature completeness -| Feature | State | -|-----------------------------------+------------------------------| -| RISC II instruction set emulation | Partial [fn::There are bugs] | -| Screen output & I/O | Work started | -| MMU/Virtual Memory | No | -| Firmware | No | +| Feature | State | +|-----------------------------------+------------------------------------| +| RISC II instruction set emulation | Partial (Incomplete and with bugs) | +| Screen output & I/O | Work started | +| MMU/Virtual Memory | No | +| Firmware | No | diff --git a/riscii.org b/riscii.org @@ -103,9 +103,9 @@ register name. The 14th bit is the /immediate bit/ which is high if shortSource2 is an immediate or low if a register. #+CAPTION: Format of a short-immediate instruction. -| 7 bits | 1 bit | 5 bits | 5 bits | 14 bits | -|--------+-------+--------+--------+--------------| -| opcode | SCC | DEST | rs1 | shortSource2 | +| 7 bits | 1 bit | 5 bits | 5 bits | 1 bit | 14 bits | +|--------+-------+--------+--------+---------+--------------| +| opcode | SCC | DEST | rs1 | imm bit | shortSource2 | #+CAPTION: shortSource2 format for register diff --git a/src/data_path.rs b/src/data_path.rs @@ -426,7 +426,9 @@ impl DataPath { } pub fn add_step(&mut self) { - self.dst_latch = self.alu.add(); + if self.scc_flag2 { + self.dst_latch = self.alu.add(); + } } pub fn set_cc_codes_arithmetic(&mut self) { diff --git a/src/debug_window.rs b/src/debug_window.rs @@ -15,9 +15,10 @@ use config::Config; use sdl::{Context, Drawable, Pane}; -use sdl2::event::{Event, WindowEvent}; use sdl2::keyboard::Keycode; use sdl2::pixels::*; +use sdl2::rect::Rect; +use sdl2::ttf::{Font, Sdl2TtfContext}; use system::System; use util::Result; @@ -25,17 +26,26 @@ pub struct DebugWindow<'a> { pane: Pane, system: &'a System, config: &'a Config, + font: Font<'a, 'static>, } impl<'a> DebugWindow<'a> { - pub fn new(config: &'a Config, system: &'a System, context: &mut Context) -> Result<Self> { + pub fn new( + config: &'a Config, + system: &'a System, + context: &mut Context, + ttf: &'a mut Sdl2TtfContext, + ) -> Result<Self> { + let pane = Pane::new( + config.get_debug_win_width(), + config.get_debug_win_height(), + format!("Debug"), + context, + )?; + let debug_font = { ttf.load_font("debug.otf", 12)? }; Ok(Self { - pane: Pane::new( - config.get_debug_win_width(), - config.get_debug_win_height(), - format!("Debug"), - context, - )?, + font: debug_font, + pane: pane, system: system, config: config, }) @@ -44,10 +54,22 @@ impl<'a> DebugWindow<'a> { impl<'a> Drawable for DebugWindow<'a> { fn draw(&mut self, context: &mut Context) { + // Clear the window. + const DRAW_COLOR: Color = Color::RGB(0, 0, 0); self.pane.canvas.set_draw_color(Color::RGB(0, 0, 0)); self.pane.canvas.clear(); - // + const OBJ_DEFAULT_COLOR: Color = Color::RGB(0xFF, 0xFF, 0xFF); + const OBJ_USE_COLOR: Color = Color::RGB(0xFa, 0x10, 0x10); + + // Register file. + let mut reg_file = Rect::new(100, 200, 200, 400); + + // Draw register file. + self.pane.canvas.set_draw_color(OBJ_DEFAULT_COLOR); + self.pane.canvas.draw_rect(reg_file); + + // Draw the debug window. self.pane.canvas.present(); } diff --git a/src/main.rs b/src/main.rs @@ -42,10 +42,8 @@ pub mod window; use config::Config; use debug_window::DebugWindow; -use sdl::{Context, Drawable}; +use sdl::{make_font_context, Context, Drawable}; use sdl2::event::{Event, WindowEvent}; -use sdl2::keyboard::Keycode; -use std::boxed::Box; use std::error::Error; use system::System; use window::MainWindow; @@ -133,16 +131,22 @@ fn main() -> Result<(), Box<dyn Error>> { //println!("Opening binary file {}.", path); //let program = fs::read(path)?; let mut sdl_context = Context::new()?; + let mut font_context = make_font_context()?; let mut main_window = MainWindow::new(&config, &system, &mut sdl_context)?; let mut debug_window = if config.is_debug_mode() { - Some(DebugWindow::new(&config, &system, &mut sdl_context)?) + Some(DebugWindow::new( + &config, + &system, + &mut sdl_context, + &mut font_context, + )?) } else { None }; 'running: loop { - match handle_events(&mut sdl_context, &mut main_window, &mut debug_window) { + match { handle_events(&mut sdl_context, &mut main_window, &mut debug_window) } { GlobalAction::QuitProgram => { break 'running; } diff --git a/src/sdl.rs b/src/sdl.rs @@ -22,11 +22,13 @@ use sdl2::event::{Event, WindowEvent}; use sdl2::keyboard::Keycode; use sdl2::pixels::Color; use sdl2::rect::Rect; -use sdl2::render::Canvas; -use sdl2::video::Window; +use sdl2::render::{Canvas, TextureCreator}; +use sdl2::ttf::{Font, Sdl2TtfContext}; +use sdl2::video::{Window, WindowContext}; use sdl2::EventPump; use sdl2::Sdl; use sdl2::VideoSubsystem; +use std::path::Path; use system::System; use util::Result; @@ -54,13 +56,21 @@ pub struct Pane { pub canvas: Canvas<Window>, /// Id. window_id: u32, + /// Texture creator. + pub texture_creator: TextureCreator<WindowContext>, } + +pub fn make_font_context() -> std::result::Result<Sdl2TtfContext, String> { + sdl2::ttf::init().map_err(|e| e.to_string()) +} + // Struct impls. impl Context { pub fn new() -> Result<Self> { let sdl = sdl2::init()?; let event_pump = sdl.event_pump()?; + Ok(Self { video_system: sdl.video()?, context: sdl, @@ -87,9 +97,12 @@ impl Pane { canvas.clear(); canvas.present(); + let texture_creator = canvas.texture_creator(); + Ok(Self { canvas: canvas, window_id: id, + texture_creator: texture_creator, }) } diff --git a/src/system.rs b/src/system.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use clock::Clock; +use clock::{Clock, Phase}; use config::Config; use cpu::OutputPins; use data_path::{Control, DataPath}; @@ -22,8 +22,6 @@ use instruction::{noop, InstructionCycle}; use memory::Memory; use util::Result; -use crate::clock::Phase; - pub struct System { /// RISCII data path. data_path: DataPath, @@ -44,8 +42,7 @@ pub struct System { impl System { pub fn new(config: &Config) -> Result<Self> { - let mut dp = DataPath::new(); - let nop = noop(&mut dp); + let dp = DataPath::new(); Ok(Self { data_path: dp, mem: Memory::new(config),