mirror of
https://github.com/libretro/MesenCE.git
synced 2026-11-10 03:02:05 -10:00
-ProcessCpuClock was used to check for events that don't need to be checked that often (auto-switch disk + auto fast-forward options). This has been moved to an EndFrame callback. -This was even slower than intended because of the call to _emu->GetFrameCount() which was, relatively speaking, fairly slow. To improve its performance (since it's used rarely for some things like turbo button processing), a separate GetFrameCount function was added on all console classes, and Emulator::GetFrameCount was also optimized to be faster when called from the emulation thread. When the auto-switch disk option is enabled, this can improve performance by about 25-30%. When the option is not enabled, this still improves performance by 4-5%.
116 lines
2.8 KiB
C++
116 lines
2.8 KiB
C++
#pragma once
|
|
#include "pch.h"
|
|
#include "Shared/BaseControlDevice.h"
|
|
#include "Shared/Emulator.h"
|
|
#include "Shared/EmuSettings.h"
|
|
#include "Shared/InputHud.h"
|
|
#include "Utilities/Serializer.h"
|
|
|
|
class GbController : public BaseControlDevice
|
|
{
|
|
private:
|
|
uint32_t _turboSpeed = 0;
|
|
|
|
protected:
|
|
string GetKeyNames() override
|
|
{
|
|
return "UDLRSsBA";
|
|
}
|
|
|
|
void InternalSetStateFromInput() override
|
|
{
|
|
bool turboOn = IsTurboOn(_turboSpeed);
|
|
|
|
for(KeyMapping& keyMapping : _keyMappings) {
|
|
SetPressedState(Buttons::A, keyMapping.A);
|
|
SetPressedState(Buttons::B, keyMapping.B);
|
|
SetPressedState(Buttons::Start, keyMapping.Start);
|
|
SetPressedState(Buttons::Select, keyMapping.Select);
|
|
SetPressedState(Buttons::Up, keyMapping.Up);
|
|
SetPressedState(Buttons::Down, keyMapping.Down);
|
|
SetPressedState(Buttons::Left, keyMapping.Left);
|
|
SetPressedState(Buttons::Right, keyMapping.Right);
|
|
|
|
if(turboOn) {
|
|
SetPressedState(Buttons::A, keyMapping.TurboA);
|
|
SetPressedState(Buttons::B, keyMapping.TurboB);
|
|
}
|
|
|
|
if(!_emu->GetSettings()->GetGameboyConfig().AllowInvalidInput) {
|
|
//If both U+D or L+R are pressed at the same time, act as if neither is pressed
|
|
if(IsPressed(Buttons::Up) && IsPressed(Buttons::Down)) {
|
|
ClearBit(Buttons::Down);
|
|
ClearBit(Buttons::Up);
|
|
}
|
|
if(IsPressed(Buttons::Left) && IsPressed(Buttons::Right)) {
|
|
ClearBit(Buttons::Left);
|
|
ClearBit(Buttons::Right);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void RefreshStateBuffer() override
|
|
{
|
|
}
|
|
|
|
public:
|
|
enum Buttons
|
|
{
|
|
Up = 0,
|
|
Down,
|
|
Left,
|
|
Right,
|
|
Start,
|
|
Select,
|
|
B,
|
|
A
|
|
};
|
|
|
|
GbController(Emulator* emu, uint8_t port, KeyMappingSet keyMappings) : BaseControlDevice(emu, ControllerType::GameboyController, port, keyMappings)
|
|
{
|
|
_turboSpeed = keyMappings.TurboSpeed;
|
|
}
|
|
|
|
uint8_t ReadRam(uint16_t addr) override
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void WriteRam(uint16_t addr, uint8_t value) override
|
|
{
|
|
}
|
|
|
|
void InternalDrawController(InputHud& hud) override
|
|
{
|
|
hud.DrawOutline(35, 14);
|
|
|
|
hud.DrawButton(5, 3, 3, 3, IsPressed(Buttons::Up));
|
|
hud.DrawButton(5, 9, 3, 3, IsPressed(Buttons::Down));
|
|
hud.DrawButton(2, 6, 3, 3, IsPressed(Buttons::Left));
|
|
hud.DrawButton(8, 6, 3, 3, IsPressed(Buttons::Right));
|
|
hud.DrawButton(5, 6, 3, 3, false);
|
|
|
|
hud.DrawButton(30, 7, 3, 3, IsPressed(Buttons::A));
|
|
hud.DrawButton(25, 7, 3, 3, IsPressed(Buttons::B));
|
|
|
|
hud.DrawButton(13, 9, 4, 2, IsPressed(Buttons::Select));
|
|
hud.DrawButton(18, 9, 4, 2, IsPressed(Buttons::Start));
|
|
|
|
hud.DrawNumber(_port + 1, 16, 2);
|
|
}
|
|
|
|
vector<DeviceButtonName> GetKeyNameAssociations() override
|
|
{
|
|
return {
|
|
{ "a", Buttons::A },
|
|
{ "b", Buttons::B },
|
|
{ "start", Buttons::Start },
|
|
{ "select", Buttons::Select },
|
|
{ "up", Buttons::Up },
|
|
{ "down", Buttons::Down },
|
|
{ "left", Buttons::Left },
|
|
{ "right", Buttons::Right },
|
|
};
|
|
}
|
|
}; |