public MegaDumperResult AutoDetect() { MegaDumperResult mdr = new MegaDumperResult(); mdr.dtStart = DateTime.Now; mdr.returnCode = ReturnCode.NOT_FOUND; mdr.operation = MegaDumperOperation.Autodetect; string[] ports = SerialPort.GetPortNames(); foreach (string p in ports) { port = p; string v = GetVersion(); if (v.StartsWith(MegaDumper.FIRMWARE_STRING)) { mdr.returnCode = ReturnCode.OK; mdr.result = p; //return named serial port in the result break; } } mdr.dtEnd = DateTime.Now; return(mdr); }
private void MegaDumper_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { toolStripProgressBar.Value = 100; //rtfLog.Text += (string)e.Result; toolStripStatusLabel.Text = LABEL_READY; MegaDumperResult mdr = (MegaDumperResult)e.Result; if (mdr.operation == MegaDumperOperation.Dump) { saveFileDialog.ShowDialog(); if (saveFileDialog.FileName != string.Empty) { Cart c = (Cart)mdr.result; File.WriteAllBytes(saveFileDialog.FileName, c.RomData); } } else if (mdr.operation == MegaDumperOperation.Autodetect) { if (mdr.returnCode == ReturnCode.OK) { log("Found GenDumper on serial port " + (string)mdr.result, LogType.Success); } else { log("GenDumper could not be found. Please plug your GenDumper in and select serial port or run auto-detection", LogType.Warning); } } toolStripProgressBar.Visible = false; }
private void MegaDumper_DoWork(object sender, DoWorkEventArgs e) { MegaDumperResult mdr = new MegaDumperResult(); if (megaDumper.Operation == MegaDumperOperation.Dump) { mdr = megaDumper.GetDump(); e.Result = mdr; } else if (megaDumper.Operation == MegaDumperOperation.Version) { string ss = megaDumper.GetVersion(); } else if (megaDumper.Operation == MegaDumperOperation.Autodetect) { mdr = megaDumper.AutoDetect(); e.Result = mdr; } //RomHeader h = megaDumper.getRomHeader(); }
public MegaDumperResult GetDump(uint from, uint to) { //set port to whatever was selected last by user serialPort.PortName = port; // Cart object Cart cart = new Cart(); // result object MegaDumperResult res = new MegaDumperResult(); res.operation = operation; res.dtStart = DateTime.Now; // dump command byte[] command = new byte[9]; byte[] fromBytes, toBytes; command[0] = (byte)'d'; // reset data buffer bytesToReceive = 0; bytesStream.Clear(); //if from and to == 0, we try to try to get the rom header first if (from == 0 && to == 0) { fromBytes = BitConverter.GetBytes(RomHeader.PHYSICAL_ADDR_START); /* rom header starts at physical address 0x80 */ toBytes = BitConverter.GetBytes(RomHeader.PHYSICAL_ADDR_END); /* rom header ends at physical address 0x100 */ fromBytes.CopyTo(command, 1); /* from address */ toBytes.CopyTo(command, 5); /* to address */ serialPort.Open(); lock (transmissionOverLock) { serialPort.Write(command, 0, command.Length); if (!Monitor.Wait(transmissionOverLock)) { //timeout } else { //business as normal } } serialPort.Close(); cart.SetHeaderFromRawData(bytesStream.ToArray()); // report this progress this.ReportProgress(0, cart); // reset data buffer in order to receive the actual rom content bytesToReceive = 0; bytesStream.Clear(); //finally get the proper rom start and end fromBytes = BitConverter.GetBytes(cart.Header.RomAddressStart); toBytes = BitConverter.GetBytes(cart.Header.RomAddressEnd >> 1); } else { fromBytes = BitConverter.GetBytes(from); toBytes = BitConverter.GetBytes(to); } fromBytes.CopyTo(command, 1); /* from address */ toBytes.CopyTo(command, 5); /* to address */ serialPort.Open(); lock (transmissionOverLock) { serialPort.Write(command, 0, command.Length); if (!Monitor.Wait(transmissionOverLock)) { //timeout } else { //business as normal } } serialPort.Close(); //save dump to cart cart.RomData = bytesStream.ToArray(); //set the cart as result res.result = cart; res.dtEnd = DateTime.Now; return(res); }