1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +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:
Thomas Harte 2016-06-19 13:46:53 -04:00
parent e7aeed2f03
commit 3fc472d5cb
4 changed files with 172 additions and 30 deletions

View File

@ -12,7 +12,7 @@
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) {}
_counter(-delay), _frequency(frequency), _string(strdup(string)), _string_pointer(0), _delegate(delegate), _phase(0) {}
void Typer::update(int duration)
{
@ -20,27 +20,38 @@ void Typer::update(int duration)
{
if(_counter < 0 && _counter + duration >= 0)
{
_delegate->typer_set_next_character(this, _string[_string_pointer]);
_string_pointer++;
type_next_character();
}
_counter += duration;
while(_counter > _frequency)
{
_counter -= _frequency;
_delegate->typer_set_next_character(this, _string[_string_pointer]);
_string_pointer++;
if(!_string[_string_pointer])
{
free(_string);
_string = nullptr;
return;
}
type_next_character();
}
}
}
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()
{
free(_string);

View File

@ -17,7 +17,7 @@ class Typer {
public:
class Delegate {
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);
@ -28,8 +28,11 @@ class Typer {
char *_string;
int _frequency;
int _counter;
int _phase;
Delegate *_delegate;
size_t _string_pointer;
void type_next_character();
};
class TypeRecipient: public Typer::Delegate {

View File

@ -126,14 +126,11 @@ void Machine::add_prg(size_t length, const uint8_t *data)
_rom_length = (uint16_t)(length - 2);
if(_rom_address >= 0x1000 && _rom_address+_rom_length < 0x2000)
{
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);
set_typer_for_string("RUN\n");
}
_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()
{
return 263*60*65 / 2; // wait half a second
return 1*263*60*65; // wait two seconds
}
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
}
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();
switch(character)
// If there's a 'ROM' installed that can never be accessed, assume that this typing was scheduled because
// 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;
case 'u': set_key_state(Key::KeyU, true); break;
case 'n': set_key_state(Key::KeyN, true); break;
case '\n': set_key_state(Key::KeyReturn, true); break;
memcpy(&_screenMemory[_rom_address - 0x1000], _rom, _rom_length);
delete[] _rom;
_rom = nullptr;
}
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;
}

View File

@ -44,6 +44,8 @@ enum Key: uint16_t {
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),
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 {
@ -124,7 +126,7 @@ class Machine:
// for Utility::TypeRecipient
virtual int get_typer_delay();
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:
uint8_t _characterROM[0x1000];