Skip to content

Commit

Permalink
Rework keyboard logic, it sorta kinda works
Browse files Browse the repository at this point in the history
Co-authored-by: ava-silver <[email protected]>
  • Loading branch information
breqdev and ava-silver committed Nov 10, 2023
1 parent 874e3c7 commit adcb889
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 33 deletions.
209 changes: 209 additions & 0 deletions src/keyboard/apple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
use crate::keyboard::{KeyAdapter, KeyPosition, KeyState};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]

Check warning on line 4 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L4

Added line #L4 was not covered by tests
pub enum AppleKeys {
Esc,
Digit1,
Digit2,
Digit3,
Digit4,
Digit5,
Digit6,
Digit7,
Digit8,
Digit9,
Digit0,
Minus,
Equals,
Del,

Tab,
Q,
W,
E,
R,
T,
Y,
U,
I,
O,
P,
LeftBracket,
RightBracket,

Ctrl,
A,
S,
D,
F,
G,
H,
J,
K,
L,
Semicolon,
Apostrophe,
Grave,
Return,

LShift,
Slash,
Z,
X,
C,
V,
B,
N,
M,
Comma,
Period,
Backslash,
RShift,

CapsLock,
OpenApple,
Space,
ClosedApple,
LeftArrow,
RightArrow,
DownArrow,
UpArrow,

NumEsc,
NumLeft,
NumRight,
NumSpace,

Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
NumComma,
NumPeriod,
NumLeftParen,
NumRightParen,
NumMinus,
NumDivide,
NumPlus,
NumMultiply,
NumReturn,
NumPrint,
}

/// An adapter for mapping positions on a standard keyboard to keys on an Apple IIe.
pub struct AppleKeyboardAdapter;

impl KeyAdapter<KeyPosition, AppleKeys> for AppleKeyboardAdapter {
fn map(state: &KeyState<KeyPosition>) -> KeyState<AppleKeys> {
let mut mapped = KeyState::new();

Check warning on line 105 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L104-L105

Added lines #L104 - L105 were not covered by tests

for symbol in state.pressed() {

Check warning on line 107 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L107

Added line #L107 was not covered by tests
use KeyPosition::*;

mapped.press(match symbol {
Escape => AppleKeys::Esc,
Digit1 => AppleKeys::Digit1,
Digit2 => AppleKeys::Digit2,
Digit3 => AppleKeys::Digit3,
Digit4 => AppleKeys::Digit4,
Digit5 => AppleKeys::Digit5,
Digit6 => AppleKeys::Digit6,
Digit7 => AppleKeys::Digit7,
Digit8 => AppleKeys::Digit8,
Digit9 => AppleKeys::Digit9,
Digit0 => AppleKeys::Digit0,
Minus => AppleKeys::Minus,
Equals => AppleKeys::Equals,
Delete => AppleKeys::Del,

Check warning on line 124 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L110-L124

Added lines #L110 - L124 were not covered by tests

Tab => AppleKeys::Tab,
Q => AppleKeys::Q,
W => AppleKeys::W,
E => AppleKeys::E,
R => AppleKeys::R,
T => AppleKeys::T,
Y => AppleKeys::Y,
U => AppleKeys::U,
I => AppleKeys::I,
O => AppleKeys::O,
P => AppleKeys::P,
LeftBracket => AppleKeys::LeftBracket,
RightBracket => AppleKeys::RightBracket,

Check warning on line 138 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L126-L138

Added lines #L126 - L138 were not covered by tests

LControl | RControl => AppleKeys::Ctrl,
A => AppleKeys::A,
S => AppleKeys::S,
D => AppleKeys::D,
F => AppleKeys::F,
G => AppleKeys::G,
H => AppleKeys::H,
J => AppleKeys::J,
K => AppleKeys::K,
L => AppleKeys::L,
Semicolon => AppleKeys::Semicolon,
Apostrophe => AppleKeys::Apostrophe,
Grave => AppleKeys::Grave,
Enter => AppleKeys::Return,

Check warning on line 153 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L140-L153

Added lines #L140 - L153 were not covered by tests

LShift => AppleKeys::LShift,
Slash => AppleKeys::Slash,
Z => AppleKeys::Z,
X => AppleKeys::X,
C => AppleKeys::C,
V => AppleKeys::V,
B => AppleKeys::B,
N => AppleKeys::N,
M => AppleKeys::M,
Comma => AppleKeys::Comma,
Period => AppleKeys::Period,
Backslash => AppleKeys::Backslash,
RShift => AppleKeys::RShift,

Check warning on line 167 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L155-L167

Added lines #L155 - L167 were not covered by tests

CapsLock => AppleKeys::CapsLock,
LSuper => AppleKeys::OpenApple,
Space => AppleKeys::Space,
RSuper => AppleKeys::ClosedApple,
LeftArrow => AppleKeys::LeftArrow,
RightArrow => AppleKeys::RightArrow,
DownArrow => AppleKeys::DownArrow,
UpArrow => AppleKeys::UpArrow,

Check warning on line 176 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L169-L176

Added lines #L169 - L176 were not covered by tests

NumLock => AppleKeys::NumEsc,

Check warning on line 178 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L178

Added line #L178 was not covered by tests
// NumLeft => AppleKeys::NumLeft,
// NumRight => AppleKeys::NumRight,
// NumSpace => AppleKeys::NumSpace,
Num0 => AppleKeys::Num0,
Num1 => AppleKeys::Num1,
Num2 => AppleKeys::Num2,
Num3 => AppleKeys::Num3,
Num4 => AppleKeys::Num4,
Num5 => AppleKeys::Num5,
Num6 => AppleKeys::Num6,
Num7 => AppleKeys::Num7,
Num8 => AppleKeys::Num8,
Num9 => AppleKeys::Num9,

Check warning on line 191 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L182-L191

Added lines #L182 - L191 were not covered by tests
// NumPeriod => AppleKeys::NumComma,
NumPeriod => AppleKeys::NumPeriod,

Check warning on line 193 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L193

Added line #L193 was not covered by tests
// NumLeftParen => AppleKeys::NumLeftParen,
// NumRightParen => AppleKeys::NumRightParen,
NumMinus => AppleKeys::NumMinus,
NumDivide => AppleKeys::NumDivide,
NumPlus => AppleKeys::NumPlus,
NumMultiply => AppleKeys::NumMultiply,
NumEnter => AppleKeys::NumReturn,
PrintScreen => AppleKeys::NumPrint,

Check warning on line 201 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L196-L201

Added lines #L196 - L201 were not covered by tests

_ => continue,

Check warning on line 203 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L203

Added line #L203 was not covered by tests
});
}

mapped
}

Check warning on line 208 in src/keyboard/apple.rs

View check run for this annotation

Codecov / codecov/patch

src/keyboard/apple.rs#L207-L208

Added lines #L207 - L208 were not covered by tests
}
3 changes: 3 additions & 0 deletions src/keyboard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// Keys and adapters for the Apple ][e and other early Apple machines.
pub mod apple;

