diff --git a/Machines/Apple/AppleII/Joystick.hpp b/Machines/Apple/AppleII/Joystick.hpp index 33c517414..33f943c54 100644 --- a/Machines/Apple/AppleII/Joystick.hpp +++ b/Machines/Apple/AppleII/Joystick.hpp @@ -63,8 +63,8 @@ class JoystickPair { return (1.0f - static_cast(joysticks_[channel >> 1].get())->axes[channel & 1]) < analogue_charge_ + analogue_biases_[channel]; } - inline void update_charge() { - analogue_charge_ = std::min(analogue_charge_ + 1.0f / 2820.0f, 1.1f); + inline void update_charge(float one_mhz_cycles = 1.0f) { + analogue_charge_ = std::min(analogue_charge_ + one_mhz_cycles * (1.0f / 2820.0f), 1.1f); } inline void access_c070() { diff --git a/Machines/Apple/AppleIIgs/AppleIIgs.cpp b/Machines/Apple/AppleIIgs/AppleIIgs.cpp index 50234875d..f89905511 100644 --- a/Machines/Apple/AppleIIgs/AppleIIgs.cpp +++ b/Machines/Apple/AppleIIgs/AppleIIgs.cpp @@ -10,14 +10,15 @@ #include "../../../Activity/Source.hpp" #include "../../MachineTypes.hpp" -#include "../../../Processors/65816/65816.hpp" #include "../../../Analyser/Static/AppleIIgs/Target.hpp" + #include "ADB.hpp" #include "MemoryMap.hpp" #include "Video.hpp" #include "Sound.hpp" +#include "../../../Processors/65816/65816.hpp" #include "../../../Components/8530/z8530.hpp" #include "../../../Components/AppleClock/AppleClock.hpp" #include "../../../Components/AudioToggle/AudioToggle.hpp" @@ -25,6 +26,8 @@ #include "../../../Components/DiskII/MacintoshDoubleDensityDrive.hpp" #include "../../../Components/DiskII/DiskIIDrive.hpp" +#include "../AppleII/Joystick.hpp" + #include "../../../Outputs/Speaker/Implementation/CompoundSource.hpp" #include "../../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" @@ -37,7 +40,7 @@ namespace { -constexpr int CLOCK_RATE = 14318180; +constexpr int CLOCK_RATE = 14'318'180; } @@ -48,11 +51,12 @@ class ConcreteMachine: public Activity::Source, public Apple::IIgs::Machine, public MachineTypes::AudioProducer, + public MachineTypes::JoystickMachine, + public MachineTypes::MappedKeyboardMachine, public MachineTypes::MediaTarget, + public MachineTypes::MouseMachine, public MachineTypes::ScanProducer, public MachineTypes::TimedMachine, - public MachineTypes::MappedKeyboardMachine, - public MachineTypes::MouseMachine, public CPU::MOS6502Esque::BusHandler { public: @@ -516,32 +520,34 @@ class ConcreteMachine: *value = rom_[rom_.size() - 65536 + address_suffix]; break; - // Analogue inputs. Joystick parts are TODO. + // Analogue inputs. case Read(0xc061): - *value = adb_glu_->get_command_button() ? 0x80 : 0x00; + *value = (adb_glu_->get_command_button() || joysticks_.button(0)) ? 0x80 : 0x00; is_1Mhz = true; break; case Read(0xc062): - *value = adb_glu_->get_option_button() ? 0x80 : 0x00; + *value = (adb_glu_->get_option_button() || joysticks_.button(1)) ? 0x80 : 0x00; is_1Mhz = true; break; - case Read(0xc060): case Read(0xc063): - // Joystick buttons. - *value = 0x00; + *value = joysticks_.button(2) ? 0x80 : 0x00; is_1Mhz = true; break; - case Read(0xc064): case Read(0xc065): case Read(0xc066): case Read(0xc067): + case Read(0xc064): + case Read(0xc065): + case Read(0xc066): + case Read(0xc067): { // Analogue inputs. - *value = 0x00; + const size_t input = address_suffix - 0xc064; + *value = joysticks_.analogue_channel_is_discharged(input) ? 0x00 : 0x80; is_1Mhz = true; - break; + } break; case Read(0xc070): case Write(0xc070): - // TODO: begin analogue channel charge. + joysticks_.access_c070(); is_1Mhz = true; break; @@ -904,6 +910,8 @@ class ConcreteMachine: } } + joysticks_.update_charge(duration.as() / 14.0f); + return duration; } @@ -930,6 +938,10 @@ class ConcreteMachine: return adb_glu_.last_valid()->get_mouse(); } + const std::vector> &get_joysticks() final { + return joysticks_.get_joysticks(); + } + private: CPU::WDC65816::Processor m65816_; MemoryMap memory_; @@ -986,8 +998,9 @@ class ConcreteMachine: }; friend AudioUpdater; - // MARK: - Keyboard. + // MARK: - Keyboard and joystick. Apple::ADB::KeyboardMapper keyboard_mapper_; + Apple::II::JoystickPair joysticks_; // MARK: - Cards. diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme index 324ac6bb0..aa72d51d7 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -62,7 +62,7 @@