psx - improve behaviour of initial disc state at frame=0

This commit is contained in:
zeromus 2015-01-12 07:32:52 +00:00
parent 2a28f2b414
commit 9b5a5e69d4
4 changed files with 164 additions and 68 deletions

View File

@ -32,8 +32,10 @@
this.lvDiscs = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.btnInsert = new BizHawk.Client.EmuHawk.VirtualPadButton();
this.btnEject = new BizHawk.Client.EmuHawk.VirtualPadButton();
this.label1 = new System.Windows.Forms.Label();
this.btnClose = new BizHawk.Client.EmuHawk.VirtualPadButton();
this.btnOpen = new BizHawk.Client.EmuHawk.VirtualPadButton();
this.lblTimeZero = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
@ -80,42 +82,64 @@
this.columnHeader2.Text = "Name";
this.columnHeader2.Width = 228;
//
// btnInsert
// label1
//
this.btnInsert.Appearance = System.Windows.Forms.Appearance.Button;
this.btnInsert.AutoSize = true;
this.btnInsert.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnInsert.Location = new System.Drawing.Point(50, 3);
this.btnInsert.Name = "btnInsert";
this.btnInsert.ReadOnly = false;
this.btnInsert.RightClicked = false;
this.btnInsert.Size = new System.Drawing.Size(43, 23);
this.btnInsert.TabIndex = 2;
this.btnInsert.Text = "Insert";
this.btnInsert.UseVisualStyleBackColor = true;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(34, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Tray :";
//
// btnEject
// btnClose
//
this.btnEject.Appearance = System.Windows.Forms.Appearance.Button;
this.btnEject.AutoSize = true;
this.btnEject.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnEject.Location = new System.Drawing.Point(3, 3);
this.btnEject.Name = "btnEject";
this.btnEject.ReadOnly = false;
this.btnEject.RightClicked = false;
this.btnEject.Size = new System.Drawing.Size(41, 23);
this.btnEject.TabIndex = 0;
this.btnEject.Text = "Eject";
this.btnEject.UseVisualStyleBackColor = true;
this.btnClose.Appearance = System.Windows.Forms.Appearance.Button;
this.btnClose.AutoSize = true;
this.btnClose.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnClose.Location = new System.Drawing.Point(93, 6);
this.btnClose.Name = "btnClose";
this.btnClose.ReadOnly = false;
this.btnClose.RightClicked = false;
this.btnClose.Size = new System.Drawing.Size(43, 23);
this.btnClose.TabIndex = 2;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnOpen
//
this.btnOpen.Appearance = System.Windows.Forms.Appearance.Button;
this.btnOpen.AutoSize = true;
this.btnOpen.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnOpen.Location = new System.Drawing.Point(46, 6);
this.btnOpen.Name = "btnOpen";
this.btnOpen.ReadOnly = false;
this.btnOpen.RightClicked = false;
this.btnOpen.Size = new System.Drawing.Size(43, 23);
this.btnOpen.TabIndex = 0;
this.btnOpen.Text = "Open";
this.btnOpen.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// lblTimeZero
//
this.lblTimeZero.AutoSize = true;
this.lblTimeZero.Location = new System.Drawing.Point(142, 11);
this.lblTimeZero.Name = "lblTimeZero";
this.lblTimeZero.Size = new System.Drawing.Size(135, 13);
this.lblTimeZero.TabIndex = 4;
this.lblTimeZero.Text = "(T=0: Freely set initial state)";
//
// VirtualPadDiscManager
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.Controls.Add(this.btnInsert);
this.Controls.Add(this.lblTimeZero);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnEject);
this.Controls.Add(this.btnOpen);
this.Name = "VirtualPadDiscManager";
this.Size = new System.Drawing.Size(286, 244);
this.groupBox1.ResumeLayout(false);
@ -126,11 +150,13 @@
#endregion
private VirtualPadButton btnEject;
private VirtualPadButton btnOpen;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ListView lvDiscs;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private VirtualPadButton btnInsert;
private VirtualPadButton btnClose;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblTimeZero;
}
}

View File

