Skip to content

Commit

Permalink
Add data exchange through a global shared state block
Browse files Browse the repository at this point in the history
This commits allows to share prviously unshared data without overloading too much the API by adding a single data block for pulsed state, device state, modulated segments, multiple DMDs, raw DMD frames (for correct rendering and allow coloring) and video.

This commit contains the skeleton and base implementation to set up the ground for more testing on client side  (VPX) when support will be more advanced there. It also gives a ground to implement in LibPinMame.
  • Loading branch information
vbousquet committed Jan 8, 2025
1 parent 9a36fd8 commit d4a99e3
Show file tree
Hide file tree
Showing 7 changed files with 749 additions and 4 deletions.
30 changes: 30 additions & 0 deletions src/win32com/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,36 @@ STDMETHODIMP CController::put_TimeFence(double timeInS)
return S_OK;
}

/****************************************************************************
* IController.get_StateBlock: returns a shared memory block name which holds
* a global state block prepended by the memory block size as an unsigned int
****************************************************************************/
STDMETHODIMP CController::get_StateBlock(/*[out, retval]*/ BSTR* pVal)
{
if (!pVal)
return E_POINTER;
if (!Machine)
return E_FAIL;
if (core_getOutputState(CORE_STATE_REQMASK_ALL) == NULL)
return E_FAIL;
CComBSTR bsStateSharedMemName(TEXT("Local\\VPinMameStateBlock"));
*pVal = bsStateSharedMemName.Detach();
return S_OK;
}

/****************************************************************************
* IController.UpdateStateBlock: Update requested outputs of the global state
* block
****************************************************************************/
STDMETHODIMP CController::UpdateStateBlock(/*[in, defaultvalue(0x3F)]*/ unsigned int updateMask)
{
if (!Machine)
return E_FAIL;
if (core_getOutputState(updateMask) == NULL)
return E_FAIL;
return S_OK;
}

/****************************************************************************
* IController.Version (read-only): gets the program version of VPM
****************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/win32com/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ DECLARE_PROTECT_FINAL_CONSTRUCT()
STDMETHOD(put_ModOutputType)(/*[in]*/ int output, /*[in]*/ int no, /*[in]*/ int newVal);

STDMETHOD(put_TimeFence)(/*[in]*/ double fenceIns);

STDMETHOD(get_StateBlock)(/*[out, retval]*/ BSTR* pVal);
STDMETHOD(UpdateStateBlock)(/*[in, defaultvalue(0x1F)]*/ unsigned int updateMask);
};

#endif // !defined(AFX_Controller_H__D2811491_40D6_4656_9AA7_8FF85FD63543__INCLUDED_)
2 changes: 2 additions & 0 deletions src/win32com/VPinMAME.idl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ import "ocidl.idl";
[propget, id(88), helpstring("property ModOutputType")] HRESULT ModOutputType([in] int output, [in] int no, [out, retval] int *pVal);
[propput, id(88), helpstring("property ModOutputType")] HRESULT ModOutputType([in] int output, [in] int no, [in] int newVal);
[propput, id(89), helpstring("property TimeFence")] HRESULT TimeFence([in] double timeInS);
[propget, id(90), helpstring("property StateBlock")] HRESULT StateBlock([out, retval] BSTR* pVal);
[id(91), helpstring("method UpdateStateBlock")] HRESULT UpdateStateBlock([in, defaultvalue(0x3F)] unsigned int updateMask);
};

