--- trunk/RomCheater/Docking/FloatingRamDumperDialog.cs 2012/05/28 02:20:29 153 +++ trunk/RomCheater/Docking/FloatingRamDumperDialog.cs 2012/05/28 03:04:05 154 @@ -14,13 +14,22 @@ { public partial class FloatingRamDumperDialog : DockContent, IProcessConfig { + #region sub-classes + private const int BYTE_CORRECTION_VALUE = 23; + public enum DumpSize + { + Bytes, + KiloBytes, + MegaBytes, + GigaBytes, + } + #endregion + private DumpSize dumpSize = DumpSize.Bytes; + public FloatingRamDumperDialog() { InitializeComponent(); this.AcceptedPlugin = null; this.AcceptedProcess = null; } public FloatingRamDumperDialog(IConfigPlugin config) : this() { this.AcceptedPlugin = config; } public FloatingRamDumperDialog(IConfigPlugin config, Process process) : this() { this.AcceptedPlugin = config; this.AcceptedProcess = process; } - - //public IConfigPlugin AcceptedPlugin { get; set; } - //public Process AcceptedProcess { get; set; } - + private void FloatingRamDumperDialog_Load(object sender, EventArgs e) { txtStart.Value = 0; @@ -34,5 +43,99 @@ #region IAcceptsPlugin Members public IConfigPlugin AcceptedPlugin { get; set; } #endregion + + private void radioBTNBytes_CheckedChanged(object sender, EventArgs e) + { + dumpSize = DumpSize.Bytes; + } + + private void radioBTNKiloBytes_CheckedChanged(object sender, EventArgs e) + { + dumpSize = DumpSize.KiloBytes; + } + + private void radioBTNMegaBytes_CheckedChanged(object sender, EventArgs e) + { + dumpSize = DumpSize.MegaBytes; + } + + private void radioBTNGigaBytes_CheckedChanged(object sender, EventArgs e) + { + dumpSize = DumpSize.GigaBytes; + } + + private void btnCalcEndAddr_Click(object sender, EventArgs e) + { + ulong start = 0; + ulong end = 0; + start = txtStart.Value; + switch (dumpSize) + { + case DumpSize.Bytes: + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1.0 + start) - BYTE_CORRECTION_VALUE; + txtEnd.Value = end; + break; + case DumpSize.KiloBytes: + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000.0 + start) - BYTE_CORRECTION_VALUE; + txtEnd.Value = end; + break; + case DumpSize.MegaBytes: + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000.0 + start) - BYTE_CORRECTION_VALUE; + txtEnd.Value = end; + break; + case DumpSize.GigaBytes: + end = (ulong)(Convert.ToDouble(txtDumpSize.Text) * 1000000000.0 + start) - BYTE_CORRECTION_VALUE; + txtEnd.Value = end; + break; + } + } + + private void btnCalcStartAddr_Click(object sender, EventArgs e) + { + long start = 0; + long end = 0; + end = txtEnd.ToInt64(); + switch (dumpSize) + { + case DumpSize.Bytes: + start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1.0)) + BYTE_CORRECTION_VALUE; + txtStart.Value = (ulong)start;; + break; + case DumpSize.KiloBytes: + start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000.0)) + BYTE_CORRECTION_VALUE; + txtStart.Value = (ulong)start;; + break; + case DumpSize.MegaBytes: + start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000000.0)) + BYTE_CORRECTION_VALUE; + txtStart.Value = (ulong)start;; + break; + case DumpSize.GigaBytes: + start = (long)((double)end - (Convert.ToDouble(txtDumpSize.Text) * 1000000000.0)) + BYTE_CORRECTION_VALUE; + txtStart.Value = (ulong)start; + break; + } + } + + private void btnCalcDumpSize_Click(object sender, EventArgs e) + { + ulong start = txtStart.Value; + ulong end = txtEnd.Value; + ulong byte_diff = (end - start) + BYTE_CORRECTION_VALUE; + switch (dumpSize) + { + case DumpSize.Bytes: + txtDumpSize.Text = string.Format("{0:n2}", (double)byte_diff); + break; + case DumpSize.KiloBytes: + txtDumpSize.Text = string.Format("{0:n3}", (double)byte_diff / 1000.0); + break; + case DumpSize.MegaBytes: + txtDumpSize.Text = string.Format("{0:n6}", (double)byte_diff / 1000000.0); + break; + case DumpSize.GigaBytes: + txtDumpSize.Text = string.Format("{0:n9}", (double)byte_diff / 1000000000.0); + break; + } + } } }