static void Main(string [] args) { Options opts = new Options(args); opts.ParseOptions(); if (opts.exec && opts.filename != null) { Computer exec = new Computer(opts.mem); exec.setFileName(opts.filename); exec.setTrace(); exec.resetComputer(); exec.Run(); Environment.Exit(0); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1(args)); }
//load the file specified by <name> and ready the Disassembly etc. panels protected void OnFileSelect(EventArgs e, string name) { Loader.Log("Form1: Loading File", false, false); terminalBox.Clear(); int fl = flagView.Rows.Add(); var flrow = flagView.Rows[fl]; flagView.ForeColor = Color.Black; flrow.Cells[0].Value = "0"; flrow.Cells[1].Value = "0"; flrow.Cells[2].Value = "0"; flrow.Cells[3].Value = "0"; flrow.Cells[4].Value = "0"; comp.setFileName(name); disassemblyView.Rows.Clear(); stackView.Rows.Clear(); memoryView.Rows.Clear(); name = name.Substring(name.LastIndexOf("\\") + 1); try { int sum = comp.resetComputer(); comp.cpu.clearBreak(); fileNamePanel.Text = "Filename: " + name; checkSumPanel.Text = "Checksum: " + sum.ToString(); int index = 0; byte[] memory = comp.getRam(); while (index < 16) { uint entry1 = comp.getReg(index); if (index == 15) { entry1 -= 4; } setRegister(index, entry1); index++; } uint addr = comp.RAM.begin; int byteindex = 0; bool instruct = false; StreamReader rd = new StreamReader("sample.txt"); bool endins = false; Loader.Log("Form1: Setting Memory", false, false); while (addr < comp.RAM.end) { int row = memoryView.Rows.Add(); DataGridViewRow r1 = memoryView.Rows[row]; r1.Height = (memoryView.ClientRectangle.Height - memoryView.ColumnHeadersHeight) / memoryView.Rows.Count; r1.Cells["Address"].Value = "0x" + addr.ToString("X8"); DataGridViewCell c1 = memoryView.Rows[row].Cells["Address"]; int readindex = 0; while (readindex < 4) { string bytestr = ""; while (byteindex < 4) { if (addr >= comp.RAM.end) { break; } byte b = memory[addr + byteindex]; bytestr += b.ToString("X2") + " "; byteindex++; } memoryView.Rows[row].Cells[readindex + 1].Value = bytestr; byteindex = 0; addr += 4; readindex++; } //memoryView.Rows.Insert() } DataGridViewRow lrow = memoryView.Rows[memoryView.Rows.Count - 1]; int cindex = 1; while (cindex < 5) { if ((string)lrow.Cells[cindex].Value == "") { lrow.Cells[cindex].Value = "00 00 00 00"; } cindex++; } addr = 0; comp.setCounter(comp.Registers.getPC()); Loader.Log("Form1: Loading Disassembly", false, false); addr = 0; var re = comp.Registers.getPC(); if (comp.RAM.ReadWord(0) == 0) { addr = comp.RAM.begin; instruct = true; } while (addr < comp.RAM.end) { string x = addr.ToString("X"); DataGridViewRow r2; int row2; comp.Registers.setRegister(15, addr + 4); if (addr == 0 || instruct) { if (comp.RAM.ReadWord(addr) != 0) { if (!endins) { row2 = disassemblyView.Rows.Add(); r2 = disassemblyView.Rows[row2]; r2.Cells["AddressColumn"].Value = "0x" + x; r2.Cells["MachineLangColumn"].Value = "0x" + addPlace(comp.RAM.ReadWord(addr)); try { Instruction x1 = Instruction.Factory(comp.RAM.ReadWord(addr), ref comp); if (x1.GetType() == typeof(BranchInstruction)) { BranchInstruction bran = (BranchInstruction)x1; r2.Cells["AssemblyColumn"].Value = (bran.ToAssembly()); } else { r2.Cells["AssemblyColumn"].Value = x1.ToAssembly(); } } catch { r2.Cells["AssemblyColumn"].Value = ""; } instruct = true; } } } addr += 4; } comp.Registers.setRegister(15, re); uint entry = comp.Registers.getPC(); foreach (DataGridViewRow y in disassemblyView.Rows) { if (y.Cells[0].Value == null) { continue; } string iii = (string)y.Cells[0].Value; var nupoint = UInt32.Parse(iii.Substring(2), System.Globalization.NumberStyles.HexNumber); if (nupoint == re) { if (y.Index > 2) { disassemblyView.FirstDisplayedScrollingRowIndex = y.Index - 2; } else { disassemblyView.FirstDisplayedScrollingRowIndex = y.Index; } y.Selected = true; firstinstructAddress = y.Index; disassemblyView.Update(); break; } disassemblyView.Rows[0].Selected = true; disassemblyView.Enabled = false; rd.Close(); } addStack(); if (comp.Registers.modetrack == 0) { modeBox.Text = "SYS"; } else { modeBox.Text = "SVC"; } } catch { fileNamePanel.Text = "None"; checkSumPanel.Text = "Load Error"; disassemblyView.Rows.Clear(); memoryView.Rows.Clear(); flagView.Rows.Clear(); stackView.Rows.Clear(); MessageBox.Show("Error: File could not load."); } disassemblyView.AutoResizeColumns(); memoryView.AutoResizeColumns(); flagView.AutoResizeColumns(); disassemblyView.CellBorderStyle = DataGridViewCellBorderStyle.None; memoryView.CellBorderStyle = DataGridViewCellBorderStyle.None; }