Skip to content

Commit

Permalink
GPGX: add setting to disable per-line sprite limit
Browse files Browse the repository at this point in the history
- resolves TASEmulators#3440
- includes manually cherry-picked e0ef0902e96bd9d71cb49c64505e755007e7452c
  • Loading branch information
Morilli committed Nov 22, 2022
1 parent 248e87b commit 914c900
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 21 deletions.
Binary file modified Assets/dll/gpgx.wbx.zst
Binary file not shown.
17 changes: 15 additions & 2 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ISettable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public PutSettingsDirtyBits PutSettings(GPGXSettings o)
bool ret = GPGXSettings.NeedsReboot(_settings, o);
_settings = o;
Core.gpgx_set_draw_mask(_settings.GetDrawMask());
Core.gpgx_set_sprite_limit_enabled(!_settings.NoSpriteLimit);
return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None;
}

Expand Down Expand Up @@ -182,20 +183,32 @@ public bool PadScreen320
set => _PadScreen320 = value;
}


[DeepEqualsIgnore]
[JsonIgnore]
private bool _Backdrop;

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

[DeepEqualsIgnore]
[JsonIgnore]
private bool _noSpriteLimit;

[DisplayName("Remove Per-Line Sprite Limit")]
[Description("Removes the original sprite-per-scanline hardware limit")]
[DefaultValue(false)]
public bool NoSpriteLimit
{
get => _noSpriteLimit;
set => _noSpriteLimit = value;
}


public GPGXSettings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void LoadStateBinary(BinaryReader reader)
Core.gpgx_set_cdd_callback(cd_callback_handle);
Core.gpgx_invalidate_pattern_cache();
Core.gpgx_set_draw_mask(_settings.GetDrawMask());
Core.gpgx_set_sprite_limit_enabled(!_settings.NoSpriteLimit);
UpdateVideo();
}

Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ public enum DrawMask : int

[BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_set_draw_mask(DrawMask mask);
[BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_set_sprite_limit_enabled(bool enabled);

[BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_write_m68k_bus(uint addr, byte data);
Expand Down
2 changes: 1 addition & 1 deletion waterbox/gpgx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CCFLAGS := -Icore -Iutil -Icore/m68k -Icore/z80 -Icore/input_hw \
-Icore/cart_hw -Icore/cart_hw/svp -Icore/sound -Icore/ntsc -Icore/cd_hw \
-Wall -Werror=pointer-to-int-cast -Werror=int-to-pointer-cast -Werror=implicit-function-declaration \
-std=c99 -fomit-frame-pointer \
-DLSB_FIRST -DUSE_32BPP_RENDERING -DINLINE=static\ __inline__
-DLSB_FIRST -DUSE_32BPP_RENDERING -DINLINE=static\ __inline__ -fcommon

LDFLAGS :=

Expand Down
5 changes: 5 additions & 0 deletions waterbox/gpgx/cinterface/cinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ GPGX_EX void gpgx_set_draw_mask(int mask)
color_update_m5(0x00, *(uint16 *)&cram[border << 1]);
}

GPGX_EX void gpgx_set_sprite_limit_enabled(int enabled)
{
config.no_sprite_limit = !enabled;
}

GPGX_EX void gpgx_invalidate_pattern_cache(void)
{
vdp_invalidate_full_cache();
Expand Down
36 changes: 20 additions & 16 deletions waterbox/gpgx/core/vdp_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ typedef struct
uint16 size;
} object_info_t;

static object_info_t obj_info[2][20];
static object_info_t obj_info[2][MAX_SPRITES_PER_LINE];

/* Sprite Counter */
static uint8 object_count[2];
Expand Down Expand Up @@ -3212,6 +3212,7 @@ void render_obj_m5(int line)
int xpos, width;
int pixelcount = 0;
int masked = 0;
int max_pixels = MODE5_MAX_SPRITE_PIXELS;

uint8 *src, *s, *lb;
uint32 temp, v_line;
Expand Down Expand Up @@ -3276,10 +3277,10 @@ void render_obj_m5(int line)
lb = &linebuf[0][0x20 + xpos];

/* Max. number of sprite pixels rendered per line */
if (pixelcount > max_sprite_pixels)
if (pixelcount > max_pixels)
{
/* Adjust number of pixels to draw */
width -= (pixelcount - max_sprite_pixels);
width -= (pixelcount - max_pixels);
}

/* Number of tiles to draw */
Expand All @@ -3298,7 +3299,7 @@ void render_obj_m5(int line)
}

/* Sprite limit */
if (pixelcount >= max_sprite_pixels)
if (pixelcount >= max_pixels)
{
/* Sprite masking is effective on next line if max pixel width is reached */
spr_ovr = (pixelcount >= bitmap.viewport.w);
Expand All @@ -3321,6 +3322,7 @@ void render_obj_m5_ste(int line)
int xpos, width;
int pixelcount = 0;
int masked = 0;
int max_pixels = MODE5_MAX_SPRITE_PIXELS;

uint8 *src, *s, *lb;
uint32 temp, v_line;
Expand Down Expand Up @@ -3388,9 +3390,9 @@ void render_obj_m5_ste(int line)
lb = &linebuf[1][0x20 + xpos];

/* Adjust number of pixels to draw for sprite limit */
if (pixelcount > max_sprite_pixels)
if (pixelcount > max_pixels)
{
width -= (pixelcount - max_sprite_pixels);
width -= (pixelcount - max_pixels);
}

/* Number of tiles to draw */
Expand All @@ -3409,7 +3411,7 @@ void render_obj_m5_ste(int line)
}

/* Sprite limit */
if (pixelcount >= max_sprite_pixels)
if (pixelcount >= max_pixels)
{
/* Sprite masking is effective on next line if max pixel width is reached */
spr_ovr = (pixelcount >= bitmap.viewport.w);
Expand Down Expand Up @@ -3439,6 +3441,7 @@ void render_obj_m5_im2(int line)
int pixelcount = 0;
int masked = 0;
int odd = odd_frame;
int max_pixels = MODE5_MAX_SPRITE_PIXELS;

uint8 *src, *s, *lb;
uint32 temp, v_line;
Expand Down Expand Up @@ -3503,9 +3506,9 @@ void render_obj_m5_im2(int line)
lb = &linebuf[0][0x20 + xpos];

/* Adjust width for sprite limit */
if (pixelcount > max_sprite_pixels)
if (pixelcount > max_pixels)
{
width -= (pixelcount - max_sprite_pixels);
width -= (pixelcount - max_pixels);
}

/* Number of tiles to draw */
Expand All @@ -3524,7 +3527,7 @@ void render_obj_m5_im2(int line)
}

/* Sprite Limit */
if (pixelcount >= max_sprite_pixels)
if (pixelcount >= max_pixels)
{
/* Sprite masking is effective on next line if max pixel width is reached */
spr_ovr = (pixelcount >= bitmap.viewport.w);
Expand All @@ -3548,6 +3551,7 @@ void render_obj_m5_im2_ste(int line)
int pixelcount = 0;
int masked = 0;
int odd = odd_frame;
int max_pixels = MODE5_MAX_SPRITE_PIXELS;

uint8 *src, *s, *lb;
uint32 temp, v_line;
Expand Down Expand Up @@ -3615,9 +3619,9 @@ void render_obj_m5_im2_ste(int line)
lb = &linebuf[1][0x20 + xpos];

/* Adjust width for sprite limit */
if (pixelcount > max_sprite_pixels)
if (pixelcount > max_pixels)
{
width -= (pixelcount - max_sprite_pixels);
width -= (pixelcount - max_pixels);
}

/* Number of tiles to draw */
Expand All @@ -3636,7 +3640,7 @@ void render_obj_m5_im2_ste(int line)
}

/* Sprite Limit */
if (pixelcount >= max_sprite_pixels)
if (pixelcount >= max_pixels)
{
/* Sprite masking is effective on next line if max pixel width is reached */
spr_ovr = (pixelcount >= bitmap.viewport.w);
Expand Down Expand Up @@ -3717,7 +3721,7 @@ void parse_satb_tms(int line)
if ((ypos >= 0) && (ypos < height))
{
/* Sprite overflow */
if (count == 4)
if (count == TMS_MAX_SPRITES_PER_LINE)
{
/* Flag is set only during active area */
if (line < bitmap.viewport.h)
Expand Down Expand Up @@ -3813,7 +3817,7 @@ void parse_satb_m4(int line)
if ((ypos >= 0) && (ypos < height))
{
/* Sprite overflow */
if (count == 8)
if (count == MODE4_MAX_SPRITES_PER_LINE)
{
/* Flag is set only during active area */
if ((line >= 0) && (line < bitmap.viewport.h))
Expand Down Expand Up @@ -3859,7 +3863,7 @@ void parse_satb_m5(int line)
int count = 0;

/* max. number of rendered sprites (16 or 20 sprites per line by default) */
int max = bitmap.viewport.w >> 4;
int max = MODE5_MAX_SPRITES_PER_LINE;

/* max. number of parsed sprites (64 or 80 sprites per line by default) */
int total = max_sprite_pixels >> 2;
Expand Down
11 changes: 9 additions & 2 deletions waterbox/gpgx/util/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ typedef unsigned char bool;
#define M_PI 3.1415926535897932385
#endif

typedef struct
#define MAX_SPRITES_PER_LINE 80
#define TMS_MAX_SPRITES_PER_LINE (config.no_sprite_limit ? MAX_SPRITES_PER_LINE : 4)
#define MODE4_MAX_SPRITES_PER_LINE (config.no_sprite_limit ? MAX_SPRITES_PER_LINE : 8)
#define MODE5_MAX_SPRITES_PER_LINE (config.no_sprite_limit ? MAX_SPRITES_PER_LINE : (bitmap.viewport.w >> 4))
#define MODE5_MAX_SPRITE_PIXELS (config.no_sprite_limit ? MAX_SPRITES_PER_LINE * 32 : max_sprite_pixels)

typedef struct
{
int8 device;
uint8 port;
uint8 padtype;
} t_input_config;

struct
struct
{
char version[16];
uint8 hq_fm;
Expand Down Expand Up @@ -64,6 +70,7 @@ struct
uint8 gg_extra;
uint8 render;
t_input_config input[MAX_INPUTS];
uint8 no_sprite_limit;
} config;

extern char GG_ROM[256];
Expand Down

0 comments on commit 914c900

Please sign in to comment.