2021-11-16 00:09:27 -06:00
|
|
|
#![allow(dead_code)]
|
2021-12-24 07:03:15 -06:00
|
|
|
use crate::trace;
|
2021-12-24 13:00:20 -06:00
|
|
|
// TODO: Evaluate variable sized mailboxes
|
2021-12-24 07:03:15 -06:00
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
pub struct MailBoxes {
|
2021-12-24 07:03:15 -06:00
|
|
|
flags: u8,
|
|
|
|
mailboxes: [u64; 4],
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
impl MailBoxes {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
flags: 0b0000_0000,
|
|
|
|
mailboxes: [0; 4],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn reset(&mut self) {
|
|
|
|
self.flags = 0b0000_0000;
|
|
|
|
self.mailboxes = [0; 4];
|
|
|
|
}
|
|
|
|
pub fn set_mailbox(&mut self, mailbox_num: u8, mailbox_data: u64) {
|
|
|
|
if let 0..=3 = mailbox_num {
|
|
|
|
self.mailboxes[mailbox_num as usize] = mailbox_data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn set_flag(&mut self, flag_num: u8) {
|
|
|
|
match flag_num {
|
|
|
|
0 => {
|
|
|
|
self.flags |= 0b0000_0001;
|
|
|
|
}
|
|
|
|
1 => {
|
|
|
|
self.flags |= 0b0000_0010;
|
|
|
|
}
|
|
|
|
2 => {
|
|
|
|
self.flags |= 0b0000_0100;
|
|
|
|
}
|
|
|
|
3 => {
|
|
|
|
self.flags |= 0b0000_1000;
|
|
|
|
}
|
|
|
|
4 => {
|
|
|
|
self.flags |= 0b0001_0000;
|
|
|
|
}
|
|
|
|
5 => {
|
|
|
|
self.flags |= 0b0010_0000;
|
|
|
|
}
|
|
|
|
6 => {
|
|
|
|
self.flags |= 0b0100_0000;
|
|
|
|
}
|
|
|
|
7 => {
|
|
|
|
self.flags |= 0b1000_0000;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn dump_flags(&self) {
|
2021-12-24 07:03:15 -06:00
|
|
|
trace!(
|
|
|
|
"Flag 0: {:08b} | {}",
|
|
|
|
self.flags & 0b0000_0001,
|
|
|
|
self.flags & 0b0000_0001
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
"Flag 1: {:08b} | {}",
|
|
|
|
self.flags & 0b0000_0010,
|
|
|
|
self.flags >> 1 & 0b0000_0001
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
"Flag 2: {:08b} | {}",
|
|
|
|
self.flags & 0b0000_0100,
|
|
|
|
self.flags >> 2 & 0b0000_0001
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
"Flag 3: {:08b} | {}",
|
|
|
|
self.flags & 0b0000_1000,
|
|
|
|
self.flags >> 3 & 0b0000_0001
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
"Flag 4: {:08b} | {}",
|
|
|
|
self.flags & 0b0001_0000,
|
|
|
|
self.flags >> 4 & 0b0000_0001
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
"Flag 5: {:08b} | {}",
|
|
|
|
self.flags & 0b0010_0000,
|
|
|
|
self.flags >> 5 & 0b0000_0001
|
|
|
|
);
|
|
|
|
|
|
|
|
trace!(
|
|
|
|
"Flag 6: {:08b} | {}",
|
|
|
|
self.flags & 0b0100_0000,
|
|
|
|
self.flags >> 6 & 0b0000_0001
|
|
|
|
);
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2021-12-24 07:03:15 -06:00
|
|
|
trace!(
|
|
|
|
"Flag 7: {:08b} | {}",
|
|
|
|
self.flags & 0b1000_0000,
|
|
|
|
self.flags >> 7 & 0b0000_0001
|
|
|
|
);
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
}
|