Skip to content

Commit

Permalink
gpgx: custom backdrop color.
Browse files Browse the repository at this point in the history
  • Loading branch information
feos committed Feb 28, 2016
1 parent 050fa6d commit 9e3d573
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 115 deletions.
18 changes: 17 additions & 1 deletion BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.ISettable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ public class GPGXSettings
[DefaultValue((short)1)]
public short HighGain { get; set; }

[DeepEqualsIgnore]
[JsonIgnore]
private bool _Backdrop;

[DisplayName("Use custom backdrop color")]
[Description("Filler when layers are off")]
[DefaultValue((bool)false)]
public bool Backdrop { get { return _Backdrop; } set { _Backdrop = value; } }

[DisplayName("Custom backdrop color")]
[Description("Magic pink (0xffff00ff) by default")]
[DefaultValue((uint)0xffff00ff)]
public uint BackdropColor { get; set; }

public GPGXSettings()
{
SettingsUtil.SetDefaultValues(this);
Expand All @@ -135,6 +149,7 @@ public LibGPGX.DrawMask GetDrawMask()
if (DrawBGB) ret |= LibGPGX.DrawMask.BGB;
if (DrawBGW) ret |= LibGPGX.DrawMask.BGW;
if (DrawObj) ret |= LibGPGX.DrawMask.Obj;
if (Backdrop) ret |= LibGPGX.DrawMask.Backdrop;
return ret;
}

Expand All @@ -153,7 +168,8 @@ public LibGPGX.InitSettings GetNativeSettings()
HighFreq = HighFreq,
LowGain = LowGain,
MidGain = MidGain,
HighGain = HighGain
HighGain = HighGain,
BackdropColor = BackdropColor
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion BizHawk.Emulation.Cores/Consoles/Sega/gpgx/LibGPGX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum FilterType : byte
public short LowGain;
public short MidGain;
public short HighGain;
public uint BackdropColor;
}

[DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -334,7 +335,8 @@ public enum DrawMask : int
BGA = 1,
BGB = 2,
BGW = 4,
Obj = 8
Obj = 8,
Backdrop = 16
}

[DllImport("libgenplusgx.dll", CallingConvention = CallingConvention.Cdecl)]
Expand Down
13 changes: 12 additions & 1 deletion genplus-gx/cinterface/cinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ static int nsamples;
int cinterface_render_bga = 1;
int cinterface_render_bgb = 1;
int cinterface_render_bgw = 1;
int cinterface_render_obj = 0;
int cinterface_render_obj = 1;
uint8 cinterface_custom_backdrop = 0;
uint32 cinterface_custom_backdrop_color = 0xffff00ff; // pink
extern uint8 border;

#define GPGX_EX __declspec(dllexport)

Expand Down Expand Up @@ -493,6 +496,7 @@ struct InitSettings
int16_t LowGain;
int16_t MidGain;
int16_t HighGain;
uint32_t BackdropColor;
};

GPGX_EX int gpgx_init(const char *feromextension, int (*feload_archive_cb)(const char *filename, unsigned char *buffer, int maxsize), int sixbutton, char system_a, char system_b, int region, struct InitSettings *settings)
Expand Down Expand Up @@ -553,6 +557,8 @@ GPGX_EX int gpgx_init(const char *feromextension, int (*feload_archive_cb)(const
input.system[0] = system_a;
input.system[1] = system_b;

cinterface_custom_backdrop_color = settings->BackdropColor;

// apparently, the only part of config.input used is the padtype identifier,
// and that's used only for choosing pad type when system_md
{
Expand Down Expand Up @@ -600,6 +606,11 @@ GPGX_EX void gpgx_set_draw_mask(int mask)
cinterface_render_bgb = !!(mask & 2);
cinterface_render_bgw = !!(mask & 4);
cinterface_render_obj = !!(mask & 8);
cinterface_custom_backdrop = !!(mask & 16);
if (cinterface_custom_backdrop)
color_update_m5(0, 0);
else
color_update_m5(0x00, *(uint16 *)&cram[border << 1]);
}

typedef struct
Expand Down
2 changes: 1 addition & 1 deletion genplus-gx/core/vdp_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static const uint8 shift_table[] = { 6, 7, 0, 8 };
static const uint8 col_mask_table[] = { 0x0F, 0x1F, 0x0F, 0x3F };
static const uint16 row_mask_table[] = { 0x0FF, 0x1FF, 0x2FF, 0x3FF };

static uint8 border; /* Border color index */
uint8 border; /* Border color index */
static uint8 pending; /* Pending write flag */
static uint8 code; /* Code register */
static uint8 dma_type; /* DMA mode */
Expand Down
231 changes: 120 additions & 111 deletions genplus-gx/core/vdp_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern int cinterface_render_bga;
extern int cinterface_render_bgb;
extern int cinterface_render_bgw;
extern int cinterface_render_obj;
extern uint8 cinterface_custom_backdrop;
extern uint32 cinterface_custom_backdrop_color;

/*** NTSC Filters ***/
extern md_ntsc_t *md_ntsc;
Expand Down Expand Up @@ -1123,22 +1125,29 @@ void color_update_m5(int index, unsigned int data)
data &= 0x49;
}

if(reg[12] & 0x08)
if (index == 0 && cinterface_custom_backdrop)
{
/* Mode 5 (Shadow/Normal/Highlight) */
pixel[0x00 | index] = pixel_lut[0][data];
pixel[0x40 | index] = pixel_lut[1][data];
pixel[0x80 | index] = pixel_lut[2][data];
pixel[0x00] = pixel[0x40] = pixel[0x80] = cinterface_custom_backdrop_color;
}
else
{
/* Mode 5 (Normal) */
data = pixel_lut[1][data];

/* Input pixel: xxiiiiii */
pixel[0x00 | index] = data;
pixel[0x40 | index] = data;
pixel[0x80 | index] = data;
if(reg[12] & 0x08)
{
/* Mode 5 (Shadow/Normal/Highlight) */
pixel[0x00 | index] = pixel_lut[0][data];
pixel[0x40 | index] = pixel_lut[1][data];
pixel[0x80 | index] = pixel_lut[2][data];
}
else
{
/* Mode 5 (Normal) */
data = pixel_lut[1][data];

/* Input pixel: xxiiiiii */
pixel[0x00 | index] = data;
pixel[0x40 | index] = data;
pixel[0x80 | index] = data;
}
}
}

