updates display of ben eater pc doesnt blow up when creating a rom chip anymore doesnt blow up when creating a pc anymore
79 lines
2.3 KiB
Rust
79 lines
2.3 KiB
Rust
use macroquad::prelude::*;
|
|
use crate::parts::address_bus::AddressBus;
|
|
use crate::parts::data_bus::DataBus;
|
|
|
|
pub struct DisplayMatrix {
|
|
width: f32,
|
|
height: f32,
|
|
text_buffer: String,
|
|
data_bus: DataBus,
|
|
rs: bool,
|
|
rw: bool,
|
|
cursor_position: u8
|
|
}
|
|
|
|
impl DisplayMatrix {
|
|
pub fn new(width: f32, height: f32) -> DisplayMatrix {
|
|
DisplayMatrix {
|
|
width,
|
|
height,
|
|
text_buffer: String::from(""),
|
|
data_bus: DataBus::new(),
|
|
rs: false,
|
|
rw: false,
|
|
cursor_position: 0x00
|
|
}
|
|
}
|
|
|
|
/// Tick
|
|
///
|
|
/// Checks the data bus and sees what the setup is.
|
|
///
|
|
/// 0 0 0 0 0 0 0 1 -> Clear Display
|
|
/// 0 0 0 0 0 0 1 - -> Return Home
|
|
/// 0 0 0 0 0 0 A B -> Sets cursor move direction and shift
|
|
/// A -> 0 = Insert, 1 = Delete
|
|
/// B -> Scroll bool
|
|
/// 0 0 0 0 1 D C B -> Sets display mode
|
|
/// D -> Display On/Off
|
|
/// C -> Cursor On/Off
|
|
/// B -> Blink
|
|
pub fn tick(&mut self) {
|
|
// parse whats on the data bus.
|
|
|
|
}
|
|
|
|
pub fn set_busses(&mut self, address_bus: &mut AddressBus, data_bus: &mut DataBus) {
|
|
|
|
}
|
|
|
|
pub fn push_letter(&mut self, letter_to_push: char) {
|
|
self.cursor_position += 1;
|
|
self.text_buffer.push(letter_to_push)
|
|
}
|
|
|
|
pub fn clear_display(&mut self) {
|
|
self.cursor_position = 0;
|
|
self.text_buffer.clear()
|
|
}
|
|
|
|
pub fn render(&self, x_offset: f32, y_offset: f32) {
|
|
DisplayMatrix::draw_square(x_offset,
|
|
y_offset,
|
|
x_offset + self.width ,
|
|
y_offset + self.height,
|
|
BLACK);
|
|
|
|
let mut tmp = self.text_buffer.clone();
|
|
tmp.push('#');
|
|
draw_text(&*tmp, x_offset + 5.0, y_offset + 20.0, 20.0, BLACK);
|
|
}
|
|
|
|
fn draw_square(x1: f32, y1: f32, x2: f32, y2: f32, color: Color) {
|
|
// println!("Square from {x1:2.0}x{y1:2.0} to {x2:2.0}x{y2:2.0} with {:?}", color);
|
|
draw_line(x1, y1, x2, y1, 1.0, color);
|
|
draw_line(x1, y1, x1, y2, 1.0, color);
|
|
draw_line(x1, y2, x2, y2, 1.0, color);
|
|
draw_line(x2, y1, x2, y2, 1.0, color);
|
|
}
|
|
} |