NES: add UI support for datach barcode reader
This commit is contained in:
parent
bd9a47f780
commit
81fc95ab43
|
@ -749,6 +749,12 @@
|
|||
<Compile Include="tools\Lua\SyncTextBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="tools\NES\BarcodeEntry.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="tools\NES\BarcodeEntry.Designer.cs">
|
||||
<DependentUpon>BarcodeEntry.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="tools\NES\NameTableViewer.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
@ -1257,6 +1263,9 @@
|
|||
<EmbeddedResource Include="tools\Lua\LuaWinform.resx">
|
||||
<DependentUpon>LuaWinform.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="tools\NES\BarcodeEntry.resx">
|
||||
<DependentUpon>BarcodeEntry.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="tools\NES\NESDebugger.resx">
|
||||
<DependentUpon>NESDebugger.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1218,6 +1218,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
NesControllerSettingsMenuItem.Enabled = Global.Emulator is NES && !Global.MovieSession.Movie.IsActive;
|
||||
MovieSettingsMenuItem.Enabled = Global.Emulator is NES && !Global.MovieSession.Movie.IsActive;
|
||||
|
||||
barcodeReaderToolStripMenuItem.Enabled = BarcodeEntry.HasReader();
|
||||
}
|
||||
|
||||
private void FdsControlsMenuItem_DropDownOpened(object sender, EventArgs e)
|
||||
|
|
|
@ -3569,5 +3569,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
// TODO: it would be cool if clicking this toggled the state
|
||||
}
|
||||
|
||||
private void barcodeReaderToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
GlobalWin.Tools.Load<BarcodeEntry>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
partial class BarcodeEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textBox1.Location = new System.Drawing.Point(12, 52);
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(520, 20);
|
||||
this.textBox1.TabIndex = 0;
|
||||
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 36);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(176, 13);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "Enter the digits of the barcode here:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(12, 9);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(503, 13);
|
||||
this.label2.TabIndex = 2;
|
||||
this.label2.Text = "THIS IS AN EXPERIMENTAL FEATURE AND WILL DESYNC MOVIES. DO NOT USE WITH MOVIES.";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(12, 75);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(35, 13);
|
||||
this.label3.TabIndex = 3;
|
||||
this.label3.Text = "label3";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.button1.Location = new System.Drawing.Point(457, 78);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
||||
this.button1.TabIndex = 4;
|
||||
this.button1.Text = "Send!";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// BarcodeEntry
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(544, 113);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.textBox1);
|
||||
this.Name = "BarcodeEntry";
|
||||
this.Text = "BarcodeEntry";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Button button1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
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.Cores.Nintendo.NES;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public partial class BarcodeEntry : Form, IToolForm
|
||||
{
|
||||
private DatachBarcode reader;
|
||||
|
||||
public BarcodeEntry()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Restart();
|
||||
}
|
||||
|
||||
#region IToolForm
|
||||
|
||||
public void UpdateValues()
|
||||
{
|
||||
}
|
||||
|
||||
public void FastUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool HasReader()
|
||||
{
|
||||
return GetReader() != null;
|
||||
}
|
||||
|
||||
private static DatachBarcode GetReader()
|
||||
{
|
||||
var nes = Global.Emulator as NES;
|
||||
if (nes == null)
|
||||
return null;
|
||||
var board = nes.GetBoard() as BANDAI_FCG_1;
|
||||
if (board == null)
|
||||
return null;
|
||||
var reader = board.reader; // will be null for non-datach FCG-1 games
|
||||
return reader;
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
reader = GetReader();
|
||||
if (reader == null)
|
||||
Close();
|
||||
textBox1_TextChanged(null, null);
|
||||
}
|
||||
|
||||
public bool AskSaveChanges()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UpdateBefore
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
string why;
|
||||
if (!DatachBarcode.ValidString(textBox1.Text, out why))
|
||||
{
|
||||
label3.Text = "Invalid: " + why;
|
||||
label3.Visible = true;
|
||||
button1.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
label3.Visible = false;
|
||||
button1.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
reader.Transfer(textBox1.Text);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
bool irq_enabled;
|
||||
ushort irq_counter;
|
||||
SEEPROM eprom;
|
||||
DatachBarcode reader;
|
||||
public DatachBarcode reader;
|
||||
|
||||
public override void SyncState(Serializer ser)
|
||||
{
|
||||
|
|
|
@ -83,21 +83,43 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
{
|
||||
return data[stream_idx] != END;
|
||||
}
|
||||
public static bool IsDigtsSupported(int count)
|
||||
private static bool IsDigtsSupported(int count)
|
||||
{
|
||||
return count.In(MIN_DIGITS, MAX_DIGITS);
|
||||
}
|
||||
|
||||
public bool Transfer(string s, int len)
|
||||
public static bool ValidString(string s, out string why)
|
||||
{
|
||||
if (s == null)
|
||||
throw new ArgumentNullException("s");
|
||||
if (!IsDigtsSupported(len))
|
||||
if (!s.Length.In(MIN_DIGITS, MAX_DIGITS))
|
||||
{
|
||||
why = string.Format("String must be {0} or {1} digits long!", MIN_DIGITS, MAX_DIGITS);
|
||||
return false;
|
||||
}
|
||||
foreach (char c in s)
|
||||
{
|
||||
if (c < '0' || c > '9')
|
||||
{
|
||||
why = "String must be numeric only!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
why = "String is OK.";
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Transfer(string s)
|
||||
{
|
||||
string why;
|
||||
if (!ValidString(s, out why))
|
||||
throw new InvalidOperationException(why);
|
||||
|
||||
Reset();
|
||||
|
||||
byte[] code = new byte[16];
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
if (s[i] >= '0' && s[i] <= '9')
|
||||
code[i] = (byte)(s[i] - '0');
|
||||
|
@ -115,7 +137,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
|
||||
int sum = 0;
|
||||
|
||||
if (len == MAX_DIGITS)
|
||||
if (s.Length == MAX_DIGITS)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
|
@ -144,7 +166,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
for (int i = 0; i < 12; i++)
|
||||
sum += code[i] * ((i & 1) != 0 ? 3 : 1);
|
||||
}
|
||||
else // len == MIN_DIGITS
|
||||
else // s.Length == MIN_DIGITS
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int j = 0; j < 7; j++)
|
||||
|
@ -178,7 +200,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
|
||||
cycles = CC_INTERVAL;
|
||||
output = data[stream_idx]; // ??
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Clock()
|
||||
|
|
Loading…
Reference in New Issue