public ROMFile(string fileName, List <byte[]> DMAData) { //Convert byte[] to dma List <DMATableEntry> dmaEntries = new List <DMATableEntry>(); uint start = 0; foreach (byte[] data in DMAData) { uint end = start + (uint)data.Length; DMATableEntry dma = new DMATableEntry(start, start, end, 0x0, data); dmaEntries.Add(dma); start = end; } DMATable = dmaEntries; IsDMALoaded = true; this.Filename = fileName; //DmaToRom DMAToRom(); //Fix CRC FixCRC(); }
private void RomToDMA() { //Transfer data from ROM to DMA Tables if (Info.DMATableOffset == 0x0) { IsDMALoaded = false; return; } IsCompressed = false; DMATable.Clear(); int CurrentPos = (int)Info.DMATableOffset; try { while (CurrentPos < Size - 16) { uint VStart = ToolSettings.ReadUInt(_romData, CurrentPos, ROMEndianness); uint PStart = ToolSettings.ReadUInt(_romData, CurrentPos + 4, ROMEndianness); uint PEnd = ToolSettings.ReadUInt(_romData, CurrentPos + 8, ROMEndianness); uint CompFlag = ToolSettings.ReadUInt(_romData, CurrentPos + 12, ROMEndianness); //Create the actual data byte[] dmaBytes = new byte[PEnd - PStart]; Array.Copy(_romData, PStart, dmaBytes, 0, dmaBytes.Length); DMATableEntry entry = new DMATableEntry(VStart, PStart, PEnd, CompFlag, dmaBytes); if ((entry.PStart == 0x00) && (entry.PEnd == 0x00)) { break; } if (entry.CompFlag == 1) { IsCompressed = true; } DMATable.Add(entry); CurrentPos += 16; } IsDMALoaded = true; } catch { IsDMALoaded = false; } //if (IsCompressed) //{ // if (DecompressDMA()) // { // DMAToRom(); // FixCRC(); // } //} }
private bool DecompressDMA() { if (!IsDMALoaded) { return(false); } for (int i = 0; i < DMATable.Count; i++) { DMATableEntry dma = DMATable[i]; if (dma.CompFlag == 0x1) { //compressed //Decompress here byte[] newDMAData; if (ToolSettings.DecompressMIO0(dma.DMAData, out newDMAData)) { dma.DMAData = newDMAData; dma.PEnd = dma.VStart + (uint)newDMAData.Length; dma.PStart = dma.VStart; dma.CompFlag = 0x0; } else { //Catastrophic failure, just quit out return(false); } } else { //uncompressed dma.PEnd = dma.VStart + (dma.PEnd - dma.PStart); dma.PStart = dma.VStart; } DMATable[i] = dma; } return(true); }