/[RomCheater]/trunk/RomCheater.Core/Docking/FloatingDataTypeConverter.cs
ViewVC logotype

Contents of /trunk/RomCheater.Core/Docking/FloatingDataTypeConverter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 889 - (show annotations) (download)
Wed Sep 17 04:55:52 2014 UTC (7 years ago) by william
File size: 7469 byte(s)


1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using WeifenLuo.WinFormsUI.Docking;
10 using libWin32.Win32.NumericConversion.IEEE754;
11 using RomCheater.Core;
12 namespace RomCheater.Core.Docking
13 {
14 public partial class FloatingDataTypeConverter : DockContent
15 {
16 public FloatingDataTypeConverter()
17 {
18 InitializeComponent();
19 this.Icon = Core.Properties.Resources.romcheater_icon;
20 chkhexadecimal.Checked = true;
21 }
22
23 private void chkBinary_CheckedChanged(object sender, EventArgs e)
24 {
25 // binary input
26 txtInput.InputType = NumericInputTypes.Binary;
27 txtInput.Value = (0).ToString();
28 }
29
30 private void chkdecimal_CheckedChanged(object sender, EventArgs e)
31 {
32 // decimal input
33 txtInput.InputType = NumericInputTypes.Decimal;
34 txtInput.Value = (0).ToString();
35 }
36
37 private void chkhexadecimal_CheckedChanged(object sender, EventArgs e)
38 {
39 // hex input
40 txtInput.InputType = NumericInputTypes.Hex;
41 txtInput.Value = (0).ToString();
42 }
43
44 private void chkoctal_CheckedChanged(object sender, EventArgs e)
45 {
46 // octal input
47 txtInput.InputType = NumericInputTypes.Octal;
48 txtInput.Value = (0).ToString();
49 }
50
51 private void chkieee754float_CheckedChanged(object sender, EventArgs e)
52 {
53 //// IEEE754 Hex Float (hex)
54 //txtInput.InputType = NumericInputTypes.IEEE754HexFloat;
55 //txtInput.Value = (0).ToString();
56 }
57
58 private void btnConvert_Click(object sender, EventArgs e)
59 {
60 try
61 {
62 switch (txtInput.InputType)
63 {
64 case NumericInputTypes.Binary:
65 txtBinary.Value = txtInput.Value;
66 ConvertData(txtBinary.Value, 2);
67 break;
68 case NumericInputTypes.Decimal:
69 txtDecimal.Value = txtInput.Value;
70 ConvertData(txtDecimal.Value, 10);
71 FloatConverter.SetFloatValue(Convert.ToSingle(txtDecimal.Value));
72 FloatConverter.CalculateHexFloat();
73 break;
74 case NumericInputTypes.Hex:
75 txtHex.Value = txtInput.Value;
76 ConvertData(txtHex.Value, 16);
77 FloatConverter.SetFloatHexValue(Convert.ToUInt32(txtHex.Value,16));
78 FloatConverter.CalculateFloat();
79 break;
80 //case NumericInputTypes.IEEE754HexFloat:
81 // txtFloat.Value = txtInput.Value;
82 // ConvertData(txtFloat.Value, 16);
83 // break;
84 case NumericInputTypes.Octal:
85 txtOctal.Value = (txtInput.Value.StartsWith("0")) ? txtInput.Value : string.Format("0{0}", txtInput.Value);
86 ConvertData(txtOctal.Value, 8);
87 break;
88 }
89
90 }
91 catch (FormatException ex)
92 {
93 MessageBox.Show(ex.ToString(),"Encountered an error in the input format", MessageBoxButtons.OK, MessageBoxIcon.Error);
94 }
95 catch (Exception ex)
96 {
97 MessageBox.Show(ex.ToString(),"Encountered an error while converting the data", MessageBoxButtons.OK, MessageBoxIcon.Error);
98 }
99 }
100
101 private void ConvertData(string value, int FromBase)
102 {
103 // binary
104 if (txtInput.InputType != NumericInputTypes.Binary)
105 {
106 int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
107 txtBinary.Value = Convert.ToString(val, 2);
108 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
109 //{
110 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
111 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
112 // converter.HexFloat = val2;
113 // txtBinary.Value = Convert.ToString(converter.Float);
114 //}
115 }
116 // decimal
117 if (txtInput.InputType != NumericInputTypes.Decimal)
118 {
119 int val = Convert.ToInt32(value, FromBase);
120 txtDecimal.Value = Convert.ToString(val, 10);
121 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
122 //{
123 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
124 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
125 // converter.HexFloat = val2;
126 // txtDecimal.Value = string.Format("{0:R}", converter.Float);
127 //}
128 }
129 // hex
130 if (txtInput.InputType != NumericInputTypes.Hex)
131 {
132 int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
133 txtHex.Value = Convert.ToString(val, 16);
134 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
135 //{
136 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
137 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
138 // converter.HexFloat = val2;
139 //}
140 }
141 // octal
142 if (txtInput.InputType != NumericInputTypes.Octal)
143 {
144 int val = Convert.ToInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
145 txtOctal.Value = Convert.ToString(val, 8);
146 //if (txtInput.InputType == NumericInputTypes.IEEE754HexFloat)
147 //{
148 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
149 // uint val2 = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
150 // converter.HexFloat = val2;
151 //}
152 }
153 //// float
154 //if (txtInput.InputType != NumericInputTypes.IEEE754HexFloat)
155 //{
156 // ieee754FloatingPointConverter converter = new ieee754FloatingPointConverter();
157 // uint val = Convert.ToUInt32(value.Contains(".") ? value.Remove(value.IndexOf(".")) : value, FromBase);
158 // float f = Convert.ToSingle(val);
159 // converter.Float = f;
160 // //txtFloat.Value = string.Format("{0:R}", converter.Float);
161 // txtFloat.Value = string.Format("0x{0:x8}", converter.HexFloat);
162 //}
163 }
164 }
165 }

  ViewVC Help
Powered by ViewVC 1.1.22