riscii

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

commit eb1222854cc0be2f761dfa2d7552c24eab42368a
parent b27bdc552bcb53edbbd666a5322f49f595efd98d
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Wed,  8 Jun 2022 20:47:42 -0700

Added sdl stub

Diffstat:
Msrc/main.rs | 7+++++--
Asrc/sdl.rs | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -12,12 +12,14 @@ // 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/>. -#[cfg(test)] -mod main_test; extern crate core; +extern crate sdl2; +#[cfg(test)] +mod main_test; mod config; +mod sdl; use core::convert::TryInto; use std::fs; @@ -390,6 +392,7 @@ fn decode_file(file: &Vec<u8>, pos: usize) -> Result<(), DecodeError> { } fn main() -> Result<(), String> { + let context = sdl::Context::new()?; let config = config::Config::init()?; println!( diff --git a/src/sdl.rs b/src/sdl.rs @@ -0,0 +1,65 @@ +// RISC II emulator configuration. +// (C) Ryan Jeffrey <ryan@ryanmj.xyz>, 2022 +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. + +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// 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/>. + +// Struct definitions. + +extern crate sdl2; + +use sdl2::event::Event; +use sdl2::keyboard::Keycode; +use sdl2::pixels::Color; +use sdl2::rect::Rect; +use sdl2::render::Canvas; +use sdl2::video::Window; +use sdl2::EventPump; +use sdl2::Sdl; +use sdl2::VideoSubsystem; + +// Struct definitions. + +pub struct Context { + context: Sdl, + video_system: VideoSubsystem, + canvas: Canvas<Window>, + event_pump: EventPump, +} + +// Struct impls. + +impl Context { + pub fn new() -> Result<Self, String> { + let sdl_context = sdl2::init()?; + let video_subsystem = sdl_context.video()?; + let window = video_subsystem + .window("RISC II", 1200, 900) + .position_centered() + .opengl() + .build() + .map_err(|e| e.to_string())?; + + let mut canvas = window.into_canvas().build().map_err(|e| e.to_string())?; + canvas.set_draw_color(Color::RGB(0, 0, 0)); + canvas.clear(); + canvas.present(); + let event_pump = sdl_context.event_pump()?; + + Ok(Self { + context: sdl_context, + video_system: video_subsystem, + canvas: canvas, + event_pump: event_pump, + }) + } +}