private void cboEntry_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (loading)
            {
                return;
            }

            int index = cboEntry.SelectedIndex;
            var bg    = GfxBattleBg.Bgs[index];

            //pLayer.Image = GfxBattleBg.GetLayer(index);

            txtGfxEntry.Text = bg.GfxEntry.ToString();
            txtArrEntry.Text = bg.ArrEntry.ToString();
            txtPalDir.Text   = bg.PalDir.ToString();
            txtPalStart.Text = bg.PalStart.ToString();
            txtPalEnd.Text   = bg.PalEnd.ToString();
            txtPalDelay.Text = bg.PalDelay.ToString();

            txtDriftH.Text   = bg.DriftH.ToString();
            txtDriftV.Text   = bg.DriftV.ToString();
            txtAmplH.Text    = bg.AmplH.ToString();
            txtAmplV.Text    = bg.AmplV.ToString();
            txtFreqH.Text    = bg.FreqH.ToString();
            txtFreqV.Text    = bg.FreqV.ToString();
            txtWavenumH.Text = bg.WavenumH.ToString();
            txtWavenumV.Text = bg.WavenumV.ToString();

            // Arrangement stuff
            arrEditor.Clear();

            int[] gfxEntry = GfxBattleBgTable.GetEntry(bg.GfxEntry);
            arrEditor.SetTileset(M3Rom.Rom, gfxEntry[0], gfxEntry[1] >> 5);
            arrEditor.SetArrangement(GfxBattleBgTable.GetArr(bg.ArrEntry), 32, 32);
            arrEditor.SetPalette(bg.Palette);

            arrEditor.RenderArr();
            arrEditor.RenderTileset();
            arrEditor.CurrentTile = 0;
            arrEditor.RefreshArr();
        }
        private void btnApply_Click(object sender, EventArgs e)
        {
            int index = cboEntry.SelectedIndex;
            var bg    = GfxBattleBg.Bgs[index];

            // Gfx entry

            /*try
             * {
             *  bg.GfxEntry = ushort.Parse(txtGfxEntry.Text);
             * }
             * catch
             * {
             *  txtGfxEntry.SelectAll();
             *  return;
             * }
             *
             * // Arr entry
             * try
             * {
             *  bg.ArrEntry = ushort.Parse(txtArrEntry.Text);
             * }
             * catch
             * {
             *  txtArrEntry.SelectAll();
             *  return;
             * }*/

            // Pal dir
            try
            {
                bg.PalDir = ushort.Parse(txtPalDir.Text);
            }
            catch
            {
                txtPalDir.SelectAll();
                return;
            }

            // Pal start
            try
            {
                bg.PalStart = ushort.Parse(txtPalStart.Text);
            }
            catch
            {
                txtPalStart.SelectAll();
                return;
            }

            // Pal end
            try
            {
                bg.PalEnd = ushort.Parse(txtPalEnd.Text);
            }
            catch
            {
                txtPalEnd.SelectAll();
                return;
            }

            // Pal delay
            try
            {
                bg.PalDelay = ushort.Parse(txtPalDelay.Text);
            }
            catch
            {
                txtPalDelay.SelectAll();
                return;
            }

            // Drift H
            try
            {
                bg.DriftH = short.Parse(txtDriftH.Text);
            }
            catch
            {
                txtDriftH.SelectAll();
                return;
            }

            // Drift V
            try
            {
                bg.DriftV = short.Parse(txtDriftV.Text);
            }
            catch
            {
                txtDriftV.SelectAll();
                return;
            }

            // Ampl H
            try
            {
                bg.AmplH = short.Parse(txtAmplH.Text);
            }
            catch
            {
                txtAmplH.SelectAll();
                return;
            }

            // Ampl V
            try
            {
                bg.AmplV = short.Parse(txtAmplV.Text);
            }
            catch
            {
                txtAmplV.SelectAll();
                return;
            }

            // Freq H
            try
            {
                bg.FreqH = short.Parse(txtFreqH.Text);
            }
            catch
            {
                txtFreqH.SelectAll();
                return;
            }

            // Freq V
            try
            {
                bg.FreqV = short.Parse(txtFreqV.Text);
            }
            catch
            {
                txtFreqV.SelectAll();
                return;
            }

            // Wavenum H
            try
            {
                bg.WavenumH = short.Parse(txtWavenumH.Text);
            }
            catch
            {
                txtWavenumH.SelectAll();
                return;
            }

            // Wavenum V
            try
            {
                bg.WavenumV = short.Parse(txtWavenumV.Text);
            }
            catch
            {
                txtWavenumV.SelectAll();
                return;
            }

            if (index > 0)
            {
                // Arrangement
                GfxBattleBgTable.SetArr(bg.ArrEntry, arrEditor.GetArrangement());

                // Graphics
                int gfxPointer = GfxBattleBgTable.GetEntry(bg.GfxEntry)[0];
                arrEditor.GetTileset(M3Rom.Rom, gfxPointer);

                // Palette
                bg.Palette = arrEditor.GetPalette();
            }

            bg.Save();

            int currentpal   = arrEditor.CurrentPalette;
            int currenttile  = arrEditor.CurrentTile;
            int primarycol   = arrEditor.PrimaryColorIndex;
            int secondarycol = arrEditor.SecondaryColorIndex;

            cboEntry_SelectedIndexChanged(null, null);

            arrEditor.CurrentPalette      = currentpal;
            arrEditor.PrimaryColorIndex   = primarycol;
            arrEditor.SecondaryColorIndex = secondarycol;
            arrEditor.CurrentTile         = currenttile;
        }