1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 03:32:01 +00:00

Expanded interface so that an external machine caller can request a string be typed without any knowledge of whatever it intends to do re: CharacterMappers. Which is immediately useful in paste functionality.

This commit is contained in:
Thomas Harte 2017-08-03 11:50:50 -04:00
parent ad3a98387f
commit bbb17acf3a
9 changed files with 36 additions and 12 deletions

View File

@ -291,8 +291,7 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) {
}
if(target.loadingCommand.length()) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper());
set_typer_for_string(target.loadingCommand.c_str(), std::move(mapper));
set_typer_for_string(target.loadingCommand.c_str());
}
switch(target.vic20.memory_model) {
@ -308,6 +307,11 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) {
}
}
void Machine::set_typer_for_string(const char *string) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper());
Utility::TypeRecipient::set_typer_for_string(string, std::move(mapper));
}
void Machine::tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape) {
keyboard_via_->set_control_line_input(KeyboardVIA::Port::A, KeyboardVIA::Line::One, !tape->get_input());
}

View File

@ -181,6 +181,7 @@ class Machine:
// for Utility::TypeRecipient
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
void set_typer_for_string(const char *string);
// for Tape::Delegate
virtual void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape);

View File

@ -98,8 +98,7 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) {
}
if(target.loadingCommand.length()) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper());
set_typer_for_string(target.loadingCommand.c_str(), std::move(mapper));
set_typer_for_string(target.loadingCommand.c_str());
}
if(target.acorn.should_shift_restart) {
@ -107,6 +106,11 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) {
}
}
void Machine::set_typer_for_string(const char *string) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper());
Utility::TypeRecipient::set_typer_for_string(string, std::move(mapper));
}
void Machine::set_rom(ROMSlot slot, std::vector<uint8_t> data, bool is_writeable) {
uint8_t *target = nullptr;
switch(slot) {

View File

@ -103,6 +103,7 @@ class Machine:
// for Utility::TypeRecipient
virtual HalfCycles get_typer_delay();
virtual HalfCycles get_typer_frequency();
virtual void set_typer_for_string(const char *string);
private:
inline void update_display();

View File

@ -37,8 +37,7 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) {
}
if(target.loadingCommand.length()) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper);
set_typer_for_string(target.loadingCommand.c_str(), std::move(mapper));
set_typer_for_string(target.loadingCommand.c_str());
}
if(target.oric.has_microdisc) {
@ -70,6 +69,11 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) {
}
}
void Machine::set_typer_for_string(const char *string) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper);
Utility::TypeRecipient::set_typer_for_string(string, std::move(mapper));
}
void Machine::set_rom(ROM rom, const std::vector<uint8_t> &data) {
switch(rom) {
case BASIC11: basic11_rom_ = std::move(data); break;

View File

@ -94,7 +94,7 @@ class Machine:
void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape_player);
// for Utility::TypeRecipient::Delegate
uint16_t *sequence_for_character(Utility::Typer *typer, char character);
void set_typer_for_string(const char *string);
// for Microdisc::Delegate
void microdisc_did_change_paging_flags(class Microdisc *microdisc);

View File

@ -95,6 +95,12 @@ class TypeRecipient: public Typer::Delegate {
typer_.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), std::move(character_mapper), this));
}
/*!
Provided as a hook for subclasses to implement so that external callers can install a typer
without needing inside knowledge as to where the character mapper comes from.
*/
virtual void set_typer_for_string(const char *string) = 0;
/*!
Provided in order to conform to that part of the Typer::Delegate interface that goes above and
beyond KeyboardMachine::Machine; responds to the end of typing by clearing all keys.

View File

@ -273,11 +273,15 @@ class ConcreteMachine:
}
if(target.loadingCommand.length()) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper(is_zx81_));
set_typer_for_string(target.loadingCommand.c_str(), std::move(mapper));
set_typer_for_string(target.loadingCommand.c_str());
}
}
void set_typer_for_string(const char *string) {
std::unique_ptr<CharacterMapper> mapper(new CharacterMapper(is_zx81_));
Utility::TypeRecipient::set_typer_for_string(string, std::move(mapper));
}
void set_rom(ROMType type, std::vector<uint8_t> data) {
switch(type) {
case ZX80: zx80_rom_ = data; break;

View File

@ -131,9 +131,9 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
}
- (void)paste:(NSString *)paste {
// Utility::TypeRecipient *typeRecipient = dynamic_cast<Utility::TypeRecipient *>(self.machine);
// if(typeRecipient)
// typeRecipient->set_typer_for_string([paste UTF8String]);
Utility::TypeRecipient *typeRecipient = dynamic_cast<Utility::TypeRecipient *>(self.machine);
if(typeRecipient)
typeRecipient->set_typer_for_string([paste UTF8String]);
}
- (void)applyTarget:(StaticAnalyser::Target)target {