mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-18 01:30:56 +00:00
Expanded typing to include phase for machines that need to go through multiple keypresses to reach a certain state, expanded Vic to be able to type most things (still bodged on lowercase though), and to schedule a 'run' if it's supposed to be loading into RAM, spotting that opportunity actually to do so.
This commit is contained in:
parent
e7aeed2f03
commit
3fc472d5cb
@ -12,7 +12,7 @@
|
|||||||
using namespace Utility;
|
using namespace Utility;
|
||||||
|
|
||||||
Typer::Typer(const char *string, int delay, int frequency, Delegate *delegate) :
|
Typer::Typer(const char *string, int delay, int frequency, Delegate *delegate) :
|
||||||
_counter(-delay), _frequency(frequency), _string(strdup(string)), _string_pointer(0), _delegate(delegate) {}
|
_counter(-delay), _frequency(frequency), _string(strdup(string)), _string_pointer(0), _delegate(delegate), _phase(0) {}
|
||||||
|
|
||||||
void Typer::update(int duration)
|
void Typer::update(int duration)
|
||||||
{
|
{
|
||||||
@ -20,27 +20,38 @@ void Typer::update(int duration)
|
|||||||
{
|
{
|
||||||
if(_counter < 0 && _counter + duration >= 0)
|
if(_counter < 0 && _counter + duration >= 0)
|
||||||
{
|
{
|
||||||
_delegate->typer_set_next_character(this, _string[_string_pointer]);
|
type_next_character();
|
||||||
_string_pointer++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_counter += duration;
|
_counter += duration;
|
||||||
while(_counter > _frequency)
|
while(_counter > _frequency)
|
||||||
{
|
{
|
||||||
_counter -= _frequency;
|
_counter -= _frequency;
|
||||||
_delegate->typer_set_next_character(this, _string[_string_pointer]);
|
type_next_character();
|
||||||
_string_pointer++;
|
|
||||||
|
|
||||||
if(!_string[_string_pointer])
|
|
||||||
{
|
|
||||||
free(_string);
|
|
||||||
_string = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Typer::type_next_character()
|
||||||
|
{
|
||||||
|
if(_delegate->typer_set_next_character(this, _string[_string_pointer], _phase))
|
||||||
|
{
|
||||||
|
_phase = 0;
|
||||||
|
if(!_string[_string_pointer])
|
||||||
|
{
|
||||||
|
free(_string);
|
||||||
|
_string = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_string_pointer++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_phase++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Typer::~Typer()
|
Typer::~Typer()
|
||||||
{
|
{
|
||||||
free(_string);
|
free(_string);
|
||||||
|
@ -17,7 +17,7 @@ class Typer {
|
|||||||
public:
|
public:
|
||||||
class Delegate {
|
class Delegate {
|
||||||
public:
|
public:
|
||||||
virtual void typer_set_next_character(Typer *typer, char character) = 0;
|
virtual bool typer_set_next_character(Typer *typer, char character, int phase) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
||||||
@ -28,8 +28,11 @@ class Typer {
|
|||||||
char *_string;
|
char *_string;
|
||||||
int _frequency;
|
int _frequency;
|
||||||
int _counter;
|
int _counter;
|
||||||
|
int _phase;
|
||||||
Delegate *_delegate;
|
Delegate *_delegate;
|
||||||
size_t _string_pointer;
|
size_t _string_pointer;
|
||||||
|
|
||||||
|
void type_next_character();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeRecipient: public Typer::Delegate {
|
class TypeRecipient: public Typer::Delegate {
|
||||||
|
@ -126,14 +126,11 @@ void Machine::add_prg(size_t length, const uint8_t *data)
|
|||||||
_rom_length = (uint16_t)(length - 2);
|
_rom_length = (uint16_t)(length - 2);
|
||||||
if(_rom_address >= 0x1000 && _rom_address+_rom_length < 0x2000)
|
if(_rom_address >= 0x1000 && _rom_address+_rom_length < 0x2000)
|
||||||
{
|
{
|
||||||
set_typer_for_string("run\n");
|
set_typer_for_string("RUN\n");
|
||||||
// memcpy(&_screenMemory[_rom_address - 0x1000], &data[2], length - 2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_rom = new uint8_t[length - 2];
|
|
||||||
memcpy(_rom, &data[2], length - 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_rom = new uint8_t[length - 2];
|
||||||
|
memcpy(_rom, &data[2], length - 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +138,7 @@ void Machine::add_prg(size_t length, const uint8_t *data)
|
|||||||
|
|
||||||
int Machine::get_typer_delay()
|
int Machine::get_typer_delay()
|
||||||
{
|
{
|
||||||
return 263*60*65 / 2; // wait half a second
|
return 1*263*60*65; // wait two seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
int Machine::get_typer_frequency()
|
int Machine::get_typer_frequency()
|
||||||
@ -149,15 +146,144 @@ int Machine::get_typer_frequency()
|
|||||||
return 2*263*65; // accept a new character every two fields
|
return 2*263*65; // accept a new character every two fields
|
||||||
}
|
}
|
||||||
|
|
||||||
void Machine::typer_set_next_character(::Utility::Typer *typer, char character)
|
bool Machine::typer_set_next_character(::Utility::Typer *typer, char character, int phase)
|
||||||
{
|
{
|
||||||
clear_all_keys();
|
// If there's a 'ROM' installed that can never be accessed, assume that this typing was scheduled because
|
||||||
switch(character)
|
// it should be in RAM. So copy it there.
|
||||||
|
if(_rom && _rom_address >= 0x1000 && _rom_address+_rom_length < 0x2000)
|
||||||
{
|
{
|
||||||
case 'r': set_key_state(Key::KeyR, true); break;
|
memcpy(&_screenMemory[_rom_address - 0x1000], _rom, _rom_length);
|
||||||
case 'u': set_key_state(Key::KeyU, true); break;
|
delete[] _rom;
|
||||||
case 'n': set_key_state(Key::KeyN, true); break;
|
_rom = nullptr;
|
||||||
case '\n': set_key_state(Key::KeyReturn, true); break;
|
|
||||||
}
|
}
|
||||||
printf(".");
|
|
||||||
|
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}, // 0
|
||||||
|
{Key1, TerminateSequence}, // 1
|
||||||
|
{Key2, TerminateSequence}, // 2
|
||||||
|
{Key3, TerminateSequence}, // 3
|
||||||
|
{Key4, TerminateSequence}, // 4
|
||||||
|
{Key5, TerminateSequence}, // 5
|
||||||
|
{Key6, TerminateSequence}, // 6
|
||||||
|
{Key7, TerminateSequence}, // 7
|
||||||
|
{Key8, TerminateSequence}, // 8
|
||||||
|
{Key9, TerminateSequence}, // 9
|
||||||
|
|
||||||
|
{KeyColon, TerminateSequence}, // :
|
||||||
|
{KeySemicolon, TerminateSequence}, // ;
|
||||||
|
{KeyLShift, KeyComma, TerminateSequence}, // <
|
||||||
|
{KeyEquals, TerminateSequence}, // =
|
||||||
|
{KeyLShift, KeyFullStop, TerminateSequence}, // >
|
||||||
|
{KeyLShift, KeySlash, TerminateSequence}, // ?
|
||||||
|
{KeyAt, TerminateSequence}, // @
|
||||||
|
|
||||||
|
{KeyA, TerminateSequence}, // A
|
||||||
|
{KeyB, TerminateSequence}, // B
|
||||||
|
{KeyC, TerminateSequence}, // C
|
||||||
|
{KeyD, TerminateSequence}, // D
|
||||||
|
{KeyE, TerminateSequence}, // E
|
||||||
|
{KeyF, TerminateSequence}, // F
|
||||||
|
{KeyG, TerminateSequence}, // G
|
||||||
|
{KeyH, TerminateSequence}, // H
|
||||||
|
{KeyI, TerminateSequence}, // I
|
||||||
|
{KeyJ, TerminateSequence}, // J
|
||||||
|
{KeyK, TerminateSequence}, // K
|
||||||
|
{KeyL, TerminateSequence}, // L
|
||||||
|
{KeyM, TerminateSequence}, // M
|
||||||
|
{KeyN, TerminateSequence}, // N
|
||||||
|
{KeyO, TerminateSequence}, // O
|
||||||
|
{KeyP, TerminateSequence}, // P
|
||||||
|
{KeyQ, TerminateSequence}, // Q
|
||||||
|
{KeyR, TerminateSequence}, // R
|
||||||
|
{KeyS, TerminateSequence}, // S
|
||||||
|
{KeyT, TerminateSequence}, // T
|
||||||
|
{KeyU, TerminateSequence}, // U
|
||||||
|
{KeyV, TerminateSequence}, // V
|
||||||
|
{KeyW, TerminateSequence}, // W
|
||||||
|
{KeyX, TerminateSequence}, // X
|
||||||
|
{KeyY, TerminateSequence}, // Y
|
||||||
|
{KeyZ, TerminateSequence}, // Z
|
||||||
|
|
||||||
|
{KeyLShift, KeyColon, TerminateSequence}, // [
|
||||||
|
{NotMapped}, // '\'
|
||||||
|
{KeyLShift, KeyFullStop, TerminateSequence}, // ]
|
||||||
|
{NotMapped}, // ^
|
||||||
|
{NotMapped}, // _
|
||||||
|
{NotMapped}, // `
|
||||||
|
|
||||||
|
{KeyLShift, KeyA, TerminateSequence}, // A
|
||||||
|
{KeyLShift, KeyB, TerminateSequence}, // B
|
||||||
|
{KeyLShift, KeyC, TerminateSequence}, // C
|
||||||
|
{KeyLShift, KeyD, TerminateSequence}, // D
|
||||||
|
{KeyLShift, KeyE, TerminateSequence}, // E
|
||||||
|
{KeyLShift, KeyF, TerminateSequence}, // F
|
||||||
|
{KeyLShift, KeyG, TerminateSequence}, // G
|
||||||
|
{KeyLShift, KeyH, TerminateSequence}, // H
|
||||||
|
{KeyLShift, KeyI, TerminateSequence}, // I
|
||||||
|
{KeyLShift, KeyJ, TerminateSequence}, // J
|
||||||
|
{KeyLShift, KeyK, TerminateSequence}, // K
|
||||||
|
{KeyLShift, KeyL, TerminateSequence}, // L
|
||||||
|
{KeyLShift, KeyM, TerminateSequence}, // M
|
||||||
|
{KeyLShift, KeyN, TerminateSequence}, // N
|
||||||
|
{KeyLShift, KeyO, TerminateSequence}, // O
|
||||||
|
{KeyLShift, KeyP, TerminateSequence}, // P
|
||||||
|
{KeyLShift, KeyQ, TerminateSequence}, // Q
|
||||||
|
{KeyLShift, KeyR, TerminateSequence}, // R
|
||||||
|
{KeyLShift, KeyS, TerminateSequence}, // S
|
||||||
|
{KeyLShift, KeyT, TerminateSequence}, // T
|
||||||
|
{KeyLShift, KeyU, TerminateSequence}, // U
|
||||||
|
{KeyLShift, KeyV, TerminateSequence}, // V
|
||||||
|
{KeyLShift, KeyW, TerminateSequence}, // W
|
||||||
|
{KeyLShift, KeyX, TerminateSequence}, // X
|
||||||
|
{KeyLShift, KeyY, TerminateSequence}, // Y
|
||||||
|
{KeyLShift, KeyZ, TerminateSequence}, // Z
|
||||||
|
|
||||||
|
};
|
||||||
|
Key *key_sequence = nullptr;
|
||||||
|
|
||||||
|
character &= 0x7f;
|
||||||
|
if(character < sizeof(key_sequences) / sizeof(*key_sequences))
|
||||||
|
{
|
||||||
|
key_sequence = key_sequences[character];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key_sequence && key_sequence[phase] != NotMapped)
|
||||||
|
{
|
||||||
|
set_key_state(key_sequence[phase], true);
|
||||||
|
return key_sequence[phase+1] == TerminateSequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,8 @@ enum Key: uint16_t {
|
|||||||
KeyI = key(1, 0x10), KeyP = key(1, 0x20), KeyAsterisk = key(1, 0x40), KeyReturn = key(1, 0x80),
|
KeyI = key(1, 0x10), KeyP = key(1, 0x20), KeyAsterisk = key(1, 0x40), KeyReturn = key(1, 0x80),
|
||||||
Key1 = key(0, 0x01), Key3 = key(0, 0x02), Key5 = key(0, 0x04), Key7 = key(0, 0x08),
|
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),
|
Key9 = key(0, 0x10), KeyPlus = key(0, 0x20), KeyGBP = key(0, 0x40), KeyDelete = key(0, 0x80),
|
||||||
|
|
||||||
|
TerminateSequence = 0, NotMapped = 0xffff
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserPortVIA: public MOS::MOS6522<UserPortVIA>, public MOS::MOS6522IRQDelegate {
|
class UserPortVIA: public MOS::MOS6522<UserPortVIA>, public MOS::MOS6522IRQDelegate {
|
||||||
@ -124,7 +126,7 @@ class Machine:
|
|||||||
// for Utility::TypeRecipient
|
// for Utility::TypeRecipient
|
||||||
virtual int get_typer_delay();
|
virtual int get_typer_delay();
|
||||||
virtual int get_typer_frequency();
|
virtual int get_typer_frequency();
|
||||||
virtual void typer_set_next_character(Utility::Typer *typer, char character);
|
virtual bool typer_set_next_character(Utility::Typer *typer, char character, int phase);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t _characterROM[0x1000];
|
uint8_t _characterROM[0x1000];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user