Skip to content

Commit

Permalink
Merge pull request #190 from vbousquet/generalized_pwm
Browse files Browse the repository at this point in the history
PWM: add threading, add faded segment to WPC & GTS3 (only PinMame, since there is no VPM API for this)
  • Loading branch information
toxieainc authored Jan 15, 2024
2 parents 2a8679b + 2d1df34 commit 91d271b
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 292 deletions.
57 changes: 54 additions & 3 deletions src/win32com/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
01/08/12 (SJE): Added Warning message for game flagged with IMPERFECT SOUND
01/09/26 (SJE): Added Check to see if Invalid CRC games can be run.
03/09/22 (SJE): Added IMPERFECT GRAPHICS FLAG and reworked code to allow more than 1 message to display together
PinMame runs on another thread than the controller without blocking synchronization primitives. Therefore when getters are called,
the return value is the last known state. For lazy updated values like physic outputs, getters also trigger an update that will be
serviced asynchronously. The theory of operation is that these getters are to be called repeatedly to update/get the actual value.
*/

// Controller.cpp : Implementation of Controller and DLL registration.
Expand Down Expand Up @@ -396,8 +400,10 @@ STDMETHODIMP CController::get_Lamp(int nLamp, VARIANT_BOOL *pVal)

if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
*pVal= false;
else
else {
core_request_pwm_output_update();
*pVal = vp_getLamp(nLamp)?VARIANT_TRUE:VARIANT_FALSE;
}

return S_OK;
}
Expand All @@ -411,8 +417,10 @@ STDMETHODIMP CController::get_Solenoid(int nSolenoid, VARIANT_BOOL *pVal)

if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
*pVal= false;
else
else {
core_request_pwm_output_update();
*pVal = vp_getSolenoid(nSolenoid)?VARIANT_TRUE:VARIANT_FALSE;
}
return S_OK;
}

Expand Down Expand Up @@ -485,6 +493,8 @@ STDMETHODIMP CController::get_Lamps(VARIANT *pVal)
if ( !pVal )
return S_FALSE;

core_request_pwm_output_update();

SAFEARRAY *psa = SafeArrayCreateVector(VT_VARIANT, 0, 89);

VARIANT* pData;
Expand Down Expand Up @@ -858,6 +868,9 @@ STDMETHODIMP CController::get_ChangedLampsState(int **buf, int *pVal)
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ *pVal = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changes --*/
vp_tChgLamps chgLamps;
int uCount = vp_getChangedLamps(chgLamps);
Expand Down Expand Up @@ -891,6 +904,9 @@ STDMETHODIMP CController::get_LampsState(int **buf, int *pVal)

if (!pVal) return S_FALSE;

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- list lamps states to array --*/
int *dst = reinterpret_cast<int*>(buf);

Expand Down Expand Up @@ -924,6 +940,9 @@ STDMETHODIMP CController::get_ChangedSolenoidsState(int **buf, int *pVal)
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ *pVal = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changes --*/
vp_tChgSols chgSol;
int uCount = vp_getChangedSolenoids(chgSol);
Expand Down Expand Up @@ -958,6 +977,9 @@ STDMETHODIMP CController::get_SolenoidsState(int **buf, int *pVal)

if (!pVal) return S_FALSE;

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- list lamps states to array --*/
int *dst = reinterpret_cast<int*>(buf);

Expand Down Expand Up @@ -993,6 +1015,9 @@ STDMETHODIMP CController::get_ChangedGIsState(int **buf, int *pVal)
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ *pVal = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changes --*/
int uCount = vp_getChangedGI(chgGI);

Expand Down Expand Up @@ -1245,6 +1270,9 @@ STDMETHODIMP CController::get_ChangedLamps(VARIANT *pVal)
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ pVal->vt = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changes --*/
int uCount = vp_getChangedLamps(chgLamps);

Expand Down Expand Up @@ -1286,6 +1314,9 @@ STDMETHODIMP CController::get_ChangedLEDs(int nHigh, int nLow, int nnHigh, int n
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ pVal->vt = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changes --*/
int uCount = vp_getChangedLEDs(chgLED, mask, mask2);

Expand Down Expand Up @@ -1340,6 +1371,9 @@ STDMETHODIMP CController::get_ChangedLEDsState(int nHigh, int nLow, int nnHigh,
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ *pVal = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changes --*/
int uCount = vp_getChangedLEDs(chgLED, mask, mask2);

Expand Down Expand Up @@ -1428,7 +1462,12 @@ STDMETHODIMP CController::put_Mech(int mechNo, int newVal)
STDMETHODIMP CController::get_GIString(int nString, int *pVal) {
if (!pVal) return S_FALSE;

*pVal = (WaitForSingleObject(m_hEmuIsRunning, 0) != WAIT_TIMEOUT) ? vp_getGI(nString) : 0;
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
*pVal = 0;
else {
core_request_pwm_output_update();
*pVal = vp_getGI(nString);
}

return S_OK;
}
Expand All @@ -1446,6 +1485,9 @@ STDMETHODIMP CController::get_ChangedGIStrings(VARIANT *pVal) {
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ pVal->vt = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

int uCount = vp_getChangedGI(chgGI);

if (uCount == 0)
Expand Down Expand Up @@ -1489,6 +1531,9 @@ STDMETHODIMP CController::get_ChangedSolenoids(VARIANT *pVal)
if (WaitForSingleObject(m_hEmuIsRunning, 0) == WAIT_TIMEOUT)
{ pVal->vt = 0; return S_OK; }

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

/*-- Count changed solenoids --*/
int uCount = vp_getChangedSolenoids(chgSol);

Expand Down Expand Up @@ -1547,6 +1592,9 @@ STDMETHODIMP CController::get_Solenoids(VARIANT *pVal)
if ( !pVal )
return S_FALSE;

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

SAFEARRAY *psa = SafeArrayCreateVector(VT_VARIANT, 0, 65);

VARIANT* pData;
Expand Down Expand Up @@ -1593,6 +1641,9 @@ STDMETHODIMP CController::get_GIStrings(VARIANT *pVal)
if ( !pVal )
return S_FALSE;

/*-- Request an update that will be processed asynchronously --*/
core_request_pwm_output_update();

SAFEARRAY *psa = SafeArrayCreateVector(VT_VARIANT, 0, CORE_MAXGI);

VARIANT* pData;
Expand Down
Loading

0 comments on commit 91d271b

Please sign in to comment.