// WSHDlg and related interfaces
Expand Down
6 changes: 6 additions & 0 deletions src/wpc/byvidpin.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ static VIDEO_STOP(byVP) {

static PINMAME_VIDEO_UPDATE(byVP_update) {
TMS9928A_refresh((core_gameData->hw.display ? 2 : 1), bitmap, 1);
struct rectangle bounds;
bounds.min_x = 0;
bounds.min_y = 0;
bounds.max_x = 192;
bounds.max_y = 256;
core_display_video_update(bitmap, &bounds, layout, 1);
return 0;
}

Expand Down
616 changes: 614 additions & 2 deletions src/wpc/core.c

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/wpc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "gen.h"
#include "sim.h"

#include "drawgfx.h"

/*-- some convenience macros --*/
#ifndef FALSE
#define FALSE (0)
Expand Down Expand Up @@ -607,6 +609,90 @@ extern int core_getPulsedSol(int solNo);
extern UINT64 core_getAllSol(void);
extern void core_getAllPhysicSols(float* const state);

/*-- full output state --*/
#pragma warning(disable : 4200) // 0 length array is a non standard extension used intentionally, so disable corresponding warning
typedef struct
{
double updateTimestamp;
unsigned int nOutputs;
UINT32 outputBitset[]; // Bitset array of nOutputs bits with their current binary state
} core_tBinaryState;
#define CORE_DEVICE_STATE_TYPE_CUSTOM 1 // Custom state defined by each driver (value maybe either binary of 0/1 or 0/255, or modulated between 0..255)
#define CORE_DEVICE_STATE_TYPE_BULB 2 // Bulb state defined by its relative luminance and average filament temperature
#define CORE_DEVICE_STATE_TYPE_LED 3 // LED state defined by its relative luminance
#define CORE_DEVICE_STATE_TYPE_SEGMENTS 4 // LED or VFD state defined by a segment layout and the relative luminance of each segment
typedef struct
{
unsigned int deviceType;
union
{
// CORE_DEVICE_STATE_TYPE_DS
UINT8 customState; // Custom value, depending on each driver definition
// CORE_DEVICE_STATE_TYPE_BULB
struct
{
float luminance; // relative luminance to bulb rating (equals 1.f when bulb is under its rating voltage after heating stabilization)
float filamentTemperature; // perceived filament temperature (equals to bulb filament rating when bulb is under its rating voltage after heating stabilization)
} bulb;
// CORE_DEVICE_STATE_TYPE_LED
float ledLuminance; // relative luminance to bulb design (equals 1.f when LED is pulsed at its designed PWM)
// CORE_DEVICE_STATE_TYPE_SEGMENTS
struct
{
unsigned int type; // see CORE_SEG16, ...
float luminance[16]; // relative luminance of each segment (from 7 to 16)
} segment;
};
} core_tDeviceSingleState;
#pragma warning(disable : 4200) // 0 length array is a non standard extension used intentionally, so disable corresponding warning
typedef struct
{
double updateTimestamp;
unsigned int nDevices;
unsigned int dataStride;
core_tDeviceSingleState states[]; // array of nDevices * dataStride with the current device state
} core_tDeviceState;
#define CORE_FRAME_LUM 1 // Linear luminance (for monochrome DMD)
#define CORE_FRAME_RGB 2 // sRGB (for video frame)
#define CORE_FRAME_BP2 3 // 2 bitplanes, used to identify frames
#define CORE_FRAME_BP4 4 // 4 bitplanes, used to identify frames
#pragma warning(disable : 4200) // 0 length array is a non standard extension used intentionally, so disable corresponding warning
typedef struct
{
unsigned int structSize; // Struct size including header and frame data in bytes (for safe DMD/Display array iteration)
unsigned int displayId; // Unique Id, shared between render frame and raw frame used for frame identification
double updateTimestamp;
unsigned int width;
unsigned int height;
unsigned int dataFormat;
unsigned int frameId;
UINT8 frameData[]; // The display frame data which size depends on width, height and data format
} core_tFrameState;
typedef struct
{
unsigned int nDisplays;
// core_tFrameState displays[]; // Array of nDisplays * core_tFrameState (can't be directly declared since frame size is undefined)
} core_tDisplayState;
typedef struct
{
unsigned int versionID;
core_tBinaryState* controlledOutputBinaryState;
core_tDeviceState* controlledOutputDeviceState;
core_tDeviceState* lampMatrixState;
core_tDeviceState* alphaDisplayState;
core_tDisplayState* displayState;
core_tDisplayState* rawDMDState;
} core_tGlobalOutputState;

#define CORE_STATE_REQMASK_GPOUTPUT_BINARY_STATE 0x01
#define CORE_STATE_REQMASK_GPOUTPUT_DEVICE_STATE 0x02
#define CORE_STATE_REQMASK_LAMP_DEVICE_STATE 0x04
#define CORE_STATE_REQMASK_ALPHA_DEVICE_STATE 0x08
#define CORE_STATE_REQMASK_DISPLAY_STATE 0x10
#define CORE_STATE_REQMASK_RAW_DMD_STATE 0x20
#define CORE_STATE_REQMASK_ALL 0x3F
extern core_tGlobalOutputState* core_getOutputState(const unsigned int updateMask);

/*-- AC sync and PWM integration --*/
extern void core_update_pwm_outputs(const int startIndex, const int count);
INLINE void core_update_pwm_gis(void) { if (options.usemodsol & (CORE_MODOUT_FORCE_ON | CORE_MODOUT_ENABLE_PHYSOUT_GI)) core_update_pwm_outputs(CORE_MODOUT_GI0, coreGlobals.nGI); }
Expand Down Expand Up @@ -669,6 +755,8 @@ extern void core_dmd_submit_frame(core_tDMDPWMState* dmd_state, const UINT8* fra
extern void core_dmd_update_pwm(core_tDMDPWMState* dmd_state);
extern void core_dmd_video_update(struct mame_bitmap *bitmap, const struct rectangle *cliprect, const struct core_dispLayout *layout, core_tDMDPWMState* dmd_state);

extern void core_display_video_update(struct mame_bitmap* bitmap, const struct rectangle* cliprect, const struct core_dispLayout* layout, const int rotation);

extern void core_sound_throttle_adj(int sIn, int *sOut, int buffersize, double samplerate);

/*-- nvram handling --*/
Expand Down
8 changes: 6 additions & 2 deletions src/wpc/sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,9 @@ static PINMAME_VIDEO_UPDATE(samminidmd_update) {
bits = (bits << 1) | (coreGlobals.dmdDotRaw[y * 5 + x] ? 1 : 0);
coreGlobals.drawSeg[35 * dmd_y + 5 * dmd_x + x] = bits;
}
#ifndef VPINMAME
if (!pmoptions.dmd_only)
#endif
core_dmd_video_update(bitmap, cliprect, layout, NULL);
return 0;
}
Expand All @@ -2288,8 +2290,10 @@ static PINMAME_VIDEO_UPDATE(samminidmd2_update) {
bits = (bits<<1) | (coreGlobals.dmdDotRaw[kk * layout->length + ii] ? 1 : 0);
coreGlobals.drawSeg[ii] = bits;
}
if (!pmoptions.dmd_only)
core_dmd_video_update(bitmap, cliprect, layout, NULL);
#ifndef VPINMAME
if (!pmoptions.dmd_only)
#endif
core_dmd_video_update(bitmap, cliprect, layout, NULL);
return 0;
}

Expand Down

0 comments on commit d4a99e3

Please sign in to comment.