From e69e8446237f31b1518838456460fe98000cfe7b Mon Sep 17 00:00:00 2001
From: "Unknown W. Brackets" <checkins@unknownbrackets.org>
Date: Mon, 28 May 2018 17:08:55 -0700
Subject: [PATCH 1/2] Ctrl: Always mark non-user buttons released.

This matches behavior on real firmware and fixes a test failure.
---
 Core/HLE/sceCtrl.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp
index 1ef00dbdaf87..1b552a419189 100644
--- a/Core/HLE/sceCtrl.cpp
+++ b/Core/HLE/sceCtrl.cpp
@@ -503,18 +503,20 @@ static int sceCtrlPeekBufferNegative(u32 ctrlDataPtr, u32 nBufs)
 	return done;
 }
 
-void __CtrlWriteUserLatch(CtrlLatch *userLatch) {
+static void __CtrlWriteUserLatch(CtrlLatch *userLatch, int bufs) {
 	*userLatch = latch;
 	userLatch->btnBreak &= CTRL_MASK_USER;
 	userLatch->btnMake &= CTRL_MASK_USER;
 	userLatch->btnPress &= CTRL_MASK_USER;
-	userLatch->btnRelease &= CTRL_MASK_USER;
+	if (bufs > 0) {
+		userLatch->btnRelease |= CTRL_MASK_USER;
+	}
 }
 
 static u32 sceCtrlPeekLatch(u32 latchDataPtr) {
 	auto userLatch = PSPPointer<CtrlLatch>::Create(latchDataPtr);
 	if (userLatch.IsValid()) {
-		__CtrlWriteUserLatch(userLatch);
+		__CtrlWriteUserLatch(userLatch, ctrlLatchBufs);
 	}
 	return hleLogSuccessI(SCECTRL, ctrlLatchBufs);
 }
@@ -522,7 +524,7 @@ static u32 sceCtrlPeekLatch(u32 latchDataPtr) {
 static u32 sceCtrlReadLatch(u32 latchDataPtr) {
 	auto userLatch = PSPPointer<CtrlLatch>::Create(latchDataPtr);
 	if (userLatch.IsValid()) {
-		__CtrlWriteUserLatch(userLatch);
+		__CtrlWriteUserLatch(userLatch, ctrlLatchBufs);
 	}
 	return hleLogSuccessI(SCECTRL, __CtrlResetLatch());
 }

From 16e0a7cc8e9f49a102df2b202ef64447a2f4f29e Mon Sep 17 00:00:00 2001
From: "Unknown W. Brackets" <checkins@unknownbrackets.org>
Date: Mon, 28 May 2018 17:24:40 -0700
Subject: [PATCH 2/2] Headless: Default memory stick inserted.

Tests expect this, oops.
---
 headless/Headless.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/headless/Headless.cpp b/headless/Headless.cpp
index 661211d1d0d0..d81a229d16ca 100644
--- a/headless/Headless.cpp
+++ b/headless/Headless.cpp
@@ -374,6 +374,7 @@ int main(int argc, const char* argv[])
 	g_Config.bBlockTransferGPU = true;
 	g_Config.iSplineBezierQuality = 2;
 	g_Config.bHighQualityDepth = true;
+	g_Config.bMemStickInserted = true;
 
 #ifdef _WIN32
 	InitSysDirectories();