Skip to content

Commit

Permalink
DMD: implement old frame identification pattern for GTS3
Browse files Browse the repository at this point in the history
Fix #344
  • Loading branch information
vbousquet committed Oct 17, 2024
1 parent 50bc803 commit 65cdbf5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
39 changes: 32 additions & 7 deletions src/wpc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,13 +2893,38 @@ void core_dmd_update_pwm(core_tDMDPWMState* dmd_state) {
// Compute combined bitplane frames as they used to be for backward compatibility with colorization plugins
#if defined(VPINMAME) || defined(LIBPINMAME)
switch (dmd_state->raw_combiner) {
case CORE_DMD_PWM_COMBINER_LUM_4:
for (int ii = 0; ii < dmd_state->height * dmd_state->width; ii++)
dmd_state->bitplaneFrame[ii] = dmd_state->luminanceFrame[ii] >> 6;
break;
case CORE_DMD_PWM_COMBINER_LUM_16: // GTS3 never had a stable combiner since PWM patterns vary over 1/3/6/8/10 frames, hence it provided raw 1 bitplane frame and not really stable combined one
for (int ii = 0; ii < dmd_state->height * dmd_state->width; ii++)
dmd_state->bitplaneFrame[ii] = dmd_state->luminanceFrame[ii] >> 4;
case CORE_DMD_PWM_COMBINER_GTS3_4C_A: // Reproduce previous (somewhat hacky) frame combiner used by GTS3 driver
case CORE_DMD_PWM_COMBINER_GTS3_4C_B:
case CORE_DMD_PWM_COMBINER_GTS3_5C:
{
static const int level4_a[7] = { 0, 1, 2, 2, 2, 2, 3 }; // 4 colors
static const int level4_a2[7] = { 0, 1, 1, 2, 2, 2, 3 }; // 4 colors
static const int level4_b[9] = { 0, 1, 2, 2, 2, 2, 2, 2, 3 }; // 4 colors
static const int level5[13] = { 0, 3, 3, 7, 7, 7, 11, 11, 11, 11, 11, 11, 15 }; // 5 colors
int* level = dmd_state->raw_combiner == CORE_DMD_PWM_COMBINER_GTS3_4C_A ? level4_a
: dmd_state->raw_combiner == CORE_DMD_PWM_COMBINER_GTS3_4C_B ? level4_b
: /* CORE_DMD_PWM_COMBINER_GTS3_5C */ level5;
int nFrames = dmd_state->raw_combiner == CORE_DMD_PWM_COMBINER_GTS3_4C_A ? 6
: dmd_state->raw_combiner == CORE_DMD_PWM_COMBINER_GTS3_4C_B ? 8
: /* CORE_DMD_PWM_COMBINER_GTS3_5C */ 12;
memset(dmd_state->bitplaneFrame, 0, dmd_state->frameSize);
for (int i = 0; i < nFrames; i++)
{
UINT8* rawData = &dmd_state->bitplaneFrame[0];
const UINT8* frameData = dmd_state->rawFrames + ((dmd_state->nextFrame + (dmd_state->nFrames - i)) % dmd_state->nFrames) * dmd_state->rawFrameSize;
for (int kk = 0; kk < dmd_state->rawFrameSize; kk++)
for (UINT8 ll = 0, data = *frameData++; ll < 8; ll++, data <<= 1)
(*rawData++) += (data >> 7);
}
if (dmd_state->raw_combiner == CORE_DMD_PWM_COMBINER_GTS3_4C_A)
for (int kk = 0; kk < dmd_state->frameSize; kk++)
if (dmd_state->bitplaneFrame[kk] == 4) {
level = level4_a2;
break;
}
for (int kk = 0; kk < dmd_state->frameSize; kk++)
dmd_state->bitplaneFrame[kk] = level[dmd_state->bitplaneFrame[kk]];
}
break;
case CORE_DMD_PWM_COMBINER_SUM_2: // Sum of the last 2 raw frames seen (WPC/Phantom Haus)
{
Expand Down
15 changes: 8 additions & 7 deletions src/wpc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,13 +632,14 @@ typedef struct {
#define CORE_DMD_PWM_FILTER_ALVG1 6
#define CORE_DMD_PWM_FILTER_ALVG2 7

#define CORE_DMD_PWM_COMBINER_LUM_4 0
#define CORE_DMD_PWM_COMBINER_LUM_16 1
#define CORE_DMD_PWM_COMBINER_SUM_2 2
#define CORE_DMD_PWM_COMBINER_SUM_3 3
#define CORE_DMD_PWM_COMBINER_SUM_2_1 4
#define CORE_DMD_PWM_COMBINER_SUM_1_2 5
#define CORE_DMD_PWM_COMBINER_SUM_4 6
#define CORE_DMD_PWM_COMBINER_GTS3_4C_A 0
#define CORE_DMD_PWM_COMBINER_GTS3_4C_B 1
#define CORE_DMD_PWM_COMBINER_GTS3_5C 2
#define CORE_DMD_PWM_COMBINER_SUM_2 3
#define CORE_DMD_PWM_COMBINER_SUM_3 4
#define CORE_DMD_PWM_COMBINER_SUM_2_1 5
#define CORE_DMD_PWM_COMBINER_SUM_1_2 6
#define CORE_DMD_PWM_COMBINER_SUM_4 7

extern void core_dmd_pwm_init(core_tDMDPWMState* dmd_state, const int width, const int height, const int filter, const int raw_combiner);
extern void core_dmd_pwm_exit(core_tDMDPWMState* dmd_state);
Expand Down
18 changes: 14 additions & 4 deletions src/wpc/gts3.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,19 @@ static void gts3dmd_init(void) {
crtc6845_init(0);
crtc6845_set_vsync(0, 3579545. / 2., dmd_vblank);

// Setup PWM shading
core_dmd_pwm_init(&GTS3_dmdlocals[0].pwm_state, 128, 32, CORE_DMD_PWM_FILTER_GTS3,
(strncasecmp(Machine->gamedrv->name, "smb", 3) == 0) || (strncasecmp(Machine->gamedrv->name, "cueball", 7) == 0) ? CORE_DMD_PWM_COMBINER_LUM_16 : CORE_DMD_PWM_COMBINER_LUM_4);
// Setup PWM shading, with a backward compatible combiner
if ((strncasecmp(Machine->gamedrv->name, "smb", 3) == 0) || (strncasecmp(Machine->gamedrv->name, "cueball", 7) == 0))
core_dmd_pwm_init(&GTS3_dmdlocals[0].pwm_state, 128, 32, CORE_DMD_PWM_FILTER_GTS3, CORE_DMD_PWM_COMBINER_GTS3_5C); // Used to be '_5C' games: SMB, SMB Mushroom, Cueball
else if ((strncasecmp(Machine->gamedrv->name, "stargat", 7) == 0)
|| (strncasecmp(Machine->gamedrv->name, "bighurt", 7) == 0)
|| (strncasecmp(Machine->gamedrv->name, "waterwl", 7) == 0)
|| (strncasecmp(Machine->gamedrv->name, "andrett", 7) == 0)
|| (strncasecmp(Machine->gamedrv->name, "barbwire", 8) == 0)
|| (strncasecmp(Machine->gamedrv->name, "brooks", 6) == 0)
|| (strncasecmp(Machine->gamedrv->name, "snspare", 7) == 0))
core_dmd_pwm_init(&GTS3_dmdlocals[0].pwm_state, 128, 32, CORE_DMD_PWM_FILTER_GTS3, CORE_DMD_PWM_COMBINER_GTS3_4C_B); // Used to be '_4C_b' games
else
core_dmd_pwm_init(&GTS3_dmdlocals[0].pwm_state, 128, 32, CORE_DMD_PWM_FILTER_GTS3, CORE_DMD_PWM_COMBINER_GTS3_4C_A); // Used to be '_4C_a' games

/*DMD*/
/*copy last 32K of ROM into last 32K of CPU region*/
Expand Down Expand Up @@ -720,7 +730,7 @@ static MACHINE_INIT(gts3dmd2) {
crtc6845_set_vsync(1, 3579545. / 2., dmd_vblank);

// Setup PWM shading
core_dmd_pwm_init(&GTS3_dmdlocals[1].pwm_state, 128, 32, CORE_DMD_PWM_FILTER_GTS3, CORE_DMD_PWM_COMBINER_LUM_16);
core_dmd_pwm_init(&GTS3_dmdlocals[1].pwm_state, 128, 32, CORE_DMD_PWM_FILTER_GTS3, CORE_DMD_PWM_COMBINER_GTS3_4C_B); // Used to be '_4C_b' games

/*copy last 32K of DMD ROM into last 32K of CPU region*/
if (memory_region(GTS3_MEMREG_DCPU2)) {
Expand Down

0 comments on commit 65cdbf5

Please sign in to comment.