Skip to content

Commit

Permalink
MiniDMD: fix invalid WPT access, fix invalid shades, fix invalid PinM…
Browse files Browse the repository at this point in the history
…ame rendering
  • Loading branch information
vbousquet committed Dec 21, 2024
1 parent 618648a commit 00574b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/wpc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3223,18 +3223,14 @@ void core_dmd_update_pwm(core_tDMDPWMState* dmd_state) {
// Render to internal display, using provided luminance, if there is a visible display (PinMAME always, and VPinMAME when its window is shown)
// FIXME apply colors LUT ?
#if defined(PINMAME) || defined(VPINMAME)
void core_dmd_render_internal(struct mame_bitmap *bitmap, const int x, const int y, const int width, const int height, const UINT8* const dmdDotLum, const int apply_aa, const int keepColor) {
void core_dmd_render_internal(struct mame_bitmap *bitmap, const int x, const int y, const int width, const int height, const UINT8* const dmdDotLum, const int apply_aa) {
#define DMD_OFS(row, col) ((row)*width + col)
#define DMD_PAL(x) ((unsigned int)sizeof(core_palette)/3u - 48u + ((unsigned int)(x) * 47u) / 255u) // The trail of PinMAME palette has 48 DMD dot shades
BMTYPE **lines = ((BMTYPE **)bitmap->line) + (y * locals.displaySize);
for (int ii = 0; ii < height; ii++) {
BMTYPE *line = (*lines) + (x * locals.displaySize);
for (int jj = 0; jj < width; jj++) {
if (keepColor) { // mini DMDs, don't change their colors
*line = coreGlobals.dmdDotRaw[ii * width + jj] + 1; // +1 needed because the entire palette was shifted!?
} else {
*line = DMD_PAL(dmdDotLum[DMD_OFS(ii, jj)]);
}
*line = DMD_PAL(dmdDotLum[DMD_OFS(ii, jj)]);
line += locals.displaySize;
}
lines += locals.displaySize;
Expand Down Expand Up @@ -3412,9 +3408,11 @@ void core_dmd_video_update(struct mame_bitmap *bitmap, const struct rectangle *c
dmdDotRaw = &coreGlobals.dmdDotRaw[0];
dmdDotLum = &coreGlobals.dmdDotLum[0];
if ((core_gameData->gen & GEN_SAM) == 0) {
const int shift = (core_gameData->gen & GEN_SPA) != 0 ? 4 : 6;
const UINT8 lum4[] = { 0, 85, 170, 255};
const UINT8 lum16[] = { 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 };
const UINT8* lum = (core_gameData->gen & GEN_SPA) != 0 ? lum16 : lum4;
for (int ii = 0; ii < layout->length * layout->start; ii++)
dmdDotLum[ii] = dmdDotRaw[ii] << shift;
dmdDotLum[ii] = lum[dmdDotRaw[ii]];
}
}

Expand All @@ -3428,7 +3426,7 @@ void core_dmd_video_update(struct mame_bitmap *bitmap, const struct rectangle *c
#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
core_dmd_render_internal(bitmap, layout->left, layout->top, layout->length, layout->start, dmdDotLum, pmoptions.dmd_antialias && !(layout->type & CORE_DMDNOAA), layout->type & CORE_NODISP);
core_dmd_render_internal(bitmap, layout->left, layout->top, layout->length, layout->start, dmdDotLum, pmoptions.dmd_antialias && !(layout->type & CORE_DMDNOAA));
if (isMainDMD) {
has_DMD_Video = 1;
core_dmd_render_vpm(layout->length, layout->start, dmdDotLum);
Expand All @@ -3437,7 +3435,7 @@ void core_dmd_video_update(struct mame_bitmap *bitmap, const struct rectangle *c
}

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

#endif
}
Expand Down
6 changes: 4 additions & 2 deletions src/wpc/sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,11 +2247,12 @@ static PINMAME_VIDEO_UPDATE(samdmd_update) {
#define SAT_NYB(v) (UINT8)(15.0f * (v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v))
#define SAT_BYTE(v) (UINT8)(255.0f * (v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v))

// Little 5x7 led matrix used in World Poker Tour (2 rows of 7 each)
static PINMAME_VIDEO_UPDATE(samminidmd_update) {
int ii,kk;
const int dmd_x = (layout->left-10)/7;
const int dmd_y = (layout->top-34)/9;
for (int y = 0; y < 8; y++)
for (int y = 0; y < 7; y++)
for (int x = 0; x < 5; x++) {
const int target = 10 * 8 + (dmd_y * 5 + x) * 49 + (dmd_x * 7 + y);
const float v = coreGlobals.physicOutputState[CORE_MODOUT_LAMP0 + target].value;
Expand All @@ -2261,7 +2262,7 @@ static PINMAME_VIDEO_UPDATE(samminidmd_update) {
// Use the video update to output mini DMD as LED segments (somewhat hacky)
for (ii = 0; ii < 5; ii++) {
int bits = 0;
for (kk = 0; kk < 7; kk++) // FIXME this does not match y in the for loop just above
for (kk = 0; kk < 7; kk++)
bits = (bits<<1) | (coreGlobals.dmdDotRaw[kk * layout->length + ii] ? 1 : 0);
coreGlobals.drawSeg[5*dmd_x + 35*dmd_y + ii] = bits;
}
Expand All @@ -2270,6 +2271,7 @@ static PINMAME_VIDEO_UPDATE(samminidmd_update) {
return 0;
}

// Wheel of Fortune Led matrix display
static PINMAME_VIDEO_UPDATE(samminidmd2_update) {
int ii,jj,kk;
for (jj = 0; jj < 35; jj++)
Expand Down

0 comments on commit 00574b4

Please sign in to comment.