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

View File

@ -36,9 +36,9 @@
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.bmpView1 = new BizHawk.MultiClient.GBtools.BmpView();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.bmpView1 = new BizHawk.MultiClient.GBtools.BmpView();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
@ -140,6 +140,14 @@
this.groupBox2.TabStop = false;
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
//
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
@ -160,14 +168,6 @@
this.buttonCancel.Text = "Cancel";
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
//
this.AcceptButton = this.buttonOK;
@ -182,6 +182,7 @@
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "CGBColorChooserForm";
this.Text = "Gameboy Color Palette Config";
this.Load += new System.EventHandler(this.CGBColorChooserForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);

View File

@ -1,10 +1,5 @@
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 BizHawk.Emulation.Consoles.GB;
@ -69,7 +64,8 @@ namespace BizHawk.MultiClient.GBtools
type = GBColors.ColorType.vbabgbold;
if (sender == radioButton6)
type = GBColors.ColorType.gba;
if ((sender as RadioButton).Checked)
var radio_button = sender as RadioButton;
if (radio_button != null && radio_button.Checked)
RefreshType();
}
@ -88,5 +84,10 @@ namespace BizHawk.MultiClient.GBtools
}
}
private void CGBColorChooserForm_Load(object sender, EventArgs e)
{
}
}
}

View File

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

View File

@ -13,7 +13,7 @@ namespace BizHawk.MultiClient.GBtools
InitializeComponent();
}
Color[] colors = new Color[12];
private readonly Color[] colors = new Color[12];
/// <summary>
/// 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
};
/// <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
};
@ -72,7 +72,7 @@ namespace BizHawk.MultiClient.GBtools
{
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);
}
RefreshAllBackdrops();
@ -143,7 +143,7 @@ namespace BizHawk.MultiClient.GBtools
var result = dlg.ShowDialog(this);
if (result == System.Windows.Forms.DialogResult.OK)
if (result == DialogResult.OK)
{
if (colors[i] != dlg.Color)
{
@ -158,7 +158,7 @@ namespace BizHawk.MultiClient.GBtools
/// <summary>
/// ini keys for gambatte palette file
/// </summary>
static string[] paletteinikeys =
private static readonly string[] paletteinikeys =
{
"Background0",
"Background1",
@ -220,14 +220,17 @@ namespace BizHawk.MultiClient.GBtools
{
f.WriteLine("[General]");
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
for (int i = 0; i < this.colors.Length; i++)
this.colors[i] = Color.FromArgb(255, Color.FromArgb(colors[i]));
for (int i = 0; i < colors.Length; i++)
{
colors[i] = Color.FromArgb(255, Color.FromArgb(_colors[i]));
}
RefreshAllBackdrops();
}
@ -318,8 +321,10 @@ namespace BizHawk.MultiClient.GBtools
ofd.RestoreDirectory = true;
var result = ofd.ShowDialog(this);
if (result != System.Windows.Forms.DialogResult.OK)
if (result != DialogResult.OK)
{
return;
}
LoadColorFile(ofd.FileName, true);
}
@ -362,8 +367,10 @@ namespace BizHawk.MultiClient.GBtools
sfd.Filter = "Gambatte Palettes (*.pal)|*.pal|All Files|*.*";
sfd.RestoreDirectory = true;
var result = sfd.ShowDialog(this);
if (result != System.Windows.Forms.DialogResult.OK)
if (result != DialogResult.OK)
{
return;
}
SaveColorFile(sfd.FileName);
}
@ -386,5 +393,10 @@ namespace BizHawk.MultiClient.GBtools
currentfile = "";
SetAllColors(DefaultCGBColors);
}
private void ColorChooserForm_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -1,12 +1,7 @@
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.Runtime.InteropServices;
namespace BizHawk.MultiClient.GBtools
{
@ -36,7 +31,7 @@ namespace BizHawk.MultiClient.GBtools
IntPtr oam;
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
@ -72,7 +67,7 @@ namespace BizHawk.MultiClient.GBtools
KeyPreview = true;
messagetimer.Interval = 5000;
messagetimer.Tick += new EventHandler(messagetimer_Tick);
messagetimer.Tick += messagetimer_Tick;
checkBoxAutoLoad.Checked = Global.Config.AutoLoadGBGPUView;
checkBoxSavePos.Checked = Global.Config.GBGPUViewSaveWindowPosition;
@ -87,7 +82,7 @@ namespace BizHawk.MultiClient.GBtools
{
gb = Global.Emulator as Emulation.Consoles.GB.Gameboy;
cgb = gb.IsCGBMode();
lcdc = 0;
_lcdc = 0;
if (!gb.GetGPUMemoryAreas(out vram, out bgpal, out sppal, out oam))
{
gb = null;
@ -365,12 +360,11 @@ namespace BizHawk.MultiClient.GBtools
void ScanlineCallback(int lcdc)
{
this.lcdc = lcdc;
_lcdc = lcdc;
// set alpha on all pixels
unsafe
{
int* p;
p = (int*)bgpal;
int* p = (int*)bgpal;
for (int i = 0; i < 32; i++)
p[i] |= unchecked((int)0xff000000);
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
// 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);
this.OnMouseMove(e);
OnMouseMove(e);
}
private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e)
@ -554,11 +548,13 @@ namespace BizHawk.MultiClient.GBtools
/// </summary>
public void UpdateValues()
{
if (!this.IsHandleCreated || this.IsDisposed)
return;
if (gb != null)
if (!IsHandleCreated || IsDisposed)
{
if (!this.Visible)
return;
}
else if (gb != null)
{
if (!Visible)
{
if (cbscanline_emu != -2)
{
@ -684,14 +680,14 @@ namespace BizHawk.MultiClient.GBtools
if (bmpViewDetails.Height != 64)
bmpViewDetails.Height = 64;
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;
x /= 8;
y /= 8;
mapoffs += y * 32 + x;
byte* mapbase = (byte*)vram + mapoffs;
int tileindex = mapbase[0];
if (win || !lcdc.Bit(4)) // 0x9000 base
if (win || !_lcdc.Bit(4)) // 0x9000 base
if (tileindex < 128)
tileindex += 256; // compute all if from 0x8000 base
int tileoffs = tileindex * 16;
@ -719,7 +715,7 @@ namespace BizHawk.MultiClient.GBtools
unsafe void SpriteMouseover(int x, int y)
{
bool tall = lcdc.Bit(2);
bool tall = _lcdc.Bit(2);
x /= 8;
y /= 8;
bmpViewDetails.ChangeBitmapSize(8, tall ? 16 : 8);
@ -884,9 +880,9 @@ namespace BizHawk.MultiClient.GBtools
private void bmpView_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
if (e.Button == MouseButtons.Right)
SetFreeze();
else if (e.Button == System.Windows.Forms.MouseButtons.Left)
else if (e.Button == MouseButtons.Left)
{
if (sender == bmpViewBGPal)
tilespal = bgpal + e.X / 16 * 16;
@ -897,23 +893,23 @@ namespace BizHawk.MultiClient.GBtools
#region copyimage
Timer messagetimer = new Timer();
private readonly Timer messagetimer = new Timer();
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
Point m = System.Windows.Forms.Cursor.Position;
Point m = Cursor.Position;
Control top = this;
Control found = null;
Control found;
do
{
found = top.GetChildAtPoint(top.PointToClient(m));
top = found;
} while (found != null && found.HasChildren);
if (found != null && found is BmpView)
if (found is BmpView)
{
var bv = found as BmpView;
Clipboard.SetImage(bv.bmp);
@ -962,7 +958,7 @@ namespace BizHawk.MultiClient.GBtools
Global.Sound.StopSound();
var result = dlg.ShowDialog();
Global.Sound.StartSound();
if (result == System.Windows.Forms.DialogResult.OK)
if (result == DialogResult.OK)
{
// force full opaque
spriteback = Color.FromArgb(255, dlg.Color);

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
#if WINDOWS
using SlimDX.Direct3D9;
using SlimDX.DirectSound;
using System.Drawing;
#endif
namespace BizHawk.MultiClient
@ -69,58 +69,58 @@ namespace BizHawk.MultiClient
public static Controller Commodore64Controls;
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"},
{"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"},
{"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"},
{"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"},
{"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"},
{"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"},
{"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"}
}
},
{
"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"},
{"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"}
}
},
{
"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"}
}
},
{
"Commodore 64 Controller", new Dictionary<string,string>()
"Commodore 64 Controller", new Dictionary<string,string>
{
{"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 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"},
{"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"}}},
{"Gameboy 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"}}},
{"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"}}},
{"PC Engine Controller", new Dictionary<string, string>() {}},
{"SMS Controller", new Dictionary<string, string>() {{"Pause", "p"}, {"Reset", "r"}}},
{"TI83 Controller", new Dictionary<string, string>() {}}
{"GBA Controller", new Dictionary<string, string> {{"Power", "P"}}},
{"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"}}},
{"SNES Controller", new Dictionary<string, string> {{"Power", "P"}, {"Reset", "r"}}},
{"PC Engine Controller", new Dictionary<string, string> {}},
{"SMS Controller", new Dictionary<string, string> {{"Pause", "p"}, {"Reset", "r"}}},
{"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},
{"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()
{
MnemonicsGenerator mg = new MnemonicsGenerator();
mg.SetSource(Global.ControllerOutput);
mg.SetSource(ControllerOutput);
return mg.GetControllersAsMnemonic();
}

View File

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

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace BizHawk.MultiClient
@ -8,8 +7,8 @@ namespace BizHawk.MultiClient
public class Controller : IController
{
private ControllerDefinition type;
private WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>();
private WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, List<string>> bindings = new WorkingDictionary<string, List<string>>();
private readonly WorkingDictionary<string, bool> buttons = new WorkingDictionary<string, bool>();
public Controller(ControllerDefinition definition)
{
@ -18,7 +17,7 @@ namespace BizHawk.MultiClient
public ControllerDefinition Type { get { return type; } }
/// <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 IsPressed(string button)
{
@ -133,16 +132,7 @@ namespace BizHawk.MultiClient
{
get
{
List<string> list = new List<string>();
foreach (var button in buttons)
{
if (button.Value)
{
list.Add(button.Key);
}
}
return list;
return (from button in buttons where button.Value select button.Key).ToList();
}
}
}
@ -212,7 +202,7 @@ namespace BizHawk.MultiClient
{
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;
}
}
@ -269,16 +259,7 @@ namespace BizHawk.MultiClient
{
get
{
List<string> list = new List<string>();
foreach (var button in buttons)
{
if (button.Value)
{
list.Add(button.Key);
}
}
return list;
return (from button in buttons where button.Value select button.Key).ToList();
}
}
}

View File

@ -107,12 +107,12 @@ namespace BizHawk.MultiClient
}
public int NumButtons { get; private set; }
List<string> names = new List<string>();
List<Func<bool>> actions = new List<Func<bool>>();
private readonly List<string> names = new List<string>();
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);
NumButtons++;
}
@ -204,13 +204,15 @@ namespace BizHawk.MultiClient
// 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
var parameters = new EffectParameters();
parameters.Duration = 0x2710;
parameters.Gain = 0x2710;
parameters.SamplePeriod = 0;
parameters.TriggerButton = 0;
parameters.TriggerRepeatInterval = 0x2710;
parameters.Flags = EffectFlags.None;
var parameters = new EffectParameters
{
Duration = 0x2710,
Gain = 0x2710,
SamplePeriod = 0,
TriggerButton = 0,
TriggerRepeatInterval = 0x2710,
Flags = EffectFlags.None
};
parameters.GetAxes(out temp1, out temp2);
parameters.SetAxes(temp1, temp2);
var effect = new Effect(joystick, EffectGuid.ConstantForce);

