More multiclient refactoring

This commit is contained in:
adelikat 2013-04-15 02:14:14 +00:00
parent be2937fdec
commit 7199b64a95
50 changed files with 989 additions and 1270 deletions

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.MultiClient.GBtools; using BizHawk.MultiClient.GBtools;
@ -15,16 +10,16 @@ namespace BizHawk.MultiClient.GBAtools
Emulation.Consoles.Nintendo.GBA.GBA gba; Emulation.Consoles.Nintendo.GBA.GBA gba;
// emulator memory areas // emulator memory areas
IntPtr vram; private IntPtr vram;
IntPtr oam; private IntPtr oam;
IntPtr mmio; private IntPtr mmio;
IntPtr palram; private IntPtr palram;
// color conversion to RGB888 // color conversion to RGB888
int[] ColorConversion; private readonly int[] ColorConversion;
MobileBmpView bg0, bg1, bg2, bg3, bgpal, sppal, sprites, bgtiles16, bgtiles256, sptiles16, sptiles256; MobileBmpView bg0, bg1, bg2, bg3, bgpal, sppal, sprites, bgtiles16, bgtiles256, sptiles16, sptiles256;
MobileDetailView details, memory; MobileDetailView memory;
public GBAGPUView() public GBAGPUView()
{ {
@ -331,13 +326,12 @@ namespace BizHawk.MultiClient.GBAtools
if (!attr0.Bit(8) && attr0.Bit(9)) if (!attr0.Bit(8) && attr0.Bit(9))
return; // 2x with affine off return; // 2x with affine off
int tw, th;
int shape = attr0 >> 14; int shape = attr0 >> 14;
if (shape == 3) if (shape == 3)
return; return;
int size = attr1 >> 14; int size = attr1 >> 14;
tw = spritesizes[shape, size, 0]; int tw = spritesizes[shape, size, 0];
th = spritesizes[shape, size, 1]; int th = spritesizes[shape, size, 1];
bool eightbit = attr0.Bit(13); bool eightbit = attr0.Bit(13);
bool hflip = attr1.Bit(12); bool hflip = attr1.Bit(12);
@ -649,7 +643,7 @@ namespace BizHawk.MultiClient.GBAtools
sptiles256 = MakeMBVWidget("Sprite Tiles (8bpp)", 128, 256); sptiles256 = MakeMBVWidget("Sprite Tiles (8bpp)", 128, 256);
bgtiles16 = MakeMBVWidget("Background Tiles (4bpp)", 512, 256); bgtiles16 = MakeMBVWidget("Background Tiles (4bpp)", 512, 256);
bgtiles256 = MakeMBVWidget("Background Tiles (8bpp)", 256, 256); bgtiles256 = MakeMBVWidget("Background Tiles (8bpp)", 256, 256);
details = MakeMDVWidget("Details", 128, 192); MakeMDVWidget("Details", 128, 192);
memory = MakeMDVWidget("Details - Memory", 128, 192); memory = MakeMDVWidget("Details - Memory", 128, 192);
listBoxWidgets.EndUpdate(); listBoxWidgets.EndUpdate();
@ -694,7 +688,7 @@ namespace BizHawk.MultiClient.GBAtools
/// <summary>belongs in ToolsBefore</summary> /// <summary>belongs in ToolsBefore</summary>
public void UpdateValues() public void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) if (!IsHandleCreated || IsDisposed)
return; return;
if (gba != null) if (gba != null)
{ {

View File

@ -36,9 +36,9 @@
this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.bmpView1 = new BizHawk.MultiClient.GBtools.BmpView();
this.buttonOK = new System.Windows.Forms.Button(); this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.bmpView1 = new BizHawk.MultiClient.GBtools.BmpView();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -140,6 +140,14 @@
this.groupBox2.TabStop = false; this.groupBox2.TabStop = false;
this.groupBox2.Text = "Preview"; this.groupBox2.Text = "Preview";
// //
// bmpView1
//
this.bmpView1.Location = new System.Drawing.Point(6, 19);
this.bmpView1.Name = "bmpView1";
this.bmpView1.Size = new System.Drawing.Size(256, 128);
this.bmpView1.TabIndex = 3;
this.bmpView1.Text = "bmpView1";
//
// buttonOK // buttonOK
// //
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK; this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
@ -160,14 +168,6 @@
this.buttonCancel.Text = "Cancel"; this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.UseVisualStyleBackColor = true;
// //
// bmpView1
//
this.bmpView1.Location = new System.Drawing.Point(6, 19);
this.bmpView1.Name = "bmpView1";
this.bmpView1.Size = new System.Drawing.Size(256, 128);
this.bmpView1.TabIndex = 3;
this.bmpView1.Text = "bmpView1";
//
// CGBColorChooserForm // CGBColorChooserForm
// //
this.AcceptButton = this.buttonOK; this.AcceptButton = this.buttonOK;
@ -182,6 +182,7 @@
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "CGBColorChooserForm"; this.Name = "CGBColorChooserForm";
this.Text = "Gameboy Color Palette Config"; this.Text = "Gameboy Color Palette Config";
this.Load += new System.EventHandler(this.CGBColorChooserForm_Load);
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.GB; using BizHawk.Emulation.Consoles.GB;
@ -69,7 +64,8 @@ namespace BizHawk.MultiClient.GBtools
type = GBColors.ColorType.vbabgbold; type = GBColors.ColorType.vbabgbold;
if (sender == radioButton6) if (sender == radioButton6)
type = GBColors.ColorType.gba; type = GBColors.ColorType.gba;
if ((sender as RadioButton).Checked) var radio_button = sender as RadioButton;
if (radio_button != null && radio_button.Checked)
RefreshType(); RefreshType();
} }
@ -88,5 +84,10 @@ namespace BizHawk.MultiClient.GBtools
} }
} }
private void CGBColorChooserForm_Load(object sender, EventArgs e)
{
}
} }
} }

View File

@ -266,8 +266,8 @@
// //
// textBox1 // textBox1
// //
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.BackColor = System.Drawing.SystemColors.Control; this.textBox1.BackColor = System.Drawing.SystemColors.Control;
this.textBox1.Location = new System.Drawing.Point(17, 195); this.textBox1.Location = new System.Drawing.Point(17, 195);
this.textBox1.Name = "textBox1"; this.textBox1.Name = "textBox1";
@ -343,6 +343,7 @@
this.Name = "ColorChooserForm"; this.Name = "ColorChooserForm";
this.ShowIcon = false; this.ShowIcon = false;
this.Text = "Gameboy Palette Config"; this.Text = "Gameboy Palette Config";
this.Load += new System.EventHandler(this.ColorChooserForm_Load);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ColorChooserForm_DragDrop); this.DragDrop += new System.Windows.Forms.DragEventHandler(this.ColorChooserForm_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ColorChooserForm_DragEnter); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.ColorChooserForm_DragEnter);
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -13,7 +13,7 @@ namespace BizHawk.MultiClient.GBtools
InitializeComponent(); InitializeComponent();
} }
Color[] colors = new Color[12]; private readonly Color[] colors = new Color[12];
/// <summary> /// <summary>
/// the most recently loaded or saved palette file /// the most recently loaded or saved palette file
@ -27,7 +27,7 @@ namespace BizHawk.MultiClient.GBtools
{ {
0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000, 0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000,
0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000, 0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000,
0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000, 0x00ffffff, 0x00aaaaaa, 0x00555555, 0x00000000
}; };
/// <summary> /// <summary>
@ -37,7 +37,7 @@ namespace BizHawk.MultiClient.GBtools
{ {
10798341, 8956165, 1922333, 337157, 10798341, 8956165, 1922333, 337157,
10798341, 8956165, 1922333, 337157, 10798341, 8956165, 1922333, 337157,
10798341, 8956165, 1922333, 337157, 10798341, 8956165, 1922333, 337157
}; };
@ -72,7 +72,7 @@ namespace BizHawk.MultiClient.GBtools
{ {
for (int i = firstindex + 1; i < lastindex; i++) for (int i = firstindex + 1; i < lastindex; i++)
{ {
double pos = (double)(i - firstindex) / (double)(lastindex - firstindex); double pos = (i - firstindex) / (double)(lastindex - firstindex);
colors[i] = betweencolor(colors[firstindex], colors[lastindex], pos); colors[i] = betweencolor(colors[firstindex], colors[lastindex], pos);
} }
RefreshAllBackdrops(); RefreshAllBackdrops();
@ -143,7 +143,7 @@ namespace BizHawk.MultiClient.GBtools
var result = dlg.ShowDialog(this); var result = dlg.ShowDialog(this);
if (result == System.Windows.Forms.DialogResult.OK) if (result == DialogResult.OK)
{ {
if (colors[i] != dlg.Color) if (colors[i] != dlg.Color)
{ {
@ -158,7 +158,7 @@ namespace BizHawk.MultiClient.GBtools
/// <summary> /// <summary>
/// ini keys for gambatte palette file /// ini keys for gambatte palette file
/// </summary> /// </summary>
static string[] paletteinikeys = private static readonly string[] paletteinikeys =
{ {
"Background0", "Background0",
"Background1", "Background1",
@ -220,14 +220,17 @@ namespace BizHawk.MultiClient.GBtools
{ {
f.WriteLine("[General]"); f.WriteLine("[General]");
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
f.WriteLine(string.Format("{0}={1}", paletteinikeys[i], colors[i])); f.WriteLine(String.Format("{0}={1}", paletteinikeys[i], colors[i]));
} }
void SetAllColors(int[] colors) void SetAllColors(int[] _colors)
{ {
// fix alpha to 255 in created color objects, else problems // fix alpha to 255 in created color objects, else problems
for (int i = 0; i < this.colors.Length; i++) for (int i = 0; i < colors.Length; i++)
this.colors[i] = Color.FromArgb(255, Color.FromArgb(colors[i])); {
colors[i] = Color.FromArgb(255, Color.FromArgb(_colors[i]));
}
RefreshAllBackdrops(); RefreshAllBackdrops();
} }
@ -318,8 +321,10 @@ namespace BizHawk.MultiClient.GBtools
ofd.RestoreDirectory = true; ofd.RestoreDirectory = true;
var result = ofd.ShowDialog(this); var result = ofd.ShowDialog(this);
if (result != System.Windows.Forms.DialogResult.OK) if (result != DialogResult.OK)
{
return; return;
}
LoadColorFile(ofd.FileName, true); LoadColorFile(ofd.FileName, true);
} }
@ -362,8 +367,10 @@ namespace BizHawk.MultiClient.GBtools
sfd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*"; sfd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*";
sfd.RestoreDirectory = true; sfd.RestoreDirectory = true;
var result = sfd.ShowDialog(this); var result = sfd.ShowDialog(this);
if (result != System.Windows.Forms.DialogResult.OK) if (result != DialogResult.OK)
{
return; return;
}
SaveColorFile(sfd.FileName); SaveColorFile(sfd.FileName);
} }
@ -386,5 +393,10 @@ namespace BizHawk.MultiClient.GBtools
currentfile = ""; currentfile = "";
SetAllColors(DefaultCGBColors); SetAllColors(DefaultCGBColors);
} }
private void ColorChooserForm_Load(object sender, EventArgs e)
{
}
} }
} }

View File

