From a6b8e88406b21adb34bb7c73d12355047096b1be Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 13 May 2018 11:30:04 -0400 Subject: [PATCH] Implements `type_string` for the Apple II. --- Machines/AppleII/AppleII.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Machines/AppleII/AppleII.cpp b/Machines/AppleII/AppleII.cpp index e312e05b8..56cbbbe10 100644 --- a/Machines/AppleII/AppleII.cpp +++ b/Machines/AppleII/AppleII.cpp @@ -117,6 +117,10 @@ class ConcreteMachine: } } + // MARK - typing + std::string input_string_; + std::size_t input_string_pointer_ = std::numeric_limits::max(); + public: ConcreteMachine(): m6502_(*this), @@ -197,7 +201,11 @@ class ConcreteMachine: default: break; case 0xc000: - *value = keyboard_input_; + if(input_string_pointer_ != std::numeric_limits::max()) { + *value = static_cast(input_string_[input_string_pointer_]) | 0x80; + } else { + *value = keyboard_input_; + } break; } } else { @@ -217,6 +225,11 @@ class ConcreteMachine: case 0xc010: keyboard_input_ &= 0x7f; + if(input_string_pointer_ != std::numeric_limits::max()) { + ++input_string_pointer_; + if(input_string_pointer_ == input_string_.size()) + input_string_pointer_ = std::numeric_limits::max(); + } break; case 0xc030: @@ -347,6 +360,25 @@ class ConcreteMachine: return *this; } + void type_string(const std::string &string) override { + input_string_.clear(); + input_string_.reserve(string.size()); + + // Commute any \ns that are not immediately after \rs to \rs; remove the rest. + bool saw_carriage_return = false; + for(auto character: string) { + if(character != '\n') { + input_string_.push_back(character); + } else { + if(!saw_carriage_return) { + input_string_.push_back('\r'); + } + } + saw_carriage_return = character == '\r'; + } + input_string_pointer_ = 0; + } + // MARK: ConfigurationTarget void configure_as_target(const Analyser::Static::Target *target) override { using Target = Analyser::Static::AppleII::Target;