Some minor PPSSPP changes, nothing to use yet

This commit is contained in:
nattthebear 2016-02-24 21:01:14 -05:00
parent 52ef67a12f
commit 4db03c18d1
2 changed files with 120 additions and 20 deletions

View File

@ -15,18 +15,74 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
public delegate void LogCB(char type, string message);
[DllImport(dd, CallingConvention = cc)]
public static extern bool init(string fn, LogCB logcallback);
public static extern bool BizInit(string fn, LogCB logcallback);
//[DllImport(dd, CallingConvention = cc)]
//public static extern void setvidbuff(IntPtr buff);
[DllImport(dd, CallingConvention = cc)]
public static extern void setvidbuff(IntPtr buff);
public static extern int BizClose();
[DllImport(dd, CallingConvention = cc)]
public static extern void die();
public static extern void BizAdvance(int[] vidbuff, [In]Input input);
[DllImport(dd, CallingConvention = cc)]
public static extern void advance();
public static extern int MixSound(short[] buff, int nsamp);
[DllImport(dd, CallingConvention = cc)]
public static extern int mixsound(short[] buff, int nsamp);
public enum Buttons : int
{
/*
A = 1, // this is what they're called in the source...
B = 2,
X = 4,
Y = 8,
LBUMPER = 16,
RBUMPER = 32,
START = 64,
SELECT = 128,
UP = 256,
DOWN = 512,
LEFT = 1024,
RIGHT = 2048,
MENU = 4096,
BACK = 8192*/
/*SQUARE*/ A= 0x8000,
/*TRIANGLE*/ B= 0x1000,
/*CIRCLE*/ X= 0x2000,
/*CROSS*/ Y= 0x4000,
UP = 0x0010,
DOWN = 0x0040,
LEFT = 0x0080,
RIGHT = 0x0020,
START = 0x0008,
SELECT = 0x0001,
/*LTRIGGER*/ LBUMPER= 0x0100,
/*RTRIGGER*/ RBUMPER= 0x0200,
MENU=0,
BACK=0
}
[StructLayout(LayoutKind.Sequential)]
public class Input
{
public Buttons CurrentButtons; // this frame
public Buttons LastButtons; // last frame
public Buttons DownButtons; // rising edge
public Buttons UpButtons; // falling edge
public float LeftStickX;
public float LeftStickY;
public float RightStickX;
public float RightStickY;
public float LeftTrigger;
public float RightTrigger;
public void SetButtons(Buttons newButtons)
{
LastButtons = CurrentButtons;
CurrentButtons = newButtons;
DownButtons = (LastButtons ^ CurrentButtons) & CurrentButtons;
UpButtons = (LastButtons ^ CurrentButtons) & LastButtons;
}
}
}
}

View File

