2011-06-11 14:40:00 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-10-27 22:07:40 +00:00
|
|
|
|
using BizHawk.Common;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2013-11-14 13:15:41 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.NES;
|
2019-01-12 15:32:01 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.SubNESHawk;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-06-11 14:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class NESGraphicsConfig : Form
|
|
|
|
|
{
|
2014-07-27 01:19:33 +00:00
|
|
|
|
// TODO:
|
|
|
|
|
// Allow selection of palette file from archive
|
|
|
|
|
// Hotkeys for BG & Sprite display toggle
|
|
|
|
|
// NTSC filter settings? Hue, Tint (This should probably be a client thing, not a nes specific thing?)
|
2017-05-31 14:47:38 +00:00
|
|
|
|
private NES _nes;
|
2019-01-12 15:32:01 +00:00
|
|
|
|
private SubNESHawk _subneshawk;
|
2017-05-31 14:47:38 +00:00
|
|
|
|
private NES.NESSettings _settings;
|
|
|
|
|
private Bitmap _bmp;
|
2011-06-11 14:40:00 +00:00
|
|
|
|
|
|
|
|
|
public NESGraphicsConfig()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NESGraphicsConfig_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-01-12 15:32:01 +00:00
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
|
|
|
|
_nes = (NES)Global.Emulator;
|
|
|
|
|
_settings = _nes.GetSettings();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_subneshawk = (SubNESHawk)Global.Emulator;
|
|
|
|
|
_settings = _subneshawk.GetSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-24 03:08:32 +00:00
|
|
|
|
LoadStuff();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadStuff()
|
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
NTSC_FirstLineNumeric.Value = _settings.NTSC_TopLine;
|
|
|
|
|
NTSC_LastLineNumeric.Value = _settings.NTSC_BottomLine;
|
|
|
|
|
PAL_FirstLineNumeric.Value = _settings.PAL_TopLine;
|
|
|
|
|
PAL_LastLineNumeric.Value = _settings.PAL_BottomLine;
|
|
|
|
|
AllowMoreSprites.Checked = _settings.AllowMoreThanEightSprites;
|
|
|
|
|
ClipLeftAndRightCheckBox.Checked = _settings.ClipLeftAndRight;
|
|
|
|
|
DispSprites.Checked = _settings.DispSprites;
|
|
|
|
|
DispBackground.Checked = _settings.DispBackground;
|
|
|
|
|
BGColorDialog.Color = Color.FromArgb(unchecked(_settings.BackgroundColor | (int)0xFF000000));
|
|
|
|
|
checkUseBackdropColor.Checked = (_settings.BackgroundColor & 0xFF000000) != 0;
|
2011-06-11 14:40:00 +00:00
|
|
|
|
SetColorBox();
|
2014-01-06 20:23:21 +00:00
|
|
|
|
SetPaletteImage();
|
2011-06-11 14:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BrowsePalette_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog
|
|
|
|
|
{
|
2013-08-11 21:48:17 +00:00
|
|
|
|
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["NES", "Palettes"].Path, "NES"),
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Filter = "Palette Files (.pal)|*.PAL|All Files (*.*)|*.*",
|
|
|
|
|
RestoreDirectory = true
|
|
|
|
|
};
|
2011-06-11 14:40:00 +00:00
|
|
|
|
|
|
|
|
|
var result = ofd.ShowDialog();
|
|
|
|
|
if (result != DialogResult.OK)
|
2013-04-15 02:14:14 +00:00
|
|
|
|
{
|
2011-06-11 14:40:00 +00:00
|
|
|
|
return;
|
2013-04-15 02:14:14 +00:00
|
|
|
|
}
|
2011-06-11 14:40:00 +00:00
|
|
|
|
|
|
|
|
|
PalettePath.Text = ofd.FileName;
|
2014-01-06 20:23:21 +00:00
|
|
|
|
AutoLoadPalette.Checked = true;
|
|
|
|
|
SetPaletteImage();
|
2011-06-11 14:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 20:23:21 +00:00
|
|
|
|
private void SetPaletteImage()
|
2011-06-11 14:40:00 +00:00
|
|
|
|
{
|
2014-01-06 20:23:21 +00:00
|
|
|
|
var pal = ResolvePalette(false);
|
|
|
|
|
|
|
|
|
|
int w = pictureBoxPalette.Size.Width;
|
|
|
|
|
int h = pictureBoxPalette.Size.Height;
|
|
|
|
|
|
2017-05-31 14:47:38 +00:00
|
|
|
|
_bmp = new Bitmap(w, h);
|
2014-01-06 20:23:21 +00:00
|
|
|
|
for (int j = 0; j < h; j++)
|
|
|
|
|
{
|
|
|
|
|
int cy = j * 4 / h;
|
|
|
|
|
for (int i = 0; i < w; i++)
|
|
|
|
|
{
|
|
|
|
|
int cx = i * 16 / w;
|
2017-05-31 14:47:38 +00:00
|
|
|
|
int cindex = (cy * 16) + cx;
|
2014-01-06 20:23:21 +00:00
|
|
|
|
Color col = Color.FromArgb(0xff, pal[cindex, 0], pal[cindex, 1], pal[cindex, 2]);
|
2017-05-31 14:47:38 +00:00
|
|
|
|
_bmp.SetPixel(i, j, col);
|
2014-01-06 20:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-31 14:47:38 +00:00
|
|
|
|
|
|
|
|
|
pictureBoxPalette.Image = _bmp;
|
2014-01-06 20:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 19:09:49 +00:00
|
|
|
|
private byte[,] ResolvePalette(bool showmsg = false)
|
2014-01-06 20:23:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (AutoLoadPalette.Checked) // checkbox checked: try to load palette from file
|
2011-06-11 14:40:00 +00:00
|
|
|
|
{
|
2013-12-22 06:55:34 +00:00
|
|
|
|
if (PalettePath.Text.Length > 0)
|
2011-06-11 14:40:00 +00:00
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
var palette = new HawkFile(PalettePath.Text);
|
2013-12-22 06:55:34 +00:00
|
|
|
|
|
2017-05-31 14:47:38 +00:00
|
|
|
|
if (palette.Exists)
|
2011-06-11 16:22:48 +00:00
|
|
|
|
{
|
2015-01-19 13:38:08 +00:00
|
|
|
|
var data = Palettes.Load_FCEUX_Palette(HawkFile.ReadAllBytes(palette.Name));
|
2017-05-31 14:47:38 +00:00
|
|
|
|
if (showmsg)
|
|
|
|
|
{
|
|
|
|
|
GlobalWin.OSD.AddMessage("Palette file loaded: " + palette.Name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 20:23:21 +00:00
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
return _settings.Palette;
|
2011-06-11 16:22:48 +00:00
|
|
|
|
}
|
2011-06-11 14:40:00 +00:00
|
|
|
|
}
|
2014-01-06 20:23:21 +00:00
|
|
|
|
else // no filename: interpret this as "reset to default"
|
2013-12-22 06:55:34 +00:00
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
if (showmsg)
|
|
|
|
|
{
|
|
|
|
|
GlobalWin.OSD.AddMessage("Standard Palette set");
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-13 19:09:49 +00:00
|
|
|
|
return (byte[,])Palettes.QuickNESPalette.Clone();
|
2013-12-22 06:55:34 +00:00
|
|
|
|
}
|
2011-06-11 16:22:48 +00:00
|
|
|
|
}
|
2014-01-06 20:23:21 +00:00
|
|
|
|
else // checkbox unchecked: we're reusing whatever palette was set
|
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
return _settings.Palette;
|
2014-01-06 20:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 14:47:38 +00:00
|
|
|
|
private void Ok_Click(object sender, EventArgs e)
|
2014-01-06 20:23:21 +00:00
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
_settings.Palette = ResolvePalette(true);
|
|
|
|
|
|
|
|
|
|
_settings.NTSC_TopLine = (int)NTSC_FirstLineNumeric.Value;
|
|
|
|
|
_settings.NTSC_BottomLine = (int)NTSC_LastLineNumeric.Value;
|
|
|
|
|
_settings.PAL_TopLine = (int)PAL_FirstLineNumeric.Value;
|
|
|
|
|
_settings.PAL_BottomLine = (int)PAL_LastLineNumeric.Value;
|
|
|
|
|
_settings.AllowMoreThanEightSprites = AllowMoreSprites.Checked;
|
|
|
|
|
_settings.ClipLeftAndRight = ClipLeftAndRightCheckBox.Checked;
|
|
|
|
|
_settings.DispSprites = DispSprites.Checked;
|
|
|
|
|
_settings.DispBackground = DispBackground.Checked;
|
|
|
|
|
_settings.BackgroundColor = BGColorDialog.Color.ToArgb();
|
2011-06-11 22:15:08 +00:00
|
|
|
|
if (!checkUseBackdropColor.Checked)
|
2017-05-31 14:47:38 +00:00
|
|
|
|
{
|
|
|
|
|
_settings.BackgroundColor &= 0x00FFFFFF;
|
|
|
|
|
}
|
2013-12-22 00:44:39 +00:00
|
|
|
|
|
2019-01-12 15:32:01 +00:00
|
|
|
|
if (Global.Emulator is NES)
|
|
|
|
|
{
|
|
|
|
|
_nes.PutSettings(_settings);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_subneshawk.PutSettings(_settings);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Close();
|
2011-06-11 14:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetColorBox()
|
|
|
|
|
{
|
|
|
|
|
int color = BGColorDialog.Color.ToArgb();
|
2017-05-31 14:47:38 +00:00
|
|
|
|
BackGroundColorNumber.Text = $"{color:X8}".Substring(2, 6);
|
2011-06-11 14:40:00 +00:00
|
|
|
|
BackgroundColorPanel.BackColor = BGColorDialog.Color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeBGColor_Click(object sender, EventArgs e)
|
2012-09-03 21:52:51 +00:00
|
|
|
|
{
|
|
|
|
|
ChangeBG();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeBG()
|
2011-06-11 14:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
if (BGColorDialog.ShowDialog() == DialogResult.OK)
|
2012-09-03 21:52:51 +00:00
|
|
|
|
{
|
2011-06-11 14:40:00 +00:00
|
|
|
|
SetColorBox();
|
2012-09-03 21:52:51 +00:00
|
|
|
|
}
|
2011-06-11 14:40:00 +00:00
|
|
|
|
}
|
2012-03-25 08:52:52 +00:00
|
|
|
|
|
2017-05-31 14:47:38 +00:00
|
|
|
|
private void BtnAreaStandard_Click(object sender, EventArgs e)
|
2012-03-25 08:52:52 +00:00
|
|
|
|
{
|
2013-03-25 01:59:34 +00:00
|
|
|
|
NTSC_FirstLineNumeric.Value = 8;
|
|
|
|
|
NTSC_LastLineNumeric.Value = 231;
|
2012-03-25 08:52:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 14:47:38 +00:00
|
|
|
|
private void BtnAreaFull_Click(object sender, EventArgs e)
|
2012-03-25 08:52:52 +00:00
|
|
|
|
{
|
2013-03-25 01:59:34 +00:00
|
|
|
|
NTSC_FirstLineNumeric.Value = 0;
|
|
|
|
|
NTSC_LastLineNumeric.Value = 239;
|
2012-03-25 08:52:52 +00:00
|
|
|
|
}
|
2012-09-03 21:52:51 +00:00
|
|
|
|
|
|
|
|
|
private void BackgroundColorPanel_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ChangeBG();
|
|
|
|
|
}
|
2012-09-24 03:08:32 +00:00
|
|
|
|
|
|
|
|
|
private void RestoreDefaultsButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-31 14:47:38 +00:00
|
|
|
|
_settings = new NES.NESSettings();
|
2013-12-22 00:44:39 +00:00
|
|
|
|
LoadStuff();
|
2012-09-24 03:08:32 +00:00
|
|
|
|
}
|
2014-01-06 20:23:21 +00:00
|
|
|
|
|
|
|
|
|
private void AutoLoadPalette_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetPaletteImage();
|
|
|
|
|
}
|
2011-06-11 14:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|