diff --git a/Machines/Apple/ADB/Bus.cpp b/Machines/Apple/ADB/Bus.cpp index 82cfadc91..a4d4459d0 100644 --- a/Machines/Apple/ADB/Bus.cpp +++ b/Machines/Apple/ADB/Bus.cpp @@ -21,8 +21,10 @@ void Bus::set_device_output(size_t device_id, bool output) { // Modify the all-devices bus state. bus_state_[device_id] = output; - // React to signal edges only. - const bool data_level = get_state(); + // React to signal edges only; don't use get_state here to avoid + // endless recursion should any reactive devices set new output + // during the various calls made below. + const bool data_level = bus_state_.all(); if(data_level_ != data_level) { data_level_ = data_level; diff --git a/Machines/Apple/ADB/Keyboard.cpp b/Machines/Apple/ADB/Keyboard.cpp new file mode 100644 index 000000000..a4bb59dd1 --- /dev/null +++ b/Machines/Apple/ADB/Keyboard.cpp @@ -0,0 +1,53 @@ +// +// Keyboard.cpp +// Clock Signal +// +// Created by Thomas Harte on 13/02/2021. +// Copyright © 2021 Thomas Harte. All rights reserved. +// + +#include "Keyboard.hpp" + +using namespace Apple::ADB; + +Keyboard::Keyboard(Bus &bus) : ReactiveDevice(bus, 2) {} + +void Keyboard::perform_command(const Command &command) { + if(command.type == Command::Type::Talk) { + switch(command.reg) { + case 0: + // Post up to two key events, or nothing if there are + // no events pending. +// post_response({0x00, 0x00}); + break; + + case 2: + /* + In all cases below: 0 = pressed/on; 1 = released/off. + + b15: None (reserved) + b14: Delete + b13: Caps lock + b12: Reset + b11: Control + b10: Shift + b9: Option + b8: Command + + -- From here onwards, available only on the extended keyboard. + + b7: Num lock/clear + b6: Scroll lock + b5–3: None (reserved) + b2: Scroll Lock LED + b1: Caps Lock LED + b0: Num Lock LED + */ + post_response({0xff, 0xff}); + break; + + default: break; + } + return; + } +} diff --git a/Machines/Apple/ADB/Keyboard.hpp b/Machines/Apple/ADB/Keyboard.hpp new file mode 100644 index 000000000..be2714cf3 --- /dev/null +++ b/Machines/Apple/ADB/Keyboard.hpp @@ -0,0 +1,28 @@ +// +// Keyboard.hpp +// Clock Signal +// +// Created by Thomas Harte on 13/02/2021. +// Copyright © 2021 Thomas Harte. All rights reserved. +// + +#ifndef Keyboard_hpp +#define Keyboard_hpp + +#include "ReactiveDevice.hpp" + +namespace Apple { +namespace ADB { + +class Keyboard: public ReactiveDevice { + public: + Keyboard(Bus &); + + private: + void perform_command(const Command &command) override; +}; + +} +} + +#endif /* Keyboard_hpp */ diff --git a/Machines/Apple/ADB/Mouse.hpp b/Machines/Apple/ADB/Mouse.hpp index ebbd0cbb9..0ab032922 100644 --- a/Machines/Apple/ADB/Mouse.hpp +++ b/Machines/Apple/ADB/Mouse.hpp @@ -18,6 +18,7 @@ class Mouse: public ReactiveDevice { public: Mouse(Bus &); + private: void perform_command(const Command &command) override; }; diff --git a/Machines/Apple/ADB/ReactiveDevice.cpp b/Machines/Apple/ADB/ReactiveDevice.cpp index 2c402bfb3..fec9d5912 100644 --- a/Machines/Apple/ADB/ReactiveDevice.cpp +++ b/Machines/Apple/ADB/ReactiveDevice.cpp @@ -42,8 +42,9 @@ void ReactiveDevice::advance_state(double microseconds) { } // Advance the implied number of bits. - bit_offset_ += int(microseconds_at_bit_ / 100); - microseconds_at_bit_ -= double(bit_offset_ * 100.0); + const int step = int(microseconds_at_bit_ / 100); + bit_offset_ += step; + microseconds_at_bit_ -= double(step * 100.0); // Check for end-of-transmission. if(bit_offset_ >= int(response_.size() * 10)) { diff --git a/Machines/Apple/AppleIIgs/ADB.cpp b/Machines/Apple/AppleIIgs/ADB.cpp index 3f16a1240..a1160ad50 100644 --- a/Machines/Apple/AppleIIgs/ADB.cpp +++ b/Machines/Apple/AppleIIgs/ADB.cpp @@ -39,7 +39,12 @@ enum class MicrocontrollerFlags: uint8_t { } -GLU::GLU() : executor_(*this), bus_(HalfCycles(1'789'772)), controller_id_(bus_.add_device()), mouse_(bus_) {} +GLU::GLU() : + executor_(*this), + bus_(HalfCycles(1'789'772)), + controller_id_(bus_.add_device()), + mouse_(bus_), + keyboard_(bus_) {} // MARK: - External interface. diff --git a/Machines/Apple/AppleIIgs/ADB.hpp b/Machines/Apple/AppleIIgs/ADB.hpp index 5423693f1..bf4e4b3a8 100644 --- a/Machines/Apple/AppleIIgs/ADB.hpp +++ b/Machines/Apple/AppleIIgs/ADB.hpp @@ -15,6 +15,7 @@ #include "../ADB/Bus.hpp" #include "../ADB/Mouse.hpp" +#include "../ADB/Keyboard.hpp" namespace Apple { namespace IIgs { @@ -58,8 +59,9 @@ class GLU: public InstructionSet::M50740::PortHandler { Apple::ADB::Bus bus_; size_t controller_id_; - // TODO: add some other devices, and attach them to the ADB bus. + // For now, attach only a keyboard and mouse. Apple::ADB::Mouse mouse_; + Apple::ADB::Keyboard keyboard_; }; } diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index dac0727e8..30620bb99 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -176,6 +176,9 @@ 4B2E86B825D7490E0024F1E9 /* ReactiveDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E86B525D7490E0024F1E9 /* ReactiveDevice.cpp */; }; 4B2E86BE25D74F160024F1E9 /* Mouse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E86BC25D74F160024F1E9 /* Mouse.cpp */; }; 4B2E86BF25D74F160024F1E9 /* Mouse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E86BC25D74F160024F1E9 /* Mouse.cpp */; }; + 4B2E86C925D892EF0024F1E9 /* DAT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BE8EB6425C750B50040BC40 /* DAT.cpp */; }; + 4B2E86CF25D8D8C70024F1E9 /* Keyboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E86CD25D8D8C70024F1E9 /* Keyboard.cpp */; }; + 4B2E86D025D8D8C70024F1E9 /* Keyboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2E86CD25D8D8C70024F1E9 /* Keyboard.cpp */; }; 4B302184208A550100773308 /* DiskII.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B302183208A550100773308 /* DiskII.cpp */; }; 4B302185208A550100773308 /* DiskII.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B302183208A550100773308 /* DiskII.cpp */; }; 4B30512D1D989E2200B4FED8 /* Drive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B30512B1D989E2200B4FED8 /* Drive.cpp */; }; @@ -1124,6 +1127,8 @@ 4B2E86B625D7490E0024F1E9 /* ReactiveDevice.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ReactiveDevice.hpp; sourceTree = ""; }; 4B2E86BC25D74F160024F1E9 /* Mouse.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Mouse.cpp; sourceTree = ""; }; 4B2E86BD25D74F160024F1E9 /* Mouse.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Mouse.hpp; sourceTree = ""; }; + 4B2E86CD25D8D8C70024F1E9 /* Keyboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Keyboard.cpp; sourceTree = ""; }; + 4B2E86CE25D8D8C70024F1E9 /* Keyboard.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Keyboard.hpp; sourceTree = ""; }; 4B302182208A550100773308 /* DiskII.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = DiskII.hpp; sourceTree = ""; }; 4B302183208A550100773308 /* DiskII.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DiskII.cpp; sourceTree = ""; }; 4B30512B1D989E2200B4FED8 /* Drive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Drive.cpp; sourceTree = ""; }; @@ -4196,11 +4201,13 @@ isa = PBXGroup; children = ( 4BCE1DEF25D4C3FA00AE7A2B /* Bus.cpp */, - 4BCE1DF025D4C3FA00AE7A2B /* Bus.hpp */, - 4B2E86B525D7490E0024F1E9 /* ReactiveDevice.cpp */, - 4B2E86B625D7490E0024F1E9 /* ReactiveDevice.hpp */, + 4B2E86CD25D8D8C70024F1E9 /* Keyboard.cpp */, 4B2E86BC25D74F160024F1E9 /* Mouse.cpp */, + 4B2E86B525D7490E0024F1E9 /* ReactiveDevice.cpp */, + 4BCE1DF025D4C3FA00AE7A2B /* Bus.hpp */, + 4B2E86CE25D8D8C70024F1E9 /* Keyboard.hpp */, 4B2E86BD25D74F160024F1E9 /* Mouse.hpp */, + 4B2E86B625D7490E0024F1E9 /* ReactiveDevice.hpp */, ); path = ADB; sourceTree = ""; @@ -5037,6 +5044,7 @@ 4B2E86BF25D74F160024F1E9 /* Mouse.cpp in Sources */, 4B6ED2F1208E2F8A0047B343 /* WOZ.cpp in Sources */, 4B055AD81FAE9B180060FFFF /* Video.cpp in Sources */, + 4B2E86D025D8D8C70024F1E9 /* Keyboard.cpp in Sources */, 4B89452F201967B4007DE474 /* StaticAnalyser.cpp in Sources */, 4B894531201967B4007DE474 /* StaticAnalyser.cpp in Sources */, 4B0ACC2D23775819008902D0 /* IntelligentKeyboard.cpp in Sources */, @@ -5092,6 +5100,7 @@ 4B055AED1FAE9BA20060FFFF /* Z80Storage.cpp in Sources */, 4B1B88BC202E2EC100B67DFF /* MultiKeyboardMachine.cpp in Sources */, 4BC890D4230F86020025A55A /* DirectAccessDevice.cpp in Sources */, + 4B2E86C925D892EF0024F1E9 /* DAT.cpp in Sources */, 4B6AAEAE230E40250078E864 /* Target.cpp in Sources */, 4BF437EF209D0F7E008CBD6B /* SegmentParser.cpp in Sources */, 4B055AD11FAE9B030060FFFF /* Video.cpp in Sources */, @@ -5366,6 +5375,7 @@ 4B4518841F75E91A00926311 /* UnformattedTrack.cpp in Sources */, 4B65086022F4CF8D009C1100 /* Keyboard.cpp in Sources */, 4B894528201967B4007DE474 /* Disk.cpp in Sources */, + 4B2E86CF25D8D8C70024F1E9 /* Keyboard.cpp in Sources */, 4BBB70A4202011C2002FE009 /* MultiMediaTarget.cpp in Sources */, 4B0ACC02237756ED008902D0 /* Line.cpp in Sources */, 4B89453A201967B4007DE474 /* StaticAnalyser.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme index 3f83509e5..6560dd001 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal Kiosk.xcscheme @@ -62,7 +62,7 @@ + isEnabled = "NO"> + isEnabled = "NO"> + isEnabled = "YES">