1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-19 23:32:28 +00:00

Adds joystick support to the IIgs.

This commit is contained in:
Thomas Harte 2021-02-16 19:39:22 -05:00
parent 96f2d802d9
commit 28bd620e7f
3 changed files with 31 additions and 18 deletions

View File

@ -63,8 +63,8 @@ class JoystickPair {
return (1.0f - static_cast<Joystick *>(joysticks_[channel >> 1].get())->axes[channel & 1]) < analogue_charge_ + analogue_biases_[channel]; return (1.0f - static_cast<Joystick *>(joysticks_[channel >> 1].get())->axes[channel & 1]) < analogue_charge_ + analogue_biases_[channel];
} }
inline void update_charge() { inline void update_charge(float one_mhz_cycles = 1.0f) {
analogue_charge_ = std::min(analogue_charge_ + 1.0f / 2820.0f, 1.1f); analogue_charge_ = std::min(analogue_charge_ + one_mhz_cycles * (1.0f / 2820.0f), 1.1f);
} }
inline void access_c070() { inline void access_c070() {

View File

@ -10,14 +10,15 @@
#include "../../../Activity/Source.hpp" #include "../../../Activity/Source.hpp"
#include "../../MachineTypes.hpp" #include "../../MachineTypes.hpp"
#include "../../../Processors/65816/65816.hpp"
#include "../../../Analyser/Static/AppleIIgs/Target.hpp" #include "../../../Analyser/Static/AppleIIgs/Target.hpp"
#include "ADB.hpp" #include "ADB.hpp"
#include "MemoryMap.hpp" #include "MemoryMap.hpp"
#include "Video.hpp" #include "Video.hpp"
#include "Sound.hpp" #include "Sound.hpp"
#include "../../../Processors/65816/65816.hpp"
#include "../../../Components/8530/z8530.hpp" #include "../../../Components/8530/z8530.hpp"
#include "../../../Components/AppleClock/AppleClock.hpp" #include "../../../Components/AppleClock/AppleClock.hpp"
#include "../../../Components/AudioToggle/AudioToggle.hpp" #include "../../../Components/AudioToggle/AudioToggle.hpp"
@ -25,6 +26,8 @@
#include "../../../Components/DiskII/MacintoshDoubleDensityDrive.hpp" #include "../../../Components/DiskII/MacintoshDoubleDensityDrive.hpp"
#include "../../../Components/DiskII/DiskIIDrive.hpp" #include "../../../Components/DiskII/DiskIIDrive.hpp"
#include "../AppleII/Joystick.hpp"
#include "../../../Outputs/Speaker/Implementation/CompoundSource.hpp" #include "../../../Outputs/Speaker/Implementation/CompoundSource.hpp"
#include "../../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" #include "../../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
@ -37,7 +40,7 @@
namespace { namespace {
constexpr int CLOCK_RATE = 14318180; constexpr int CLOCK_RATE = 14'318'180;
} }
@ -48,11 +51,12 @@ class ConcreteMachine:
public Activity::Source, public Activity::Source,
public Apple::IIgs::Machine, public Apple::IIgs::Machine,
public MachineTypes::AudioProducer, public MachineTypes::AudioProducer,
public MachineTypes::JoystickMachine,
public MachineTypes::MappedKeyboardMachine,
public MachineTypes::MediaTarget, public MachineTypes::MediaTarget,
public MachineTypes::MouseMachine,
public MachineTypes::ScanProducer, public MachineTypes::ScanProducer,
public MachineTypes::TimedMachine, public MachineTypes::TimedMachine,
public MachineTypes::MappedKeyboardMachine,
public MachineTypes::MouseMachine,
public CPU::MOS6502Esque::BusHandler<uint32_t> { public CPU::MOS6502Esque::BusHandler<uint32_t> {
public: public:
@ -516,32 +520,34 @@ class ConcreteMachine:
*value = rom_[rom_.size() - 65536 + address_suffix]; *value = rom_[rom_.size() - 65536 + address_suffix];
break; break;
// Analogue inputs. Joystick parts are TODO. // Analogue inputs.
case Read(0xc061): 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; is_1Mhz = true;
break; break;
case Read(0xc062): 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; is_1Mhz = true;
break; break;
case Read(0xc060):
case Read(0xc063): case Read(0xc063):
// Joystick buttons. *value = joysticks_.button(2) ? 0x80 : 0x00;
*value = 0x00;
is_1Mhz = true; is_1Mhz = true;
break; 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. // Analogue inputs.
*value = 0x00; const size_t input = address_suffix - 0xc064;
*value = joysticks_.analogue_channel_is_discharged(input) ? 0x00 : 0x80;
is_1Mhz = true; is_1Mhz = true;
break; } break;
case Read(0xc070): case Write(0xc070): case Read(0xc070): case Write(0xc070):
// TODO: begin analogue channel charge. joysticks_.access_c070();
is_1Mhz = true; is_1Mhz = true;
break; break;
@ -904,6 +910,8 @@ class ConcreteMachine:
} }
} }
joysticks_.update_charge(duration.as<float>() / 14.0f);
return duration; return duration;
} }
@ -930,6 +938,10 @@ class ConcreteMachine:
return adb_glu_.last_valid()->get_mouse(); return adb_glu_.last_valid()->get_mouse();
} }
const std::vector<std::unique_ptr<Inputs::Joystick>> &get_joysticks() final {
return joysticks_.get_joysticks();
}
private: private:
CPU::WDC65816::Processor<ConcreteMachine, false> m65816_; CPU::WDC65816::Processor<ConcreteMachine, false> m65816_;
MemoryMap memory_; MemoryMap memory_;
@ -986,8 +998,9 @@ class ConcreteMachine:
}; };
friend AudioUpdater; friend AudioUpdater;
// MARK: - Keyboard. // MARK: - Keyboard and joystick.
Apple::ADB::KeyboardMapper keyboard_mapper_; Apple::ADB::KeyboardMapper keyboard_mapper_;
Apple::II::JoystickPair joysticks_;
// MARK: - Cards. // MARK: - Cards.

View File

@ -62,7 +62,7 @@
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableAddressSanitizer = "YES" enableAddressSanitizer = "YES"