psxbios: don't limit pointers to ram
[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{
9170c48e 62 /* note: values are = (10000 / gui_option) */
d7907215 63 /* Internal Section - fussy about timings */
64 { "SLPS01868", 202 },
65 /* Super Robot Taisen Alpha - on the edge with 175,
66 * changing memcard settings is enough to break/unbreak it */
67 { "SLPS02528", 190 },
68 { "SLPS02636", 190 },
b8f3d43d 69 /* Brave Fencer Musashi - cd sectors arrive too fast */
70 { "SLUS00726", 170 },
71 { "SLPS01490", 170 },
86be2515 72#if defined(DRC_DISABLE) || defined(LIGHTREC) /* new_dynarec has a hack for this game */
1562ed57 73 /* Parasite Eve II - internal timer checks */
74 { "SLUS01042", 125 },
75 { "SLUS01055", 125 },
76 { "SLES02558", 125 },
77 { "SLES12558", 125 },
78#endif
b99a48f2 79 /* Discworld Noir - audio skips if CPU runs too fast */
80 { "SLES01549", 222 },
81 { "SLES02063", 222 },
82 { "SLES02064", 222 },
9170c48e 83 /* Judge Dredd - could also be poor MDEC timing */
84 { "SLUS00630", 128 },
85 { "SLES00755", 128 },
86 /* Digimon World */
87 { "SLUS01032", 153 },
88 { "SLES02914", 153 },
d7907215 89};
90
8bccdd17
PC
91static const struct
92{
93 const char * const id;
94 u32 hacks;
95}
96lightrec_hacks_db[] =
97{
98 /* Formula One Arcade */
99 { "SCES03886", LIGHTREC_HACK_INV_DMA_ONLY },
100
101 /* Formula One '99 */
102 { "SLUS00870", LIGHTREC_HACK_INV_DMA_ONLY },
103 { "SCPS10101", LIGHTREC_HACK_INV_DMA_ONLY },
104 { "SCES01979", LIGHTREC_HACK_INV_DMA_ONLY },
105 { "SLES01979", LIGHTREC_HACK_INV_DMA_ONLY },
106
107 /* Formula One 2000 */
108 { "SLUS01134", LIGHTREC_HACK_INV_DMA_ONLY },
109 { "SCES02777", LIGHTREC_HACK_INV_DMA_ONLY },
110 { "SCES02778", LIGHTREC_HACK_INV_DMA_ONLY },
111 { "SCES02779", LIGHTREC_HACK_INV_DMA_ONLY },
112
113 /* Formula One 2001 */
114 { "SCES03404", LIGHTREC_HACK_INV_DMA_ONLY },
115 { "SCES03423", LIGHTREC_HACK_INV_DMA_ONLY },
116 { "SCES03424", LIGHTREC_HACK_INV_DMA_ONLY },
117 { "SCES03524", LIGHTREC_HACK_INV_DMA_ONLY },
118};
119
630b122b 120/* Function for automatic patching according to GameID. */
121void Apply_Hacks_Cdrom()
122{
d0d2939d 123 size_t i, j;
124
125 memset(&Config.hacks, 0, sizeof(Config.hacks));
126
127 for (i = 0; i < ARRAY_SIZE(hack_db); i++)
128 {
129 for (j = 0; j < hack_db[i].id_list_len; j++)
130 {
131 if (strncmp(CdromId, hack_db[i].id_list[j], 9))
132 continue;
133 *hack_db[i].var = 1;
134 SysPrintf("using hack: %s\n", hack_db[i].name);
135 break;
136 }
137 }
138
630b122b 139 /* Apply Memory card hack for Codename Tenka. (The game needs one of the memory card slots to be empty) */
d0d2939d 140 for (i = 0; i < ARRAY_SIZE(MemorycardHack_db); i++)
630b122b 141 {
142 if (strncmp(CdromId, MemorycardHack_db[i], 9) == 0)
143 {
144 /* Disable the second memory card slot for the game */
145 Config.Mcd2[0] = 0;
146 /* This also needs to be done because in sio.c, they don't use Config.Mcd2 for that purpose */
147 McdDisable[1] = 1;
d0d2939d 148 break;
630b122b 149 }
150 }
151
152 /* Dynarec game-specific hacks */
153 new_dynarec_hacks_pergame = 0;
1562ed57 154 Config.cycle_multiplier_override = 0;
630b122b 155
1562ed57 156 for (i = 0; i < ARRAY_SIZE(cycle_multiplier_overrides); i++)
630b122b 157 {
1562ed57 158 if (strcmp(CdromId, cycle_multiplier_overrides[i].id) == 0)
d7907215 159 {
1562ed57 160 Config.cycle_multiplier_override = cycle_multiplier_overrides[i].mult;
d7907215 161 new_dynarec_hacks_pergame |= NDHACK_OVERRIDE_CYCLE_M;
1562ed57 162 SysPrintf("using cycle_multiplier_override: %d\n",
163 Config.cycle_multiplier_override);
d7907215 164 break;
165 }
630b122b 166 }
8bccdd17
PC
167
168 lightrec_hacks = 0;
169
170 for (i = 0; drc_is_lightrec() && i < ARRAY_SIZE(lightrec_hacks_db); i++) {
171 if (strcmp(CdromId, lightrec_hacks_db[i].id) == 0)
172 {
173 lightrec_hacks = lightrec_hacks_db[i].hacks;
174 SysPrintf("using lightrec_hacks: 0x%x\n", lightrec_hacks);
175 break;
176 }
177 }
630b122b 178}