DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/ROMInfo.cpp
00001 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
00002  * Copyright (C) 2011, 2012, 2013 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
00003  *
00004  *  This program is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 2.1 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <cstring>
00019 #include "ROMInfo.h"
00020 
00021 namespace MT32Emu {
00022 
00023 // Known ROMs
00024 static const ROMInfo CTRL_MT32_V1_04 = {65536, "5a5cb5a77d7d55ee69657c2f870416daed52dea7", ROMInfo::Control, "ctrl_mt32_1_04", "MT-32 Control v1.04", ROMInfo::Full, NULL, NULL};
00025 static const ROMInfo CTRL_MT32_V1_05 = {65536, "e17a3a6d265bf1fa150312061134293d2b58288c", ROMInfo::Control, "ctrl_mt32_1_05", "MT-32 Control v1.05", ROMInfo::Full, NULL, NULL};
00026 static const ROMInfo CTRL_MT32_V1_06 = {65536, "a553481f4e2794c10cfe597fef154eef0d8257de", ROMInfo::Control, "ctrl_mt32_1_06", "MT-32 Control v1.06", ROMInfo::Full, NULL, NULL};
00027 static const ROMInfo CTRL_MT32_V1_07 = {65536, "b083518fffb7f66b03c23b7eb4f868e62dc5a987", ROMInfo::Control, "ctrl_mt32_1_07", "MT-32 Control v1.07", ROMInfo::Full, NULL, NULL};
00028 static const ROMInfo CTRL_MT32_BLUER = {65536, "7b8c2a5ddb42fd0732e2f22b3340dcf5360edf92", ROMInfo::Control, "ctrl_mt32_bluer", "MT-32 Control BlueRidge", ROMInfo::Full, NULL, NULL};
00029 
00030 static const ROMInfo CTRL_CM32L_V1_00 = {65536, "73683d585cd6948cc19547942ca0e14a0319456d", ROMInfo::Control, "ctrl_cm32l_1_00", "CM-32L/LAPC-I Control v1.00", ROMInfo::Full, NULL, NULL};
00031 static const ROMInfo CTRL_CM32L_V1_02 = {65536, "a439fbb390da38cada95a7cbb1d6ca199cd66ef8", ROMInfo::Control, "ctrl_cm32l_1_02", "CM-32L/LAPC-I Control v1.02", ROMInfo::Full, NULL, NULL};
00032 
00033 static const ROMInfo PCM_MT32 = {524288, "f6b1eebc4b2d200ec6d3d21d51325d5b48c60252", ROMInfo::PCM, "pcm_mt32", "MT-32 PCM ROM", ROMInfo::Full, NULL, NULL};
00034 static const ROMInfo PCM_CM32L = {1048576, "289cc298ad532b702461bfc738009d9ebe8025ea", ROMInfo::PCM, "pcm_cm32l", "CM-32L/CM-64/LAPC-I PCM ROM", ROMInfo::Full, NULL, NULL};
00035 
00036 static const ROMInfo * const ROM_INFOS[] = {
00037                 &CTRL_MT32_V1_04,
00038                 &CTRL_MT32_V1_05,
00039                 &CTRL_MT32_V1_06,
00040                 &CTRL_MT32_V1_07,
00041                 &CTRL_MT32_BLUER,
00042                 &CTRL_CM32L_V1_00,
00043                 &CTRL_CM32L_V1_02,
00044                 &PCM_MT32,
00045                 &PCM_CM32L,
00046                 NULL};
00047 
00048 const ROMInfo* ROMInfo::getROMInfo(File *file) {
00049         size_t fileSize = file->getSize();
00050         const char *fileDigest = file->getSHA1();
00051         for (int i = 0; ROM_INFOS[i] != NULL; i++) {
00052                 const ROMInfo *romInfo = ROM_INFOS[i];
00053                 if (fileSize == romInfo->fileSize && !strcmp(fileDigest, romInfo->sha1Digest)) {
00054                         return romInfo;
00055                 }
00056         }
00057         return NULL;
00058 }
00059 
00060 void ROMInfo::freeROMInfo(const ROMInfo *romInfo) {
00061         (void) romInfo;
00062 }
00063 
00064 static int getROMCount() {
00065         int count;
00066         for(count = 0; ROM_INFOS[count] != NULL; count++) {
00067         }
00068         return count;
00069 }
00070 
00071 const ROMInfo** ROMInfo::getROMInfoList(unsigned int types, unsigned int pairTypes) {
00072         const ROMInfo **romInfoList = new const ROMInfo*[getROMCount() + 1];
00073         const ROMInfo **currentROMInList = romInfoList;
00074         for(int i = 0; ROM_INFOS[i] != NULL; i++) {
00075                 const ROMInfo *romInfo = ROM_INFOS[i];
00076                 if ((types & (1 << romInfo->type)) && (pairTypes & (1 << romInfo->pairType))) {
00077                         *currentROMInList++ = romInfo;
00078                 }
00079         }
00080         *currentROMInList = NULL;
00081         return romInfoList;
00082 }
00083 
00084 void ROMInfo::freeROMInfoList(const ROMInfo **romInfoList) {
00085         delete[] romInfoList;
00086 }
00087 
00088 const ROMImage* ROMImage::makeROMImage(File *file) {
00089         ROMImage *romImage = new ROMImage;
00090         romImage->file = file;
00091         romImage->romInfo = ROMInfo::getROMInfo(romImage->file);
00092         return romImage;
00093 }
00094 
00095 void ROMImage::freeROMImage(const ROMImage *romImage) {
00096         ROMInfo::freeROMInfo(romImage->romInfo);
00097         delete romImage;
00098 }
00099 
00100 
00101 File* ROMImage::getFile() const {
00102         return file;
00103 }
00104 
00105 const ROMInfo* ROMImage::getROMInfo() const {
00106         return romInfo;
00107 }
00108 
00109 }