@ -22,16 +22,22 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
Name = "PSP Controller",
BoolButtons =
{
"Up", "Down", "Left", "Right", "Select", "Start", "L", "R", "Square", "Triangle", "Circle", "Cross", "Power"
"Up", "Down", "Left", "Right", "Select", "Start", "L", "R", "Square", "Triangle", "Circle", "Cross",
"Menu", "Back",
"Power"
},
FloatControls =
{
"Stick X", "Stick Y"
"Left Stick X", "Left Stick Y", "Right Stick X", "Right Stick Y", "Left Trigger", "Right Trigger"
},
FloatRanges = // TODO
{
new[] {-1.0f, 0.0f, 1.0f},
new[] {-1.0f, 0.0f, 1.0f},
new[] {-1.0f, 0.0f, 1.0f},
new[] {-1.0f, 0.0f, 1.0f},
new[] {-1.0f, 0.0f, 1.0f},
new[] {-1.0f, 0.0f, 1.0f},
}
};
@ -49,6 +55,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
PPSSPPDll.LogCB logcallback = null;
Queue<string> debugmsgs = new Queue<string>();
PPSSPPDll.Input input = new PPSSPPDll.Input();
void LogCallbackFunc(char type, string message)
{
debugmsgs.Enqueue(string.Format("PSP: {0} {1}", type, message));
@ -63,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
bool disposed = false;
static PSP attachedcore = null;
GCHandle vidhandle;
object glcontext;
public PSP(CoreComm comm, string isopath)
{
@ -75,14 +83,15 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
}
CoreComm = comm;
glcontext = CoreComm.RequestGLContext(3, 0, true);
CoreComm.ActivateGLContext(glcontext);
logcallback = new PPSSPPDll.LogCB(LogCallbackFunc);
bool good = PPSSPPDll.init(isopath, logcallback);
bool good = PPSSPPDll.BizInit(isopath, logcallback);
LogFlush();
if (!good)
throw new Exception("PPSSPP Init failed!");
vidhandle = GCHandle.Alloc(screenbuffer, GCHandleType.Pinned);
PPSSPPDll.setvidbuff(vidhandle.AddrOfPinnedObject());
CoreComm.VsyncDen = 1;
CoreComm.VsyncNum = 60;
@ -97,38 +106,72 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
{
if (!disposed)
{
vidhandle.Free();
PPSSPPDll.setvidbuff(IntPtr.Zero);
PPSSPPDll.die();
PPSSPPDll.BizClose();
logcallback = null;
disposed = true;
LogFlush();
Console.WriteLine("PSP Core Disposed.");
}
}
private void UpdateInput()
{
PPSSPPDll.Buttons b = 0;
var c = Controller;
if (c["Up"]) b |= PPSSPPDll.Buttons.UP;
if (c["Down"]) b |= PPSSPPDll.Buttons.DOWN;
if (c["Left"]) b |= PPSSPPDll.Buttons.LEFT;
if (c["Right"]) b |= PPSSPPDll.Buttons.RIGHT;
if (c["Select"]) b |= PPSSPPDll.Buttons.SELECT;
if (c["Start"]) b |= PPSSPPDll.Buttons.START;
if (c["L"]) b |= PPSSPPDll.Buttons.LBUMPER;
if (c["R"]) b |= PPSSPPDll.Buttons.RBUMPER;
if (c["Square"]) b |= PPSSPPDll.Buttons.A;
if (c["Triangle"]) b |= PPSSPPDll.Buttons.B;
if (c["Circle"]) b |= PPSSPPDll.Buttons.X;
if (c["Cross"]) b |= PPSSPPDll.Buttons.Y;
if (c["Menu"]) b |= PPSSPPDll.Buttons.MENU;
if (c["Back"]) b |= PPSSPPDll.Buttons.BACK;
input.SetButtons(b);
input.LeftStickX = c.GetFloat("Left Stick X");
input.LeftStickY = c.GetFloat("Left Stick Y");
input.RightStickX = c.GetFloat("Right Stick X");
input.RightStickY = c.GetFloat("Right Stick Y");
input.LeftTrigger = c.GetFloat("Left Trigger");
input.RightTrigger = c.GetFloat("Right Trigger");
}
public void FrameAdvance(bool render, bool rendersound = true)
{
PPSSPPDll.advance();
Frame++;
UpdateInput();
PPSSPPDll.BizAdvance(screenbuffer, input);
// problem 1: audio can be 48khz, if a particular core parameter is set. we're not accounting for that.
// problem 2: we seem to be getting approximately the right amount of output, but with
// a lot of jitter on the per-frame buffer size
nsampavail = PPSSPPDll.mixsound(audiobuffer, audiobuffer.Length / 2);
nsampavail = PPSSPPDll.MixSound(audiobuffer, audiobuffer.Length / 2);
//Console.WriteLine(nsampavail);
//nsampavail = PPSSPPDll.mixsound(audiobuffer, audiobuffer.Length / 2);
LogFlush();
//Console.WriteLine("Audio Service: {0}", nsampavail);
}
public int Frame
{
[FeatureNotImplemented]
get { return 0; }
get;
private set;
}
[FeatureNotImplemented]
public void ResetCounters()
{
Frame = 0;
}
const int screenwidth = 480;
@ -147,6 +190,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSP
{
samples = audiobuffer;
nsamp = nsampavail;
//nsamp = 735;
}
public void DiscardSamples()
{