1use crate::{Condition, Instruction, MatrixPoint};
2
3pub const START: u16 = 300;
4
5#[derive(Clone, Copy, Debug, PartialEq)]
6pub struct Pixel {
7 pub value: u16,
8 pub point: MatrixPoint,
9}
10
11impl Pixel {
12 pub fn new(value: u16, point: MatrixPoint) -> Pixel {
13 Pixel { value, point }
14 }
15
16 pub fn as_instruction(&self) -> Instruction {
17 match self.value {
18 0..=8 => Instruction::PushA,
19 18..=26 => Instruction::PopUntil,
20 36..=44 => Instruction::Push,
21 54..=62 => Instruction::Save,
22 72..=80 => Instruction::MovA,
23 90..=98 => Instruction::PopA,
24 108..=116 => Instruction::Add,
25 126..=134 => Instruction::Sub,
26 144..=152 => Instruction::Mult,
27 162..=170 => Instruction::Div,
28 180..=188 => Instruction::Road,
29 198..=206 => Instruction::LeftShift,
30 216..=224 => Instruction::RightShift,
31 234..=242 => Instruction::And,
32 252..=260 => Instruction::Or,
33 270..=278 => Instruction::Not,
34 288..=296 => Instruction::Xor,
35 306..=314 => Instruction::Output,
36 324..=332 => Instruction::OutputUntil,
37 342..=350 => Instruction::Modulo,
38 START => Instruction::Start,
39 _ => Instruction::None,
40 }
41 }
42
43 pub fn as_data(&self) -> u16 {
44 self.value
45 }
46
47 pub fn as_condition(&self) -> Condition {
48 match self.value {
49 0..=8 => Condition::NotEqual,
50 72..=80 => Condition::Less,
51 144..=152 => Condition::LessEqual,
52 216..=224 => Condition::Greater,
53 288..=296 => Condition::GreaterEqual,
54 _ => Condition::Equal,
55 }
56 }
57}