/// Keys and adapters for the Commodore 64, VIC-20, and other Commodore machines.
pub mod commodore;

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn main() {
),
SystemArg::Aiie => AiieSystemBuilder::build(
AiieSystemRoms::from_disk(),
AiieSystemConfig { mapping },
AiieSystemConfig {},
platform.provider(),
),

Check warning on line 112 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L108-L112

Added lines #L108 - L112 were not covered by tests
};
Expand Down
60 changes: 42 additions & 18 deletions src/systems/aiie/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
use crate::keyboard::commodore::C64Keys;
use crate::keyboard::apple::AppleKeys;

/// The keyboard matrix found on a Commodore 64.
/// Source: <https://www.c64-wiki.com/wiki/Keyboard>.
pub const KEYBOARD_MAPPING: [[C64Keys; 8]; 8] = {
use C64Keys::*;
pub const KEYBOARD_MAPPING: [[AppleKeys; 10]; 8] = {

Check failure on line 5 in src/systems/aiie/keyboard.rs

View workflow job for this annotation

GitHub Actions / Desktop Build and Style Check

constant `KEYBOARD_MAPPING` is never used

Check warning on line 5 in src/systems/aiie/keyboard.rs

View workflow job for this annotation

GitHub Actions / WASM Build, Docs Build, and Web Deploy

constant `KEYBOARD_MAPPING` is never used
use AppleKeys::*;

[
[
InsertDelete,
Return,
CursorLeftRight,
F7,
F1,
F3,
F5,
CursorUpDown,
Esc, Digit1, Digit2, Digit3, Digit4, Digit6, Digit5, Digit7, Digit8, Digit9,
],
[Tab, Q, W, E, R, Y, T, U, I, O],
[A, D, S, H, F, G, J, K, Semicolon, L],
[Z, X, C, V, B, N, M, Comma, Period, Backslash],
[
NumDivide, NumLeft, Num0, Num1, Num2, Num3, Slash, Equals, Digit0, Minus,
],
[Digit3, W, A, Digit4, Z, S, E, LShift],
[Digit5, R, D, Digit6, C, F, T, X],
[Digit7, Y, G, Digit8, B, H, U, V],
[Digit9, I, J, Digit0, M, K, O, N],
[Plus, P, L, Minus, Period, Colon, At, Comma],
[
Pound, Asterisk, Semicolon, ClrHome, RShift, Equals, UpArrow, Slash,
NumRightParen,
NumEsc,
Num4,
Num5,
Num6,
Num7,
Grave,
P,
LeftBracket,
RightBracket,
],
[
NumMultiply,
NumRight,
Digit8,
Digit9,
NumPeriod,
NumPlus,
Return,
UpArrow,
Space,
Apostrophe,
],
[
Digit1, LeftArrow, Control, Digit2, Space, Commodore, Q, RunStop,
NumPrint,
NumSpace,
NumLeftParen,
NumMinus,
NumReturn,
NumComma,
Del,
DownArrow,
LeftArrow,
RightArrow,
],
]
};
Loading

0 comments on commit adcb889

Please sign in to comment.