Beispiel #1
0
            internal byte[]        GamecardInfo;         // [x] Gamecard info

            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("Signature: {0}\n", BitConverter.ToString(Signature));
                sb.AppendFormat("Magic: {0}\n", Encoding.ASCII.GetString(BitConverter.GetBytes(Magic)));
                sb.AppendFormat("SecureOffset: 0x{0:X} * 0x200\n", SecureOffset);
                sb.AppendFormat("BackupOffset: 0x{0:X} * 0x200\n", BackupAreaAddress);
                sb.AppendFormat("KEK Index: 0x{0:X}\n", KEK);
                sb.AppendFormat("CartType: {0}\n", CartType.ToString());
                sb.AppendFormat("HeaderVersion: 0x{0:X}\n", HeaderVersion);
                sb.AppendFormat("Flag: 0x{0:X}\n", Flag);
                sb.AppendFormat("PackageID: {0}\n", BitConverter.ToString(BitConverter.GetBytes(PackageID)));
                sb.AppendFormat("CardSize: 0x{0} * 0x200\n", CardSize);
                sb.AppendFormat("IV (raw-data): {0}\n", BitConverter.ToString(GamecardIV));
                sb.AppendFormat("HFS0Offset: 0x{0:X}\n", HFS0HeaderSize);
                sb.AppendFormat("HFS0HeaderSize: 0x{0:X}\n", HFS0HeaderSize);
                sb.AppendFormat("HFS0HeaderHash: {0}\n", BitConverter.ToString(HFS0HeaderHash));
                sb.AppendFormat("InitialDataHash: {0}\n", BitConverter.ToString(InitialDataHash));
                sb.AppendFormat("SecureModeFlag: 0x{0:X}\n", SecureModeFlag);
                sb.AppendFormat("TitleKeyFlag: 0x{0:X}\n", TitleKeyFlag);
                sb.AppendFormat("KeyFlag: 0x{0:X}\n", KeyFlag);
                sb.AppendFormat("NormalAreaEndAddress: 0x{0:X}\n", NormalAreaEndAddress);
                sb.AppendFormat("GamecardInfo [Encrypted]: {0}\n", BitConverter.ToString(GamecardInfo));
                return(sb.ToString());
            }
 private static bool NameContainsSegment(this CartridgeType src, string segment)
 {
     return(new Regex("(^|_)" + Regex.Escape(segment) + "($|_)").IsMatch(src.ToString()));
 }
Beispiel #3
0
        public void setByte(ushort address, Byte Value)
        {
            CartridgeType type = (CartridgeType)this.headerInfoDict.Where(fi => fi.description == "Cartridge Type").First().value;

            switch (type)
            {
            case CartridgeType.ROM_ONLY:
                break;

            case CartridgeType.ROM_MBC1:
            case CartridgeType.ROM_MBC1_RAM:
            case CartridgeType.ROM_MBC1_RAM_BATT:
                if (address >= 0x0000 && address <= 0x1FFF)
                {
                    // RAM Enable
                }
                else if (address >= 0x2000 && address <= 0x3FFF)
                {
                    // ROM Select
                    Byte romBankNum = Value;

                    // ROM Address MBC1 Bug
                    if ((romBankNum & 0x1F) == 0)
                    {
                        romBankNum += 1;
                    }
                    romBankNum = (Byte)(romBankNum & 0x1F);

                    // Set ROM Bank Num
                    if (memContMode == MBC1_Mode.ROM_MODE)
                    {
                        // Set only 5 lsb bits
                        selectedRomBank = (ushort)((selectedRomBank & 0xC0) | (romBankNum & 0x1F));
                    }
                }
                else if (address >= 0x4000 && address <= 0x5FFF)
                {
                    Byte tmp = (Byte)(Value & 0x03);

                    if (memContMode == MBC1_Mode.ROM_MODE)
                    {
                        // Upper ROM Select (Set upper 2 bits 5-6)
                        selectedRomBank = (ushort)((selectedRomBank & 0x1F) | (tmp << 5));
                    }
                    else
                    {
                        // RAM Mode
                        selectedRamBank = tmp;
                    }
                }
                else if (address >= 0x6000 && address <= 0x7FFF)
                {
                    // ROM/RAM mode select
                    if (Value == 0)
                    {
                        memContMode = MBC1_Mode.ROM_MODE;
                    }
                    else if (Value == 1)
                    {
                        memContMode = MBC1_Mode.RAM_MODE;
                    }
                    else
                    {
                        throw new ArgumentException($"Invalid Write to ROM Address 0x{address.ToString("X4")} value 0x{Value.ToString("X2")}");
                    }
                }
                else
                {
                    throw new ArgumentException($"Attempted Write to Address Which is in ROM Space");
                }
                break;


            default:
                throw new NotImplementedException($"Cartridge Type {type.ToString()} MMC Operation write at {address.ToString("X4")} not Implemented");
            }
        }