Beispiel #1
0
        // https://stackoverflow.com/a/29679597
        private void UpdateSample()
        {
            // cheeky way of using the same methods for disassembling a different set of data :^)
            while (sampleTable.Count < 0x8000)
            {
                sampleTable.Add(new ROMByte());
            }

            using (MemoryStream mem = new MemoryStream())
                using (StreamWriter sw = new StreamWriter(mem))
                {
                    List <ROMByte>             tempTable = Data.GetTable();
                    Data.ROMMapMode            tempMode = Data.GetROMMapMode();
                    Data.ROMSpeed              tempSpeed = Data.GetROMSpeed();
                    Dictionary <int, string>   tempAlias = Data.GetAllLabels(), tempComment = Data.GetAllComments();
                    LogCreator.FormatStructure tempStructure = LogCreator.structure;
                    Data.Restore(sampleTable, Data.ROMMapMode.LoROM, Data.ROMSpeed.FastROM, sampleAlias, sampleComment);
                    LogCreator.structure = LogCreator.FormatStructure.SingleFile;

                    LogCreator.CreateLog(sw, StreamWriter.Null);

                    Data.Restore(tempTable, tempMode, tempSpeed, tempAlias, tempComment);
                    LogCreator.structure = tempStructure;

                    sw.Flush();
                    mem.Seek(0, SeekOrigin.Begin);

                    textSample.Text = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
                }
        }
Beispiel #2
0
 public static int ConvertPCtoSNES(int offset)
 {
     if (Data.GetROMMapMode() == Data.ROMMapMode.LoROM)
     {
         offset = ((offset & 0x3F8000) << 1) | 0x8000 | (offset & 0x7FFF);
         if (Data.GetROMSpeed() == Data.ROMSpeed.FastROM || offset >= 0x7E0000)
         {
             offset |= 0x800000;
         }
     }
     else if (Data.GetROMMapMode() == Data.ROMMapMode.HiROM)
     {
         offset |= 0x400000;
         if (Data.GetROMSpeed() == Data.ROMSpeed.FastROM || offset >= 0x7E0000)
         {
             offset |= 0x800000;
         }
     }
     else if (Data.GetROMMapMode() == Data.ROMMapMode.ExHiROM)
     {
         if (offset < 0x40000)
         {
             offset |= 0xC00000;
         }
         else if (offset >= 0x7E0000)
         {
             offset &= 0x3FFFFF;
         }
     }
     else
     {
         if (offset >= 0x400000 && Data.GetROMMapMode() == Data.ROMMapMode.ExSA1ROM)
         {
             offset += 0x800000;
         }
         else
         {
             offset = ((offset & 0x3F8000) << 1) | 0x8000 | (offset & 0x7FFF);
             if (offset >= 0x400000)
             {
                 offset += 0x400000;
             }
         }
     }
     return(offset);
 }
Beispiel #3
0
        private static byte[] SaveVersion1()
        {
            int size = Data.GetROMSize();

            byte[] romSettings = new byte[31];
            romSettings[0] = (byte)Data.GetROMMapMode();
            romSettings[1] = (byte)Data.GetROMSpeed();
            Util.IntegerIntoByteArray(size, romSettings, 2);
            for (int i = 0; i < 0x15; i++)
            {
                romSettings[6 + i] = (byte)Data.GetROMByte(Util.ConvertSNEStoPC(0xFFC0 + i));
            }
            for (int i = 0; i < 4; i++)
            {
                romSettings[27 + i] = (byte)Data.GetROMByte(Util.ConvertSNEStoPC(0xFFDC + i));
            }

            // TODO put selected offset in save file

            List <byte> label = new List <byte>(), comment = new List <byte>();
            Dictionary <int, string> all_labels = Data.GetAllLabels(), all_comments = Data.GetAllComments();

            Util.IntegerIntoByteList(all_labels.Count, label);
            foreach (KeyValuePair <int, string> pair in all_labels)
            {
                Util.IntegerIntoByteList(pair.Key, label);
                for (int i = 0; i < pair.Value.Length; i++)
                {
                    label.Add((byte)pair.Value[i]);
                }
                label.Add(0);
            }

            Util.IntegerIntoByteList(all_comments.Count, comment);
            foreach (KeyValuePair <int, string> pair in all_comments)
            {
                Util.IntegerIntoByteList(pair.Key, comment);
                for (int i = 0; i < pair.Value.Length; i++)
                {
                    comment.Add((byte)pair.Value[i]);
                }
                comment.Add(0);
            }

            byte[] romLocation = Util.StringToByteArray(currentROMFile);

            byte[] data = new byte[romSettings.Length + romLocation.Length + 8 * size + label.Count + comment.Count];
            romSettings.CopyTo(data, 0);
            for (int i = 0; i < romLocation.Length; i++)
            {
                data[romSettings.Length + i] = romLocation[i];
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + i] = (byte)Data.GetDataBank(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + size + i] = (byte)Data.GetDirectPage(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 2 * size + i] = (byte)(Data.GetDirectPage(i) >> 8);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 3 * size + i] = (byte)(Data.GetXFlag(i) ? 1 : 0);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 4 * size + i] = (byte)(Data.GetMFlag(i) ? 1 : 0);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 5 * size + i] = (byte)Data.GetFlag(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 6 * size + i] = (byte)Data.GetArchitechture(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 7 * size + i] = (byte)Data.GetInOutPoint(i);
            }
            // ???
            label.CopyTo(data, romSettings.Length + romLocation.Length + 8 * size);
            comment.CopyTo(data, romSettings.Length + romLocation.Length + 8 * size + label.Count);
            // ???

            return(data);
        }