using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TheDarkWraith.WM16MEV
{
    public partial class DumpByte : Form
    {
        #region Variables
        WM16MEV wm16ev = null;
        #endregion

        #region Constructor
        public DumpByte(WM16MEV wm16evpassed)
        {
            InitializeComponent();

            wm16ev = wm16evpassed;

            wm16ev.DisplayDialog("Dump byte - building addresses...", true);

            // populate address combo box with range of addresses
            for (int i = 0; i < 0xFFFF; i++)
            {
                Application.DoEvents();
                comboAddress.Items.Add("0x" + i.ToString("X4"));
            }

            comboAddress.SelectedIndex = 0;
        }
        #endregion

        #region GetValue_Click
        private void btnGetValue_Click(object sender, EventArgs e)
        {
            int address = 0;

            try
            {
                if (comboAddress.Text.StartsWith("0x"))
                {
                    address = Convert.ToInt32(((String)comboAddress.Text).Remove(0, 2), 16);
                }
                else
                {
                    address = Convert.ToInt32(((String)comboAddress.Text), 16);
                }
                if (!wm16ev.DumpECUByte(address))
                {
                    tbValue.Text = "";
                    return;
                }

                tbValue.Text = "0x" + wm16ev.ReceivedByte.ToString("X2");
            }
            catch
            {
                tbValue.Text = "Error";
            }
        }
        #endregion

        #region Destroy
        internal void Destroy()
        {
            wm16ev = null;
        }
        #endregion

        #region Shown
        private void DumpByte_Shown(object sender, EventArgs e)
        {
            wm16ev.DisplayDialog("", false);
        }
        #endregion
    }
}
