/* Form related things */ private void AssembleASM_Click(object sender, EventArgs e) { CodeBox.Text = ASMDeclarations.ASMAssemble(ASMBox, codeDefBox, outputType, GlobalFileName); if (ASMDeclarations.debugString != "") { DebugMenu(ASMDeclarations.debugString); } return; }
private void DisassembleASM_Click(object sender, EventArgs e) { if (ASMBox.Text != "") { DialogResult a = MessageBox.Show(null, "If you continue, all the assembly will be erased!", "", MessageBoxButtons.OKCancel); if (DialogResult.Cancel == a) { return; } } ASMBox.Text = ASMDeclarations.ASMDisassemble(CodeBox.Text); ASMColorBox(); }
private void Main_Load(object sender, EventArgs e) { ASMDeclarations.DeclareHelpStr(); ASMDeclarations.DeclareInstructions(); string[] args = Environment.GetCommandLineArgs(); if (args.Length == 2) { GlobalFileName = args[1]; LoadCWP3RTB(); codeDefBox.SelectionStart = 0; codeDefBox.SelectionLength = codeDefBox.Text.Length; codeDefBox.SelectionFont = codeDefBox.Font; codeDefBox.SelectionLength = 0; ASMBox.SelectionStart = 0; ASMBox.SelectionLength = ASMBox.Text.Length; ASMBox.SelectionFont = ASMBox.Font; ASMBox.SelectionLength = 0; } //Set minimum size this.MinimumSize = new System.Drawing.Size(654, 564); //Set settings file int off = Application.ExecutablePath.LastIndexOf("\\"); settFile = sLeft(Application.ExecutablePath, off + 1); pathDir = settFile; settFile += "cwps3.ini"; //Load settings string a = FileIO.OpenFile(settFile); if (a != "" && a != null) { string[] b = a.Split('\n'); try { outputType = Convert.ToInt32(b[0]); bitOrder = Convert.ToInt32(b[1]); minMemRange = Convert.ToUInt32(b[2], 16); maxMemRange = Convert.ToUInt32(b[3], 16); colEnabled = Convert.ToBoolean(b[4]); colIns = Convert.ToBoolean(b[5]); colReg = Convert.ToBoolean(b[6]); colCom = Convert.ToBoolean(b[7]); colCommand = Convert.ToBoolean(b[8]); colLab = Convert.ToBoolean(b[9]); } catch { } } if (System.IO.Directory.Exists(Main.DirOf(Application.ExecutablePath) + "\\Pseudo Instructions") == false) { System.IO.Directory.CreateDirectory(Main.DirOf(Application.ExecutablePath) + "\\Pseudo Instructions"); } customPIns = CustomPIns.LoadAllPCI(Main.DirOf(Application.ExecutablePath) + "\\Pseudo Instructions"); ASMBox.Focus(); }
/* -------- Colorizer -------- */ /* Color line by going through each substring */ public void ColorLine(int lineNum) { if (colorRTB == null) { return; } string prefix = "\r"; if (lineNum == 0) { prefix = ""; } if (lineNum < 0 || lineNum >= colorRTB.Lines.Length) { return; } int line = colorRTB.GetFirstCharIndexFromLine(lineNum); int end = colorRTB.GetFirstCharIndexFromLine(colorRTB.GetLineFromCharIndex(line)) + colorRTB.Lines[lineNum].Length; int x = 0; if (line == end || line < 0 || end < 0) { return; } ColorIns = false; if (colCom && colEnabled) //Color Single-line Comment { if (ColorASM("//", line, end, -1, Color.GreenYellow, 1)) { return; } int tempFind = colorRTB.Find("/*", line, RichTextBoxFinds.None); int tempFind2 = 0; if (tempFind >= 0 && tempFind <= end) { int oldSel = colorRTB.SelectionStart; colorRTB.Enabled = false; tempFind2 = colorRTB.Find("*/", tempFind + 2, RichTextBoxFinds.None); if (tempFind2 < 0) { tempFind2 = tempFind; } colorRTB.Select(tempFind, tempFind2 - tempFind + 2); colorRTB.SelectionColor = Color.GreenYellow; colorRTB.Select(tempFind2 + 2, 1); colorRTB.SelectionColor = colorRTB.ForeColor; colorRTB.Enabled = true; colorRTB.Focus(); colorRTB.SelectionStart = oldSel; return; } tempFind2 = colorRTB.Find("*/", line, RichTextBoxFinds.None); if (tempFind < 0 && tempFind2 >= 0) { return; } } ColorIns = true; if (colCommand && colEnabled) { if (ColorASM("hookl", line, end, 0, Color.Red, 1)) { return; } if (ColorASM("hook", line, end, 0, Color.Red, 1)) { return; } if (ColorASM("address", line, end, 0, Color.Red, 1)) { return; } if (ColorASM("hexcode", line, end, 0, Color.Red, 1)) { return; } if (ColorASM("import", line, end, 0, Color.Red, 1)) { return; } if (ColorASM("float", line, end, 0, Color.Red, 1)) { return; } if (ColorASM("string", line, end, 0, Color.Red, 1)) { return; } } if (colLab && colEnabled) { if (ColorLabels(line, end, Color.LightSteelBlue) == 1) { return; } } if (colReg && colEnabled) { ColorRegs(line, end); } /* Commands with register arguments */ if (colCommand && colEnabled) { if (ColorASM("setreg", line, end, 0, Color.Red, 1)) { return; } /* * if (ColorASM("lwi", line, end, 0, Color.Red, 1)) * return; */ //Pseudo Instructions for (int cpiCnt = 0; cpiCnt < customPIns.Length; cpiCnt++) { if (colorRTB.Find(prefix + customPIns[cpiCnt].name + " ", 0) >= 0) { if (ColorINS(prefix + customPIns[cpiCnt].name + " ", line - prefix.Length, end, 0, Color.DarkRed, 0)) { return; } } } } if (colIns && colEnabled) { x = ASMDeclarations.GetInsStart(colorRTB.Lines[lineNum][0]); while (ASMDeclarations.ASMDef[x].name != null) { switch (ASMDeclarations.ASMDef[x].type) { case ASMDeclarations.typeBNCMP: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.Snow, 0)) { return; } break; case ASMDeclarations.typeBNC: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.Blue, 0)) { return; } break; case ASMDeclarations.typeFNAN: case ASMDeclarations.typeNAN: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.Orange, 0)) { return; } break; case ASMDeclarations.typeFOFI: case ASMDeclarations.typeOFI: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.Purple, 0)) { return; } break; case ASMDeclarations.typeNOP: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name, line - prefix.Length, end, 0, Color.Yellow, 0)) { return; } break; case ASMDeclarations.typeIMM: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.LightPink, 0)) { return; } break; case ASMDeclarations.typeSPR: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.Gainsboro, 0)) { return; } break; case ASMDeclarations.typeCND: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.Violet, 0)) { return; } break; case ASMDeclarations.typeIMM5: if (ColorINS(prefix + ASMDeclarations.ASMDef[x].name + " ", line - prefix.Length, end, 0, Color.LightPink, 0)) { return; } break; } x++; } } if (colEnabled) { //Otherwise color green colorRTB.Select(line, end - line); colorRTB.SelectionColor = Color.GreenYellow; colorRTB.Select(end, 1); colorRTB.SelectionColor = colorRTB.ForeColor; } else { //Otherwise color white colorRTB.Select(line, end - line); colorRTB.SelectionColor = Color.White; colorRTB.Select(end, 1); colorRTB.SelectionColor = colorRTB.ForeColor; } }