Skip to content

Commit

Permalink
Merge pull request #1352 from LapisRegia/master
Browse files Browse the repository at this point in the history
Touchpanel Support
  • Loading branch information
jpd002 authored Feb 23, 2024
2 parents 1c42b05 + 6cad8b2 commit a9a4046
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ set(COMMON_SRC_FILES
FrameDump.h
FrameLimiter.cpp
FrameLimiter.h
GunListener.h
ScreenPositionListener.h
InputConfig.cpp
InputConfig.h
GenericMipsExecutor.h
Expand Down
8 changes: 0 additions & 8 deletions Source/GunListener.h

This file was deleted.

31 changes: 29 additions & 2 deletions Source/PS2VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bool CPS2VM::HasGunListener() const
return m_gunListener != nullptr;
}

void CPS2VM::SetGunListener(CGunListener* listener)
void CPS2VM::SetGunListener(CScreenPositionListener* listener)
{
m_gunListener = listener;
}
Expand All @@ -145,7 +145,33 @@ void CPS2VM::ReportGunPosition(float x, float y)
{
if(m_gunListener)
{
m_gunListener->SetGunPosition(x, y);
m_gunListener->SetScreenPosition(x, y);
}
}

bool CPS2VM::HasTouchListener() const
{
return m_touchListener != nullptr;
}

void CPS2VM::SetTouchListener(CScreenPositionListener* listener)
{
m_touchListener = listener;
}

void CPS2VM::ReportTouchPosition(float x, float y)
{
if(m_touchListener)
{
m_touchListener->SetScreenPosition(x, y);
}
}

void CPS2VM::ReleaseScreenPosition()
{
if(m_touchListener)
{
m_touchListener->ReleaseScreenPosition();
}
}

Expand Down Expand Up @@ -490,6 +516,7 @@ void CPS2VM::ResetVM()

RegisterModulesInPadHandler();
m_gunListener = nullptr;
m_touchListener = nullptr;
}

void CPS2VM::DestroyVM()
Expand Down
12 changes: 9 additions & 3 deletions Source/PS2VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "MIPS.h"
#include "MailBox.h"
#include "PadHandler.h"
#include "GunListener.h"
#include "ScreenPositionListener.h"
#include "OpticalMedia.h"
#include "VirtualMachine.h"
#include "ee/Ee_SubSystem.h"
Expand Down Expand Up @@ -87,7 +87,12 @@ class CPS2VM : public CVirtualMachine

void ReportGunPosition(float, float);
bool HasGunListener() const;
void SetGunListener(CGunListener*);
void SetGunListener(CScreenPositionListener*);

void ReportTouchPosition(float, float);
bool HasTouchListener() const;
void SetTouchListener(CScreenPositionListener*);
void ReleaseScreenPosition();

OpticalMediaPtr m_cdrom0;
CPadHandler* m_pad = nullptr;
Expand Down Expand Up @@ -188,7 +193,8 @@ class CPS2VM : public CVirtualMachine
int m_spuBlockCount = 0;
CSoundHandler* m_soundHandler = nullptr;

CGunListener* m_gunListener = nullptr;
CScreenPositionListener* m_gunListener = nullptr;
CScreenPositionListener* m_touchListener = nullptr;

CProfiler::ZoneHandle m_eeProfilerZone = 0;
CProfiler::ZoneHandle m_iopProfilerZone = 0;
Expand Down
9 changes: 9 additions & 0 deletions Source/ScreenPositionListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

class CScreenPositionListener
{
public:
virtual ~CScreenPositionListener() = default;
virtual void SetScreenPosition(float, float) = 0;
virtual void ReleaseScreenPosition() = 0;
};
50 changes: 33 additions & 17 deletions Source/iop/namco_sys246/Iop_NamcoSys246.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ static const std::array<uint16, PS2::CControllerInfo::MAX_BUTTONS> g_defaultJvsB
0x0000,
0x0020, //DPAD_UP,
0x0010, //DPAD_DOWN,
0x0008, //DPAD_LEFT,
0x0004, //DPAD_RIGHT,
0x0008, //DPAD_LEFT (Shutter Sensor Top),
0x0004, //DPAD_RIGHT (Shutter Sensor Down),
0x0040, //SELECT,
0x0080, //START,
0x4000, //SQUARE,
0x8000, //TRIANGLE,
0x0001, //CIRCLE,
0x0001, //CIRCLE (Motor Sensor),
0x0002, //CROSS,
0x0100, //L1,
0x0200, //L2,
Expand Down Expand Up @@ -253,6 +253,15 @@ void CSys246::ProcessJvsPacket(const uint8* input, uint8* output)