@ -18,13 +18,24 @@ namespace BizHawk.Client.EmuHawk
public VirtualPadDiscManager(string[] buttonNames)
{
InitializeComponent();
btnEject.Name = buttonNames[0];
btnInsert.Name = buttonNames[1];
btnOpen.Name = buttonNames[0];
btnClose.Name = buttonNames[1];
_discSelectName = buttonNames[2];
UpdateCoreAssociation();
}
string _discSelectName;
public object OwnerEmulator { get; set; }
object _ownerEmulator;
public object OwnerEmulator
{
get { return _ownerEmulator; }
set
{
_ownerEmulator = value;
UpdateValues();
}
}
object lastCoreOwner;
@ -69,17 +80,48 @@ namespace BizHawk.Client.EmuHawk
if (OwnerEmulator is Octoshock)
{
var psx = OwnerEmulator as Octoshock;
bool eject = psx.CurrentDiscEjected;
bool eject = psx.CurrentTrayOpen;
bool enableDiscs = eject;
bool refreshDiscs = true;
btnEject.Enabled = !eject;
btnInsert.Enabled = eject;
//special logic: if this is frame 0, we can begin in any state
if (psx.Frame == 0)
{
lblTimeZero.Visible = true;
btnOpen.Enabled = true;
btnClose.Enabled = true;
if (!btnEject.Enabled) btnEject.Checked = false;
if (!btnInsert.Enabled) btnInsert.Checked = false;
//if neither button is picked, start with 'closed' selected
//(kind of a hack for the initial update)
if (!btnClose.Checked && !btnOpen.Checked)
{
btnClose.Checked = true;
}
else
{
//while we're here, make sure this only happens the first time
refreshDiscs = false;
}
enableDiscs = btnOpen.Checked;
//since user hasnt ever needed to set the disc, make sure it's set here
//UPDATE: do it below
//Global.StickyXORAdapter.SetFloat(_discSelectName, psx.CurrentDiscIndexMounted);
}
else
{
lblTimeZero.Visible = false;
btnOpen.Enabled = !eject;
btnClose.Enabled = eject;
if (!btnOpen.Enabled) btnOpen.Checked = false;
if (!btnClose.Enabled) btnClose.Checked = false;
}
//if we're not ejected, then the disc is frozen in the current configuration
lvDiscs.Enabled = eject;
if (!eject)
lvDiscs.Enabled = enableDiscs;
if (!eject && refreshDiscs)
{
lvDiscs.SelectedIndices.Clear();
lvDiscs.SelectedIndices.Add(psx.CurrentDiscIndexMounted);
@ -119,6 +161,24 @@ namespace BizHawk.Client.EmuHawk
else Global.StickyXORAdapter.SetFloat(_discSelectName, lvDiscs.SelectedIndices[0]);
}
private void btnClose_Click(object sender, EventArgs e)
{
if (lblTimeZero.Visible)
{
btnOpen.Checked = !btnClose.Checked;
UpdateValues();
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (lblTimeZero.Visible)
{
btnClose.Checked = !btnOpen.Checked;
UpdateValues();
}
}

View File

@ -188,7 +188,7 @@ namespace BizHawk.Client.EmuHawk
Location = new Point(10,54),
TargetSize = new Size(300,300),
OwnerEmulator = psx,
SecondaryNames = new [] { "Eject", "Insert", "Disc Select" }
SecondaryNames = new [] { "Open", "Close", "Disc Select" }
}
}
};

View File

