diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.Designer.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.Designer.cs
index e9dd9ee4ac..28e39a0335 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.Designer.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.Designer.cs
@@ -49,6 +49,7 @@
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
+ this.button6 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// panel1
@@ -245,11 +246,23 @@
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
+ // button6
+ //
+ this.button6.Location = new System.Drawing.Point(42, 197);
+ this.button6.Name = "button6";
+ this.button6.Size = new System.Drawing.Size(75, 23);
+ this.button6.TabIndex = 28;
+ this.button6.Text = "Load...";
+ this.button6.UseVisualStyleBackColor = true;
+ this.button6.Click += new System.EventHandler(this.button6_Click);
+ //
// ColorChooserForm
//
+ this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(315, 259);
+ this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
@@ -273,6 +286,8 @@
this.Controls.Add(this.panel1);
this.Name = "ColorChooserForm";
this.Text = "ColorChooserForm";
+ this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ColorChooserForm_DragDrop);
+ this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ColorChooserForm_DragEnter);
this.ResumeLayout(false);
this.PerformLayout();
@@ -301,5 +316,6 @@
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
+ private System.Windows.Forms.Button button6;
}
}
\ No newline at end of file
diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.cs
index 54c905255d..741fa6cb28 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/ColorChooserForm.cs
@@ -6,6 +6,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
+using System.IO;
namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
{
@@ -126,13 +127,66 @@ namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
}
}
+ ///
+ /// load gambatte-style .pal file
+ ///
+ ///
+ /// null on failure
+ public static int[] LoadPalFile(TextReader f)
+ {
+ Dictionary lines = new Dictionary();
+
+ string line;
+ while ((line = f.ReadLine()) != null)
+ {
+ int i = line.IndexOf('=');
+ if (i < 0)
+ continue;
+ try
+ {
+ lines.Add(line.Substring(0, i), int.Parse(line.Substring(i + 1)));
+ }
+ catch (FormatException)
+ {
+ }
+ }
+
+ int[] ret = new int[12];
+ try
+ {
+ ret[0] = lines["Background0"];
+ ret[1] = lines["Background1"];
+ ret[2] = lines["Background2"];
+ ret[3] = lines["Background3"];
+ ret[4] = lines["Sprite%2010"];
+ ret[5] = lines["Sprite%2011"];
+ ret[6] = lines["Sprite%2012"];
+ ret[7] = lines["Sprite%2013"];
+ ret[8] = lines["Sprite%2020"];
+ ret[9] = lines["Sprite%2021"];
+ ret[10] = lines["Sprite%2022"];
+ ret[11] = lines["Sprite%2023"];
+ }
+ catch (KeyNotFoundException)
+ {
+ return null;
+ }
+ return ret;
+ }
+
+ void SetAllColors(int[] colors)
+ {
+ // fix alpha to 255 in created color objects, else problems
+ for (int i = 0; i < this.colors.Length; i++)
+ this.colors[i] = Color.FromArgb(255, Color.FromArgb(colors[i]));
+ RefreshAllBackdrops();
+ }
+
public static bool DoColorChooserFormDialog(int[] colors)
{
using (var dlg = new ColorChooserForm())
{
- for (int i = 0; i < dlg.colors.Length; i++)
- dlg.colors[i] = Color.FromArgb(255, Color.FromArgb(colors[i]));
- dlg.RefreshAllBackdrops();
+ dlg.SetAllColors(colors);
var result = dlg.ShowDialog();
if (result != DialogResult.OK)
@@ -147,5 +201,61 @@ namespace BizHawk.Emulation.Consoles.Nintendo.Gameboy
}
}
}
+
+ void LoadColorFile(string filename)
+ {
+ try
+ {
+ using (StreamReader f = new StreamReader(filename))
+ {
+ int[] newcolors = LoadPalFile(f);
+ if (newcolors == null)
+ throw new Exception();
+
+ SetAllColors(newcolors);
+ }
+ }
+ catch
+ {
+ MessageBox.Show(this, "Error loading .pal file!");
+ }
+ }
+
+
+ private void button6_Click(object sender, EventArgs e)
+ {
+ using (var ofd = new OpenFileDialog())
+ {
+ //ofd.InitialDirectory =
+ ofd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*";
+ ofd.RestoreDirectory = true;
+
+ var result = ofd.ShowDialog(this);
+ if (result != System.Windows.Forms.DialogResult.OK)
+ return;
+
+ LoadColorFile(ofd.FileName);
+ }
+ }
+
+ private void ColorChooserForm_DragDrop(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
+ {
+ string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
+
+ if (files.Length > 1)
+ return;
+ LoadColorFile(files[0]);
+ }
+ }
+
+ private void ColorChooserForm_DragEnter(object sender, DragEventArgs e)
+ {
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
+ e.Effect = DragDropEffects.Move;
+ else
+ e.Effect = DragDropEffects.None;
+ }
}
}
diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
index 4caa51ddf9..ee5ae856c8 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
@@ -430,6 +430,10 @@ namespace BizHawk.Emulation.Consoles.GB
get { return 0; }
}
+ #endregion
+
+ #region palette
+
///
/// palette colors to display in dmg mode
///
@@ -464,9 +468,6 @@ namespace BizHawk.Emulation.Consoles.GB
LibGambatte.gambatte_setdmgpalettecolor(GambatteState, (LibGambatte.PalType)(i / 4), (uint)i % 4, (uint)dmgcolors[i]);
}
-
-
-
#endregion
#region ISoundProvider