Skip to content

Commit

Permalink
Merge branch 'master' into libretro
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Dec 28, 2024
2 parents 7625ec4 + 78c8d21 commit 9c11535
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 140 deletions.
27 changes: 10 additions & 17 deletions frontend/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,7 @@ static void update_variables(bool in_flight)
{
axis_bounds_modifier = true;
}
else if (strcmp(var.value, "circle") == 0)
else
{
axis_bounds_modifier = false;
}
Expand Down Expand Up @@ -2864,26 +2864,19 @@ static uint16_t get_analog_button(int16_t ret, retro_input_state_t input_state_c
return button;
}

unsigned char axis_range_modifier(int16_t axis_value, bool is_square)
static unsigned char axis_range_modifier(int axis_value, bool is_square)
{
float modifier_axis_range = 0;
int modifier_axis_range;

if (is_square)
{
modifier_axis_range = round((axis_value >> 8) / 0.785) + 128;
if (modifier_axis_range < 0)
{
modifier_axis_range = 0;
}
else if (modifier_axis_range > 255)
{
modifier_axis_range = 255;
}
}
modifier_axis_range = roundf((axis_value >> 8) / 0.785f) + 128;
else
{
modifier_axis_range = MIN(((axis_value >> 8) + 128), 255);
}
modifier_axis_range = (axis_value >> 8) + 128;

if (modifier_axis_range < 0)
modifier_axis_range = 0;
else if (modifier_axis_range > 255)
modifier_axis_range = 255;

return modifier_axis_range;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
{ "square", "Square" },
{ NULL, NULL },
},
"circle",
"square",
},
{
"pcsx_rearmed_vibration",
Expand Down
1 change: 0 additions & 1 deletion libpcsxcore/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@ void cdrInterrupt(void) {
error = ERROR_BAD_ARGNUM;
goto set_error;
}
cdr.DriveState = DRIVESTATE_STANDBY;
second_resp_time = cdReadTime * 125 / 2;
start_rotating = 1;
break;
Expand Down
41 changes: 34 additions & 7 deletions libpcsxcore/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static const char * const gpu_slow_llist_db[] =
"SLES01712", "SLPS01525", "SLPS91138", "SLPM87102", "SLUS00823",
/* Crash Bash */
"SCES02834", "SCUS94570", "SCUS94616", "SCUS94654",
/* F1 2000 - aborting/resuming dma in menus */
"SLUS01120", "SLES02722", "SLES02723", "SLES02724", "SLPS02758", "SLPM80564",
/* Final Fantasy IV */
"SCES03840", "SLPM86028", "SLUS01360",
/* Point Blank - calibration cursor */
Expand All @@ -54,12 +56,6 @@ static const char * const gpu_centering_hack_db[] =
"SLPM86009",
};

static const char * const dualshock_timing1024_hack_db[] =
{
/* Judge Dredd - could also be poor cdrom+mdec+dma timing */
"SLUS00630", "SLES00755",
};

static const char * const dualshock_init_analog_hack_db[] =
{
/* Formula 1 Championship Edition */
Expand Down Expand Up @@ -109,7 +105,6 @@ hack_db[] =
HACK_ENTRY(cdr_read_timing, cdr_read_hack_db),
HACK_ENTRY(gpu_slow_list_walking, gpu_slow_llist_db),
HACK_ENTRY(gpu_centering, gpu_centering_hack_db),
HACK_ENTRY(gpu_timing1024, dualshock_timing1024_hack_db),
HACK_ENTRY(dualshock_init_analog, dualshock_init_analog_hack_db),
HACK_ENTRY(fractional_Framerate, fractional_Framerate_hack_db),
HACK_ENTRY(f1, f1_hack_db),
Expand Down Expand Up @@ -157,6 +152,22 @@ cycle_multiplier_overrides[] =
{ 200, { "SLUS01519", "SCPS45260", "SLPS01463" } },
};

static const struct
{
int cycles;
const char * const id[4];
}
gpu_timing_hack_db[] =
{
/* Judge Dredd - poor cdrom+mdec+dma+gpu timing */
{ 1024, { "SLUS00630", "SLES00755" } },
/* F1 2000 - flooding the GPU in menus */
{ 300*1024, { "SLUS01120", "SLES02722", "SLES02723", "SLES02724" } },
{ 300*1024, { "SLPS02758", "SLPM80564" } },
/* Soul Blade - same as above */
{ 512*1024, { "SLUS00240", "SCES00577" } },
};

static const char * const lightrec_hack_db[] =
{
/* Tomb Raider (Rev 2) - boot menu clears over itself */
Expand Down Expand Up @@ -223,6 +234,22 @@ void Apply_Hacks_Cdrom(void)
}
}

