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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use crate::hardware::memory::Memory;
use crate::int;
const PALETTE: [u32; 16] = [
0x000000, 0xF00000, 0x00F000, 0xF0F000, 0x0000F0, 0xF000F0, 0x00F0F0, 0xF0F0F0, 0x636363,
0xF06363, 0x63F063, 0xF0F063, 0x0063F0, 0xF063F0, 0x63F0F0, 0xF06300,
];
pub(crate) const WIDTH: usize = 320;
pub(crate) const HEIGHT: usize = 200;
pub(crate) const DEFAULT_PIXEL_SIZE: usize = 1;
#[derive(Debug)]
pub(crate) struct Screen {
pub(crate) mouse_clic: bool,
pub(crate) mouse_x: int,
pub(crate) mouse_y: int,
pub(crate) pixels: Vec<u32>,
pub(crate) rgb_pixels: Vec<u8>,
filter: bool,
pub(crate) led: int,
pub(crate) show_led: int,
}
impl Screen {
pub(crate) fn new() -> Self {
Screen {
mouse_clic: false,
mouse_x: -1,
mouse_y: -1,
pixels: vec![0xff000000; WIDTH * HEIGHT],
rgb_pixels: Vec::new(),
filter: false,
led: 0,
show_led: 0,
}
}
// pub(crate) fn set_pixel_size(&mut self, ps: usize, mem: &mut Memory) {
// mem.set_all_dirty();
// }
pub(crate) fn paint(&mut self, mem: &mut Memory) {
if self.show_led > 0 {
//todo : restore this
// self.show_led -= 1;
// let color = if self.led != 0 {
// Color::from_rgb(255., 0., 0.)
// } else {
// Color::from_rgb(0., 0., 0.)
// };
// let rectangle: Rectangle<f32> = Rectangle::new(Vector2::new(WIDTH as f32 - 16., 0.), Vector2::new(16., 8.));
// graphics.draw_rectangle(rectangle, color);
}
self.dopaint(mem);
}
pub(crate) fn get_pixels(&self, pixel_size: usize) -> Vec<u8> {
let mut buffer: Vec<u8> = Vec::new();
for y in 0..HEIGHT {
for _ in 0..pixel_size {
for x in 0..WIDTH {
for _ in 0..pixel_size {
let p = self.pixels[x + y * WIDTH];
let r = (p & 0xFF) as u8;
let g = ((p >> 8) & 0xFF) as u8;
let b = ((p >> 16) & 0xFF) as u8;
buffer.push(b);
buffer.push(g);
buffer.push(r);
}
}
}
}
buffer
}
pub(crate) fn dopaint(&mut self, mem: &mut Memory) {
let mut i = 0;
for y in 0..HEIGHT {
let offset: usize = y * WIDTH;
if !mem.is_dirty(y) {
i += 40;
} else {
let mut x: usize = 0;
for _ in 0..40 {
let col = mem.COLOR(i);
let c2: usize = (col & 0x0F) as usize;
let c1: usize = (col >> 4) as usize;
let cc2 = PALETTE[c1];
let cc1 = PALETTE[c2];
let pt = mem.POINT(i);
if (0x80 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x40 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x20 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x10 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x08 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x04 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x02 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
if (0x01 & pt) != 0 {
self.pixels[x + offset] = cc2;
} else {
self.pixels[x + offset] = cc1;
}
x += 1;
i += 1;
}
}
}
}
}