libpcsxcore: Add database for Lightrec hacks
[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         /* 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 },
68         /* Brave Fencer Musashi - cd sectors arrive too fast */
69         { "SLUS00726", 170 },
70         { "SLPS01490", 170 },
71 #if defined(DRC_DISABLE) || defined(LIGHTREC) /* new_dynarec has a hack for this game */
72         /* Parasite Eve II - internal timer checks */
73         { "SLUS01042", 125 },
74         { "SLUS01055", 125 },
75         { "SLES02558", 125 },
76         { "SLES12558", 125 },
77 #endif
78         /* Discworld Noir - audio skips if CPU runs too fast */
79         { "SLES01549", 222 },
80         { "SLES02063", 222 },
81         { "SLES02064", 222 },
82 };
83
84 static const struct
85 {
86         const char * const id;
87         u32 hacks;
88 }
89 lightrec_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
113 /* Function for automatic patching according to GameID. */
114 void Apply_Hacks_Cdrom()
115 {
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
132         /* Apply Memory card hack for Codename Tenka. (The game needs one of the memory card slots to be empty) */
133         for (i = 0; i < ARRAY_SIZE(MemorycardHack_db); i++)
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;
141                         break;
142                 }
143         }
144
145         /* Dynarec game-specific hacks */
146         new_dynarec_hacks_pergame = 0;
147         Config.cycle_multiplier_override = 0;
148
149         for (i = 0; i < ARRAY_SIZE(cycle_multiplier_overrides); i++)
150         {
151                 if (strcmp(CdromId, cycle_multiplier_overrides[i].id) == 0)
152                 {
153                         Config.cycle_multiplier_override = cycle_multiplier_overrides[i].mult;
154                         new_dynarec_hacks_pergame |= NDHACK_OVERRIDE_CYCLE_M;
155                         SysPrintf("using cycle_multiplier_override: %d\n",
156                                 Config.cycle_multiplier_override);
157                         break;
158                 }
159         }
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         }
171 }