mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 23:52:26 +00:00
Merge pull request #72 from TomHarte/RefactoredTyper
Attempts to clean up the Typer code, reducing duplication and improving per-platform readability
This commit is contained in:
commit
bc83a8f2d0
87
Machines/Commodore/Vic-20/Typer.cpp
Normal file
87
Machines/Commodore/Vic-20/Typer.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// Typer.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 05/11/2016.
|
||||
// Copyright © 2016 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Vic20.hpp"
|
||||
|
||||
uint16_t *Commodore::Vic20::Machine::sequence_for_character(Utility::Typer *typer, char character)
|
||||
{
|
||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
||||
#define SHIFT(...) {KeyLShift, __VA_ARGS__, TerminateSequence}
|
||||
#define X {NotMapped}
|
||||
static Key key_sequences[][3] = {
|
||||
/* NUL */ X, /* SOH */ X,
|
||||
/* STX */ X, /* ETX */ X,
|
||||
/* EOT */ X, /* ENQ */ X,
|
||||
/* ACK */ X, /* BEL */ X,
|
||||
/* BS */ KEYS(KeyDelete), /* HT */ X,
|
||||
/* LF */ KEYS(KeyReturn), /* VT */ X,
|
||||
/* FF */ X, /* CR */ X,
|
||||
/* SO */ X, /* SI */ X,
|
||||
/* DLE */ X, /* DC1 */ X,
|
||||
/* DC2 */ X, /* DC3 */ X,
|
||||
/* DC4 */ X, /* NAK */ X,
|
||||
/* SYN */ X, /* ETB */ X,
|
||||
/* CAN */ X, /* EM */ X,
|
||||
/* SUB */ X, /* ESC */ X,
|
||||
/* FS */ X, /* GS */ X,
|
||||
/* RS */ X, /* US */ X,
|
||||
/* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1),
|
||||
/* " */ SHIFT(Key2), /* # */ SHIFT(Key3),
|
||||
/* $ */ SHIFT(Key4), /* % */ SHIFT(Key5),
|
||||
/* & */ SHIFT(Key6), /* ' */ SHIFT(Key7),
|
||||
/* ( */ SHIFT(Key8), /* ) */ SHIFT(Key9),
|
||||
/* * */ KEYS(KeyAsterisk), /* + */ KEYS(KeyPlus),
|
||||
/* , */ KEYS(KeyComma), /* - */ KEYS(KeyDash),
|
||||
/* . */ KEYS(KeyFullStop), /* / */ KEYS(KeySlash),
|
||||
/* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1),
|
||||
/* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3),
|
||||
/* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5),
|
||||
/* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7),
|
||||
/* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9),
|
||||
/* : */ KEYS(KeyColon), /* ; */ KEYS(KeySemicolon),
|
||||
/* < */ SHIFT(KeyComma), /* = */ KEYS(KeyEquals),
|
||||
/* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeySlash),
|
||||
/* @ */ KEYS(KeyAt), /* A */ KEYS(KeyA),
|
||||
/* B */ KEYS(KeyB), /* C */ KEYS(KeyC),
|
||||
/* D */ KEYS(KeyD), /* E */ KEYS(KeyE),
|
||||
/* F */ KEYS(KeyF), /* G */ KEYS(KeyG),
|
||||
/* H */ KEYS(KeyH), /* I */ KEYS(KeyI),
|
||||
/* J */ KEYS(KeyJ), /* K */ KEYS(KeyK),
|
||||
/* L */ KEYS(KeyL), /* M */ KEYS(KeyM),
|
||||
/* N */ KEYS(KeyN), /* O */ KEYS(KeyO),
|
||||
/* P */ KEYS(KeyP), /* Q */ KEYS(KeyQ),
|
||||
/* R */ KEYS(KeyR), /* S */ KEYS(KeyS),
|
||||
/* T */ KEYS(KeyT), /* U */ KEYS(KeyU),
|
||||
/* V */ KEYS(KeyV), /* W */ KEYS(KeyW),
|
||||
/* X */ KEYS(KeyX), /* Y */ KEYS(KeyY),
|
||||
/* Z */ KEYS(KeyZ), /* [ */ SHIFT(KeyColon),
|
||||
/* \ */ X, /* ] */ SHIFT(KeySemicolon),
|
||||
/* ^ */ X, /* _ */ X,
|
||||
/* ` */ X, /* a */ KEYS(KeyA),
|
||||
/* b */ KEYS(KeyB), /* c */ KEYS(KeyC),
|
||||
/* d */ KEYS(KeyD), /* e */ KEYS(KeyE),
|
||||
/* f */ KEYS(KeyF), /* g */ KEYS(KeyG),
|
||||
/* h */ KEYS(KeyH), /* i */ KEYS(KeyI),
|
||||
/* j */ KEYS(KeyJ), /* k */ KEYS(KeyK),
|
||||
/* l */ KEYS(KeyL), /* m */ KEYS(KeyM),
|
||||
/* n */ KEYS(KeyN), /* o */ KEYS(KeyO),
|
||||
/* p */ KEYS(KeyP), /* q */ KEYS(KeyQ),
|
||||
/* r */ KEYS(KeyR), /* s */ KEYS(KeyS),
|
||||
/* t */ KEYS(KeyT), /* u */ KEYS(KeyU),
|
||||
/* v */ KEYS(KeyV), /* w */ KEYS(KeyW),
|
||||
/* x */ KEYS(KeyX), /* y */ KEYS(KeyY),
|
||||
/* z */ KEYS(KeyZ)
|
||||
};
|
||||
#undef KEYS
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr;
|
||||
if(key_sequences[character][0] == NotMapped) return nullptr;
|
||||
return (uint16_t *)key_sequences[character];
|
||||
}
|
@ -162,7 +162,10 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
if(_typer && operation == CPU6502::BusOperation::ReadOpcode && address == 0xEB1E)
|
||||
{
|
||||
if(!_typer->type_next_character())
|
||||
{
|
||||
clear_all_keys();
|
||||
_typer.reset();
|
||||
}
|
||||
}
|
||||
_tape.run_for_cycles(1);
|
||||
if(_c1540) _c1540->run_for_cycles(1);
|
||||
@ -368,112 +371,6 @@ void Machine::install_disk_rom()
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Typer
|
||||
|
||||
int Machine::get_typer_delay()
|
||||
{
|
||||
return get_is_resetting() ? 1*263*60*65 : 0; // wait a second if resetting
|
||||
}
|
||||
|
||||
int Machine::get_typer_frequency()
|
||||
{
|
||||
return 2*263*65; // accept a new character every two fields
|
||||
}
|
||||
|
||||
bool Machine::typer_set_next_character(::Utility::Typer *typer, char character, int phase)
|
||||
{
|
||||
if(!phase) clear_all_keys();
|
||||
|
||||
// The following table is arranged in ASCII order
|
||||
Key key_sequences[][3] = {
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{KeyDelete, TerminateSequence},
|
||||
{NotMapped},
|
||||
{KeyReturn, TerminateSequence},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
|
||||
{KeySpace, TerminateSequence}, // space
|
||||
|
||||
{KeyLShift, Key1, TerminateSequence}, {KeyLShift, Key2, TerminateSequence}, // !, "
|
||||
{KeyLShift, Key3, TerminateSequence}, {KeyLShift, Key4, TerminateSequence}, // #, $
|
||||
{KeyLShift, Key5, TerminateSequence}, {KeyLShift, Key6, TerminateSequence}, // %, &
|
||||
{KeyLShift, Key7, TerminateSequence}, {KeyLShift, Key8, TerminateSequence}, // ', (
|
||||
{KeyLShift, Key9, TerminateSequence}, {KeyAsterisk, TerminateSequence}, // ), *
|
||||
{KeyPlus, TerminateSequence}, {KeyComma, TerminateSequence}, // +, ,
|
||||
{KeyDash, TerminateSequence}, {KeyFullStop, TerminateSequence}, // -, .
|
||||
{KeySlash, TerminateSequence}, // /
|
||||
|
||||
{Key0, TerminateSequence}, {Key1, TerminateSequence}, // 0, 1
|
||||
{Key2, TerminateSequence}, {Key3, TerminateSequence}, // 2, 3
|
||||
{Key4, TerminateSequence}, {Key5, TerminateSequence}, // 4, 5
|
||||
{Key6, TerminateSequence}, {Key7, TerminateSequence}, // 6, 7
|
||||
{Key8, TerminateSequence}, {Key9, TerminateSequence}, // 8, 9
|
||||
|
||||
{KeyColon, TerminateSequence}, {KeySemicolon, TerminateSequence}, // :, ;
|
||||
{KeyLShift, KeyComma, TerminateSequence}, {KeyEquals, TerminateSequence}, // <, =
|
||||
{KeyLShift, KeyFullStop, TerminateSequence}, {KeyLShift, KeySlash, TerminateSequence}, // >, ?
|
||||
{KeyAt, TerminateSequence}, // @
|
||||
|
||||
{KeyA, TerminateSequence}, {KeyB, TerminateSequence}, {KeyC, TerminateSequence}, {KeyD, TerminateSequence}, // A, B, C, D
|
||||
{KeyE, TerminateSequence}, {KeyF, TerminateSequence}, {KeyG, TerminateSequence}, {KeyH, TerminateSequence}, // E, F, G, H
|
||||
{KeyI, TerminateSequence}, {KeyJ, TerminateSequence}, {KeyK, TerminateSequence}, {KeyL, TerminateSequence}, // I, J, K L
|
||||
{KeyM, TerminateSequence}, {KeyN, TerminateSequence}, {KeyO, TerminateSequence}, {KeyP, TerminateSequence}, // M, N, O, P
|
||||
{KeyQ, TerminateSequence}, {KeyR, TerminateSequence}, {KeyS, TerminateSequence}, {KeyT, TerminateSequence}, // Q, R, S, T
|
||||
{KeyU, TerminateSequence}, {KeyV, TerminateSequence}, {KeyW, TerminateSequence}, {KeyX, TerminateSequence}, // U, V, W X
|
||||
{KeyY, TerminateSequence}, {KeyZ, TerminateSequence}, // Y, Z
|
||||
|
||||
{KeyLShift, KeyColon, TerminateSequence}, {NotMapped}, // [, '\'
|
||||
{KeyLShift, KeyFullStop, TerminateSequence}, {NotMapped}, // ], ^
|
||||
{NotMapped}, {NotMapped}, // _, `
|
||||
|
||||
{KeyA, TerminateSequence}, {KeyB, TerminateSequence}, {KeyC, TerminateSequence}, {KeyD, TerminateSequence}, // A, B, C, D
|
||||
{KeyE, TerminateSequence}, {KeyF, TerminateSequence}, {KeyG, TerminateSequence}, {KeyH, TerminateSequence}, // E, F, G, H
|
||||
{KeyI, TerminateSequence}, {KeyJ, TerminateSequence}, {KeyK, TerminateSequence}, {KeyL, TerminateSequence}, // I, J, K L
|
||||
{KeyM, TerminateSequence}, {KeyN, TerminateSequence}, {KeyO, TerminateSequence}, {KeyP, TerminateSequence}, // M, N, O, P
|
||||
{KeyQ, TerminateSequence}, {KeyR, TerminateSequence}, {KeyS, TerminateSequence}, {KeyT, TerminateSequence}, // Q, R, S, T
|
||||
{KeyU, TerminateSequence}, {KeyV, TerminateSequence}, {KeyW, TerminateSequence}, {KeyX, TerminateSequence}, // U, V, W X
|
||||
{KeyY, TerminateSequence}, {KeyZ, TerminateSequence}, // Y, Z
|
||||
// {KeyLShift, KeyA, TerminateSequence}, {KeyLShift, KeyB, TerminateSequence}, // a, b
|
||||
// {KeyLShift, KeyC, TerminateSequence}, {KeyLShift, KeyD, TerminateSequence}, // c, d
|
||||
// {KeyLShift, KeyE, TerminateSequence}, {KeyLShift, KeyF, TerminateSequence}, // e, f
|
||||
// {KeyLShift, KeyG, TerminateSequence}, {KeyLShift, KeyH, TerminateSequence}, // g, h
|
||||
// {KeyLShift, KeyI, TerminateSequence}, {KeyLShift, KeyJ, TerminateSequence}, // i, j
|
||||
// {KeyLShift, KeyK, TerminateSequence}, {KeyLShift, KeyL, TerminateSequence}, // k, l
|
||||
// {KeyLShift, KeyM, TerminateSequence}, {KeyLShift, KeyN, TerminateSequence}, // m, n
|
||||
// {KeyLShift, KeyO, TerminateSequence}, {KeyLShift, KeyP, TerminateSequence}, // o, p
|
||||
// {KeyLShift, KeyQ, TerminateSequence}, {KeyLShift, KeyR, TerminateSequence}, // q, r
|
||||
// {KeyLShift, KeyS, TerminateSequence}, {KeyLShift, KeyT, TerminateSequence}, // s, t
|
||||
// {KeyLShift, KeyU, TerminateSequence}, {KeyLShift, KeyV, TerminateSequence}, // u, v
|
||||
// {KeyLShift, KeyW, TerminateSequence}, {KeyLShift, KeyX, TerminateSequence}, // w, x
|
||||
// {KeyLShift, KeyY, TerminateSequence}, {KeyLShift, KeyZ, TerminateSequence}, // y, z
|
||||
|
||||
};
|
||||
Key *key_sequence = nullptr;
|
||||
|
||||
character &= 0x7f;
|
||||
if(character < sizeof(key_sequences) / sizeof(*key_sequences))
|
||||
{
|
||||
key_sequence = key_sequences[character];
|
||||
|
||||
if(key_sequence[0] != NotMapped)
|
||||
{
|
||||
if(phase > 0)
|
||||
{
|
||||
set_key_state(key_sequence[phase-1], true);
|
||||
return key_sequence[phase] == TerminateSequence;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma mark - UserPortVIA
|
||||
|
||||
uint8_t UserPortVIA::get_port_input(Port port)
|
||||
@ -535,7 +432,7 @@ KeyboardVIA::KeyboardVIA() : _portB(0xff)
|
||||
clear_all_keys();
|
||||
}
|
||||
|
||||
void KeyboardVIA::set_key_state(Key key, bool isPressed)
|
||||
void KeyboardVIA::set_key_state(uint16_t key, bool isPressed)
|
||||
{
|
||||
if(isPressed)
|
||||
_columns[key & 7] &= ~(key >> 3);
|
||||
|
@ -64,7 +64,7 @@ enum Key: uint16_t {
|
||||
Key1 = key(0, 0x01), Key3 = key(0, 0x02), Key5 = key(0, 0x04), Key7 = key(0, 0x08),
|
||||
Key9 = key(0, 0x10), KeyPlus = key(0, 0x20), KeyGBP = key(0, 0x40), KeyDelete = key(0, 0x80),
|
||||
|
||||
TerminateSequence = 0, NotMapped = 0xffff
|
||||
TerminateSequence = 0xffff, NotMapped = 0xfffe
|
||||
};
|
||||
|
||||
enum JoystickInput {
|
||||
@ -98,7 +98,7 @@ class KeyboardVIA: public MOS::MOS6522<KeyboardVIA>, public MOS::MOS6522IRQDeleg
|
||||
KeyboardVIA();
|
||||
using MOS6522IRQDelegate::set_interrupt_status;
|
||||
|
||||
void set_key_state(Key key, bool isPressed);
|
||||
void set_key_state(uint16_t key, bool isPressed);
|
||||
void clear_all_keys();
|
||||
|
||||
// to satisfy MOS::MOS6522
|
||||
@ -157,7 +157,7 @@ class Machine:
|
||||
// void set_tape(std::shared_ptr<Storage::Tape::Tape> tape);
|
||||
// void set_disk(std::shared_ptr<Storage::Disk::Disk> disk);
|
||||
|
||||
void set_key_state(Key key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); }
|
||||
void set_key_state(uint16_t key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); }
|
||||
void clear_all_keys() { _keyboardVIA->clear_all_keys(); }
|
||||
void set_joystick_state(JoystickInput input, bool isPressed) {
|
||||
_userPortVIA->set_joystick_state(input, isPressed);
|
||||
@ -186,9 +186,7 @@ class Machine:
|
||||
virtual void mos6522_did_change_interrupt_status(void *mos6522);
|
||||
|
||||
// for Utility::TypeRecipient
|
||||
virtual int get_typer_delay();
|
||||
virtual int get_typer_frequency();
|
||||
virtual bool typer_set_next_character(Utility::Typer *typer, char character, int phase);
|
||||
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
||||
|
||||
// for Tape::Delegate
|
||||
virtual void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape);
|
||||
|
@ -916,7 +916,7 @@ void Machine::clear_all_keys()
|
||||
memset(_key_states, 0, sizeof(_key_states));
|
||||
}
|
||||
|
||||
void Machine::set_key_state(Key key, bool isPressed)
|
||||
void Machine::set_key_state(uint16_t key, bool isPressed)
|
||||
{
|
||||
if(key == KeyBreak)
|
||||
{
|
||||
@ -1099,98 +1099,3 @@ inline void Tape::run_for_cycles(unsigned int number_of_cycles)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Typer
|
||||
|
||||
int Machine::get_typer_delay()
|
||||
{
|
||||
return get_is_resetting() ? 625*25*128 : 0; // wait one second if resetting
|
||||
}
|
||||
|
||||
int Machine::get_typer_frequency()
|
||||
{
|
||||
return 625*128; // accept a new character every frame
|
||||
}
|
||||
|
||||
bool Machine::typer_set_next_character(::Utility::Typer *typer, char character, int phase)
|
||||
{
|
||||
if(!phase) clear_all_keys();
|
||||
|
||||
// The following table is arranged in ASCII order
|
||||
Key key_sequences[][3] = {
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{KeyDelete, TerminateSequence},
|
||||
{NotMapped},
|
||||
{KeyReturn, TerminateSequence},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
|
||||
{KeySpace, TerminateSequence}, // space
|
||||
|
||||
{KeyShift, Key1, TerminateSequence}, {KeyShift, Key2, TerminateSequence}, // !, "
|
||||
{KeyShift, Key3, TerminateSequence}, {KeyShift, Key4, TerminateSequence}, // #, $
|
||||
{KeyShift, Key5, TerminateSequence}, {KeyShift, Key6, TerminateSequence}, // %, &
|
||||
{KeyShift, Key7, TerminateSequence}, {KeyShift, Key8, TerminateSequence}, // ', (
|
||||
{KeyShift, Key9, TerminateSequence}, {KeyShift, KeyColon, TerminateSequence}, // ), *
|
||||
{KeyShift, KeySemiColon, TerminateSequence}, {KeyComma, TerminateSequence}, // +, ,
|
||||
{KeyMinus, TerminateSequence}, {KeyFullStop, TerminateSequence}, // -, .
|
||||
{KeySlash, TerminateSequence}, // /
|
||||
|
||||
{Key0, TerminateSequence}, {Key1, TerminateSequence}, // 0, 1
|
||||
{Key2, TerminateSequence}, {Key3, TerminateSequence}, // 2, 3
|
||||
{Key4, TerminateSequence}, {Key5, TerminateSequence}, // 4, 5
|
||||
{Key6, TerminateSequence}, {Key7, TerminateSequence}, // 6, 7
|
||||
{Key8, TerminateSequence}, {Key9, TerminateSequence}, // 8, 9
|
||||
|
||||
{KeyColon, TerminateSequence}, {KeySemiColon, TerminateSequence}, // :, ;
|
||||
{KeyShift, KeyComma, TerminateSequence}, {KeyShift, KeyMinus, TerminateSequence}, // <, =
|
||||
{KeyShift, KeyFullStop, TerminateSequence}, {KeyShift, KeySlash, TerminateSequence}, // >, ?
|
||||
{KeyShift, Key0, TerminateSequence}, // @
|
||||
|
||||
{KeyA, TerminateSequence}, {KeyB, TerminateSequence}, {KeyC, TerminateSequence}, {KeyD, TerminateSequence}, // A, B, C, D
|
||||
{KeyE, TerminateSequence}, {KeyF, TerminateSequence}, {KeyG, TerminateSequence}, {KeyH, TerminateSequence}, // E, F, G, H
|
||||
{KeyI, TerminateSequence}, {KeyJ, TerminateSequence}, {KeyK, TerminateSequence}, {KeyL, TerminateSequence}, // I, J, K L
|
||||
{KeyM, TerminateSequence}, {KeyN, TerminateSequence}, {KeyO, TerminateSequence}, {KeyP, TerminateSequence}, // M, N, O, P
|
||||
{KeyQ, TerminateSequence}, {KeyR, TerminateSequence}, {KeyS, TerminateSequence}, {KeyT, TerminateSequence}, // Q, R, S, T
|
||||
{KeyU, TerminateSequence}, {KeyV, TerminateSequence}, {KeyW, TerminateSequence}, {KeyX, TerminateSequence}, // U, V, W X
|
||||
{KeyY, TerminateSequence}, {KeyZ, TerminateSequence}, // Y, Z
|
||||
|
||||
{KeyShift, KeyCopy, TerminateSequence}, {KeyControl, KeyRight, TerminateSequence}, // [, '\'
|
||||
{KeyControl, KeyCopy, TerminateSequence}, {KeyShift, KeyLeft, TerminateSequence}, // ], ^
|
||||
{KeyShift, KeyDown, TerminateSequence}, {NotMapped}, // _, `
|
||||
|
||||
{KeyShift, KeyA, TerminateSequence}, {KeyShift, KeyB, TerminateSequence}, {KeyShift, KeyC, TerminateSequence}, {KeyShift, KeyD, TerminateSequence}, // a, b, c, d
|
||||
{KeyShift, KeyE, TerminateSequence}, {KeyShift, KeyF, TerminateSequence}, {KeyShift, KeyG, TerminateSequence}, {KeyShift, KeyH, TerminateSequence}, // e, f, g, h
|
||||
{KeyShift, KeyI, TerminateSequence}, {KeyShift, KeyJ, TerminateSequence}, {KeyShift, KeyK, TerminateSequence}, {KeyShift, KeyL, TerminateSequence}, // i, j, k, l
|
||||
{KeyShift, KeyM, TerminateSequence}, {KeyShift, KeyN, TerminateSequence}, {KeyShift, KeyO, TerminateSequence}, {KeyShift, KeyP, TerminateSequence}, // m, n, o, p
|
||||
{KeyShift, KeyQ, TerminateSequence}, {KeyShift, KeyR, TerminateSequence}, {KeyShift, KeyS, TerminateSequence}, {KeyShift, KeyT, TerminateSequence}, // q, r, s, t
|
||||
{KeyShift, KeyU, TerminateSequence}, {KeyShift, KeyV, TerminateSequence}, {KeyShift, KeyW, TerminateSequence}, {KeyShift, KeyX, TerminateSequence}, // u, v, w, x
|
||||
{KeyShift, KeyY, TerminateSequence}, {KeyShift, KeyZ, TerminateSequence}, // y, z
|
||||
|
||||
{KeyControl, KeyUp, TerminateSequence}, {KeyShift, KeyRight, TerminateSequence}, // {, |
|
||||
{KeyControl, KeyDown, TerminateSequence}, {KeyControl, KeyLeft, TerminateSequence}, // }, ~
|
||||
};
|
||||
Key *key_sequence = nullptr;
|
||||
|
||||
character &= 0x7f;
|
||||
if(character < sizeof(key_sequences) / sizeof(*key_sequences))
|
||||
{
|
||||
key_sequence = key_sequences[character];
|
||||
|
||||
if(key_sequence[0] != NotMapped)
|
||||
{
|
||||
if(phase > 0)
|
||||
{
|
||||
set_key_state(key_sequence[phase-1], true);
|
||||
return key_sequence[phase] == TerminateSequence;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ enum Key: uint16_t {
|
||||
KeyZ = 0x00c0 | 0x08, KeyA = 0x00c0 | 0x04, KeyQ = 0x00c0 | 0x02, Key1 = 0x00c0 | 0x01,
|
||||
KeyShift = 0x00d0 | 0x08, KeyControl = 0x00d0 | 0x04, KeyFunc = 0x00d0 | 0x02, KeyEscape = 0x00d0 | 0x01,
|
||||
|
||||
KeyBreak = 0xffff,
|
||||
KeyBreak = 0xfffd,
|
||||
|
||||
TerminateSequence = 0, NotMapped = 0xfffe,
|
||||
TerminateSequence = 0xffff, NotMapped = 0xfffe,
|
||||
};
|
||||
|
||||
class Tape: public Storage::Tape::TapePlayer {
|
||||
@ -149,7 +149,7 @@ class Machine:
|
||||
|
||||
void set_rom(ROMSlot slot, std::vector<uint8_t> data, bool is_writeable);
|
||||
|
||||
void set_key_state(Key key, bool isPressed);
|
||||
void set_key_state(uint16_t key, bool isPressed);
|
||||
void clear_all_keys();
|
||||
|
||||
inline void set_use_fast_tape_hack(bool activate) { _use_fast_tape_hack = activate; }
|
||||
@ -174,7 +174,7 @@ class Machine:
|
||||
// for Utility::TypeRecipient
|
||||
virtual int get_typer_delay();
|
||||
virtual int get_typer_frequency();
|
||||
virtual bool typer_set_next_character(Utility::Typer *typer, char character, int phase);
|
||||
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
||||
|
||||
private:
|
||||
|
||||
|
100
Machines/Electron/Typer.cpp
Normal file
100
Machines/Electron/Typer.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
//
|
||||
// Typer.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 05/11/2016.
|
||||
// Copyright © 2016 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Electron.hpp"
|
||||
|
||||
int Electron::Machine::get_typer_delay()
|
||||
{
|
||||
return get_is_resetting() ? 625*25*128 : 0; // wait one second if resetting
|
||||
}
|
||||
|
||||
int Electron::Machine::get_typer_frequency()
|
||||
{
|
||||
return 625*128*2; // accept a new character every two frames
|
||||
}
|
||||
|
||||
uint16_t *Electron::Machine::sequence_for_character(Utility::Typer *typer, char character)
|
||||
{
|
||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
||||
#define SHIFT(...) {KeyShift, __VA_ARGS__, TerminateSequence}
|
||||
#define CTRL(...) {KeyControl, __VA_ARGS__, TerminateSequence}
|
||||
#define X {NotMapped}
|
||||
static Key key_sequences[][3] = {
|
||||
/* NUL */ X, /* SOH */ X,
|
||||
/* STX */ X, /* ETX */ X,
|
||||
/* EOT */ X, /* ENQ */ X,
|
||||
/* ACK */ X, /* BEL */ X,
|
||||
/* BS */ KEYS(KeyDelete), /* HT */ X,
|
||||
/* LF */ KEYS(KeyReturn), /* VT */ X,
|
||||
/* FF */ X, /* CR */ X,
|
||||
/* SO */ X, /* SI */ X,
|
||||
/* DLE */ X, /* DC1 */ X,
|
||||
/* DC2 */ X, /* DC3 */ X,
|
||||
/* DC4 */ X, /* NAK */ X,
|
||||
/* SYN */ X, /* ETB */ X,
|
||||
/* CAN */ X, /* EM */ X,
|
||||
/* SUB */ X, /* ESC */ X,
|
||||
/* FS */ X, /* GS */ X,
|
||||
/* RS */ X, /* US */ X,
|
||||
/* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1),
|
||||
/* " */ SHIFT(Key2), /* # */ SHIFT(Key3),
|
||||
/* $ */ SHIFT(Key4), /* % */ SHIFT(Key5),
|
||||
/* & */ SHIFT(Key6), /* ' */ SHIFT(Key7),
|
||||
/* ( */ SHIFT(Key8), /* ) */ SHIFT(Key9),
|
||||
/* * */ SHIFT(KeyColon), /* + */ SHIFT(KeySemiColon),
|
||||
/* , */ KEYS(KeyComma), /* - */ KEYS(KeyMinus),
|
||||
/* . */ KEYS(KeyFullStop), /* / */ KEYS(KeySlash),
|
||||
/* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1),
|
||||
/* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3),
|
||||
/* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5),
|
||||
/* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7),
|
||||
/* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9),
|
||||
/* : */ KEYS(KeyColon), /* ; */ KEYS(KeySemiColon),
|
||||
/* < */ SHIFT(KeyComma), /* = */ SHIFT(KeyMinus),
|
||||
/* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeySlash),
|
||||
/* @ */ SHIFT(Key0), /* A */ KEYS(KeyA),
|
||||
/* B */ KEYS(KeyB), /* C */ KEYS(KeyC),
|
||||
/* D */ KEYS(KeyD), /* E */ KEYS(KeyE),
|
||||
/* F */ KEYS(KeyF), /* G */ KEYS(KeyG),
|
||||
/* H */ KEYS(KeyH), /* I */ KEYS(KeyI),
|
||||
/* J */ KEYS(KeyJ), /* K */ KEYS(KeyK),
|
||||
/* L */ KEYS(KeyL), /* M */ KEYS(KeyM),
|
||||
/* N */ KEYS(KeyN), /* O */ KEYS(KeyO),
|
||||
/* P */ KEYS(KeyP), /* Q */ KEYS(KeyQ),
|
||||
/* R */ KEYS(KeyR), /* S */ KEYS(KeyS),
|
||||
/* T */ KEYS(KeyT), /* U */ KEYS(KeyU),
|
||||
/* V */ KEYS(KeyV), /* W */ KEYS(KeyW),
|
||||
/* X */ KEYS(KeyX), /* Y */ KEYS(KeyY),
|
||||
/* Z */ KEYS(KeyZ), /* [ */ SHIFT(KeyCopy),
|
||||
/* \ */ CTRL(KeyRight), /* ] */ CTRL(KeyCopy),
|
||||
/* ^ */ SHIFT(KeyLeft), /* _ */ SHIFT(KeyDown),
|
||||
/* ` */ X, /* a */ SHIFT(KeyA),
|
||||
/* b */ SHIFT(KeyB), /* c */ SHIFT(KeyC),
|
||||
/* d */ SHIFT(KeyD), /* e */ SHIFT(KeyE),
|
||||
/* f */ SHIFT(KeyF), /* g */ SHIFT(KeyG),
|
||||
/* h */ SHIFT(KeyH), /* i */ SHIFT(KeyI),
|
||||
/* j */ SHIFT(KeyJ), /* k */ SHIFT(KeyK),
|
||||
/* l */ SHIFT(KeyL), /* m */ SHIFT(KeyM),
|
||||
/* n */ SHIFT(KeyN), /* o */ SHIFT(KeyO),
|
||||
/* p */ SHIFT(KeyP), /* q */ SHIFT(KeyQ),
|
||||
/* r */ SHIFT(KeyR), /* s */ SHIFT(KeyS),
|
||||
/* t */ SHIFT(KeyT), /* u */ SHIFT(KeyU),
|
||||
/* v */ SHIFT(KeyV), /* w */ SHIFT(KeyW),
|
||||
/* x */ SHIFT(KeyX), /* y */ SHIFT(KeyY),
|
||||
/* z */ SHIFT(KeyZ), /* { */ CTRL(KeyUp),
|
||||
/* | */ SHIFT(KeyRight), /* } */ CTRL(KeyDown),
|
||||
/* ~ */ CTRL(KeyLeft)
|
||||
};
|
||||
#undef KEYS
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr;
|
||||
if(key_sequences[character][0] == NotMapped) return nullptr;
|
||||
return (uint16_t *)key_sequences[character];
|
||||
}
|
22
Machines/KeyboardMachine.hpp
Normal file
22
Machines/KeyboardMachine.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// KeyboardMachine.h
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 05/11/2016.
|
||||
// Copyright © 2016 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef KeyboardMachine_h
|
||||
#define KeyboardMachine_h
|
||||
|
||||
namespace KeyboardMachine {
|
||||
|
||||
class Machine {
|
||||
public:
|
||||
virtual void set_key_state(uint16_t key, bool isPressed) = 0;
|
||||
virtual void clear_all_keys() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* KeyboardMachine_h */
|
@ -81,7 +81,11 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin
|
||||
|
||||
if(_typer && operation == CPU6502::BusOperation::ReadOpcode && address == 0xF495)
|
||||
{
|
||||
if(!_typer->type_next_character()) _typer.reset();
|
||||
if(!_typer->type_next_character())
|
||||
{
|
||||
clear_all_keys();
|
||||
_typer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
_via.run_for_cycles(1);
|
||||
@ -119,7 +123,7 @@ void Machine::mos6522_did_change_interrupt_status(void *mos6522)
|
||||
set_irq_line(_via.get_interrupt_line());
|
||||
}
|
||||
|
||||
void Machine::set_key_state(Key key, bool isPressed)
|
||||
void Machine::set_key_state(uint16_t key, bool isPressed)
|
||||
{
|
||||
if(key == KeyNMI)
|
||||
{
|
||||
@ -165,91 +169,6 @@ void Machine::run_for_cycles(int number_of_cycles)
|
||||
CPU6502::Processor<Machine>::run_for_cycles(number_of_cycles);
|
||||
}
|
||||
|
||||
#pragma mark - Automatic typing
|
||||
|
||||
bool Machine::typer_set_next_character(::Utility::Typer *typer, char character, int phase)
|
||||
{
|
||||
if(!phase) clear_all_keys();
|
||||
|
||||
// The following table is arranged in ASCII order
|
||||
Key key_sequences[][3] = {
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{KeyDelete, TerminateSequence},
|
||||
{NotMapped},
|
||||
{KeyReturn, TerminateSequence},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
{NotMapped}, {NotMapped}, {NotMapped}, {NotMapped},
|
||||
|
||||
{KeySpace, TerminateSequence}, // space
|
||||
|
||||
{KeyLeftShift, Key1, TerminateSequence}, {KeyLeftShift, KeyQuote, TerminateSequence}, // !, "
|
||||
{KeyLeftShift, Key3, TerminateSequence}, {KeyLeftShift, Key4, TerminateSequence}, // #, $
|
||||
{KeyLeftShift, Key5, TerminateSequence}, {KeyLeftShift, Key7, TerminateSequence}, // %, &
|
||||
{KeyQuote, TerminateSequence}, {KeyLeftShift, Key9, TerminateSequence}, // ', (
|
||||
{KeyLeftShift, Key0, TerminateSequence}, {KeyLeftShift, Key8, TerminateSequence}, // ), *
|
||||
{KeyLeftShift, KeyEquals, TerminateSequence}, {KeyComma, TerminateSequence}, // +, ,
|
||||
{KeyMinus, TerminateSequence}, {KeyFullStop, TerminateSequence}, // -, .
|
||||
{KeyForwardSlash, TerminateSequence}, // /
|
||||
|
||||
{Key0, TerminateSequence}, {Key1, TerminateSequence}, // 0, 1
|
||||
{Key2, TerminateSequence}, {Key3, TerminateSequence}, // 2, 3
|
||||
{Key4, TerminateSequence}, {Key5, TerminateSequence}, // 4, 5
|
||||
{Key6, TerminateSequence}, {Key7, TerminateSequence}, // 6, 7
|
||||
{Key8, TerminateSequence}, {Key9, TerminateSequence}, // 8, 9
|
||||
|
||||
{KeyLeftShift, KeySemiColon, TerminateSequence}, {KeySemiColon, TerminateSequence}, // :, ;
|
||||
{KeyLeftShift, KeyComma, TerminateSequence}, {KeyEquals, TerminateSequence}, // <, =
|
||||
{KeyLeftShift, KeyFullStop, TerminateSequence}, {KeyLeftShift, KeyForwardSlash, TerminateSequence}, // >, ?
|
||||
{KeyLeftShift, Key2, TerminateSequence}, // @
|
||||
|
||||
{KeyLeftShift, KeyA, TerminateSequence}, {KeyLeftShift, KeyB, TerminateSequence}, {KeyLeftShift, KeyC, TerminateSequence}, {KeyLeftShift, KeyD, TerminateSequence}, // A, B, C, D
|
||||
{KeyLeftShift, KeyE, TerminateSequence}, {KeyLeftShift, KeyF, TerminateSequence}, {KeyLeftShift, KeyG, TerminateSequence}, {KeyLeftShift, KeyH, TerminateSequence}, // E, F, G, H
|
||||
{KeyLeftShift, KeyI, TerminateSequence}, {KeyLeftShift, KeyJ, TerminateSequence}, {KeyLeftShift, KeyK, TerminateSequence}, {KeyLeftShift, KeyL, TerminateSequence}, // I, J, K L
|
||||
{KeyLeftShift, KeyM, TerminateSequence}, {KeyLeftShift, KeyN, TerminateSequence}, {KeyLeftShift, KeyO, TerminateSequence}, {KeyLeftShift, KeyP, TerminateSequence}, // M, N, O, P
|
||||
{KeyLeftShift, KeyQ, TerminateSequence}, {KeyLeftShift, KeyR, TerminateSequence}, {KeyLeftShift, KeyS, TerminateSequence}, {KeyLeftShift, KeyT, TerminateSequence}, // Q, R, S, T
|
||||
{KeyLeftShift, KeyU, TerminateSequence}, {KeyLeftShift, KeyV, TerminateSequence}, {KeyLeftShift, KeyW, TerminateSequence}, {KeyLeftShift, KeyX, TerminateSequence}, // U, V, W X
|
||||
{KeyLeftShift, KeyY, TerminateSequence}, {KeyLeftShift, KeyZ, TerminateSequence}, // Y, Z
|
||||
|
||||
{KeyOpenSquare, TerminateSequence}, {KeyBackSlash, TerminateSequence}, // [, '\'
|
||||
{KeyCloseSquare, TerminateSequence}, {KeyLeftShift, Key6, TerminateSequence}, // ], ^
|
||||
{NotMapped}, {NotMapped}, // _, `
|
||||
|
||||
{KeyA, TerminateSequence}, {KeyB, TerminateSequence}, {KeyC, TerminateSequence}, {KeyD, TerminateSequence}, // A, B, C, D
|
||||
{KeyE, TerminateSequence}, {KeyF, TerminateSequence}, {KeyG, TerminateSequence}, {KeyH, TerminateSequence}, // E, F, G, H
|
||||
{KeyI, TerminateSequence}, {KeyJ, TerminateSequence}, {KeyK, TerminateSequence}, {KeyL, TerminateSequence}, // I, J, K L
|
||||
{KeyM, TerminateSequence}, {KeyN, TerminateSequence}, {KeyO, TerminateSequence}, {KeyP, TerminateSequence}, // M, N, O, P
|
||||
{KeyQ, TerminateSequence}, {KeyR, TerminateSequence}, {KeyS, TerminateSequence}, {KeyT, TerminateSequence}, // Q, R, S, T
|
||||
{KeyU, TerminateSequence}, {KeyV, TerminateSequence}, {KeyW, TerminateSequence}, {KeyX, TerminateSequence}, // U, V, W X
|
||||
{KeyY, TerminateSequence}, {KeyZ, TerminateSequence}, // Y, Z
|
||||
|
||||
{KeyLeftShift, KeyOpenSquare, TerminateSequence}, {KeyLeftShift, KeyBackSlash, TerminateSequence}, // {, |
|
||||
{KeyLeftShift, KeyCloseSquare, TerminateSequence}, // }, ~
|
||||
};
|
||||
Key *key_sequence = nullptr;
|
||||
|
||||
character &= 0x7f;
|
||||
if(character < sizeof(key_sequences) / sizeof(*key_sequences))
|
||||
{
|
||||
key_sequence = key_sequences[character];
|
||||
|
||||
if(key_sequence[0] != NotMapped)
|
||||
{
|
||||
if(phase)
|
||||
{
|
||||
set_key_state(key_sequence[phase-1], true);
|
||||
return key_sequence[phase] == TerminateSequence;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma mark - The 6522
|
||||
|
||||
Machine::VIA::VIA() : MOS::MOS6522<Machine::VIA>(), _cycles_since_ay_update(0) {}
|
||||
|
@ -45,9 +45,9 @@ enum Key: uint16_t {
|
||||
KeyEquals = 0x0700 | 0x80, KeyReturn = 0x0700 | 0x20, KeyRightShift = 0x0700 | 0x10,
|
||||
KeyForwardSlash = 0x0700 | 0x08, Key0 = 0x0700 | 0x04, KeyL = 0x0700 | 0x02, Key8 = 0x0700 | 0x01,
|
||||
|
||||
KeyNMI = 0xffff,
|
||||
KeyNMI = 0xfffd,
|
||||
|
||||
TerminateSequence = 0xfffe, NotMapped = 0xfffc
|
||||
TerminateSequence = 0xffff, NotMapped = 0xfffe
|
||||
};
|
||||
|
||||
class Machine:
|
||||
@ -62,7 +62,7 @@ class Machine:
|
||||
Machine();
|
||||
|
||||
void set_rom(std::vector<uint8_t> data);
|
||||
void set_key_state(Key key, bool isPressed);
|
||||
void set_key_state(uint16_t key, bool isPressed);
|
||||
void clear_all_keys();
|
||||
|
||||
void set_use_fast_tape_hack(bool activate);
|
||||
@ -87,8 +87,8 @@ class Machine:
|
||||
// to satisfy Storage::Tape::BinaryTapePlayer::Delegate
|
||||
void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape_player);
|
||||
|
||||
// for Utility::TypeRecipient
|
||||
virtual bool typer_set_next_character(Utility::Typer *typer, char character, int phase);
|
||||
// for Utility::TypeRecipient::Delegate
|
||||
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
|
||||
|
||||
private:
|
||||
// RAM and ROM
|
||||
|
80
Machines/Oric/Typer.cpp
Normal file
80
Machines/Oric/Typer.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include "Oric.hpp"
|
||||
|
||||
uint16_t *Oric::Machine::sequence_for_character(Utility::Typer *typer, char character)
|
||||
{
|
||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
||||
#define SHIFT(...) {KeyLeftShift, __VA_ARGS__, TerminateSequence}
|
||||
#define X {NotMapped}
|
||||
static Key key_sequences[][3] = {
|
||||
/* NUL */ X, /* SOH */ X,
|
||||
/* STX */ X, /* ETX */ X,
|
||||
/* EOT */ X, /* ENQ */ X,
|
||||
/* ACK */ X, /* BEL */ X,
|
||||
/* BS */ KEYS(KeyDelete), /* HT */ X,
|
||||
/* LF */ KEYS(KeyReturn), /* VT */ X,
|
||||
/* FF */ X, /* CR */ X,
|
||||
/* SO */ X, /* SI */ X,
|
||||
/* DLE */ X, /* DC1 */ X,
|
||||
/* DC2 */ X, /* DC3 */ X,
|
||||
/* DC4 */ X, /* NAK */ X,
|
||||
/* SYN */ X, /* ETB */ X,
|
||||
/* CAN */ X, /* EM */ X,
|
||||
/* SUB */ X, /* ESC */ X,
|
||||
/* FS */ X, /* GS */ X,
|
||||
/* RS */ X, /* US */ X,
|
||||
/* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1),
|
||||
/* " */ SHIFT(KeyQuote), /* # */ SHIFT(Key3),
|
||||
/* $ */ SHIFT(Key4), /* % */ SHIFT(Key5),
|
||||
/* & */ SHIFT(Key7), /* ' */ KEYS(KeyQuote),
|
||||
/* ( */ SHIFT(Key9), /* ) */ SHIFT(Key0),
|
||||
/* * */ SHIFT(Key8), /* + */ SHIFT(KeyEquals),
|
||||
/* , */ KEYS(KeyComma), /* - */ KEYS(KeyMinus),
|
||||
/* . */ KEYS(KeyFullStop), /* / */ KEYS(KeyForwardSlash),
|
||||
/* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1),
|
||||
/* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3),
|
||||
/* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5),
|
||||
/* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7),
|
||||
/* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9),
|
||||
/* : */ SHIFT(KeySemiColon), /* ; */ KEYS(KeySemiColon),
|
||||
/* < */ SHIFT(KeyComma), /* = */ KEYS(KeyEquals),
|
||||
/* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeyForwardSlash),
|
||||
/* @ */ SHIFT(Key2), /* A */ SHIFT(KeyA),
|
||||
/* B */ SHIFT(KeyB), /* C */ SHIFT(KeyC),
|
||||
/* D */ SHIFT(KeyD), /* E */ SHIFT(KeyE),
|
||||
/* F */ SHIFT(KeyF), /* G */ SHIFT(KeyG),
|
||||
/* H */ SHIFT(KeyH), /* I */ SHIFT(KeyI),
|
||||
/* J */ SHIFT(KeyJ), /* K */ SHIFT(KeyK),
|
||||
/* L */ SHIFT(KeyL), /* M */ SHIFT(KeyM),
|
||||
/* N */ SHIFT(KeyN), /* O */ SHIFT(KeyO),
|
||||
/* P */ SHIFT(KeyP), /* Q */ SHIFT(KeyQ),
|
||||
/* R */ SHIFT(KeyR), /* S */ SHIFT(KeyS),
|
||||
/* T */ SHIFT(KeyT), /* U */ SHIFT(KeyU),
|
||||
/* V */ SHIFT(KeyV), /* W */ SHIFT(KeyW),
|
||||
/* X */ SHIFT(KeyX), /* Y */ SHIFT(KeyY),
|
||||
/* Z */ SHIFT(KeyZ), /* [ */ KEYS(KeyOpenSquare),
|
||||
/* \ */ KEYS(KeyBackSlash), /* ] */ KEYS(KeyCloseSquare),
|
||||
/* ^ */ SHIFT(Key6), /* _ */ X,
|
||||
/* ` */ X, /* a */ KEYS(KeyA),
|
||||
/* b */ KEYS(KeyB), /* c */ KEYS(KeyC),
|
||||
/* d */ KEYS(KeyD), /* e */ KEYS(KeyE),
|
||||
/* f */ KEYS(KeyF), /* g */ KEYS(KeyG),
|
||||
/* h */ KEYS(KeyH), /* i */ KEYS(KeyI),
|
||||
/* j */ KEYS(KeyJ), /* k */ KEYS(KeyK),
|
||||
/* l */ KEYS(KeyL), /* m */ KEYS(KeyM),
|
||||
/* n */ KEYS(KeyN), /* o */ KEYS(KeyO),
|
||||
/* p */ KEYS(KeyP), /* q */ KEYS(KeyQ),
|
||||
/* r */ KEYS(KeyR), /* s */ KEYS(KeyS),
|
||||
/* t */ KEYS(KeyT), /* u */ KEYS(KeyU),
|
||||
/* v */ KEYS(KeyV), /* w */ KEYS(KeyW),
|
||||
/* x */ KEYS(KeyX), /* y */ KEYS(KeyY),
|
||||
/* z */ KEYS(KeyZ), /* { */ SHIFT(KeyOpenSquare),
|
||||
/* | */ SHIFT(KeyBackSlash), /* } */ SHIFT(KeyCloseSquare),
|
||||
};
|
||||
#undef KEYS
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr;
|
||||
if(key_sequences[character][0] == NotMapped) return nullptr;
|
||||
return (uint16_t *)key_sequences[character];
|
||||
}
|
@ -12,7 +12,12 @@
|
||||
using namespace Utility;
|
||||
|
||||
Typer::Typer(const char *string, int delay, int frequency, Delegate *delegate) :
|
||||
_counter(-delay), _frequency(frequency), _string(strdup(string)), _string_pointer(0), _delegate(delegate), _phase(0) {}
|
||||
_counter(-delay), _frequency(frequency), _string_pointer(0), _delegate(delegate), _phase(0)
|
||||
{
|
||||
size_t string_size = strlen(string) + 3;
|
||||
_string = (char *)malloc(string_size);
|
||||
snprintf(_string, strlen(string) + 3, "%c%s%c", Typer::BeginString, string, Typer::EndString);
|
||||
}
|
||||
|
||||
void Typer::update(int duration)
|
||||
{
|
||||
@ -20,14 +25,20 @@ void Typer::update(int duration)
|
||||
{
|
||||
if(_counter < 0 && _counter + duration >= 0)
|
||||
{
|
||||
type_next_character();
|
||||
if(!type_next_character())
|
||||
{
|
||||
_delegate->typer_reset(this);
|
||||
}
|
||||
}
|
||||
|
||||
_counter += duration;
|
||||
while(_string && _counter > _frequency)
|
||||
{
|
||||
_counter -= _frequency;
|
||||
type_next_character();
|
||||
if(!type_next_character())
|
||||
{
|
||||
_delegate->typer_reset(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,3 +71,25 @@ Typer::~Typer()
|
||||
{
|
||||
free(_string);
|
||||
}
|
||||
|
||||
#pragma mark - Delegate
|
||||
|
||||
bool Typer::Delegate::typer_set_next_character(Utility::Typer *typer, char character, int phase)
|
||||
{
|
||||
uint16_t *sequence = sequence_for_character(typer, character);
|
||||
if(!sequence) return true;
|
||||
|
||||
if(!phase) clear_all_keys();
|
||||
else
|
||||
{
|
||||
set_key_state(sequence[phase - 1], true);
|
||||
return sequence[phase] == Typer::Delegate::EndSequence;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t *Typer::Delegate::sequence_for_character(Typer *typer, char character)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -10,14 +10,20 @@
|
||||
#define Typer_hpp
|
||||
|
||||
#include <memory>
|
||||
#include "KeyboardMachine.hpp"
|
||||
|
||||
namespace Utility {
|
||||
|
||||
class Typer {
|
||||
public:
|
||||
class Delegate {
|
||||
class Delegate: public KeyboardMachine::Machine {
|
||||
public:
|
||||
virtual bool typer_set_next_character(Typer *typer, char character, int phase) = 0;
|
||||
virtual bool typer_set_next_character(Typer *typer, char character, int phase);
|
||||
virtual void typer_reset(Typer *typer) = 0;
|
||||
|
||||
virtual uint16_t *sequence_for_character(Typer *typer, char character);
|
||||
|
||||
const uint16_t EndSequence = 0xffff;
|
||||
};
|
||||
|
||||
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
||||
@ -25,6 +31,9 @@ class Typer {
|
||||
void update(int duration);
|
||||
bool type_next_character();
|
||||
|
||||
const char BeginString = 0x02; // i.e. ASCII start of text
|
||||
const char EndString = 0x03; // i.e. ASCII end of text
|
||||
|
||||
private:
|
||||
char *_string;
|
||||
int _frequency;
|
||||
@ -41,6 +50,12 @@ class TypeRecipient: public Typer::Delegate {
|
||||
_typer.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), this));
|
||||
}
|
||||
|
||||
void typer_reset(Typer *typer)
|
||||
{
|
||||
clear_all_keys();
|
||||
_typer.reset();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual int get_typer_delay() { return 0; }
|
||||
virtual int get_typer_frequency() { return 0; }
|
||||
|
@ -357,6 +357,9 @@
|
||||
4BC76E691C98E31700E6EF73 /* FIRFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC76E671C98E31700E6EF73 /* FIRFilter.cpp */; };
|
||||
4BC76E6B1C98F43700E6EF73 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */; };
|
||||
4BC830D11D6E7C690000A26F /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC830CF1D6E7C690000A26F /* Tape.cpp */; };
|
||||
4BC8A62A1DCE4F2700DAC693 /* Typer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC8A6291DCE4F2700DAC693 /* Typer.cpp */; };
|
||||
4BC8A62D1DCE60E000DAC693 /* Typer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC8A62B1DCE60E000DAC693 /* Typer.cpp */; };
|
||||
4BC8A62F1DCE63CA00DAC693 /* Typer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC8A62E1DCE63CA00DAC693 /* Typer.cpp */; };
|
||||
4BC91B831D1F160E00884B76 /* CommodoreTAP.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC91B811D1F160E00884B76 /* CommodoreTAP.cpp */; };
|
||||
4BC9DF451D044FCA00F44158 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; };
|
||||
4BC9DF4F1D04691600F44158 /* 6560.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BC9DF4D1D04691600F44158 /* 6560.cpp */; };
|
||||
@ -494,6 +497,7 @@
|
||||
4B69FB451C4D950F00B5F0AA /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
||||
4B6C73BB1D387AE500AFCFCA /* DiskController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DiskController.cpp; sourceTree = "<group>"; };
|
||||
4B6C73BC1D387AE500AFCFCA /* DiskController.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DiskController.hpp; sourceTree = "<group>"; };
|
||||
4B8E4ECD1DCE483D003716C3 /* KeyboardMachine.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = KeyboardMachine.hpp; sourceTree = "<group>"; };
|
||||
4B8FE2141DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/Atari2600Options.xib"; sourceTree = SOURCE_ROOT; };
|
||||
4B8FE2161DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/MachineDocument.xib"; sourceTree = SOURCE_ROOT; };
|
||||
4B8FE2181DA19D5F0090D3CE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = "Clock Signal/Base.lproj/ElectronOptions.xib"; sourceTree = SOURCE_ROOT; };
|
||||
@ -830,6 +834,9 @@
|
||||
4BC76E6A1C98F43700E6EF73 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
|
||||
4BC830CF1D6E7C690000A26F /* Tape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Tape.cpp; path = ../../StaticAnalyser/Commodore/Tape.cpp; sourceTree = "<group>"; };
|
||||
4BC830D01D6E7C690000A26F /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Tape.hpp; path = ../../StaticAnalyser/Commodore/Tape.hpp; sourceTree = "<group>"; };
|
||||
4BC8A6291DCE4F2700DAC693 /* Typer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Typer.cpp; path = Oric/Typer.cpp; sourceTree = "<group>"; };
|
||||
4BC8A62B1DCE60E000DAC693 /* Typer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Typer.cpp; path = Electron/Typer.cpp; sourceTree = "<group>"; };
|
||||
4BC8A62E1DCE63CA00DAC693 /* Typer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Typer.cpp; sourceTree = "<group>"; };
|
||||
4BC91B811D1F160E00884B76 /* CommodoreTAP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommodoreTAP.cpp; sourceTree = "<group>"; };
|
||||
4BC91B821D1F160E00884B76 /* CommodoreTAP.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CommodoreTAP.hpp; sourceTree = "<group>"; };
|
||||
4BC9DF441D044FCA00F44158 /* ROMImages */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ROMImages; path = ../../../../ROMImages; sourceTree = "<group>"; };
|
||||
@ -1019,6 +1026,7 @@
|
||||
4B2E2D9C1C3A070400138695 /* Electron.hpp */,
|
||||
4B30512E1D98ACC600B4FED8 /* Plus3.cpp */,
|
||||
4B30512F1D98ACC600B4FED8 /* Plus3.hpp */,
|
||||
4BC8A62B1DCE60E000DAC693 /* Typer.cpp */,
|
||||
);
|
||||
name = Electron;
|
||||
sourceTree = "<group>";
|
||||
@ -1083,6 +1091,7 @@
|
||||
4B4DC81E1D2C2425003C5BF8 /* Vic-20 */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4BC8A62E1DCE63CA00DAC693 /* Typer.cpp */,
|
||||
4B4DC81F1D2C2425003C5BF8 /* Vic20.cpp */,
|
||||
4B4DC8201D2C2425003C5BF8 /* Vic20.hpp */,
|
||||
);
|
||||
@ -1607,6 +1616,7 @@
|
||||
4B1E85731D170228001EF87D /* Typer.cpp */,
|
||||
4BA9C3CF1D8164A9002DDB61 /* ConfigurationTarget.hpp */,
|
||||
4B046DC31CFE651500E9E45E /* CRTMachine.hpp */,
|
||||
4B8E4ECD1DCE483D003716C3 /* KeyboardMachine.hpp */,
|
||||
4B2A33291DB8544D002876E3 /* MemoryFuzzer.hpp */,
|
||||
4B1E85741D170228001EF87D /* Typer.hpp */,
|
||||
4B2E2D961C3A06EC00138695 /* Atari2600 */,
|
||||
@ -1718,6 +1728,7 @@
|
||||
children = (
|
||||
4BCF1FA21DADC3DD0039D2E7 /* Oric.cpp */,
|
||||
4BCF1FA31DADC3DD0039D2E7 /* Oric.hpp */,
|
||||
4BC8A6291DCE4F2700DAC693 /* Typer.cpp */,
|
||||
4B2BFDB01DAEF5FF001A68B8 /* Video.cpp */,
|
||||
4B2BFDB11DAEF5FF001A68B8 /* Video.hpp */,
|
||||
);
|
||||
@ -2232,6 +2243,7 @@
|
||||
4BBF99151C8FBA6F0075DAFB /* CRTOpenGL.cpp in Sources */,
|
||||
4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */,
|
||||
4BCF1FA41DADC3DD0039D2E7 /* Oric.cpp in Sources */,
|
||||
4BC8A62D1DCE60E000DAC693 /* Typer.cpp in Sources */,
|
||||
4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */,
|
||||
4BA799951D8B656E0045123D /* StaticAnalyser.cpp in Sources */,
|
||||
4BF829601D8F3C87001BAE39 /* CRC.cpp in Sources */,
|
||||
@ -2270,6 +2282,7 @@
|
||||
4B1E85751D170228001EF87D /* Typer.cpp in Sources */,
|
||||
4BF829631D8F536B001BAE39 /* SSD.cpp in Sources */,
|
||||
4B2E2D9D1C3A070400138695 /* Electron.cpp in Sources */,
|
||||
4BC8A62A1DCE4F2700DAC693 /* Typer.cpp in Sources */,
|
||||
4B3940E71DA83C8300427841 /* AsyncTaskQueue.cpp in Sources */,
|
||||
4BAB62B81D3302CA00DF5BA0 /* PCMTrack.cpp in Sources */,
|
||||
4B69FB3D1C4D908A00B5F0AA /* Tape.cpp in Sources */,
|
||||
@ -2298,6 +2311,7 @@
|
||||
4BCF1FAB1DADD41B0039D2E7 /* StaticAnalyser.cpp in Sources */,
|
||||
4B2A539F1D117D36003C6002 /* CSAudioQueue.m in Sources */,
|
||||
4B37EE821D7345A6006A09A4 /* BinaryDump.cpp in Sources */,
|
||||
4BC8A62F1DCE63CA00DAC693 /* Typer.cpp in Sources */,
|
||||
4BB73EA21B587A5100552FC2 /* AppDelegate.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user