use core::fmt::Debug;
pub mod cursor;
pub mod fuller;
pub mod kempston;
pub mod sinclair;
bitflags! {
#[derive(Default)]
pub struct Directions: u8 {
const UP = 0b0000_0001;
const RIGHT = 0b0000_0010;
const DOWN = 0b0000_0100;
const LEFT = 0b0000_1000;
}
}
pub enum JoyDirection {
Center,
Up,
UpRight,
Right,
DownRight,
Down,
DownLeft,
Left,
UpLeft
}
pub trait JoystickInterface {
fn fire(&mut self, btn: u8, pressed: bool);
fn get_fire(&self, btn: u8) -> bool;
fn set_directions(&mut self, dir: Directions);
fn get_directions(&self) -> Directions;
#[inline]
fn direction(&mut self, dir: JoyDirection) {
self.set_directions(match dir {
JoyDirection::Center => Directions::empty(),
JoyDirection::Up => Directions::UP,
JoyDirection::UpRight => Directions::UP|Directions::RIGHT,
JoyDirection::Right => Directions::RIGHT,
JoyDirection::DownRight => Directions::DOWN|Directions::RIGHT,
JoyDirection::Down => Directions::DOWN,
JoyDirection::DownLeft => Directions::DOWN|Directions::LEFT,
JoyDirection::Left => Directions::LEFT,
JoyDirection::UpLeft => Directions::UP|Directions::LEFT,
})
}
#[inline]
fn center(&mut self) {
self.set_directions(Directions::empty());
}
#[inline]
fn is_up(&self) -> bool {
self.get_directions().intersects(Directions::UP)
}
#[inline]
fn is_right(&self) -> bool {
self.get_directions().intersects(Directions::RIGHT)
}
#[inline]
fn is_left(&self) -> bool {
self.get_directions().intersects(Directions::LEFT)
}
#[inline]
fn is_down(&self) -> bool {
self.get_directions().intersects(Directions::DOWN)
}
#[inline]
fn is_center(&self) -> bool {
self.get_directions().intersects(Directions::empty())
}
}
pub trait JoystickDevice: Debug {
fn port_read(&self, port: u16) -> u8;
fn port_write(&mut self, _port: u16, _data: u8) -> bool { false }
}
#[derive(Clone, Copy, Default, Debug)]
pub struct NullJoystickDevice;
impl JoystickDevice for NullJoystickDevice {
fn port_read(&self, _port: u16) -> u8 {
u8::max_value()
}
}
impl JoystickInterface for NullJoystickDevice {
fn fire(&mut self, _btn: u8, _pressed: bool) {}
fn get_fire(&self, _btn: u8) -> bool { false }
fn set_directions(&mut self, _dir: Directions) {}
fn get_directions(&self) -> Directions {
Directions::empty()
}
}