unai: Fix scalers doing endianness conversion
[pcsx_rearmed.git] / libpcsxcore / database.c
CommitLineData
630b122b 1#include "misc.h"
2#include "sio.h"
3#include "new_dynarec/new_dynarec.h"
8bccdd17 4#include "lightrec/plugin.h"
630b122b 5
6/* It's duplicated from emu_if.c */
7#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
8
8bccdd17
PC
9/* Corresponds to LIGHTREC_OPT_INV_DMA_ONLY of lightrec.h */
10#define LIGHTREC_HACK_INV_DMA_ONLY (1 << 0)
11
12u32 lightrec_hacks;
13
d0d2939d 14static const char * const MemorycardHack_db[] =
630b122b 15{
16 /* Lifeforce Tenka, also known as Codename Tenka */
d0d2939d 17 "SLES00613", "SLED00690", "SLES00614", "SLES00615",
18 "SLES00616", "SLES00617", "SCUS94409"
19};
20
21static const char * const cdr_read_hack_db[] =
22{
23 /* T'ai Fu - Wrath of the Tiger */
24 "SLUS00787",
25};
26
fae38d7a 27static const char * const gpu_slow_llist_db[] =
28{
29 /* Crash Bash */
30 "SCES02834", "SCUS94570", "SCUS94616", "SCUS94654",
31 /* Final Fantasy IV */
32 "SCES03840", "SLPM86028", "SLUS01360",
33 /* Spot Goes to Hollywood */
34 "SLES00330", "SLPS00394", "SLUS00014",
35 /* Vampire Hunter D */
36 "SLES02731", "SLPS02477", "SLPS03198", "SLUS01138",
37};
38
d0d2939d 39#define HACK_ENTRY(var, list) \
40 { #var, &Config.hacks.var, list, ARRAY_SIZE(list) }
41
42static const struct
43{
44 const char *name;
45 boolean *var;
46 const char * const * id_list;
47 size_t id_list_len;
48}
49hack_db[] =
50{
51 HACK_ENTRY(cdr_read_timing, cdr_read_hack_db),
fae38d7a 52 HACK_ENTRY(gpu_slow_list_walking, gpu_slow_llist_db),
630b122b 53};
54
d7907215 55static const struct
56{
57 const char * const id;
58 int mult;
59}
1562ed57 60cycle_multiplier_overrides[] =
d7907215 61{
62 /* Internal Section - fussy about timings */
63 { "SLPS01868", 202 },
64 /* Super Robot Taisen Alpha - on the edge with 175,
65 * changing memcard settings is enough to break/unbreak it */
66 { "SLPS02528", 190 },
67 { "SLPS02636", 190 },
b8f3d43d 68 /* Brave Fencer Musashi - cd sectors arrive too fast */
69 { "SLUS00726", 170 },
70 { "SLPS01490", 170 },
86be2515 71#if defined(DRC_DISABLE) || defined(LIGHTREC) /* new_dynarec has a hack for this game */
1562ed57 72 /* Parasite Eve II - internal timer checks */
73 { "SLUS01042", 125 },
74 { "SLUS01055", 125 },
75 { "SLES02558", 125 },
76 { "SLES12558", 125 },
77#endif
b99a48f2 78 /* Discworld Noir - audio skips if CPU runs too fast */
79 { "SLES01549", 222 },
80 { "SLES02063", 222 },
81 { "SLES02064", 222 },
d7907215 82};
83
8bccdd17
PC
84static const struct
85{
86 const char * const id;
87 u32 hacks;
88}
89lightrec_hacks_db[] =
90{
91 /* Formula One Arcade */
92 { "SCES03886", LIGHTREC_HACK_INV_DMA_ONLY },
93
94 /* Formula One '99 */
95 { "SLUS00870", LIGHTREC_HACK_INV_DMA_ONLY },
96 { "SCPS10101", LIGHTREC_HACK_INV_DMA_ONLY },
97 { "SCES01979", LIGHTREC_HACK_INV_DMA_ONLY },
98 { "SLES01979", LIGHTREC_HACK_INV_DMA_ONLY },
99
100 /* Formula One 2000 */
101 { "SLUS01134", LIGHTREC_HACK_INV_DMA_ONLY },
102 { "SCES02777", LIGHTREC_HACK_INV_DMA_ONLY },
103 { "SCES02778", LIGHTREC_HACK_INV_DMA_ONLY },
104 { "SCES02779", LIGHTREC_HACK_INV_DMA_ONLY },
105
106 /* Formula One 2001 */
107 { "SCES03404", LIGHTREC_HACK_INV_DMA_ONLY },
108 { "SCES03423", LIGHTREC_HACK_INV_DMA_ONLY },
109 { "SCES03424", LIGHTREC_HACK_INV_DMA_ONLY },
110 { "SCES03524", LIGHTREC_HACK_INV_DMA_ONLY },
111};
112
630b122b 113/* Function for automatic patching according to GameID. */
114void Apply_Hacks_Cdrom()
115{
d0d2939d 116 size_t i, j;
117
118 memset(&Config.hacks, 0, sizeof(Config.hacks));
119
120 for (i = 0; i < ARRAY_SIZE(hack_db); i++)
121 {
122 for (j = 0; j < hack_db[i].id_list_len; j++)
123 {
124 if (strncmp(CdromId, hack_db[i].id_list[j], 9))
125 continue;
126 *hack_db[i].var = 1;
127 SysPrintf("using hack: %s\n", hack_db[i].name);
128 break;
129 }
130 }
131
630b122b 132 /* Apply Memory card hack for Codename Tenka. (The game needs one of the memory card slots to be empty) */
d0d2939d 133 for (i = 0; i < ARRAY_SIZE(MemorycardHack_db); i++)
630b122b 134 {
135 if (strncmp(CdromId, MemorycardHack_db[i], 9) == 0)
136 {
137 /* Disable the second memory card slot for the game */
138 Config.Mcd2[0] = 0;
139 /* This also needs to be done because in sio.c, they don't use Config.Mcd2 for that purpose */
140 McdDisable[1] = 1;
d0d2939d 141 break;
630b122b 142 }
143 }
144
145 /* Dynarec game-specific hacks */
146 new_dynarec_hacks_pergame = 0;
1562ed57 147 Config.cycle_multiplier_override = 0;
630b122b 148
1562ed57 149 for (i = 0; i < ARRAY_SIZE(cycle_multiplier_overrides); i++)
630b122b 150 {
1562ed57 151 if (strcmp(CdromId, cycle_multiplier_overrides[i].id) == 0)
d7907215 152 {
1562ed57 153 Config.cycle_multiplier_override = cycle_multiplier_overrides[i].mult;
d7907215 154 new_dynarec_hacks_pergame |= NDHACK_OVERRIDE_CYCLE_M;
1562ed57 155 SysPrintf("using cycle_multiplier_override: %d\n",
156 Config.cycle_multiplier_override);
d7907215 157 break;
158 }
630b122b 159 }
8bccdd17
PC
160
161 lightrec_hacks = 0;
162
163 for (i = 0; drc_is_lightrec() && i < ARRAY_SIZE(lightrec_hacks_db); i++) {
164 if (strcmp(CdromId, lightrec_hacks_db[i].id) == 0)
165 {
166 lightrec_hacks = lightrec_hacks_db[i].hacks;
167 SysPrintf("using lightrec_hacks: 0x%x\n", lightrec_hacks);
168 break;
169 }
170 }
630b122b 171}