1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use image as im;

pub const MAX_WIDTH_MODE0:u32 = 96*2;
pub const MAX_WIDTH_MODE1:u32 = 96*4;
pub const MAX_WIDTH_MODE2:u32 = 96*8;
pub const MAX_WIDTH_MODE3:u32 = 96*2;
pub const MAX_HEIGHT:u32 = 39*8;

 
pub struct SimpleMonitor {
    pub width: u32,
    pub height: u32,
    pub mode: u8,
    pub pixels: Vec<Vec<u8>>,
    pub palette: Vec<char>,
    pub buffer: im::ImageBuffer<im::Rgba<u8>, Vec<u8>>        }

    impl SimpleMonitor{
        pub fn new(width: u32, height: u32, mode: u8) -> SimpleMonitor {
            SimpleMonitor {
                width,
                height,
                mode,
                pixels: vec![vec![0u8; width as usize]; height as usize],
                palette: vec![0 as char; 16],
                buffer: im::ImageBuffer::new(width, height)

            }
        }

        pub fn width(&self) -> u32 {
            self.width
        }

        pub fn height(&self) -> u32 {
            self.height
        }



        pub fn set_pixel(&mut self, x:u32, y: u32, pen: u8) {
            self.pixels[y as usize][x as usize] = pen;
        }

        pub fn set_ink(&mut self, ink: char, color: char) {
            assert!(ink<=17 as char);
            assert!(color<=27 as char);

            self.palette[ink as usize] = color
        }

        pub fn update_buffer(&mut self){
            // Here we have to draw our pixel array in the buffer
        }

        pub fn canvas(&mut self) -> &mut im::ImageBuffer<im::Rgba<u8>, Vec<u8>> {
            &mut self.buffer
        }
    }