Skip to content

Commit

Permalink
libpinmame: add support for state blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 committed Jan 28, 2025
1 parent 35c9eed commit 74a9ade
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 4 deletions.
33 changes: 33 additions & 0 deletions src/libpinmame/libpinmame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,4 +1410,37 @@ PINMAMEAPI int PinmameGetChangedNVRAM(PinmameNVRAMState* const p_nvramStates)
PINMAMEAPI void PinmameSetUserData(const void* p_userData)
{
_p_userData = (void*)p_userData;
}

/******************************************************
* PinmameGetStateBlock
******************************************************/

PINMAMEAPI int PinmameGetStateBlock(PinMame::core_tGlobalOutputState** pp_outputState)
{
if (!_isRunning)
return -1;

PinMame::core_tGlobalOutputState* p_outputState = (PinMame::core_tGlobalOutputState*)core_getOutputState(CORE_STATE_REQMASK_ALL);
if (!p_outputState)
return -1;

*pp_outputState = p_outputState;

return 0;
}

/******************************************************
* PinmameUpdateStateBlock
******************************************************/

PINMAMEAPI int PinmameUpdateStateBlock(const unsigned int updateMask)
{
if (!_isRunning)
return -1;

if (!core_getOutputState(updateMask))
return -1;

return 0;
}
88 changes: 88 additions & 0 deletions src/libpinmame/libpinmame.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,91 @@
#define PINMAME_MAX_MECHSW 20
#define PINMAME_ACCUMULATOR_SAMPLES 8192 // from mixer.c

namespace PinMame
{
#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_t 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_t 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_t 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
};

typedef enum {
PINMAME_LOG_LEVEL_DEBUG = 0,
PINMAME_LOG_LEVEL_INFO = 1,
Expand Down Expand Up @@ -477,3 +562,6 @@ PINMAMEAPI int PinmameGetMaxNVRAM();
PINMAMEAPI int PinmameGetNVRAM(PinmameNVRAMState* const p_nvramStates);
PINMAMEAPI int PinmameGetChangedNVRAM(PinmameNVRAMState* const p_nvramStates);
PINMAMEAPI void PinmameSetUserData(const void* p_userData);
PINMAMEAPI int PinmameGetStateBlock(PinMame::core_tGlobalOutputState** pp_outputState);
PINMAMEAPI int PinmameUpdateStateBlock(const unsigned int updateMask);

6 changes: 2 additions & 4 deletions src/wpc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3891,7 +3891,7 @@ void core_dmd_render_dmddevice(const int width, const int height, const UINT8* c
#endif

// Prepare data for VPinMame state block
#ifdef VPINMAME
#if defined(VPINMAME) || defined(LIBPINMAME)
void core_dmd_update_state_block(const struct core_dispLayout* layout, const UINT8* dmdDotRaw, const UINT8* dmdDotLum) {
if (locals.outputStateBlock && locals.outputStateBlock->displayState) {
for (unsigned int i = 0; i < locals.outputStateBlock->displayState->nDisplays; i++) {
Expand Down Expand Up @@ -4018,7 +4018,7 @@ void core_dmd_video_update(struct mame_bitmap *bitmap, const struct rectangle *c
core_dmd_render_lpm(layout->length, layout->start, dmdDotLum, dmdDotRaw);
has_DMD_Video = 1;
}

core_dmd_update_state_block(layout, dmdDotRaw, dmdDotLum);
#elif defined(VPINMAME)
const int isMainDMD = layout->length >= 128; // Up to 2 main DMDs (1 for all games, except Strike'n Spares which has 2)
// FIXME check for VPinMame window hidden/shown state, and do not render if hidden
Expand All @@ -4030,10 +4030,8 @@ void core_dmd_video_update(struct mame_bitmap *bitmap, const struct rectangle *c
core_dmd_capture_frame(layout->length, layout->start, dmdDotRaw, raw_dmd_frame_count ,raw_dmd_frames);
}
core_dmd_update_state_block(layout, dmdDotRaw, dmdDotLum);

#elif defined(PINMAME)
core_dmd_render_internal(bitmap, layout->left, layout->top, layout->length, layout->start, dmdDotLum, pmoptions.dmd_antialias && !(layout->type & CORE_DMDNOAA));

#endif
}

Expand Down

0 comments on commit 74a9ade

Please sign in to comment.