(*dstSize) += 4;
}
else if(m_jvsMode == JVS_MODE::TOUCH)
{
(*output++) = 0x06; //Screen Pos Input
(*output++) = 0x10; //X pos bits
(*output++) = 0x10; //Y pos bits
(*output++) = 0x01; //channels

(*dstSize) += 4;
}

(*output++) = 0x00; //End of features

Expand Down Expand Up @@ -394,10 +403,10 @@ void CSys246::ProcessJvsPacket(const uint8* input, uint8* output)
if(m_jvsMode == JVS_MODE::LIGHTGUN)
{
assert(channel == 2);
(*output++) = static_cast<uint8>(m_jvsGunPosX >> 8); //Pos X MSB
(*output++) = static_cast<uint8>(m_jvsGunPosX); //Pos X LSB
(*output++) = static_cast<uint8>(m_jvsGunPosY >> 8); //Pos Y MSB
(*output++) = static_cast<uint8>(m_jvsGunPosY); //Pos Y LSB
(*output++) = static_cast<uint8>(m_jvsScreenPosX >> 8); //Pos X MSB
(*output++) = static_cast<uint8>(m_jvsScreenPosX); //Pos X LSB
(*output++) = static_cast<uint8>(m_jvsScreenPosY >> 8); //Pos Y MSB
(*output++) = static_cast<uint8>(m_jvsScreenPosY); //Pos Y LSB
}
else if(m_jvsMode == JVS_MODE::DRUM)
{
Expand Down Expand Up @@ -434,10 +443,10 @@ void CSys246::ProcessJvsPacket(const uint8* input, uint8* output)

(*output++) = 0x01; //Command success

(*output++) = static_cast<uint8>(m_jvsGunPosX >> 8); //Pos X MSB
(*output++) = static_cast<uint8>(m_jvsGunPosX); //Pos X LSB
(*output++) = static_cast<uint8>(m_jvsGunPosY >> 8); //Pos Y MSB
(*output++) = static_cast<uint8>(m_jvsGunPosY); //Pos Y LSB
(*output++) = static_cast<uint8>(m_jvsScreenPosX >> 8); //Pos X MSB
(*output++) = static_cast<uint8>(m_jvsScreenPosX); //Pos X LSB
(*output++) = static_cast<uint8>(m_jvsScreenPosY >> 8); //Pos Y MSB
(*output++) = static_cast<uint8>(m_jvsScreenPosY); //Pos Y LSB

(*dstSize) += 5;
}
Expand Down Expand Up @@ -477,9 +486,9 @@ void CSys246::SetButton(unsigned int buttonIndex, PS2::CControllerInfo::BUTTON b
m_jvsButtonBits[buttonValue] = (1 << buttonIndex);
}

void CSys246::SetLightGunXform(const std::array<float, 4>& lightGunXform)
void CSys246::SetScreenPosXform(const std::array<float, 4>& screenPosXform)
{
m_lightGunXform = lightGunXform;
m_screenPosXform = screenPosXform;
}

void CSys246::SetButtonState(unsigned int padNumber, PS2::CControllerInfo::BUTTON button, bool pressed, uint8* ram)
Expand Down Expand Up @@ -597,15 +606,22 @@ void CSys246::SetAxisState(unsigned int padNumber, PS2::CControllerInfo::BUTTON
}
}

void CSys246::SetGunPosition(float x, float y)
void CSys246::SetScreenPosition(float x, float y)
{
m_jvsScreenPosX = static_cast<int16>((x * m_screenPosXform[0]) + m_screenPosXform[1]);
m_jvsScreenPosY = static_cast<int16>((y * m_screenPosXform[2]) + m_screenPosXform[3]);
}

void CSys246::ReleaseScreenPosition()
{
m_jvsGunPosX = static_cast<int16>((x * m_lightGunXform[0]) + m_lightGunXform[1]);
m_jvsGunPosY = static_cast<int16>((y * m_lightGunXform[2]) + m_lightGunXform[3]);
m_jvsScreenPosX = 0xFFFF;
m_jvsScreenPosY = 0xFFFF; //Y position is negligible
}