@ -1,12 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace BizHawk.MultiClient.GBtools namespace BizHawk.MultiClient.GBtools
{ {
@ -36,7 +31,7 @@ namespace BizHawk.MultiClient.GBtools
IntPtr oam; IntPtr oam;
bool cgb; // set once at start bool cgb; // set once at start
int lcdc; // set at each callback int _lcdc; // set at each callback
IntPtr tilespal; // current palette to use on tiles IntPtr tilespal; // current palette to use on tiles
@ -72,7 +67,7 @@ namespace BizHawk.MultiClient.GBtools
KeyPreview = true; KeyPreview = true;
messagetimer.Interval = 5000; messagetimer.Interval = 5000;
messagetimer.Tick += new EventHandler(messagetimer_Tick); messagetimer.Tick += messagetimer_Tick;
checkBoxAutoLoad.Checked = Global.Config.AutoLoadGBGPUView; checkBoxAutoLoad.Checked = Global.Config.AutoLoadGBGPUView;
checkBoxSavePos.Checked = Global.Config.GBGPUViewSaveWindowPosition; checkBoxSavePos.Checked = Global.Config.GBGPUViewSaveWindowPosition;
@ -87,7 +82,7 @@ namespace BizHawk.MultiClient.GBtools
{ {
gb = Global.Emulator as Emulation.Consoles.GB.Gameboy; gb = Global.Emulator as Emulation.Consoles.GB.Gameboy;
cgb = gb.IsCGBMode(); cgb = gb.IsCGBMode();
lcdc = 0; _lcdc = 0;
if (!gb.GetGPUMemoryAreas(out vram, out bgpal, out sppal, out oam)) if (!gb.GetGPUMemoryAreas(out vram, out bgpal, out sppal, out oam))
{ {
gb = null; gb = null;
@ -365,12 +360,11 @@ namespace BizHawk.MultiClient.GBtools
void ScanlineCallback(int lcdc) void ScanlineCallback(int lcdc)
{ {
this.lcdc = lcdc; _lcdc = lcdc;
// set alpha on all pixels // set alpha on all pixels
unsafe unsafe
{ {
int* p; int* p = (int*)bgpal;
p = (int*)bgpal;
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
p[i] |= unchecked((int)0xff000000); p[i] |= unchecked((int)0xff000000);
p = (int*)sppal; p = (int*)sppal;
@ -473,7 +467,7 @@ namespace BizHawk.MultiClient.GBtools
// try to run the current mouseover, to refresh if the mouse is being held over a pane while the emulator runs // try to run the current mouseover, to refresh if the mouse is being held over a pane while the emulator runs
// this doesn't really work well; the update rate seems to be throttled // this doesn't really work well; the update rate seems to be throttled
MouseEventArgs e = new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y, 0); MouseEventArgs e = new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y, 0);
this.OnMouseMove(e); OnMouseMove(e);
} }
private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e) private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e)
@ -554,11 +548,13 @@ namespace BizHawk.MultiClient.GBtools
/// </summary> /// </summary>
public void UpdateValues() public void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) if (!IsHandleCreated || IsDisposed)
return;
if (gb != null)
{ {
if (!this.Visible) return;
}
else if (gb != null)
{
if (!Visible)
{ {
if (cbscanline_emu != -2) if (cbscanline_emu != -2)
{ {
@ -684,14 +680,14 @@ namespace BizHawk.MultiClient.GBtools
if (bmpViewDetails.Height != 64) if (bmpViewDetails.Height != 64)
bmpViewDetails.Height = 64; bmpViewDetails.Height = 64;
var sb = new StringBuilder(); var sb = new StringBuilder();
bool secondmap = win ? lcdc.Bit(6) : lcdc.Bit(3); bool secondmap = win ? _lcdc.Bit(6) : _lcdc.Bit(3);
int mapoffs = secondmap ? 0x1c00 : 0x1800; int mapoffs = secondmap ? 0x1c00 : 0x1800;
x /= 8; x /= 8;
y /= 8; y /= 8;
mapoffs += y * 32 + x; mapoffs += y * 32 + x;
byte* mapbase = (byte*)vram + mapoffs; byte* mapbase = (byte*)vram + mapoffs;
int tileindex = mapbase[0]; int tileindex = mapbase[0];
if (win || !lcdc.Bit(4)) // 0x9000 base if (win || !_lcdc.Bit(4)) // 0x9000 base
if (tileindex < 128) if (tileindex < 128)
tileindex += 256; // compute all if from 0x8000 base tileindex += 256; // compute all if from 0x8000 base
int tileoffs = tileindex * 16; int tileoffs = tileindex * 16;
@ -719,7 +715,7 @@ namespace BizHawk.MultiClient.GBtools
unsafe void SpriteMouseover(int x, int y) unsafe void SpriteMouseover(int x, int y)
{ {
bool tall = lcdc.Bit(2); bool tall = _lcdc.Bit(2);
x /= 8; x /= 8;
y /= 8; y /= 8;
bmpViewDetails.ChangeBitmapSize(8, tall ? 16 : 8); bmpViewDetails.ChangeBitmapSize(8, tall ? 16 : 8);
@ -884,9 +880,9 @@ namespace BizHawk.MultiClient.GBtools
private void bmpView_MouseClick(object sender, MouseEventArgs e) private void bmpView_MouseClick(object sender, MouseEventArgs e)
{ {
if (e.Button == System.Windows.Forms.MouseButtons.Right) if (e.Button == MouseButtons.Right)
SetFreeze(); SetFreeze();
else if (e.Button == System.Windows.Forms.MouseButtons.Left) else if (e.Button == MouseButtons.Left)
{ {
if (sender == bmpViewBGPal) if (sender == bmpViewBGPal)
tilespal = bgpal + e.X / 16 * 16; tilespal = bgpal + e.X / 16 * 16;
@ -897,23 +893,23 @@ namespace BizHawk.MultiClient.GBtools
#region copyimage #region copyimage
Timer messagetimer = new Timer(); private readonly Timer messagetimer = new Timer();
private void GBGPUView_KeyDown(object sender, KeyEventArgs e) private void GBGPUView_KeyDown(object sender, KeyEventArgs e)
{ {
if (Control.ModifierKeys.HasFlag(Keys.Control) && e.KeyCode == Keys.C) if (ModifierKeys.HasFlag(Keys.Control) && e.KeyCode == Keys.C)
{ {
// find the control under the mouse // find the control under the mouse
Point m = System.Windows.Forms.Cursor.Position; Point m = Cursor.Position;
Control top = this; Control top = this;
Control found = null; Control found;
do do
{ {
found = top.GetChildAtPoint(top.PointToClient(m)); found = top.GetChildAtPoint(top.PointToClient(m));
top = found; top = found;
} while (found != null && found.HasChildren); } while (found != null && found.HasChildren);
if (found != null && found is BmpView) if (found is BmpView)
{ {
var bv = found as BmpView; var bv = found as BmpView;
Clipboard.SetImage(bv.bmp); Clipboard.SetImage(bv.bmp);
@ -962,7 +958,7 @@ namespace BizHawk.MultiClient.GBtools
Global.Sound.StopSound(); Global.Sound.StopSound();
var result = dlg.ShowDialog(); var result = dlg.ShowDialog();
Global.Sound.StartSound(); Global.Sound.StartSound();
if (result == System.Windows.Forms.DialogResult.OK) if (result == DialogResult.OK)
{ {
// force full opaque // force full opaque
spriteback = Color.FromArgb(255, dlg.Color); spriteback = Color.FromArgb(255, dlg.Color);

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
#if WINDOWS #if WINDOWS
using SlimDX.Direct3D9; using SlimDX.Direct3D9;
using SlimDX.DirectSound; using SlimDX.DirectSound;
using System.Drawing;
#endif #endif
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -69,58 +69,58 @@ namespace BizHawk.MultiClient
public static Controller Commodore64Controls; public static Controller Commodore64Controls;
public static AutofireController AutofireCommodore64Controls; public static AutofireController AutofireCommodore64Controls;
public static readonly Dictionary<string, Dictionary<string, string>> BUTTONS = new Dictionary<string, Dictionary<string, string>>() public static readonly Dictionary<string, Dictionary<string, string>> BUTTONS = new Dictionary<string, Dictionary<string, string>>
{ {
{ {
"Gameboy Controller", new Dictionary<string, string>() "Gameboy Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"},
{"A", "A"} {"A", "A"}
} }
}, },
{ {
"GBA Controller", new Dictionary<string, string>() "GBA Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"},
{"A", "A"}, {"L", "L"}, {"R", "R"} {"A", "A"}, {"L", "L"}, {"R", "R"}
} }
}, },
{ {
"Genesis 3-Button Controller", new Dictionary<string, string>() "Genesis 3-Button Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Start", "S"}, {"A", "A"}, {"B", "B"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Start", "S"}, {"A", "A"}, {"B", "B"},
{"C", "C"} {"C", "C"}
} }
}, },
{ {
"NES Controller", new Dictionary<string, string>() "NES Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"},
{"A", "A"} {"A", "A"}
} }
}, },
{ {
"SNES Controller", new Dictionary<string, string>() "SNES Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Start", "S"}, {"B", "B"},
{"A", "A"}, {"X", "X"}, {"Y", "Y"}, {"L", "L"}, {"R", "R"} {"A", "A"}, {"X", "X"}, {"Y", "Y"}, {"L", "L"}, {"R", "R"}
} }
}, },
{ {
"PC Engine Controller", new Dictionary<string, string>() "PC Engine Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Run", "r"}, {"B2", "2"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Select", "s"}, {"Run", "r"}, {"B2", "2"},
{"B1", "1"} {"B1", "1"}
} }
}, },
{ {
"SMS Controller", new Dictionary<string, string>() "SMS Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"B1", "1"}, {"B2", "2"} {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"B1", "1"}, {"B2", "2"}
} }
}, },
{ {
"TI83 Controller", new Dictionary<string, string>() "TI83 Controller", new Dictionary<string, string>
{ {
{"0", "0"}, {"1", "1"}, {"2", "2"}, {"3", "3"}, {"4", "4"}, {"5", "5"}, {"6", "6"}, {"7", "7"}, {"0", "0"}, {"1", "1"}, {"2", "2"}, {"3", "3"}, {"4", "4"}, {"5", "5"}, {"6", "6"}, {"7", "7"},
{"8", "8"}, {"9", "9"}, {"DOT", "`"}, {"ON", "O"}, {"ENTER", "="}, {"UP", "U"}, {"DOWN", "D"}, {"8", "8"}, {"9", "9"}, {"DOT", "`"}, {"ON", "O"}, {"ENTER", "="}, {"UP", "U"}, {"DOWN", "D"},
@ -133,25 +133,25 @@ namespace BizHawk.MultiClient
} }
}, },
{ {
"Atari 2600 Basic Controller", new Dictionary<string,string>() "Atari 2600 Basic Controller", new Dictionary<string,string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Button", "B"} {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Button", "B"}
} }
}, },
{ {
"Atari 7800 ProLine Joystick Controller", new Dictionary<string,string>() "Atari 7800 ProLine Joystick Controller", new Dictionary<string,string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Trigger", "1"}, {"Trigger 2", "2"} {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Trigger", "1"}, {"Trigger 2", "2"}
} }
}, },
{ {
"Commodore 64 Controller", new Dictionary<string,string>() "Commodore 64 Controller", new Dictionary<string,string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Button", "B"} {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"Button", "B"}
} }
}, },
{ {
"Commodore 64 Keyboard", new Dictionary<string,string>() "Commodore 64 Keyboard", new Dictionary<string,string>
{ {
{"Key F1", "1"}, {"Key F3", "3"}, {"Key F5", "5"}, {"Key F7", "7"}, {"Key F1", "1"}, {"Key F3", "3"}, {"Key F5", "5"}, {"Key F7", "7"},
{"Key Left Arrow", "l"}, {"Key 1", "1"}, {"Key 2", "2"}, {"Key 3", "3"}, {"Key 4", "4"}, {"Key 5", "5"}, {"Key 6", "6"}, {"Key 7", "7"}, {"Key 8", "8"}, {"Key 9", "9"}, {"Key 0", "0"}, {"Key Plus", "+"}, {"Key Minus", "-"}, {"Key Pound", "l"}, {"Key Clear/Home", "c"}, {"Key Insert/Delete", "i"}, {"Key Left Arrow", "l"}, {"Key 1", "1"}, {"Key 2", "2"}, {"Key 3", "3"}, {"Key 4", "4"}, {"Key 5", "5"}, {"Key 6", "6"}, {"Key 7", "7"}, {"Key 8", "8"}, {"Key 9", "9"}, {"Key 0", "0"}, {"Key Plus", "+"}, {"Key Minus", "-"}, {"Key Pound", "l"}, {"Key Clear/Home", "c"}, {"Key Insert/Delete", "i"},
@ -162,7 +162,7 @@ namespace BizHawk.MultiClient
} }
}, },
{ {
"ColecoVision Basic Controller", new Dictionary<string, string>() "ColecoVision Basic Controller", new Dictionary<string, string>
{ {
{"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"L", "l"}, {"R", "r"}, {"Up", "U"}, {"Down", "D"}, {"Left", "L"}, {"Right", "R"}, {"L", "l"}, {"R", "r"},
{"Key1", "1"}, {"Key2", "2"}, {"Key3", "3"}, {"Key4", "4"}, {"Key5", "5"}, {"Key6", "6"}, {"Key1", "1"}, {"Key2", "2"}, {"Key3", "3"}, {"Key4", "4"}, {"Key5", "5"}, {"Key6", "6"},
@ -171,21 +171,21 @@ namespace BizHawk.MultiClient
} }
}; };
public static readonly Dictionary<string, Dictionary<string, string>> COMMANDS = new Dictionary<string, Dictionary<string, string>>() public static readonly Dictionary<string, Dictionary<string, string>> COMMANDS = new Dictionary<string, Dictionary<string, string>>
{ {
{"Atari 2600 Basic Controller", new Dictionary<string, string>() {{"Reset", "r"}, {"Select", "s"}}}, {"Atari 2600 Basic Controller", new Dictionary<string, string> {{"Reset", "r"}, {"Select", "s"}}},
{"Atari 7800 ProLine Joystick Controller", new Dictionary<string, string>() {{"Reset", "r"}, {"Select", "s"}}}, {"Atari 7800 ProLine Joystick Controller", new Dictionary<string, string>() {{"Reset", "r"}, {"Select", "s"}}},
{"Gameboy Controller", new Dictionary<string, string>() {{"Power", "P"}}}, {"Gameboy Controller", new Dictionary<string, string>() {{"Power", "P"}}},
{"GBA Controller", new Dictionary<string, string>() {{"Power", "P"}}}, {"GBA Controller", new Dictionary<string, string> {{"Power", "P"}}},
{"Genesis 3-Button Controller", new Dictionary<string, string>() {{"Reset", "r"}}}, {"Genesis 3-Button Controller", new Dictionary<string, string> {{"Reset", "r"}}},
{"NES Controller", new Dictionary<string, string>() {{"Reset", "r"}, {"Power", "P"}, {"FDS Eject", "E"}, {"FDS Insert 0", "0"}, {"FDS Insert 1", "1"}, {"VS Coin 1", "c"}, {"VS Coin 2", "C"}}}, {"NES Controller", new Dictionary<string, string> {{"Reset", "r"}, {"Power", "P"}, {"FDS Eject", "E"}, {"FDS Insert 0", "0"}, {"FDS Insert 1", "1"}, {"VS Coin 1", "c"}, {"VS Coin 2", "C"}}},
{"SNES Controller", new Dictionary<string, string>() {{"Power", "P"}, {"Reset", "r"}}}, {"SNES Controller", new Dictionary<string, string> {{"Power", "P"}, {"Reset", "r"}}},
{"PC Engine Controller", new Dictionary<string, string>() {}}, {"PC Engine Controller", new Dictionary<string, string> {}},
{"SMS Controller", new Dictionary<string, string>() {{"Pause", "p"}, {"Reset", "r"}}}, {"SMS Controller", new Dictionary<string, string> {{"Pause", "p"}, {"Reset", "r"}}},
{"TI83 Controller", new Dictionary<string, string>() {}} {"TI83 Controller", new Dictionary<string, string> {}}
}; };
public static readonly Dictionary<string, int> PLAYERS = new Dictionary<string, int>() public static readonly Dictionary<string, int> PLAYERS = new Dictionary<string, int>
{ {
{"Gameboy Controller", 1}, {"GBA Controller", 1}, {"Genesis 3-Button Controller", 2}, {"NES Controller", 4}, {"Gameboy Controller", 1}, {"GBA Controller", 1}, {"Genesis 3-Button Controller", 2}, {"NES Controller", 4},
{"SNES Controller", 4}, {"PC Engine Controller", 5}, {"SMS Controller", 2}, {"TI83 Controller", 1}, {"Atari 2600 Basic Controller", 2}, {"Atari 7800 ProLine Joystick Controller", 2}, {"SNES Controller", 4}, {"PC Engine Controller", 5}, {"SMS Controller", 2}, {"TI83 Controller", 1}, {"Atari 2600 Basic Controller", 2}, {"Atari 7800 ProLine Joystick Controller", 2},
@ -258,7 +258,7 @@ namespace BizHawk.MultiClient
public static string GetOutputControllersAsMnemonic() public static string GetOutputControllersAsMnemonic()
{ {
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
mg.SetSource(Global.ControllerOutput); mg.SetSource(ControllerOutput);
return mg.GetControllersAsMnemonic(); return mg.GetControllersAsMnemonic();
} }

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -220,10 +220,7 @@ namespace BizHawk.MultiClient
/// </summary> /// </summary>
public ArchiveItem FindArchiveMember(string name) public ArchiveItem FindArchiveMember(string name)
{ {
foreach (var ai in ArchiveItems) return ArchiveItems.FirstOrDefault(ai => ai.name == name);
if (ai.name == name)
return ai;
return null;
} }
/// <summary> /// <summary>
@ -344,10 +341,7 @@ namespace BizHawk.MultiClient
{ {
var afd = extractor.ArchiveFileData[i]; var afd = extractor.ArchiveFileData[i];
if (afd.IsDirectory) continue; if (afd.IsDirectory) continue;
var ai = new ArchiveItem(); var ai = new ArchiveItem {name = FixArchiveFilename(afd.FileName), size = (long) afd.Size, index = i};
ai.name = FixArchiveFilename(afd.FileName);
ai.size = (long)afd.Size; //ulong. obnoxious.
ai.index = i;
archiveItems.Add(ai); archiveItems.Add(ai);
} }
} }
@ -357,9 +351,10 @@ namespace BizHawk.MultiClient
SevenZip.FileChecker.ThrowExceptions = false; SevenZip.FileChecker.ThrowExceptions = false;
int offset; int offset;
bool isExecutable; bool isExecutable;
foreach(string ext in NonArchiveExtensions) if (NonArchiveExtensions.Any(ext => Path.GetExtension(path).Substring(1).ToLower() == ext.ToLower()))
if(Path.GetExtension(path).Substring(1).ToLower() == ext.ToLower()) {
return; return;
}
if (SevenZip.FileChecker.CheckSignature(path, out offset, out isExecutable) != SevenZip.InArchiveFormat.None) if (SevenZip.FileChecker.CheckSignature(path, out offset, out isExecutable) != SevenZip.InArchiveFormat.None)
{ {

View File

@ -1,14 +1,11 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class HistoryCollection public class HistoryCollection
{ {
public List<List<Watch>> History = new List<List<Watch>>(); public List<List<Watch>> History = new List<List<Watch>>();
private int curPos = 0; //1-based private int curPos; //1-based
public HistoryCollection(List<Watch> newState) public HistoryCollection(List<Watch> newState)
{ {

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Linq; using System.Linq;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -8,8 +7,8 @@ namespace BizHawk.MultiClient
public class Controller : IController public class Controller : IController
{ {
private ControllerDefinition type; private ControllerDefinition type;
private WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>(); private readonly WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>();
private WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>(); private readonly WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>();
public Controller(ControllerDefinition definition) public Controller(ControllerDefinition definition)
{ {
@ -18,7 +17,7 @@ namespace BizHawk.MultiClient
public ControllerDefinition Type { get { return type; } } public ControllerDefinition Type { get { return type; } }
/// <summary>don't do this</summary> /// <summary>don't do this</summary>
public void ForceType(ControllerDefinition newtype) { this.type = newtype; } public void ForceType(ControllerDefinition newtype) { type = newtype; }
public bool this[string button] { get { return IsPressed(button); } } public bool this[string button] { get { return IsPressed(button); } }
public bool IsPressed(string button) public bool IsPressed(string button)
{ {
@ -133,16 +132,7 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
List<string> list = new List<string>(); return (from button in buttons where button.Value select button.Key).ToList();
foreach (var button in buttons)
{
if (button.Value)
{
list.Add(button.Key);
}
}
return list;
} }
} }
} }
@ -212,7 +202,7 @@ namespace BizHawk.MultiClient
{ {
foreach (var bound_button in kvp.Value) foreach (var bound_button in kvp.Value)
{ {
if (buttons[kvp.Key] == false && controller[bound_button] == true) if (buttons[kvp.Key] == false && controller[bound_button])
buttonStarts[kvp.Key] = Global.Emulator.Frame; buttonStarts[kvp.Key] = Global.Emulator.Frame;
} }
} }
@ -269,16 +259,7 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
List<string> list = new List<string>(); return (from button in buttons where button.Value select button.Key).ToList();
foreach (var button in buttons)
{
if (button.Value)
{
list.Add(button.Key);
}
}
return list;
} }
} }
} }

View File

@ -107,12 +107,12 @@ namespace BizHawk.MultiClient
} }
public int NumButtons { get; private set; } public int NumButtons { get; private set; }
List<string> names = new List<string>(); private readonly List<string> names = new List<string>();
List<Func<bool>> actions = new List<Func<bool>>(); private readonly List<Func<bool>> actions = new List<Func<bool>>();
void AddItem(string name, Func<bool> callback) void AddItem(string _name, Func<bool> callback)
{ {
names.Add(name); names.Add(_name);
actions.Add(callback); actions.Add(callback);
NumButtons++; NumButtons++;
} }
@ -204,13 +204,15 @@ namespace BizHawk.MultiClient
// my first clue that it doesnt work is that LEFT and RIGHT _ARENT USED_ // my first clue that it doesnt work is that LEFT and RIGHT _ARENT USED_
// I should just look for C++ examples instead of trying to look for SlimDX examples // I should just look for C++ examples instead of trying to look for SlimDX examples
var parameters = new EffectParameters(); var parameters = new EffectParameters
parameters.Duration = 0x2710; {
parameters.Gain = 0x2710; Duration = 0x2710,
parameters.SamplePeriod = 0; Gain = 0x2710,
parameters.TriggerButton = 0; SamplePeriod = 0,
parameters.TriggerRepeatInterval = 0x2710; TriggerButton = 0,
parameters.Flags = EffectFlags.None; TriggerRepeatInterval = 0x2710,
Flags = EffectFlags.None
};
parameters.GetAxes(out temp1, out temp2); parameters.GetAxes(out temp1, out temp2);
parameters.SetAxes(temp1, temp2); parameters.SetAxes(temp1, temp2);
var effect = new Effect(joystick, EffectGuid.ConstantForce); var effect = new Effect(joystick, EffectGuid.ConstantForce);

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using SlimDX;
using SlimDX.XInput; using SlimDX.XInput;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -65,8 +64,8 @@ namespace BizHawk.MultiClient
public int NumButtons { get; private set; } public int NumButtons { get; private set; }
List<string> names = new List<string>(); private readonly List<string> names = new List<string>();
List<Func<bool>> actions = new List<Func<bool>>(); private readonly List<Func<bool>> actions = new List<Func<bool>>();
void InitializeButtons() void InitializeButtons()
{ {

View File

@ -2,7 +2,6 @@
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Windows.Forms;
#if WINDOWS #if WINDOWS
using SlimDX.DirectInput; using SlimDX.DirectInput;
#endif #endif
@ -22,7 +21,7 @@ namespace BizHawk.MultiClient
//when a button is released, all modified variants of it are released as well //when a button is released, all modified variants of it are released as well
if (!state) if (!state)
{ {
var releases = Buttons.Where((kvp) => kvp.Key.Contains("+") && kvp.Key.EndsWith(ie.LogicalButton.Button)).ToArray(); var releases = Buttons.Where(kvp => kvp.Key.Contains("+") && kvp.Key.EndsWith(ie.LogicalButton.Button)).ToArray();
foreach (var kvp in releases) foreach (var kvp in releases)
Buttons[kvp.Key] = false; Buttons[kvp.Key] = false;
} }
@ -40,7 +39,7 @@ namespace BizHawk.MultiClient
//For controller input, we want Shift+X to register as both Shift and X (for Keyboard controllers) //For controller input, we want Shift+X to register as both Shift and X (for Keyboard controllers)
string[] subgroups = button.Split('+'); string[] subgroups = button.Split('+');
if (subgroups != null && subgroups.Length > 0) if (subgroups.Length > 0)
{ {
foreach (string s in subgroups) foreach (string s in subgroups)
{ {
@ -60,6 +59,7 @@ namespace BizHawk.MultiClient
public class Input public class Input
{ {
[Flags]
public enum ModifierKey public enum ModifierKey
{ {
// Summary: // Summary:
@ -84,13 +84,12 @@ namespace BizHawk.MultiClient
} }
public static Input Instance { get; private set; } public static Input Instance { get; private set; }
Thread UpdateThread; readonly Thread UpdateThread;
private Input() private Input()
{ {
#if WINDOWS #if WINDOWS
UpdateThread = new Thread(UpdateThreadProc); UpdateThread = new Thread(UpdateThreadProc) {IsBackground = true};
UpdateThread.IsBackground = true;
UpdateThread.Start(); UpdateThread.Start();
#endif #endif
} }
@ -116,8 +115,8 @@ namespace BizHawk.MultiClient
Button = button; Button = button;
Modifiers = modifiers; Modifiers = modifiers;
} }
public string Button; public readonly string Button;
public ModifierKey Modifiers; public readonly ModifierKey Modifiers;
public bool Alt { get { return ((Modifiers & ModifierKey.Alt) != 0); } } public bool Alt { get { return ((Modifiers & ModifierKey.Alt) != 0); } }
public bool Control { get { return ((Modifiers & ModifierKey.Control) != 0); } } public bool Control { get { return ((Modifiers & ModifierKey.Control) != 0); } }
@ -160,11 +159,11 @@ namespace BizHawk.MultiClient
} }
} }
WorkingDictionary<string, object> ModifierState = new WorkingDictionary<string, object>(); private readonly WorkingDictionary<string, object> ModifierState = new WorkingDictionary<string, object>();
WorkingDictionary<string, bool> LastState = new WorkingDictionary<string, bool>(); private readonly WorkingDictionary<string, bool> LastState = new WorkingDictionary<string, bool>();
WorkingDictionary<string, bool> UnpressState = new WorkingDictionary<string, bool>(); private readonly WorkingDictionary<string, bool> UnpressState = new WorkingDictionary<string, bool>();
private readonly HashSet<string> IgnoreKeys = new HashSet<string>(new[] { "LeftShift", "RightShift", "LeftControl", "RightControl", "LeftAlt", "RightAlt" });
HashSet<string> IgnoreKeys = new HashSet<string>(new[] { "LeftShift", "RightShift", "LeftControl", "RightControl", "LeftAlt", "RightAlt" });
void HandleButton(string button, bool newState) void HandleButton(string button, bool newState)
{ {
if (EnableIgnoreModifiers && IgnoreKeys.Contains(button)) return; if (EnableIgnoreModifiers && IgnoreKeys.Contains(button)) return;
@ -189,9 +188,11 @@ namespace BizHawk.MultiClient
if (button == "LeftAlt") mods &= ~ModifierKey.Alt; if (button == "LeftAlt") mods &= ~ModifierKey.Alt;
if (button == "RightAlt") mods &= ~ModifierKey.Alt; if (button == "RightAlt") mods &= ~ModifierKey.Alt;
var ie = new InputEvent(); var ie = new InputEvent
ie.EventType = newState ? InputEventType.Press : InputEventType.Release; {
ie.LogicalButton = new LogicalButton(button, mods); EventType = newState ? InputEventType.Press : InputEventType.Release,
LogicalButton = new LogicalButton(button, mods)
};
LastState[button] = newState; LastState[button] = newState;
//track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers //track the pressed events with modifiers that we send so that we can send corresponding unpresses with modifiers
@ -210,9 +211,11 @@ namespace BizHawk.MultiClient
if (ModifierState[button] != null) if (ModifierState[button] != null)
{ {
LogicalButton alreadyReleased = ie.LogicalButton; LogicalButton alreadyReleased = ie.LogicalButton;
var ieModified = new InputEvent(); var ieModified = new InputEvent
ieModified.LogicalButton = (LogicalButton)ModifierState[button]; {
ieModified.EventType = InputEventType.Release; LogicalButton = (LogicalButton) ModifierState[button],
EventType = InputEventType.Release
};
if (ieModified.LogicalButton != alreadyReleased) if (ieModified.LogicalButton != alreadyReleased)
_NewEvents.Add(ieModified); _NewEvents.Add(ieModified);
} }
@ -223,7 +226,7 @@ namespace BizHawk.MultiClient
} }
ModifierKey _Modifiers; ModifierKey _Modifiers;
List<InputEvent> _NewEvents = new List<InputEvent>(); private readonly List<InputEvent> _NewEvents = new List<InputEvent>();
//do we need this? //do we need this?
public void ClearEvents() public void ClearEvents()
@ -234,7 +237,7 @@ namespace BizHawk.MultiClient
} }
} }
Queue<InputEvent> InputEvents = new Queue<InputEvent>(); private readonly Queue<InputEvent> InputEvents = new Queue<InputEvent>();
public InputEvent DequeueEvent() public InputEvent DequeueEvent()
{ {
lock (this) lock (this)

View File

@ -1,6 +1,4 @@
using System.Collections.Generic; using SlimDX;
using System.Text;
using SlimDX;
using SlimDX.DirectInput; using SlimDX.DirectInput;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient

View File

@ -1,13 +1,12 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.IO; using System.IO;
using LuaInterface; using LuaInterface;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing; using System.Drawing;
using System.Threading; using System.Threading;
using System.Globalization;
using BizHawk.Emulation.Consoles.Nintendo; using BizHawk.Emulation.Consoles.Nintendo;
using BizHawk.MultiClient.tools; using BizHawk.MultiClient.tools;
@ -17,17 +16,20 @@ namespace BizHawk.MultiClient
public class LuaImplementation public class LuaImplementation
{ {
public LuaDocumentation docs = new LuaDocumentation(); public LuaDocumentation docs = new LuaDocumentation();
private Lua lua = new Lua();
private LuaConsole Caller;
public EventWaitHandle LuaWait;
public bool isRunning; public bool isRunning;
private int CurrentMemoryDomain = 0; //Main memory by default public EventWaitHandle LuaWait;
public bool FrameAdvanceRequested; public bool FrameAdvanceRequested;
private Lua _lua = new Lua();
private readonly LuaConsole Caller;
private int CurrentMemoryDomain; //Main memory by default
private Lua currThread; private Lua currThread;
private LuaFunction savestate_registersavefunc; private LuaFunction savestate_registersavefunc;
private LuaFunction savestate_registerloadfunc; private LuaFunction savestate_registerloadfunc;
private LuaFunction frame_startfunc; private LuaFunction frame_startfunc;
private LuaFunction frame_endfunc; private LuaFunction frame_endfunc;
private readonly Dictionary<Color, SolidBrush> SolidBrushes = new Dictionary<Color, SolidBrush>();
private readonly Dictionary<Color, Pen> Pens = new Dictionary<Color, Pen>();
public void SavestateRegisterSave(string name) public void SavestateRegisterSave(string name)
{ {
@ -102,128 +104,128 @@ namespace BizHawk.MultiClient
LuaWait = new AutoResetEvent(false); LuaWait = new AutoResetEvent(false);
docs.Clear(); docs.Clear();
Caller = passed.get(); Caller = passed.get();
LuaRegister(lua); LuaRegister(_lua);
} }
public void Close() public void Close()
{ {
lua = new Lua(); _lua = new Lua();
foreach (var brush in SolidBrushes.Values) brush.Dispose(); foreach (var brush in SolidBrushes.Values) brush.Dispose();
foreach (var brush in Pens.Values) brush.Dispose(); foreach (var brush in Pens.Values) brush.Dispose();
} }
public void LuaRegister(Lua lua) public void LuaRegister(Lua lua)
{ {
lua.RegisterFunction("print", this, this.GetType().GetMethod("print")); lua.RegisterFunction("print", this, GetType().GetMethod("print"));
//Register libraries //Register libraries
lua.NewTable("console"); lua.NewTable("console");
for (int i = 0; i < ConsoleFunctions.Length; i++) foreach (string t in ConsoleFunctions)
{ {
lua.RegisterFunction("console." + ConsoleFunctions[i], this, lua.RegisterFunction("console." + t, this,
this.GetType().GetMethod("console_" + ConsoleFunctions[i])); GetType().GetMethod("console_" + t));
docs.Add("console", ConsoleFunctions[i], this.GetType().GetMethod("console_" + ConsoleFunctions[i])); docs.Add("console", t, GetType().GetMethod("console_" + t));
} }
lua.NewTable("gui"); lua.NewTable("gui");
for (int i = 0; i < GuiFunctions.Length; i++) foreach (string t in GuiFunctions)
{ {
lua.RegisterFunction("gui." + GuiFunctions[i], this, this.GetType().GetMethod("gui_" + GuiFunctions[i])); lua.RegisterFunction("gui." + t, this, GetType().GetMethod("gui_" + t));
docs.Add("gui", GuiFunctions[i], this.GetType().GetMethod("gui_" + GuiFunctions[i])); docs.Add("gui", t, GetType().GetMethod("gui_" + t));
} }
lua.NewTable("emu"); lua.NewTable("emu");
for (int i = 0; i < EmuFunctions.Length; i++) foreach (string t in EmuFunctions)
{ {
lua.RegisterFunction("emu." + EmuFunctions[i], this, this.GetType().GetMethod("emu_" + EmuFunctions[i])); lua.RegisterFunction("emu." + t, this, GetType().GetMethod("emu_" + t));
docs.Add("emu", EmuFunctions[i], this.GetType().GetMethod("emu_" + EmuFunctions[i])); docs.Add("emu", t, GetType().GetMethod("emu_" + t));
} }
lua.NewTable("memory"); lua.NewTable("memory");
for (int i = 0; i < MemoryFunctions.Length; i++) foreach (string t in MemoryFunctions)
{ {
lua.RegisterFunction("memory." + MemoryFunctions[i], this, this.GetType().GetMethod("memory_" + MemoryFunctions[i])); lua.RegisterFunction("memory." + t, this, GetType().GetMethod("memory_" + t));
docs.Add("memory", MemoryFunctions[i], this.GetType().GetMethod("memory_" + MemoryFunctions[i])); docs.Add("memory", t, GetType().GetMethod("memory_" + t));
} }
lua.NewTable("mainmemory"); lua.NewTable("mainmemory");
for (int i = 0; i < MainMemoryFunctions.Length; i++) foreach (string t in MainMemoryFunctions)
{ {
lua.RegisterFunction("mainmemory." + MainMemoryFunctions[i], this, lua.RegisterFunction("mainmemory." + t, this,
this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i])); GetType().GetMethod("mainmemory_" + t));
docs.Add("mainmemory", MainMemoryFunctions[i], this.GetType().GetMethod("mainmemory_" + MainMemoryFunctions[i])); docs.Add("mainmemory", t, GetType().GetMethod("mainmemory_" + t));
} }
lua.NewTable("savestate"); lua.NewTable("savestate");
for (int i = 0; i < SaveStateFunctions.Length; i++) foreach (string t in SaveStateFunctions)
{ {
lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, lua.RegisterFunction("savestate." + t, this,
this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); GetType().GetMethod("savestate_" + t));
docs.Add("savestate", SaveStateFunctions[i], this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); docs.Add("savestate", t, GetType().GetMethod("savestate_" + t));
} }
lua.NewTable("movie"); lua.NewTable("movie");
for (int i = 0; i < MovieFunctions.Length; i++) foreach (string t in MovieFunctions)
{ {
lua.RegisterFunction("movie." + MovieFunctions[i], this, this.GetType().GetMethod("movie_" + MovieFunctions[i])); lua.RegisterFunction("movie." + t, this, GetType().GetMethod("movie_" + t));
docs.Add("movie", MovieFunctions[i], this.GetType().GetMethod("movie_" + MovieFunctions[i])); docs.Add("movie", t, GetType().GetMethod("movie_" + t));
} }
lua.NewTable("input"); lua.NewTable("input");
for (int i = 0; i < InputFunctions.Length; i++) foreach (string t in InputFunctions)
{ {
lua.RegisterFunction("input." + InputFunctions[i], this, this.GetType().GetMethod("input_" + InputFunctions[i])); lua.RegisterFunction("input." + t, this, GetType().GetMethod("input_" + t));
docs.Add("input", InputFunctions[i], this.GetType().GetMethod("input_" + InputFunctions[i])); docs.Add("input", t, GetType().GetMethod("input_" + t));
} }
lua.NewTable("joypad"); lua.NewTable("joypad");
for (int i = 0; i < JoypadFunctions.Length; i++) foreach (string t in JoypadFunctions)
{ {
lua.RegisterFunction("joypad." + JoypadFunctions[i], this, this.GetType().GetMethod("joypad_" + JoypadFunctions[i])); lua.RegisterFunction("joypad." + t, this, GetType().GetMethod("joypad_" + t));
docs.Add("joypad", JoypadFunctions[i], this.GetType().GetMethod("joypad_" + JoypadFunctions[i])); docs.Add("joypad", t, GetType().GetMethod("joypad_" + t));
} }
lua.NewTable("client"); lua.NewTable("client");
for (int i = 0; i < MultiClientFunctions.Length; i++) foreach (string t in MultiClientFunctions)
{ {
lua.RegisterFunction("client." + MultiClientFunctions[i], this, lua.RegisterFunction("client." + t, this,
this.GetType().GetMethod("client_" + MultiClientFunctions[i])); GetType().GetMethod("client_" + t));
docs.Add("client", MultiClientFunctions[i], this.GetType().GetMethod("client_" + MultiClientFunctions[i])); docs.Add("client", t, GetType().GetMethod("client_" + t));
} }
lua.NewTable("forms"); lua.NewTable("forms");
for (int i = 0; i < FormsFunctions.Length; i++) foreach (string t in FormsFunctions)
{ {
lua.RegisterFunction("forms." + FormsFunctions[i], this, this.GetType().GetMethod("forms_" + FormsFunctions[i])); lua.RegisterFunction("forms." + t, this, GetType().GetMethod("forms_" + t));
docs.Add("forms", FormsFunctions[i], this.GetType().GetMethod("forms_" + FormsFunctions[i])); docs.Add("forms", t, GetType().GetMethod("forms_" + t));
} }
lua.NewTable("bit"); lua.NewTable("bit");
for (int i = 0; i < BitwiseFunctions.Length; i++) foreach (string t in BitwiseFunctions)
{ {
lua.RegisterFunction("bit." + BitwiseFunctions[i], this, this.GetType().GetMethod("bit_" + BitwiseFunctions[i])); lua.RegisterFunction("bit." + t, this, GetType().GetMethod("bit_" + t));
docs.Add("bit", BitwiseFunctions[i], this.GetType().GetMethod("bit_" + BitwiseFunctions[i])); docs.Add("bit", t, GetType().GetMethod("bit_" + t));
} }
lua.NewTable("nes"); lua.NewTable("nes");
for (int i = 0; i < NESFunctions.Length; i++) foreach (string t in NESFunctions)
{ {
lua.RegisterFunction("nes." + NESFunctions[i], this, this.GetType().GetMethod("nes_" + NESFunctions[i])); lua.RegisterFunction("nes." + t, this, GetType().GetMethod("nes_" + t));
docs.Add("nes", NESFunctions[i], this.GetType().GetMethod("nes_" + NESFunctions[i])); docs.Add("nes", t, GetType().GetMethod("nes_" + t));
} }
lua.NewTable("snes"); lua.NewTable("snes");
for (int i = 0; i < SNESFunctions.Length; i++) foreach (string t in SNESFunctions)
{ {
lua.RegisterFunction("snes." + SNESFunctions[i], this, this.GetType().GetMethod("snes_" + SNESFunctions[i])); lua.RegisterFunction("snes." + t, this, GetType().GetMethod("snes_" + t));
docs.Add("snes", SNESFunctions[i], this.GetType().GetMethod("snes_" + SNESFunctions[i])); docs.Add("snes", t, GetType().GetMethod("snes_" + t));
} }
lua.NewTable("event"); lua.NewTable("event");
for (int i = 0; i < EventFunctions.Length; i++) foreach (string t in EventFunctions)
{ {
lua.RegisterFunction("event." + EventFunctions[i], this, this.GetType().GetMethod("event_" + EventFunctions[i])); lua.RegisterFunction("event." + t, this, GetType().GetMethod("event_" + t));
docs.Add("event", EventFunctions[i], this.GetType().GetMethod("event_" + EventFunctions[i])); docs.Add("event", t, GetType().GetMethod("event_" + t));
} }
docs.Sort(); docs.Sort();
@ -231,7 +233,7 @@ namespace BizHawk.MultiClient
public Lua SpawnCoroutine(string File) public Lua SpawnCoroutine(string File)
{ {
var t = lua.NewThread(); var t = _lua.NewThread();
//LuaRegister(t); //adelikat: Not sure why this was here but it was causing the entire luaimplmeentaiton to be duplicated each time, eventually resulting in crashes //LuaRegister(t); //adelikat: Not sure why this was here but it was causing the entire luaimplmeentaiton to be duplicated each time, eventually resulting in crashes
var main = t.LoadFile(File); var main = t.LoadFile(File);
t.Push(main); //push main function on to stack for subsequent resuming t.Push(main); //push main function on to stack for subsequent resuming
@ -251,20 +253,16 @@ namespace BizHawk.MultiClient
public Color GetColor(object color) public Color GetColor(object color)
{ {
if (color.GetType() == typeof(Double)) if (color is double)
{ {
return return Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"), NumberStyles.HexNumber));
System.Drawing.Color.FromArgb(int.Parse(long.Parse(color.ToString()).ToString("X"),
System.Globalization.NumberStyles.HexNumber));
} }
else else
{ {
return System.Drawing.Color.FromName(color.ToString().ToLower()); return Color.FromName(color.ToString().ToLower());
} }
} }
Dictionary<Color, SolidBrush> SolidBrushes = new Dictionary<Color, SolidBrush>();
public SolidBrush GetBrush(object color) public SolidBrush GetBrush(object color)
{ {
Color c = GetColor(color); Color c = GetColor(color);
@ -277,7 +275,6 @@ namespace BizHawk.MultiClient
return b; return b;
} }
Dictionary<Color, Pen> Pens = new Dictionary<Color, Pen>();
public Pen GetPen(object color) public Pen GetPen(object color)
{ {
Color c = GetColor(color); Color c = GetColor(color);
@ -345,15 +342,15 @@ namespace BizHawk.MultiClient
/*************library definitions********************/ /*************library definitions********************/
/****************************************************/ /****************************************************/
public static string[] ConsoleFunctions = new string[] public static string[] ConsoleFunctions = new[]
{ {
"output", "output",
"log", "log",
"clear", "clear",
"getluafunctionslist", "getluafunctionslist"
}; };
public static string[] GuiFunctions = new string[] public static string[] GuiFunctions = new[]
{ {
"text", "text",
"alert", "alert",
@ -370,10 +367,10 @@ namespace BizHawk.MultiClient
"drawImage", "drawImage",
"addmessage", "addmessage",
"drawText", "drawText",
"drawString", "drawString"
}; };
public static string[] EmuFunctions = new string[] public static string[] EmuFunctions = new[]
{ {
"frameadvance", "frameadvance",
"yield", "yield",
@ -392,10 +389,10 @@ namespace BizHawk.MultiClient
"limitframerate", "limitframerate",
"displayvsync", "displayvsync",
"enablerewind", "enablerewind",
"on_snoop", "on_snoop"
}; };
public static string[] MemoryFunctions = new string[] public static string[] MemoryFunctions = new[]
{ {
"usememorydomain", "usememorydomain",
"getmemorydomainlist", "getmemorydomainlist",
@ -429,12 +426,12 @@ namespace BizHawk.MultiClient
"write_u24_be", "write_u24_be",
"write_u32_be", "write_u32_be",
"readbyte", "readbyte",
"writebyte", "writebyte"
//"registerwrite", //"registerwrite",
//"registerread", //"registerread",
}; };
public static string[] MainMemoryFunctions = new string[] public static string[] MainMemoryFunctions = new[]
{ {
"read_s8", "read_s8",
"read_u8", "read_u8",
@ -465,20 +462,20 @@ namespace BizHawk.MultiClient
"write_u24_be", "write_u24_be",
"write_u32_be", "write_u32_be",
"readbyterange", "readbyterange",
"writebyterange", "writebyterange"
}; };
public static string[] SaveStateFunctions = new string[] public static string[] SaveStateFunctions = new[]
{ {
"saveslot", "saveslot",
"loadslot", "loadslot",
"save", "save",
"load", "load",
"registersave", "registersave",
"registerload", "registerload"
}; };
public static string[] MovieFunctions = new string[] public static string[] MovieFunctions = new[]
{ {
"mode", "mode",
"isloaded", "isloaded",
@ -490,23 +487,23 @@ namespace BizHawk.MultiClient
"setreadonly", "setreadonly",
"getrerecordcounting", "getrerecordcounting",
"setrerecordcounting", "setrerecordcounting",
"getinput", "getinput"
}; };
public static string[] InputFunctions = new string[] public static string[] InputFunctions = new[]
{ {
"get", "get",
"getmouse", "getmouse"
}; };
public static string[] JoypadFunctions = new string[] public static string[] JoypadFunctions = new[]
{ {
"set", "set",
"get", "get",
"getimmediate" "getimmediate"
}; };
public static string[] MultiClientFunctions = new string[] public static string[] MultiClientFunctions = new[]
{ {
"getwindowsize", "getwindowsize",
"setwindowsize", "setwindowsize",
@ -525,10 +522,10 @@ namespace BizHawk.MultiClient
"screenshottoclipboard", "screenshottoclipboard",
"setscreenshotosd", "setscreenshotosd",
"pause_av", "pause_av",
"unpause_av", "unpause_av"
}; };
public static string[] FormsFunctions = new string[] public static string[] FormsFunctions = new[]
{ {
"newform", "newform",
"destroy", "destroy",
@ -543,10 +540,10 @@ namespace BizHawk.MultiClient
"clearclicks", "clearclicks",
"gettext", "gettext",
"setproperty", "setproperty",
"getproperty", "getproperty"
}; };
public static string[] BitwiseFunctions = new string[] public static string[] BitwiseFunctions = new[]
{ {
"band", "band",
"lshift", "lshift",
@ -555,10 +552,10 @@ namespace BizHawk.MultiClient
"ror", "ror",
"bor", "bor",
"bxor", "bxor",
"bnot", "bnot"
}; };
public static string[] NESFunctions = new string[] public static string[] NESFunctions = new[]
{ {
"setscanlines", "setscanlines",
"gettopscanline", "gettopscanline",
@ -572,10 +569,10 @@ namespace BizHawk.MultiClient
"getallowmorethaneightsprites", "getallowmorethaneightsprites",
"setallowmorethaneightsprites", "setallowmorethaneightsprites",
"addgamegenie", "addgamegenie",
"removegamegenie", "removegamegenie"
}; };
public static string[] SNESFunctions = new string[] public static string[] SNESFunctions = new[]
{ {
"setlayer_bg_1", "setlayer_bg_1",
"setlayer_bg_2", "setlayer_bg_2",
@ -593,10 +590,10 @@ namespace BizHawk.MultiClient
"getlayer_obj_1", "getlayer_obj_1",
"getlayer_obj_2", "getlayer_obj_2",
"getlayer_obj_3", "getlayer_obj_3",
"getlayer_obj_4", "getlayer_obj_4"
}; };
public static string[] EventFunctions = new string[] public static string[] EventFunctions = new[]
{ {
"onloadstate", "onloadstate",
"onsavestate", "onsavestate",
@ -604,7 +601,7 @@ namespace BizHawk.MultiClient
"onframeend", "onframeend",
"onmemoryread", "onmemoryread",
"onmemorywrite", "onmemorywrite",
"oninputpoll", "oninputpoll"
}; };
/****************************************************/ /****************************************************/
/*************function definitions********************/ /*************function definitions********************/
@ -831,7 +828,6 @@ namespace BizHawk.MultiClient
{ {
using (var g = GetGraphics()) using (var g = GetGraphics())
{ {
float x = LuaInt(X) + 0.1F;
try try
{ {
int fsize = 12; int fsize = 12;
@ -870,7 +866,7 @@ namespace BizHawk.MultiClient
} }
} }
Font font = new System.Drawing.Font(family, fsize, fstyle, GraphicsUnit.Pixel); Font font = new Font(family, fsize, fstyle, GraphicsUnit.Pixel);
g.DrawString(message.ToString(), font, GetBrush(color ?? "white"), LuaInt(X), LuaInt(Y)); g.DrawString(message.ToString(), font, GetBrush(color ?? "white"), LuaInt(X), LuaInt(Y));
} }
catch (Exception) catch (Exception)
@ -939,11 +935,11 @@ namespace BizHawk.MultiClient
{ {
try try
{ {
System.Drawing.Point[] Points = new System.Drawing.Point[points.Values.Count]; Point[] Points = new Point[points.Values.Count];
int i = 0; int i = 0;
foreach (LuaTable point in points.Values) foreach (LuaTable point in points.Values)
{ {
Points[i] = new System.Drawing.Point(LuaInt(point[1]), LuaInt(point[2])); Points[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
i++; i++;
} }
@ -981,11 +977,11 @@ namespace BizHawk.MultiClient
{ {
try try
{ {
System.Drawing.Point[] Points = new System.Drawing.Point[4]; Point[] Points = new Point[4];
int i = 0; int i = 0;
foreach (LuaTable point in points.Values) foreach (LuaTable point in points.Values)
{ {
Points[i] = new System.Drawing.Point(LuaInt(point[1]), LuaInt(point[2])); Points[i] = new Point(LuaInt(point[1]), LuaInt(point[2]));
i++; i++;
if (i >= 4) if (i >= 4)
break; break;
@ -1250,12 +1246,12 @@ namespace BizHawk.MultiClient
// TODO: error handling for argument count mismatch // TODO: error handling for argument count mismatch
private void emu_setrenderplanes_do(object[] lua_p) private void emu_setrenderplanes_do(object[] lua_p)
{ {
if (Global.Emulator is BizHawk.Emulation.Consoles.Nintendo.NES) if (Global.Emulator is NES)
{ {
Global.CoreComm.NES_ShowOBJ = Global.Config.NESDispSprites = (bool)lua_p[0]; Global.CoreComm.NES_ShowOBJ = Global.Config.NESDispSprites = (bool)lua_p[0];
Global.CoreComm.NES_ShowBG = Global.Config.NESDispBackground = (bool)lua_p[1]; Global.CoreComm.NES_ShowBG = Global.Config.NESDispBackground = (bool)lua_p[1];
} }
else if (Global.Emulator is BizHawk.Emulation.Consoles.TurboGrafx.PCEngine) else if (Global.Emulator is Emulation.Consoles.TurboGrafx.PCEngine)
{ {
Global.CoreComm.PCE_ShowOBJ1 = Global.Config.PCEDispOBJ1 = (bool)lua_p[0]; Global.CoreComm.PCE_ShowOBJ1 = Global.Config.PCEDispOBJ1 = (bool)lua_p[0];
Global.CoreComm.PCE_ShowBG1 = Global.Config.PCEDispBG1 = (bool)lua_p[1]; Global.CoreComm.PCE_ShowBG1 = Global.Config.PCEDispBG1 = (bool)lua_p[1];
@ -1265,7 +1261,7 @@ namespace BizHawk.MultiClient
Global.CoreComm.PCE_ShowBG2 = Global.Config.PCEDispBG2 = (bool)lua_p[3]; Global.CoreComm.PCE_ShowBG2 = Global.Config.PCEDispBG2 = (bool)lua_p[3];
} }
} }
else if (Global.Emulator is BizHawk.Emulation.Consoles.Sega.SMS) else if (Global.Emulator is Emulation.Consoles.Sega.SMS)
{ {
Global.CoreComm.SMS_ShowOBJ = Global.Config.SMSDispOBJ = (bool)lua_p[0]; Global.CoreComm.SMS_ShowOBJ = Global.Config.SMSDispOBJ = (bool)lua_p[0];
Global.CoreComm.SMS_ShowBG = Global.Config.SMSDispBG = (bool)lua_p[1]; Global.CoreComm.SMS_ShowBG = Global.Config.SMSDispBG = (bool)lua_p[1];
@ -1327,12 +1323,7 @@ namespace BizHawk.MultiClient
public string memory_getmemorydomainlist() public string memory_getmemorydomainlist()
{ {
string list = ""; return Global.Emulator.MemoryDomains.Aggregate("", (current, t) => current + (t.Name + '\n'));
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
{
list += Global.Emulator.MemoryDomains[x].Name + '\n';
}
return list;
} }
public string memory_getcurrentmemorydomain() public string memory_getcurrentmemorydomain()
@ -1615,7 +1606,7 @@ namespace BizHawk.MultiClient
int l = LuaInt(length); int l = LuaInt(length);
int addr = LuaInt(address); int addr = LuaInt(address);
int last_addr = l + addr; int last_addr = l + addr;
LuaTable table = lua.NewTable(); LuaTable table = _lua.NewTable();
for (int i = addr; i <= last_addr; i++) for (int i = addr; i <= last_addr; i++)
{ {
string a = String.Format("{0:X2}", i); string a = String.Format("{0:X2}", i);
@ -2074,11 +2065,10 @@ namespace BizHawk.MultiClient
public LuaTable movie_getinput(object frame) public LuaTable movie_getinput(object frame)
{ {
LuaTable input = lua.NewTable(); LuaTable input = _lua.NewTable();
string s = Global.MovieSession.Movie.GetInput(LuaInt(frame)); string s = Global.MovieSession.Movie.GetInput(LuaInt(frame));
MovieControllerAdapter m = new MovieControllerAdapter(); MovieControllerAdapter m = new MovieControllerAdapter {Type = Global.MovieSession.MovieControllerAdapter.Type};
m.Type = Global.MovieSession.MovieControllerAdapter.Type;
m.SetControllersAsMnemonic(s); m.SetControllersAsMnemonic(s);
foreach (string button in m.Type.BoolButtons) foreach (string button in m.Type.BoolButtons)
input[button] = m[button]; input[button] = m[button];
@ -2103,7 +2093,7 @@ namespace BizHawk.MultiClient
//---------------------------------------------------- //----------------------------------------------------
public LuaTable input_get() public LuaTable input_get()
{ {
LuaTable buttons = lua.NewTable(); LuaTable buttons = _lua.NewTable();
foreach (var kvp in Global.ControllerInputCoalescer.BoolButtons()) foreach (var kvp in Global.ControllerInputCoalescer.BoolButtons())
if (kvp.Value) if (kvp.Value)
buttons[kvp.Key] = true; buttons[kvp.Key] = true;
@ -2117,7 +2107,7 @@ namespace BizHawk.MultiClient
//Currently sends all controllers, needs to control which ones it sends //Currently sends all controllers, needs to control which ones it sends
public LuaTable joypad_get(object controller = null) public LuaTable joypad_get(object controller = null)
{ {
LuaTable buttons = lua.NewTable(); LuaTable buttons = _lua.NewTable();
foreach (string button in Global.ControllerOutput.Source.Type.BoolButtons) foreach (string button in Global.ControllerOutput.Source.Type.BoolButtons)
if (controller == null) if (controller == null)
buttons[button] = Global.ControllerOutput[button]; buttons[button] = Global.ControllerOutput[button];
@ -2133,7 +2123,7 @@ namespace BizHawk.MultiClient
public LuaTable joypad_getimmediate() public LuaTable joypad_getimmediate()
{ {
LuaTable buttons = lua.NewTable(); LuaTable buttons = _lua.NewTable();
foreach (string button in Global.ActiveController.Type.BoolButtons) foreach (string button in Global.ActiveController.Type.BoolButtons)
buttons[button] = Global.ActiveController[button]; buttons[button] = Global.ActiveController[button];
return buttons; return buttons;
@ -2182,8 +2172,8 @@ namespace BizHawk.MultiClient
} }
else else
{ {
Global.ClickyVirtualPadController.Click("P" + controller.ToString() + " " + button.ToString()); Global.ClickyVirtualPadController.Click("P" + controller + " " + button);
Global.ForceOffAdaptor.SetSticky("P" + controller.ToString() + " " + button.ToString(), false); Global.ForceOffAdaptor.SetSticky("P" + controller + " " + button, false);
} }
} }
else if (theValue == false) //Force off else if (theValue == false) //Force off
@ -2194,7 +2184,7 @@ namespace BizHawk.MultiClient
} }
else else
{ {
Global.ForceOffAdaptor.SetSticky("P" + controller.ToString() + " " + button.ToString(), true); Global.ForceOffAdaptor.SetSticky("P" + controller + " " + button, true);
} }
} }
else if (theValue == null) else if (theValue == null)
@ -2206,7 +2196,7 @@ namespace BizHawk.MultiClient
} }
else else
{ {
Global.ForceOffAdaptor.SetSticky("P" + controller.ToString() + " " + button.ToString(), false); Global.ForceOffAdaptor.SetSticky("P" + controller + " " + button, false);
} }
} }
} }
@ -2219,8 +2209,8 @@ namespace BizHawk.MultiClient
} }
else else
{ {
Global.StickyXORAdapter.SetSticky("P" + controller.ToString() + " " + button.ToString(), true); Global.StickyXORAdapter.SetSticky("P" + controller + " " + button, true);
Global.ForceOffAdaptor.SetSticky("P" + controller.ToString() + " " + button.ToString(), false); Global.ForceOffAdaptor.SetSticky("P" + controller + " " + button, false);
} }
} }
} }
@ -2400,14 +2390,7 @@ namespace BizHawk.MultiClient
private LuaWinform GetForm(object form_handle) private LuaWinform GetForm(object form_handle)
{ {
IntPtr ptr = new IntPtr(LuaInt(form_handle)); IntPtr ptr = new IntPtr(LuaInt(form_handle));
foreach (LuaWinform form in LuaForms) return LuaForms.FirstOrDefault(form => form.Handle == ptr);
{
if (form.Handle == ptr)
{
return form;
}
}
return null;
} }
private void SetLocation(Control control, object X, object Y) private void SetLocation(Control control, object X, object Y)
@ -2721,7 +2704,7 @@ namespace BizHawk.MultiClient
public LuaTable input_getmouse() public LuaTable input_getmouse()
{ {
LuaTable buttons = lua.NewTable(); LuaTable buttons = _lua.NewTable();
Point p = Global.RenderPanel.ScreenToScreen(Control.MousePosition); Point p = Global.RenderPanel.ScreenToScreen(Control.MousePosition);
buttons["X"] = p.X; buttons["X"] = p.X;
buttons["Y"] = p.Y; buttons["Y"] = p.Y;
@ -2866,16 +2849,18 @@ namespace BizHawk.MultiClient
{ {
NESGameGenie gg = new NESGameGenie(); NESGameGenie gg = new NESGameGenie();
gg.DecodeGameGenieCode(code); gg.DecodeGameGenieCode(code);
if (gg.address > 0 && gg.value > 0) if (gg.Address > 0 && gg.Value > 0)
{ {
Cheat c = new Cheat(); Cheat c = new Cheat
c.name = code; {
c.domain = Global.Emulator.MemoryDomains[1]; name = code,
c.address = gg.address; domain = Global.Emulator.MemoryDomains[1],
c.value = (byte)gg.value; address = gg.Address,
if (gg.compare != -1) value = (byte) gg.Value
};
if (gg.Compare != -1)
{ {
c.compare = (byte)gg.compare; c.compare = (byte)gg.Compare;
} }
c.Enable(); c.Enable();
Global.MainForm.Cheats1.AddCheat(c); Global.MainForm.Cheats1.AddCheat(c);
@ -2889,16 +2874,18 @@ namespace BizHawk.MultiClient
{ {
NESGameGenie gg = new NESGameGenie(); NESGameGenie gg = new NESGameGenie();
gg.DecodeGameGenieCode(code); gg.DecodeGameGenieCode(code);
if (gg.address > 0 && gg.value > 0) if (gg.Address > 0 && gg.Value > 0)
{ {
Cheat c = new Cheat(); Cheat c = new Cheat
c.name = code; {
c.domain = Global.Emulator.MemoryDomains[1]; name = code,
c.address = gg.address; domain = Global.Emulator.MemoryDomains[1],
c.value = (byte)gg.value; address = gg.Address,
if (gg.compare != -1) value = (byte) gg.Value
};
if (gg.Compare != -1)
{ {
c.compare = (byte)gg.compare; c.compare = (byte)gg.Compare;
} }
Global.CheatList.RemoveCheat(Global.Emulator.MemoryDomains[1], c.address); Global.CheatList.RemoveCheat(Global.Emulator.MemoryDomains[1], c.address);
} }

View File

@ -955,7 +955,7 @@ namespace BizHawk.MultiClient
s.DisableFrame(); s.DisableFrame();
int index = -1; int index = -1;
Subtitle sub = new Subtitle(); Subtitle sub = new Subtitle();
for (int x = 0; x < Global.MovieSession.Movie.Subtitles.Count(); x++) for (int x = 0; x < Global.MovieSession.Movie.Subtitles.Count; x++)
{ {
sub = Global.MovieSession.Movie.Subtitles.GetSubtitleByIndex(x); sub = Global.MovieSession.Movie.Subtitles.GetSubtitleByIndex(x);
if (Global.Emulator.Frame == sub.Frame) if (Global.Emulator.Frame == sub.Frame)

View File

@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Nintendo; using BizHawk.Emulation.Consoles.Nintendo;
@ -12,28 +8,28 @@ namespace BizHawk.MultiClient
{ {
public partial class NESDebugger : Form public partial class NESDebugger : Form
{ {
const int ADDR_MAX = 0xFFFF; private const int ADDR_MAX = 0xFFFF;
const int DISASM_LINE_COUNT = 100; private const int DISASM_LINE_COUNT = 100;
private int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired private int defaultHeight;
int defaultHeight; private NES _nes;
NES Nes; private int pc;
private int addr;
private readonly List<DisasmOp> lines = new List<DisasmOp>();
private struct DisasmOp private struct DisasmOp
{ {
public int size; public readonly int size;
public string mnemonic; public readonly string mnemonic;
public DisasmOp(int s, string m) { size = s; mnemonic = m; } public DisasmOp(int s, string m) { size = s; mnemonic = m; }
} }
int pc;
int addr;
List<DisasmOp> lines = new List<DisasmOp>();
public NESDebugger() public NESDebugger()
{ {
InitializeComponent(); InitializeComponent();
DebugView.QueryItemText += new QueryItemTextHandler(DebugView_QueryItemText); DebugView.QueryItemText += DebugView_QueryItemText;
DebugView.QueryItemBkColor += new QueryItemBkColorHandler(DebugView_QueryItemBkColor); DebugView.QueryItemBkColor += DebugView_QueryItemBkColor;
DebugView.VirtualMode = true; DebugView.VirtualMode = true;
DebugView.ItemCount = ADDR_MAX + 1; DebugView.ItemCount = ADDR_MAX + 1;
Activated += (o, e) => UpdateValues(); Activated += (o, e) => UpdateValues();
@ -42,16 +38,16 @@ namespace BizHawk.MultiClient
public void Restart() public void Restart()
{ {
if (!(Global.Emulator is NES)) this.Close(); if (!(Global.Emulator is NES)) Close();
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
Nes = Global.Emulator as NES; _nes = Global.Emulator as NES;
} }
public void UpdateValues() public void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
addr = pc = Nes.cpu.PC; addr = pc = _nes.cpu.PC;
UpdateDebugView(); UpdateDebugView();
} }
@ -72,7 +68,7 @@ namespace BizHawk.MultiClient
for (int i = 0; i < line_count; ++i) for (int i = 0; i < line_count; ++i)
{ {
int advance; int advance;
string line = Nes.cpu.Disassemble((ushort)a, out advance); string line = _nes.cpu.Disassemble((ushort)a, out advance);
lines.Add(new DisasmOp(advance, line)); lines.Add(new DisasmOp(advance, line));
a += advance; a += advance;
if (a > ADDR_MAX) break; if (a > ADDR_MAX) break;
@ -82,29 +78,29 @@ namespace BizHawk.MultiClient
private void NESDebugger_Load(object sender, EventArgs e) private void NESDebugger_Load(object sender, EventArgs e)
{ {
LoadConfigSettings(); LoadConfigSettings();
Nes = Global.Emulator as NES; _nes = Global.Emulator as NES;
} }
private void LoadConfigSettings() private void LoadConfigSettings()
{ {
defaultWidth = this.Size.Width; //Save these first so that the user can restore to its original size defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = this.Size.Height; defaultHeight = Size.Height;
if (Global.Config.NESDebuggerSaveWindowPosition && Global.Config.NESDebuggerWndx >= 0 && Global.Config.NESDebuggerWndy >= 0) if (Global.Config.NESDebuggerSaveWindowPosition && Global.Config.NESDebuggerWndx >= 0 && Global.Config.NESDebuggerWndy >= 0)
this.Location = new Point(Global.Config.NESDebuggerWndx, Global.Config.NESDebuggerWndy); Location = new Point(Global.Config.NESDebuggerWndx, Global.Config.NESDebuggerWndy);
if (Global.Config.NESDebuggerWidth >= 0 && Global.Config.NESDebuggerHeight >= 0) if (Global.Config.NESDebuggerWidth >= 0 && Global.Config.NESDebuggerHeight >= 0)
{ {
this.Size = new System.Drawing.Size(Global.Config.NESDebuggerWidth, Global.Config.NESDebuggerHeight); Size = new Size(Global.Config.NESDebuggerWidth, Global.Config.NESDebuggerHeight);
} }
} }
public void SaveConfigSettings() public void SaveConfigSettings()
{ {
Global.Config.NESDebuggerWndx = this.Location.X; Global.Config.NESDebuggerWndx = Location.X;
Global.Config.NESDebuggerWndy = this.Location.Y; Global.Config.NESDebuggerWndy = Location.Y;
Global.Config.NESDebuggerWidth = this.Right - this.Left; Global.Config.NESDebuggerWidth = Right - Left;
Global.Config.NESDebuggerHeight = this.Bottom - this.Top; Global.Config.NESDebuggerHeight = Bottom - Top;
} }
private void DebugView_QueryItemBkColor(int index, int column, ref Color color) private void DebugView_QueryItemBkColor(int index, int column, ref Color color)
@ -134,7 +130,7 @@ namespace BizHawk.MultiClient
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void autoloadToolStripMenuItem_Click(object sender, EventArgs e) private void autoloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -155,7 +151,7 @@ namespace BizHawk.MultiClient
private void restoreOriginalSizeToolStripMenuItem_Click(object sender, EventArgs e) private void restoreOriginalSizeToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Size = new System.Drawing.Size(defaultWidth, defaultHeight); Size = new Size(defaultWidth, defaultHeight);
} }
} }
} }

View File

@ -1,22 +1,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
using BizHawk;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public partial class NESGameGenie : Form public partial class NESGameGenie : Form
{ {
public int address = -1; public int Address = -1;
public int value = -1; public int Value = -1;
public int compare = -1; public int Compare = -1;
Dictionary<char, int> GameGenieTable = new Dictionary<char, int>(); private readonly Dictionary<char, int> GameGenieTable = new Dictionary<char, int>();
public NESGameGenie() public NESGameGenie()
{ {
@ -51,8 +46,8 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.NESGGWndx = this.Location.X; Global.Config.NESGGWndx = Location.X;
Global.Config.NESGGWndy = this.Location.Y; Global.Config.NESGGWndy = Location.Y;
} }
private void GameGenieCode_KeyPress(object sender, KeyPressEventArgs e) private void GameGenieCode_KeyPress(object sender, KeyPressEventArgs e)
@ -63,7 +58,7 @@ namespace BizHawk.MultiClient
if (!(GameGenieTable.ContainsKey(e.KeyChar))) if (!(GameGenieTable.ContainsKey(e.KeyChar)))
{ {
if (!(e.KeyChar == (char)Keys.Back) || e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) if (e.KeyChar != (char)Keys.Back || e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{ {
e.Handled = true; e.Handled = true;
} }
@ -74,11 +69,6 @@ namespace BizHawk.MultiClient
} }
} }
private int GetBit(int value, int bit)
{
return (value >> bit) & 1;
}
public void DecodeGameGenieCode(string code) public void DecodeGameGenieCode(string code)
{ {
//char 3 bit 3 denotes the code length. //char 3 bit 3 denotes the code length.
@ -87,32 +77,32 @@ namespace BizHawk.MultiClient
//Char # | 1 | 2 | 3 | 4 | 5 | 6 | //Char # | 1 | 2 | 3 | 4 | 5 | 6 |
//Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0| //Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|
//maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|5|E|F|G| //maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|5|E|F|G|
value = 0; Value = 0;
address = 0x8000; Address = 0x8000;
int x; int x;
GameGenieTable.TryGetValue(code[0], out x); GameGenieTable.TryGetValue(code[0], out x);
value |= (x & 0x07); Value |= (x & 0x07);
value |= (x & 0x08) << 4; Value |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[1], out x); GameGenieTable.TryGetValue(code[1], out x);
value |= (x & 0x07) << 4; Value |= (x & 0x07) << 4;
address |= (x & 0x08) << 4; Address |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[2], out x); GameGenieTable.TryGetValue(code[2], out x);
address |= (x & 0x07) << 4; Address |= (x & 0x07) << 4;
GameGenieTable.TryGetValue(code[3], out x); GameGenieTable.TryGetValue(code[3], out x);
address |= (x & 0x07) << 12; Address |= (x & 0x07) << 12;
address |= (x & 0x08); Address |= (x & 0x08);
GameGenieTable.TryGetValue(code[4], out x); GameGenieTable.TryGetValue(code[4], out x);
address |= (x & 0x07); Address |= (x & 0x07);
address |= (x & 0x08) << 8; Address |= (x & 0x08) << 8;
GameGenieTable.TryGetValue(code[5], out x); GameGenieTable.TryGetValue(code[5], out x);
address |= (x & 0x07) << 8; Address |= (x & 0x07) << 8;
value |= (x & 0x08); Value |= (x & 0x08);
SetProperties(); SetProperties();
@ -122,67 +112,67 @@ namespace BizHawk.MultiClient
//Char # | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | //Char # | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
//Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0| //Bit # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|
//maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|%|E|F|G|!|^|&|*|5|@|#|$| //maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|%|E|F|G|!|^|&|*|5|@|#|$|
value = 0; Value = 0;
address = 0x8000; Address = 0x8000;
compare = 0; Compare = 0;
int x; int x;
GameGenieTable.TryGetValue(code[0], out x); GameGenieTable.TryGetValue(code[0], out x);
value |= (x & 0x07); Value |= (x & 0x07);
value |= (x & 0x08) << 4; Value |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[1], out x); GameGenieTable.TryGetValue(code[1], out x);
value |= (x & 0x07) << 4; Value |= (x & 0x07) << 4;
address |= (x & 0x08) << 4; Address |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[2], out x); GameGenieTable.TryGetValue(code[2], out x);
address |= (x & 0x07) << 4; Address |= (x & 0x07) << 4;
GameGenieTable.TryGetValue(code[3], out x); GameGenieTable.TryGetValue(code[3], out x);
address |= (x & 0x07) << 12; Address |= (x & 0x07) << 12;
address |= (x & 0x08); Address |= (x & 0x08);
GameGenieTable.TryGetValue(code[4], out x); GameGenieTable.TryGetValue(code[4], out x);
address |= (x & 0x07); Address |= (x & 0x07);
address |= (x & 0x08) << 8; Address |= (x & 0x08) << 8;
GameGenieTable.TryGetValue(code[5], out x); GameGenieTable.TryGetValue(code[5], out x);
address |= (x & 0x07) << 8; Address |= (x & 0x07) << 8;
compare |= (x & 0x08); Compare |= (x & 0x08);
GameGenieTable.TryGetValue(code[6], out x); GameGenieTable.TryGetValue(code[6], out x);
compare |= (x & 0x07); Compare |= (x & 0x07);
compare |= (x & 0x08) << 4; Compare |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[7], out x); GameGenieTable.TryGetValue(code[7], out x);
compare |= (x & 0x07) << 4; Compare |= (x & 0x07) << 4;
value |= (x & 0x08); Value |= (x & 0x08);
SetProperties(); SetProperties();
} }
} }
private void SetProperties() private void SetProperties()
{ {
if (address >= 0) if (Address >= 0)
AddressBox.Text = String.Format("{0:X4}", address); AddressBox.Text = String.Format("{0:X4}", Address);
else else
AddressBox.Text = ""; AddressBox.Text = "";
if (compare >= 0) if (Compare >= 0)
CompareBox.Text = String.Format("{0:X2}", compare); CompareBox.Text = String.Format("{0:X2}", Compare);
else else
CompareBox.Text = ""; CompareBox.Text = "";
if (value >= 0) if (Value >= 0)
ValueBox.Text = String.Format("{0:X2}", value); ValueBox.Text = String.Format("{0:X2}", Value);
} }
private void ClearProperties() private void ClearProperties()
{ {
address = -1; Address = -1;
value = -1; Value = -1;
compare = -1; Compare = -1;
AddressBox.Text = ""; AddressBox.Text = "";
CompareBox.Text = ""; CompareBox.Text = "";
ValueBox.Text = ""; ValueBox.Text = "";
@ -234,10 +224,10 @@ namespace BizHawk.MultiClient
{ {
if (Encoding.Checked && AddressBox.Text.Length > 0) if (Encoding.Checked && AddressBox.Text.Length > 0)
{ {
int a = int.Parse(AddressBox.Text, NumberStyles.HexNumber); //TODO: try/catch just in case? int a = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
if (ValueBox.Text.Length > 0) if (ValueBox.Text.Length > 0)
{ {
address = a; Address = a;
EncodeGameGenie(); EncodeGameGenie();
} }
} }
@ -255,14 +245,14 @@ namespace BizHawk.MultiClient
{ {
if (ValueBox.Text.Length > 0 && AddressBox.Text.Length > 0) if (ValueBox.Text.Length > 0 && AddressBox.Text.Length > 0)
{ {
compare = c; Compare = c;
EncodeGameGenie(); EncodeGameGenie();
} }
} }
} }
else else
{ {
compare = -1; Compare = -1;
EncodeGameGenie(); EncodeGameGenie();
} }
} }
@ -286,7 +276,7 @@ namespace BizHawk.MultiClient
{ {
if (AddressBox.Text.Length > 0) if (AddressBox.Text.Length > 0)
{ {
value = v; Value = v;
EncodeGameGenie(); EncodeGameGenie();
} }
} }
@ -298,29 +288,29 @@ namespace BizHawk.MultiClient
private void EncodeGameGenie() private void EncodeGameGenie()
{ {
char[] letters = { 'A', 'P', 'Z', 'L', 'G', 'I', 'T', 'Y', 'E', 'O', 'X', 'U', 'K', 'S', 'V', 'N' }; char[] letters = { 'A', 'P', 'Z', 'L', 'G', 'I', 'T', 'Y', 'E', 'O', 'X', 'U', 'K', 'S', 'V', 'N' };
if (address >= 0x8000) if (Address >= 0x8000)
address -= 0x8000; Address -= 0x8000;
GameGenieCode.Text = ""; GameGenieCode.Text = "";
byte[] num = { 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] num = { 0, 0, 0, 0, 0, 0, 0, 0 };
num[0] = (byte)((value & 7) + ((value >> 4) & 8)); num[0] = (byte)((Value & 7) + ((Value >> 4) & 8));
num[1] = (byte)(((value >> 4) & 7) + ((address >> 4) & 8)); num[1] = (byte)(((Value >> 4) & 7) + ((Address >> 4) & 8));
num[2] = (byte)(((address >> 4) & 7)); num[2] = (byte)(((Address >> 4) & 7));
num[3] = (byte)((address >> 12) + (address & 8)); num[3] = (byte)((Address >> 12) + (Address & 8));
num[4] = (byte)((address & 7) + ((address >> 8) & 8)); num[4] = (byte)((Address & 7) + ((Address >> 8) & 8));
num[5] = (byte)(((address >> 8) & 7)); num[5] = (byte)(((Address >> 8) & 7));
if (compare < 0 || CompareBox.Text.Length == 0) if (Compare < 0 || CompareBox.Text.Length == 0)
{ {
num[5] += (byte)(value & 8); num[5] += (byte)(Value & 8);
for (int x = 0; x < 6; x++) for (int x = 0; x < 6; x++)
GameGenieCode.Text += letters[num[x]]; GameGenieCode.Text += letters[num[x]];
} }
else else
{ {
num[2] += 8; num[2] += 8;
num[5] += (byte)(compare & 8); num[5] += (byte)(Compare & 8);
num[6] = (byte)((compare & 7) + ((compare >> 4) & 8)); num[6] = (byte)((Compare & 7) + ((Compare >> 4) & 8));
num[7] = (byte)(((compare >> 4) & 7) + (value & 8)); num[7] = (byte)(((Compare >> 4) & 7) + (Value & 8));
for (int x = 0; x < 8; x++) for (int x = 0; x < 8; x++)
GameGenieCode.Text += letters[num[x]]; GameGenieCode.Text += letters[num[x]];
} }
@ -341,8 +331,7 @@ namespace BizHawk.MultiClient
private void AddCheatClick() private void AddCheatClick()
{ {
Cheat c = new Cheat(); Cheat c = new Cheat {name = GameGenieCode.Text};
c.name = GameGenieCode.Text;
if (String.IsNullOrWhiteSpace(AddressBox.Text)) if (String.IsNullOrWhiteSpace(AddressBox.Text))
{ {
@ -379,7 +368,7 @@ namespace BizHawk.MultiClient
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e) private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,12 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO;
using BizHawk.Emulation.Consoles.Nintendo; using BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -14,13 +8,12 @@ namespace BizHawk.MultiClient
public partial class NESGraphicsConfig : Form public partial class NESGraphicsConfig : Form
{ {
//TODO: //TODO:
//Allow selection of palette file from archive //Allow selection of palette file from archive
//Hotkeys for BG & Sprite display toggle //Hotkeys for BG & Sprite display toggle
//NTSC filter settings? Hue, Tint (This should probably be a multiclient thing, not a nes specific thing?) //NTSC filter settings? Hue, Tint (This should probably be a multiclient thing, not a nes specific thing?)
HawkFile palette = null; private HawkFile palette;
NES nes; private NES nes;
public NESGraphicsConfig() public NESGraphicsConfig()
{ {
@ -52,14 +45,18 @@ namespace BizHawk.MultiClient
private void BrowsePalette_Click(object sender, EventArgs e) private void BrowsePalette_Click(object sender, EventArgs e)
{ {
OpenFileDialog ofd = new OpenFileDialog(); OpenFileDialog ofd = new OpenFileDialog
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESPalette, "NES"); {
ofd.Filter = "Palette Files (.pal)|*.PAL|All Files (*.*)|*.*"; InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESPalette, "NES"),
ofd.RestoreDirectory = true; Filter = "Palette Files (.pal)|*.PAL|All Files (*.*)|*.*",
RestoreDirectory = true
};
var result = ofd.ShowDialog(); var result = ofd.ShowDialog();
if (result != DialogResult.OK) if (result != DialogResult.OK)
{
return; return;
}
PalettePath.Text = ofd.FileName; PalettePath.Text = ofd.FileName;
} }
@ -68,7 +65,6 @@ namespace BizHawk.MultiClient
{ {
if (PalettePath.Text.Length > 0) if (PalettePath.Text.Length > 0)
{ {
string path = PathManager.MakeAbsolutePath(PalettePath.Text, "NES");
palette = new HawkFile(PalettePath.Text); palette = new HawkFile(PalettePath.Text);
if (palette != null && palette.Exists) if (palette != null && palette.Exists)
@ -108,9 +104,10 @@ namespace BizHawk.MultiClient
Global.Config.NESDispBackground = DispBackground.Checked; Global.Config.NESDispBackground = DispBackground.Checked;
Global.Config.NESBackgroundColor = BGColorDialog.Color.ToArgb(); Global.Config.NESBackgroundColor = BGColorDialog.Color.ToArgb();
if (!checkUseBackdropColor.Checked) if (!checkUseBackdropColor.Checked)
{
Global.Config.NESBackgroundColor &= 0x00FFFFFF; Global.Config.NESBackgroundColor &= 0x00FFFFFF;
}
this.Close(); Close();
} }
private void SetColorBox() private void SetColorBox()

View File

@ -1,14 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Nintendo; using BizHawk.Emulation.Consoles.Nintendo;
using System.IO;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -17,12 +11,8 @@ namespace BizHawk.MultiClient
//TODO: //TODO:
//Show Scroll Lines + UI Toggle //Show Scroll Lines + UI Toggle
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired private NES _nes;
int defaultHeight; private readonly NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
NES Nes;
NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
public NESNameTableViewer() public NESNameTableViewer()
{ {
@ -33,35 +23,35 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.NESNameTableWndx = this.Location.X; Global.Config.NESNameTableWndx = Location.X;
Global.Config.NESNameTableWndy = this.Location.Y; Global.Config.NESNameTableWndy = Location.Y;
Global.Config.NESNameTableRefreshRate = RefreshRate.Value; Global.Config.NESNameTableRefreshRate = RefreshRate.Value;
} }
unsafe void Generate(bool now = false) unsafe void Generate(bool now = false)
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (Nes == null) return; if (_nes == null) return;
if (now == false) if (now == false)
{ {
if (Global.Emulator.Frame % RefreshRate.Value != 0) return; if (Global.Emulator.Frame % RefreshRate.Value != 0) return;
} }
BitmapData bmpdata = NameTableView.nametables.LockBits(new Rectangle(0, 0, 512, 480), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bmpdata = NameTableView.Nametables.LockBits(new Rectangle(0, 0, 512, 480), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
int* dptr = (int*)bmpdata.Scan0.ToPointer(); int* dptr = (int*)bmpdata.Scan0.ToPointer();
int pitch = bmpdata.Stride / 4; int pitch = bmpdata.Stride / 4;
int pt_add = Nes.ppu.reg_2000.bg_pattern_hi ? 0x1000 : 0; int pt_add = _nes.ppu.reg_2000.bg_pattern_hi ? 0x1000 : 0;
//buffer all the data from the ppu, because it will be read multiple times and that is slow //buffer all the data from the ppu, because it will be read multiple times and that is slow
byte[] p = new byte[0x3000]; byte[] p = new byte[0x3000];
for (int x = 0; x < 0x3000; x++) for (int x = 0; x < 0x3000; x++)
p[x] = Nes.ppu.ppubus_peek(x); p[x] = _nes.ppu.ppubus_peek(x);
byte[] palram = new byte[0x20]; byte[] palram = new byte[0x20];
for (int x = 0; x < 0x20; x++) for (int x = 0; x < 0x20; x++)
palram[x] = Nes.ppu.PALRAM[x]; palram[x] = _nes.ppu.PALRAM[x];
int ytable = 0, yline = 0; int ytable = 0, yline = 0;
for (int y = 0; y < 480; y++) for (int y = 0; y < 480; y++)
@ -102,19 +92,19 @@ namespace BizHawk.MultiClient
pixel |= at; pixel |= at;
pixel = palram[pixel]; pixel = palram[pixel];
int cvalue = Nes.LookupColor(pixel); int cvalue = _nes.LookupColor(pixel);
*dptr = cvalue; *dptr = cvalue;
} }
dptr += pitch - 512; dptr += pitch - 512;
} }
NameTableView.nametables.UnlockBits(bmpdata); NameTableView.Nametables.UnlockBits(bmpdata);
NameTableView.Refresh(); NameTableView.Refresh();
} }
public void UpdateValues() public void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is NES)) return; if (!(Global.Emulator is NES)) return;
NES.PPU ppu = (Global.Emulator as NES).ppu; NES.PPU ppu = (Global.Emulator as NES).ppu;
ppu.NTViewCallback = Callback; ppu.NTViewCallback = Callback;
@ -122,27 +112,24 @@ namespace BizHawk.MultiClient
public void Restart() public void Restart()
{ {
if (!(Global.Emulator is NES)) this.Close(); if (!(Global.Emulator is NES)) Close();
Nes = Global.Emulator as NES; _nes = Global.Emulator as NES;
Generate(true); Generate(true);
} }
private void NESNameTableViewer_Load(object sender, EventArgs e) private void NESNameTableViewer_Load(object sender, EventArgs e)
{ {
defaultWidth = this.Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = this.Size.Height;
if (Global.Config.NESNameTableSaveWindowPosition && Global.Config.NESNameTableWndx >= 0 && Global.Config.NESNameTableWndy >= 0) if (Global.Config.NESNameTableSaveWindowPosition && Global.Config.NESNameTableWndx >= 0 && Global.Config.NESNameTableWndy >= 0)
this.Location = new Point(Global.Config.NESNameTableWndx, Global.Config.NESNameTableWndy); Location = new Point(Global.Config.NESNameTableWndx, Global.Config.NESNameTableWndy);
Nes = Global.Emulator as NES; _nes = Global.Emulator as NES;
RefreshRate.Value = Global.Config.NESNameTableRefreshRate; RefreshRate.Value = Global.Config.NESNameTableRefreshRate;
Generate(true); Generate(true);
} }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void autoloadToolStripMenuItem_Click(object sender, EventArgs e) private void autoloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -163,7 +150,7 @@ namespace BizHawk.MultiClient
private void txtScanline_TextChanged(object sender, EventArgs e) private void txtScanline_TextChanged(object sender, EventArgs e)
{ {
int temp = 0; int temp;
if (int.TryParse(txtScanline.Text, out temp)) if (int.TryParse(txtScanline.Text, out temp))
{ {
Callback.Scanline = temp; Callback.Scanline = temp;
@ -172,9 +159,9 @@ namespace BizHawk.MultiClient
private void NESNameTableViewer_FormClosed(object sender, FormClosedEventArgs e) private void NESNameTableViewer_FormClosed(object sender, FormClosedEventArgs e)
{ {
if (Nes == null) return; if (_nes == null) return;
if (Nes.ppu.NTViewCallback == Callback) if (_nes.ppu.NTViewCallback == Callback)
Nes.ppu.NTViewCallback = null; _nes.ppu.NTViewCallback = null;
} }
@ -222,7 +209,7 @@ namespace BizHawk.MultiClient
XYLabel.Text = TileX.ToString() + " : " + TileY.ToString(); XYLabel.Text = TileX.ToString() + " : " + TileY.ToString();
int PPUAddress = 0x2000 + (NameTable * 0x400) + ((TileY % 30) * 32) + (TileX % 32); int PPUAddress = 0x2000 + (NameTable * 0x400) + ((TileY % 30) * 32) + (TileX % 32);
PPUAddressLabel.Text = String.Format("{0:X4}", PPUAddress); PPUAddressLabel.Text = String.Format("{0:X4}", PPUAddress);
int TileID = Nes.ppu.ppubus_read(PPUAddress, true); int TileID = _nes.ppu.ppubus_read(PPUAddress, true);
TileIDLabel.Text = String.Format("{0:X2}", TileID); TileIDLabel.Text = String.Format("{0:X2}", TileID);
TableLabel.Text = NameTable.ToString(); TableLabel.Text = NameTable.ToString();
@ -232,18 +219,14 @@ namespace BizHawk.MultiClient
ytable += 2; ytable += 2;
yline = 240; yline = 240;
} }
int pt_add = Nes.ppu.reg_2000.bg_pattern_hi ? 0x1000 : 0;
int table = (e.X >> 8) + ytable; int table = (e.X >> 8) + ytable;
int ntaddr = (table << 10); int ntaddr = (table << 10);
int px = e.X & 255; int px = e.X & 255;
int py = e.Y - yline; int py = e.Y - yline;
int tx = px >> 3; int tx = px >> 3;
int ty = py >> 3; int ty = py >> 3;
int ntbyte_ptr = ntaddr + (ty * 32) + tx;
int atbyte_ptr = ntaddr + 0x3C0 + ((ty >> 2) << 3) + (tx >> 2); int atbyte_ptr = ntaddr + 0x3C0 + ((ty >> 2) << 3) + (tx >> 2);
int nt = Nes.ppu.ppubus_peek(ntbyte_ptr + 0x2000); int at = _nes.ppu.ppubus_peek(atbyte_ptr + 0x2000);
int at = Nes.ppu.ppubus_peek(atbyte_ptr + 0x2000);
if ((ty & 2) != 0) at >>= 4; if ((ty & 2) != 0) at >>= 4;
if ((tx & 2) != 0) at >>= 2; if ((tx & 2) != 0) at >>= 2;
at &= 0x03; at &= 0x03;

View File

@ -1,14 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
using BizHawk.Emulation.Consoles.Nintendo; using BizHawk.Emulation.Consoles.Nintendo;
using System.Diagnostics;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
@ -16,22 +10,18 @@ namespace BizHawk.MultiClient
{ {
//TODO: //TODO:
//If 8/16 sprite mode, mouse over should put 32x64 version of prite //If 8/16 sprite mode, mouse over should put 32x64 version of prite
//Speedups //Speedups
//Smarter refreshing? only refresh when things of changed, perhaps peek at the ppu to when the pattern table has changed, or sprites have moved //Smarter refreshing? only refresh when things of changed, perhaps peek at the ppu to when the pattern table has changed, or sprites have moved
//Maybe 48 individual bitmaps for sprites is faster than the overhead of redrawing all that transparent space //Maybe 48 individual bitmaps for sprites is faster than the overhead of redrawing all that transparent space
Bitmap ZoomBoxDefaultImage = new Bitmap(64, 64); private Bitmap ZoomBoxDefaultImage = new Bitmap(64, 64);
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired private NES _nes;
int defaultHeight; private readonly byte[] PPUBus = new byte[0x2000];
NES Nes; private readonly byte[] PPUBusprev = new byte[0x2000];
private readonly byte[] PALRAM = new byte[0x20];
byte[] PPUBus = new byte[0x2000]; private readonly byte[] PALRAMprev = new byte[0x20];
byte[] PPUBusprev = new byte[0x2000]; private readonly NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
byte[] PALRAM = new byte[0x20]; private bool ForceChange;
byte[] PALRAMprev = new byte[0x20];
NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
public NESPPU() public NESPPU()
{ {
@ -53,24 +43,21 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.NESPPUWndx = this.Location.X; Global.Config.NESPPUWndx = Location.X;
Global.Config.NESPPUWndy = this.Location.Y; Global.Config.NESPPUWndy = Location.Y;
Global.Config.NESPPURefreshRate = RefreshRate.Value; Global.Config.NESPPURefreshRate = RefreshRate.Value;
} }
public void Restart() public void Restart()
{ {
if (!(Global.Emulator is NES)) this.Close(); if (!(Global.Emulator is NES)) Close();
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
Nes = Global.Emulator as NES; _nes = Global.Emulator as NES;
Generate(true); Generate(true);
} }
private void LoadConfigSettings() private void LoadConfigSettings()
{ {
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height;
if (Global.Config.NESPPUSaveWindowPosition && Global.Config.NESPPUWndx >= 0 && Global.Config.NESPPUWndy >= 0) if (Global.Config.NESPPUSaveWindowPosition && Global.Config.NESPPUWndx >= 0 && Global.Config.NESPPUWndy >= 0)
Location = new Point(Global.Config.NESPPUWndx, Global.Config.NESPPUWndy); Location = new Point(Global.Config.NESPPUWndx, Global.Config.NESPPUWndy);
} }
@ -79,15 +66,14 @@ namespace BizHawk.MultiClient
{ {
return (byte)(((PPUBus[address] >> (7 - bit)) & 1)); return (byte)(((PPUBus[address] >> (7 - bit)) & 1));
} }
bool ForceChange = false; private bool CheckChange()
bool CheckChange()
{ {
bool changed = false; bool changed = false;
for (int x = 0; x < 0x20; x++) for (int x = 0; x < 0x20; x++)
{ {
PALRAMprev[x] = PALRAM[x]; PALRAMprev[x] = PALRAM[x];
PALRAM[x] = Nes.ppu.PALRAM[x]; PALRAM[x] = _nes.ppu.PALRAM[x];
if (PALRAM[x] != PALRAMprev[x]) if (PALRAM[x] != PALRAMprev[x])
{ {
changed = true; changed = true;
@ -97,7 +83,7 @@ namespace BizHawk.MultiClient
for (int x = 0; x < 0x2000; x++) for (int x = 0; x < 0x2000; x++)
{ {
PPUBusprev[x] = PPUBus[x]; PPUBusprev[x] = PPUBus[x];
PPUBus[x] = Nes.ppu.ppubus_peek(x); PPUBus[x] = _nes.ppu.ppubus_peek(x);
if (PPUBus[x] != PPUBusprev[x]) if (PPUBus[x] != PPUBusprev[x])
{ {
changed = true; changed = true;
@ -111,14 +97,14 @@ namespace BizHawk.MultiClient
unsafe void Generate(bool now = false) unsafe void Generate(bool now = false)
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (Global.Emulator.Frame % RefreshRate.Value == 0 || now) if (Global.Emulator.Frame % RefreshRate.Value == 0 || now)
{ {
bool Changed = CheckChange(); bool Changed = CheckChange();
int b0 = 0; int b0;
int b1 = 0; int b1;
byte value; byte value;
int cvalue; int cvalue;
@ -127,13 +113,12 @@ namespace BizHawk.MultiClient
ForceChange = false; ForceChange = false;
//Pattern Viewer //Pattern Viewer
int pal;
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
{ {
PaletteView.bgPalettesPrev[x].Value = PaletteView.bgPalettes[x].Value; PaletteView.BgPalettesPrev[x].Value = PaletteView.BgPalettes[x].Value;
PaletteView.spritePalettesPrev[x].Value = PaletteView.spritePalettes[x].Value; PaletteView.SpritePalettesPrev[x].Value = PaletteView.SpritePalettes[x].Value;
PaletteView.bgPalettes[x].Value = Nes.LookupColor(Nes.ppu.PALRAM[PaletteView.bgPalettes[x].Address]); PaletteView.BgPalettes[x].Value = _nes.LookupColor(_nes.ppu.PALRAM[PaletteView.BgPalettes[x].Address]);
PaletteView.spritePalettes[x].Value = Nes.LookupColor(Nes.ppu.PALRAM[PaletteView.spritePalettes[x].Address]); PaletteView.SpritePalettes[x].Value = _nes.LookupColor(_nes.ppu.PALRAM[PaletteView.SpritePalettes[x].Address]);
} }
if (PaletteView.HasChanged()) if (PaletteView.HasChanged())
{ {
@ -144,6 +129,7 @@ namespace BizHawk.MultiClient
int* framebuf = (int*)bmpdata.Scan0.ToPointer(); int* framebuf = (int*)bmpdata.Scan0.ToPointer();
for (int z = 0; z < 2; z++) for (int z = 0; z < 2; z++)
{ {
int pal;
if (z == 0) if (z == 0)
pal = PatternView.Pal0; pal = PatternView.Pal0;
else else
@ -162,7 +148,7 @@ namespace BizHawk.MultiClient
b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 1)); b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 1));
value = (byte)(b0 + (b1 << 1)); value = (byte)(b0 + (b1 << 1));
cvalue = Nes.LookupColor(Nes.ppu.PALRAM[value + (pal << 2)]); cvalue = _nes.LookupColor(_nes.ppu.PALRAM[value + (pal << 2)]);
int adr = (x + (j << 3)) + (y + (i << 3)) * (bmpdata.Stride >> 2); int adr = (x + (j << 3)) + (y + (i << 3)) * (bmpdata.Stride >> 2);
framebuf[adr + (z << 7)] = cvalue; framebuf[adr + (z << 7)] = cvalue;
} }
@ -176,10 +162,9 @@ namespace BizHawk.MultiClient
System.Drawing.Imaging.BitmapData bmpdata2 = SpriteView.sprites.LockBits(new Rectangle(new Point(0, 0), SpriteView.sprites.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Imaging.BitmapData bmpdata2 = SpriteView.sprites.LockBits(new Rectangle(new Point(0, 0), SpriteView.sprites.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
int* framebuf2 = (int*)bmpdata2.Scan0.ToPointer(); int* framebuf2 = (int*)bmpdata2.Scan0.ToPointer();
int BaseAddr, TileNum, Attributes, Palette;
int pt_add = Nes.ppu.reg_2000.obj_pattern_hi ? 0x1000 : 0; int pt_add = _nes.ppu.reg_2000.obj_pattern_hi ? 0x1000 : 0;
bool is8x16 = Nes.ppu.reg_2000.obj_size_16; bool is8x16 = _nes.ppu.reg_2000.obj_size_16;
//Sprite Viewer //Sprite Viewer
@ -187,9 +172,9 @@ namespace BizHawk.MultiClient
{ {
for (int r = 0; r < 16; r++) for (int r = 0; r < 16; r++)
{ {
BaseAddr = (r << 2) + (n << 6); int BaseAddr = (r << 2) + (n << 6);
TileNum = Nes.ppu.OAM[BaseAddr + 1]; int TileNum = _nes.ppu.OAM[BaseAddr + 1];
int PatAddr = 0; int PatAddr;
if (is8x16) if (is8x16)
{ {
@ -203,8 +188,8 @@ namespace BizHawk.MultiClient
} }
Attributes = Nes.ppu.OAM[BaseAddr + 2]; int Attributes = _nes.ppu.OAM[BaseAddr + 2];
Palette = Attributes & 0x03; int Palette = Attributes & 0x03;
for (int x = 0; x < 8; x++) for (int x = 0; x < 8; x++)
{ {
@ -214,7 +199,7 @@ namespace BizHawk.MultiClient
b0 = (byte)(((PPUBus[address] >> (7 - x)) & 1)); b0 = (byte)(((PPUBus[address] >> (7 - x)) & 1));
b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 1)); b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 1));
value = (byte)(b0 + (b1 << 1)); value = (byte)(b0 + (b1 << 1));
cvalue = Nes.LookupColor(Nes.ppu.PALRAM[16 + value + (Palette << 2)]); cvalue = _nes.LookupColor(_nes.ppu.PALRAM[16 + value + (Palette << 2)]);
int adr = (x + (r * 16)) + (y + (n * 24)) * (bmpdata2.Stride >> 2); int adr = (x + (r * 16)) + (y + (n * 24)) * (bmpdata2.Stride >> 2);
framebuf2[adr] = cvalue; framebuf2[adr] = cvalue;
@ -228,7 +213,7 @@ namespace BizHawk.MultiClient
b0 = (byte)(((PPUBus[address] >> (7 - x)) & 1)); b0 = (byte)(((PPUBus[address] >> (7 - x)) & 1));
b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 1)); b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 1));
value = (byte)(b0 + (b1 << 1)); value = (byte)(b0 + (b1 << 1));
cvalue = Nes.LookupColor(Nes.ppu.PALRAM[16 + value + (Palette << 2)]); cvalue = _nes.LookupColor(_nes.ppu.PALRAM[16 + value + (Palette << 2)]);
int adr = (x + (r << 4)) + ((y+8) + (n * 24)) * (bmpdata2.Stride >> 2); int adr = (x + (r << 4)) + ((y+8) + (n * 24)) * (bmpdata2.Stride >> 2);
framebuf2[adr] = cvalue; framebuf2[adr] = cvalue;
@ -243,17 +228,17 @@ namespace BizHawk.MultiClient
} }
} }
public unsafe void UpdateValues() public void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is NES)) return; if (!(Global.Emulator is NES)) return;
Nes.ppu.PPUViewCallback = Callback; _nes.ppu.PPUViewCallback = Callback;
} }
private void NESPPU_Load(object sender, EventArgs e) private void NESPPU_Load(object sender, EventArgs e)
{ {
LoadConfigSettings(); LoadConfigSettings();
Nes = Global.Emulator as NES; _nes = Global.Emulator as NES;
ClearDetails(); ClearDetails();
RefreshRate.Value = Global.Config.NESPPURefreshRate; RefreshRate.Value = Global.Config.NESPPURefreshRate;
Generate(true); Generate(true);
@ -288,7 +273,7 @@ namespace BizHawk.MultiClient
baseAddr += 16; baseAddr += 16;
int column = (e.X - PaletteView.Location.X) / 16; int column = (e.X - PaletteView.Location.X) / 16;
int addr = column + baseAddr; int addr = column + baseAddr;
AddressLabel.Text = "Address: 0x" + String.Format("{0:X4}", addr, NumberStyles.HexNumber); AddressLabel.Text = "Address: 0x" + String.Format("{0:X4}", addr);
int val; int val;
int offset = addr & 0x03; int offset = addr & 0x03;
@ -297,19 +282,19 @@ namespace BizHawk.MultiClient
if (baseAddr == 0x3F00) if (baseAddr == 0x3F00)
{ {
val = Nes.ppu.PALRAM[PaletteView.bgPalettes[column].Address]; val = _nes.ppu.PALRAM[PaletteView.BgPalettes[column].Address];
ValueLabel.Text = "ID: BG" + (column / 4).ToString(); ValueLabel.Text = "ID: BG" + (column / 4).ToString();
g.FillRectangle(new SolidBrush(PaletteView.bgPalettes[column].Color), 0, 0, 64, 64); g.FillRectangle(new SolidBrush(PaletteView.BgPalettes[column].Color), 0, 0, 64, 64);
} }
else else
{ {
val = Nes.ppu.PALRAM[PaletteView.spritePalettes[column].Address]; val = _nes.ppu.PALRAM[PaletteView.SpritePalettes[column].Address];
ValueLabel.Text = "ID: SPR" + (column / 4).ToString(); ValueLabel.Text = "ID: SPR" + (column / 4).ToString();
g.FillRectangle(new SolidBrush(PaletteView.spritePalettes[column].Color), 0, 0, 64, 64); g.FillRectangle(new SolidBrush(PaletteView.SpritePalettes[column].Color), 0, 0, 64, 64);
} }
g.Dispose(); g.Dispose();
Value3Label.Text = "Color: 0x" + String.Format("{0:X2}", val, NumberStyles.HexNumber); Value3Label.Text = "Color: 0x" + String.Format("{0:X2}", val);
Value4Label.Text = "Offset: " + offset.ToString(); Value4Label.Text = "Offset: " + offset.ToString();
ZoomBox.Image = bmp; ZoomBox.Image = bmp;
} }
@ -346,7 +331,7 @@ namespace BizHawk.MultiClient
} }
UpdatePaletteSelection(); UpdatePaletteSelection();
} }
HandleDefaultImage(e); HandleDefaultImage();
} }
private void UpdatePaletteSelection() private void UpdatePaletteSelection()
@ -369,8 +354,8 @@ namespace BizHawk.MultiClient
private void PatternView_MouseMove(object sender, MouseEventArgs e) private void PatternView_MouseMove(object sender, MouseEventArgs e)
{ {
int table = 0; int table = 0;
int address = 0; int address;
int tile = 0; int tile;
if (e.X > PatternView.Width / 2) if (e.X > PatternView.Width / 2)
table = 1; table = 1;
@ -391,12 +376,12 @@ namespace BizHawk.MultiClient
tile += (e.Y / 8) * 16; tile += (e.Y / 8) * 16;
string Usage = "Usage: "; string Usage = "Usage: ";
if ((Nes.ppu.reg_2000.Value & 0x10) << 4 == ((address >> 4) & 0x100)) if ((_nes.ppu.reg_2000.Value & 0x10) << 4 == ((address >> 4) & 0x100))
Usage = "BG"; Usage = "BG";
else if (((Nes.ppu.reg_2000.Value & 0x08) << 5) == ((address >> 4) & 0x100)) else if (((_nes.ppu.reg_2000.Value & 0x08) << 5) == ((address >> 4) & 0x100))
Usage = "SPR"; Usage = "SPR";
if ((Nes.ppu.reg_2000.Value & 0x20) > 0) if ((_nes.ppu.reg_2000.Value & 0x20) > 0)
Usage += " (SPR16)"; Usage += " (SPR16)";
AddressLabel.Text = "Address: " + String.Format("{0:X4}", address); AddressLabel.Text = "Address: " + String.Format("{0:X4}", address);
@ -531,7 +516,7 @@ namespace BizHawk.MultiClient
private void txtScanline_TextChanged(object sender, EventArgs e) private void txtScanline_TextChanged(object sender, EventArgs e)
{ {
int temp = 0; int temp;
if (int.TryParse(txtScanline.Text, out temp)) if (int.TryParse(txtScanline.Text, out temp))
{ {
Callback.Scanline = temp; Callback.Scanline = temp;
@ -540,9 +525,9 @@ namespace BizHawk.MultiClient
private void NESPPU_FormClosed(object sender, FormClosedEventArgs e) private void NESPPU_FormClosed(object sender, FormClosedEventArgs e)
{ {
if (Nes == null) return; if (_nes == null) return;
if (Nes.ppu.PPUViewCallback == Callback) if (_nes.ppu.PPUViewCallback == Callback)
Nes.ppu.PPUViewCallback = null; _nes.ppu.PPUViewCallback = null;
} }
private void SpriteView_MouseEnter(object sender, EventArgs e) private void SpriteView_MouseEnter(object sender, EventArgs e)
@ -557,12 +542,12 @@ namespace BizHawk.MultiClient
private void SpriteView_MouseMove(object sender, MouseEventArgs e) private void SpriteView_MouseMove(object sender, MouseEventArgs e)
{ {
bool is8x16 = Nes.ppu.reg_2000.obj_size_16; bool is8x16 = _nes.ppu.reg_2000.obj_size_16;
int SpriteNumber = ((e.Y / 24) * 16) + (e.X / 16); int SpriteNumber = ((e.Y / 24) * 16) + (e.X / 16);
int X = Nes.ppu.OAM[(SpriteNumber * 4) + 3]; int X = _nes.ppu.OAM[(SpriteNumber * 4) + 3];
int Y = Nes.ppu.OAM[SpriteNumber * 4]; int Y = _nes.ppu.OAM[SpriteNumber * 4];
int Color = Nes.ppu.OAM[(SpriteNumber * 4) + 2] & 0x03; int Color = _nes.ppu.OAM[(SpriteNumber * 4) + 2] & 0x03;
int Attributes = Nes.ppu.OAM[(SpriteNumber * 4) + 2]; int Attributes = _nes.ppu.OAM[(SpriteNumber * 4) + 2];
string flags = "Flags: "; string flags = "Flags: ";
int h = GetBit(Attributes, 6); int h = GetBit(Attributes, 6);
@ -577,7 +562,7 @@ namespace BizHawk.MultiClient
else else
flags += "Front"; flags += "Front";
int Tile = Nes.ppu.OAM[SpriteNumber * 1]; ; int Tile = _nes.ppu.OAM[SpriteNumber * 1];
AddressLabel.Text = "Number: " + String.Format("{0:X2}", SpriteNumber); AddressLabel.Text = "Number: " + String.Format("{0:X2}", SpriteNumber);
ValueLabel.Text = "X: " + String.Format("{0:X2}", X); ValueLabel.Text = "X: " + String.Format("{0:X2}", X);
@ -594,17 +579,17 @@ namespace BizHawk.MultiClient
private void PaletteView_MouseClick(object sender, MouseEventArgs e) private void PaletteView_MouseClick(object sender, MouseEventArgs e)
{ {
HandleDefaultImage(e); HandleDefaultImage();
} }
private void SpriteView_MouseClick(object sender, MouseEventArgs e) private void SpriteView_MouseClick(object sender, MouseEventArgs e)
{ {
HandleDefaultImage(e); HandleDefaultImage();
} }
private void HandleDefaultImage(MouseEventArgs e) private void HandleDefaultImage()
{ {
if (Control.ModifierKeys == Keys.Shift) //if (e.Button == MouseButtons.Right) if (ModifierKeys == Keys.Shift)
{ {
ZoomBoxDefaultImage = ZoomBox.Image as Bitmap; ZoomBoxDefaultImage = ZoomBox.Image as Bitmap;
} }
@ -687,12 +672,12 @@ namespace BizHawk.MultiClient
private void NESPPU_KeyDown(object sender, KeyEventArgs e) private void NESPPU_KeyDown(object sender, KeyEventArgs e)
{ {
if (Control.ModifierKeys.HasFlag(Keys.Control) && e.KeyCode == Keys.C) if (ModifierKeys.HasFlag(Keys.Control) && e.KeyCode == Keys.C)
{ {
// find the control under the mouse // find the control under the mouse
Point m = System.Windows.Forms.Cursor.Position; Point m = Cursor.Position;
Control top = this; Control top = this;
Control found = null; Control found;
do do
{ {
found = top.GetChildAtPoint(top.PointToClient(m)); found = top.GetChildAtPoint(top.PointToClient(m));
@ -702,13 +687,19 @@ namespace BizHawk.MultiClient
if (found != null) if (found != null)
{ {
var meth = found.GetType().GetMethod("ScreenshotToClipboard", System.Type.EmptyTypes); var meth = found.GetType().GetMethod("ScreenshotToClipboard", Type.EmptyTypes);
if (meth != null) if (meth != null)
{
meth.Invoke(found, null); meth.Invoke(found, null);
}
else if (found is PictureBox) else if (found is PictureBox)
{
Clipboard.SetImage((found as PictureBox).Image); Clipboard.SetImage((found as PictureBox).Image);
}
else else
{
return; return;
}
toolStripStatusLabel1.Text = found.Text + " copied to clipboard."; toolStripStatusLabel1.Text = found.Text + " copied to clipboard.";

View File

@ -1,12 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {

View File

@ -1,32 +1,28 @@
using System; using System.Drawing;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO; using System.IO;
using System.Drawing.Imaging; using System.Drawing.Imaging;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class NameTableViewer : Control public sealed class NameTableViewer : Control
{ {
Size pSize; public Bitmap Nametables;
public Bitmap nametables;
private readonly Size pSize;
public NameTableViewer() public NameTableViewer()
{ {
pSize = new Size(512, 480); pSize = new Size(512, 480);
nametables = new Bitmap(pSize.Width, pSize.Height); Nametables = new Bitmap(pSize.Width, pSize.Height);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.Opaque, true);
this.Size = new Size(256, 224); Size = new Size(256, 224);
this.BackColor = Color.Transparent; BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.NameTableViewer_Paint); Paint += NameTableViewer_Paint;
} }
public enum WhichNametable public enum WhichNametable
@ -36,38 +32,6 @@ namespace BizHawk.MultiClient
public WhichNametable Which = WhichNametable.NT_ALL; public WhichNametable Which = WhichNametable.NT_ALL;
private void Display(Graphics g)
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
switch (Which)
{
case WhichNametable.NT_ALL:
g.DrawImageUnscaled(nametables, 1, 1);
break;
case WhichNametable.NT_2000:
g.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 0, 0, 256, 240, GraphicsUnit.Pixel);
break;
case WhichNametable.NT_2400:
g.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 256, 0, 256, 240, GraphicsUnit.Pixel);
break;
case WhichNametable.NT_2800:
g.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 0, 240, 256, 240, GraphicsUnit.Pixel);
break;
case WhichNametable.NT_2C00:
g.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 256, 240, 256, 240, GraphicsUnit.Pixel);
break;
//adelikat: Meh, just in case we might want these, someone requested it but I can't remember the justification so I didn't do the UI part
case WhichNametable.TOPS:
g.DrawImage(nametables, new Rectangle(0, 0, 512, 240), 0, 0, 512, 240, GraphicsUnit.Pixel);
break;
case WhichNametable.BOTTOMS:
g.DrawImage(nametables, new Rectangle(0, 240, 512, 240), 0, 240, 512, 240, GraphicsUnit.Pixel);
break;
}
}
private void NameTableViewer_Paint(object sender, PaintEventArgs e) private void NameTableViewer_Paint(object sender, PaintEventArgs e)
{ {
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
@ -75,44 +39,48 @@ namespace BizHawk.MultiClient
switch (Which) switch (Which)
{ {
case WhichNametable.NT_ALL: case WhichNametable.NT_ALL:
e.Graphics.DrawImageUnscaled(nametables, 0, 0); e.Graphics.DrawImageUnscaled(Nametables, 0, 0);
break; break;
case WhichNametable.NT_2000: case WhichNametable.NT_2000:
e.Graphics.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 0, 0, 256, 240, GraphicsUnit.Pixel); e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 0, 0, 256, 240, GraphicsUnit.Pixel);
break; break;
case WhichNametable.NT_2400: case WhichNametable.NT_2400:
e.Graphics.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 256, 0, 256, 240, GraphicsUnit.Pixel); e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 256, 0, 256, 240, GraphicsUnit.Pixel);
break; break;
case WhichNametable.NT_2800: case WhichNametable.NT_2800:
e.Graphics.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 0, 240, 256, 240, GraphicsUnit.Pixel); e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 0, 240, 256, 240, GraphicsUnit.Pixel);
break; break;
case WhichNametable.NT_2C00: case WhichNametable.NT_2C00:
e.Graphics.DrawImage(nametables, new Rectangle(0, 0, 512, 480), 256, 240, 256, 240, GraphicsUnit.Pixel); e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 256, 240, 256, 240, GraphicsUnit.Pixel);
break; break;
//adelikat: Meh, just in case we might want these, someone requested it but I can't remember the justification so I didn't do the UI part //adelikat: Meh, just in case we might want these, someone requested it but I can't remember the justification so I didn't do the UI part
case WhichNametable.TOPS: case WhichNametable.TOPS:
e.Graphics.DrawImage(nametables, new Rectangle(0, 0, 512, 240), 0, 0, 512, 240, GraphicsUnit.Pixel); e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 240), 0, 0, 512, 240, GraphicsUnit.Pixel);
break; break;
case WhichNametable.BOTTOMS: case WhichNametable.BOTTOMS:
e.Graphics.DrawImage(nametables, new Rectangle(0, 240, 512, 240), 0, 240, 512, 240, GraphicsUnit.Pixel); e.Graphics.DrawImage(Nametables, new Rectangle(0, 240, 512, 240), 0, 240, 512, 240, GraphicsUnit.Pixel);
break; break;
} }
} }
public void Screenshot() public void Screenshot()
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Nametables"; {
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"); FileName = PathManager.FilesystemSafeName(Global.Game) + "-Nametables",
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*"; InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound(); Global.Sound.StopSound();
var result = sfd.ShowDialog(); var result = sfd.ShowDialog();
Global.Sound.StartSound(); Global.Sound.StartSound();
if (result != DialogResult.OK) if (result != DialogResult.OK)
{
return; return;
}
var file = new FileInfo(sfd.FileName); var file = new FileInfo(sfd.FileName);
using (Bitmap b = new Bitmap(Width, Height)) using (Bitmap b = new Bitmap(Width, Height))
@ -143,7 +111,7 @@ namespace BizHawk.MultiClient
{ {
Rectangle rect = new Rectangle(new Point(0, 0), Size); Rectangle rect = new Rectangle(new Point(0, 0), Size);
DrawToBitmap(b, rect); DrawToBitmap(b, rect);
System.Windows.Forms.Clipboard.SetImage(b); Clipboard.SetImage(b);
} }
} }
} }

View File

@ -1,22 +1,20 @@
using System; using System.Drawing;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO; using System.IO;
using System.Drawing.Imaging; using System.Drawing.Imaging;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class PaletteViewer : Control public sealed class PaletteViewer : Control
{ {
public class Palette public class Palette
{ {
public int Address { get; private set; } public int Address { get; private set; }
public int Value { get; set; } public int Value { get; set; }
public Color Color { get { return Color.FromArgb(Value); } private set { Value = value.ToArgb(); } } public Color Color
{
get { return Color.FromArgb(Value); }
}
public Palette(int address) public Palette(int address)
{ {
@ -25,11 +23,11 @@ namespace BizHawk.MultiClient
} }
} }
public Palette[] bgPalettes = new Palette[16]; public Palette[] BgPalettes = new Palette[16];
public Palette[] spritePalettes = new Palette[16]; public Palette[] SpritePalettes = new Palette[16];
public Palette[] bgPalettesPrev = new Palette[16]; public Palette[] BgPalettesPrev = new Palette[16];
public Palette[] spritePalettesPrev = new Palette[16]; public Palette[] SpritePalettesPrev = new Palette[16];
public PaletteViewer() public PaletteViewer()
{ {
@ -38,16 +36,16 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.Opaque, true);
this.Size = new Size(128, 32); Size = new Size(128, 32);
this.BackColor = Color.Transparent; BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PaletteViewer_Paint); Paint += PaletteViewer_Paint;
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
{ {
bgPalettes[x] = new Palette(x); BgPalettes[x] = new Palette(x);
spritePalettes[x] = new Palette(x + 16); SpritePalettes[x] = new Palette(x + 16);
bgPalettesPrev[x] = new Palette(x); BgPalettesPrev[x] = new Palette(x);
spritePalettesPrev[x] = new Palette(x + 16); SpritePalettesPrev[x] = new Palette(x + 16);
} }
} }
@ -56,8 +54,8 @@ namespace BizHawk.MultiClient
{ {
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
{ {
e.Graphics.FillRectangle(new SolidBrush(bgPalettes[x].Color), new Rectangle(x * 16, 0, 16, 16)); e.Graphics.FillRectangle(new SolidBrush(BgPalettes[x].Color), new Rectangle(x * 16, 0, 16, 16));
e.Graphics.FillRectangle(new SolidBrush(spritePalettes[x].Color), new Rectangle(x * 16, 16, 16, 16)); e.Graphics.FillRectangle(new SolidBrush(SpritePalettes[x].Color), new Rectangle(x * 16, 16, 16, 16));
} }
} }
@ -65,9 +63,9 @@ namespace BizHawk.MultiClient
{ {
for (int x = 0; x < 16; x++) for (int x = 0; x < 16; x++)
{ {
if (bgPalettes[x].Value != bgPalettesPrev[x].Value) if (BgPalettes[x].Value != BgPalettesPrev[x].Value)
return true; return true;
if (spritePalettes[x].Value != spritePalettesPrev[x].Value) if (SpritePalettes[x].Value != SpritePalettesPrev[x].Value)
return true; return true;
} }
return false; return false;
@ -75,12 +73,14 @@ namespace BizHawk.MultiClient
public void Screenshot() public void Screenshot()
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Palettes"; {
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"); FileName = PathManager.FilesystemSafeName(Global.Game) + "-Palettes",
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*"; InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound(); Global.Sound.StopSound();
var result = sfd.ShowDialog(); var result = sfd.ShowDialog();
Global.Sound.StartSound(); Global.Sound.StartSound();
@ -116,7 +116,7 @@ namespace BizHawk.MultiClient
using (var img = b) using (var img = b)
{ {
System.Windows.Forms.Clipboard.SetImage(img); Clipboard.SetImage(img);
} }
} }
} }

View File

@ -1,22 +1,18 @@
using System; using System.Drawing;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO; using System.IO;
using System.Drawing.Imaging; using System.Drawing.Imaging;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class PatternViewer : Control public sealed class PatternViewer : Control
{ {
Size pSize;
public Bitmap pattern; public Bitmap pattern;
public int Pal0 = 0; //0-7 Palette choice public int Pal0 = 0; //0-7 Palette choice
public int Pal1 = 0; public int Pal1 = 0;
private readonly Size pSize;
public PatternViewer() public PatternViewer()
{ {
pSize = new Size(256, 128); pSize = new Size(256, 128);
@ -26,9 +22,9 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true); SetStyle(ControlStyles.Opaque, true);
this.Size = pSize; Size = pSize;
this.BackColor = Color.Transparent; BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PatternViewer_Paint); Paint += PatternViewer_Paint;
} }
private void PatternViewer_Paint(object sender, PaintEventArgs e) private void PatternViewer_Paint(object sender, PaintEventArgs e)
@ -38,12 +34,14 @@ namespace BizHawk.MultiClient
public void Screenshot() public void Screenshot()
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Patterns"; {
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"); FileName = PathManager.FilesystemSafeName(Global.Game) + "-Patterns",
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*"; InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound(); Global.Sound.StopSound();
var result = sfd.ShowDialog(); var result = sfd.ShowDialog();
Global.Sound.StartSound(); Global.Sound.StartSound();
@ -79,7 +77,7 @@ namespace BizHawk.MultiClient
using (var img = b) using (var img = b)
{ {
System.Windows.Forms.Clipboard.SetImage(img); Clipboard.SetImage(img);
} }
} }
} }

View File

@ -1,20 +1,16 @@
using System; using System.Drawing;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO; using System.IO;
using System.Drawing.Imaging; using System.Drawing.Imaging;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class SpriteViewer : Control public sealed class SpriteViewer : Control
{ {
Size pSize;
public Bitmap sprites; public Bitmap sprites;
private readonly Size pSize;
public SpriteViewer() public SpriteViewer()
{ {
SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true);
@ -23,9 +19,9 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.DoubleBuffer, true);
this.Size = pSize; Size = pSize;
this.BackColor = Color.Transparent; BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.SpriteViewer_Paint); Paint += SpriteViewer_Paint;
} }
private void Display(Graphics g) private void Display(Graphics g)
@ -43,12 +39,14 @@ namespace BizHawk.MultiClient
public void Screenshot() public void Screenshot()
{ {
var sfd = new SaveFileDialog(); var sfd = new SaveFileDialog
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Sprites"; {
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"); FileName = PathManager.FilesystemSafeName(Global.Game) + "-Sprites",
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*"; InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound(); Global.Sound.StopSound();
var result = sfd.ShowDialog(); var result = sfd.ShowDialog();
Global.Sound.StartSound(); Global.Sound.StartSound();
@ -84,7 +82,7 @@ namespace BizHawk.MultiClient
using (var img = b) using (var img = b)
{ {
System.Windows.Forms.Clipboard.SetImage(img); Clipboard.SetImage(img);
} }
} }
} }

View File

@ -1,10 +1,4 @@
using System; using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing.Imaging; using System.Drawing.Imaging;
@ -12,10 +6,11 @@ namespace BizHawk.MultiClient
{ {
public partial class PCEBGCanvas : Control public partial class PCEBGCanvas : Control
{ {
const int BAT_WIDTH = 1024;
const int BAT_HEIGHT = 512;
public Bitmap bat; public Bitmap bat;
private const int BAT_WIDTH = 1024;
private const int BAT_HEIGHT = 512;
public PCEBGCanvas() public PCEBGCanvas()
{ {
bat = new Bitmap(BAT_WIDTH, BAT_HEIGHT, PixelFormat.Format32bppArgb); bat = new Bitmap(BAT_WIDTH, BAT_HEIGHT, PixelFormat.Format32bppArgb);
@ -23,25 +18,14 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.DoubleBuffer, true);
//SetStyle(ControlStyles.SupportsTransparentBackColor, true); //SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.Size = new Size(BAT_WIDTH, BAT_HEIGHT); Size = new Size(BAT_WIDTH, BAT_HEIGHT);
//this.BackColor = Color.Transparent; //this.BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.BGViewer_Paint); Paint += BGViewer_Paint;
} }
private void BGViewer_Paint(object sender, PaintEventArgs e) private void BGViewer_Paint(object sender, PaintEventArgs e)
{ {
e.Graphics.DrawImageUnscaled(bat, 0, 0); e.Graphics.DrawImageUnscaled(bat, 0, 0);
} }
private void InitializeComponent()
{
this.SuspendLayout();
//
// PCEBGCanvas
//
this.Name = "PCEBGCanvas";
this.ResumeLayout(false);
}
} }
} }

View File

@ -285,7 +285,6 @@
this.Name = "PCEBGViewer"; this.Name = "PCEBGViewer";
this.ShowIcon = false; this.ShowIcon = false;
this.Text = "PCE BG Viewer"; this.Text = "PCE BG Viewer";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PCEBGViewer_FormClosed);
this.Load += new System.EventHandler(this.PCEBGViewer_Load); this.Load += new System.EventHandler(this.PCEBGViewer_Load);
this.menuStrip1.ResumeLayout(false); this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout(); this.menuStrip1.PerformLayout();

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using BizHawk.Emulation.Consoles.TurboGrafx; using BizHawk.Emulation.Consoles.TurboGrafx;
@ -13,10 +8,8 @@ namespace BizHawk.MultiClient
{ {
public partial class PCEBGViewer : Form public partial class PCEBGViewer : Form
{ {
PCEngine pce; private PCEngine pce;
int VDCtype = 0; private int VDCtype;
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
public PCEBGViewer() public PCEBGViewer()
{ {
@ -36,13 +29,12 @@ namespace BizHawk.MultiClient
BitmapData buf = canvas.bat.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, canvas.bat.PixelFormat); BitmapData buf = canvas.bat.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, canvas.bat.PixelFormat);
int pitch = buf.Stride / 4; int pitch = buf.Stride / 4;
int* begin = (int*)buf.Scan0.ToPointer(); int* begin = (int*)buf.Scan0.ToPointer();
int* p = begin;
// TODO: this does not clear background, why? // TODO: this does not clear background, why?
//for (int i = 0; i < pitch * buf.Height; ++i, ++p) //for (int i = 0; i < pitch * buf.Height; ++i, ++p)
// *p = canvas.BackColor.ToArgb(); // *p = canvas.BackColor.ToArgb();
p = begin; int* p = begin;
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
{ {
int yTile = y / 8; int yTile = y / 8;
@ -72,10 +64,10 @@ namespace BizHawk.MultiClient
public void Restart() public void Restart()
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is PCEngine)) if (!(Global.Emulator is PCEngine))
{ {
this.Close(); Close();
return; return;
} }
pce = Global.Emulator as PCEngine; pce = Global.Emulator as PCEngine;
@ -83,23 +75,20 @@ namespace BizHawk.MultiClient
public void UpdateValues() public void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is PCEngine)) return; if (!(Global.Emulator is PCEngine)) return;
Generate(); Generate();
} }
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.PCEBGViewerWndx = this.Location.X; Global.Config.PCEBGViewerWndx = Location.X;
Global.Config.PCEBGViewerWndy = this.Location.Y; Global.Config.PCEBGViewerWndy = Location.Y;
Global.Config.PCEBGViewerRefreshRate = RefreshRate.Value; Global.Config.PCEBGViewerRefreshRate = RefreshRate.Value;
} }
private void LoadConfigSettings() private void LoadConfigSettings()
{ {
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height;
if (Global.Config.PCEBGViewerSaveWIndowPosition && Global.Config.PCEBGViewerWndx >= 0 && Global.Config.PCEBGViewerWndy >= 0) if (Global.Config.PCEBGViewerSaveWIndowPosition && Global.Config.PCEBGViewerWndx >= 0 && Global.Config.PCEBGViewerWndy >= 0)
Location = new Point(Global.Config.PCEBGViewerWndx, Global.Config.PCEBGViewerWndy); Location = new Point(Global.Config.PCEBGViewerWndx, Global.Config.PCEBGViewerWndy);
} }
@ -118,19 +107,9 @@ namespace BizHawk.MultiClient
} }
} }
private void PCEBGViewer_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void vdcComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
Generate();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e) private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,19 +1,10 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.TurboGrafx;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public partial class PCEGraphicsConfig : Form public partial class PCEGraphicsConfig : Form
{ {
PCEngine pce;
public PCEGraphicsConfig() public PCEGraphicsConfig()
{ {
InitializeComponent(); InitializeComponent();
@ -21,7 +12,6 @@ namespace BizHawk.MultiClient
private void PCEGraphicsConfig_Load(object sender, EventArgs e) private void PCEGraphicsConfig_Load(object sender, EventArgs e)
{ {
pce = Global.Emulator as PCEngine;
DispOBJ1.Checked = Global.Config.PCEDispOBJ1; DispOBJ1.Checked = Global.Config.PCEDispOBJ1;
DispBG1.Checked = Global.Config.PCEDispBG1; DispBG1.Checked = Global.Config.PCEDispBG1;
DispOBJ2.Checked = Global.Config.PCEDispOBJ2; DispOBJ2.Checked = Global.Config.PCEDispOBJ2;
@ -35,7 +25,7 @@ namespace BizHawk.MultiClient
Global.Config.PCEDispOBJ2 = DispOBJ2.Checked; Global.Config.PCEDispOBJ2 = DispOBJ2.Checked;
Global.Config.PCEDispBG2 = DispBG2.Checked; Global.Config.PCEDispBG2 = DispBG2.Checked;
this.Close(); Close();
} }
} }
} }

View File

@ -1,9 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
@ -12,15 +9,15 @@ namespace BizHawk.MultiClient
{ {
public partial class PlayMovie : Form public partial class PlayMovie : Form
{ {
List<Movie> MovieList = new List<Movie>(); private readonly List<Movie> MovieList = new List<Movie>();
bool sortReverse; private bool sortReverse;
string sortedCol; private string sortedCol;
public PlayMovie() public PlayMovie()
{ {
InitializeComponent(); InitializeComponent();
MovieView.QueryItemText += new QueryItemTextHandler(MovieView_QueryItemText); MovieView.QueryItemText += MovieView_QueryItemText;
MovieView.QueryItemBkColor += new QueryItemBkColorHandler(MovieView_QueryItemBkColor); MovieView.QueryItemBkColor += MovieView_QueryItemBkColor;
MovieView.VirtualMode = true; MovieView.VirtualMode = true;
sortReverse = false; sortReverse = false;
sortedCol = ""; sortedCol = "";
@ -54,15 +51,17 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e) private void Cancel_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void Run() private void Run()
{ {
ListView.SelectedIndexCollection indexes = MovieView.SelectedIndices; ListView.SelectedIndexCollection indexes = MovieView.SelectedIndices;
if (indexes.Count == 0) if (indexes.Count == 0)
{
return; return;
}
//Import file if necessary //Import file if necessary
@ -73,13 +72,12 @@ namespace BizHawk.MultiClient
{ {
Global.MainForm.ReadOnly = ReadOnlyCheckBox.Checked; Global.MainForm.ReadOnly = ReadOnlyCheckBox.Checked;
Run(); Run();
this.Close(); Close();
} }
private void BrowseMovies_Click(object sender, EventArgs e) private void BrowseMovies_Click(object sender, EventArgs e)
{ {
OpenFileDialog ofd = new OpenFileDialog(); OpenFileDialog ofd = new OpenFileDialog {InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath)};
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath);
string filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*"; string filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
ofd.Filter = filter; ofd.Filter = filter;
@ -115,13 +113,11 @@ namespace BizHawk.MultiClient
} }
} }
private int AddStateToList(string filename) private void AddStateToList(string filename)
{ {
using (var file = new HawkFile(filename)) using (var file = new HawkFile(filename))
{ {
if (!file.Exists) if (file.Exists)
return 0;
else
{ {
int x = IsDuplicate(filename); int x = IsDuplicate(filename);
if (x == 0) if (x == 0)
@ -133,10 +129,8 @@ namespace BizHawk.MultiClient
MovieList.Add(m); MovieList.Add(m);
sortReverse = false; sortReverse = false;
sortedCol = ""; sortedCol = "";
x = MovieList.Count - 1;
} }
} }
return x;
} }
} }
} }
@ -256,9 +250,8 @@ namespace BizHawk.MultiClient
} }
//Final tie breaker - Last used file //Final tie breaker - Last used file
DateTime t = new DateTime();
FileInfo f = new FileInfo(MovieList[Indexes[0]].Filename); FileInfo f = new FileInfo(MovieList[Indexes[0]].Filename);
t = f.LastAccessTime; DateTime t = f.LastAccessTime;
int mostRecent = Indexes[0]; int mostRecent = Indexes[0];
for (int x = 1; x < Indexes.Count; x++) for (int x = 1; x < Indexes.Count; x++)
{ {
@ -298,8 +291,7 @@ namespace BizHawk.MultiClient
{ {
Directory.CreateDirectory(d); Directory.CreateDirectory(d);
} }
string extension = "*." + Global.Config.MovieExtension;
foreach (string f in Directory.GetFiles(d, "*." + Global.Config.MovieExtension)) foreach (string f in Directory.GetFiles(d, "*." + Global.Config.MovieExtension))
{ {
AddMovieToList(f, false); AddMovieToList(f, false);
@ -379,29 +371,29 @@ namespace BizHawk.MultiClient
ListViewItem item = new ListViewItem(kvp.Key); ListViewItem item = new ListViewItem(kvp.Key);
item.SubItems.Add(kvp.Value); item.SubItems.Add(kvp.Value);
switch (kvp.Key.ToString()) switch (kvp.Key)
{ {
case MovieHeader.SHA1: case MovieHeader.SHA1:
if (kvp.Value.ToString() != Global.Game.Hash) if (kvp.Value != Global.Game.Hash)
{ {
item.BackColor = Color.Pink; item.BackColor = Color.Pink;
toolTip1.SetToolTip(DetailsView, "Current SHA1: " + Global.Game.Hash); toolTip1.SetToolTip(DetailsView, "Current SHA1: " + Global.Game.Hash);
} }
break; break;
case MovieHeader.MOVIEVERSION: case MovieHeader.MOVIEVERSION:
if (kvp.Value.ToString() != MovieHeader.MovieVersion) if (kvp.Value != MovieHeader.MovieVersion)
{ {
item.BackColor = Color.Yellow; item.BackColor = Color.Yellow;
} }
break; break;
case MovieHeader.EMULATIONVERSION: case MovieHeader.EMULATIONVERSION:
if (kvp.Value.ToString() != Global.MainForm.GetEmuVersion()) if (kvp.Value != Global.MainForm.GetEmuVersion())
{ {
item.BackColor = Color.Yellow; item.BackColor = Color.Yellow;
} }
break; break;
case MovieHeader.PLATFORM: case MovieHeader.PLATFORM:
if (kvp.Value.ToString() != Global.Game.System) if (kvp.Value != Global.Game.System)
{ {
item.BackColor = Color.Pink; item.BackColor = Color.Pink;
} }
@ -421,7 +413,7 @@ namespace BizHawk.MultiClient
button1.Enabled = false; button1.Enabled = false;
} }
if (MovieList[x].Subtitles.Count() > 0) if (MovieList[x].Subtitles.Count > 0)
{ {
button2.Enabled = true; button2.Enabled = true;
} }
@ -435,8 +427,7 @@ namespace BizHawk.MultiClient
{ {
ListView.SelectedIndexCollection indexes = MovieView.SelectedIndices; ListView.SelectedIndexCollection indexes = MovieView.SelectedIndices;
if (indexes.Count == 0) return; if (indexes.Count == 0) return;
EditCommentsForm c = new EditCommentsForm(); EditCommentsForm c = new EditCommentsForm {ReadOnly = true};
c.ReadOnly = true;
c.GetMovie(MovieList[MovieView.SelectedIndices[0]]); c.GetMovie(MovieList[MovieView.SelectedIndices[0]]);
c.Show(); c.Show();
} }
@ -445,8 +436,7 @@ namespace BizHawk.MultiClient
{ {
ListView.SelectedIndexCollection indexes = MovieView.SelectedIndices; ListView.SelectedIndexCollection indexes = MovieView.SelectedIndices;
if (indexes.Count == 0) return; if (indexes.Count == 0) return;
EditSubtitlesForm s = new EditSubtitlesForm(); EditSubtitlesForm s = new EditSubtitlesForm {ReadOnly = true};
s.ReadOnly = true;
s.GetMovie(MovieList[MovieView.SelectedIndices[0]]); s.GetMovie(MovieList[MovieView.SelectedIndices[0]]);
s.Show(); s.Show();
} }
@ -454,12 +444,12 @@ namespace BizHawk.MultiClient
private void MovieView_DoubleClick(object sender, EventArgs e) private void MovieView_DoubleClick(object sender, EventArgs e)
{ {
Run(); Run();
this.Close(); Close();
} }
private void MovieView_DragEnter(object sender, DragEventArgs e) private void MovieView_DragEnter(object sender, DragEventArgs e)
{ {
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
} }
private void MovieView_DragDrop(object sender, DragEventArgs e) private void MovieView_DragDrop(object sender, DragEventArgs e)

View File

@ -1,12 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Linq;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class RecentFiles public class RecentFiles
{ {
private int MAX_RECENT_FILES; //Maximum number of files private readonly int MAX_RECENT_FILES; //Maximum number of files
private List<string> recentlist; //List of recent files private readonly List<string> recentlist; //List of recent files
public RecentFiles() : this(8) { } public RecentFiles() : this(8) { }
public RecentFiles(int max) public RecentFiles(int max)
@ -22,7 +22,7 @@ namespace BizHawk.MultiClient
public bool IsEmpty public bool IsEmpty
{ {
get { return recentlist.Count > 0 ? false : true; } get { return recentlist.Count == 0; }
} }
public int Count public int Count
@ -63,12 +63,7 @@ namespace BizHawk.MultiClient
public List<string> GetRecentListTruncated(int length) public List<string> GetRecentListTruncated(int length)
{ {
//iterate through list, truncating each item to length, and return the result in a List<string> //iterate through list, truncating each item to length, and return the result in a List<string>
List<string> temp = new List<string>(); return recentlist.Select(t => t.Substring(0, length)).ToList();
for (int x = 0; x < recentlist.Count; x++)
{
temp.Add(recentlist[x].Substring(0, length));
}
return temp;
} }
public string GetRecentFileByPosition(int position) public string GetRecentFileByPosition(int position)

View File

@ -1,13 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using BizHawk.Emulation.Consoles.GB; using BizHawk.Emulation.Consoles.GB;
using BizHawk.Emulation.Consoles.Nintendo.SNES; using BizHawk.Emulation.Consoles.Nintendo.SNES;
using BizHawk.Emulation.Consoles.Sega; using BizHawk.Emulation.Consoles.Sega;
@ -33,7 +26,6 @@ namespace BizHawk.MultiClient
if (RecordBox.Text.Length == 0) if (RecordBox.Text.Length == 0)
return ""; return "";
string path = RecordBox.Text; string path = RecordBox.Text;
int x = path.LastIndexOf('\\');
if (path.LastIndexOf('\\') == -1) if (path.LastIndexOf('\\') == -1)
{ {
if (path[0] != '\\') if (path[0] != '\\')
@ -58,7 +50,7 @@ namespace BizHawk.MultiClient
if (test.Exists) if (test.Exists)
{ {
var result = MessageBox.Show(path + " already exists, overwrite?", "Confirm overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); var result = MessageBox.Show(path + " already exists, overwrite?", "Confirm overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == System.Windows.Forms.DialogResult.Cancel) if (result == DialogResult.Cancel)
return; return;
} }
@ -127,7 +119,7 @@ namespace BizHawk.MultiClient
var file = new FileInfo(temppath); var file = new FileInfo(temppath);
using (StreamReader sr = file.OpenText()) using (StreamReader sr = file.OpenText())
{ {
string str = ""; string str;
while ((str = sr.ReadLine()) != null) while ((str = sr.ReadLine()) != null)
{ {
@ -147,7 +139,7 @@ namespace BizHawk.MultiClient
{ {
Global.Config.DefaultAuthor = AuthorBox.Text; Global.Config.DefaultAuthor = AuthorBox.Text;
} }
this.Close(); Close();
} }
else else
{ {
@ -158,17 +150,19 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e) private void Cancel_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
string filename = ""; string filename = "";
SaveFileDialog sfd = new SaveFileDialog(); SaveFileDialog sfd = new SaveFileDialog
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath); {
sfd.DefaultExt = "." + Global.Config.MovieExtension; InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath),
sfd.FileName = RecordBox.Text; DefaultExt = "." + Global.Config.MovieExtension,
sfd.OverwritePrompt = false; FileName = RecordBox.Text,
OverwritePrompt = false
};
string filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*"; string filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
sfd.Filter = filter; sfd.Filter = filter;
@ -199,7 +193,7 @@ namespace BizHawk.MultiClient
private void RecordBox_DragEnter(object sender, DragEventArgs e) private void RecordBox_DragEnter(object sender, DragEventArgs e)
{ {
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
} }
private void RecordBox_DragDrop(object sender, DragEventArgs e) private void RecordBox_DragDrop(object sender, DragEventArgs e)

View File

@ -1,18 +1,10 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Sega;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public partial class SMSGraphicsConfig : Form public partial class SMSGraphicsConfig : Form
{ {
SMS sms;
public SMSGraphicsConfig() public SMSGraphicsConfig()
{ {
@ -21,7 +13,6 @@ namespace BizHawk.MultiClient
private void SMSGraphicsConfig_Load(object sender, EventArgs e) private void SMSGraphicsConfig_Load(object sender, EventArgs e)
{ {
sms = Global.Emulator as SMS;
DispOBJ.Checked = Global.Config.SMSDispOBJ; DispOBJ.Checked = Global.Config.SMSDispOBJ;
DispBG.Checked = Global.Config.SMSDispBG; DispBG.Checked = Global.Config.SMSDispBG;
} }
@ -31,7 +22,7 @@ namespace BizHawk.MultiClient
Global.Config.SMSDispOBJ = DispOBJ.Checked; Global.Config.SMSDispOBJ = DispOBJ.Checked;
Global.Config.SMSDispBG = DispBG.Checked; Global.Config.SMSDispBG = DispBG.Checked;
this.Close(); Close();
} }
} }
} }

View File

@ -25,11 +25,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Reflection; using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Nintendo.SNES; using BizHawk.Emulation.Consoles.Nintendo.SNES;
@ -118,7 +114,7 @@ namespace BizHawk.MultiClient
public void UpdateToolsAfter() public void UpdateToolsAfter()
{ {
SyncCore(); SyncCore();
if (this.Visible && !checkScanlineControl.Checked) if (Visible && !checkScanlineControl.Checked)
{ {
RegenerateData(); RegenerateData();
UpdateValues(); UpdateValues();
@ -128,7 +124,7 @@ namespace BizHawk.MultiClient
public void UpdateToolsLoadstate() public void UpdateToolsLoadstate()
{ {
SyncCore(); SyncCore();
if (this.Visible) if (Visible)
{ {
RegenerateData(); RegenerateData();
UpdateValues(); UpdateValues();
@ -174,7 +170,7 @@ namespace BizHawk.MultiClient
if (currentSnesCore != null) if (currentSnesCore != null)
{ {
if (this.Visible && checkScanlineControl.Checked) if (Visible && checkScanlineControl.Checked)
currentSnesCore.ScanlineHookManager.Register(this, ScanlineHook); currentSnesCore.ScanlineHookManager.Register(this, ScanlineHook);
else else
currentSnesCore.ScanlineHookManager.Unregister(this); currentSnesCore.ScanlineHookManager.Unregister(this);
@ -211,7 +207,7 @@ namespace BizHawk.MultiClient
void UpdateValues() void UpdateValues()
{ {
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
if (currentSnesCore == null) return; if (currentSnesCore == null) return;
txtOBSELSizeBits.Text = si.OBSEL_Size.ToString(); txtOBSELSizeBits.Text = si.OBSEL_Size.ToString();
@ -488,23 +484,23 @@ namespace BizHawk.MultiClient
class DisplayTypeItem class DisplayTypeItem
{ {
public eDisplayType type { get; set; } public eDisplayType Type { get; private set; }
public string descr { get; set; } public string Descr { get; private set; }
public DisplayTypeItem(string descr, eDisplayType type) public DisplayTypeItem(string descr, eDisplayType type)
{ {
this.type = type; Type = type;
this.descr = descr; Descr = descr;
} }
} }
class PaletteTypeItem class PaletteTypeItem
{ {
public SnesColors.ColorType type { get; set; } public SnesColors.ColorType Type { get; private set; }
public string descr { get; set; } public string Descr { get; private set; }
public PaletteTypeItem(string descr, SnesColors.ColorType type) public PaletteTypeItem(string descr, SnesColors.ColorType type)
{ {
this.type = type; Type = type;
this.descr = descr; Descr = descr;
} }
} }
@ -519,7 +515,7 @@ namespace BizHawk.MultiClient
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e) private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
@ -540,12 +536,12 @@ namespace BizHawk.MultiClient
private void SNESGraphicsDebugger_Load(object sender, EventArgs e) private void SNESGraphicsDebugger_Load(object sender, EventArgs e)
{ {
defaultWidth = this.Size.Width; //Save these first so that the user can restore to its original size defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = this.Size.Height; defaultHeight = Size.Height;
if (Global.Config.SNESGraphicsDebuggerSaveWindowPosition && Global.Config.SNESGraphicsDebuggerWndx >= 0 && Global.Config.SNESGraphicsDebuggerWndy >= 0) if (Global.Config.SNESGraphicsDebuggerSaveWindowPosition && Global.Config.SNESGraphicsDebuggerWndx >= 0 && Global.Config.SNESGraphicsDebuggerWndy >= 0)
{ {
this.Location = new Point(Global.Config.SNESGraphicsDebuggerWndx, Global.Config.SNESGraphicsDebuggerWndy); Location = new Point(Global.Config.SNESGraphicsDebuggerWndx, Global.Config.SNESGraphicsDebuggerWndy);
} }
checkBackdropColor.Checked = Global.Config.SNESGraphicsUseUserBackdropColor; checkBackdropColor.Checked = Global.Config.SNESGraphicsUseUserBackdropColor;
@ -561,8 +557,8 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.SNESGraphicsDebuggerWndx = this.Location.X; Global.Config.SNESGraphicsDebuggerWndx = Location.X;
Global.Config.SNESGraphicsDebuggerWndy = this.Location.Y; Global.Config.SNESGraphicsDebuggerWndy = Location.Y;
} }
bool suppression = false; bool suppression = false;
@ -889,7 +885,7 @@ namespace BizHawk.MultiClient
{ {
viewerPan = true; viewerPan = true;
panStartLocation = viewer.PointToScreen(e.Location); panStartLocation = viewer.PointToScreen(e.Location);
this.Cursor = Cursors.SizeAll; Cursor = Cursors.SizeAll;
} }
if ((e.Button & System.Windows.Forms.MouseButtons.Right) != 0) if ((e.Button & System.Windows.Forms.MouseButtons.Right) != 0)
@ -933,7 +929,7 @@ namespace BizHawk.MultiClient
{ {
viewerPan = false; viewerPan = false;
viewer.Capture = false; viewer.Capture = false;
this.Cursor = Cursors.Default; Cursor = Cursors.Default;
} }
private void viewer_MouseMove(object sender, MouseEventArgs e) private void viewer_MouseMove(object sender, MouseEventArgs e)
@ -1296,7 +1292,7 @@ namespace BizHawk.MultiClient
} }
string label = ""; string label = "";
if (found.Name == "viewer") if (found.Name == "viewer")
label = displayTypeItems.Find((x) => x.type == CurrDisplaySelection).descr; label = displayTypeItems.Find((x) => x.Type == CurrDisplaySelection).Descr;
if (found.Name == "viewerTile") if (found.Name == "viewerTile")
label = "Tile"; label = "Tile";
if (found.Name == "viewerMapEntryTile") if (found.Name == "viewerMapEntryTile")

View File

@ -1,12 +1,5 @@
using System; using System.Drawing;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Drawing.Imaging;
using BizHawk.Core; using BizHawk.Core;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -17,7 +10,7 @@ namespace BizHawk.MultiClient
{ {
SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true);
if(!DesignMode) if(!DesignMode)
this.BackColor = Color.Transparent; BackColor = Color.Transparent;
} }
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)

View File

@ -1,15 +1,11 @@
using System; using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
class SavestateManager class SavestateManager
{ {
private bool[] slots = new bool[10]; private readonly bool[] slots = new bool[10];
private bool[] redo = new bool[10]; private readonly bool[] redo = new bool[10];
public SavestateManager() public SavestateManager()
{ {
@ -18,7 +14,6 @@ namespace BizHawk.MultiClient
public void Update() public void Update()
{ {
string path;
if (Global.Game == null || Global.Emulator == null) if (Global.Game == null || Global.Emulator == null)
{ {
for (int x = 0; x < 10; x++) for (int x = 0; x < 10; x++)
@ -27,9 +22,9 @@ namespace BizHawk.MultiClient
} }
for (int x = 0; x < 10; x++) for (int x = 0; x < 10; x++)
{ {
path = PathManager.SaveStatePrefix(Global.Game) + "." + "QuickSave" + x + ".State"; string path = PathManager.SaveStatePrefix(Global.Game) + "." + "QuickSave" + x + ".State";
var file = new FileInfo(path); var file = new FileInfo(path);
if (file.Directory.Exists == false) if (file.Directory != null && file.Directory.Exists == false)
file.Directory.Create(); file.Directory.Create();
slots[x] = file.Exists; slots[x] = file.Exists;
} }

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Calculator; using BizHawk.Emulation.Consoles.Calculator;
@ -95,19 +90,19 @@ namespace BizHawk.MultiClient
public void Restart() public void Restart()
{ {
if (!(Global.Emulator is TI83)) if (!(Global.Emulator is TI83))
this.Close(); Close();
if (!this.IsHandleCreated || this.IsDisposed) return; if (!IsHandleCreated || IsDisposed) return;
} }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.Config.TI83KeyPadWndx = this.Location.X; Global.Config.TI83KeyPadWndx = Location.X;
Global.Config.TI83KeyPadWndy = this.Location.Y; Global.Config.TI83KeyPadWndy = Location.Y;
} }
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e) private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)
@ -369,10 +364,15 @@ namespace BizHawk.MultiClient
private void showHotkToolStripMenuItem_Click(object sender, EventArgs e) private void showHotkToolStripMenuItem_Click(object sender, EventArgs e)
{ {
Global.Config.TI83ToolTips ^= true; Global.Config.TI83ToolTips ^= true;
if (Global.Config.TI83ToolTips == true)
if (Global.Config.TI83ToolTips)
{
SetToolTips(); SetToolTips();
}
else else
{
StopToolTips(); StopToolTips();
}
} }
private void ZERO_Click(object sender, EventArgs e) private void ZERO_Click(object sender, EventArgs e)

View File

@ -1,10 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -39,7 +33,7 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e) private void Cancel_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void OK_Click(object sender, EventArgs e) private void OK_Click(object sender, EventArgs e)
@ -50,11 +44,11 @@ namespace BizHawk.MultiClient
for (int x = 0; x < CommentGrid.Rows.Count - 1; x++) for (int x = 0; x < CommentGrid.Rows.Count - 1; x++)
{ {
DataGridViewCell c = CommentGrid.Rows[x].Cells[0]; DataGridViewCell c = CommentGrid.Rows[x].Cells[0];
selectedMovie.Header.Comments.Add("comment " + c.Value.ToString()); selectedMovie.Header.Comments.Add("comment " + c.Value);
} }
selectedMovie.WriteMovie(); selectedMovie.WriteMovie();
} }
this.Close(); Close();
} }
public void GetMovie(Movie m) public void GetMovie(Movie m)

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
@ -35,21 +30,21 @@ namespace BizHawk.MultiClient
{ {
int x = Height + ((SubGrid.Rows.Count - 8) * 21); int x = Height + ((SubGrid.Rows.Count - 8) * 21);
if (x < 600) if (x < 600)
this.Height = x; Height = x;
else else
this.Height = 600; Height = 600;
} }
} }
private void Cancel_Click(object sender, EventArgs e) private void Cancel_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void ShowError(int row, int column) private void ShowError(int row, int column)
{ {
DataGridViewCell c = SubGrid.Rows[row].Cells[column]; DataGridViewCell c = SubGrid.Rows[row].Cells[column];
string error = "Unable to parse value: " + c.Value.ToString(); string error = "Unable to parse value: " + c.Value;
string caption = "Parse Error Row " + row.ToString() + " Column " + column.ToString(); string caption = "Parse Error Row " + row.ToString() + " Column " + column.ToString();
MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
@ -85,16 +80,16 @@ namespace BizHawk.MultiClient
} }
selectedMovie.WriteMovie(); selectedMovie.WriteMovie();
} }
this.Close(); Close();
} }
public void GetMovie(Movie m) public void GetMovie(Movie m)
{ {
selectedMovie = m; selectedMovie = m;
SubtitleList subs = new SubtitleList(m); SubtitleList subs = new SubtitleList(m);
if (subs.Count() == 0) return; if (subs.Count == 0) return;
for (int x = 0; x < subs.Count(); x++) for (int x = 0; x < subs.Count; x++)
{ {
Subtitle s = subs.GetSubtitleByIndex(x); Subtitle s = subs.GetSubtitleByIndex(x);
SubGrid.Rows.Add(); SubGrid.Rows.Add();

View File

@ -51,7 +51,7 @@ namespace BizHawk.MultiClient
} }
} }
HashSet<string> Pressed = new HashSet<string>(); readonly HashSet<string> Pressed = new HashSet<string>();
} }
//filters input for things called Up and Down while considering the client's AllowUD_LR option. //filters input for things called Up and Down while considering the client's AllowUD_LR option.
@ -67,8 +67,10 @@ namespace BizHawk.MultiClient
public bool IsPressed(string button) public bool IsPressed(string button)
{ {
if (Global.Config.AllowUD_LR == true) if (Global.Config.AllowUD_LR)
{
return Source.IsPressed(button); return Source.IsPressed(button);
}
string prefix; string prefix;
@ -76,13 +78,17 @@ namespace BizHawk.MultiClient
{ {
prefix = button.GetPrecedingString("Down"); prefix = button.GetPrecedingString("Down");
if (Source.IsPressed(prefix + "Up")) if (Source.IsPressed(prefix + "Up"))
{
return false; return false;
}
} }
if (button.Contains("Right")) if (button.Contains("Right"))
{ {
prefix = button.GetPrecedingString("Right"); prefix = button.GetPrecedingString("Right");
if (Source.IsPressed(prefix + "Left")) if (Source.IsPressed(prefix + "Left"))
{
return false; return false;
}
} }
return Source.IsPressed(button); return Source.IsPressed(button);
@ -150,7 +156,6 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
bool source = Source[button];
if (stickySet.Contains(button)) if (stickySet.Contains(button))
{ {
return false; return false;
@ -249,7 +254,7 @@ namespace BizHawk.MultiClient
public int Off { get; set; } public int Off { get; set; }
public WorkingDictionary<string, int> buttonStarts = new WorkingDictionary<string, int>(); public WorkingDictionary<string, int> buttonStarts = new WorkingDictionary<string, int>();
private HashSet<string> stickySet = new HashSet<string>(); private readonly HashSet<string> stickySet = new HashSet<string>();
public IController Source; public IController Source;
@ -508,13 +513,6 @@ namespace BizHawk.MultiClient
foreach (string button in Global.BUTTONS["Commodore 64 Keyboard"].Keys) foreach (string button in Global.BUTTONS["Commodore 64 Keyboard"].Keys)
{ {
if (Global.BUTTONS["Commodore 64 Keyboard"][button] == "Key Restore")
{
int xx = 0;
xx++;
int y = xx;
y++;
}
input.Append(IsBasePressed(button) ? Global.BUTTONS["Commodore 64 Keyboard"][button] : "."); input.Append(IsBasePressed(button) ? Global.BUTTONS["Commodore 64 Keyboard"][button] : ".");
} }
input.Append('|'); input.Append('|');
@ -683,7 +681,8 @@ namespace BizHawk.MultiClient
public class CopyControllerAdapter : IController public class CopyControllerAdapter : IController
{ {
public IController Source; public IController Source;
NullController _null = new NullController();
private readonly NullController _null = new NullController();
IController Curr IController Curr
{ {
@ -713,13 +712,15 @@ namespace BizHawk.MultiClient
string[] parts = button.Split(' '); string[] parts = button.Split(' ');
if (parts.Length < 2) return null; if (parts.Length < 2) return null;
if (parts[0][0] != 'P') return null; if (parts[0][0] != 'P') return null;
int player = 0; int player;
if (!int.TryParse(parts[0].Substring(1), out player)) if (!int.TryParse(parts[0].Substring(1), out player))
{
return null; return null;
var bnp = new ButtonNameParser(); }
bnp.PlayerNum = player; else
bnp.ButtonPart = button.Substring(parts[0].Length + 1); {
return bnp; return new ButtonNameParser { PlayerNum = player, ButtonPart = button.Substring(parts[0].Length + 1) };
}
} }
public int PlayerNum; public int PlayerNum;
@ -741,7 +742,7 @@ namespace BizHawk.MultiClient
public int PlayerTargetMask = 0; public int PlayerTargetMask = 0;
public ControllerDefinition Type { get { return Source.Type; } } public ControllerDefinition Type { get { return Source.Type; } }
public bool this[string button] { get { return this.IsPressed(button); } } public bool this[string button] { get { return IsPressed(button); } }
public float GetFloat(string name) { return Source.GetFloat(name); } public float GetFloat(string name) { return Source.GetFloat(name); }
public void UpdateControls(int frame) { Source.UpdateControls(frame); } public void UpdateControls(int frame) { Source.UpdateControls(frame); }
@ -766,11 +767,6 @@ namespace BizHawk.MultiClient
public class MovieControllerAdapter : IController public class MovieControllerAdapter : IController
{ {
public MovieControllerAdapter()
{
//OutputController = new ForceControllerAdapter();
}
//IController implementation: //IController implementation:
public ControllerDefinition Type { get; set; } public ControllerDefinition Type { get; set; }
public bool this[string button] { get { return MyBoolButtons[button]; } } public bool this[string button] { get { return MyBoolButtons[button]; } }
@ -779,7 +775,7 @@ namespace BizHawk.MultiClient
public void UpdateControls(int frame) { } public void UpdateControls(int frame) { }
//-------- //--------
WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>(); private readonly WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
void Force(string button, bool state) void Force(string button, bool state)
{ {
@ -790,11 +786,13 @@ namespace BizHawk.MultiClient
class MnemonicChecker class MnemonicChecker
{ {
private readonly string m;
public MnemonicChecker(string _m) public MnemonicChecker(string _m)
{ {
m = _m; m = _m;
} }
string m;
public bool this[int c] public bool this[int c]
{ {
get { return m[c] != '.'; } get { return m[c] != '.'; }

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using System.IO;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
@ -16,9 +12,8 @@ namespace BizHawk.MultiClient
public Movie(string filename) public Movie(string filename)
{ {
Mode = MOVIEMODE.INACTIVE; Mode = MOVIEMODE.INACTIVE;
lastlog = 0;
Rerecords = 0; Rerecords = 0;
this.Filename = filename; Filename = filename;
IsText = true; IsText = true;
preload_framecount = 0; preload_framecount = 0;
IsCountingRerecords = true; IsCountingRerecords = true;
@ -134,7 +129,7 @@ namespace BizHawk.MultiClient
set set
{ {
startsfromsavestate = value; startsfromsavestate = value;
if (value == true) if (value)
{ {
Header.AddHeaderLine(MovieHeader.STARTSFROMSAVESTATE, "1"); Header.AddHeaderLine(MovieHeader.STARTSFROMSAVESTATE, "1");
} }
@ -312,7 +307,9 @@ namespace BizHawk.MultiClient
return; return;
} }
Directory.CreateDirectory(new FileInfo(Filename).Directory.FullName); var directory_info = new FileInfo(Filename).Directory;
if (directory_info != null) Directory.CreateDirectory(directory_info.FullName);
if (IsText) if (IsText)
{ {
WriteText(stream); WriteText(stream);
@ -329,7 +326,9 @@ namespace BizHawk.MultiClient
{ {
return; return;
} }
Directory.CreateDirectory(new FileInfo(Filename).Directory.FullName); var directory_info = new FileInfo(Filename).Directory;
if (directory_info != null) Directory.CreateDirectory(directory_info.FullName);
if (IsText) if (IsText)
{ {
WriteText(Filename); WriteText(Filename);
@ -370,7 +369,8 @@ namespace BizHawk.MultiClient
BackupName = BackupName.Insert(Filename.LastIndexOf("."), String.Format(".{0:yyyy-MM-dd HH.mm.ss}", DateTime.Now)); BackupName = BackupName.Insert(Filename.LastIndexOf("."), String.Format(".{0:yyyy-MM-dd HH.mm.ss}", DateTime.Now));
BackupName = Global.Config.MoviesBackupPath + "\\" + Path.GetFileName(BackupName); BackupName = Global.Config.MoviesBackupPath + "\\" + Path.GetFileName(BackupName);
Directory.CreateDirectory(new FileInfo(BackupName).Directory.FullName); var directory_info = new FileInfo(BackupName).Directory;
if (directory_info != null) Directory.CreateDirectory(directory_info.FullName);
Global.OSD.AddMessage("Backup movie saved to " + BackupName); Global.OSD.AddMessage("Backup movie saved to " + BackupName);
if (IsText) if (IsText)
@ -402,27 +402,37 @@ namespace BizHawk.MultiClient
using (StreamReader sr = file.OpenText()) using (StreamReader sr = file.OpenText())
{ {
string str = ""; string str;
while ((str = sr.ReadLine()) != null) while ((str = sr.ReadLine()) != null)
{ {
if (str == "" || Header.AddHeaderFromLine(str)) if (str == "" || Header.AddHeaderFromLine(str))
{
continue; continue;
}
if (str.StartsWith("subtitle") || str.StartsWith("sub")) if (str.StartsWith("subtitle") || str.StartsWith("sub"))
{
Subtitles.AddSubtitle(str); Subtitles.AddSubtitle(str);
}
else if (str[0] == '|') else if (str[0] == '|')
{ {
string frames = sr.ReadToEnd(); string frames = sr.ReadToEnd();
int length = str.Length; int length = str.Length;
// Account for line breaks of either size. // Account for line breaks of either size.
if (frames.IndexOf("\r\n") != -1) if (frames.IndexOf("\r\n") != -1)
{
length++; length++;
}
length++; length++;
// Count the remaining frames and the current one. // Count the remaining frames and the current one.
this.preload_framecount = (frames.Length / length) + 1; preload_framecount = (frames.Length/length) + 1;
break; break;
} }
else else
{
Header.Comments.Add(str); Header.Comments.Add(str);
}
} }
sr.Close(); sr.Close();
} }
@ -448,8 +458,6 @@ namespace BizHawk.MultiClient
public string GetInput(int frame) public string GetInput(int frame)
{ {
lastlog = frame;
int getframe; int getframe;
if (Loop) if (Loop)
@ -553,7 +561,7 @@ namespace BizHawk.MultiClient
public void CaptureState() public void CaptureState()
{ {
if (StateCapturing == true) if (StateCapturing)
{ {
byte[] state = Global.Emulator.SaveStateBinary(); byte[] state = Global.Emulator.SaveStateBinary();
Log.AddState(state); Log.AddState(state);
@ -572,7 +580,7 @@ namespace BizHawk.MultiClient
if (frame <= Log.StateFirstIndex) if (frame <= Log.StateFirstIndex)
{ {
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Log.InitState))); Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Log.InitState)));
if (Global.MainForm.EmulatorPaused == true && frame > 0) if (Global.MainForm.EmulatorPaused && frame > 0)
{ {
Global.MainForm.UnpauseEmulator(); Global.MainForm.UnpauseEmulator();
} }
@ -785,22 +793,25 @@ namespace BizHawk.MultiClient
var reader = new StreamReader(path); var reader = new StreamReader(path);
MovieLog l = new MovieLog(); MovieLog l = new MovieLog();
string line;
string GUID;
int stateFrame = 0; int stateFrame = 0;
while (true) while (true)
{ {
line = reader.ReadLine(); string line = reader.ReadLine();
if (line == null) if (line == null)
{
return false; return false;
if (line.Trim() == "") continue; }
else if (line.Trim() == "")
{
continue;
}
else if (line.Contains("GUID")) else if (line.Contains("GUID"))
{ {
GUID = ParseHeader(line, MovieHeader.GUID); string guid = ParseHeader(line, MovieHeader.GUID);
if (Header.GetHeaderLine(MovieHeader.GUID) != GUID) if (Header.GetHeaderLine(MovieHeader.GUID) != guid)
{ {
//GUID Mismatch error //GUID Mismatch error
var result = MessageBox.Show(GUID + " : " + Header.GetHeaderLine(MovieHeader.GUID) + "\n" + var result = MessageBox.Show(guid + " : " + Header.GetHeaderLine(MovieHeader.GUID) + "\n" +
"The savestate GUID does not match the current movie. Proceed anyway?", "GUID Mismatch error", "The savestate GUID does not match the current movie. Proceed anyway?", "GUID Mismatch error",
MessageBoxButtons.YesNo, MessageBoxIcon.Question); MessageBoxButtons.YesNo, MessageBoxIcon.Question);
@ -901,15 +912,14 @@ namespace BizHawk.MultiClient
#region Private Fields #region Private Fields
private MovieLog Log = new MovieLog(); private readonly MovieLog Log = new MovieLog();
private enum MOVIEMODE { INACTIVE, PLAY, RECORD, FINISHED }; private enum MOVIEMODE { INACTIVE, PLAY, RECORD, FINISHED };
private MOVIEMODE Mode = MOVIEMODE.INACTIVE; private MOVIEMODE Mode = MOVIEMODE.INACTIVE;
private bool statecapturing; private bool statecapturing;
private bool startsfromsavestate; private bool startsfromsavestate;
private int preload_framecount; //Not a a reliable number, used for preloading (when no log has yet been loaded), this is only for quick stat compilation for dialogs such as play movie private int preload_framecount; //Not a a reliable number, used for preloading (when no log has yet been loaded), this is only for quick stat compilation for dialogs such as play movie
private int lastlog;
private int rerecords; private int rerecords;
private bool changes = false; private bool changes;
#endregion #endregion
#region Helpers #region Helpers
@ -929,8 +939,6 @@ namespace BizHawk.MultiClient
private void WriteText(Stream stream) private void WriteText(Stream stream)
{ {
int length = Log.Length;
using (StreamWriter sw = new StreamWriter(stream)) using (StreamWriter sw = new StreamWriter(stream))
{ {
Header.WriteText(sw); Header.WriteText(sw);
@ -967,8 +975,7 @@ namespace BizHawk.MultiClient
using (StreamReader sr = file.OpenText()) using (StreamReader sr = file.OpenText())
{ {
string str = ""; string str;
string rerecordStr = "";
while ((str = sr.ReadLine()) != null) while ((str = sr.ReadLine()) != null)
{ {
@ -979,7 +986,7 @@ namespace BizHawk.MultiClient
if (str.Contains(MovieHeader.RERECORDS)) if (str.Contains(MovieHeader.RERECORDS))
{ {
rerecordStr = ParseHeader(str, MovieHeader.RERECORDS); string rerecordStr = ParseHeader(str, MovieHeader.RERECORDS);
try try
{ {
Rerecords = int.Parse(rerecordStr); Rerecords = int.Parse(rerecordStr);
@ -1036,23 +1043,22 @@ namespace BizHawk.MultiClient
return true; return true;
} }
private string MakeDigits(decimal num)
{
return MakeDigits((int)num);
}
private string MakeDigits(int num) private string MakeDigits(int num)
{ {
if (num < 10) if (num < 10)
{
return "0" + num.ToString(); return "0" + num.ToString();
}
else else
{
return num.ToString(); return num.ToString();
}
} }
private double GetSeconds(int frameCount) private double GetSeconds(int frameCount)
{ {
const double NES_PAL = 50.006977968268290849; const double NES_PAL = 50.006977968268290849;
const double NES_NTSC = (double)60.098813897440515532; const double NES_NTSC = 60.098813897440515532;
const double SNES_NTSC = (double)21477272 / (4 * 341 * 262); const double SNES_NTSC = (double)21477272 / (4 * 341 * 262);
const double SNES_PAL = (double)21281370 / (4 * 341 * 312); const double SNES_PAL = (double)21281370 / (4 * 341 * 312);
const double PCE = (7159090.90909090 / 455 / 263); //~59.826 const double PCE = (7159090.90909090 / 455 / 263); //~59.826
@ -1064,10 +1070,13 @@ namespace BizHawk.MultiClient
const double WSWAN = (3072000.0 / (159 * 256)); const double WSWAN = (3072000.0 / (159 * 256));
const double GB = 262144.0 / 4389.0; const double GB = 262144.0 / 4389.0;
const double A26 = 59.9227510135505; const double A26 = 59.9227510135505;
double seconds = 0;
double frames = (double)frameCount; double frames = frameCount;
if (frames < 1) if (frames < 1)
return seconds; {
return 0;
}
bool pal = false; bool pal = false;
if (Header.HeaderParams.ContainsKey(MovieHeader.PAL)) if (Header.HeaderParams.ContainsKey(MovieHeader.PAL))
@ -1127,24 +1136,10 @@ namespace BizHawk.MultiClient
} }
} }
private bool IsStateFromAMovie(StreamReader reader)
{
while (true)
{
if (reader.ReadLine().Contains("GUID"))
break;
if (reader.EndOfStream)
return false;
}
return true;
}
private static string ParseHeader(string line, string headerName) private static string ParseHeader(string line, string headerName)
{ {
string str;
int x = line.LastIndexOf(headerName) + headerName.Length; int x = line.LastIndexOf(headerName) + headerName.Length;
str = line.Substring(x + 1, line.Length - x - 1); return line.Substring(x + 1, line.Length - x - 1);
return str;
} }
#endregion #endregion
@ -1216,15 +1211,22 @@ namespace BizHawk.MultiClient
private int CompareFileName(Movie Other) private int CompareFileName(Movie Other)
{ {
string otherName = Path.GetFileName(Other.Filename); string otherName = Path.GetFileName(Other.Filename);
string thisName = Path.GetFileName(this.Filename); string thisName = Path.GetFileName(Filename);
return thisName.CompareTo(otherName); if (thisName != null)
{
return thisName.CompareTo(otherName);
}
else
{
return 0;
}
} }
private int CompareSysID(Movie Other) private int CompareSysID(Movie Other)
{ {
string otherSysID = Other.SysID; string otherSysID = Other.SysID;
string thisSysID = this.SysID; string thisSysID = SysID;
if (thisSysID == null && otherSysID == null) if (thisSysID == null && otherSysID == null)
return 0; return 0;
@ -1239,7 +1241,7 @@ namespace BizHawk.MultiClient
private int CompareGameName(Movie Other) private int CompareGameName(Movie Other)
{ {
string otherGameName = Other.GameName; string otherGameName = Other.GameName;
string thisGameName = this.GameName; string thisGameName = GameName;
if (thisGameName == null && otherGameName == null) if (thisGameName == null && otherGameName == null)
return 0; return 0;
@ -1254,7 +1256,7 @@ namespace BizHawk.MultiClient
private int CompareLength(Movie Other) private int CompareLength(Movie Other)
{ {
int otherLength = Other.preload_framecount; int otherLength = Other.preload_framecount;
int thisLength = this.preload_framecount; int thisLength = preload_framecount;
if (thisLength < otherLength) if (thisLength < otherLength)
{ {

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using System.IO;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -71,7 +68,7 @@ namespace BizHawk.MultiClient
/// <param name="value"></param> /// <param name="value"></param>
public void AddHeaderLine(string key, string value) public void AddHeaderLine(string key, string value)
{ {
string temp = value; string temp;
if (!HeaderParams.TryGetValue(key, out temp)) //TODO: does a failed attempt mess with value? if (!HeaderParams.TryGetValue(key, out temp)) //TODO: does a failed attempt mess with value?
HeaderParams.Add(key, value); HeaderParams.Add(key, value);
@ -94,7 +91,7 @@ namespace BizHawk.MultiClient
public string GetHeaderLine(string key) public string GetHeaderLine(string key)
{ {
string value = ""; string value;
HeaderParams.TryGetValue(key, out value); HeaderParams.TryGetValue(key, out value);
return value; return value;
} }
@ -111,17 +108,16 @@ namespace BizHawk.MultiClient
sw.WriteLine(kvp.Key + " " + kvp.Value); sw.WriteLine(kvp.Key + " " + kvp.Value);
} }
for (int x = 0; x < Comments.Count; x++) foreach (string t in Comments)
{ {
sw.WriteLine(Comments[x]); sw.WriteLine(t);
} }
} }
private string ParseHeader(string line, string headerName) private string ParseHeader(string line, string headerName)
{ {
string str;
int x = line.LastIndexOf(headerName) + headerName.Length; int x = line.LastIndexOf(headerName) + headerName.Length;
str = line.Substring(x + 1, line.Length - x - 1); string str = line.Substring(x + 1, line.Length - x - 1);
return str; return str;
} }
@ -134,75 +130,75 @@ namespace BizHawk.MultiClient
public bool AddHeaderFromLine(string line) public bool AddHeaderFromLine(string line)
{ {
if (line.Length == 0) return false; if (line.Length == 0) return false;
else if (line.Contains(MovieHeader.EMULATIONVERSION)) else if (line.Contains(EMULATIONVERSION))
{ {
line = ParseHeader(line, MovieHeader.EMULATIONVERSION); line = ParseHeader(line, EMULATIONVERSION);
AddHeaderLine(MovieHeader.EMULATIONVERSION, line); AddHeaderLine(EMULATIONVERSION, line);
} }
else if (line.Contains(MovieHeader.MOVIEVERSION)) else if (line.Contains(MOVIEVERSION))
{ {
line = ParseHeader(line, MovieHeader.MOVIEVERSION); line = ParseHeader(line, MOVIEVERSION);
AddHeaderLine(MovieHeader.MOVIEVERSION, line); AddHeaderLine(MOVIEVERSION, line);
} }
else if (line.Contains(MovieHeader.PLATFORM)) else if (line.Contains(PLATFORM))
{ {
line = ParseHeader(line, MovieHeader.PLATFORM); line = ParseHeader(line, PLATFORM);
AddHeaderLine(MovieHeader.PLATFORM, line); AddHeaderLine(PLATFORM, line);
} }
else if (line.Contains(MovieHeader.GAMENAME)) else if (line.Contains(GAMENAME))
{ {
line = ParseHeader(line, MovieHeader.GAMENAME); line = ParseHeader(line, GAMENAME);
AddHeaderLine(MovieHeader.GAMENAME, line); AddHeaderLine(GAMENAME, line);
} }
else if (line.Contains(MovieHeader.RERECORDS)) else if (line.Contains(RERECORDS))
{ {
line = ParseHeader(line, MovieHeader.RERECORDS); line = ParseHeader(line, RERECORDS);
AddHeaderLine(MovieHeader.RERECORDS, line); AddHeaderLine(RERECORDS, line);
} }
else if (line.Contains(MovieHeader.AUTHOR)) else if (line.Contains(AUTHOR))
{ {
line = ParseHeader(line, MovieHeader.AUTHOR); line = ParseHeader(line, AUTHOR);
AddHeaderLine(MovieHeader.AUTHOR, line); AddHeaderLine(AUTHOR, line);
} }
else if (line.ToUpper().Contains(MovieHeader.GUID)) else if (line.ToUpper().Contains(GUID))
{ {
line = ParseHeader(line, MovieHeader.GUID); line = ParseHeader(line, GUID);
AddHeaderLine(MovieHeader.GUID, line); AddHeaderLine(GUID, line);
} }
else if (line.Contains(MovieHeader.STARTSFROMSAVESTATE)) else if (line.Contains(STARTSFROMSAVESTATE))
{ {
line = ParseHeader(line, MovieHeader.STARTSFROMSAVESTATE); line = ParseHeader(line, STARTSFROMSAVESTATE);
AddHeaderLine(MovieHeader.STARTSFROMSAVESTATE, line); AddHeaderLine(STARTSFROMSAVESTATE, line);
} }
else if (line.Contains(MovieHeader.SHA1)) else if (line.Contains(SHA1))
{ {
line = ParseHeader(line, MovieHeader.SHA1); line = ParseHeader(line, SHA1);
AddHeaderLine(MovieHeader.SHA1, line); AddHeaderLine(SHA1, line);
} }
else if (line.Contains(MovieHeader.SKIPBIOS)) else if (line.Contains(SKIPBIOS))
{ {
line = ParseHeader(line, MovieHeader.SKIPBIOS); line = ParseHeader(line, SKIPBIOS);
AddHeaderLine(MovieHeader.SKIPBIOS, line); AddHeaderLine(SKIPBIOS, line);
} }
else if (line.Contains(MovieHeader.GB_FORCEDMG)) else if (line.Contains(GB_FORCEDMG))
{ {
line = ParseHeader(line, MovieHeader.GB_FORCEDMG); line = ParseHeader(line, GB_FORCEDMG);
AddHeaderLine(MovieHeader.GB_FORCEDMG, line); AddHeaderLine(GB_FORCEDMG, line);
} }
else if (line.Contains(MovieHeader.GB_GBA_IN_CGB)) else if (line.Contains(GB_GBA_IN_CGB))
{ {
line = ParseHeader(line, MovieHeader.GB_GBA_IN_CGB); line = ParseHeader(line, GB_GBA_IN_CGB);
AddHeaderLine(MovieHeader.GB_GBA_IN_CGB, line); AddHeaderLine(GB_GBA_IN_CGB, line);
} }
else if (line.Contains(MovieHeader.SGB)) else if (line.Contains(SGB))
{ {
line = ParseHeader(line, MovieHeader.SGB); line = ParseHeader(line, SGB);
AddHeaderLine(MovieHeader.SGB, line); AddHeaderLine(SGB, line);
} }
else if (line.Contains(MovieHeader.PAL)) else if (line.Contains(PAL))
{ {
line = ParseHeader(line, MovieHeader.PAL); line = ParseHeader(line, PAL);
AddHeaderLine(MovieHeader.PAL, line); AddHeaderLine(PAL, line);
} }
else if (line.StartsWith("subtitle") || line.StartsWith("sub")) else if (line.StartsWith("subtitle") || line.StartsWith("sub"))
{ {
@ -226,7 +222,7 @@ namespace BizHawk.MultiClient
{ {
using (reader) using (reader)
{ {
string str = ""; string str;
while ((str = reader.ReadLine()) != null) while ((str = reader.ReadLine()) != null)
{ {
AddHeaderFromLine(str); AddHeaderFromLine(str);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -37,9 +36,11 @@ namespace BizHawk.MultiClient
Movie m = new Movie(); Movie m = new Movie();
errorMsg = ""; errorMsg = "";
warningMsg = ""; warningMsg = "";
string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
try try
{ {
switch (Path.GetExtension(path).ToUpper()) switch (ext)
{ {
case ".FCM": case ".FCM":
m = ImportFCM(path, out errorMsg, out warningMsg); m = ImportFCM(path, out errorMsg, out warningMsg);
@ -96,17 +97,11 @@ namespace BizHawk.MultiClient
// Return whether or not the type of file provided can currently be imported. // Return whether or not the type of file provided can currently be imported.
public static bool IsValidMovieExtension(string extension) public static bool IsValidMovieExtension(string extension)
{ {
string[] extensions = new string[13] { string[] extensions = new[]
{
"FCM", "FM2", "FMV", "GMV", "MCM", "MC2", "MMV", "NMV", "LSMV", "SMV", "VBM", "VMV", "ZMV" "FCM", "FM2", "FMV", "GMV", "MCM", "MC2", "MMV", "NMV", "LSMV", "SMV", "VBM", "VMV", "ZMV"
}; };
foreach (string ext in extensions) return extensions.Any(ext => extension.ToUpper() == "." + ext);
{
if (extension.ToUpper() == "." + ext)
{
return true;
}
}
return false;
} }
// Reduce all whitespace to single spaces. // Reduce all whitespace to single spaces.
@ -132,35 +127,34 @@ namespace BizHawk.MultiClient
{ {
string[] buttons = new string[] { }; string[] buttons = new string[] { };
string controller = ""; string controller = "";
switch (Path.GetExtension(path).ToUpper()) string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
switch (ext)
{ {
case ".FM2": case ".FM2":
buttons = new string[8] { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" }; buttons = new[] { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" };
controller = "NES Controller"; controller = "NES Controller";
break; break;
case ".MC2": case ".MC2":
buttons = new string[8] { "Up", "Down", "Left", "Right", "B1", "B2", "Run", "Select" }; buttons = new[] { "Up", "Down", "Left", "Right", "B1", "B2", "Run", "Select" };
controller = "PC Engine Controller"; controller = "PC Engine Controller";
break; break;
case ".LSMV": case ".LSMV":
buttons = new string[12] { buttons = new[] {
"B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R" "B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R"
}; };
controller = "SNES Controller"; controller = "SNES Controller";
if (platform == "GB" || platform == "GBC") if (platform == "GB" || platform == "GBC")
{ {
buttons = new string[8] { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down" }; buttons = new[] { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down" };
controller = "Gameboy Controller"; controller = "Gameboy Controller";
} }
break; break;
} }
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = controller}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = controller;
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
// Split up the sections of the frame. // Split up the sections of the frame.
string[] sections = line.Split('|'); string[] sections = line.Split('|');
if (Path.GetExtension(path).ToUpper() == ".FM2" && sections.Length >= 2 && sections[1].Length != 0) if (ext == ".FM2" && sections.Length >= 2 && sections[1].Length != 0)
{ {
controllers["Reset"] = (sections[1][0] == '1'); controllers["Reset"] = (sections[1][0] == '1');
// Get the first invalid command warning message that arises. // Get the first invalid command warning message that arises.
@ -194,7 +188,7 @@ namespace BizHawk.MultiClient
} }
} }
} }
if (Path.GetExtension(path).ToUpper() == ".LSMV" && sections.Length != 0) if (ext == ".LSMV" && sections.Length != 0)
{ {
string flags = sections[0]; string flags = sections[0];
char[] off = { '.', ' ', '\t', '\n', '\r' }; char[] off = { '.', ' ', '\t', '\n', '\r' };
@ -223,7 +217,7 @@ namespace BizHawk.MultiClient
int start = 2; int start = 2;
int end = sections.Length - 1; int end = sections.Length - 1;
int player_offset = -1; int player_offset = -1;
if (Path.GetExtension(path).ToUpper() == ".LSMV") if (ext == ".LSMV")
{ {
// LSNES frames don't start or end with a |. // LSNES frames don't start or end with a |.
start--; start--;
@ -270,9 +264,10 @@ namespace BizHawk.MultiClient
{ {
// Concatenate the frame and message with default values for the additional fields. // Concatenate the frame and message with default values for the additional fields.
string frame; string frame;
string message;
string length; string length;
if (Path.GetExtension(path).ToUpper() != ".LSMV") string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
if (ext != ".LSMV")
{ {
frame = line.Substring(first + 1, second - first - 1); frame = line.Substring(first + 1, second - first - 1);
length = "200"; length = "200";
@ -282,7 +277,7 @@ namespace BizHawk.MultiClient
frame = line.Substring(0, first); frame = line.Substring(0, first);
length = line.Substring(first + 1, second - first - 1); length = line.Substring(first + 1, second - first - 1);
} }
message = line.Substring(second + 1).Trim(); string message = line.Substring(second + 1).Trim();
m.Subtitles.AddSubtitle("subtitle " + frame + " 0 0 " + length + " FFFFFFFF " + message); m.Subtitles.AddSubtitle("subtitle " + frame + " 0 0 " + length + " FFFFFFFF " + message);
} }
return m; return m;
@ -311,7 +306,7 @@ namespace BizHawk.MultiClient
} }
m.Header.SetHeaderLine(MovieHeader.PLATFORM, platform); m.Header.SetHeaderLine(MovieHeader.PLATFORM, platform);
int lineNum = 0; int lineNum = 0;
string line = ""; string line;
while ((line = sr.ReadLine()) != null) while ((line = sr.ReadLine()) != null)
{ {
lineNum++; lineNum++;
@ -361,7 +356,7 @@ namespace BizHawk.MultiClient
byte[] md5 = DecodeBlob(blob); byte[] md5 = DecodeBlob(blob);
if (md5 != null && md5.Length == 16) if (md5 != null && md5.Length == 16)
{ {
m.Header.SetHeaderLine(MD5, BizHawk.Util.BytesToHexString(md5).ToLower()); m.Header.SetHeaderLine(MD5, Util.BytesToHexString(md5).ToLower());
} }
else else
{ {
@ -421,12 +416,11 @@ namespace BizHawk.MultiClient
// Get the content for a particular header. // Get the content for a particular header.
private static string ParseHeader(string line, string headerName) private static string ParseHeader(string line, string headerName)
{ {
string str;
// Case-insensitive search. // Case-insensitive search.
int x = line.ToLower().LastIndexOf( int x = line.ToLower().LastIndexOf(
headerName.ToLower() headerName.ToLower()
) + headerName.Length; ) + headerName.Length;
str = line.Substring(x + 1, line.Length - x - 1); string str = line.Substring(x + 1, line.Length - x - 1);
return str.Trim(); return str.Trim();
} }
@ -440,7 +434,7 @@ namespace BizHawk.MultiClient
if (blob[0] == '0' && (blob[1] == 'x' || blob[1] == 'X')) if (blob[0] == '0' && (blob[1] == 'x' || blob[1] == 'X'))
{ {
// hex // hex
return BizHawk.Util.HexStringToBytes(blob.Substring(2)); return Util.HexStringToBytes(blob.Substring(2));
} }
else else
{ {
@ -537,8 +531,6 @@ namespace BizHawk.MultiClient
// 010 4-byte little-endian unsigned int: rerecord count // 010 4-byte little-endian unsigned int: rerecord count
uint rerecordCount = r.ReadUInt32(); uint rerecordCount = r.ReadUInt32();
m.Rerecords = (int)rerecordCount; m.Rerecords = (int)rerecordCount;
// 014 4-byte little-endian unsigned int: length of controller data in bytes
uint movieDataSize = r.ReadUInt32();
/* /*
018 4-byte little-endian unsigned int: offset to the savestate inside file 018 4-byte little-endian unsigned int: offset to the savestate inside file
The savestate offset is <header_size + length_of_metadata_in_bytes + padding>. The savestate offset should be The savestate offset is <header_size + length_of_metadata_in_bytes + padding>. The savestate offset should be
@ -550,7 +542,7 @@ namespace BizHawk.MultiClient
uint firstFrameOffset = r.ReadUInt32(); uint firstFrameOffset = r.ReadUInt32();
// 020 16-byte md5sum of the ROM used // 020 16-byte md5sum of the ROM used
byte[] md5 = r.ReadBytes(16); byte[] md5 = r.ReadBytes(16);
m.Header.SetHeaderLine(MD5, BizHawk.Util.BytesToHexString(md5).ToLower()); m.Header.SetHeaderLine(MD5, Util.BytesToHexString(md5).ToLower());
// 030 4-byte little-endian unsigned int: version of the emulator used // 030 4-byte little-endian unsigned int: version of the emulator used
uint emuVersion = r.ReadUInt32(); uint emuVersion = r.ReadUInt32();
m.Header.Comments.Add(EMULATIONORIGIN + " FCEU " + emuVersion.ToString()); m.Header.Comments.Add(EMULATIONORIGIN + " FCEU " + emuVersion.ToString());
@ -576,11 +568,9 @@ namespace BizHawk.MultiClient
m.Header.SetHeaderLine(MovieHeader.AUTHOR, author); m.Header.SetHeaderLine(MovieHeader.AUTHOR, author);
// Advance to first byte of input data. // Advance to first byte of input data.
r.BaseStream.Position = firstFrameOffset; r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
string[] buttons = new string[8] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }; string[] buttons = new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
bool fds = false; bool fds = false;
bool fourscore = false; bool fourscore = false;
int frame = 1; int frame = 1;
@ -728,10 +718,7 @@ namespace BizHawk.MultiClient
// FM2 file format: http://www.fceux.com/web/FM2.html // FM2 file format: http://www.fceux.com/web/FM2.html
private static Movie ImportFM2(string path, out string errorMsg, out string warningMsg) private static Movie ImportFM2(string path, out string errorMsg, out string warningMsg)
{ {
errorMsg = ""; return ImportText(path, out errorMsg, out warningMsg);
warningMsg = "";
Movie m = ImportText(path, out errorMsg, out warningMsg);
return m;
} }
// FMV file format: http://tasvideos.org/FMV.html // FMV file format: http://tasvideos.org/FMV.html
@ -813,9 +800,7 @@ namespace BizHawk.MultiClient
*/ */
m.Header.SetHeaderLine(MovieHeader.PAL, "False"); m.Header.SetHeaderLine(MovieHeader.PAL, "False");
// 090 frame data begins here // 090 frame data begins here
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
/* /*
* 01 Right * 01 Right
@ -827,8 +812,8 @@ namespace BizHawk.MultiClient
* 40 Select * 40 Select
* 80 Start * 80 Start
*/ */
string[] buttons = new string[8] { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" }; string[] buttons = new[] { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" };
bool[] masks = new bool[3] { controller1, controller2, FDS }; bool[] masks = new[] { controller1, controller2, FDS };
/* /*
The file has no terminator byte or frame count. The number of frames is the <filesize minus 144> divided by The file has no terminator byte or frame count. The number of frames is the <filesize minus 144> divided by
<number of bytes per frame>. <number of bytes per frame>.
@ -933,9 +918,10 @@ namespace BizHawk.MultiClient
// 018 40-byte zero-terminated ASCII movie name string // 018 40-byte zero-terminated ASCII movie name string
string description = NullTerminated(r.ReadStringFixedAscii(40)); string description = NullTerminated(r.ReadStringFixedAscii(40));
m.Header.Comments.Add(COMMENT + " " + description); m.Header.Comments.Add(COMMENT + " " + description);
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController
controllers.Type = new ControllerDefinition(); {
controllers.Type.Name = "Genesis 3-Button Controller"; Type = new ControllerDefinition {Name = "Genesis 3-Button Controller"}
};
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
/* /*
040 frame data 040 frame data
@ -1261,7 +1247,7 @@ namespace BizHawk.MultiClient
byte[] md5 = r.ReadBytes(16); byte[] md5 = r.ReadBytes(16);
// Discard the second 16 bytes. // Discard the second 16 bytes.
r.ReadBytes(16); r.ReadBytes(16);
m.Header.SetHeaderLine(MD5, BizHawk.Util.BytesToHexString(md5).ToLower()); m.Header.SetHeaderLine(MD5, Util.BytesToHexString(md5).ToLower());
// 030 64-byte Filename of the ROM used (with extension) // 030 64-byte Filename of the ROM used (with extension)
string gameName = NullTerminated(r.ReadStringFixedAscii(64)); string gameName = NullTerminated(r.ReadStringFixedAscii(64));
m.Header.SetHeaderLine(MovieHeader.GAMENAME, gameName); m.Header.SetHeaderLine(MovieHeader.GAMENAME, gameName);
@ -1270,8 +1256,8 @@ namespace BizHawk.MultiClient
m.Rerecords = (int)rerecordCount; m.Rerecords = (int)rerecordCount;
// 074 5-byte Console indicator (pce, ngp, pcfx, wswan) // 074 5-byte Console indicator (pce, ngp, pcfx, wswan)
string platform = NullTerminated(r.ReadStringFixedAscii(5)); string platform = NullTerminated(r.ReadStringFixedAscii(5));
Dictionary<string, Dictionary<string, object>> platforms = new Dictionary<string, Dictionary<string, object>>() Dictionary<string, Dictionary<string, object>> platforms = new Dictionary<string, Dictionary<string, object>>
{ {
{ {
/* /*
Normally, NES receives from 5 input ports, where the first 4 have a length of 1 byte, and the last has Normally, NES receives from 5 input ports, where the first 4 have a length of 1 byte, and the last has
@ -1281,14 +1267,14 @@ namespace BizHawk.MultiClient
"nes", new Dictionary<string, object> "nes", new Dictionary<string, object>
{ {
{"name", "NES"}, {"ports", 4}, {"bytesPerPort", 1}, {"name", "NES"}, {"ports", 4}, {"bytesPerPort", 1},
{"buttons", new string[8] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }} {"buttons", new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }}
} }
}, },
{ {
"pce", new Dictionary<string, object> "pce", new Dictionary<string, object>
{ {
{"name", "PC Engine"}, {"ports", 5}, {"bytesPerPort", 2}, {"name", "PC Engine"}, {"ports", 5}, {"bytesPerPort", 2},
{"buttons", new string[8] { "B1", "B2", "Select", "Run", "Up", "Right", "Down", "Left" }} {"buttons", new[] { "B1", "B2", "Select", "Run", "Up", "Right", "Down", "Left" }}
} }
} }
}; };
@ -1308,9 +1294,7 @@ namespace BizHawk.MultiClient
r.ReadBytes(103); r.ReadBytes(103);
// TODO: Verify if NTSC/"PAL" mode used for the movie can be detected or not. // TODO: Verify if NTSC/"PAL" mode used for the movie can be detected or not.
// 100 variable Input data // 100 variable Input data
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = name + " Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = name + " Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
int bytes = 256; int bytes = 256;
// The input stream consists of 1 byte for power-on and reset, and then X bytes per each input port per frame. // The input stream consists of 1 byte for power-on and reset, and then X bytes per each input port per frame.
@ -1357,10 +1341,7 @@ namespace BizHawk.MultiClient
// MC2 file format: http://code.google.com/p/pcejin/wiki/MC2 // MC2 file format: http://code.google.com/p/pcejin/wiki/MC2
private static Movie ImportMC2(string path, out string errorMsg, out string warningMsg) private static Movie ImportMC2(string path, out string errorMsg, out string warningMsg)
{ {
errorMsg = ""; return ImportText(path, out errorMsg, out warningMsg);
warningMsg = "";
Movie m = ImportText(path, out errorMsg, out warningMsg);
return m;
} }
// MMV file format: http://tasvideos.org/MMV.html // MMV file format: http://tasvideos.org/MMV.html
@ -1435,10 +1416,8 @@ namespace BizHawk.MultiClient
m.Header.SetHeaderLine(MovieHeader.GAMENAME, gameName); m.Header.SetHeaderLine(MovieHeader.GAMENAME, gameName);
// 00e4-00f3: binary: rom MD5 digest // 00e4-00f3: binary: rom MD5 digest
byte[] md5 = r.ReadBytes(16); byte[] md5 = r.ReadBytes(16);
m.Header.SetHeaderLine(MD5, String.Format("{0:x8}", BizHawk.Util.BytesToHexString(md5).ToLower())); m.Header.SetHeaderLine(MD5, String.Format("{0:x8}", Util.BytesToHexString(md5).ToLower()));
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SMS Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SMS Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
/* /*
76543210 76543210
@ -1451,7 +1430,7 @@ namespace BizHawk.MultiClient
* bit 6 (0x40): start (Master System) * bit 6 (0x40): start (Master System)
* bit 7 (0x80): start (Game Gear) * bit 7 (0x80): start (Game Gear)
*/ */
string[] buttons = new string[6] { "Up", "Down", "Left", "Right", "B1", "B2" }; string[] buttons = new[] { "Up", "Down", "Left", "Right", "B1", "B2" };
for (int frame = 1; frame <= frameCount; frame++) for (int frame = 1; frame <= frameCount; frame++)
{ {
/* /*
@ -1551,7 +1530,7 @@ namespace BizHawk.MultiClient
*/ */
bool fourscore = (controller1 == 5); bool fourscore = (controller1 == 5);
m.Header.SetHeaderLine(MovieHeader.FOURSCORE, fourscore.ToString()); m.Header.SetHeaderLine(MovieHeader.FOURSCORE, fourscore.ToString());
bool[] masks = new bool[5] { false, false, false, false, false }; bool[] masks = new[] { false, false, false, false, false };
if (fourscore) if (fourscore)
{ {
/* /*
@ -1567,7 +1546,7 @@ namespace BizHawk.MultiClient
} }
else else
{ {
byte[] types = new byte[2] { controller1, controller2 }; byte[] types = new[] { controller1, controller2 };
for (int controller = 1; controller <= types.Length; controller++) for (int controller = 1; controller <= types.Length; controller++)
{ {
masks[controller - 1] = (types[controller - 1] == 1); masks[controller - 1] = (types[controller - 1] == 1);
@ -1617,7 +1596,7 @@ namespace BizHawk.MultiClient
* 5 - Family Trainer (2 bytes) * 5 - Family Trainer (2 bytes)
* 6 - Oeka Kids writing tablet (3 bytes) * 6 - Oeka Kids writing tablet (3 bytes)
*/ */
string[] expansions = new string[7] { string[] expansions = new[] {
"Unconnected", "Famicom 4-player adapter", "Famicom Arkanoid paddle", "Family Basic Keyboard", "Unconnected", "Famicom 4-player adapter", "Famicom Arkanoid paddle", "Family Basic Keyboard",
"Alternate keyboard layout", "Family Trainer", "Oeka Kids writing tablet" "Alternate keyboard layout", "Family Trainer", "Oeka Kids writing tablet"
}; };
@ -1666,9 +1645,7 @@ namespace BizHawk.MultiClient
// ... 4-byte little-endian unsigned int: length of controller data in bytes // ... 4-byte little-endian unsigned int: length of controller data in bytes
uint length = r.ReadUInt32(); uint length = r.ReadUInt32();
// ... (variable) controller data // ... (variable) controller data
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
/* /*
Standard controllers store data in the following format: Standard controllers store data in the following format:
@ -1682,7 +1659,7 @@ namespace BizHawk.MultiClient
* 80: Right * 80: Right
Other controllers store data in their own formats, and are beyond the scope of this document. Other controllers store data in their own formats, and are beyond the scope of this document.
*/ */
string[] buttons = new string[8] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }; string[] buttons = new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
// The controller data contains <number_of_bytes> / <bytes_per_frame> frames. // The controller data contains <number_of_bytes> / <bytes_per_frame> frames.
long frameCount = length / bytesPerFrame; long frameCount = length / bytesPerFrame;
for (int frame = 1; frame <= frameCount; frame++) for (int frame = 1; frame <= frameCount; frame++)
@ -1774,9 +1751,7 @@ namespace BizHawk.MultiClient
* bit 4: controller 5 in use * bit 4: controller 5 in use
* other: reserved, set to 0 * other: reserved, set to 0
*/ */
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SNES Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SNES Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
bool[] controllersUsed = new bool[5]; bool[] controllersUsed = new bool[5];
for (int controller = 1; controller <= controllersUsed.Length; controller++) for (int controller = 1; controller <= controllersUsed.Length; controller++)
@ -1890,9 +1865,11 @@ namespace BizHawk.MultiClient
00 40 Y 00 40 Y
00 80 B 00 80 B
*/ */
string[] buttons = new string[12] { string[] buttons = new[]
{
"Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A" "Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A"
}; };
for (int frame = 0; frame <= frameCount; frame++) for (int frame = 0; frame <= frameCount; frame++)
{ {
controllers["Reset"] = true; controllers["Reset"] = true;
@ -2084,14 +2061,16 @@ namespace BizHawk.MultiClient
// bit 2: if "1", movie is for the SGB system // bit 2: if "1", movie is for the SGB system
bool is_sgb = (((flags >> 2) & 0x1) != 0); bool is_sgb = (((flags >> 2) & 0x1) != 0);
// other: reserved, set to 0 // other: reserved, set to 0
// (At most one of bits 0, 1, 2 can be "1") // (At most one of bits 0, 1, 2 can be "1")
if (!(is_gba ^ is_gbc ^ is_sgb) && (is_gba || is_gbc || is_sgb)) //if (!(is_gba ^ is_gbc ^ is_sgb) && (is_gba || is_gbc || is_sgb)) //TODO: adelikat: this doesn't do what the comment above suggests it is trying to check for, it is always false!
{ //{
errorMsg = "This is not a valid .VBM file."; //errorMsg = "This is not a valid .VBM file.";
r.Close(); //r.Close();
fs.Close(); //fs.Close();
return null; //return null;
} //}
// (If all 3 of these bits are "0", it is for regular GB.) // (If all 3 of these bits are "0", it is for regular GB.)
string platform = "GB"; string platform = "GB";
if (is_gba) if (is_gba)
@ -2181,8 +2160,7 @@ namespace BizHawk.MultiClient
string movieDescription = NullTerminated(r.ReadStringFixedAscii(128)); string movieDescription = NullTerminated(r.ReadStringFixedAscii(128));
m.Header.Comments.Add(COMMENT + " " + movieDescription); m.Header.Comments.Add(COMMENT + " " + movieDescription);
r.BaseStream.Position = firstFrameOffset; r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition()};
controllers.Type = new ControllerDefinition();
if (platform == "GBA") if (platform == "GBA")
{ {
controllers.Type.Name = "Gameboy Controller"; controllers.Type.Name = "Gameboy Controller";
@ -2202,7 +2180,7 @@ namespace BizHawk.MultiClient
* 40 00 Up * 40 00 Up
* 80 00 Down * 80 00 Down
*/ */
string[] buttons = new string[8] { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down" }; string[] buttons = new[] { "A", "B", "Select", "Start", "Right", "Left", "Up", "Down" };
/* /*
* 00 01 R * 00 01 R
* 00 02 L * 00 02 L
@ -2213,7 +2191,7 @@ namespace BizHawk.MultiClient
* 00 40 Down motion sensor * 00 40 Down motion sensor
* 00 80 Up motion sensor * 00 80 Up motion sensor
*/ */
string[] other = new string[8] { string[] other = new[] {
"R", "L", "Reset (old timing)" , "Reset (new timing since version 1.1)", "Left motion sensor", "R", "L", "Reset (old timing)" , "Reset (new timing since version 1.1)", "Left motion sensor",
"Right motion sensor", "Down motion sensor", "Up motion sensor" "Right motion sensor", "Down motion sensor", "Up motion sensor"
}; };
@ -2362,9 +2340,7 @@ namespace BizHawk.MultiClient
return m; return m;
} }
r.BaseStream.Position = firstFrameOffset; r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
/* /*
* 01 A * 01 A
@ -2376,7 +2352,7 @@ namespace BizHawk.MultiClient
* 40 Left * 40 Left
* 80 Right * 80 Right
*/ */
string[] buttons = new string[8] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" }; string[] buttons = new[] { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
for (int frame = 1; frame <= frameCount; frame++) for (int frame = 1; frame <= frameCount; frame++)
{ {
/* /*
@ -2559,7 +2535,6 @@ namespace BizHawk.MultiClient
{ {
peripheral = "First Mouse"; peripheral = "First Mouse";
} }
controllerFlags >>= 1;
if (peripheral != "") if (peripheral != "")
{ {
warningMsg = "Unable to import " + peripheral + "."; warningMsg = "Unable to import " + peripheral + ".";
@ -2599,9 +2574,7 @@ namespace BizHawk.MultiClient
uint savestateSize = (uint)((r.ReadByte() | (r.ReadByte() << 8) | (r.ReadByte() << 16)) & 0x7FFFFF); uint savestateSize = (uint)((r.ReadByte() | (r.ReadByte() << 8) | (r.ReadByte() << 16)) & 0x7FFFFF);
// Next follows a ZST format savestate. // Next follows a ZST format savestate.
r.ReadBytes((int)savestateSize); r.ReadBytes((int)savestateSize);
SimpleController controllers = new SimpleController(); SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SNES Controller"}};
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SNES Controller";
MnemonicsGenerator mg = new MnemonicsGenerator(); MnemonicsGenerator mg = new MnemonicsGenerator();
/* /*
* bit 11: A * bit 11: A
@ -2617,7 +2590,8 @@ namespace BizHawk.MultiClient
* bit 1: Left * bit 1: Left
* bit 0: Right * bit 0: Right
*/ */
string[] buttons = new string[12] { string[] buttons = new[]
{
"Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A" "Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A"
}; };
int frames = 1; int frames = 1;

View File

@ -1,7 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; using System.IO;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -19,7 +16,7 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
return StateRecords.Count; return _state_records.Count;
} }
} }
@ -27,7 +24,7 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
return MovieRecords.Count; return _movie_records.Count;
} }
} }
@ -35,7 +32,7 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
return (StateRecords.Count == 0) ? -1 : StateRecords[0].Index; return (_state_records.Count == 0) ? -1 : _state_records[0].Index;
} }
} }
@ -43,7 +40,7 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
return (StateRecords.Count == 0) ? -1 : StateRecords[StateRecords.Count - 1].Index; return (_state_records.Count == 0) ? -1 : _state_records[_state_records.Count - 1].Index;
} }
} }
@ -51,9 +48,9 @@ namespace BizHawk.MultiClient
{ {
get get
{ {
if (StateRecords.Count > 0) if (_state_records.Count > 0)
{ {
return StateCount * StateRecords[0].State.Length; return StateCount * _state_records[0].State.Length;
} }
else else
{ {
@ -68,18 +65,18 @@ namespace BizHawk.MultiClient
public void Clear() public void Clear()
{ {
MovieRecords.Clear(); _movie_records.Clear();
StateRecords.Clear(); _state_records.Clear();
} }
public void ClearStates() public void ClearStates()
{ {
StateRecords.Clear(); _state_records.Clear();
} }
public void AppendFrame(string frame) public void AppendFrame(string frame)
{ {
MovieRecords.Add(frame); _movie_records.Add(frame);
} }
public void AddState(byte[] state) public void AddState(byte[] state)
@ -90,17 +87,17 @@ namespace BizHawk.MultiClient
} }
if (Global.Emulator.Frame < StateFirstIndex) if (Global.Emulator.Frame < StateFirstIndex)
{ {
StateRecords.Clear(); _state_records.Clear();
StateRecords.Add(new StateRecord(Global.Emulator.Frame, state)); _state_records.Add(new StateRecord(Global.Emulator.Frame, state));
} }
if (Global.Emulator.Frame > StateLastIndex) if (Global.Emulator.Frame > StateLastIndex)
{ {
if (StateSizeInBytes + state.Length > MaxStateRecordSize) if (StateSizeInBytes + state.Length > MAXSTATERECORDSIZE)
{ {
// Discard the oldest state to save space. // Discard the oldest state to save space.
StateRecords.RemoveAt(0); _state_records.RemoveAt(0);
} }
StateRecords.Add(new StateRecord(Global.Emulator.Frame,state)); _state_records.Add(new StateRecord(Global.Emulator.Frame,state));
} }
} }
@ -111,30 +108,30 @@ namespace BizHawk.MultiClient
TruncateStates(frameNum+1); TruncateStates(frameNum+1);
} }
if (MovieRecords.Count > frameNum) if (_movie_records.Count > frameNum)
{ {
MovieRecords[frameNum] = frame; _movie_records[frameNum] = frame;
} }
else else
{ {
MovieRecords.Add(frame); _movie_records.Add(frame);
} }
} }
public void AddFrameAt(int frame, string record) public void AddFrameAt(int frame, string record)
{ {
MovieRecords.Insert(frame, record); _movie_records.Insert(frame, record);
if (frame <= StateLastIndex) if (frame <= StateLastIndex)
{ {
if (frame <= StateFirstIndex) if (frame <= StateFirstIndex)
{ {
StateRecords.Clear(); _state_records.Clear();
Global.MovieSession.Movie.RewindToFrame(0); Global.MovieSession.Movie.RewindToFrame(0);
} }
else else
{ {
StateRecords.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1); _state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
Global.MovieSession.Movie.RewindToFrame(frame); Global.MovieSession.Movie.RewindToFrame(frame);
} }
} }
@ -142,21 +139,21 @@ namespace BizHawk.MultiClient
public byte[] GetState(int frame) public byte[] GetState(int frame)
{ {
return StateRecords[frame - StateFirstIndex].State; return _state_records[frame - StateFirstIndex].State;
} }
public void DeleteFrame(int frame) public void DeleteFrame(int frame)
{ {
MovieRecords.RemoveAt(frame); _movie_records.RemoveAt(frame);
if (frame <= StateLastIndex) if (frame <= StateLastIndex)
{ {
if (frame <= StateFirstIndex) if (frame <= StateFirstIndex)
{ {
StateRecords.Clear(); _state_records.Clear();
} }
else else
{ {
StateRecords.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1); _state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
} }
} }
} }
@ -167,20 +164,20 @@ namespace BizHawk.MultiClient
{ {
if (frame < StateFirstIndex) if (frame < StateFirstIndex)
{ {
StateRecords.Clear(); _state_records.Clear();
} }
else if (frame <= StateLastIndex) else if (frame <= StateLastIndex)
{ {
StateRecords.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1); _state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
} }
} }
} }
public string GetFrame(int frame) public string GetFrame(int frame)
{ {
if (frame >= 0 && frame < MovieRecords.Count) if (frame >= 0 && frame < _movie_records.Count)
{ {
return MovieRecords[frame]; return _movie_records[frame];
} }
else else
{ {
@ -190,7 +187,7 @@ namespace BizHawk.MultiClient
public void WriteText(StreamWriter sw) public void WriteText(StreamWriter sw)
{ {
for (int i = 0; i < MovieRecords.Count; i++) for (int i = 0; i < _movie_records.Count; i++)
{ {
sw.WriteLine(GetFrame(i)); sw.WriteLine(GetFrame(i));
} }
@ -198,20 +195,20 @@ namespace BizHawk.MultiClient
public void TruncateMovie(int frame) public void TruncateMovie(int frame)
{ {
if (frame < MovieRecords.Count) if (frame < _movie_records.Count)
{ {
MovieRecords.RemoveRange(frame, MovieRecords.Count - frame); _movie_records.RemoveRange(frame, _movie_records.Count - frame);
TruncateStates(frame); TruncateStates(frame);
} }
} }
public bool FrameLagged(int frame) public bool FrameLagged(int frame)
{ {
if (frame >= StateFirstIndex && frame <= StateLastIndex && frame <= StateRecords.Count) if (frame >= StateFirstIndex && frame <= StateLastIndex && frame <= _state_records.Count)
{ {
if (frame < StateRecords.Count) if (frame < _state_records.Count)
{ {
return StateRecords[frame].Lagged; return _state_records[frame].Lagged;
} }
else else
{ {
@ -237,16 +234,16 @@ namespace BizHawk.MultiClient
Lagged = Global.Emulator.IsLagFrame; Lagged = Global.Emulator.IsLagFrame;
} }
public int Index; public readonly int Index;
public byte[] State; public readonly byte[] State;
public bool Lagged; public readonly bool Lagged;
} }
private List<string> MovieRecords = new List<string>(); private readonly List<string> _movie_records = new List<string>();
private List<StateRecord> StateRecords = new List<StateRecord>(); private readonly List<StateRecord> _state_records = new List<StateRecord>();
//TODO: Make this size limit configurable by the user //TODO: Make this size limit configurable by the user
private int MaxStateRecordSize = 512 * 1024 * 1024; //To limit memory usage. private const int MAXSTATERECORDSIZE = 512*1024*1024; //To limit memory usage.
#endregion #endregion
} }

View File

@ -1,20 +1,5 @@
using System; namespace BizHawk.MultiClient
using System.Text;
using System.Threading;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using BizHawk.Core;
using BizHawk.Emulation.Consoles.Sega;
using BizHawk.Emulation.Consoles.TurboGrafx;
using BizHawk.Emulation.Consoles.Calculator;
using BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient
{ {
public class MovieSession public class MovieSession
{ {
public MultitrackRecording MultiTrack = new MultitrackRecording(); public MultitrackRecording MultiTrack = new MultitrackRecording();

View File

@ -1,20 +1,15 @@
using System; namespace BizHawk.MultiClient
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient
{ {
public class MultitrackRecording public class MultitrackRecording
{ {
public bool IsActive; public bool IsActive;
public int CurrentPlayer; public int CurrentPlayer;
public bool RecordAll; public bool RecordAll;
public MultitrackRecording() public MultitrackRecording()
{ {
IsActive = false; IsActive = false;
CurrentPlayer = 0; CurrentPlayer = 0;
RecordAll = false; RecordAll = false;
} }
} }
} }

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -10,7 +9,7 @@ namespace BizHawk.MultiClient
{ {
public class SubtitleList public class SubtitleList
{ {
private List<Subtitle> subs = new List<Subtitle>(); private readonly List<Subtitle> subs = new List<Subtitle>();
public SubtitleList() public SubtitleList()
{ {
@ -19,9 +18,12 @@ namespace BizHawk.MultiClient
public SubtitleList(Movie m) public SubtitleList(Movie m)
{ {
if (m.Subtitles.Count() == 0) return; if (m != null && m.Subtitles.Count == 0)
{
return;
}
for (int x = 0; x < m.Subtitles.Count(); x++) for (int x = 0; x < m.Subtitles.Count; x++)
{ {
Subtitle s = new Subtitle(m.Subtitles.GetSubtitleByIndex(x)); Subtitle s = new Subtitle(m.Subtitles.GetSubtitleByIndex(x));
subs.Add(s); subs.Add(s);
@ -37,7 +39,10 @@ namespace BizHawk.MultiClient
public string GetSubtitleText(int index) public string GetSubtitleText(int index)
{ {
if (index >= subs.Count || index < 0) return ""; if (index >= subs.Count || index < 0)
{
return "";
}
StringBuilder sb = new StringBuilder("subtitle "); StringBuilder sb = new StringBuilder("subtitle ");
sb.Append(subs[index].Frame.ToString()); sb.Append(subs[index].Frame.ToString());
@ -63,10 +68,12 @@ namespace BizHawk.MultiClient
{ {
if (subs.Count == 0) return ""; if (subs.Count == 0) return "";
for (int x = 0; x < subs.Count; x++) foreach (Subtitle t in subs)
{ {
if (frame >= subs[x].Frame && frame <= subs[x].Frame + subs[x].Duration) if (frame >= t.Frame && frame <= t.Frame + t.Duration)
return subs[x].Message; {
return t.Message;
}
} }
return ""; return "";
} }
@ -75,33 +82,29 @@ namespace BizHawk.MultiClient
{ {
if (subs.Count == 0) return new Subtitle(); if (subs.Count == 0) return new Subtitle();
for (int x = 0; x < subs.Count; x++) foreach (Subtitle t in subs)
{ {
if (frame >= subs[x].Frame && frame <= subs[x].Frame + subs[x].Duration) if (frame >= t.Frame && frame <= t.Frame + t.Duration)
return subs[x]; {
return t;
}
} }
return new Subtitle(); return new Subtitle();
} }
public List<Subtitle> GetSubtitles(int frame) public List<Subtitle> GetSubtitles(int frame)
{ {
if (subs.Count == 0) if (subs.Count == 0)
return null;
List<Subtitle> s = new List<Subtitle>();
for (int x = 0; x < subs.Count; x++)
{ {
if (frame >= subs[x].Frame && frame <= subs[x].Frame + subs[x].Duration) return null;
s.Add(subs[x]);
} }
return s; return subs.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
} }
public int Count() public int Count
{ {
return subs.Count; get { return subs.Count; }
} }
//TODO //TODO

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
@ -25,7 +20,7 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e) private void Cancel_Click(object sender, EventArgs e)
{ {
this.Close(); Close();
} }
private void OK_Click(object sender, EventArgs e) private void OK_Click(object sender, EventArgs e)
@ -35,8 +30,8 @@ namespace BizHawk.MultiClient
sub.X = (int)XNumeric.Value; sub.X = (int)XNumeric.Value;
sub.Duration = (int)DurationNumeric.Value; sub.Duration = (int)DurationNumeric.Value;
sub.Color = (uint)colorDialog1.Color.ToArgb(); sub.Color = (uint)colorDialog1.Color.ToArgb();
this.DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
this.Close(); Close();
} }
private void SubtitleMaker_Load(object sender, EventArgs e) private void SubtitleMaker_Load(object sender, EventArgs e)
@ -54,7 +49,9 @@ namespace BizHawk.MultiClient
private void ColorPanel_DoubleClick(object sender, EventArgs e) private void ColorPanel_DoubleClick(object sender, EventArgs e)
{ {
if (colorDialog1.ShowDialog() == DialogResult.OK) if (colorDialog1.ShowDialog() == DialogResult.OK)
{
ColorPanel.BackColor = colorDialog1.Color; ColorPanel.BackColor = colorDialog1.Color;
}
} }
} }
} }