-Refactored NES and PCE button orders.

-Realized that FixMnemonic is useless as GetControllersAsMnemonic() + WriteMovie() = Fixed.
-Finished the NES / PCE importers, now without string builders (Thanks zeromus)!
-Converted ImportMMV to this same method.

TODO:
-Decide how's the best way to handle the mnemonic header and implement it. Apparently, anything other than a predefined header and a | is considered as a comment, so I might do something like:

comment Mnemonic format:
[0|UDLRsSBA]
This commit is contained in:
brandman211 2012-02-19 07:09:24 +00:00
parent 5534bbd8b5
commit 79d12b9181
4 changed files with 79 additions and 77 deletions

View File

@ -122,7 +122,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
int gg_check, gg_replace;
NESWatch[] watches;
}
@ -186,7 +185,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
}
}
MyVideoProvider videoProvider;
public IVideoProvider VideoProvider { get { return videoProvider; } }
public ISoundProvider SoundProvider { get { return apu; } }
@ -194,9 +192,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public static readonly ControllerDefinition NESController =
new ControllerDefinition
{
Name = "NES Controls",
BoolButtons = { "P1 A","P1 B","P1 Select","P1 Start","P1 Left","P1 Up","P1 Down","P1 Right", "Reset",
"P2 A", "P2 B", "P2 Select", "P2 Start", "P2 Up", "P2 Down", "P2 Left", "P2 Right"}
Name = "NES Controller",
BoolButtons = {
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Select", "P1 Start", "P1 B", "P1 A", "Reset",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Select", "P2 Start", "P2 B", "P2 A"
}
};
public ControllerDefinition ControllerDefinition { get { return NESController; } }
@ -208,7 +208,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
set { controller = value; }
}
interface IPortDevice
{
void Write(int value);
@ -230,9 +229,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo
void Strobe()
{
value = 0;
foreach (string str in new string[] { "P" + (player + 1).ToString() + " Right", "P" + (player + 1).ToString() + " Left",
"P" + (player + 1).ToString() + " Down", "P" + (player + 1).ToString() + " Up", "P" + (player + 1).ToString() + " Start",
"P" + (player + 1).ToString() + " Select", "P" + (player + 1).ToString() + " B", "P" + (player + 1).ToString() + " A" })
foreach (
string str in new string[] {
"P" + (player + 1).ToString() + " Right", "P" + (player + 1).ToString() + " Left",
"P" + (player + 1).ToString() + " Down", "P" + (player + 1).ToString() + " Up",
"P" + (player + 1).ToString() + " Start", "P" + (player + 1).ToString() + " Select",
"P" + (player + 1).ToString() + " B", "P" + (player + 1).ToString() + " A"
}
)
{
value <<= 1;
value |= nes.Controller.IsPressed(str) ? 1 : 0;
@ -271,7 +275,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
}
}
int _frame;
int _lagcount;
bool lagged = true;
@ -538,7 +541,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
LoadReport.Flush();
CoreOutputComm.RomStatusDetails = LoadReport.ToString();
//create the board's rom and vrom
board.ROM = new byte[choice.prg_size * 1024];
Array.Copy(file, 16, board.ROM, 0, board.ROM.Length);
@ -554,7 +556,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
if (cart.vram_size != 0)
board.VRAM = new byte[cart.vram_size * 1024];
HardReset();
SetupMemoryDomains();
}

View File

@ -8,11 +8,11 @@
Name = "PC Engine Controller",
BoolButtons =
{
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 B2", "P1 B1", "P1 Select", "P1 Run",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 B2", "P2 B1", "P2 Select", "P2 Run",
"P3 Up", "P3 Down", "P3 Left", "P3 Right", "P3 B2", "P3 B1", "P3 Select", "P3 Run",
"P4 Up", "P4 Down", "P4 Left", "P4 Right", "P4 B2", "P4 B1", "P4 Select", "P4 Run",
"P5 Up", "P5 Down", "P5 Left", "P5 Right", "P5 B2", "P5 B1", "P5 Select", "P5 Run"
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Select", "P1 Run", "P1 B2", "P1 B1",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Select", "P2 Run", "P2 B2", "P2 B1",
"P3 Up", "P3 Down", "P3 Left", "P3 Right", "P3 Select", "P3 Run", "P3 B2", "P3 B1",
"P4 Up", "P4 Down", "P4 Left", "P4 Right", "P4 Select", "P4 Run", "P4 B2", "P4 B1",
"P5 Up", "P5 Down", "P5 Left", "P5 Right", "P5 Select", "P5 Run", "P5 B2", "P5 B1"
}
};

