Ejemplo n.º 1
0
    public GBHeader(byte[] rom)
    {
        // Verify that there's at least enough here to try reading the header info
        if (rom.Length < 0x014f)
        {
            return;
        }
        couldParse = true;

        containsScrollingNintendoGraphic = CheckScrollingGraphics(rom);
        gameTitle           = GetTitle(rom);
        gbcVal              = GetGBCVal(rom);
        newLicenseeCode     = GetNewLicenseeCode(rom);
        sgbFunctions        = GetSGBFunctions(rom);
        cartridgeType       = GetCartridgeType(rom);
        romSize             = GetRomSize(rom);
        ramSize             = GetRamSize(rom);
        destinationCode     = GetDestinationCode(rom);
        oldLicenseeCode     = GetOldLicenseeCode(rom);
        maskROMVersion      = rom[0x14C];
        complementCheckByte = rom[0x14D];
        checksumHigh        = rom[0x14E];
        checksumLow         = rom[0x14F];

        passesComplementCheck = RunComplementCheck(rom);

        isValid = containsScrollingNintendoGraphic & passesComplementCheck;
    }
Ejemplo n.º 2
0
 internal override void WriteRom(ushort address, byte value)
 {
     if (address <= 0x1FFF)
     {
         IsRamEnabled = (value & 0x0F) == 0x0A;
     }
     else if (address >= 0x2000 && address <= 0x2FFF)
     {
         _romb0  = value;
         RomBank = ((_romb1 << 8) | _romb0) % ROMSize.NumberBanks();
     }
     else if (address >= 0x3000 && address <= 0x3FFF)
     {
         _romb1  = (byte)(value & 0b0000_0001); // Only bottom 1 bit is used AFAICT
         RomBank = ((_romb1 << 8) | _romb0) % ROMSize.NumberBanks();
     }
     else if (address >= 0x4000 && address <= 0x5FFF)
     {
         if (RAMSize == CartridgeRAMSize.None)
         {
             RamBank = 0;
         }
         else
         {
             RamBank = (value & 8) % RAMSize.NumberBanks();
         }
     }
 }
 internal override void WriteRom(ushort address, byte value)
 {
     if (address <= 0x1FFF)
     {
         IsRamEnabled = (value & 0x0F) == 0x0A;
     }
     else if (address >= 0x2000 && address <= 0x3FFF)
     {
         RomBank = (value & 0x7f) % ROMSize.NumberBanks();
         if (RomBank == 0x0)
         {
             RomBank = 0x1;
         }
     }
     else if (address >= 0x4000 && address < 0x5FFF)
     {
         if (value <= 0x3)
         {
             RamBank            = value % RAMSize.NumberBanks();
             _mappedRTCRegister = null;
         }
         else if (value >= 0x8 && value <= 0xC)
         {
             _mappedRTCRegister = value switch
             {
                 0x8 => _rtcSecondsRegister,
                 0x9 => _rtcMinutesRegister,
                 0xA => _rtcHoursRegister,
                 0xB => _rtcLowBitsDayCounter,
                 0xC => _rtcHighBitsDayCounter,
                 _ => throw new ArgumentOutOfRangeException(nameof(value), value, $"Value {value} isn't mapped to an RTC register")
             };
         }
     }
     else if (address < 0x7FFF)
     {
         // Allow clock to start counting again
         if (value == 0x1 && _latchedTime.HasValue)
         {
             _latchedTime = null;
         }
         // Latch current time
         else if (value == 0x1)
         {
             _latchedTime = DateTime.UtcNow;
         }
     }
 }
Ejemplo n.º 4
0
        public static ROMSize GetSize(byte i)
        {
            ROMSize retval = Size[0];

            try
            {
                foreach (ROMSize rs in Size)
                {
                    if (rs.Code == i)
                    {
                        retval = rs;
                    }
                }

                return(retval);
            }
            catch (Exception)
            {
                return(Size[0]);
            }
        }
