pub struct Config {
pub border_color: u8,
pub csel: bool,
pub rsel: bool,
}
impl Config {
pub fn new() -> Self {
Config {
border_color: 0x0e,
csel: true,
rsel: true,
}
}
pub fn reset(&mut self) {
self.border_color = 0x0e;
self.csel = true;
self.rsel = true;
}
}
pub struct BorderUnit {
pub config: Config,
main_flop: bool,
vertical_flop: bool,
}
impl BorderUnit {
pub fn new() -> Self {
BorderUnit {
config: Config::new(),
main_flop: false,
vertical_flop: false,
}
}
pub fn is_enabled(&self) -> bool {
self.main_flop || self.vertical_flop
}
pub fn output(&self) -> u8 {
self.config.border_color
}
pub fn reset(&mut self) {
self.config.reset();
self.main_flop = false;
self.vertical_flop = false;
}
pub fn update_main_flop(&mut self, x: u16, y: u16, den: bool) {
if self.config.csel {
if x == 0x7c {
self.update_vertical_flop(y, den);
if !self.vertical_flop {
self.main_flop = false;
}
} else if x == 0x1bc {
self.main_flop = true;
}
} else {
if x == 0x83 {
self.update_vertical_flop(y, den);
if !self.vertical_flop {
self.main_flop = false;
}
} else if x == 0x1b3 {
self.main_flop = true;
}
}
}
pub fn update_vertical_flop(&mut self, y: u16, den: bool) {
if self.config.rsel {
if y == 51 && den {
self.vertical_flop = false;
} else if y == 251 {
self.vertical_flop = true;
}
} else {
if y == 55 && den {
self.vertical_flop = false;
} else if y == 247 {
self.vertical_flop = true;
}
}
}
}