improved matrix display stuff
This commit is contained in:
@@ -23,7 +23,7 @@ impl BenEaterPC {
|
||||
}
|
||||
|
||||
pub fn tick_system(&mut self) {
|
||||
let (address, data, rw) = self.cpu.tick();
|
||||
self.cpu.tick();
|
||||
if self.cpu.microcode_step == 0 {
|
||||
// tick the clock.
|
||||
// tick the memory
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
use macroquad::prelude::*;
|
||||
use crate::parts::address_bus::AddressBus;
|
||||
use crate::parts::data_bus::DataBus;
|
||||
use crate::parts::display_matrix::MatrixEntryMode::{Delete, DeleteShift, Insert, InsertShift};
|
||||
|
||||
pub enum MatrixEntryMode {
|
||||
Delete,
|
||||
DeleteShift,
|
||||
Insert,
|
||||
InsertShift,
|
||||
}
|
||||
|
||||
pub struct DisplayMatrix {
|
||||
width: f32,
|
||||
@@ -9,42 +17,138 @@ pub struct DisplayMatrix {
|
||||
data_bus: DataBus,
|
||||
rs: bool,
|
||||
rw: bool,
|
||||
cursor_position: u8
|
||||
cursor_position: u8,
|
||||
busy: bool,
|
||||
entry_mode: MatrixEntryMode,
|
||||
cursor: bool,
|
||||
on: bool,
|
||||
blink: bool,
|
||||
cursor_shift: bool,
|
||||
display_shift: bool,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl DisplayMatrix {
|
||||
pub fn set_bus(&mut self, rs: bool, rw: bool, bus: u8, e: bool) {
|
||||
self.rs = rs;
|
||||
self.rw = rw;
|
||||
self.data_bus.data = bus;
|
||||
self.enabled = e;
|
||||
}
|
||||
|
||||
/// Reset the Display to its 'factory boot' state
|
||||
pub fn reset(&mut self) {
|
||||
// 1. Display clear
|
||||
self.set_bus(false, false, 0b0000_0001, true);
|
||||
self.tick(false, false, true, 0b0000_0001);
|
||||
// Function Set
|
||||
// DL = 1; 8-bit interface data
|
||||
// N = 0; 1-line display
|
||||
// F = 0; 5 × 8 dot character font
|
||||
self.tick(false, false, true, 0b0011_0000);;
|
||||
// 3. Display on/off control:
|
||||
// D = 0; Display off
|
||||
// C = 0; Cursor off
|
||||
// B = 0; Blinking off
|
||||
self.tick(false, false, true, 0b0000_1000);
|
||||
// 4. Entry mode set:
|
||||
// I/D = 1; Increment by 1
|
||||
// S = 0; No shift
|
||||
self.tick(false, false,true, 0b0000_0110);
|
||||
self.busy = false;
|
||||
}
|
||||
|
||||
pub fn new(width: f32, height: f32) -> DisplayMatrix {
|
||||
DisplayMatrix {
|
||||
let mut matrix = DisplayMatrix {
|
||||
width,
|
||||
height,
|
||||
text_buffer: String::from(""),
|
||||
data_bus: DataBus::new(),
|
||||
rs: false,
|
||||
rw: false,
|
||||
cursor_position: 0x00
|
||||
}
|
||||
cursor_position: 0x00,
|
||||
busy: false,
|
||||
entry_mode: MatrixEntryMode::InsertShift,
|
||||
on: false,
|
||||
cursor: false,
|
||||
blink: false,
|
||||
cursor_shift: false,
|
||||
display_shift: false,
|
||||
enabled: false,
|
||||
};
|
||||
matrix
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
pub fn tick(&mut self, rw: bool, rs: bool, enabled: bool, data: u8) {
|
||||
self.enabled = enabled;
|
||||
self.data_bus.data = data;
|
||||
self.rw = rw;
|
||||
self.rs = rs;
|
||||
// parse whats on the data bus.
|
||||
|
||||
}
|
||||
|
||||
pub fn set_busses(&mut self, address_bus: &mut AddressBus, data_bus: &mut DataBus) {
|
||||
|
||||
match (self.rs, self.rw) {
|
||||
(true, true) => {
|
||||
// read from cg or ddram
|
||||
}
|
||||
(true, false) => {
|
||||
// write to cg or ddram
|
||||
println!("WRITE TO CG/DD RAM -> {:08b} / {:02x} / {}", self.data_bus.data, self.data_bus.data, self.data_bus.data);
|
||||
}
|
||||
(false, true) => {
|
||||
// read the busy flag.
|
||||
self.data_bus.data = (self.busy as u8) << 7 | (self.cursor_position & 0x7F);
|
||||
self.enabled = true;
|
||||
}
|
||||
(false, false) => {
|
||||
match self.data_bus.data {
|
||||
0b0000_0001 => {
|
||||
// clear display
|
||||
self.text_buffer = " ".repeat(32);
|
||||
}
|
||||
0b0000_0010..=0b0000_0011 => {
|
||||
// return home
|
||||
self.cursor_position = 0x00;
|
||||
}
|
||||
0b0000_0100..=0b0000_0111 => {
|
||||
self.entry_mode = match self.data_bus.data {
|
||||
0b01 => DeleteShift,
|
||||
0b10 => Insert,
|
||||
0b11 => InsertShift,
|
||||
_ => {
|
||||
// Default mode
|
||||
Delete
|
||||
}
|
||||
};
|
||||
}
|
||||
0b0000_1000..=0b0000_1111 => {
|
||||
// display control
|
||||
self.on = self.data_bus.data & 0b100 == 0b100;
|
||||
self.cursor = self.data_bus.data & 0b10 == 0b10;
|
||||
self.blink = self.data_bus.data & 0b1 == 0b1;
|
||||
}
|
||||
0b0001_0000..=0b0001_1111 => {
|
||||
// cursor control
|
||||
self.cursor_shift = self.data_bus.data & 0b1000 == 0b1000;
|
||||
self.display_shift = self.data_bus.data & 0b100 == 0b100;
|
||||
}
|
||||
0b0010_0000..=0b0011_1111 => {
|
||||
// function set
|
||||
println!("Ignoring function set. this is going to play like an 8bit 2 row");
|
||||
}
|
||||
0b0100_0000..=0b0111_1111 => {
|
||||
// set CGRam Address
|
||||
println!("Ignoring set CGRam Address. Not Changing how the characters are displayed.");
|
||||
}
|
||||
0b1000_0000..=0b1111_1111 => {
|
||||
// set DDRam address
|
||||
self.cursor_position = self.data_bus.data & 0b0111_1111;
|
||||
}
|
||||
_ => {
|
||||
// Invalid Command
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_letter(&mut self, letter_to_push: char) {
|
||||
@@ -60,7 +164,7 @@ impl DisplayMatrix {
|
||||
pub fn render(&self, x_offset: f32, y_offset: f32) {
|
||||
DisplayMatrix::draw_square(x_offset,
|
||||
y_offset,
|
||||
x_offset + self.width ,
|
||||
x_offset + self.width,
|
||||
y_offset + self.height,
|
||||
BLACK);
|
||||
|
||||
@@ -76,4 +180,17 @@ impl DisplayMatrix {
|
||||
draw_line(x1, y2, x2, y2, 1.0, color);
|
||||
draw_line(x2, y1, x2, y2, 1.0, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn smoke() { assert!(true); }
|
||||
|
||||
#[test]
|
||||
fn device_init() {
|
||||
let display = DisplayMatrix::new(100.0, 100.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user