-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: Keyboard layout.
- Loading branch information
Showing
4 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Family BASIC Keyboard | ||
|
||
import {Address, Byte} from "../types"; | ||
|
||
export interface Peripheral { | ||
getIoMap(): Map<number, (adr: Address, value?: Byte) => any> | ||
} | ||
|
||
export const enum KeyType { | ||
F8, RETURN, LBRACKET, RBRACKET, KANA, RSHIFT, YEN, STOP, | ||
F7, ATMARK, COLON, SEMICOLON, UNDERSCORE, SLASH, MINUS, HAT, | ||
F6, O, L, K, PERIOD, COMMA, P, NUM0, | ||
F5, I, U, J, M, N, NUM9, NUM8, | ||
F4, Y, G, H, B, V, NUM7, NUM6, | ||
F3, T, R, D, F, C, NUM5, NUM4, | ||
F2, W, S, A, X, Z, E, NUM3, | ||
F1, ESC, Q, CTR, LSHIFT, GRPH, NUM1, NUM2, | ||
CLR_HOME, UP, RIGHT, LEFT, DOWN, SPACE, DEL, INS, | ||
} | ||
|
||
export class Keyboard implements Peripheral { | ||
private ioMap: Map<number, (adr: Address, value?: Byte) => any> | ||
private state = new Uint8Array(10 * 2) | ||
private rowcol = 0 | ||
|
||
constructor() { | ||
this.state.fill(0x1e) | ||
|
||
this.ioMap = new Map<number, (adr: Address, value?: Byte) => any>() | ||
this.ioMap.set(0x4016, (_adr: Address, value?: Byte) => { | ||
const prevcol = this.rowcol & 1 | ||
const col = (value! >> 1) & 1 | ||
this.rowcol = (this.rowcol & ~1) | col | ||
if (col === 0 && prevcol !== 0) // High to low. | ||
this.rowcol = (this.rowcol + 2) % (10 * 2) | ||
if ((value! & 1) !== 0) { | ||
this.rowcol = 0 | ||
} | ||
}) | ||
this.ioMap.set(0x4017, (_adr: Address) => { | ||
const result = this.state[this.rowcol] | ||
this.rowcol += 1 | ||
return result | ||
}) | ||
} | ||
|
||
public getIoMap(): Map<number, (adr: number, value?: Byte) => any> { | ||
return this.ioMap | ||
} | ||
|
||
public setKeyState(type: KeyType, pressed: boolean): void { | ||
const i = type >> 2 | ||
const b = 2 << (type & 3) | ||
const s = this.state[i] | ||
this.state[i] = pressed ? (s & ~b) : (s | b) // Pressed=>clear, not pressed=>set | ||
} | ||
} |