Expand Down Expand Up @@ -1707,47 +1716,47 @@ void render_bg_m5_vs(int line)

if (cinterface_render_bgb)
{
if(shift)
{
/* Plane B vertical scroll */
v_line = (line + yscroll) & pf_row_mask;

/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];

/* Pattern row index */
v_line = (v_line & 7) << 3;

/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x10 + shift];

atbuf = nt[(index - 1) & pf_col_mask];
DRAW_COLUMN(atbuf, v_line)
}
else
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x20];
}
if(shift)
{
/* Plane B vertical scroll */
v_line = (line + yscroll) & pf_row_mask;
/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];
/* Pattern row index */
v_line = (v_line & 7) << 3;
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x10 + shift];
atbuf = nt[(index - 1) & pf_col_mask];
DRAW_COLUMN(atbuf, v_line)
}
else
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x20];
}

for(column = 0; column < end; column++, index++)
{
/* Plane B vertical scroll */
for(column = 0; column < end; column++, index++)
{
/* Plane B vertical scroll */
#ifdef LSB_FIRST
v_line = (line + (vs[column] >> 16)) & pf_row_mask;
v_line = (line + (vs[column] >> 16)) & pf_row_mask;
#else
v_line = (line + vs[column]) & pf_row_mask;
v_line = (line + vs[column]) & pf_row_mask;
#endif

/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];

/* Pattern row index */
v_line = (v_line & 7) << 3;

atbuf = nt[index & pf_col_mask];
DRAW_COLUMN(atbuf, v_line)
}
/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];
/* Pattern row index */
v_line = (v_line & 7) << 3;
atbuf = nt[index & pf_col_mask];
DRAW_COLUMN(atbuf, v_line)
}
}
else
{
Expand Down Expand Up @@ -1902,30 +1911,30 @@ void render_bg_m5_im2(int line)
uint32 *nt;
if (cinterface_render_bgb)
{
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];

/* Pattern row index */
v_line = (((v_line & 7) << 1) | odd) << 3;

if(shift)
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x10 + shift];

atbuf = nt[(index - 1) & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
else
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x20];
}

for(column = 0; column < end; column++, index++)
{
atbuf = nt[index & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];
/* Pattern row index */
v_line = (((v_line & 7) << 1) | odd) << 3;
if(shift)
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x10 + shift];
atbuf = nt[(index - 1) & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
else
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x20];
}
for(column = 0; column < end; column++, index++)
{
atbuf = nt[index & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
}
else
{
Expand Down Expand Up @@ -2073,47 +2082,47 @@ void render_bg_m5_im2_vs(int line)

if (cinterface_render_bgb)
{
if(shift)
{
/* Plane B vertical scroll */
v_line = (line + yscroll) & pf_row_mask;

/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];

/* Pattern row index */
v_line = (((v_line & 7) << 1) | odd) << 3;

/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x10 + shift];

atbuf = nt[(index - 1) & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
else
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x20];
}

for(column = 0; column < end; column++, index++)
{
/* Plane B vertical scroll */
if(shift)
{
/* Plane B vertical scroll */
v_line = (line + yscroll) & pf_row_mask;
/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];
/* Pattern row index */
v_line = (((v_line & 7) << 1) | odd) << 3;
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x10 + shift];
atbuf = nt[(index - 1) & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
else
{
/* Plane B line buffer */
dst = (uint32 *)&linebuf[0][0x20];
}
for(column = 0; column < end; column++, index++)
{
/* Plane B vertical scroll */
#ifdef LSB_FIRST
v_line = (line + (vs[column] >> 17)) & pf_row_mask;
v_line = (line + (vs[column] >> 17)) & pf_row_mask;
#else
v_line = (line + (vs[column] >> 1)) & pf_row_mask;
v_line = (line + (vs[column] >> 1)) & pf_row_mask;
#endif

/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];

/* Pattern row index */
v_line = (((v_line & 7) << 1) | odd) << 3;

atbuf = nt[index & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
/* Plane B name table */
nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)];
/* Pattern row index */
v_line = (((v_line & 7) << 1) | odd) << 3;
atbuf = nt[index & pf_col_mask];
DRAW_COLUMN_IM2(atbuf, v_line)
}
}
else
{
Expand Down
Binary file modified output/dll/libgenplusgx.dll
Binary file not shown.

0 comments on commit 9e3d573

Please sign in to comment.