Skip to content

Commit

Permalink
tweak PWM flags and only integrate the ones that are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
toxieainc committed Mar 14, 2024
1 parent 07ea26e commit bfa2cca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
33 changes: 18 additions & 15 deletions src/wpc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ void core_updateSw(int flipEn) {

/*-- Report changed solenoids --*/
if (coreGlobals.nSolenoids &&
((options.usemodsol & CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS) || ((core_gameData->gen & (GEN_ALLWPC | GEN_SAM)) && (options.usemodsol & CORE_MODOUT_ENABLE_MODSOL)) ))
((options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_FORCE_ON)) || ((core_gameData->gen & (GEN_ALLWPC | GEN_SAM)) && (options.usemodsol & CORE_MODOUT_ENABLE_MODSOL)) ))
{
float state[CORE_MODOUT_SOL_MAX];
core_getAllPhysicSols(state);
Expand Down Expand Up @@ -1888,10 +1888,10 @@ void core_updInvSw(int swNo, int inv) {
/--------------------------------------*/
int core_getSol(int solNo) {
if (solNo <= 28)
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + solNo - 1].value) : coreGlobals.solenoids & CORE_SOLBIT(solNo);
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL | CORE_MODOUT_FORCE_ON)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + solNo - 1].value) : coreGlobals.solenoids & CORE_SOLBIT(solNo);
else if (solNo <= 32) { // 29-32
if (core_gameData->gen & GEN_ALLS11)
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + solNo - 1].value) : coreGlobals.solenoids & CORE_SOLBIT(solNo);
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL | CORE_MODOUT_FORCE_ON)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + solNo - 1].value) : coreGlobals.solenoids & CORE_SOLBIT(solNo);
else if (core_gameData->gen & GEN_ALLWPC) // GI circuits
return coreGlobals.solenoids2 & (1<<(solNo-29+8)); // GameOn
}
Expand All @@ -1910,9 +1910,9 @@ int core_getSol(int solNo) {
}
else if (solNo <= 44) { // 37-44 WPC95 & S11 extra
if (core_gameData->gen & (GEN_WPC95|GEN_WPC95DCS)) // Duplicated in 37..40 / 41..44, so always read from 41..44 (hence the |4 in the index/mask)
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + ((solNo - 13) | 4)].value) : coreGlobals.solenoids & (1<<((solNo - 13)|4));
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL | CORE_MODOUT_FORCE_ON)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + ((solNo - 13) | 4)].value) : coreGlobals.solenoids & (1<<((solNo - 13)|4));
if (core_gameData->gen & GEN_ALLS11)
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + 32 + solNo - 37 + 8].value) : coreGlobals.solenoids2 & (1<<(solNo - 37 + 8));
return coreGlobals.nSolenoids && (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_ENABLE_MODSOL | CORE_MODOUT_FORCE_ON)) ? saturatedByte(coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + 32 + solNo - 37 + 8].value) : coreGlobals.solenoids2 & (1<<(solNo - 37 + 8));
}
else if (solNo <= 48) { // 45-48 Lower flippers
int mask = 1<<(solNo - 45);
Expand Down Expand Up @@ -2238,8 +2238,7 @@ static MACHINE_INIT(core) {
#ifdef VPINMAME
// If physical output is enabled and supported, we add a 1ms timer that will service physical outputs requests from other threads, that is to say the VPinMAME client thread
// Note that physical outputs are also updated once per frame by the core machine driver video update callback.
if (((options.usemodsol & CORE_MODOUT_ENABLE_MODSOL) && coreGlobals.nSolenoids)
|| ((options.usemodsol & CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS) && coreGlobals.nSolenoids)
if (((options.usemodsol & (CORE_MODOUT_ENABLE_MODSOL | CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS)) && coreGlobals.nSolenoids)
|| ((options.usemodsol & CORE_MODOUT_ENABLE_PHYSOUT_LAMPS) && coreGlobals.nLamps)
|| ((options.usemodsol & CORE_MODOUT_ENABLE_PHYSOUT_GI) && coreGlobals.nGI)
|| ((options.usemodsol & CORE_MODOUT_ENABLE_PHYSOUT_ALPHASEGS) && coreGlobals.nAlphaSegs)
Expand Down Expand Up @@ -2632,14 +2631,18 @@ void core_update_pwm_outputs(int forceUpdate)
if (locals.pwmUpdateRequested || forceUpdate) {
locals.pwmUpdateRequested = FALSE;
const double now = timer_get_time();
for (int i = 0; i < coreGlobals.nLamps; i++)
coreGlobals.physicOutputState[CORE_MODOUT_LAMP0 + i].integrator(now, CORE_MODOUT_LAMP0 + i, FALSE);
for (int i = 0; i < coreGlobals.nGI; i++)
coreGlobals.physicOutputState[CORE_MODOUT_GI0 + i].integrator(now, CORE_MODOUT_GI0 + i, FALSE);
for (int i = 0; i < coreGlobals.nSolenoids; i++)
coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + i].integrator(now, CORE_MODOUT_SOL0 + i, FALSE);
for (int i = 0; i < coreGlobals.nAlphaSegs; i++)
coreGlobals.physicOutputState[CORE_MODOUT_SEG0 + i].integrator(now, CORE_MODOUT_SEG0 + i, FALSE);
if (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_LAMPS | CORE_MODOUT_FORCE_ON))
for (int i = 0; i < coreGlobals.nLamps; i++)
coreGlobals.physicOutputState[CORE_MODOUT_LAMP0 + i].integrator(now, CORE_MODOUT_LAMP0 + i, FALSE);
if (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_GI | CORE_MODOUT_FORCE_ON))
for (int i = 0; i < coreGlobals.nGI; i++)
coreGlobals.physicOutputState[CORE_MODOUT_GI0 + i].integrator(now, CORE_MODOUT_GI0 + i, FALSE);
if (options.usemodsol & (CORE_MODOUT_ENABLE_MODSOL | CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS | CORE_MODOUT_FORCE_ON))
for (int i = 0; i < coreGlobals.nSolenoids; i++)
coreGlobals.physicOutputState[CORE_MODOUT_SOL0 + i].integrator(now, CORE_MODOUT_SOL0 + i, FALSE);
if (options.usemodsol & (CORE_MODOUT_ENABLE_PHYSOUT_ALPHASEGS | CORE_MODOUT_FORCE_ON))
for (int i = 0; i < coreGlobals.nAlphaSegs; i++)
coreGlobals.physicOutputState[CORE_MODOUT_SEG0 + i].integrator(now, CORE_MODOUT_SEG0 + i, FALSE);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/wpc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ extern void video_update_core_dmd(struct mame_bitmap *bitmap, const struct recta
/*-- Physical devices on binary outputs --*/

#define CORE_MODOUT_ENABLE_MODSOL 1 /* Bitmask for options.usemodsol to enable legacy behavior (simple solenoid linear integration for WPC/SAM) */
#define CORE_MODOUT_ENABLE_PHYSOUT_LAMPS 0x02
#define CORE_MODOUT_ENABLE_PHYSOUT_GI 0x04
#define CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS 0x08
#define CORE_MODOUT_ENABLE_PHYSOUT_ALPHASEGS 0x10
#define CORE_MODOUT_ENABLE_PHYSOUT_LAMPS 0x04
#define CORE_MODOUT_ENABLE_PHYSOUT_GI 0x08
#define CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS 0x10
#define CORE_MODOUT_ENABLE_PHYSOUT_ALPHASEGS 0x20
#define CORE_MODOUT_ENABLE_PHYSOUT_ALL (CORE_MODOUT_ENABLE_PHYSOUT_LAMPS|CORE_MODOUT_ENABLE_PHYSOUT_GI|CORE_MODOUT_ENABLE_PHYSOUT_SOLENOIDS|CORE_MODOUT_ENABLE_PHYSOUT_ALPHASEGS) /* Bitmask for options.usemodsol to enable physics output for solenoids/Lamp/GI/AlphaSegments */
#define CORE_MODOUT_FORCE_ON 128 /* Bitmask for options.usemodsol for drivers that needs PWM integration to be performed whatever the user settings are */
#define CORE_MODOUT_FORCE_ON 0x80 /* Bitmask for options.usemodsol for drivers that needs PWM integration to be performed whatever the user settings are */

#define CORE_MODOUT_LAMP_MAX (CORE_MAXLAMPCOL * 8) /* Maximum number of modulated outputs for lamps */
#define CORE_MODOUT_SOL_MAX 72 /* Maximum number of modulated outputs for solenoids */
Expand Down
2 changes: 1 addition & 1 deletion src/wpc/vpintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void vp_setSolMask(int no, int mask) {
// Use index 2 to turn on/off modulated solenoids, using a bit mask:
// 1 enable legacy "modulated solenoid"
// 2 enable physical outputs (solenoids/lamps/GI/alphanum segments)
options.usemodsol = (options.usemodsol & CORE_MODOUT_FORCE_ON) | mask;
options.usemodsol = (options.usemodsol & CORE_MODOUT_FORCE_ON) | (mask==2 ? CORE_MODOUT_ENABLE_PHYSOUT_ALL : mask);
}
else if (no == 0 || no == 1)
{
Expand Down

0 comments on commit bfa2cca

Please sign in to comment.