2012-12-17 20:45:32 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2017-08-20 18:03:06 +00:00
|
|
|
#include "base/NativeApp.h"
|
2020-08-10 04:20:42 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
|
|
|
#include "Common/ChunkFileDo.h"
|
2014-03-15 18:22:19 +00:00
|
|
|
#include "Core/HLE/HLE.h"
|
|
|
|
#include "Core/HLE/FunctionWrappers.h"
|
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-02-04 04:31:46 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
2014-03-15 18:22:19 +00:00
|
|
|
#include "Core/HLE/sceUsb.h"
|
2012-12-17 20:45:32 +00:00
|
|
|
|
2014-07-03 20:27:01 +00:00
|
|
|
// TODO: Map by driver name
|
|
|
|
bool usbStarted = false;
|
|
|
|
// TODO: Check actual status
|
|
|
|
bool usbConnected = true;
|
|
|
|
// TODO: Activation by product id
|
2012-12-17 20:45:32 +00:00
|
|
|
bool usbActivated = false;
|
|
|
|
|
2014-07-03 20:27:01 +00:00
|
|
|
enum UsbStatus {
|
|
|
|
USB_STATUS_STOPPED = 0x001,
|
|
|
|
USB_STATUS_STARTED = 0x002,
|
|
|
|
USB_STATUS_DISCONNECTED = 0x010,
|
|
|
|
USB_STATUS_CONNECTED = 0x020,
|
|
|
|
USB_STATUS_DEACTIVATED = 0x100,
|
|
|
|
USB_STATUS_ACTIVATED = 0x200,
|
|
|
|
};
|
|
|
|
|
2012-12-24 06:47:52 +00:00
|
|
|
void __UsbInit()
|
|
|
|
{
|
2014-07-03 20:27:01 +00:00
|
|
|
usbStarted = false;
|
|
|
|
usbConnected = true;
|
2012-12-24 06:47:52 +00:00
|
|
|
usbActivated = false;
|
|
|
|
}
|
|
|
|
|
2012-12-28 07:00:04 +00:00
|
|
|
void __UsbDoState(PointerWrap &p)
|
|
|
|
{
|
2014-07-03 20:27:01 +00:00
|
|
|
auto s = p.Section("sceUsb", 1, 2);
|
2013-09-15 03:23:03 +00:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2014-07-05 14:30:03 +00:00
|
|
|
if (s >= 2) {
|
2020-08-10 04:20:42 +00:00
|
|
|
Do(p, usbStarted);
|
|
|
|
Do(p, usbConnected);
|
2014-07-05 14:30:03 +00:00
|
|
|
} else {
|
|
|
|
usbStarted = false;
|
|
|
|
usbConnected = true;
|
|
|
|
}
|
2020-08-10 04:20:42 +00:00
|
|
|
Do(p, usbActivated);
|
2012-12-28 07:00:04 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceUsbStart(const char* driverName, u32 argsSize, u32 argsPtr) {
|
2019-08-25 22:09:59 +00:00
|
|
|
INFO_LOG(HLE, "sceUsbStart(%s, %i, %08x)", driverName, argsSize, argsPtr);
|
2014-07-03 20:27:01 +00:00
|
|
|
usbStarted = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceUsbStop(const char* driverName, u32 argsSize, u32 argsPtr) {
|
2019-08-25 22:09:59 +00:00
|
|
|
INFO_LOG(HLE, "sceUsbStop(%s, %i, %08x)", driverName, argsSize, argsPtr);
|
2014-07-03 20:27:01 +00:00
|
|
|
usbStarted = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceUsbGetState() {
|
2017-08-20 18:03:06 +00:00
|
|
|
int state = 0;
|
|
|
|
if (!usbStarted) {
|
|
|
|
state = 0x80243007;
|
|
|
|
} else {
|
|
|
|
state = USB_STATUS_STARTED
|
|
|
|
| (usbConnected ? USB_STATUS_CONNECTED : USB_STATUS_DISCONNECTED)
|
|
|
|
| (usbActivated ? USB_STATUS_ACTIVATED : USB_STATUS_DEACTIVATED);
|
|
|
|
}
|
2020-07-31 02:24:17 +00:00
|
|
|
DEBUG_LOG(HLE, "sceUsbGetState: 0x%x", state);
|
2014-07-03 20:27:01 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceUsbActivate(u32 pid) {
|
2019-08-25 22:09:59 +00:00
|
|
|
INFO_LOG(HLE, "sceUsbActivate(%i)", pid);
|
2012-12-17 20:45:32 +00:00
|
|
|
usbActivated = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceUsbDeactivate(u32 pid) {
|
2019-08-25 22:09:59 +00:00
|
|
|
INFO_LOG(HLE, "sceUsbDeactivate(%i)", pid);
|
2014-07-03 20:27:01 +00:00
|
|
|
usbActivated = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-09 13:57:09 +00:00
|
|
|
static int sceUsbWaitState(int state, int waitMode, u32 timeoutAddr) {
|
|
|
|
ERROR_LOG(HLE, "UNIMPL sceUsbWaitStat(%i, %i, %08x)", state, waitMode, timeoutAddr);
|
|
|
|
return sceUsbGetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sceUsbWaitStateCB(int state, int waitMode, u32 timeoutAddr) {
|
|
|
|
ERROR_LOG(HLE, "UNIMPL sceUsbWaitStateCB(%i, %i, %08x)", state, waitMode, timeoutAddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-17 20:45:32 +00:00
|
|
|
const HLEFunction sceUsb[] =
|
|
|
|
{
|
2015-03-22 23:57:56 +00:00
|
|
|
{0XAE5DE6AF, &WrapI_CUU<sceUsbStart>, "sceUsbStart", 'i', "sxx"},
|
|
|
|
{0XC2464FA0, &WrapI_CUU<sceUsbStop>, "sceUsbStop", 'i', "sxx"},
|
|
|
|
{0XC21645A4, &WrapI_V<sceUsbGetState>, "sceUsbGetState", 'i', "" },
|
|
|
|
{0X4E537366, nullptr, "sceUsbGetDrvList", '?', "" },
|
|
|
|
{0X112CC951, nullptr, "sceUsbGetDrvState", '?', "" },
|
|
|
|
{0X586DB82C, &WrapI_U<sceUsbActivate>, "sceUsbActivate", 'i', "x" },
|
|
|
|
{0XC572A9C8, &WrapI_U<sceUsbDeactivate>, "sceUsbDeactivate", 'i', "x" },
|
2020-01-09 13:57:09 +00:00
|
|
|
{0X5BE0E002, &WrapI_IIU<sceUsbWaitState>, "sceUsbWaitState", '?', "xxx"},
|
|
|
|
{0X616F2B61, &WrapI_IIU<sceUsbWaitStateCB>, "sceUsbWaitStateCB", '?', "xxx"},
|
2015-03-22 23:57:56 +00:00
|
|
|
{0X1C360735, nullptr, "sceUsbWaitCancel", '?', "" },
|
2012-12-17 20:45:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const HLEFunction sceUsbstor[] =
|
|
|
|
{
|
2015-03-22 23:57:56 +00:00
|
|
|
{0X60066CFE, nullptr, "sceUsbstorGetStatus", '?', "" },
|
2012-12-17 20:45:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const HLEFunction sceUsbstorBoot[] =
|
|
|
|
{
|
2015-03-22 23:57:56 +00:00
|
|
|
{0XE58818A8, nullptr, "sceUsbstorBootSetCapacity", '?', "" },
|
|
|
|
{0X594BBF95, nullptr, "sceUsbstorBootSetLoadAddr", '?', "" },
|
|
|
|
{0X6D865ECD, nullptr, "sceUsbstorBootGetDataSize", '?', "" },
|
|
|
|
{0XA1119F0D, nullptr, "sceUsbstorBootSetStatus", '?', "" },
|
|
|
|
{0X1F080078, nullptr, "sceUsbstorBootRegisterNotify", '?', "" },
|
|
|
|
{0XA55C9E16, nullptr, "sceUsbstorBootUnregisterNotify", '?', "" },
|
2012-12-17 20:45:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void Register_sceUsb()
|
|
|
|
{
|
|
|
|
RegisterModule("sceUsbstor", ARRAY_SIZE(sceUsbstor), sceUsbstor);
|
|
|
|
RegisterModule("sceUsbstorBoot", ARRAY_SIZE(sceUsbstorBoot), sceUsbstorBoot);
|
|
|
|
RegisterModule("sceUsb", ARRAY_SIZE(sceUsb), sceUsb);
|
2015-03-08 04:09:30 +00:00
|
|
|
}
|