View File

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

View File

@ -2,7 +2,6 @@
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
#if WINDOWS
using SlimDX.DirectInput;
#endif
@ -22,7 +21,7 @@ namespace BizHawk.MultiClient
//when a button is released, all modified variants of it are released as well
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)
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)
string[] subgroups = button.Split('+');
if (subgroups != null && subgroups.Length > 0)
if (subgroups.Length > 0)
{
foreach (string s in subgroups)
{
@ -60,6 +59,7 @@ namespace BizHawk.MultiClient
public class Input
{
[Flags]
public enum ModifierKey
{
// Summary:
@ -84,13 +84,12 @@ namespace BizHawk.MultiClient
}
public static Input Instance { get; private set; }
Thread UpdateThread;
readonly Thread UpdateThread;
private Input()
{
#if WINDOWS
UpdateThread = new Thread(UpdateThreadProc);
UpdateThread.IsBackground = true;
UpdateThread = new Thread(UpdateThreadProc) {IsBackground = true};
UpdateThread.Start();
#endif
}
@ -116,8 +115,8 @@ namespace BizHawk.MultiClient
Button = button;
Modifiers = modifiers;
}
public string Button;
public ModifierKey Modifiers;
public readonly string Button;
public readonly ModifierKey Modifiers;
public bool Alt { get { return ((Modifiers & ModifierKey.Alt) != 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>();
WorkingDictionary<string, bool> LastState = new WorkingDictionary<string, bool>();
WorkingDictionary<string, bool> UnpressState = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, object> ModifierState = new WorkingDictionary<string, object>();
private readonly WorkingDictionary<string, bool> LastState = 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)
{
if (EnableIgnoreModifiers && IgnoreKeys.Contains(button)) return;
@ -189,9 +188,11 @@ namespace BizHawk.MultiClient
if (button == "LeftAlt") mods &= ~ModifierKey.Alt;
if (button == "RightAlt") mods &= ~ModifierKey.Alt;
var ie = new InputEvent();
ie.EventType = newState ? InputEventType.Press : InputEventType.Release;
ie.LogicalButton = new LogicalButton(button, mods);
var ie = new InputEvent
{
EventType = newState ? InputEventType.Press : InputEventType.Release,
LogicalButton = new LogicalButton(button, mods)
};
LastState[button] = newState;
//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)
{
LogicalButton alreadyReleased = ie.LogicalButton;
var ieModified = new InputEvent();
ieModified.LogicalButton = (LogicalButton)ModifierState[button];
ieModified.EventType = InputEventType.Release;
var ieModified = new InputEvent
{
LogicalButton = (LogicalButton) ModifierState[button],
EventType = InputEventType.Release
};
if (ieModified.LogicalButton != alreadyReleased)
_NewEvents.Add(ieModified);
}
@ -223,7 +226,7 @@ namespace BizHawk.MultiClient
}
ModifierKey _Modifiers;
List<InputEvent> _NewEvents = new List<InputEvent>();
private readonly List<InputEvent> _NewEvents = new List<InputEvent>();
//do we need this?
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()
{
lock (this)

View File

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

View File

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

View File

@ -955,7 +955,7 @@ namespace BizHawk.MultiClient
s.DisableFrame();
int index = -1;
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);
if (Global.Emulator.Frame == sub.Frame)

View File

@ -1,10 +1,6 @@
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 BizHawk.Emulation.Consoles.Nintendo;
@ -12,28 +8,28 @@ namespace BizHawk.MultiClient
{
public partial class NESDebugger : Form
{
const int ADDR_MAX = 0xFFFF;
const int DISASM_LINE_COUNT = 100;
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
NES Nes;
private const int ADDR_MAX = 0xFFFF;
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
private int defaultHeight;
private NES _nes;
private int pc;
private int addr;
private readonly List<DisasmOp> lines = new List<DisasmOp>();
private struct DisasmOp
{
public int size;
public string mnemonic;
public readonly int size;
public readonly string mnemonic;
public DisasmOp(int s, string m) { size = s; mnemonic = m; }
}
int pc;
int addr;
List<DisasmOp> lines = new List<DisasmOp>();
public NESDebugger()
{
InitializeComponent();
DebugView.QueryItemText += new QueryItemTextHandler(DebugView_QueryItemText);
DebugView.QueryItemBkColor += new QueryItemBkColorHandler(DebugView_QueryItemBkColor);
DebugView.QueryItemText += DebugView_QueryItemText;
DebugView.QueryItemBkColor += DebugView_QueryItemBkColor;
DebugView.VirtualMode = true;
DebugView.ItemCount = ADDR_MAX + 1;
Activated += (o, e) => UpdateValues();
@ -42,16 +38,16 @@ namespace BizHawk.MultiClient
public void Restart()
{
if (!(Global.Emulator is NES)) this.Close();
if (!this.IsHandleCreated || this.IsDisposed) return;
Nes = Global.Emulator as NES;
if (!(Global.Emulator is NES)) Close();
if (!IsHandleCreated || IsDisposed) return;
_nes = Global.Emulator as NES;
}
public void UpdateValues()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (!IsHandleCreated || IsDisposed) return;
addr = pc = Nes.cpu.PC;
addr = pc = _nes.cpu.PC;
UpdateDebugView();
}
@ -72,7 +68,7 @@ namespace BizHawk.MultiClient
for (int i = 0; i < line_count; ++i)
{
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));
a += advance;
if (a > ADDR_MAX) break;
@ -82,29 +78,29 @@ namespace BizHawk.MultiClient
private void NESDebugger_Load(object sender, EventArgs e)
{
LoadConfigSettings();
Nes = Global.Emulator as NES;
_nes = Global.Emulator as NES;
}
private void LoadConfigSettings()
{
defaultWidth = this.Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = this.Size.Height;
defaultWidth = Size.Width; //Save these first so that the user can restore to its original size
defaultHeight = Size.Height;
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)
{
this.Size = new System.Drawing.Size(Global.Config.NESDebuggerWidth, Global.Config.NESDebuggerHeight);
Size = new Size(Global.Config.NESDebuggerWidth, Global.Config.NESDebuggerHeight);
}
}
public void SaveConfigSettings()
{
Global.Config.NESDebuggerWndx = this.Location.X;
Global.Config.NESDebuggerWndy = this.Location.Y;
Global.Config.NESDebuggerWidth = this.Right - this.Left;
Global.Config.NESDebuggerHeight = this.Bottom - this.Top;
Global.Config.NESDebuggerWndx = Location.X;
Global.Config.NESDebuggerWndy = Location.Y;
Global.Config.NESDebuggerWidth = Right - Left;
Global.Config.NESDebuggerHeight = Bottom - Top;
}
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)
{
this.Close();
Close();
}
private void autoloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -155,7 +151,7 @@ namespace BizHawk.MultiClient
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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using BizHawk;
namespace BizHawk.MultiClient
{
public partial class NESGameGenie : Form
{
public int address = -1;
public int value = -1;
public int compare = -1;
Dictionary<char, int> GameGenieTable = new Dictionary<char, int>();
public int Address = -1;
public int Value = -1;
public int Compare = -1;
private readonly Dictionary<char, int> GameGenieTable = new Dictionary<char, int>();
public NESGameGenie()
{
@ -51,8 +46,8 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings()
{
Global.Config.NESGGWndx = this.Location.X;
Global.Config.NESGGWndy = this.Location.Y;
Global.Config.NESGGWndx = Location.X;
Global.Config.NESGGWndy = Location.Y;
}
private void GameGenieCode_KeyPress(object sender, KeyPressEventArgs e)
@ -63,7 +58,7 @@ namespace BizHawk.MultiClient
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;
}
@ -74,11 +69,6 @@ namespace BizHawk.MultiClient
}
}
private int GetBit(int value, int bit)
{
return (value >> bit) & 1;
}
public void DecodeGameGenieCode(string code)
{
//char 3 bit 3 denotes the code length.
@ -87,32 +77,32 @@ namespace BizHawk.MultiClient
//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|
//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;
address = 0x8000;
Value = 0;
Address = 0x8000;
int x;
GameGenieTable.TryGetValue(code[0], out x);
value |= (x & 0x07);
value |= (x & 0x08) << 4;
Value |= (x & 0x07);
Value |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[1], out x);
value |= (x & 0x07) << 4;
address |= (x & 0x08) << 4;
Value |= (x & 0x07) << 4;
Address |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[2], out x);
address |= (x & 0x07) << 4;
Address |= (x & 0x07) << 4;
GameGenieTable.TryGetValue(code[3], out x);
address |= (x & 0x07) << 12;
address |= (x & 0x08);
Address |= (x & 0x07) << 12;
Address |= (x & 0x08);
GameGenieTable.TryGetValue(code[4], out x);
address |= (x & 0x07);
address |= (x & 0x08) << 8;
Address |= (x & 0x07);
Address |= (x & 0x08) << 8;
GameGenieTable.TryGetValue(code[5], out x);
address |= (x & 0x07) << 8;
value |= (x & 0x08);
Address |= (x & 0x07) << 8;
Value |= (x & 0x08);
SetProperties();
@ -122,67 +112,67 @@ namespace BizHawk.MultiClient
//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|
//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;
address = 0x8000;
compare = 0;
Value = 0;
Address = 0x8000;
Compare = 0;
int x;
GameGenieTable.TryGetValue(code[0], out x);
value |= (x & 0x07);
value |= (x & 0x08) << 4;
Value |= (x & 0x07);
Value |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[1], out x);
value |= (x & 0x07) << 4;
address |= (x & 0x08) << 4;
Value |= (x & 0x07) << 4;
Address |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[2], out x);
address |= (x & 0x07) << 4;
Address |= (x & 0x07) << 4;
GameGenieTable.TryGetValue(code[3], out x);
address |= (x & 0x07) << 12;
address |= (x & 0x08);
Address |= (x & 0x07) << 12;
Address |= (x & 0x08);
GameGenieTable.TryGetValue(code[4], out x);
address |= (x & 0x07);
address |= (x & 0x08) << 8;
Address |= (x & 0x07);
Address |= (x & 0x08) << 8;
GameGenieTable.TryGetValue(code[5], out x);
address |= (x & 0x07) << 8;
compare |= (x & 0x08);
Address |= (x & 0x07) << 8;
Compare |= (x & 0x08);
GameGenieTable.TryGetValue(code[6], out x);
compare |= (x & 0x07);
compare |= (x & 0x08) << 4;
Compare |= (x & 0x07);
Compare |= (x & 0x08) << 4;
GameGenieTable.TryGetValue(code[7], out x);
compare |= (x & 0x07) << 4;
value |= (x & 0x08);
Compare |= (x & 0x07) << 4;
Value |= (x & 0x08);
SetProperties();
}
}
private void SetProperties()
{
if (address >= 0)
AddressBox.Text = String.Format("{0:X4}", address);
if (Address >= 0)
AddressBox.Text = String.Format("{0:X4}", Address);
else
AddressBox.Text = "";
if (compare >= 0)
CompareBox.Text = String.Format("{0:X2}", compare);
if (Compare >= 0)
CompareBox.Text = String.Format("{0:X2}", Compare);
else
CompareBox.Text = "";
if (value >= 0)
ValueBox.Text = String.Format("{0:X2}", value);
if (Value >= 0)
ValueBox.Text = String.Format("{0:X2}", Value);
}
private void ClearProperties()
{
address = -1;
value = -1;
compare = -1;
Address = -1;
Value = -1;
Compare = -1;
AddressBox.Text = "";
CompareBox.Text = "";
ValueBox.Text = "";
@ -234,10 +224,10 @@ namespace BizHawk.MultiClient
{
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)
{
address = a;
Address = a;
EncodeGameGenie();
}
}
@ -255,14 +245,14 @@ namespace BizHawk.MultiClient
{
if (ValueBox.Text.Length > 0 && AddressBox.Text.Length > 0)
{
compare = c;
Compare = c;
EncodeGameGenie();
}
}
}
else
{
compare = -1;
Compare = -1;
EncodeGameGenie();
}
}
@ -286,7 +276,7 @@ namespace BizHawk.MultiClient
{
if (AddressBox.Text.Length > 0)
{
value = v;
Value = v;
EncodeGameGenie();
}
}
@ -298,29 +288,29 @@ namespace BizHawk.MultiClient
private void EncodeGameGenie()
{
char[] letters = { 'A', 'P', 'Z', 'L', 'G', 'I', 'T', 'Y', 'E', 'O', 'X', 'U', 'K', 'S', 'V', 'N' };
if (address >= 0x8000)
address -= 0x8000;
if (Address >= 0x8000)
Address -= 0x8000;
GameGenieCode.Text = "";
byte[] num = { 0, 0, 0, 0, 0, 0, 0, 0 };
num[0] = (byte)((value & 7) + ((value >> 4) & 8));
num[1] = (byte)(((value >> 4) & 7) + ((address >> 4) & 8));
num[2] = (byte)(((address >> 4) & 7));
num[3] = (byte)((address >> 12) + (address & 8));
num[4] = (byte)((address & 7) + ((address >> 8) & 8));
num[5] = (byte)(((address >> 8) & 7));
num[0] = (byte)((Value & 7) + ((Value >> 4) & 8));
num[1] = (byte)(((Value >> 4) & 7) + ((Address >> 4) & 8));
num[2] = (byte)(((Address >> 4) & 7));
num[3] = (byte)((Address >> 12) + (Address & 8));
num[4] = (byte)((Address & 7) + ((Address >> 8) & 8));
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++)
GameGenieCode.Text += letters[num[x]];
}
else
{
num[2] += 8;
num[5] += (byte)(compare & 8);
num[6] = (byte)((compare & 7) + ((compare >> 4) & 8));
num[7] = (byte)(((compare >> 4) & 7) + (value & 8));
num[5] += (byte)(Compare & 8);
num[6] = (byte)((Compare & 7) + ((Compare >> 4) & 8));
num[7] = (byte)(((Compare >> 4) & 7) + (Value & 8));
for (int x = 0; x < 8; x++)
GameGenieCode.Text += letters[num[x]];
}
@ -341,8 +331,7 @@ namespace BizHawk.MultiClient
private void AddCheatClick()
{
Cheat c = new Cheat();
c.name = GameGenieCode.Text;
Cheat c = new Cheat {name = GameGenieCode.Text};
if (String.IsNullOrWhiteSpace(AddressBox.Text))
{
@ -379,7 +368,7 @@ namespace BizHawk.MultiClient
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)

View File

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

View File

@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Emulation.Consoles.Nintendo;
using System.IO;
namespace BizHawk.MultiClient
{
@ -17,12 +11,8 @@ namespace BizHawk.MultiClient
//TODO:
//Show Scroll Lines + UI Toggle
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
NES Nes;
NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
private NES _nes;
private readonly NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
public NESNameTableViewer()
{
@ -33,35 +23,35 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings()
{
Global.Config.NESNameTableWndx = this.Location.X;
Global.Config.NESNameTableWndy = this.Location.Y;
Global.Config.NESNameTableWndx = Location.X;
Global.Config.NESNameTableWndy = Location.Y;
Global.Config.NESNameTableRefreshRate = RefreshRate.Value;
}
unsafe void Generate(bool now = false)
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (Nes == null) return;
if (!IsHandleCreated || IsDisposed) return;
if (_nes == null) return;
if (now == false)
{
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 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
byte[] p = new byte[0x3000];
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];
for (int x = 0; x < 0x20; x++)
palram[x] = Nes.ppu.PALRAM[x];
palram[x] = _nes.ppu.PALRAM[x];
int ytable = 0, yline = 0;
for (int y = 0; y < 480; y++)
@ -102,19 +92,19 @@ namespace BizHawk.MultiClient
pixel |= at;
pixel = palram[pixel];
int cvalue = Nes.LookupColor(pixel);
int cvalue = _nes.LookupColor(pixel);
*dptr = cvalue;
}
dptr += pitch - 512;
}
NameTableView.nametables.UnlockBits(bmpdata);
NameTableView.Nametables.UnlockBits(bmpdata);
NameTableView.Refresh();
}
public void UpdateValues()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is NES)) return;
NES.PPU ppu = (Global.Emulator as NES).ppu;
ppu.NTViewCallback = Callback;
@ -122,27 +112,24 @@ namespace BizHawk.MultiClient
public void Restart()
{
if (!(Global.Emulator is NES)) this.Close();
Nes = Global.Emulator as NES;
if (!(Global.Emulator is NES)) Close();
_nes = Global.Emulator as NES;
Generate(true);
}
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)
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;
Generate(true);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void autoloadToolStripMenuItem_Click(object sender, EventArgs e)
@ -163,7 +150,7 @@ namespace BizHawk.MultiClient
private void txtScanline_TextChanged(object sender, EventArgs e)
{
int temp = 0;
int temp;
if (int.TryParse(txtScanline.Text, out temp))
{
Callback.Scanline = temp;
@ -172,9 +159,9 @@ namespace BizHawk.MultiClient
private void NESNameTableViewer_FormClosed(object sender, FormClosedEventArgs e)
{
if (Nes == null) return;
if (Nes.ppu.NTViewCallback == Callback)
Nes.ppu.NTViewCallback = null;
if (_nes == null) return;
if (_nes.ppu.NTViewCallback == Callback)
_nes.ppu.NTViewCallback = null;
}
@ -222,7 +209,7 @@ namespace BizHawk.MultiClient
XYLabel.Text = TileX.ToString() + " : " + TileY.ToString();
int PPUAddress = 0x2000 + (NameTable * 0x400) + ((TileY % 30) * 32) + (TileX % 32);
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);
TableLabel.Text = NameTable.ToString();
@ -232,18 +219,14 @@ namespace BizHawk.MultiClient
ytable += 2;
yline = 240;
}
int pt_add = Nes.ppu.reg_2000.bg_pattern_hi ? 0x1000 : 0;
int table = (e.X >> 8) + ytable;
int ntaddr = (table << 10);
int px = e.X & 255;
int py = e.Y - yline;
int tx = px >> 3;
int ty = py >> 3;
int ntbyte_ptr = ntaddr + (ty * 32) + tx;
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 ((tx & 2) != 0) at >>= 2;
at &= 0x03;

