public static byte[] BuildHeader(RomInfo ri, byte[] startCode) { var header = new int[0x50]; if(startCode.Length > 4) throw new ArgumentException("The startCode can be at most 4 bytes long!"); header[0x43] = ri.IsColor ? 0x80 : 0; header[0x44] = ri.LicenseeCode >> 8; header[0x45] = ri.LicenseeCode & 0xFF; header[0x46] = ri.IsSuperGb ? 3 : 0; header[0x47] = ri.CartridgeInfo.GetCode(); header[0x48] = ri.RomSize.GetCode(); header[0x49] = ri.RamSize.GetCode(); header[0x4A] = ri.Japanese ? 0 : 1; header[0x4B] = ri.OldLincenseeCode; header[0x4C] = ri.MaskRomVersionNumber; header[0x4D] = ri.ComplementCheck; header[0x4E] = ri.Checksum >> 8; header[0x4F] = ri.Checksum & 0xFF; var byteHeader = header.Select(i => (byte)i).ToArray(); Array.Copy(startCode, byteHeader, startCode.Length.Max(4)); Array.Copy(ri.NintendoGraphic, 0, byteHeader, 0x04, 48); Array.Copy(ri.RomName.PadRight(14, '\0').Select(c => (byte)(int)c).ToArray(), 0, byteHeader, 0x34, 14); return byteHeader; }
public GameBoy(byte[] rom) { var romInfo = new RomInfo(rom); Rom = romInfo.Rom; Mmu = new MemoryManagementUnit(romInfo, Timer); Init(); }
public static byte[] BuildHeader(RomInfo ri, byte[] startCode) { var header = new int[0x50]; if (startCode.Length > 4) { throw new ArgumentException("The startCode can be at most 4 bytes long!"); } header[0x43] = ri.IsColor ? 0x80 : 0; header[0x44] = ri.LicenseeCode >> 8; header[0x45] = ri.LicenseeCode & 0xFF; header[0x46] = ri.IsSuperGb ? 3 : 0; header[0x47] = ri.CartridgeInfo.GetCode(); header[0x48] = ri.RomSize.GetCode(); header[0x49] = ri.RamSize.GetCode(); header[0x4A] = ri.Japanese ? 0 : 1; header[0x4B] = ri.OldLincenseeCode; header[0x4C] = ri.MaskRomVersionNumber; header[0x4D] = ri.ComplementCheck; header[0x4E] = ri.Checksum >> 8; header[0x4F] = ri.Checksum & 0xFF; var byteHeader = header.Select(i => (byte)i).ToArray(); Array.Copy(startCode, byteHeader, startCode.Length.Max(4)); Array.Copy(ri.NintendoGraphic, 0, byteHeader, 0x04, 48); Array.Copy(ri.RomName.PadRight(14, '\0').Select(c => (byte)(int)c).ToArray(), 0, byteHeader, 0x34, 14); return(byteHeader); }
public static byte[] BuildRom(RomInfo ri, byte[] jumptable, byte[] inttable, byte[] header, byte[] code) { var rom = new byte[ri.RomSize.Size]; Array.Copy(jumptable, 0, rom, 0x00, jumptable.Length.Max(0x40)); Array.Copy(inttable, 0, rom, 0x40, inttable.Length.Max(0x28)); Array.Copy(header, 0, rom, 0x100, header.Length.Max(0x4F)); Array.Copy(code, 0, rom, 0x150, code.Length.Max(rom.Length - 0x150)); return rom; }
public static byte[] BuildRom(RomInfo ri, byte[] jumptable, byte[] inttable, byte[] header, byte[] code) { var rom = new byte[ri.RomSize.Size]; Array.Copy(jumptable, 0, rom, 0x00, jumptable.Length.Max(0x40)); Array.Copy(inttable, 0, rom, 0x40, inttable.Length.Max(0x28)); Array.Copy(header, 0, rom, 0x100, header.Length.Max(0x4F)); Array.Copy(code, 0, rom, 0x150, code.Length.Max(rom.Length - 0x150)); return(rom); }
public MemoryBankController(RomInfo romInfo) { ri = romInfo; Eram = new byte[romInfo.RamSize.Size]; Wram = new byte[0x1FFF]; Zram = new byte[128]; Rombank = 0; RamBank = 0; ExternalRamOn = false; Mode = MemoryMode.M16_8; }
public Mbc2(RomInfo romInfo) : base(romInfo) { Eram = new byte[512 * 4]; }
public static RomInfo GetRomInfo(string[] metadataSection) { const string rbool = @"\s*=\s*(true|false)"; const string rbyte = @"\s*=\s*([\dA-F]{1,2})"; const string rushort = @"\s*=\s*([\dA-F]{1,4})"; // No, I'm quite tall var dataRegexs = new[] { @"name\s*=\s*([ -~]+)", @"cartType" + rbyte, @"color" + rbool, @"licenseeCode" + rushort, @"superGb" + rbool, @"romSize" + rbyte, @"ramSize" + rbyte, @"japanese" + rbool, @"oldLicenseeCode" + rbyte }.ToDictionary(s => s.Split('\\')[0], s => new Regex(s)); var data = dataRegexs.ToDictionary(kvp => kvp.Key, kvp => ""); foreach (string s in metadataSection) foreach (var kvp in dataRegexs) if (data[kvp.Key] == "" && kvp.Value.IsMatch(s)) data[kvp.Key] = kvp.Value.Match(s).Groups[1].Value; var ri = new RomInfo(); foreach (var kvp in data.Where(kvp => kvp.Value != "")) switch (kvp.Key) { case "name": ri.RomName = kvp.Value; break; case "cartType": ri.CartridgeInfo = new CartridgeInfo(Convert.ToByte(kvp.Value, 16)); break; case "color": ri.IsColor = Convert.ToBoolean(kvp.Value); break; case "licenseeCode": ri.LicenseeCode = Convert.ToUInt16(kvp.Value, 16); break; case "superGb": ri.IsSuperGb = Convert.ToBoolean(kvp.Value); break; case "romSize": ri.RomSize = new RomSize(Convert.ToByte(kvp.Value, 16)); break; case "ramSize": ri.RamSize = new RamSize(Convert.ToByte(kvp.Value, 16)); break; case "japanese": ri.Japanese = Convert.ToBoolean(kvp.Value); break; case "oldLicenseeCode": ri.OldLincenseeCode = Convert.ToByte(kvp.Value); break; } return ri; }
public Mbc5(RomInfo romInfo) : base(romInfo) { }
public MbcRumble(RomInfo romInfo) : base(romInfo) { }
public static MemoryBankController Factory(RomInfo ri) { switch(ri.CartridgeInfo.MbcType) { case MbcType.Mbc1: return new Mbc1(ri); case MbcType.Mbc2: return new Mbc2(ri); case MbcType.Mbc3: return new Mbc3(ri); case MbcType.Mbc5: return new Mbc5(ri); case MbcType.Rumble: return new MbcRumble(ri); } throw new NotSupportedException("MbcType: " + ri.CartridgeInfo.MbcType + " is not yet supported."); }