bool CSys246::Invoke001(uint32 method, uint32* args, uint32 argsSize, uint32* ret, uint32 retSize, uint8* ram)
{
//JVIO stuff?
//method 0x01 -> ??? called once upon idolm@ster's startup. args[2] == 0x001, args[3] == 0x2000.
switch(method)
{
case 0x02:
Expand All @@ -629,7 +645,7 @@ bool CSys246::Invoke001(uint32 method, uint32* args, uint32 argsSize, uint32* re
ret[0] = 0;
ret[1] = size;
}
//Sengoku Basara & Time Crisis have argsSize == 0x10
//Sengoku Basara, Time Crisis & Idolm@ster have argsSize == 0x10
else if(argsSize == 0x10)
{
assert(argsSize >= 0x10);
Expand Down
18 changes: 10 additions & 8 deletions Source/iop/namco_sys246/Iop_NamcoSys246.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../Iop_SifMan.h"
#include "../../SifModuleAdapter.h"
#include "../../PadInterface.h"
#include "../../GunListener.h"
#include "../../ScreenPositionListener.h"
#include "filesystem_def.h"

namespace Iop
Expand All @@ -16,7 +16,7 @@ namespace Iop
{
class CAcRam;

class CSys246 : public CModule, public CPadInterface, public CGunListener
class CSys246 : public CModule, public CPadInterface, public CScreenPositionListener
{
public:
enum class JVS_MODE
Expand All @@ -25,6 +25,7 @@ namespace Iop
LIGHTGUN,
DRUM,
DRIVE,
TOUCH,
};

CSys246(CSifMan&, CSifCmd&, Namco::CAcRam&, const std::string&);
Expand All @@ -39,15 +40,16 @@ namespace Iop

void SetJvsMode(JVS_MODE);
void SetButton(unsigned int, PS2::CControllerInfo::BUTTON);
void SetLightGunXform(const std::array<float, 4>&);
void SetScreenPosXform(const std::array<float, 4>&);

//CPadInterface
void SetButtonState(unsigned int, PS2::CControllerInfo::BUTTON, bool, uint8*) override;
void SetAxisState(unsigned int, PS2::CControllerInfo::BUTTON, uint8, uint8*) override;
void GetVibration(unsigned int, uint8& largeMotor, uint8& smallMotor) override{};

//CGunListener
void SetGunPosition(float, float) override;
//CScreenPositionListener
void SetScreenPosition(float, float) override;
void ReleaseScreenPosition() override;

private:
enum MODULE_ID
Expand Down Expand Up @@ -117,13 +119,13 @@ namespace Iop
uint32 m_sendAddr = 0;

JVS_MODE m_jvsMode = JVS_MODE::DEFAULT;
std::array<float, 4> m_lightGunXform = {65535, 0, 65535, 0};
std::array<float, 4> m_screenPosXform = {65535, 0, 65535, 0};

std::array<uint16, PS2::CControllerInfo::MAX_BUTTONS> m_jvsButtonBits = {};
uint16 m_jvsButtonState[JVS_PLAYER_COUNT] = {};
uint16 m_jvsSystemButtonState = 0;
uint16 m_jvsGunPosX = 0x7FFF;
uint16 m_jvsGunPosY = 0x7FFF;
uint16 m_jvsScreenPosX = 0x7FFF;
uint16 m_jvsScreenPosY = 0x7FFF;
uint16 m_jvsDrumChannels[JVS_DRUM_CHANNEL_MAX] = {};
uint16 m_jvsWheelChannels[JVS_WHEEL_CHANNEL_MAX] = {};
uint16 m_jvsWheel = 0x0;
Expand Down
29 changes: 28 additions & 1 deletion Source/ui_qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ void MainWindow::focusInEvent(QFocusEvent* event)

void MainWindow::outputWindow_doubleClickEvent(QMouseEvent* ev)
{
if(!m_virtualMachine->HasGunListener() && (ev->button() == Qt::LeftButton))
if((!m_virtualMachine->HasGunListener() && !m_virtualMachine->HasTouchListener()) && (ev->button() == Qt::LeftButton))
{
on_actionToggleFullscreen_triggered();
}
Expand Down Expand Up @@ -862,11 +862,38 @@ void MainWindow::outputWindow_mouseMoveEvent(QMouseEvent* ev)
void MainWindow::outputWindow_mousePressEvent(QMouseEvent* ev)
{
m_qtMouseInputProvider->OnMousePress(ev->button());
if(m_virtualMachine->HasTouchListener() && (ev->button() == Qt::LeftButton))
{
auto gsHandler = m_virtualMachine->GetGSHandler();
if(!gsHandler) return;
qreal scale = 1.0;
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
scale = devicePixelRatioF();
#endif
auto presentationViewport = gsHandler->GetPresentationViewport();
float vpOfsX = static_cast<float>(presentationViewport.offsetX) / scale;
float vpOfsY = static_cast<float>(presentationViewport.offsetY) / scale;
float vpWidth = static_cast<float>(presentationViewport.width) / scale;
float vpHeight = static_cast<float>(presentationViewport.height) / scale;
float mouseX = ev->x();
float mouseY = ev->y();
mouseX -= vpOfsX;
mouseY -= vpOfsY;
mouseX = std::clamp<float>(mouseX, 0, vpWidth);
mouseY = std::clamp<float>(mouseY, 0, vpHeight);
m_virtualMachine->ReportTouchPosition(
static_cast<float>(mouseX) / static_cast<float>(vpWidth),
static_cast<float>(mouseY) / static_cast<float>(vpHeight));
}
}

void MainWindow::outputWindow_mouseReleaseEvent(QMouseEvent* ev)
{
m_qtMouseInputProvider->OnMouseRelease(ev->button());
if(m_virtualMachine->HasTouchListener())
{
m_virtualMachine->ReleaseScreenPosition();
}
}

void MainWindow::on_actionToggleFullscreen_triggered()
Expand Down
3 changes: 2 additions & 1 deletion Source/ui_shared/ArcadeDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct ARCADE_MACHINE_DEF
LIGHTGUN,
DRUM,
DRIVE,
TOUCH,
};

enum DRIVER
Expand All @@ -39,7 +40,7 @@ struct ARCADE_MACHINE_DEF
std::string nandFileName;
std::map<unsigned int, PS2::CControllerInfo::BUTTON> buttons;
INPUT_MODE inputMode = INPUT_MODE::DEFAULT;
std::array<float, 4> lightGunXform = {65535, 0, 65535, 0};
std::array<float, 4> screenPosXform = {65535, 0, 65535, 0};
uint32 eeFreqScaleNumerator = 1;
uint32 eeFreqScaleDenominator = 1;
std::string boot;
Expand Down
9 changes: 5 additions & 4 deletions Source/ui_shared/ArcadeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static const std::pair<const char*, ARCADE_MACHINE_DEF::INPUT_MODE> g_inputModeV
{ "lightgun", ARCADE_MACHINE_DEF::INPUT_MODE::LIGHTGUN },
{ "drum", ARCADE_MACHINE_DEF::INPUT_MODE::DRUM },
{ "drive", ARCADE_MACHINE_DEF::INPUT_MODE::DRIVE },
{ "touch", ARCADE_MACHINE_DEF::INPUT_MODE::TOUCH },
};
// clang-format on

Expand Down Expand Up @@ -165,14 +166,14 @@ ARCADE_MACHINE_DEF ReadArcadeMachineDefinition(const fs::path& arcadeDefPath)
std::string inputModeString = defJson["inputMode"];
def.inputMode = ParseEnumValue(inputModeString.c_str(), std::begin(g_inputModeValues), std::end(g_inputModeValues));
}
if(defJson.contains("lightGunXform"))
if(defJson.contains("screenPosXform"))
{
auto lightGunXformArray = defJson["lightGunXform"];
if(lightGunXformArray.is_array() && (lightGunXformArray.size() >= 4))
auto screenPosXformArray = defJson["screenPosXform"];
if(screenPosXformArray.is_array() && (screenPosXformArray.size() >= 4))
{
for(int i = 0; i < 4; i++)
{
def.lightGunXform[i] = lightGunXformArray[i];
def.screenPosXform[i] = screenPosXformArray[i];
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Source/ui_shared/arcadedrivers/NamcoSys246Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,19 @@ void CNamcoSys246Driver::PrepareEnvironment(CPS2VM* virtualMachine, const ARCADE
case ARCADE_MACHINE_DEF::INPUT_MODE::LIGHTGUN:
virtualMachine->SetGunListener(namcoArcadeModule.get());
namcoArcadeModule->SetJvsMode(Iop::Namco::CSys246::JVS_MODE::LIGHTGUN);
namcoArcadeModule->SetLightGunXform(def.lightGunXform);
namcoArcadeModule->SetScreenPosXform(def.screenPosXform);
break;
case ARCADE_MACHINE_DEF::INPUT_MODE::DRUM:
namcoArcadeModule->SetJvsMode(Iop::Namco::CSys246::JVS_MODE::DRUM);
break;
case ARCADE_MACHINE_DEF::INPUT_MODE::DRIVE:
namcoArcadeModule->SetJvsMode(Iop::Namco::CSys246::JVS_MODE::DRIVE);
break;
case ARCADE_MACHINE_DEF::INPUT_MODE::TOUCH:
virtualMachine->SetTouchListener(namcoArcadeModule.get());
namcoArcadeModule->SetJvsMode(Iop::Namco::CSys246::JVS_MODE::TOUCH);
namcoArcadeModule->SetScreenPosXform(def.screenPosXform);
break;
default:
break;
}
Expand Down
Loading

0 comments on commit a9a4046

Please sign in to comment.