dc3144cf522a82ead1279a290bb55bb9ea440c43
[pcsx_rearmed.git] / libpcsxcore / database.c
1 #include "misc.h"
2 #include "sio.h"
3 #include "new_dynarec/new_dynarec.h"
4 #include "lightrec/plugin.h"
5
6 /* It's duplicated from emu_if.c */
7 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
8
9 /* Corresponds to LIGHTREC_OPT_INV_DMA_ONLY of lightrec.h */
10 #define LIGHTREC_HACK_INV_DMA_ONLY (1 << 0)
11
12 u32 lightrec_hacks;
13
14 static const char * const MemorycardHack_db[] =
15 {
16         /* Lifeforce Tenka, also known as Codename Tenka */
17         "SLES00613", "SLED00690", "SLES00614", "SLES00615",
18         "SLES00616", "SLES00617", "SCUS94409"
19 };
20
21 static const char * const cdr_read_hack_db[] =
22 {
23         /* T'ai Fu - Wrath of the Tiger */
24         "SLUS00787",
25 };
26
27 static 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
39 #define HACK_ENTRY(var, list) \
40         { #var, &Config.hacks.var, list, ARRAY_SIZE(list) }
41
42 static const struct
43 {
44         const char *name;
45         boolean *var;
46         const char * const * id_list;
47         size_t id_list_len;
48 }
49 hack_db[] =
50 {
51         HACK_ENTRY(cdr_read_timing, cdr_read_hack_db),
52         HACK_ENTRY(gpu_slow_list_walking, gpu_slow_llist_db),
53 };
54
55 static const struct
56 {
57         const char * const id;
58         int mult;
59 }
60 cycle_multiplier_overrides[] =
61 {
62         /* note: values are = (10000 / gui_option) */
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 },
69         /* Brave Fencer Musashi - cd sectors arrive too fast */
70         { "SLUS00726", 170 },
71         { "SLPS01490", 170 },
72 #if defined(DRC_DISABLE) || defined(LIGHTREC) /* new_dynarec has a hack for this game */
73         /* Parasite Eve II - internal timer checks */
74         { "SLUS01042", 125 },
75         { "SLUS01055", 125 },
76         { "SLES02558", 125 },
77         { "SLES12558", 125 },
78 #endif
79         /* Discworld Noir - audio skips if CPU runs too fast */
80         { "SLES01549", 222 },
81         { "SLES02063", 222 },
82         { "SLES02064", 222 },
83         /* Judge Dredd - could also be poor MDEC timing */
84         { "SLUS00630", 128 },
85         { "SLES00755", 128 },
86         /* Digimon World */
87         { "SLUS01032", 153 },
88         { "SLES02914", 153 },
89 };
90
91 static const struct
92 {
93         const char * const id;
94         u32 hacks;
95 }
96 lightrec_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
120 /* Function for automatic patching according to GameID. */
121 void Apply_Hacks_Cdrom()
122 {
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
139         /* Apply Memory card hack for Codename Tenka. (The game needs one of the memory card slots to be empty) */
140         for (i = 0; i < ARRAY_SIZE(MemorycardHack_db); i++)
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;
148                         break;
149                 }
150         }
151
152         /* Dynarec game-specific hacks */
153         new_dynarec_hacks_pergame = 0;
154         Config.cycle_multiplier_override = 0;
155
156         for (i = 0; i < ARRAY_SIZE(cycle_multiplier_overrides); i++)
157         {
158                 if (strcmp(CdromId, cycle_multiplier_overrides[i].id) == 0)
159                 {
160                         Config.cycle_multiplier_override = cycle_multiplier_overrides[i].mult;
161                         new_dynarec_hacks_pergame |= NDHACK_OVERRIDE_CYCLE_M;
162                         SysPrintf("using cycle_multiplier_override: %d\n",
163                                 Config.cycle_multiplier_override);
164                         break;
165                 }
166         }
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         }
178 }