update libpicofe
[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{
fe564285
WVP
29 /* Bomberman Fantasy Race */
30 "SLES01712", "SLPS01525", "SLPS91138", "SLPM87102", "SLUS00823",
fae38d7a 31 /* Crash Bash */
32 "SCES02834", "SCUS94570", "SCUS94616", "SCUS94654",
33 /* Final Fantasy IV */
34 "SCES03840", "SLPM86028", "SLUS01360",
35 /* Spot Goes to Hollywood */
36 "SLES00330", "SLPS00394", "SLUS00014",
37 /* Vampire Hunter D */
38 "SLES02731", "SLPS02477", "SLPS03198", "SLUS01138",
39};
40
55ff7130 41static const char * const gpu_busy_hack_db[] =
42{
43 /* ToHeart (Japan) */
44 "SLPS01919", "SLPS01920",
45};
46
d0d2939d 47#define HACK_ENTRY(var, list) \
48 { #var, &Config.hacks.var, list, ARRAY_SIZE(list) }
49
50static const struct
51{
52 const char *name;
53 boolean *var;
54 const char * const * id_list;
55 size_t id_list_len;
56}
57hack_db[] =
58{
59 HACK_ENTRY(cdr_read_timing, cdr_read_hack_db),
fae38d7a 60 HACK_ENTRY(gpu_slow_list_walking, gpu_slow_llist_db),
55ff7130 61 HACK_ENTRY(gpu_busy_hack, gpu_busy_hack_db),
630b122b 62};
63
d7907215 64static const struct
65{
66 const char * const id;
67 int mult;
68}
1562ed57 69cycle_multiplier_overrides[] =
d7907215 70{
9170c48e 71 /* note: values are = (10000 / gui_option) */
d7907215 72 /* Internal Section - fussy about timings */
73 { "SLPS01868", 202 },
74 /* Super Robot Taisen Alpha - on the edge with 175,
75 * changing memcard settings is enough to break/unbreak it */
76 { "SLPS02528", 190 },
77 { "SLPS02636", 190 },
b8f3d43d 78 /* Brave Fencer Musashi - cd sectors arrive too fast */
79 { "SLUS00726", 170 },
80 { "SLPS01490", 170 },
86be2515 81#if defined(DRC_DISABLE) || defined(LIGHTREC) /* new_dynarec has a hack for this game */
1562ed57 82 /* Parasite Eve II - internal timer checks */
83 { "SLUS01042", 125 },
84 { "SLUS01055", 125 },
85 { "SLES02558", 125 },
86 { "SLES12558", 125 },
87#endif
b99a48f2 88 /* Discworld Noir - audio skips if CPU runs too fast */
89 { "SLES01549", 222 },
90 { "SLES02063", 222 },
91 { "SLES02064", 222 },
9170c48e 92 /* Judge Dredd - could also be poor MDEC timing */
93 { "SLUS00630", 128 },
94 { "SLES00755", 128 },
95 /* Digimon World */
96 { "SLUS01032", 153 },
97 { "SLES02914", 153 },
d7907215 98};
99
8bccdd17
PC
100static const struct
101{
102 const char * const id;
103 u32 hacks;
104}
105lightrec_hacks_db[] =
106{
107 /* Formula One Arcade */
108 { "SCES03886", LIGHTREC_HACK_INV_DMA_ONLY },
109
110 /* Formula One '99 */
111 { "SLUS00870", LIGHTREC_HACK_INV_DMA_ONLY },
112 { "SCPS10101", LIGHTREC_HACK_INV_DMA_ONLY },
113 { "SCES01979", LIGHTREC_HACK_INV_DMA_ONLY },
114 { "SLES01979", LIGHTREC_HACK_INV_DMA_ONLY },
115
116 /* Formula One 2000 */
117 { "SLUS01134", LIGHTREC_HACK_INV_DMA_ONLY },
118 { "SCES02777", LIGHTREC_HACK_INV_DMA_ONLY },
119 { "SCES02778", LIGHTREC_HACK_INV_DMA_ONLY },
120 { "SCES02779", LIGHTREC_HACK_INV_DMA_ONLY },
121
122 /* Formula One 2001 */
123 { "SCES03404", LIGHTREC_HACK_INV_DMA_ONLY },
124 { "SCES03423", LIGHTREC_HACK_INV_DMA_ONLY },
125 { "SCES03424", LIGHTREC_HACK_INV_DMA_ONLY },
126 { "SCES03524", LIGHTREC_HACK_INV_DMA_ONLY },
127};
128
630b122b 129/* Function for automatic patching according to GameID. */
130void Apply_Hacks_Cdrom()
131{
d0d2939d 132 size_t i, j;
133
134 memset(&Config.hacks, 0, sizeof(Config.hacks));
135
136 for (i = 0; i < ARRAY_SIZE(hack_db); i++)
137 {
138 for (j = 0; j < hack_db[i].id_list_len; j++)
139 {
140 if (strncmp(CdromId, hack_db[i].id_list[j], 9))
141 continue;
142 *hack_db[i].var = 1;
143 SysPrintf("using hack: %s\n", hack_db[i].name);
144 break;
145 }
146 }
147
630b122b 148 /* Apply Memory card hack for Codename Tenka. (The game needs one of the memory card slots to be empty) */
d0d2939d 149 for (i = 0; i < ARRAY_SIZE(MemorycardHack_db); i++)
630b122b 150 {
151 if (strncmp(CdromId, MemorycardHack_db[i], 9) == 0)
152 {
153 /* Disable the second memory card slot for the game */
154 Config.Mcd2[0] = 0;
155 /* This also needs to be done because in sio.c, they don't use Config.Mcd2 for that purpose */
156 McdDisable[1] = 1;
d0d2939d 157 break;
630b122b 158 }
159 }
160
161 /* Dynarec game-specific hacks */
162 new_dynarec_hacks_pergame = 0;
1562ed57 163 Config.cycle_multiplier_override = 0;
630b122b 164
1562ed57 165 for (i = 0; i < ARRAY_SIZE(cycle_multiplier_overrides); i++)
630b122b 166 {
1562ed57 167 if (strcmp(CdromId, cycle_multiplier_overrides[i].id) == 0)
d7907215 168 {
1562ed57 169 Config.cycle_multiplier_override = cycle_multiplier_overrides[i].mult;
d7907215 170 new_dynarec_hacks_pergame |= NDHACK_OVERRIDE_CYCLE_M;
1562ed57 171 SysPrintf("using cycle_multiplier_override: %d\n",
172 Config.cycle_multiplier_override);
d7907215 173 break;
174 }
630b122b 175 }
8bccdd17
PC
176
177 lightrec_hacks = 0;
178
179 for (i = 0; drc_is_lightrec() && i < ARRAY_SIZE(lightrec_hacks_db); i++) {
180 if (strcmp(CdromId, lightrec_hacks_db[i].id) == 0)
181 {
182 lightrec_hacks = lightrec_hacks_db[i].hacks;
183 SysPrintf("using lightrec_hacks: 0x%x\n", lightrec_hacks);
184 break;
185 }
186 }
630b122b 187}