@ -44,7 +44,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
"P1 R1", "P1 L2", "P1 R2", "P1 L3", "P1 R3", "P1 MODE",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Select", "P2 Start", "P2 Square", "P2 Triangle", "P2 Circle", "P2 Cross", "P2 L1",
"P2 R1", "P2 L2", "P2 R2", "P2 L3", "P2 R3", "P2 MODE",
"Eject", "Insert", "Reset",
"Open", "Close", "Reset",
},
FloatControls =
{
@ -62,7 +62,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
new[] {255.0f, 128.0f, 0.0f},
new[] {0.0f, 128.0f, 255.0f},
new[] {255.0f, 128.0f, 0.0f},
new[] {1.0f,1.0f,5.0f},
new[] {-1f,-1f,-1f}, //this is carefully chosen so that we end up with a -1 disc by default (indicating that it's never been set)
},
};
@ -191,7 +191,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public OctoshockDll.eVidStandard SystemVidStandard { get; private set; }
public System.Drawing.Size CurrentVideoSize { get; private set; }
public bool CurrentDiscEjected { get; private set; }
public bool CurrentTrayOpen { get; private set; }
public int CurrentDiscIndexMounted { get; private set; }
public List<string> HackyDiscButtons = new List<string>();
@ -292,16 +292,12 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
frameBuffer = new int[BufferWidth * BufferHeight];
}
//TODO - should be able to cold boot system with disc isnerted
if (discInterfaces.Count != 0)
{
//start with first disc inserted and tray closed
CurrentDiscEjected = false;
//start with first disc inserted and tray closed. it's a sensible default.
//it will be possible for the user to specify a different initial configuration, but this will inform the UI
CurrentTrayOpen = false;
CurrentDiscIndexMounted = 1;
currentDiscInterface = discInterfaces[CurrentDiscIndexMounted - 1];
OctoshockDll.shock_OpenTray(psx);
OctoshockDll.shock_SetDisc(psx, currentDiscInterface.OctoshockHandle);
OctoshockDll.shock_CloseTray(psx);
}
else
{
@ -310,7 +306,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
OctoshockDll.shock_MountEXE(psx, pExeBuffer, exe.Length);
//start with no disc inserted and tray closed
CurrentDiscEjected = false;
CurrentTrayOpen = false;
CurrentDiscIndexMounted = 0;
OctoshockDll.shock_CloseTray(psx);
}
@ -450,19 +446,26 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
void FrameAdvance_PrepDiscState()
{
//if eject is requested, and valid, apply it
if (Controller["Eject"] && !CurrentDiscEjected)
//reminder: if this is the beginning of time, we can begin with the disc ejected or inserted.
//if tray open is requested, and valid, apply it
//in the first frame, go ahead and open it up so we have a chance to put a disc in it
if (Controller["Open"] && !CurrentTrayOpen || Frame==0)
{
OctoshockDll.shock_OpenTray(psx);
CurrentDiscEjected = true;
CurrentTrayOpen = true;
}
//change the disc if needed, and valid
//TODO - warning if zero time change?
//also if frame is 0, we need to set a disc no matter what
int requestedDisc = (int)Controller.GetFloat("Disc Select");
if (requestedDisc != CurrentDiscIndexMounted && CurrentDiscEjected)
if (requestedDisc != CurrentDiscIndexMounted && CurrentTrayOpen
|| Frame == 0
)
{
CurrentDiscIndexMounted = requestedDisc;
//dont replace default disc with the leave-default placeholder!
if (requestedDisc == -1) { }
else CurrentDiscIndexMounted = requestedDisc;
if (CurrentDiscIndexMounted == 0)
{
currentDiscInterface = null;
@ -475,24 +478,31 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
}
}
//if insert is requested, and valid, apply it
if (Controller["Insert"] && CurrentDiscEjected)
//if tray close is requested, and valid, apply it.
if (Controller["Close"] && CurrentTrayOpen)
{
OctoshockDll.shock_CloseTray(psx);
CurrentDiscEjected = false;
CurrentTrayOpen = false;
}
//if frame is 0 and user has made no preference, close the tray
if (!Controller["Close"] && !Controller["Open"] && Frame == 0 && CurrentTrayOpen)
{
OctoshockDll.shock_CloseTray(psx);
CurrentTrayOpen = false;
}
}
public void FrameAdvance(bool render, bool rendersound)
{
Frame++;
FrameAdvance_PrepDiscState();
//clear drive light. itll get set to light up by sector-reading callbacks
//TODO - debounce this by a frame or so perhaps?
DriveLightOn = false;
FrameAdvance_PrepDiscState();
Frame++;
SetInput();
var ropts = new OctoshockDll.ShockRenderOptions()
@ -710,7 +720,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
s.ExtraData.IsLagFrame = IsLagFrame;
s.ExtraData.LagCount = LagCount;
s.ExtraData.Frame = Frame;
s.ExtraData.CurrentDiscEjected = CurrentDiscEjected;
s.ExtraData.CurrentDiscEjected = CurrentTrayOpen;
s.ExtraData.CurrentDiscIndexMounted = CurrentDiscIndexMounted;
ser.Serialize(writer, s);
@ -734,7 +744,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
IsLagFrame = s.ExtraData.IsLagFrame;
LagCount = s.ExtraData.LagCount;
Frame = s.ExtraData.Frame;
CurrentDiscEjected = s.ExtraData.CurrentDiscEjected;
CurrentTrayOpen = s.ExtraData.CurrentDiscEjected;
CurrentDiscIndexMounted = s.ExtraData.CurrentDiscIndexMounted;
}
@ -771,7 +781,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
writer.Write(IsLagFrame);
writer.Write(LagCount);
writer.Write(Frame);
writer.Write(CurrentDiscEjected);
writer.Write(CurrentTrayOpen);
writer.Write(CurrentDiscIndexMounted);
}
}
@ -799,7 +809,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
IsLagFrame = reader.ReadBoolean();
LagCount = reader.ReadInt32();
Frame = reader.ReadInt32();
CurrentDiscEjected = reader.ReadBoolean();
CurrentTrayOpen = reader.ReadBoolean();
CurrentDiscIndexMounted = reader.ReadInt32();
//TODO - need a method to sneak the required disc, without having to do a proper eject sequence