ScummVM API documentation
ROMInfo.h
1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2022 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_ROMINFO_H
19 #define MT32EMU_ROMINFO_H
20 
21 #include <cstddef>
22 
23 #include "globals.h"
24 #include "File.h"
25 
26 namespace MT32Emu {
27 
28 // Defines vital info about ROM file to be used by synth and applications
29 
30 struct ROMInfo {
31 public:
32  size_t fileSize;
33  const File::SHA1Digest &sha1Digest;
34  enum Type {PCM, Control, Reverb} type;
35  const char *shortName;
36  const char *description;
37  enum PairType {
38  // Complete ROM image ready to use with Synth.
39  Full,
40  // ROM image contains data that occupies lower addresses. Needs pairing before use.
41  FirstHalf,
42  // ROM image contains data that occupies higher addresses. Needs pairing before use.
43  SecondHalf,
44  // ROM image contains data that occupies even addresses. Needs pairing before use.
45  Mux0,
46  // ROM image contains data that occupies odd addresses. Needs pairing before use.
47  Mux1
48  } pairType;
49  // NULL for Full images or a pointer to the corresponding other image for pairing.
50  const ROMInfo *pairROMInfo;
51 
52  // Returns a ROMInfo struct by inspecting the size and the SHA1 hash of the file
53  // among all the known ROMInfos.
54  MT32EMU_EXPORT static const ROMInfo *getROMInfo(File *file);
55 
56  // Returns a ROMInfo struct by inspecting the size and the SHA1 hash of the file
57  // among the ROMInfos listed in the NULL-terminated list romInfos.
58  MT32EMU_EXPORT_V(2.5) static const ROMInfo *getROMInfo(File *file, const ROMInfo * const *romInfos);
59 
60  // Currently no-op
61  MT32EMU_EXPORT static void freeROMInfo(const ROMInfo *romInfo);
62 
63  // Allows retrieving a NULL-terminated list of ROMInfos for a range of types and pairTypes
64  // (specified by bitmasks)
65  // Useful for GUI/console app to output information on what ROMs it supports
66  // The caller must free the returned list with freeROMInfoList when finished.
67  MT32EMU_EXPORT static const ROMInfo **getROMInfoList(Bit32u types, Bit32u pairTypes);
68 
69  // Frees the list of ROMInfos given that has been created by getROMInfoList.
70  MT32EMU_EXPORT static void freeROMInfoList(const ROMInfo **romInfos);
71 
72  // Returns an immutable NULL-terminated list of all (full and partial) supported ROMInfos.
73  // For convenience, this method also can fill the number of non-NULL items present in the list
74  // if a non-NULL value is provided in optional argument itemCount.
75  MT32EMU_EXPORT_V(2.5) static const ROMInfo * const *getAllROMInfos(Bit32u *itemCount = NULL);
76  // Returns an immutable NULL-terminated list of all supported full ROMInfos.
77  // For convenience, this method also can fill the number of non-NULL items present in the list
78  // if a non-NULL value is provided in optional argument itemCount.
79  MT32EMU_EXPORT_V(2.5) static const ROMInfo * const *getFullROMInfos(Bit32u *itemCount = NULL);
80  // Returns an immutable NULL-terminated list of all supported partial ROMInfos.
81  // For convenience, this method also can fill the number of non-NULL items present in the list
82  // if a non-NULL value is provided in optional argument itemCount.
83  MT32EMU_EXPORT_V(2.5) static const ROMInfo * const *getPartialROMInfos(Bit32u *itemCount = NULL);
84 };
85 
86 // Synth::open() requires a full control ROMImage and a compatible full PCM ROMImage to work
87 
88 class ROMImage {
89 public:
90  // Creates a ROMImage object given a ROMInfo and a File. Keeps a reference
91  // to the File and ROMInfo given, which must be freed separately by the user
92  // after the ROMImage is freed.
93  // CAVEAT: This method always prefers full ROM images over partial ones.
94  // Because the lower half of CM-32L/CM-64/LAPC-I PCM ROM is essentially the full
95  // MT-32 PCM ROM, it is therefore aliased. In this case a partial image can only be
96  // created by the overridden method makeROMImage(File *, const ROMInfo * const *).
97  MT32EMU_EXPORT static const ROMImage *makeROMImage(File *file);
98 
99  // Same as the method above but only permits creation of a ROMImage if the file content
100  // matches one of the ROMs described in a NULL-terminated list romInfos. This list can be
101  // created using e.g. method ROMInfo::getROMInfoList.
102  MT32EMU_EXPORT_V(2.5) static const ROMImage *makeROMImage(File *file, const ROMInfo * const *romInfos);
103 
104  // Creates a ROMImage object given a couple of files that contain compatible partial ROM images.
105  // The files aren't referenced by the resulting ROMImage and may be freed anytime afterwards.
106  // The file in the resulting image will be automatically freed along with the ROMImage.
107  // If the given files contain incompatible partial images, NULL is returned.
108  MT32EMU_EXPORT_V(2.5) static const ROMImage *makeROMImage(File *file1, File *file2);
109 
110  // Must only be done after all Synths using the ROMImage are deleted
111  MT32EMU_EXPORT static void freeROMImage(const ROMImage *romImage);
112 
113  // Checks whether the given ROMImages are pairable and merges them into a full image, if possible.
114  // If the check fails, NULL is returned.
115  MT32EMU_EXPORT_V(2.5) static const ROMImage *mergeROMImages(const ROMImage *romImage1, const ROMImage *romImage2);
116 
117  MT32EMU_EXPORT File *getFile() const;
118 
119  // Returns true in case this ROMImage is built with a user provided File that has to be deallocated separately.
120  // For a ROMImage created via merging two partial ROMImages, this method returns false.
121  MT32EMU_EXPORT_V(2.5) bool isFileUserProvided() const;
122  MT32EMU_EXPORT const ROMInfo *getROMInfo() const;
123 
124 private:
125  static const ROMImage *makeFullROMImage(Bit8u *data, size_t dataSize);
126  static const ROMImage *appendImages(const ROMImage *romImageLow, const ROMImage *romImageHigh);
127  static const ROMImage *interleaveImages(const ROMImage *romImageEven, const ROMImage *romImageOdd);
128 
129  File * const file;
130  const bool ownFile;
131  const ROMInfo * const romInfo;
132 
133  ROMImage(File *file, bool ownFile, const ROMInfo * const *romInfos);
134  ~ROMImage();
135 
136  // Make ROMIMage an identity class.
137  ROMImage(const ROMImage &);
138  ROMImage &operator=(const ROMImage &);
139 };
140 
142 public:
143  // Returns an immutable NULL-terminated list of all supported machine configurations.
144  // For convenience, this method also can fill the number of non-NULL items present in the list
145  // if a non-NULL value is provided in optional argument itemCount.
146  MT32EMU_EXPORT_V(2.5) static const MachineConfiguration * const *getAllMachineConfigurations(Bit32u *itemCount = NULL);
147 
148  // Returns a string identifier of this MachineConfiguration.
149  MT32EMU_EXPORT_V(2.5) const char *getMachineID() const;
150 
151  // Returns an immutable NULL-terminated list of ROMInfos that are compatible with this
152  // MachineConfiguration. That means the respective ROMImages can be successfully used together
153  // by the emulation engine. Calling ROMInfo::getROMInfo or ROMImage::makeROMImage with this list
154  // supplied enables identification of all files containing desired ROM images while filtering out
155  // any incompatible ones.
156  // For convenience, this method also can fill the number of non-NULL items present in the list
157  // if a non-NULL value is provided in optional argument itemCount.
158  MT32EMU_EXPORT_V(2.5) const ROMInfo * const *getCompatibleROMInfos(Bit32u *itemCount = NULL) const;
159 
160 private:
161  const char * const machineID;
162  const ROMInfo * const * const romInfos;
163  const Bit32u romInfosCount;
164 
165  MachineConfiguration(const char *machineID, const ROMInfo * const *romInfos, Bit32u romInfosCount);
166 
167  // Make MachineConfiguration an identity class.
170  MachineConfiguration &operator=(const MachineConfiguration &);
171 };
172 
173 } // namespace MT32Emu
174 
175 #endif // #ifndef MT32EMU_ROMINFO_H
Definition: Analog.h:26
Definition: ROMInfo.h:141
Definition: ROMInfo.h:88
Definition: File.h:28
Definition: ROMInfo.h:30