Config.gpu_timing_override = 0;
for (i = 0; i < ARRAY_SIZE(gpu_timing_hack_db); i++)
{
const char * const * const ids = gpu_timing_hack_db[i].id;
for (j = 0; j < ARRAY_SIZE(gpu_timing_hack_db[i].id); j++)
if (ids[j] && strcmp(ids[j], CdromId) == 0)
break;
if (j < ARRAY_SIZE(gpu_timing_hack_db[i].id))
{
Config.gpu_timing_override = gpu_timing_hack_db[i].cycles;
SysPrintf("using gpu_timing_override: %d\n",
Config.gpu_timing_override);
break;
}
}

if (drc_is_lightrec()) {
lightrec_hacks = 0;
if (Config.hacks.f1)
Expand Down
2 changes: 1 addition & 1 deletion libpcsxcore/psxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ typedef struct {
boolean TurboCD;
int cycle_multiplier; // 100 for 1.0
int cycle_multiplier_override;
int gpu_timing_override;
s8 GpuListWalking;
s8 FractionalFramerate; // ~49.75 and ~59.81 instead of 50 and 60
u8 Cpu; // CPU_DYNAREC or CPU_INTERPRETER
Expand All @@ -154,7 +155,6 @@ typedef struct {
boolean gpu_slow_list_walking;
boolean gpu_centering;
boolean dualshock_init_analog;
boolean gpu_timing1024;
boolean fractional_Framerate;
boolean f1;
} hacks;
Expand Down
15 changes: 8 additions & 7 deletions libpcsxcore/psxdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU
case 0x01000401: // dma chain
PSXDMA_LOG("*** DMA 2 - GPU dma chain *** %lx addr = %lx size = %lx\n", chcr, madr, bcr);
// when not emulating walking progress, end immediately
// (some games abort the dma and read madr so break out of that logic)
madr_next = 0xffffff;

do_walking = Config.GpuListWalking;
if (do_walking < 0 || Config.hacks.gpu_timing1024)
if (do_walking < 0)
do_walking = Config.hacks.gpu_slow_list_walking;
madr_next_p = do_walking ? &madr_next : NULL;

Expand All @@ -204,13 +205,13 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU

HW_DMA2_MADR = SWAPu32(madr_next);

// a hack for Judge Dredd which is annoyingly sensitive to timing
if (Config.hacks.gpu_timing1024)
cycles_sum = 1024;
// timing hack with some lame heuristics
if (Config.gpu_timing_override && (do_walking || cycles_sum > 64))
cycles_sum = Config.gpu_timing_override;

psxRegs.gpuIdleAfter = psxRegs.cycle + cycles_sum + cycles_last_cmd;
set_event(PSXINT_GPUDMA, cycles_sum);
//printf("%u dma2cf: %6d,%4d %08x %08x %08x %08x\n", psxRegs.cycle,
//printf("%u dma2cf: %6ld,%4d %08x %08x %08x %08x\n", psxRegs.cycle,
// cycles_sum, cycles_last_cmd, madr, bcr, chcr, HW_DMA2_MADR);
return;

Expand All @@ -237,8 +238,8 @@ void gpuInterrupt() {
cycles_sum += psxRegs.gpuIdleAfter - psxRegs.cycle;
psxRegs.gpuIdleAfter = psxRegs.cycle + cycles_sum + cycles_last_cmd;
set_event(PSXINT_GPUDMA, cycles_sum);
//printf("%u dma2cn: %6d,%4d %08x\n", psxRegs.cycle, cycles_sum,
// cycles_last_cmd, HW_DMA2_MADR);
//printf("%u dma2cn: %6ld,%4d %08x\n", psxRegs.cycle, cycles_sum,
// cycles_last_cmd, HW_DMA2_MADR);
return;
}
if (HW_DMA2_CHCR & SWAP32(0x01000000))
Expand Down
36 changes: 24 additions & 12 deletions plugins/gpu_neon/psx_gpu/psx_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ setup_blocks_uv_adj_hack(psx_gpu_struct *psx_gpu, block_struct *block,

#define setup_blocks_add_blocks_direct() \
stats_add(texel_blocks_untextured, span_num_blocks); \
span_pixel_blocks += span_num_blocks \
stats_add(span_pixel_blocks, span_num_blocks); \


#define setup_blocks_builder(shading, texturing, dithering, sw, target) \
Expand Down Expand Up @@ -2918,9 +2918,9 @@ char *render_block_flag_strings[] =
(triangle_winding_##winding << 6)) \

static int prepare_triangle(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
vertex_struct *vertexes_out[3])
prepared_triangle *triangle_out)
{
s32 y_top, y_bottom;
s32 y_top, y_bottom, offset_x, offset_y, i;
s32 triangle_area;
u32 triangle_winding = 0;

Expand Down Expand Up @@ -2955,6 +2955,7 @@ static int prepare_triangle(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,

y_bottom = c->y;
y_top = a->y;
offset_y = sign_extend_11bit(y_top + psx_gpu->offset_y) - y_top;

if((y_bottom - y_top) >= 512)
{
Expand Down Expand Up @@ -2982,29 +2983,39 @@ static int prepare_triangle(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
vertex_swap(a, b);
}

if((c->x - psx_gpu->offset_x) >= 1024 || (c->x - a->x) >= 1024)
if(c->x - a->x >= 1024)
{
#ifdef PROFILE
trivial_rejects++;
#endif
return 0;
}

if(invalidate_texture_cache_region_viewport(psx_gpu, a->x, y_top, c->x,
y_bottom) == 0)
offset_x = sign_extend_11bit(a->x + psx_gpu->offset_x) - a->x;
if(invalidate_texture_cache_region_viewport(psx_gpu,
a->x + offset_x, y_top + offset_y,
c->x + offset_x, y_bottom + offset_y) == 0)
{
#ifdef PROFILE
trivial_rejects++;
#endif
return 0;
}

for (i = 0; i < 3; i++)
{
vertexes[i].x += offset_x;
vertexes[i].y += offset_y;
}

psx_gpu->triangle_area = triangle_area;
psx_gpu->triangle_winding = triangle_winding;

vertexes_out[0] = a;
vertexes_out[1] = b;
vertexes_out[2] = c;
triangle_out->vertexes[0] = a;
triangle_out->vertexes[1] = b;
triangle_out->vertexes[2] = c;
triangle_out->offset_x = offset_x;
triangle_out->offset_y = offset_y;

return 1;
}
Expand Down Expand Up @@ -3157,9 +3168,9 @@ static void render_triangle_p(psx_gpu_struct *psx_gpu,
void render_triangle(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
u32 flags)
{
vertex_struct *vertex_ptrs[3];
if (prepare_triangle(psx_gpu, vertexes, vertex_ptrs))
render_triangle_p(psx_gpu, vertex_ptrs, flags);
prepared_triangle triangle;
if (prepare_triangle(psx_gpu, vertexes, &triangle))
render_triangle_p(psx_gpu, triangle.vertexes, flags);
}

#if !defined(NEON_BUILD) || defined(SIMD_BUILD)
Expand Down Expand Up @@ -5067,6 +5078,7 @@ void initialize_psx_gpu(psx_gpu_struct *psx_gpu, u16 *vram)
psx_gpu->dither_table[1] = dither_table_row(2, -2, 3, -1);
psx_gpu->dither_table[2] = dither_table_row(-3, 1, -4, 0);
psx_gpu->dither_table[3] = dither_table_row(3, -1, 2, -2);
psx_gpu->allow_dithering = 1;

psx_gpu->primitive_type = PRIMITIVE_TYPE_UNKNOWN;

Expand Down
12 changes: 11 additions & 1 deletion plugins/gpu_neon/psx_gpu/psx_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#define unlikely(x) __builtin_expect((x), 0)
#endif

#define sign_extend_11bit(value) \
(((s32)((value) << 21)) >> 21)

typedef enum
{
PRIMITIVE_TYPE_TRIANGLE = 0,
Expand Down Expand Up @@ -215,7 +218,7 @@ typedef struct

// Align up to 64 byte boundary to keep the upcoming buffers cache line
// aligned, also make reachable with single immediate addition
u8 reserved_a[184 + 8*4 - 9*sizeof(void *)];
u8 reserved_a[180 + 9*4 - 9*sizeof(void *)];

// 8KB
block_struct blocks[MAX_BLOCKS_PER_ROW];
Expand Down Expand Up @@ -247,6 +250,13 @@ typedef struct __attribute__((aligned(16)))
u32 padding;
} vertex_struct;

typedef struct
{
vertex_struct *vertexes[3];
s16 offset_x;
s16 offset_y;
} prepared_triangle;

void render_block_fill(psx_gpu_struct *psx_gpu, u32 color, u32 x, u32 y,
u32 width, u32 height);
void render_block_copy(psx_gpu_struct *psx_gpu, u16 *source, u32 x, u32 y,
Expand Down
6 changes: 6 additions & 0 deletions plugins/gpu_neon/psx_gpu/psx_gpu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "SDL.h"
#include "common.h"

#include "../../gpulib/gpu.h"
#include "psx_gpu.c"
#include "psx_gpu_parse.c"

#pragma GCC diagnostic ignored "-Wunused-result"

extern u32 span_pixels;
extern u32 span_pixel_blocks;
extern u32 spans;
Expand Down
Loading

0 comments on commit 9c11535

Please sign in to comment.