View File

@ -1,14 +1,8 @@
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.Globalization;
using BizHawk.Emulation.Consoles.Nintendo;
using System.Diagnostics;
namespace BizHawk.MultiClient
{
@ -16,22 +10,18 @@ namespace BizHawk.MultiClient
{
//TODO:
//If 8/16 sprite mode, mouse over should put 32x64 version of prite
//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
//Maybe 48 individual bitmaps for sprites is faster than the overhead of redrawing all that transparent space
Bitmap ZoomBoxDefaultImage = new Bitmap(64, 64);
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
NES Nes;
byte[] PPUBus = new byte[0x2000];
byte[] PPUBusprev = new byte[0x2000];
byte[] PALRAM = new byte[0x20];
byte[] PALRAMprev = new byte[0x20];
NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
private Bitmap ZoomBoxDefaultImage = new Bitmap(64, 64);
private NES _nes;
private readonly byte[] PPUBus = new byte[0x2000];
private readonly byte[] PPUBusprev = new byte[0x2000];
private readonly byte[] PALRAM = new byte[0x20];
private readonly byte[] PALRAMprev = new byte[0x20];
private readonly NES.PPU.DebugCallback Callback = new NES.PPU.DebugCallback();
private bool ForceChange;
public NESPPU()
{
@ -53,24 +43,21 @@ namespace BizHawk.MultiClient
private void SaveConfigSettings()
{
Global.Config.NESPPUWndx = this.Location.X;
Global.Config.NESPPUWndy = this.Location.Y;
Global.Config.NESPPUWndx = Location.X;
Global.Config.NESPPUWndy = Location.Y;
Global.Config.NESPPURefreshRate = RefreshRate.Value;
}
public void Restart()
{
if (!(Global.Emulator is NES)) this.Close();
if (!this.IsHandleCreated || this.IsDisposed) return;
Nes = Global.Emulator as NES;
if (!(Global.Emulator is NES)) Close();
if (!IsHandleCreated || IsDisposed) return;
_nes = Global.Emulator as NES;
Generate(true);
}
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)
Location = new Point(Global.Config.NESPPUWndx, Global.Config.NESPPUWndy);
}
@ -79,15 +66,14 @@ namespace BizHawk.MultiClient
{
return (byte)(((PPUBus[address] >> (7 - bit)) & 1));
}
bool ForceChange = false;
bool CheckChange()
private bool CheckChange()
{
bool changed = false;
for (int x = 0; x < 0x20; x++)
{
PALRAMprev[x] = PALRAM[x];
PALRAM[x] = Nes.ppu.PALRAM[x];
PALRAM[x] = _nes.ppu.PALRAM[x];
if (PALRAM[x] != PALRAMprev[x])
{
changed = true;
@ -97,7 +83,7 @@ namespace BizHawk.MultiClient
for (int x = 0; x < 0x2000; x++)
{
PPUBusprev[x] = PPUBus[x];
PPUBus[x] = Nes.ppu.ppubus_peek(x);
PPUBus[x] = _nes.ppu.ppubus_peek(x);
if (PPUBus[x] != PPUBusprev[x])
{
changed = true;
@ -111,14 +97,14 @@ namespace BizHawk.MultiClient
unsafe void Generate(bool now = false)
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (!IsHandleCreated || IsDisposed) return;
if (Global.Emulator.Frame % RefreshRate.Value == 0 || now)
{
bool Changed = CheckChange();
int b0 = 0;
int b1 = 0;
int b0;
int b1;
byte value;
int cvalue;
@ -127,13 +113,12 @@ namespace BizHawk.MultiClient
ForceChange = false;
//Pattern Viewer
int pal;
for (int x = 0; x < 16; x++)
{
PaletteView.bgPalettesPrev[x].Value = PaletteView.bgPalettes[x].Value;
PaletteView.spritePalettesPrev[x].Value = PaletteView.spritePalettes[x].Value;
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.BgPalettesPrev[x].Value = PaletteView.BgPalettes[x].Value;
PaletteView.SpritePalettesPrev[x].Value = PaletteView.SpritePalettes[x].Value;
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]);
}
if (PaletteView.HasChanged())
{
@ -144,6 +129,7 @@ namespace BizHawk.MultiClient
int* framebuf = (int*)bmpdata.Scan0.ToPointer();
for (int z = 0; z < 2; z++)
{
int pal;
if (z == 0)
pal = PatternView.Pal0;
else
@ -162,7 +148,7 @@ namespace BizHawk.MultiClient
b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 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);
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);
int* framebuf2 = (int*)bmpdata2.Scan0.ToPointer();
int BaseAddr, TileNum, Attributes, Palette;
int pt_add = Nes.ppu.reg_2000.obj_pattern_hi ? 0x1000 : 0;
bool is8x16 = Nes.ppu.reg_2000.obj_size_16;
int pt_add = _nes.ppu.reg_2000.obj_pattern_hi ? 0x1000 : 0;
bool is8x16 = _nes.ppu.reg_2000.obj_size_16;
//Sprite Viewer
@ -187,9 +172,9 @@ namespace BizHawk.MultiClient
{
for (int r = 0; r < 16; r++)
{
BaseAddr = (r << 2) + (n << 6);
TileNum = Nes.ppu.OAM[BaseAddr + 1];
int PatAddr = 0;
int BaseAddr = (r << 2) + (n << 6);
int TileNum = _nes.ppu.OAM[BaseAddr + 1];
int PatAddr;
if (is8x16)
{
@ -203,8 +188,8 @@ namespace BizHawk.MultiClient
}
Attributes = Nes.ppu.OAM[BaseAddr + 2];
Palette = Attributes & 0x03;
int Attributes = _nes.ppu.OAM[BaseAddr + 2];
int Palette = Attributes & 0x03;
for (int x = 0; x < 8; x++)
{
@ -214,7 +199,7 @@ namespace BizHawk.MultiClient
b0 = (byte)(((PPUBus[address] >> (7 - x)) & 1));
b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 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);
framebuf2[adr] = cvalue;
@ -228,7 +213,7 @@ namespace BizHawk.MultiClient
b0 = (byte)(((PPUBus[address] >> (7 - x)) & 1));
b1 = (byte)(((PPUBus[address + 8] >> (7 - x)) & 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);
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;
Nes.ppu.PPUViewCallback = Callback;
_nes.ppu.PPUViewCallback = Callback;
}
private void NESPPU_Load(object sender, EventArgs e)
{
LoadConfigSettings();
Nes = Global.Emulator as NES;
_nes = Global.Emulator as NES;
ClearDetails();
RefreshRate.Value = Global.Config.NESPPURefreshRate;
Generate(true);
@ -288,7 +273,7 @@ namespace BizHawk.MultiClient
baseAddr += 16;
int column = (e.X - PaletteView.Location.X) / 16;
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 offset = addr & 0x03;
@ -297,19 +282,19 @@ namespace BizHawk.MultiClient
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();
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
{
val = Nes.ppu.PALRAM[PaletteView.spritePalettes[column].Address];
val = _nes.ppu.PALRAM[PaletteView.SpritePalettes[column].Address];
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();
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();
ZoomBox.Image = bmp;
}
@ -346,7 +331,7 @@ namespace BizHawk.MultiClient
}
UpdatePaletteSelection();
}
HandleDefaultImage(e);
HandleDefaultImage();
}
private void UpdatePaletteSelection()
@ -369,8 +354,8 @@ namespace BizHawk.MultiClient
private void PatternView_MouseMove(object sender, MouseEventArgs e)
{
int table = 0;
int address = 0;
int tile = 0;
int address;
int tile;
if (e.X > PatternView.Width / 2)
table = 1;
@ -391,12 +376,12 @@ namespace BizHawk.MultiClient
tile += (e.Y / 8) * 16;
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";
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";
if ((Nes.ppu.reg_2000.Value & 0x20) > 0)
if ((_nes.ppu.reg_2000.Value & 0x20) > 0)
Usage += " (SPR16)";
AddressLabel.Text = "Address: " + String.Format("{0:X4}", address);
@ -531,7 +516,7 @@ namespace BizHawk.MultiClient
private void txtScanline_TextChanged(object sender, EventArgs e)
{
int temp = 0;
int temp;
if (int.TryParse(txtScanline.Text, out temp))
{
Callback.Scanline = temp;
@ -540,9 +525,9 @@ namespace BizHawk.MultiClient
private void NESPPU_FormClosed(object sender, FormClosedEventArgs e)
{
if (Nes == null) return;
if (Nes.ppu.PPUViewCallback == Callback)
Nes.ppu.PPUViewCallback = null;
if (_nes == null) return;
if (_nes.ppu.PPUViewCallback == Callback)
_nes.ppu.PPUViewCallback = null;
}
private void SpriteView_MouseEnter(object sender, EventArgs e)
@ -557,12 +542,12 @@ namespace BizHawk.MultiClient
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 X = Nes.ppu.OAM[(SpriteNumber * 4) + 3];
int Y = Nes.ppu.OAM[SpriteNumber * 4];
int Color = Nes.ppu.OAM[(SpriteNumber * 4) + 2] & 0x03;
int Attributes = Nes.ppu.OAM[(SpriteNumber * 4) + 2];
int X = _nes.ppu.OAM[(SpriteNumber * 4) + 3];
int Y = _nes.ppu.OAM[SpriteNumber * 4];
int Color = _nes.ppu.OAM[(SpriteNumber * 4) + 2] & 0x03;
int Attributes = _nes.ppu.OAM[(SpriteNumber * 4) + 2];
string flags = "Flags: ";
int h = GetBit(Attributes, 6);
@ -577,7 +562,7 @@ namespace BizHawk.MultiClient
else
flags += "Front";
int Tile = Nes.ppu.OAM[SpriteNumber * 1]; ;
int Tile = _nes.ppu.OAM[SpriteNumber * 1];
AddressLabel.Text = "Number: " + String.Format("{0:X2}", SpriteNumber);
ValueLabel.Text = "X: " + String.Format("{0:X2}", X);
@ -594,17 +579,17 @@ namespace BizHawk.MultiClient
private void PaletteView_MouseClick(object sender, MouseEventArgs e)
{
HandleDefaultImage(e);
HandleDefaultImage();
}
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;
}
@ -687,12 +672,12 @@ namespace BizHawk.MultiClient
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
Point m = System.Windows.Forms.Cursor.Position;
Point m = Cursor.Position;
Control top = this;
Control found = null;
Control found;
do
{
found = top.GetChildAtPoint(top.PointToClient(m));
@ -702,13 +687,19 @@ namespace BizHawk.MultiClient
if (found != null)
{
var meth = found.GetType().GetMethod("ScreenshotToClipboard", System.Type.EmptyTypes);
var meth = found.GetType().GetMethod("ScreenshotToClipboard", Type.EmptyTypes);
if (meth != null)
{
meth.Invoke(found, null);
}
else if (found is PictureBox)
{
Clipboard.SetImage((found as PictureBox).Image);
}
else
{
return;
}
toolStripStatusLabel1.Text = found.Text + " copied to clipboard.";

View File

@ -1,12 +1,5 @@
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 BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient
{

View File

@ -1,32 +1,28 @@
using System;
using System.Drawing;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Drawing.Imaging;
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()
{
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.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
this.Size = new Size(256, 224);
this.BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.NameTableViewer_Paint);
Size = new Size(256, 224);
BackColor = Color.Transparent;
Paint += NameTableViewer_Paint;
}
public enum WhichNametable
@ -36,38 +32,6 @@ namespace BizHawk.MultiClient
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)
{
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
@ -75,44 +39,48 @@ namespace BizHawk.MultiClient
switch (Which)
{
case WhichNametable.NT_ALL:
e.Graphics.DrawImageUnscaled(nametables, 0, 0);
e.Graphics.DrawImageUnscaled(Nametables, 0, 0);
break;
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;
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;
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;
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;
//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:
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;
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;
}
}
public void Screenshot()
{
var sfd = new SaveFileDialog();
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Nametables";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES");
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*";
var sfd = new SaveFileDialog
{
FileName = PathManager.FilesystemSafeName(Global.Game) + "-Nametables",
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound();
var result = sfd.ShowDialog();
Global.Sound.StartSound();
if (result != DialogResult.OK)
{
return;
}
var file = new FileInfo(sfd.FileName);
using (Bitmap b = new Bitmap(Width, Height))
@ -143,7 +111,7 @@ namespace BizHawk.MultiClient
{
Rectangle rect = new Rectangle(new Point(0, 0), Size);
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Drawing.Imaging;
namespace BizHawk.MultiClient
{
public class PaletteViewer : Control
public sealed class PaletteViewer : Control
{
public class Palette
{
public int Address { get; private 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)
{
@ -25,11 +23,11 @@ namespace BizHawk.MultiClient
}
}
public Palette[] bgPalettes = new Palette[16];
public Palette[] spritePalettes = new Palette[16];
public Palette[] BgPalettes = new Palette[16];
public Palette[] SpritePalettes = new Palette[16];
public Palette[] bgPalettesPrev = new Palette[16];
public Palette[] spritePalettesPrev = new Palette[16];
public Palette[] BgPalettesPrev = new Palette[16];
public Palette[] SpritePalettesPrev = new Palette[16];
public PaletteViewer()
{
@ -38,16 +36,16 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
this.Size = new Size(128, 32);
this.BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PaletteViewer_Paint);
Size = new Size(128, 32);
BackColor = Color.Transparent;
Paint += PaletteViewer_Paint;
for (int x = 0; x < 16; x++)
{
bgPalettes[x] = new Palette(x);
spritePalettes[x] = new Palette(x + 16);
bgPalettesPrev[x] = new Palette(x);
spritePalettesPrev[x] = new Palette(x + 16);
BgPalettes[x] = new Palette(x);
SpritePalettes[x] = new Palette(x + 16);
BgPalettesPrev[x] = new Palette(x);
SpritePalettesPrev[x] = new Palette(x + 16);
}
}
@ -56,8 +54,8 @@ namespace BizHawk.MultiClient
{
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(spritePalettes[x].Color), new Rectangle(x * 16, 16, 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));
}
}
@ -65,9 +63,9 @@ namespace BizHawk.MultiClient
{
for (int x = 0; x < 16; x++)
{
if (bgPalettes[x].Value != bgPalettesPrev[x].Value)
if (BgPalettes[x].Value != BgPalettesPrev[x].Value)
return true;
if (spritePalettes[x].Value != spritePalettesPrev[x].Value)
if (SpritePalettes[x].Value != SpritePalettesPrev[x].Value)
return true;
}
return false;
@ -75,12 +73,14 @@ namespace BizHawk.MultiClient
public void Screenshot()
{
var sfd = new SaveFileDialog();
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Palettes";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES");
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*";
var sfd = new SaveFileDialog
{
FileName = PathManager.FilesystemSafeName(Global.Game) + "-Palettes",
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound();
var result = sfd.ShowDialog();
Global.Sound.StartSound();
@ -116,7 +116,7 @@ namespace BizHawk.MultiClient
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Drawing.Imaging;
namespace BizHawk.MultiClient
{
public class PatternViewer : Control
public sealed class PatternViewer : Control
{
Size pSize;
public Bitmap pattern;
public int Pal0 = 0; //0-7 Palette choice
public int Pal1 = 0;
private readonly Size pSize;
public PatternViewer()
{
pSize = new Size(256, 128);
@ -26,9 +22,9 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
this.Size = pSize;
this.BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.PatternViewer_Paint);
Size = pSize;
BackColor = Color.Transparent;
Paint += PatternViewer_Paint;
}
private void PatternViewer_Paint(object sender, PaintEventArgs e)
@ -38,12 +34,14 @@ namespace BizHawk.MultiClient
public void Screenshot()
{
var sfd = new SaveFileDialog();
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Patterns";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES");
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*";
var sfd = new SaveFileDialog
{
FileName = PathManager.FilesystemSafeName(Global.Game) + "-Patterns",
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound();
var result = sfd.ShowDialog();
Global.Sound.StartSound();
@ -79,7 +77,7 @@ namespace BizHawk.MultiClient
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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Drawing.Imaging;
namespace BizHawk.MultiClient
{
public class SpriteViewer : Control
public sealed class SpriteViewer : Control
{
Size pSize;
public Bitmap sprites;
private readonly Size pSize;
public SpriteViewer()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
@ -23,9 +19,9 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
this.Size = pSize;
this.BackColor = Color.Transparent;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.SpriteViewer_Paint);
Size = pSize;
BackColor = Color.Transparent;
Paint += SpriteViewer_Paint;
}
private void Display(Graphics g)
@ -43,12 +39,14 @@ namespace BizHawk.MultiClient
public void Screenshot()
{
var sfd = new SaveFileDialog();
sfd.FileName = PathManager.FilesystemSafeName(Global.Game) + "-Sprites";
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES");
sfd.Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*";
var sfd = new SaveFileDialog
{
FileName = PathManager.FilesystemSafeName(Global.Game) + "-Sprites",
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathNESScreenshots, "NES"),
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
RestoreDirectory = true
};
sfd.RestoreDirectory = true;
Global.Sound.StopSound();
var result = sfd.ShowDialog();
Global.Sound.StartSound();
@ -84,7 +82,7 @@ namespace BizHawk.MultiClient
using (var img = b)
{
System.Windows.Forms.Clipboard.SetImage(img);
Clipboard.SetImage(img);
}
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
@ -12,10 +6,11 @@ namespace BizHawk.MultiClient
{
public partial class PCEBGCanvas : Control
{
const int BAT_WIDTH = 1024;
const int BAT_HEIGHT = 512;
public Bitmap bat;
private const int BAT_WIDTH = 1024;
private const int BAT_HEIGHT = 512;
public PCEBGCanvas()
{
bat = new Bitmap(BAT_WIDTH, BAT_HEIGHT, PixelFormat.Format32bppArgb);
@ -23,25 +18,14 @@ namespace BizHawk.MultiClient
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, 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.Paint += new System.Windows.Forms.PaintEventHandler(this.BGViewer_Paint);
Paint += BGViewer_Paint;
}
private void BGViewer_Paint(object sender, PaintEventArgs e)
{
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.ShowIcon = false;
this.Text = "PCE BG Viewer";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PCEBGViewer_FormClosed);
this.Load += new System.EventHandler(this.PCEBGViewer_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();

View File

@ -1,10 +1,5 @@
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.Drawing.Imaging;
using BizHawk.Emulation.Consoles.TurboGrafx;
@ -13,10 +8,8 @@ namespace BizHawk.MultiClient
{
public partial class PCEBGViewer : Form
{
PCEngine pce;
int VDCtype = 0;
int defaultWidth; //For saving the default size of the dialog, so the user can restore if desired
int defaultHeight;
private PCEngine pce;
private int VDCtype;
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);
int pitch = buf.Stride / 4;
int* begin = (int*)buf.Scan0.ToPointer();
int* p = begin;
// TODO: this does not clear background, why?
//for (int i = 0; i < pitch * buf.Height; ++i, ++p)
// *p = canvas.BackColor.ToArgb();
p = begin;
int* p = begin;
for (int y = 0; y < height; ++y)
{
int yTile = y / 8;
@ -72,10 +64,10 @@ namespace BizHawk.MultiClient
public void Restart()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is PCEngine))
{
this.Close();
Close();
return;
}
pce = Global.Emulator as PCEngine;
@ -83,23 +75,20 @@ namespace BizHawk.MultiClient
public void UpdateValues()
{
if (!this.IsHandleCreated || this.IsDisposed) return;
if (!IsHandleCreated || IsDisposed) return;
if (!(Global.Emulator is PCEngine)) return;
Generate();
}
private void SaveConfigSettings()
{
Global.Config.PCEBGViewerWndx = this.Location.X;
Global.Config.PCEBGViewerWndy = this.Location.Y;
Global.Config.PCEBGViewerWndx = Location.X;
Global.Config.PCEBGViewerWndy = Location.Y;
Global.Config.PCEBGViewerRefreshRate = RefreshRate.Value;
}
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)
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)
{
this.Close();
Close();
}
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,19 +1,10 @@
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 BizHawk.Emulation.Consoles.TurboGrafx;
namespace BizHawk.MultiClient
{
public partial class PCEGraphicsConfig : Form
{
PCEngine pce;
public PCEGraphicsConfig()
{
InitializeComponent();
@ -21,7 +12,6 @@ namespace BizHawk.MultiClient
private void PCEGraphicsConfig_Load(object sender, EventArgs e)
{
pce = Global.Emulator as PCEngine;
DispOBJ1.Checked = Global.Config.PCEDispOBJ1;
DispBG1.Checked = Global.Config.PCEDispBG1;
DispOBJ2.Checked = Global.Config.PCEDispOBJ2;
@ -35,7 +25,7 @@ namespace BizHawk.MultiClient
Global.Config.PCEDispOBJ2 = DispOBJ2.Checked;
Global.Config.PCEDispBG2 = DispBG2.Checked;
this.Close();
Close();
}
}
}

View File

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

View File

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

View File

@ -1,13 +1,6 @@
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.IO;
using BizHawk.Emulation.Consoles.GB;
using BizHawk.Emulation.Consoles.Nintendo.SNES;
using BizHawk.Emulation.Consoles.Sega;
@ -33,7 +26,6 @@ namespace BizHawk.MultiClient
if (RecordBox.Text.Length == 0)
return "";
string path = RecordBox.Text;
int x = path.LastIndexOf('\\');
if (path.LastIndexOf('\\') == -1)
{
if (path[0] != '\\')
@ -58,7 +50,7 @@ namespace BizHawk.MultiClient
if (test.Exists)
{
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;
}
@ -127,7 +119,7 @@ namespace BizHawk.MultiClient
var file = new FileInfo(temppath);
using (StreamReader sr = file.OpenText())
{
string str = "";
string str;
while ((str = sr.ReadLine()) != null)
{
@ -147,7 +139,7 @@ namespace BizHawk.MultiClient
{
Global.Config.DefaultAuthor = AuthorBox.Text;
}
this.Close();
Close();
}
else
{
@ -158,17 +150,19 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void button1_Click(object sender, EventArgs e)
{
string filename = "";
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath);
sfd.DefaultExt = "." + Global.Config.MovieExtension;
sfd.FileName = RecordBox.Text;
sfd.OverwritePrompt = false;
SaveFileDialog sfd = new SaveFileDialog
{
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.MoviesPath),
DefaultExt = "." + Global.Config.MovieExtension,
FileName = RecordBox.Text,
OverwritePrompt = false
};
string filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
sfd.Filter = filter;
@ -199,7 +193,7 @@ namespace BizHawk.MultiClient
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)

View File

@ -1,18 +1,10 @@
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 BizHawk.Emulation.Consoles.Sega;
namespace BizHawk.MultiClient
{
public partial class SMSGraphicsConfig : Form
{
SMS sms;
public SMSGraphicsConfig()
{
@ -21,7 +13,6 @@ namespace BizHawk.MultiClient
private void SMSGraphicsConfig_Load(object sender, EventArgs e)
{
sms = Global.Emulator as SMS;
DispOBJ.Checked = Global.Config.SMSDispOBJ;
DispBG.Checked = Global.Config.SMSDispBG;
}
@ -31,7 +22,7 @@ namespace BizHawk.MultiClient
Global.Config.SMSDispOBJ = DispOBJ.Checked;
Global.Config.SMSDispBG = DispBG.Checked;
this.Close();
Close();
}
}
}

View File

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

View File

@ -1,12 +1,5 @@
using System;
using System.Drawing;
using System.Drawing;
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;
namespace BizHawk.MultiClient
@ -17,7 +10,7 @@ namespace BizHawk.MultiClient
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
if(!DesignMode)
this.BackColor = Color.Transparent;
BackColor = Color.Transparent;
}
protected override void OnPaint(PaintEventArgs e)

View File

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

View File

@ -1,10 +1,5 @@
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 BizHawk.Emulation.Consoles.Calculator;
@ -95,19 +90,19 @@ namespace BizHawk.MultiClient
public void Restart()
{
if (!(Global.Emulator is TI83))
this.Close();
if (!this.IsHandleCreated || this.IsDisposed) return;
Close();
if (!IsHandleCreated || IsDisposed) return;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void SaveConfigSettings()
{
Global.Config.TI83KeyPadWndx = this.Location.X;
Global.Config.TI83KeyPadWndy = this.Location.Y;
Global.Config.TI83KeyPadWndx = Location.X;
Global.Config.TI83KeyPadWndy = Location.Y;
}
private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e)
@ -369,10 +364,15 @@ namespace BizHawk.MultiClient
private void showHotkToolStripMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TI83ToolTips ^= true;
if (Global.Config.TI83ToolTips == true)
if (Global.Config.TI83ToolTips)
{
SetToolTips();
}
else
{
StopToolTips();
}
}
private void ZERO_Click(object sender, EventArgs e)

View File

@ -1,10 +1,4 @@
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;
namespace BizHawk.MultiClient
@ -39,7 +33,7 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
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++)
{
DataGridViewCell c = CommentGrid.Rows[x].Cells[0];
selectedMovie.Header.Comments.Add("comment " + c.Value.ToString());
selectedMovie.Header.Comments.Add("comment " + c.Value);
}
selectedMovie.WriteMovie();
}
this.Close();
Close();
}
public void GetMovie(Movie m)

View File

@ -1,10 +1,5 @@
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.Globalization;
@ -35,21 +30,21 @@ namespace BizHawk.MultiClient
{
int x = Height + ((SubGrid.Rows.Count - 8) * 21);
if (x < 600)
this.Height = x;
Height = x;
else
this.Height = 600;
Height = 600;
}
}
private void Cancel_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void ShowError(int row, int 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();
MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
@ -85,16 +80,16 @@ namespace BizHawk.MultiClient
}
selectedMovie.WriteMovie();
}
this.Close();
Close();
}
public void GetMovie(Movie m)
{
selectedMovie = 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);
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.
@ -67,8 +67,10 @@ namespace BizHawk.MultiClient
public bool IsPressed(string button)
{
if (Global.Config.AllowUD_LR == true)
if (Global.Config.AllowUD_LR)
{
return Source.IsPressed(button);
}
string prefix;
@ -76,13 +78,17 @@ namespace BizHawk.MultiClient
{
prefix = button.GetPrecedingString("Down");
if (Source.IsPressed(prefix + "Up"))
{
return false;
}
}
if (button.Contains("Right"))
{
prefix = button.GetPrecedingString("Right");
if (Source.IsPressed(prefix + "Left"))
{
return false;
}
}
return Source.IsPressed(button);
@ -150,7 +156,6 @@ namespace BizHawk.MultiClient
{
get
{
bool source = Source[button];
if (stickySet.Contains(button))
{
return false;
@ -249,7 +254,7 @@ namespace BizHawk.MultiClient
public int Off { get; set; }
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;
@ -508,13 +513,6 @@ namespace BizHawk.MultiClient
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('|');
@ -683,7 +681,8 @@ namespace BizHawk.MultiClient
public class CopyControllerAdapter : IController
{
public IController Source;
NullController _null = new NullController();
private readonly NullController _null = new NullController();
IController Curr
{
@ -713,13 +712,15 @@ namespace BizHawk.MultiClient
string[] parts = button.Split(' ');
if (parts.Length < 2) return null;
if (parts[0][0] != 'P') return null;
int player = 0;
int player;
if (!int.TryParse(parts[0].Substring(1), out player))
{
return null;
var bnp = new ButtonNameParser();
bnp.PlayerNum = player;
bnp.ButtonPart = button.Substring(parts[0].Length + 1);
return bnp;
}
else
{
return new ButtonNameParser { PlayerNum = player, ButtonPart = button.Substring(parts[0].Length + 1) };
}
}
public int PlayerNum;
@ -741,7 +742,7 @@ namespace BizHawk.MultiClient
public int PlayerTargetMask = 0;
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 void UpdateControls(int frame) { Source.UpdateControls(frame); }
@ -766,11 +767,6 @@ namespace BizHawk.MultiClient
public class MovieControllerAdapter : IController
{
public MovieControllerAdapter()
{
//OutputController = new ForceControllerAdapter();
}
//IController implementation:
public ControllerDefinition Type { get; set; }
public bool this[string button] { get { return MyBoolButtons[button]; } }
@ -779,7 +775,7 @@ namespace BizHawk.MultiClient
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)
{
@ -790,11 +786,13 @@ namespace BizHawk.MultiClient
class MnemonicChecker
{
private readonly string m;
public MnemonicChecker(string _m)
{
m = _m;
}
string m;
public bool this[int c]
{
get { return m[c] != '.'; }

View File

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization;
@ -16,9 +12,8 @@ namespace BizHawk.MultiClient
public Movie(string filename)
{
Mode = MOVIEMODE.INACTIVE;
lastlog = 0;
Rerecords = 0;
this.Filename = filename;
Filename = filename;
IsText = true;
preload_framecount = 0;
IsCountingRerecords = true;
@ -134,7 +129,7 @@ namespace BizHawk.MultiClient
set
{
startsfromsavestate = value;
if (value == true)
if (value)
{
Header.AddHeaderLine(MovieHeader.STARTSFROMSAVESTATE, "1");
}
@ -312,7 +307,9 @@ namespace BizHawk.MultiClient
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)
{
WriteText(stream);
@ -329,7 +326,9 @@ namespace BizHawk.MultiClient
{
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)
{
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 = 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);
if (IsText)
@ -402,27 +402,37 @@ namespace BizHawk.MultiClient
using (StreamReader sr = file.OpenText())
{
string str = "";
string str;
while ((str = sr.ReadLine()) != null)
{
if (str == "" || Header.AddHeaderFromLine(str))
{
continue;
}
if (str.StartsWith("subtitle") || str.StartsWith("sub"))
{
Subtitles.AddSubtitle(str);
}
else if (str[0] == '|')
{
string frames = sr.ReadToEnd();
int length = str.Length;
// Account for line breaks of either size.
if (frames.IndexOf("\r\n") != -1)
{
length++;
}
length++;
// Count the remaining frames and the current one.
this.preload_framecount = (frames.Length / length) + 1;
preload_framecount = (frames.Length/length) + 1;
break;
}
else
{
Header.Comments.Add(str);
}
}
sr.Close();
}
@ -448,8 +458,6 @@ namespace BizHawk.MultiClient
public string GetInput(int frame)
{
lastlog = frame;
int getframe;
if (Loop)
@ -553,7 +561,7 @@ namespace BizHawk.MultiClient
public void CaptureState()
{
if (StateCapturing == true)
if (StateCapturing)
{
byte[] state = Global.Emulator.SaveStateBinary();
Log.AddState(state);
@ -572,7 +580,7 @@ namespace BizHawk.MultiClient
if (frame <= Log.StateFirstIndex)
{
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();
}
@ -785,22 +793,25 @@ namespace BizHawk.MultiClient
var reader = new StreamReader(path);
MovieLog l = new MovieLog();
string line;
string GUID;
int stateFrame = 0;
while (true)
{
line = reader.ReadLine();
string line = reader.ReadLine();
if (line == null)
{
return false;
if (line.Trim() == "") continue;
}
else if (line.Trim() == "")
{
continue;
}
else if (line.Contains("GUID"))
{
GUID = ParseHeader(line, MovieHeader.GUID);
if (Header.GetHeaderLine(MovieHeader.GUID) != GUID)
string guid = ParseHeader(line, MovieHeader.GUID);
if (Header.GetHeaderLine(MovieHeader.GUID) != guid)
{
//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",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
@ -901,15 +912,14 @@ namespace BizHawk.MultiClient
#region Private Fields
private MovieLog Log = new MovieLog();
private readonly MovieLog Log = new MovieLog();
private enum MOVIEMODE { INACTIVE, PLAY, RECORD, FINISHED };
private MOVIEMODE Mode = MOVIEMODE.INACTIVE;
private bool statecapturing;
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 lastlog;
private int rerecords;
private bool changes = false;
private bool changes;
#endregion
#region Helpers
@ -929,8 +939,6 @@ namespace BizHawk.MultiClient
private void WriteText(Stream stream)
{
int length = Log.Length;
using (StreamWriter sw = new StreamWriter(stream))
{
Header.WriteText(sw);
@ -967,8 +975,7 @@ namespace BizHawk.MultiClient
using (StreamReader sr = file.OpenText())
{
string str = "";
string rerecordStr = "";
string str;
while ((str = sr.ReadLine()) != null)
{
@ -979,7 +986,7 @@ namespace BizHawk.MultiClient
if (str.Contains(MovieHeader.RERECORDS))
{
rerecordStr = ParseHeader(str, MovieHeader.RERECORDS);
string rerecordStr = ParseHeader(str, MovieHeader.RERECORDS);
try
{
Rerecords = int.Parse(rerecordStr);
@ -1036,23 +1043,22 @@ namespace BizHawk.MultiClient
return true;
}
private string MakeDigits(decimal num)
{
return MakeDigits((int)num);
}
private string MakeDigits(int num)
{
if (num < 10)
{
return "0" + num.ToString();
}
else
{
return num.ToString();
}
}
private double GetSeconds(int frameCount)
{
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_PAL = (double)21281370 / (4 * 341 * 312);
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 GB = 262144.0 / 4389.0;
const double A26 = 59.9227510135505;
double seconds = 0;
double frames = (double)frameCount;
double frames = frameCount;
if (frames < 1)
return seconds;
{
return 0;
}
bool pal = false;
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)
{
string str;
int x = line.LastIndexOf(headerName) + headerName.Length;
str = line.Substring(x + 1, line.Length - x - 1);
return str;
return line.Substring(x + 1, line.Length - x - 1);
}
#endregion
@ -1216,15 +1211,22 @@ namespace BizHawk.MultiClient
private int CompareFileName(Movie Other)
{
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)
{
string otherSysID = Other.SysID;
string thisSysID = this.SysID;
string thisSysID = SysID;
if (thisSysID == null && otherSysID == null)
return 0;
@ -1239,7 +1241,7 @@ namespace BizHawk.MultiClient
private int CompareGameName(Movie Other)
{
string otherGameName = Other.GameName;
string thisGameName = this.GameName;
string thisGameName = GameName;
if (thisGameName == null && otherGameName == null)
return 0;
@ -1254,7 +1256,7 @@ namespace BizHawk.MultiClient
private int CompareLength(Movie Other)
{
int otherLength = Other.preload_framecount;
int thisLength = this.preload_framecount;
int thisLength = preload_framecount;
if (thisLength < otherLength)
{

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.IO;
namespace BizHawk.MultiClient
@ -71,7 +68,7 @@ namespace BizHawk.MultiClient
/// <param name="value"></param>
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?
HeaderParams.Add(key, value);
@ -94,7 +91,7 @@ namespace BizHawk.MultiClient
public string GetHeaderLine(string key)
{
string value = "";
string value;
HeaderParams.TryGetValue(key, out value);
return value;
}
@ -111,17 +108,16 @@ namespace BizHawk.MultiClient
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)
{
string str;
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;
}
@ -134,75 +130,75 @@ namespace BizHawk.MultiClient
public bool AddHeaderFromLine(string line)
{
if (line.Length == 0) return false;
else if (line.Contains(MovieHeader.EMULATIONVERSION))
else if (line.Contains(EMULATIONVERSION))
{
line = ParseHeader(line, MovieHeader.EMULATIONVERSION);
AddHeaderLine(MovieHeader.EMULATIONVERSION, line);
line = ParseHeader(line, EMULATIONVERSION);
AddHeaderLine(EMULATIONVERSION, line);
}
else if (line.Contains(MovieHeader.MOVIEVERSION))
else if (line.Contains(MOVIEVERSION))
{
line = ParseHeader(line, MovieHeader.MOVIEVERSION);
AddHeaderLine(MovieHeader.MOVIEVERSION, line);
line = ParseHeader(line, MOVIEVERSION);
AddHeaderLine(MOVIEVERSION, line);
}
else if (line.Contains(MovieHeader.PLATFORM))
else if (line.Contains(PLATFORM))
{
line = ParseHeader(line, MovieHeader.PLATFORM);
AddHeaderLine(MovieHeader.PLATFORM, line);
line = ParseHeader(line, PLATFORM);
AddHeaderLine(PLATFORM, line);
}
else if (line.Contains(MovieHeader.GAMENAME))
else if (line.Contains(GAMENAME))
{
line = ParseHeader(line, MovieHeader.GAMENAME);
AddHeaderLine(MovieHeader.GAMENAME, line);
line = ParseHeader(line, GAMENAME);
AddHeaderLine(GAMENAME, line);
}
else if (line.Contains(MovieHeader.RERECORDS))
else if (line.Contains(RERECORDS))
{
line = ParseHeader(line, MovieHeader.RERECORDS);
AddHeaderLine(MovieHeader.RERECORDS, line);
line = ParseHeader(line, RERECORDS);
AddHeaderLine(RERECORDS, line);
}
else if (line.Contains(MovieHeader.AUTHOR))
else if (line.Contains(AUTHOR))
{
line = ParseHeader(line, MovieHeader.AUTHOR);
AddHeaderLine(MovieHeader.AUTHOR, line);
line = ParseHeader(line, AUTHOR);
AddHeaderLine(AUTHOR, line);
}
else if (line.ToUpper().Contains(MovieHeader.GUID))
else if (line.ToUpper().Contains(GUID))
{
line = ParseHeader(line, MovieHeader.GUID);
AddHeaderLine(MovieHeader.GUID, line);
line = ParseHeader(line, GUID);
AddHeaderLine(GUID, line);
}
else if (line.Contains(MovieHeader.STARTSFROMSAVESTATE))
else if (line.Contains(STARTSFROMSAVESTATE))
{
line = ParseHeader(line, MovieHeader.STARTSFROMSAVESTATE);
AddHeaderLine(MovieHeader.STARTSFROMSAVESTATE, line);
line = ParseHeader(line, STARTSFROMSAVESTATE);
AddHeaderLine(STARTSFROMSAVESTATE, line);
}
else if (line.Contains(MovieHeader.SHA1))
else if (line.Contains(SHA1))
{
line = ParseHeader(line, MovieHeader.SHA1);
AddHeaderLine(MovieHeader.SHA1, line);
line = ParseHeader(line, SHA1);
AddHeaderLine(SHA1, line);
}
else if (line.Contains(MovieHeader.SKIPBIOS))
else if (line.Contains(SKIPBIOS))
{
line = ParseHeader(line, MovieHeader.SKIPBIOS);
AddHeaderLine(MovieHeader.SKIPBIOS, line);
line = ParseHeader(line, SKIPBIOS);
AddHeaderLine(SKIPBIOS, line);
}
else if (line.Contains(MovieHeader.GB_FORCEDMG))
else if (line.Contains(GB_FORCEDMG))
{
line = ParseHeader(line, MovieHeader.GB_FORCEDMG);
AddHeaderLine(MovieHeader.GB_FORCEDMG, line);
line = ParseHeader(line, GB_FORCEDMG);
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);
AddHeaderLine(MovieHeader.GB_GBA_IN_CGB, line);
line = ParseHeader(line, GB_GBA_IN_CGB);
AddHeaderLine(GB_GBA_IN_CGB, line);
}
else if (line.Contains(MovieHeader.SGB))
else if (line.Contains(SGB))
{
line = ParseHeader(line, MovieHeader.SGB);
AddHeaderLine(MovieHeader.SGB, line);
line = ParseHeader(line, SGB);
AddHeaderLine(SGB, line);
}
else if (line.Contains(MovieHeader.PAL))
else if (line.Contains(PAL))
{
line = ParseHeader(line, MovieHeader.PAL);
AddHeaderLine(MovieHeader.PAL, line);
line = ParseHeader(line, PAL);
AddHeaderLine(PAL, line);
}
else if (line.StartsWith("subtitle") || line.StartsWith("sub"))
{
@ -226,7 +222,7 @@ namespace BizHawk.MultiClient
{
using (reader)
{
string str = "";
string str;
while ((str = reader.ReadLine()) != null)
{
AddHeaderFromLine(str);

View File

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -37,9 +36,11 @@ namespace BizHawk.MultiClient
Movie m = new Movie();
errorMsg = "";
warningMsg = "";
string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
try
{
switch (Path.GetExtension(path).ToUpper())
switch (ext)
{
case ".FCM":
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.
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"
};
foreach (string ext in extensions)
{
if (extension.ToUpper() == "." + ext)
{
return true;
}
}
return false;
return extensions.Any(ext => extension.ToUpper() == "." + ext);
}
// Reduce all whitespace to single spaces.
@ -132,35 +127,34 @@ namespace BizHawk.MultiClient
{
string[] buttons = new string[] { };
string controller = "";
switch (Path.GetExtension(path).ToUpper())
string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
switch (ext)
{
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";
break;
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";
break;
case ".LSMV":
buttons = new string[12] {
buttons = new[] {
"B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R"
};
controller = "SNES Controller";
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";
}
break;
}
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = controller;
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = controller}};
MnemonicsGenerator mg = new MnemonicsGenerator();
// Split up the sections of the frame.
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');
// 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];
char[] off = { '.', ' ', '\t', '\n', '\r' };
@ -223,7 +217,7 @@ namespace BizHawk.MultiClient
int start = 2;
int end = sections.Length - 1;
int player_offset = -1;
if (Path.GetExtension(path).ToUpper() == ".LSMV")
if (ext == ".LSMV")
{
// LSNES frames don't start or end with a |.
start--;
@ -270,9 +264,10 @@ namespace BizHawk.MultiClient
{
// Concatenate the frame and message with default values for the additional fields.
string frame;
string message;
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);
length = "200";
@ -282,7 +277,7 @@ namespace BizHawk.MultiClient
frame = line.Substring(0, first);
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);
}
return m;
@ -311,7 +306,7 @@ namespace BizHawk.MultiClient
}
m.Header.SetHeaderLine(MovieHeader.PLATFORM, platform);
int lineNum = 0;
string line = "";
string line;
while ((line = sr.ReadLine()) != null)
{
lineNum++;
@ -361,7 +356,7 @@ namespace BizHawk.MultiClient
byte[] md5 = DecodeBlob(blob);
if (md5 != null && md5.Length == 16)
{
m.Header.SetHeaderLine(MD5, BizHawk.Util.BytesToHexString(md5).ToLower());
m.Header.SetHeaderLine(MD5, Util.BytesToHexString(md5).ToLower());
}
else
{
@ -421,12 +416,11 @@ namespace BizHawk.MultiClient
// Get the content for a particular header.
private static string ParseHeader(string line, string headerName)
{
string str;
// Case-insensitive search.
int x = line.ToLower().LastIndexOf(
headerName.ToLower()
) + headerName.Length;
str = line.Substring(x + 1, line.Length - x - 1);
string str = line.Substring(x + 1, line.Length - x - 1);
return str.Trim();
}
@ -440,7 +434,7 @@ namespace BizHawk.MultiClient
if (blob[0] == '0' && (blob[1] == 'x' || blob[1] == 'X'))
{
// hex
return BizHawk.Util.HexStringToBytes(blob.Substring(2));
return Util.HexStringToBytes(blob.Substring(2));
}
else
{
@ -537,8 +531,6 @@ namespace BizHawk.MultiClient
// 010 4-byte little-endian unsigned int: rerecord count
uint rerecordCount = r.ReadUInt32();
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
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();
// 020 16-byte md5sum of the ROM used
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
uint emuVersion = r.ReadUInt32();
m.Header.Comments.Add(EMULATIONORIGIN + " FCEU " + emuVersion.ToString());
@ -576,11 +568,9 @@ namespace BizHawk.MultiClient
m.Header.SetHeaderLine(MovieHeader.AUTHOR, author);
// Advance to first byte of input data.
r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
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 fourscore = false;
int frame = 1;
@ -728,10 +718,7 @@ namespace BizHawk.MultiClient
// FM2 file format: http://www.fceux.com/web/FM2.html
private static Movie ImportFM2(string path, out string errorMsg, out string warningMsg)
{
errorMsg = "";
warningMsg = "";
Movie m = ImportText(path, out errorMsg, out warningMsg);
return m;
return ImportText(path, out errorMsg, out warningMsg);
}
// FMV file format: http://tasvideos.org/FMV.html
@ -813,9 +800,7 @@ namespace BizHawk.MultiClient
*/
m.Header.SetHeaderLine(MovieHeader.PAL, "False");
// 090 frame data begins here
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
/*
* 01 Right
@ -827,8 +812,8 @@ namespace BizHawk.MultiClient
* 40 Select
* 80 Start
*/
string[] buttons = new string[8] { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" };
bool[] masks = new bool[3] { controller1, controller2, FDS };
string[] buttons = new[] { "Right", "Left", "Up", "Down", "B", "A", "Select", "Start" };
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
<number of bytes per frame>.
@ -933,9 +918,10 @@ namespace BizHawk.MultiClient
// 018 40-byte zero-terminated ASCII movie name string
string description = NullTerminated(r.ReadStringFixedAscii(40));
m.Header.Comments.Add(COMMENT + " " + description);
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "Genesis 3-Button Controller";
SimpleController controllers = new SimpleController
{
Type = new ControllerDefinition {Name = "Genesis 3-Button Controller"}
};
MnemonicsGenerator mg = new MnemonicsGenerator();
/*
040 frame data
@ -1261,7 +1247,7 @@ namespace BizHawk.MultiClient
byte[] md5 = r.ReadBytes(16);
// Discard the second 16 bytes.
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)
string gameName = NullTerminated(r.ReadStringFixedAscii(64));
m.Header.SetHeaderLine(MovieHeader.GAMENAME, gameName);
@ -1270,8 +1256,8 @@ namespace BizHawk.MultiClient
m.Rerecords = (int)rerecordCount;
// 074 5-byte Console indicator (pce, ngp, pcfx, wswan)
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
@ -1281,14 +1267,14 @@ namespace BizHawk.MultiClient
"nes", new Dictionary<string, object>
{
{"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>
{
{"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);
// TODO: Verify if NTSC/"PAL" mode used for the movie can be detected or not.
// 100 variable Input data
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = name + " Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = name + " Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
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.
@ -1357,10 +1341,7 @@ namespace BizHawk.MultiClient
// MC2 file format: http://code.google.com/p/pcejin/wiki/MC2
private static Movie ImportMC2(string path, out string errorMsg, out string warningMsg)
{
errorMsg = "";
warningMsg = "";
Movie m = ImportText(path, out errorMsg, out warningMsg);
return m;
return ImportText(path, out errorMsg, out warningMsg);
}
// MMV file format: http://tasvideos.org/MMV.html
@ -1435,10 +1416,8 @@ namespace BizHawk.MultiClient
m.Header.SetHeaderLine(MovieHeader.GAMENAME, gameName);
// 00e4-00f3: binary: rom MD5 digest
byte[] md5 = r.ReadBytes(16);
m.Header.SetHeaderLine(MD5, String.Format("{0:x8}", BizHawk.Util.BytesToHexString(md5).ToLower()));
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SMS Controller";
m.Header.SetHeaderLine(MD5, String.Format("{0:x8}", Util.BytesToHexString(md5).ToLower()));
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SMS Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
/*
76543210
@ -1451,7 +1430,7 @@ namespace BizHawk.MultiClient
* bit 6 (0x40): start (Master System)
* 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++)
{
/*
@ -1551,7 +1530,7 @@ namespace BizHawk.MultiClient
*/
bool fourscore = (controller1 == 5);
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)
{
/*
@ -1567,7 +1546,7 @@ namespace BizHawk.MultiClient
}
else
{
byte[] types = new byte[2] { controller1, controller2 };
byte[] types = new[] { controller1, controller2 };
for (int controller = 1; controller <= types.Length; controller++)
{
masks[controller - 1] = (types[controller - 1] == 1);
@ -1617,7 +1596,7 @@ namespace BizHawk.MultiClient
* 5 - Family Trainer (2 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",
"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
uint length = r.ReadUInt32();
// ... (variable) controller data
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
/*
Standard controllers store data in the following format:
@ -1682,7 +1659,7 @@ namespace BizHawk.MultiClient
* 80: Right
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.
long frameCount = length / bytesPerFrame;
for (int frame = 1; frame <= frameCount; frame++)
@ -1774,9 +1751,7 @@ namespace BizHawk.MultiClient
* bit 4: controller 5 in use
* other: reserved, set to 0
*/
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SNES Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SNES Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
bool[] controllersUsed = new bool[5];
for (int controller = 1; controller <= controllersUsed.Length; controller++)
@ -1890,9 +1865,11 @@ namespace BizHawk.MultiClient
00 40 Y
00 80 B
*/
string[] buttons = new string[12] {
string[] buttons = new[]
{
"Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A"
};
for (int frame = 0; frame <= frameCount; frame++)
{
controllers["Reset"] = true;
@ -2084,14 +2061,16 @@ namespace BizHawk.MultiClient
// bit 2: if "1", movie is for the SGB system
bool is_sgb = (((flags >> 2) & 0x1) != 0);
// other: reserved, set to 0
// (At most one of bits 0, 1, 2 can be "1")
if (!(is_gba ^ is_gbc ^ is_sgb) && (is_gba || is_gbc || is_sgb))
{
errorMsg = "This is not a valid .VBM file.";
r.Close();
fs.Close();
return null;
}
//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.";
//r.Close();
//fs.Close();
//return null;
//}
// (If all 3 of these bits are "0", it is for regular GB.)
string platform = "GB";
if (is_gba)
@ -2181,8 +2160,7 @@ namespace BizHawk.MultiClient
string movieDescription = NullTerminated(r.ReadStringFixedAscii(128));
m.Header.Comments.Add(COMMENT + " " + movieDescription);
r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
SimpleController controllers = new SimpleController {Type = new ControllerDefinition()};
if (platform == "GBA")
{
controllers.Type.Name = "Gameboy Controller";
@ -2202,7 +2180,7 @@ namespace BizHawk.MultiClient
* 40 00 Up
* 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 02 L
@ -2213,7 +2191,7 @@ namespace BizHawk.MultiClient
* 00 40 Down 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",
"Right motion sensor", "Down motion sensor", "Up motion sensor"
};
@ -2362,9 +2340,7 @@ namespace BizHawk.MultiClient
return m;
}
r.BaseStream.Position = firstFrameOffset;
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "NES Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "NES Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
/*
* 01 A
@ -2376,7 +2352,7 @@ namespace BizHawk.MultiClient
* 40 Left
* 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++)
{
/*
@ -2559,7 +2535,6 @@ namespace BizHawk.MultiClient
{
peripheral = "First Mouse";
}
controllerFlags >>= 1;
if (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);
// Next follows a ZST format savestate.
r.ReadBytes((int)savestateSize);
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SNES Controller";
SimpleController controllers = new SimpleController {Type = new ControllerDefinition {Name = "SNES Controller"}};
MnemonicsGenerator mg = new MnemonicsGenerator();
/*
* bit 11: A
@ -2617,7 +2590,8 @@ namespace BizHawk.MultiClient
* bit 1: Left
* bit 0: Right
*/
string[] buttons = new string[12] {
string[] buttons = new[]
{
"Right", "Left", "Down", "Up", "Start", "Select", "Y", "B", "R", "L", "X", "A"
};
int frames = 1;

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.IO;
namespace BizHawk.MultiClient
@ -19,7 +16,7 @@ namespace BizHawk.MultiClient
{
get
{
return StateRecords.Count;
return _state_records.Count;
}
}
@ -27,7 +24,7 @@ namespace BizHawk.MultiClient
{
get
{
return MovieRecords.Count;
return _movie_records.Count;
}
}
@ -35,7 +32,7 @@ namespace BizHawk.MultiClient
{
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
{
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
{
if (StateRecords.Count > 0)
if (_state_records.Count > 0)
{
return StateCount * StateRecords[0].State.Length;
return StateCount * _state_records[0].State.Length;
}
else
{
@ -68,18 +65,18 @@ namespace BizHawk.MultiClient
public void Clear()
{
MovieRecords.Clear();
StateRecords.Clear();
_movie_records.Clear();
_state_records.Clear();
}
public void ClearStates()
{
StateRecords.Clear();
_state_records.Clear();
}
public void AppendFrame(string frame)
{
MovieRecords.Add(frame);
_movie_records.Add(frame);
}
public void AddState(byte[] state)
@ -90,17 +87,17 @@ namespace BizHawk.MultiClient
}
if (Global.Emulator.Frame < StateFirstIndex)
{
StateRecords.Clear();
StateRecords.Add(new StateRecord(Global.Emulator.Frame, state));
_state_records.Clear();
_state_records.Add(new StateRecord(Global.Emulator.Frame, state));
}
if (Global.Emulator.Frame > StateLastIndex)
{
if (StateSizeInBytes + state.Length > MaxStateRecordSize)
if (StateSizeInBytes + state.Length > MAXSTATERECORDSIZE)
{
// 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);
}
if (MovieRecords.Count > frameNum)
if (_movie_records.Count > frameNum)
{
MovieRecords[frameNum] = frame;
_movie_records[frameNum] = frame;
}
else
{
MovieRecords.Add(frame);
_movie_records.Add(frame);
}
}
public void AddFrameAt(int frame, string record)
{
MovieRecords.Insert(frame, record);
_movie_records.Insert(frame, record);
if (frame <= StateLastIndex)
{
if (frame <= StateFirstIndex)
{
StateRecords.Clear();
_state_records.Clear();
Global.MovieSession.Movie.RewindToFrame(0);
}
else
{
StateRecords.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
_state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
Global.MovieSession.Movie.RewindToFrame(frame);
}
}
@ -142,21 +139,21 @@ namespace BizHawk.MultiClient
public byte[] GetState(int frame)
{
return StateRecords[frame - StateFirstIndex].State;
return _state_records[frame - StateFirstIndex].State;
}
public void DeleteFrame(int frame)
{
MovieRecords.RemoveAt(frame);
_movie_records.RemoveAt(frame);
if (frame <= StateLastIndex)
{
if (frame <= StateFirstIndex)
{
StateRecords.Clear();
_state_records.Clear();
}
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)
{
StateRecords.Clear();
_state_records.Clear();
}
else if (frame <= StateLastIndex)
{
StateRecords.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
_state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
}
}
}
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
{
@ -190,7 +187,7 @@ namespace BizHawk.MultiClient
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));
}
@ -198,20 +195,20 @@ namespace BizHawk.MultiClient
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);
}
}
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
{
@ -237,16 +234,16 @@ namespace BizHawk.MultiClient
Lagged = Global.Emulator.IsLagFrame;
}
public int Index;
public byte[] State;
public bool Lagged;
public readonly int Index;
public readonly byte[] State;
public readonly bool Lagged;
}
private List<string> MovieRecords = new List<string>();
private List<StateRecord> StateRecords = new List<StateRecord>();
private readonly List<string> _movie_records = new List<string>();
private readonly List<StateRecord> _state_records = new List<StateRecord>();
//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
}

View File

@ -1,20 +1,5 @@
using System;
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
namespace BizHawk.MultiClient
{
public class MovieSession
{
public MultitrackRecording MultiTrack = new MultitrackRecording();

View File

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

View File

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

View File

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

View File

@ -1,10 +1,5 @@
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;
namespace BizHawk.MultiClient
@ -25,7 +20,7 @@ namespace BizHawk.MultiClient
private void Cancel_Click(object sender, EventArgs e)
{
this.Close();
Close();
}
private void OK_Click(object sender, EventArgs e)
@ -35,8 +30,8 @@ namespace BizHawk.MultiClient
sub.X = (int)XNumeric.Value;
sub.Duration = (int)DurationNumeric.Value;
sub.Color = (uint)colorDialog1.Color.ToArgb();
this.DialogResult = DialogResult.OK;
this.Close();
DialogResult = DialogResult.OK;
Close();
}
private void SubtitleMaker_Load(object sender, EventArgs e)
@ -54,7 +49,9 @@ namespace BizHawk.MultiClient
private void ColorPanel_DoubleClick(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
ColorPanel.BackColor = colorDialog1.Color;
}
}
}
}