View File

@ -123,7 +123,7 @@ namespace BizHawk.MultiClient
//this allows users to restore a movie with any savestate from that "timeline"
MnemonicsGenerator mg = new MnemonicsGenerator();
mg.SetSource(source);
Log.SetFrameAt(frameNum, mg.GetControllersAsMnemonic());
}
@ -217,8 +217,7 @@ namespace BizHawk.MultiClient
{
continue;
}
if (str.Contains(MovieHeader.RERECORDS))
{
rerecordStr = ParseHeader(str, MovieHeader.RERECORDS);
@ -288,9 +287,9 @@ namespace BizHawk.MultiClient
{
continue;
}
else if (Header.AddHeaderFromLine(str))
else if (Header.AddHeaderFromLine(str))
continue;
if (str.StartsWith("subtitle") || str.StartsWith("sub"))
{
Subtitles.AddSubtitle(str);
@ -329,17 +328,6 @@ namespace BizHawk.MultiClient
return LoadText();
}
public void FixMnemonic()
{
int frame = 0;
while (frame < Log.Length())
{
// TODO: Correct mnemonics, using Log.GetFrame(frame))?
break;
}
lastLog = frame;
}
public void DumpLogIntoSavestateText(TextWriter writer)
{
writer.WriteLine("[Input]");
@ -355,7 +343,7 @@ namespace BizHawk.MultiClient
{
var reader = new StreamReader(path);
int stateFrame = 0;
//We are in record mode so replace the movie log with the one from the savestate
//We are in record mode so replace the movie log with the one from the savestate
if (!Global.MovieSession.MultiTrack.IsActive)
{
if (Global.Config.EnableBackupMovies && MakeBackup && Log.Length() > 0)
@ -367,7 +355,6 @@ namespace BizHawk.MultiClient
int i = 0; //TODO: Debug remove me
while (true)
{
string line = reader.ReadLine();
if (line.Contains(".[NES")) //TODO: Remove debug
{
@ -573,7 +560,7 @@ namespace BizHawk.MultiClient
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);
@ -632,7 +619,6 @@ namespace BizHawk.MultiClient
return false; //For now throw an error if recording, ideally what should happen is that the state gets loaded, and the movie set to movie finished, the movie at its current state is preserved and the state is loaded just fine. This should probably also only happen if checktimelines passes
}
if (stateFrame == 0)
{
stateFrame = l.Length(); //In case the frame count failed to parse, revert to using the entire state input log

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -45,7 +46,6 @@ namespace BizHawk.MultiClient
mov = new Movie();
break;
}
mov.FixMnemonic();
mov.WriteMovie();
return mov;
}
@ -153,7 +153,40 @@ namespace BizHawk.MultiClient
}
else if (str[0] == '|')
{
m.AppendFrame(str);
ArrayList frame = new ArrayList();
// Split up the sections of the frame.
string[] sections = str.Split('|');
string[] buttons = {};
string console = "";
switch (emulator)
{
case "FCEUX":
buttons = new string[8] {"Right", "Left", "Down", "Up", "Start", "Select", "B", "A"};
console = "NES";
break;
case "Mednafen/PCEjin":
buttons = new string[8] {"Up", "Down", "Left", "Right", "B1", "B2", "Run", "Select"};
console = "PC Engine";
break;
}
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = console + " Controller";
for (int player = 2; player < sections.Length; player++)
{
if (sections[player].Length == buttons.Length)
{
for (int button = 0; button < buttons.Length; button++)
{
controllers["P" + (player - 1).ToString() + " " + buttons[button]] = (
sections[player][button] != '.'
);
}
}
}
MnemonicsGenerator mg = new MnemonicsGenerator();
mg.SetSource(controllers);
m.AppendFrame(mg.GetControllersAsMnemonic());
}
else
{
@ -183,7 +216,6 @@ namespace BizHawk.MultiClient
errorMsg = "This is not a valid FCM file!";
return null;
}
UInt32 version = r.ReadUInt32();
m.Header.SetHeaderLine(MovieHeader.MovieVersion, "FCEU movie version " + version.ToString() + " (.fcm)");
@ -410,40 +442,30 @@ namespace BizHawk.MultiClient
//TODO: format correctly
m.Header.SetHeaderLine("MD5", MD5);
for (int x = 0; x < (framecount); x++)
{
//TODO: use StringBuilder
string frame = "|";
char start;
byte tmp;
tmp = r.ReadByte();
if ((int)(tmp & 1) > 0) frame += "U"; else frame += ".";
if ((int)(tmp & 2) > 0) frame += "D"; else frame += ".";
if ((int)(tmp & 4) > 0) frame += "L"; else frame += ".";
if ((int)(tmp & 8) > 0) frame += "R"; else frame += ".";
if ((int)(tmp & 16) > 0) frame += "1"; else frame += ".";
if ((int)(tmp & 32) > 0) frame += "2|"; else frame += ".|";
if ((int)(tmp & 64) > 0 && (!gamegear)) start = 'P'; else start = '.';
if ((int)(tmp & 128) > 0 && gamegear) start = 'P'; else start = '.';
//Controller 2
tmp = r.ReadByte();
if ((int)(tmp & 1) > 0) frame += "U"; else frame += ".";
if ((int)(tmp & 2) > 0) frame += "D"; else frame += ".";
if ((int)(tmp & 4) > 0) frame += "L"; else frame += ".";
if ((int)(tmp & 8) > 0) frame += "R"; else frame += ".";
if ((int)(tmp & 16) > 0) frame += "1"; else frame += ".";
if ((int)(tmp & 32) > 0) frame += "2|"; else frame += ".|";
frame += start;
frame += ".|";
m.AppendFrame(frame);
SimpleController controllers = new SimpleController();
controllers.Type = new ControllerDefinition();
controllers.Type.Name = "SMS Controller";
for (int player = 1; player <= 2; player++)
{
tmp = r.ReadByte();
controllers["P" + player + " Up"] = ((int)(tmp & 1) > 0);
controllers["P" + player + " Down"] = ((int)(tmp & 2) > 0);
controllers["P" + player + " Left"] = ((int)(tmp & 4) > 0);
controllers["P" + player + " Right"] = ((int)(tmp & 8) > 0);
controllers["P" + player + " B1"] = ((int)(tmp & 16) > 0);
controllers["P" + player + " B2"] = ((int)(tmp & 32) > 0);
if (player == 1)
{
controllers["Pause"] = (((int)(tmp & 64) > 0 && (!gamegear)) || ((int)(tmp & 128) > 0 && gamegear));
}
}
MnemonicsGenerator mg = new MnemonicsGenerator();
mg.SetSource(controllers);
m.AppendFrame(mg.GetControllersAsMnemonic());
}
m.WriteMovie();
return m;
}
@ -520,7 +542,6 @@ namespace BizHawk.MultiClient
else
numControllers = 1;
byte MovieFlags = r.ReadByte();
if ((int)(MovieFlags & 1) == 0)
@ -549,8 +570,6 @@ namespace BizHawk.MultiClient
{
UInt16 fd = r.ReadUInt16();
}
}
return m;
@ -585,8 +604,6 @@ namespace BizHawk.MultiClient
m.Header.SetHeaderLine(MovieHeader.RERECORDS, m.Rerecords.ToString());
Byte moviestartflags = r.ReadByte();
bool startfromquicksave = false;
bool startfromsram = false;
@ -709,9 +726,7 @@ namespace BizHawk.MultiClient
if ((controllerstate & 0x0001) > 0) frame += "A"; else frame += ".";
frame += "|";
m.AppendFrame(frame);
}
m.WriteMovie();