Ejemplo n.º 5
0
 public ROM(ROMSize size)
 {
     _size = size;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Chargé en mémoire le fichier Rom spécifier par this._FileName
        /// </summary>
        /// <returns>Return true si le fichier est bien chargé</returns>
        public bool Load()
        {
            if (File.Exists(this._FileName))
            {
                if (SnesRom.isValid(this._FileName))                   //Verifie si le fichier Rom valide
                //Variable de Verification pour determiner de quel type est la rom a charg
                {
                    string CheckLow1     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DC", "81DD", this.FileName, true));
                    string CheckLow2     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DE", "81DF", this.FileName, true));
                    string CheckLow1b    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDC", "7FDD", this.FileName, true));
                    string CheckLow2b    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDE", "7FDF", this.FileName, true));
                    string CheckHigh1    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DC", "101DD", this.FileName, true));
                    string CheckHigh2    = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DE", "101DF", this.FileName, true));
                    string CheckHigh1b   = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDC", "FFDD", this.FileName, true));
                    string CheckHigh2b   = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDE", "FFDF", this.FileName, true));
                    long   ValCheckLowb  = Convertir.HexaToDecimal(CheckLow1b) + Convertir.HexaToDecimal(CheckLow2b);
                    long   ValCheckHigh  = Convertir.HexaToDecimal(CheckHigh1) + Convertir.HexaToDecimal(CheckHigh2);
                    long   ValCheckHighb = Convertir.HexaToDecimal(CheckHigh1b) + Convertir.HexaToDecimal(CheckHigh2b);
                    long   ValCheckLow   = Convertir.HexaToDecimal(CheckLow1) + Convertir.HexaToDecimal(CheckLow2);

                    //Extraire les informations sur la rom dependant du type de rom
                    if (ValCheckLow == 65535)                     //LowRom 1
                    {
                        this._RomType       = RomType.LowRom_School_1;
                        this._RomName       = ExtractData.AspireString("81C0", "81D4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("81C0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D6", "81D6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D7", "81D7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D8", "81D8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81D9", "81D9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("81DA", "81DA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DB", "81DB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DC", "81DD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81DE", "81DF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81EA", "81EB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("81FC", "81FD", this.FileName, true));
                    }
                    else if (ValCheckLowb == 65535)                      //LowRom 2
                    {
                        this._RomType       = RomType.LowRom_School_2;
                        this._RomName       = ExtractData.AspireString("7FC0", "7FD4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("7FC0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD6", "7FD6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD7", "7FD7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD8", "7FD8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FD9", "7FD9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("7FDA", "7FDA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDB", "7FDB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDC", "7FDD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FDE", "7FDF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FEA", "7FEB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("7FFC", "7FFD", this.FileName, true));
                    }
                    else if (ValCheckHigh == 65535)                      // HighRom
                    {
                        this._RomType       = RomType.HighRom;
                        this._RomName       = ExtractData.AspireString("101C0", "101D4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("101C0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D6", "101D6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D7", "101D7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D8", "101D8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101D9", "101D9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("101DA", "101DA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DB", "101DB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DC", "101DD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101DE", "101DF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101EA", "101EB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("101FC", "101FD", this.FileName, true));
                    }
                    else if (ValCheckHighb == 65535)                      // HighRom
                    {
                        this._RomType       = RomType.HighRom;
                        this._RomName       = ExtractData.AspireString("FFC0", "FFD4", this.FileName).TrimEnd(new char[] { ' ' });
                        this._PostitionName = (int)Convertir.HexaToDecimal("FFC0");
                        this._InfoCart      = (InformationCartouche)
                                              Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD6", "FFD6", this.FileName, true)));
                        this._RomSizeMB = (ROMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD7", "FFD7", this.FileName, true)));
                        this._RamSizeKB = (RAMSize)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD8", "FFD8", this.FileName, true)));
                        this._Country = (Country)
                                        Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFD9", "FFD9", this.FileName, true)));
                        this._Compagnie = (Compagnie)
                                          Convertir.HexaToDecimal(
                            Convertir.StringHexa_LittleEndian(
                                ExtractData.AspireString("FFDA", "FFDA", this.FileName, true)));
                        this._Version      = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDB", "FFDB", this.FileName, true));
                        this._CompChecksum = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDC", "FFDD", this.FileName, true));
                        this._Checksum     = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFDE", "FFDF", this.FileName, true));
                        this._NmiVblVector = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFEA", "FFEB", this.FileName, true));
                        this._ResetVector  = Convertir.StringHexa_LittleEndian(ExtractData.AspireString("FFFC", "FFFD", this.FileName, true));
                    }

                    //Format d'affichage
                    if (this._Country.ToString() == "Japon" ||
                        this._Country.ToString() == "USA")
                    {
                        this._FormatAffichage = FormatAffichage.NTSC;
                    }
                    else
                    {
                        this._FormatAffichage = FormatAffichage.PAL;
                    }

                    //MD5 hashing
                    this._MD5 = HashFile.GetMD5Hexa(this._FileName);

                    #region DEBUG INFOS : Informations sur la Rom
//					#if DEBUG //Informations de debuggage
//						Debug.WriteLine("DEBUG INFOS START : VRS.Library.Console.SuperNintendo.SnesRom.Load()");
//						Debug.WriteLine("CheckLow1        :" + CheckLow1);
//						Debug.WriteLine("CheckLow2        :" + CheckLow2);
//						Debug.WriteLine("CheckLow1b       :" + CheckLow1b);
//						Debug.WriteLine("CheckLow2b       :" + CheckLow2b);
//						Debug.WriteLine("CheckHigh1       :" + CheckHigh1);
//						Debug.WriteLine("CheckHigh2       :" + CheckHigh2);
//						Debug.WriteLine("CheckHigh1b      :" + CheckHigh1b);
//						Debug.WriteLine("CheckHigh2b      :" + CheckHigh2b);
//						Debug.WriteLine("ValCheckLowb     :" + ValCheckLowb);
//						Debug.WriteLine("ValCheckHigh     :" + ValCheckHigh);
//						Debug.WriteLine("ValCheckHighb    :" + ValCheckHighb);
//						Debug.WriteLine("ValCheckLow      :" + ValCheckLow);
//						Debug.WriteLine("this._RomName    :" + this._RomName);
//						Debug.WriteLine("this._InfoCart   :" + this._InfoCart.ToString());
//						Debug.WriteLine("this._RomSizeMB  :" + this._RomSizeMB.ToString());
//						Debug.WriteLine("this._RamSizeKB  :" + this._RamSizeKB.ToString());
//						Debug.WriteLine("this._Country    :" + this._Country.ToString());
//						Debug.WriteLine("this._Compagnie  :" + this._Compagnie.ToString());
//						Debug.WriteLine("this._version    : 1." + this._Version);
//						Debug.WriteLine("this._CompChecksum :" + this._CompChecksum);
//						Debug.WriteLine("this._Checksum :" + this._Checksum);
//						Debug.WriteLine("this._ResetVector :" + this._ResetVector);
//						Debug.WriteLine("this._NmiVblVector :" + this._NmiVblVector);
//						Debug.WriteLine("this._FormatAffichage :" + this._FormatAffichage);
//						Debug.WriteLine("this._MD5 :" + this._MD5);
//						Debug.WriteLine("DEBUG INFOS END : VRS.Library.Console.SuperNintendo.SnesRom.Load()");
//					#endif
                    #endregion

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                throw new FileNotFoundException();
            }
        }