public void GetRomSize_WhenRomNameExists_ReturnsRomSize() { var dictionary = new RomSizeDictionary(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "snesromsizes.csv")); var result = dictionary.GetRomSize("ROCKMAN SOCCER"); Assert.Equal(1310720, result); }
public void GetRomName_WhenRomNameDoesNotExist_ReturnsMaxRomSize() { var dictionary = new RomSizeDictionary(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "snesromsizes.csv")); var result = dictionary.GetRomSize("WUP-JUNKANDSUCH", 1024000); Assert.Equal(1024000, result); }
public string ExtractRom() { // Quiet down the console during the extraction valid rom check var consoleOutputStream = Console.Out; Console.SetOut(TextWriter.Null); if (this.IsValidRom()) { Console.SetOut(consoleOutputStream); byte[] header = new byte[SNES_HEADER_LENGTH]; switch (headerType) { case SnesHeaderType.HiROM: header = snesHiRomHeader; break; case SnesHeaderType.LoROM: header = snesLoRomHeader; break; } // Attempt to get the game title from the dictionary romName = snesDictionary.getRomName(vcName); string romHeaderName = GetRomName(header); if (String.IsNullOrEmpty(romName)) { romName = romHeaderName; // If a rom name could not be determined from the dictionary or rom, prompt the user if (String.IsNullOrEmpty(romName)) { Console.WriteLine("Could not determine SNES rom name, please enter your desired filename:"); romName = Console.ReadLine(); } } Console.WriteLine("Virtual Console Title: " + vcName); Console.WriteLine("SNES Title: " + romName); Console.WriteLine("SNES Header Name: " + romHeaderName); extractedRomPath = romName + ".sfc"; Console.WriteLine("Getting size of rom..."); int romSize = GetRomSize(header[HEADER_ROM_SIZE_OFFSET]); if (verbose) { Console.WriteLine("Rom size from header is {0} bytes.", romSize); } romSize = snesSizeDictionary.GetRomSize(romHeaderName, romSize); if (verbose) { Console.WriteLine("Actual rom size is {0} bytes.", romSize); } Console.WriteLine("Total SNES rom size: " + romSize + " Bytes"); Console.WriteLine("Getting rom data..."); byte[] pcmData; // Browse to the romPosition in the file using (FileStream fs = new FileStream(decompressedRomPath, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding())) { if (verbose) { Console.WriteLine("Browsing to 0x{0:X} in {1} to read in the rom data...", romPosition, decompressedRomPath); } br.BaseStream.Seek(romPosition, SeekOrigin.Begin); snesRomData = br.ReadBytes(romSize); pcmData = br.ReadBytes((int)(br.BaseStream.Length - romPosition + romSize)); } } SnesPcmExtractor pcmExtract = new SnesPcmExtractor(snesRomData, pcmData); snesRomData = pcmExtract.ExtractPcmData(); Console.WriteLine("Writing to " + extractedRomPath + "..."); using (BinaryWriter bw = new BinaryWriter(File.Open(extractedRomPath, FileMode.Create))) { Console.WriteLine("Writing SNES rom data..."); bw.Write(snesRomData); } Console.WriteLine("SNES rom has been created successfully at " + extractedRomPath); } return(extractedRomPath); }