1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | * Mupen64plus - rom.h * |
3 | * Mupen64Plus homepage: https://mupen64plus.org/ * |
4 | * Copyright (C) 2008 Tillin9 * |
5 | * Copyright (C) 2002 Hacktarux * |
6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * |
11 | * * |
12 | * This program is distributed in the hope that it will be useful, * |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 | * GNU General Public License for more details. * |
16 | * * |
17 | * You should have received a copy of the GNU General Public License * |
18 | * along with this program; if not, write to the * |
19 | * Free Software Foundation, Inc., * |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
22 | |
23 | #ifndef __ROM_H__ |
24 | #define __ROM_H__ |
25 | |
26 | #include <md5.h> |
27 | #include <stdint.h> |
28 | |
29 | #include "api/m64p_types.h" |
30 | |
31 | #define BIT(bitnr) (1ULL << (bitnr)) |
32 | #ifdef __GNUC__ |
33 | #define isset_bitmask(x, bitmask) __extension__ ({ __typeof__(bitmask) _bitmask = (bitmask); \ |
34 | (_bitmask & (x)) == _bitmask; }) |
35 | #else |
36 | #define isset_bitmask(x, bitmask) ((bitmask & (x)) == bitmask) |
37 | #endif |
38 | |
39 | /* ROM Loading and Saving functions */ |
40 | |
41 | m64p_error open_rom(const unsigned char* romimage, unsigned int size); |
42 | m64p_error close_rom(void); |
43 | |
44 | extern int g_rom_size; |
45 | |
46 | typedef struct _rom_params |
47 | { |
48 | char *cheats; |
49 | m64p_system_type systemtype; |
50 | char [21]; /* ROM Name as in the header, removing trailing whitespace */ |
51 | unsigned char countperop; |
52 | int ; |
53 | unsigned int sidmaduration; |
54 | } rom_params; |
55 | |
56 | extern m64p_rom_header ; |
57 | extern rom_params ROM_PARAMS; |
58 | extern m64p_rom_settings ROM_SETTINGS; |
59 | |
60 | /* Supported rom compressiontypes. */ |
61 | enum |
62 | { |
63 | UNCOMPRESSED, |
64 | ZIP_COMPRESSION, |
65 | GZIP_COMPRESSION, |
66 | BZIP2_COMPRESSION, |
67 | LZMA_COMPRESSION, |
68 | SZIP_COMPRESSION |
69 | }; |
70 | |
71 | /* Supported rom image types. */ |
72 | enum |
73 | { |
74 | Z64IMAGE, |
75 | V64IMAGE, |
76 | N64IMAGE |
77 | }; |
78 | |
79 | /* Supported CIC chips. */ |
80 | enum |
81 | { |
82 | CIC_NUS_6101, |
83 | CIC_NUS_6102, |
84 | CIC_NUS_6103, |
85 | CIC_NUS_6105, |
86 | CIC_NUS_6106 |
87 | }; |
88 | |
89 | /* Supported save types. */ |
90 | enum |
91 | { |
92 | EEPROM_4KB, |
93 | EEPROM_16KB, |
94 | SRAM, |
95 | FLASH_RAM, |
96 | CONTROLLER_PACK, |
97 | NONE |
98 | }; |
99 | |
100 | /* Rom INI database structures and functions */ |
101 | |
102 | /* The romdatabase contains the items mupen64plus indexes for each rom. These |
103 | * include the goodname (from the GoodN64 project), the current status of the rom |
104 | * in mupen, the N64 savetype used in the original cartridge (often necessary for |
105 | * booting the rom in mupen), the number of players (including netplay options), |
106 | * and whether the rom can make use of the N64's rumble feature. Md5, crc1, and |
107 | * crc2 used for rom lookup. Md5s are unique hashes of the ENTIRE rom. Crcs are not |
108 | * unique and read from the rom header, meaning corrupt crcs are also a problem. |
109 | * Crcs were widely used (mainly in the cheat system). Refmd5s allows for a smaller |
110 | * database file and need not be used outside database loading. |
111 | */ |
112 | typedef struct |
113 | { |
114 | char* goodname; |
115 | md5_byte_t md5[16]; |
116 | md5_byte_t* refmd5; |
117 | char *cheats; |
118 | unsigned int crc1; |
119 | unsigned int crc2; |
120 | unsigned char status; /* Rom status on a scale from 0-5. */ |
121 | unsigned char savetype; |
122 | unsigned char players; /* Local players 0-4, 2/3/4 way Netplay indicated by 5/6/7. */ |
123 | unsigned char rumble; /* 0 - No, 1 - Yes boolean for rumble support. */ |
124 | unsigned char countperop; |
125 | unsigned char ; |
126 | unsigned char transferpak; /* 0 - No, 1 - Yes boolean for transferpak support. */ |
127 | unsigned char mempak; /* 0 - No, 1 - Yes boolean for mempak support. */ |
128 | unsigned char biopak; /* 0 - No, 1 - Yes boolean for biopak support. */ |
129 | unsigned int sidmaduration; |
130 | uint32_t set_flags; |
131 | } romdatabase_entry; |
132 | |
133 | #define ROMDATABASE_ENTRY_NONE 0ULL |
134 | #define ROMDATABASE_ENTRY_GOODNAME BIT(0) |
135 | #define ROMDATABASE_ENTRY_CRC BIT(1) |
136 | #define ROMDATABASE_ENTRY_STATUS BIT(2) |
137 | #define ROMDATABASE_ENTRY_SAVETYPE BIT(3) |
138 | #define ROMDATABASE_ENTRY_PLAYERS BIT(4) |
139 | #define ROMDATABASE_ENTRY_RUMBLE BIT(5) |
140 | #define ROMDATABASE_ENTRY_COUNTEROP BIT(6) |
141 | #define ROMDATABASE_ENTRY_CHEATS BIT(7) |
142 | #define BIT(8) |
143 | #define ROMDATABASE_ENTRY_TRANSFERPAK BIT(9) |
144 | #define ROMDATABASE_ENTRY_MEMPAK BIT(10) |
145 | #define ROMDATABASE_ENTRY_BIOPAK BIT(11) |
146 | #define ROMDATABASE_ENTRY_SIDMADURATION BIT(12) |
147 | |
148 | typedef struct _romdatabase_search |
149 | { |
150 | romdatabase_entry entry; |
151 | struct _romdatabase_search* next_entry; |
152 | struct _romdatabase_search* next_crc; |
153 | struct _romdatabase_search* next_md5; |
154 | } romdatabase_search; |
155 | |
156 | typedef struct |
157 | { |
158 | int have_database; |
159 | romdatabase_search* crc_lists[256]; |
160 | romdatabase_search* md5_lists[256]; |
161 | romdatabase_search* list; |
162 | } _romdatabase; |
163 | |
164 | void romdatabase_open(void); |
165 | void romdatabase_close(void); |
166 | /* Should be used by current cheat system (isn't), when cheat system is |
167 | * migrated to md5s, will be fully depreciated. |
168 | */ |
169 | romdatabase_entry* ini_search_by_crc(unsigned int crc1, unsigned int crc2); |
170 | |
171 | #endif /* __ROM_H__ */ |
172 | |
173 | |