示例#1
0
        private void assembleButton_Click(object sender, EventArgs e)
        {
            preComCheck = null;
            CompError c = new CompError();
            int off;
            bool success = Utility.OffsetStringToInt(offsetBox.Text, out off);
            if (success)
            {
                insertOffset = off;
                bool syntaxPass = false;
                preComCheck = new BinFile(asm.AssembleASM(off, mainTextBox.Text, ref c, out syntaxPass));

                if (!syntaxPass)
                {
                    Error.ShowErrorMessage(c);
                    gcheckSuccess = false;
                }
                else if (preComCheck.Length != 0)
                {
                    string message = "Are you sure you want to insert this code?";
                    message += "\n" + "Offset: $" + insertOffset.ToString("X") + "  Size: $" + preComCheck.Length.ToString("X") + " byte(s)";
                    if (MessageBox.Show(message, "Confirm Insertion", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        baseFile.ModifyFile(insertOffset, preComCheck);
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                }
            }
        }
示例#2
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            OptionsManager opm = new OptionsManager();
            opm.LoadOptions();

            BinFile bFile = new BinFile();
            LabelContainer lContainer = new LabelContainer();
            Disassembler dsembler = new Disassembler(bFile, lContainer);
            Assembler asmbler = new Assembler(lContainer);
            MainForm mainForm = new MainForm(bFile, dsembler, asmbler, lContainer);

            mainForm.GetOptions(opm.options);
            dsembler.GetOptions(opm.options);
            asmbler.GetOptions(opm.options);

            Application.Run(mainForm);

            mainForm.SetOptions(opm.options);
            dsembler.SetOptions(opm.options);
            asmbler.SetOptions(opm.options);

            opm.SaveOptions();
        }
示例#3
0
 public static List<Bitmap> renderImageTiles(BinFile dxtFile, int offset, int length, Color[] palette)
 {
     List<Bitmap> tileList = new List<Bitmap>();
     for (int i = offset; i < offset + length; i += 0x10)
     {
         Bitmap tile = new Bitmap(8, 8);
         for (int tileRow = 0; tileRow < 8; tileRow++)
         {
             int colorLow = dxtFile.ReadByte(i + (2 * tileRow));
             int colorHigh = dxtFile.ReadByte(i + (2 * tileRow) + 1);
             int color1 = (((colorHigh >> 7) & 1) << 1) | ((colorLow >> 7) & 1);
             int color2 = (((colorHigh >> 6) & 1) << 1) | ((colorLow >> 6) & 1);
             int color3 = (((colorHigh >> 5) & 1) << 1) | ((colorLow >> 5) & 1);
             int color4 = (((colorHigh >> 4) & 1) << 1) | ((colorLow >> 4) & 1);
             int color5 = (((colorHigh >> 3) & 1) << 1) | ((colorLow >> 3) & 1);
             int color6 = (((colorHigh >> 2) & 1) << 1) | ((colorLow >> 2) & 1);
             int color7 = (((colorHigh >> 1) & 1) << 1) | ((colorLow >> 1) & 1);
             int color8 = ((colorHigh & 1) << 1) | (colorLow & 1);
             tile.SetPixel(0, tileRow, palette[color1]);
             tile.SetPixel(1, tileRow, palette[color2]);
             tile.SetPixel(2, tileRow, palette[color3]);
             tile.SetPixel(3, tileRow, palette[color4]);
             tile.SetPixel(4, tileRow, palette[color5]);
             tile.SetPixel(5, tileRow, palette[color6]);
             tile.SetPixel(6, tileRow, palette[color7]);
             tile.SetPixel(7, tileRow, palette[color8]);
         }
         tileList.Add(tile);
     }
     return tileList;
 }
示例#4
0
 public ImageDisplayForm(BinFile dt, DataLabel ds)
 {
     InitializeComponent();
     dst = ds;
     bin = dt;
     gbs = ds.Palette;
     labelOff = ds.Offset;
     labelLen = ds.Length;
     SetColors();
     InitializeImage();
 }
示例#5
0
 public Disassembler(BinFile cs, LabelContainer lcs)
 {
     CoreFile = cs;
     lc = lcs;
     PrintOffsets = true;
     PrintedOffsetFormat = OffsetFormat.BankOffset;
     InstructionNumberFormat = OffsetFormat.Hex;
     PrintBitPattern = true;
     PrintComments = false;
     HideDefinedData = false;
 }
示例#6
0
 public InsertCodeForm(BinFile existing, Disassembler disassembler, Assembler asnew, int offset = 0)
 {
     InitializeComponent();
     mainTextBox = ((TextBoxHost)elementHost1.Child).mainTextBox;
     mainTextBox.ShowLineNumbers = true;
     refFile = disassembler;
     baseFile = existing;
     gcheckSuccess = false;
     offsetBox.Text = offset.ToString("X");
     asm = asnew;
     insertOffset = -1;
 }
示例#7
0
 public MainForm(BinFile cs, Disassembler ds, Assembler ac, LabelContainer lcnew)
 {
     InitializeComponent();
     mainTextBox = ((TextBoxHost)elementHost2.Child).mainTextBox;
     disassembler = ds;
     assembler = ac;
     labelContainer = lcnew;
     romFile = cs;
     funcLabelBox.DataSource = labelContainer.FuncList;
     dataLabelBox.DataSource = labelContainer.DataList;
     varLabelBox.DataSource = labelContainer.VarList;
 }
示例#8
0
 public bool ModifyFile(int offset, BinFile insertFile)
 {
     return(ModifyFile(offset, insertFile.binFile));
 }
示例#9
0
 public bool ModifyFile(int offset, BinFile insertFile)
 {
     return ModifyFile(offset, insertFile.binFile);
 }
示例#10
0
        private string GetInstruction(BinFile refFile, int OrgOffset, int BinaryOffset, ref GBInstruction isu)
        {
            int currentAddress = OrgOffset + BinaryOffset;
            if (lc.isAddressMarkedAsData(currentAddress))
            {
                GBASM.CreateDBInstruction(refFile.MainFile, OrgOffset, BinaryOffset, ref isu);
            }
            else
            {
                GBASM.GetInstruction(refFile.MainFile, OrgOffset, BinaryOffset, ref isu);
            }
            StringBuilder returned = new StringBuilder();

            if (PrintOffsets || PrintBitPattern)
            {
                returned.Append("/*");
                if (PrintOffsets)
                {
                    returned.Append(AddressToString(isu));
                }
                if (PrintBitPattern)
                {
                    var bp = new string[] { "  ", "  ", "  ", "  " };
                    for (int i = 0; i < isu.InstSize; i++)
                    {
                        bp[i] = refFile.ReadByte(BinaryOffset + i).ToString("X2");
                    }
                    returned.Append(string.Join("", bp));
                }
                returned.Append("*/ ");
            }
            else
            {
                returned.Append("    ");
            }

            returned.Append(isu.InstType.ToString());
            string numArg = "";
            if (isu.ArgCount > 0)
            {
                returned.Append(" ");
                numArg = ArgumentToString(isu.Bank, isu.Address, isu.InstType, isu.Arg1);
                returned.Append(numArg);
            }
            if (isu.ArgCount == 2)
            {
                returned.Append(",");
                numArg = ArgumentToString(isu.Bank, isu.Address, isu.InstType, isu.Arg2);
                returned.Append(numArg);
            }

            #region Check comments

            if (PrintComments)
            {
                returned.Append("  ;");
                int x = refFile.ReadByte(BinaryOffset);
                if (refFile.ReadByte(BinaryOffset) == 0xCB)
                {
                    returned.AppendFormat(CBLongInst[x], numArg);
                }
                else
                {
                    returned.AppendFormat(longInst[x], numArg);
                }
            }

            #endregion Check comments

            return returned.ToString();
        }
示例#11
0
 public string PrintASM(BinFile file, int baseOffset, int start, int length)
 {
     StringBuilder output = new StringBuilder();
     GBInstruction isu = new GBInstruction();
     int current = start;
     while (current < start + length)
     {
         var labelsAt = from s in lc.FuncList
                        where s.Offset == current
                        orderby s.Name
                        select s;
         var dataAt = from s in lc.DataList
                      where s.Offset == current
                      select s;
         foreach (var label in labelsAt)
         {
             output.AppendLine(label.ToASMString());
         }
         int advanceBy = 0;
         if (dataAt.Count() != 0)
         {
             if (HideDefinedData)
             {
                 output.AppendLine(String.Format("INCBIN \"{0}.bin\"", dataAt.First().Name));
             }
             else
             {
                 output.Append(ShowDataLabel(dataAt.First()));
             }
             advanceBy = dataAt.First().Length;
         }
         else
         {
             output.AppendLine(GetInstruction(file, baseOffset, current, ref isu));
             advanceBy = isu.InstSize;
         }
         if (lc.Comments.ContainsKey(current))
         {
             output.AppendLine(";" + lc.Comments[current].Replace("\n", "\n;"));
         }
         current += advanceBy;
     }
     return output.ToString();
 }
示例#12
0
 public async Task<string> PrintASMAsync(BinFile file, int baseOffset, int start, int length)
 {
     var task = new Task<string>(() => PrintASM(file, baseOffset, start, length));
     task.Start();
     return await task;
 }
示例#13
0
 public InsertBinaryForm(BinFile preTemp)
 {
     InitializeComponent();
     pre = preTemp;
 }