mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 17:23:40 +01:00
Merge branch 'master' of https://github.com/hrydgard/ppsspp.git
Conflicts: Core/Core.vcxproj.filters Core/HLE/sceFont.cpp Core/HLE/sceGe.cpp Core/HLE/sceIo.cpp Core/HLE/sceKernelMutex.cpp
This commit is contained in:
commit
602623e007
197 files changed
+18547
-4623
No files matched your search
@@ -23,6 +23,9 @@ Release
|
||||
Windows/x64
|
||||
Windows/ipch
|
||||
|
||||
# For Mac
|
||||
.DS_Store
|
||||
|
||||
# For ppsspp.ini, etc.
|
||||
*.ini
|
||||
|
||||
@@ -37,6 +40,7 @@ gen
|
||||
libs
|
||||
obj
|
||||
build*/
|
||||
/git-version.cpp
|
||||
|
||||
.pspsh.hist
|
||||
__testoutput.txt
|
||||
@@ -46,5 +50,6 @@ __testfailure.bmp
|
||||
GameLogNotes.txt
|
||||
|
||||
android/ui_atlas.zim
|
||||
android/assets/flash0
|
||||
ppge_atlas.zim.png
|
||||
local.properties
|
||||
@@ -3,8 +3,8 @@
|
||||
<id>com.Qtness.PPSSPP</id>
|
||||
<name>PPSSPP</name>
|
||||
<filename>PPSSPPBlackberry</filename>
|
||||
<versionNumber>0.6.1</versionNumber>
|
||||
<buildId>2</buildId>
|
||||
<versionNumber>0.7.0</versionNumber>
|
||||
<buildId>1</buildId>
|
||||
<description>Playstation portable emulator.</description>
|
||||
|
||||
<author>Qtness</author>
|
||||
@@ -20,6 +20,7 @@
|
||||
<asset path="PPSSPPBlackberry" entry="true" type="Qnx/Elf">PPSSPPBlackberry</asset>
|
||||
<asset path="../assets/icon-114.png">icon-114.png</asset>
|
||||
<asset path="../android/assets">assets</asset>
|
||||
<asset path="../flash0">assets/flash</asset>
|
||||
|
||||
<category>core.games</category>
|
||||
<icon>
|
||||
|
||||
+43
-5
@@ -16,6 +16,10 @@ if(BLACKBERRY)
|
||||
set(ARM ON)
|
||||
endif()
|
||||
|
||||
if(LOONGSON)
|
||||
set(MIPS ON) # MIPS + x86 for now
|
||||
endif()
|
||||
|
||||
if(ARM)
|
||||
set(USING_GLES2 ON)
|
||||
else() # Assume x86
|
||||
@@ -30,6 +34,7 @@ endif()
|
||||
|
||||
# User-editable options (go into CMakeCache.txt)
|
||||
option(ARM "Set to ON if targeting an ARM processor" ${ARM})
|
||||
option(MIPS "Set to ON if targeting a MIPS processor" ${MIPS})
|
||||
option(X86 "Set to ON if targeting an X86 processor" ${X86})
|
||||
option(ANDROID "Set to ON if targeting an Android device" ${ANDROID})
|
||||
option(BLACKBERRY "Set to ON if targeting a Blackberry device" ${BLACKBERRY})
|
||||
@@ -105,6 +110,10 @@ if(USING_GLES2)
|
||||
add_definitions(-DUSING_GLES2)
|
||||
endif()
|
||||
|
||||
if(MIPS)
|
||||
add_definitions(-DMIPS)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_NDEBUG")
|
||||
|
||||
@@ -127,7 +136,7 @@ if(NOT MSVC)
|
||||
add_definitions(-D_QNX_SOURCE=1 -D_C99=1)
|
||||
endif()
|
||||
|
||||
if(X86)
|
||||
if(X86 AND NOT MIPS)
|
||||
# enable sse2 code generation
|
||||
add_definitions(-msse2)
|
||||
endif()
|
||||
@@ -136,6 +145,7 @@ if(NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
|
||||
elseif(APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
|
||||
endif()
|
||||
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.0)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
@@ -618,6 +628,8 @@ if(ARM)
|
||||
Core/MIPS/ARM/ArmJitCache.h
|
||||
Core/MIPS/ARM/ArmRegCache.cpp
|
||||
Core/MIPS/ARM/ArmRegCache.h
|
||||
Core/MIPS/ARM/ArmRegCacheFPU.cpp
|
||||
Core/MIPS/ARM/ArmRegCacheFPU.h
|
||||
ext/disarm.cpp)
|
||||
elseif(X86)
|
||||
set(CoreExtra ${CoreExtra}
|
||||
@@ -684,6 +696,8 @@ add_library(${CoreLibName} ${CoreLinkType}
|
||||
Core/FileSystems/ISOFileSystem.h
|
||||
Core/FileSystems/MetaFileSystem.cpp
|
||||
Core/FileSystems/MetaFileSystem.h
|
||||
Core/Font/PGF.cpp
|
||||
Core/Font/PGF.h
|
||||
Core/HLE/FunctionWrappers.h
|
||||
Core/HLE/HLE.cpp
|
||||
Core/HLE/HLE.h
|
||||
@@ -747,6 +761,8 @@ add_library(${CoreLibName} ${CoreLinkType}
|
||||
Core/HLE/sceNet.h
|
||||
Core/HLE/sceOpenPSID.cpp
|
||||
Core/HLE/sceOpenPSID.h
|
||||
Core/HLE/sceP3da.cpp
|
||||
Core/HLE/sceP3da.h
|
||||
Core/HLE/sceParseHttp.cpp
|
||||
Core/HLE/sceParseHttp.h
|
||||
Core/HLE/sceParseUri.cpp
|
||||
@@ -810,6 +826,8 @@ add_library(${CoreLibName} ${CoreLinkType}
|
||||
Core/PSPLoaders.h
|
||||
Core/PSPMixer.cpp
|
||||
Core/PSPMixer.h
|
||||
Core/Reporting.cpp
|
||||
Core/Reporting.h
|
||||
Core/SaveState.cpp
|
||||
Core/SaveState.h
|
||||
Core/System.cpp
|
||||
@@ -818,15 +836,26 @@ add_library(${CoreLibName} ${CoreLinkType}
|
||||
Core/Util/BlockAllocator.h
|
||||
Core/Util/PPGeDraw.cpp
|
||||
Core/Util/PPGeDraw.h
|
||||
Core/Util/Pool.h
|
||||
Core/Util/ppge_atlas.cpp
|
||||
Core/Util/ppge_atlas.h
|
||||
$<TARGET_OBJECTS:GPU>
|
||||
Globals.h)
|
||||
Globals.h
|
||||
git-version.cpp)
|
||||
target_link_libraries(${CoreLibName} Common native kirk cityhash
|
||||
${GLEW_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||
setup_target_project(${CoreLibName} Core)
|
||||
|
||||
# Generate git-version.cpp at build time.
|
||||
add_custom_target(GitVersion ALL
|
||||
DEPENDS something_that_never_exists)
|
||||
add_custom_command(OUTPUT something_that_never_exists
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake)
|
||||
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/git-version.cpp
|
||||
PROPERTIES GENERATED TRUE)
|
||||
add_dependencies(${CoreLibName} GitVersion)
|
||||
|
||||
add_library(GPU OBJECT
|
||||
GPU/GLES/DisplayListInterpreter.cpp
|
||||
GPU/GLES/DisplayListInterpreter.h
|
||||
@@ -944,6 +973,7 @@ endif()
|
||||
set(NativeAppSource
|
||||
android/jni/NativeApp.cpp
|
||||
android/jni/EmuScreen.cpp
|
||||
android/jni/TestRunner.cpp
|
||||
android/jni/MenuScreens.cpp
|
||||
android/jni/GamepadEmu.cpp
|
||||
android/jni/UIShader.cpp
|
||||
@@ -970,13 +1000,21 @@ file(INSTALL ${NativeAssets} DESTINATION assets)
|
||||
|
||||
# packaging and code signing
|
||||
if (IOS)
|
||||
file(GLOB IOSAssets ios/assets/*.png)
|
||||
file(INSTALL
|
||||
${IOSAssets}
|
||||
DESTINATION assets)
|
||||
file(INSTALL flash0 DESTINATION assets)
|
||||
set(RSRC_XIB_FILES assets/Icon@2x.png)
|
||||
SET_SOURCE_FILES_PROPERTIES(${RSRC_XIB_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
|
||||
set(APP_DIR_NAME \${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME})
|
||||
add_custom_command(TARGET PPSSPP POST_BUILD
|
||||
COMMAND tar -c -C . --exclude .DS_Store --exclude .git -H `find assets` | tar -x -C ${APP_DIR_NAME}
|
||||
COMMAND tar -c -C . --exclude .DS_Store --exclude .git -H `find assets` | tar -x -C '${APP_DIR_NAME}'
|
||||
)
|
||||
set_target_properties(${TargetBin} PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST "../ios/PPSSPP-Info.plist"
|
||||
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "iPhone/iPad"
|
||||
)
|
||||
set_target_properties(${TargetBin} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "../ios/PPSSPP-Info.plist" XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer: My Name")
|
||||
endif()
|
||||
|
||||
#include(CPack)
|
||||
@@ -139,8 +139,10 @@ void CPUInfo::Detect()
|
||||
bVFPv3 = CheckCPUFeature("vfpv3");
|
||||
bTLS = CheckCPUFeature("tls");
|
||||
bVFPv4 = CheckCPUFeature("vfpv4");
|
||||
bIDIVa = CheckCPUFeature("idiva");
|
||||
bIDIVt = CheckCPUFeature("idivt");
|
||||
// On some buggy kernels(Qualcomm) they show that they support VFPv4 but not IDIVa
|
||||
// All VFPv4 CPUs will support IDIVa
|
||||
bIDIVa = bVFPv4 || CheckCPUFeature("idiva");
|
||||
bIDIVt = bVFPv4 || CheckCPUFeature("idivt");
|
||||
// These two require ARMv8 or higher
|
||||
bFP = CheckCPUFeature("fp");
|
||||
bASIMD = CheckCPUFeature("asimd");
|
||||
@@ -155,11 +157,12 @@ void CPUInfo::Detect()
|
||||
#ifdef __SYMBIAN32__
|
||||
bThumbEE = false;
|
||||
bNEON = false;
|
||||
bVFPv3 = false;
|
||||
#else
|
||||
bThumbEE = true;
|
||||
bNEON = true;
|
||||
#endif
|
||||
bVFPv3 = true;
|
||||
#endif
|
||||
bTLS = true;
|
||||
bVFPv4 = false;
|
||||
bIDIVa = false;
|
||||
|
||||
+425
-116
@@ -83,65 +83,104 @@ bool TryMakeOperand2_AllowNegation(s32 imm, Operand2 &op2, bool *negated)
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::MOVI2F(ARMReg dest, float val, ARMReg tempReg)
|
||||
{
|
||||
union {float f; u32 u;} conv;
|
||||
conv.f = val;
|
||||
MOVI2R(tempReg, conv.u);
|
||||
VMOV(dest, tempReg);
|
||||
// TODO: VMOV an IMM directly if possible
|
||||
// Otherwise, use a literal pool and VLDR directly (+- 1020)
|
||||
}
|
||||
|
||||
void ARMXEmitter::ANDI2R(ARMReg rd, ARMReg rs, u32 val, ARMReg scratch)
|
||||
{
|
||||
Operand2 op2;
|
||||
bool inverse;
|
||||
if (TryMakeOperand2_AllowInverse(val, op2, &inverse)) {
|
||||
if (!inverse) {
|
||||
AND(rd, rs, op2);
|
||||
} else {
|
||||
BIC(rd, rs, op2);
|
||||
}
|
||||
} else {
|
||||
MOVI2R(scratch, val);
|
||||
AND(rd, rs, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::ORI2R(ARMReg rd, ARMReg rs, u32 val, ARMReg scratch)
|
||||
{
|
||||
Operand2 op2;
|
||||
if (TryMakeOperand2(val, op2)) {
|
||||
ORR(rd, rs, op2);
|
||||
} else {
|
||||
MOVI2R(scratch, val);
|
||||
ORR(rd, rs, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::FlushLitPool()
|
||||
{
|
||||
for(std::vector<LiteralPool>::iterator it = currentLitPool.begin(); it != currentLitPool.end(); ++it) {
|
||||
// Search for duplicates
|
||||
for(std::vector<LiteralPool>::iterator old_it = currentLitPool.begin(); old_it != it; ++old_it) {
|
||||
if ((*old_it).val == (*it).val)
|
||||
(*it).loc = (*old_it).loc;
|
||||
}
|
||||
|
||||
// Write the constant to Literal Pool
|
||||
if (!(*it).loc)
|
||||
{
|
||||
(*it).loc = (s32)code;
|
||||
Write32((*it).val);
|
||||
}
|
||||
s32 offset = (*it).loc - (s32)(*it).ldr_address - 8;
|
||||
|
||||
// Backpatch the LDR
|
||||
*(u32*)(*it).ldr_address |= (offset >= 0) << 23 | abs(offset);
|
||||
}
|
||||
// TODO: Save a copy of previous pools in case they are still in range.
|
||||
currentLitPool.clear();
|
||||
}
|
||||
|
||||
void ARMXEmitter::AddNewLit(u32 val)
|
||||
{
|
||||
LiteralPool pool_item;
|
||||
pool_item.loc = 0;
|
||||
pool_item.val = val;
|
||||
pool_item.ldr_address = code;
|
||||
currentLitPool.push_back(pool_item);
|
||||
}
|
||||
|
||||
void ARMXEmitter::MOVI2R(ARMReg reg, u32 val, bool optimize)
|
||||
{
|
||||
Operand2 op2;
|
||||
bool inverse;
|
||||
if (!optimize)
|
||||
|
||||
if (cpu_info.bArmV7 && !optimize)
|
||||
{
|
||||
// Only used in backpatch atm
|
||||
// Only support ARMv7 right now
|
||||
if (cpu_info.bArmV7) {
|
||||
MOVW(reg, val & 0xFFFF);
|
||||
MOVT(reg, val, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ARMv6 version won't use backpatch for now
|
||||
// Run again with optimizations
|
||||
MOVI2R(reg, val);
|
||||
}
|
||||
} else if (TryMakeOperand2_AllowInverse(val, op2, &inverse)) {
|
||||
if (!inverse)
|
||||
MOV(reg, op2);
|
||||
else
|
||||
MVN(reg, op2);
|
||||
// For backpatching on ARMv7
|
||||
MOVW(reg, val & 0xFFFF);
|
||||
MOVT(reg, val, true);
|
||||
}
|
||||
else if (TryMakeOperand2_AllowInverse(val, op2, &inverse)) {
|
||||
inverse ? MVN(reg, op2) : MOV(reg, op2);
|
||||
} else {
|
||||
if (cpu_info.bArmV7) {
|
||||
// ARMv7 - can use MOVT/MOVW, best choice
|
||||
if (cpu_info.bArmV7)
|
||||
{
|
||||
// Use MOVW+MOVT for ARMv7+
|
||||
MOVW(reg, val & 0xFFFF);
|
||||
if(val & 0xFFFF0000)
|
||||
MOVT(reg, val, true);
|
||||
} else {
|
||||
// ARMv6 - fallback sequence.
|
||||
// TODO: Optimize further. Can for example choose negation etc.
|
||||
// Literal pools is another way to do this but much more complicated
|
||||
// so I can't really be bothered for an outdated CPU architecture like ARMv6.
|
||||
bool first = true;
|
||||
int shift = 16;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (val & 0xFF) {
|
||||
if (first) {
|
||||
MOV(reg, Operand2((u8)val, (u8)(shift & 0xF)));
|
||||
first = false;
|
||||
} else {
|
||||
ORR(reg, reg, Operand2((u8)val, (u8)(shift & 0xF)));
|
||||
}
|
||||
}
|
||||
shift -= 4;
|
||||
val >>= 8;
|
||||
}
|
||||
// Use literal pool for ARMv6.
|
||||
AddNewLit(val);
|
||||
LDR(reg, _PC); // To be backpatched later
|
||||
}
|
||||
}
|
||||
}
|
||||
// Moves IMM to memory location
|
||||
void ARMXEmitter::ARMABI_MOVI2M(Operand2 op, Operand2 val)
|
||||
{
|
||||
// This moves imm to a memory location
|
||||
MOVW(R14, val); MOVT(R14, val, true);
|
||||
MOVW(R12, op); MOVT(R12, op, true);
|
||||
STR(R12, R14); // R10 is what we want to store
|
||||
}
|
||||
|
||||
void ARMXEmitter::QuickCallFunction(ARMReg reg, void *func) {
|
||||
MOVI2R(reg, (u32)(func));
|
||||
BL(reg);
|
||||
@@ -151,9 +190,7 @@ void ARMXEmitter::SetCodePtr(u8 *ptr)
|
||||
{
|
||||
code = ptr;
|
||||
startcode = code;
|
||||
#ifdef IOS
|
||||
lastCacheFlushEnd = ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
const u8 *ARMXEmitter::GetCodePtr() const
|
||||
@@ -197,8 +234,8 @@ void ARMXEmitter::FlushIcacheSection(u8 *start, u8 *end)
|
||||
#elif defined(BLACKBERRY)
|
||||
msync(start, end - start, MS_SYNC | MS_INVALIDATE_ICACHE);
|
||||
#elif defined(IOS)
|
||||
if (start != NULL)
|
||||
sys_cache_control(kCacheFunctionPrepareForExecution, start, end - start);
|
||||
// Header file says this is equivalent to: sys_icache_invalidate(start, end - start);
|
||||
sys_cache_control(kCacheFunctionPrepareForExecution, start, end - start);
|
||||
#elif !defined(_WIN32)
|
||||
__builtin___clear_cache(start, end);
|
||||
#endif
|
||||
@@ -475,6 +512,7 @@ void ARMXEmitter::LSL (ARMReg dest, ARMReg src, Operand2 op2) { WriteShiftedData
|
||||
void ARMXEmitter::LSLS(ARMReg dest, ARMReg src, Operand2 op2) { WriteShiftedDataOp(0, true, dest, src, op2);}
|
||||
void ARMXEmitter::LSL (ARMReg dest, ARMReg src, ARMReg op2) { WriteShiftedDataOp(1, false, dest, src, op2);}
|
||||
void ARMXEmitter::LSLS(ARMReg dest, ARMReg src, ARMReg op2) { WriteShiftedDataOp(1, true, dest, src, op2);}
|
||||
void ARMXEmitter::LSR (ARMReg dest, ARMReg src, Operand2 op2) { WriteShiftedDataOp(3, false, dest, src, op2);}
|
||||
void ARMXEmitter::MUL (ARMReg dest, ARMReg src, ARMReg op2)
|
||||
{
|
||||
Write32(condition | (dest << 16) | (src << 8) | (9 << 4) | op2);
|
||||
@@ -498,10 +536,38 @@ void ARMXEmitter::SMULL(ARMReg destLo, ARMReg destHi, ARMReg rm, ARMReg rn)
|
||||
Write4OpMultiply(0xC, destLo, destHi, rn, rm);
|
||||
}
|
||||
|
||||
void ARMXEmitter::UMLAL(ARMReg destLo, ARMReg destHi, ARMReg rm, ARMReg rn)
|
||||
{
|
||||
Write4OpMultiply(0xA, destLo, destHi, rn, rm);
|
||||
}
|
||||
|
||||
void ARMXEmitter::SMLAL(ARMReg destLo, ARMReg destHi, ARMReg rm, ARMReg rn)
|
||||
{
|
||||
Write4OpMultiply(0xE, destLo, destHi, rn, rm);
|
||||
}
|
||||
|
||||
void ARMXEmitter::UBFX(ARMReg dest, ARMReg rn, u8 lsb, u8 width)
|
||||
{
|
||||
Write32(condition | (0x7E0 << 16) | ((width - 1) << 16) | (dest << 12) | (lsb << 7) | (5 << 4) | rn);
|
||||
}
|
||||
|
||||
void ARMXEmitter::CLZ(ARMReg rd, ARMReg rm)
|
||||
{
|
||||
Write32(condition | (0x16F << 16) | (rd << 12) | (0xF1 << 4) | rm);
|
||||
}
|
||||
|
||||
void ARMXEmitter::BFI(ARMReg rd, ARMReg rn, u8 lsb, u8 width)
|
||||
{
|
||||
u32 msb = (lsb + width - 1);
|
||||
if (msb > 31) msb = 31;
|
||||
Write32(condition | (0x7C0 << 16) | (msb << 16) | (rd << 12) | (lsb << 7) | (1 << 4) | rn);
|
||||
}
|
||||
|
||||
void ARMXEmitter::SXTB (ARMReg dest, ARMReg op2)
|
||||
{
|
||||
Write32(condition | (0x6AF << 16) | (dest << 12) | (7 << 4) | op2);
|
||||
}
|
||||
|
||||
void ARMXEmitter::SXTH (ARMReg dest, ARMReg op2, u8 rotation)
|
||||
{
|
||||
SXTAH(dest, (ARMReg)15, op2, rotation);
|
||||
@@ -512,9 +578,13 @@ void ARMXEmitter::SXTAH(ARMReg dest, ARMReg src, ARMReg op2, u8 rotation)
|
||||
// information
|
||||
Write32(condition | (0x6B << 20) | (src << 16) | (dest << 12) | (rotation << 10) | (7 << 4) | op2);
|
||||
}
|
||||
void ARMXEmitter::REV (ARMReg dest, ARMReg src )
|
||||
void ARMXEmitter::RBIT(ARMReg dest, ARMReg src)
|
||||
{
|
||||
Write32(condition | (107 << 20) | (15 << 16) | (dest << 12) | (243 << 4) | src);
|
||||
Write32(condition | (0x6F << 20) | (0xF << 16) | (dest << 12) | (0xF3 << 4) | src);
|
||||
}
|
||||
void ARMXEmitter::REV (ARMReg dest, ARMReg src)
|
||||
{
|
||||
Write32(condition | (0x6B << 20) | (0xF << 16) | (dest << 12) | (0xF3 << 4) | src);
|
||||
}
|
||||
void ARMXEmitter::REV16(ARMReg dest, ARMReg src)
|
||||
{
|
||||
@@ -534,27 +604,14 @@ void ARMXEmitter::MRS (ARMReg dest)
|
||||
Write32(condition | (16 << 20) | (15 << 16) | (dest << 12));
|
||||
}
|
||||
|
||||
void ARMXEmitter::WriteStoreOp(u32 op, ARMReg dest, ARMReg src, Operand2 op2)
|
||||
{
|
||||
if (op2.GetData() == 0) // set the preindex bit, but not the W bit!
|
||||
Write32(condition | 0x01800000 | (op << 20) | (dest << 16) | (src << 12) | op2.Imm12());
|
||||
else
|
||||
Write32(condition | (op << 20) | (3 << 23) | (dest << 16) | (src << 12) | op2.Imm12());
|
||||
}
|
||||
void ARMXEmitter::STR (ARMReg dest, ARMReg src, Operand2 op) { WriteStoreOp(0x40, dest, src, op);}
|
||||
void ARMXEmitter::STRB(ARMReg dest, ARMReg src, Operand2 op) { WriteStoreOp(0x44, dest, src, op);}
|
||||
void ARMXEmitter::STR (ARMReg dest, ARMReg base, ARMReg offset, bool Index, bool Add)
|
||||
{
|
||||
Write32(condition | (0x60 << 20) | (Index << 24) | (Add << 23) | (dest << 16) | (base << 12) | offset);
|
||||
}
|
||||
void ARMXEmitter::LDREX(ARMReg dest, ARMReg base)
|
||||
{
|
||||
Write32(condition | (25 << 20) | (base << 16) | (dest << 12) | 0xF9F);
|
||||
}
|
||||
void ARMXEmitter::STREX(ARMReg dest, ARMReg base, ARMReg op)
|
||||
void ARMXEmitter::STREX(ARMReg result, ARMReg base, ARMReg op)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, (dest != base && dest != op), "STREX dest can't be other two registers");
|
||||
Write32(condition | (24 << 20) | (base << 16) | (dest << 12) | (0xF9 << 4) | op);
|
||||
_assert_msg_(DYNA_REC, (result != base && result != op), "STREX dest can't be other two registers");
|
||||
Write32(condition | (24 << 20) | (base << 16) | (result << 12) | (0xF9 << 4) | op);
|
||||
}
|
||||
void ARMXEmitter::DMB ()
|
||||
{
|
||||
@@ -564,19 +621,120 @@ void ARMXEmitter::SVC(Operand2 op)
|
||||
{
|
||||
Write32(condition | (0x0F << 24) | op.Imm24());
|
||||
}
|
||||
// IMM, REG, IMMSREG, RSR
|
||||
// -1 for invalid if the instruction doesn't support that
|
||||
const s32 LoadStoreOps[][4] = {
|
||||
{0x40, 0x60, 0x60, -1}, // STR
|
||||
{0x41, 0x61, 0x61, -1}, // LDR
|
||||
{0x44, 0x64, 0x64, -1}, // STRB
|
||||
{0x45, 0x65, 0x65, -1}, // LDRB
|
||||
// Special encodings
|
||||
{ 0x4, 0x0, -1, -1}, // STRH
|
||||
{ 0x5, 0x1, -1, -1}, // LDRH
|
||||
{ 0x5, 0x1, -1, -1}, // LDRSB
|
||||
{ 0x5, 0x1, -1, -1}, // LDRSH
|
||||
};
|
||||
const char *LoadStoreNames[] = {
|
||||
"STR",
|
||||
"LDR",
|
||||
"STRB",
|
||||
"LDRB",
|
||||
"STRH",
|
||||
"LDRH",
|
||||
"LDRSB",
|
||||
"LDRSH",
|
||||
};
|
||||
|
||||
void ARMXEmitter::LDR (ARMReg dest, ARMReg src, Operand2 op) { WriteStoreOp(0x41, src, dest, op);}
|
||||
void ARMXEmitter::LDRH(ARMReg dest, ARMReg src, Operand2 op)
|
||||
void ARMXEmitter::WriteStoreOp(u32 Op, ARMReg Rt, ARMReg Rn, Operand2 Rm, bool RegAdd)
|
||||
{
|
||||
u8 Imm = op.Imm8();
|
||||
Write32(condition | (0x05 << 20) | (src << 16) | (dest << 12) | ((Imm >> 4) << 8) | (0xB << 4) | (Imm & 0x0F));
|
||||
}
|
||||
void ARMXEmitter::LDRB(ARMReg dest, ARMReg src, Operand2 op) { WriteStoreOp(0x45, src, dest, op);}
|
||||
s32 op = LoadStoreOps[Op][Rm.GetType()]; // Type always decided by last operand
|
||||
u32 Data;
|
||||
|
||||
void ARMXEmitter::LDR (ARMReg dest, ARMReg base, ARMReg offset, bool Index, bool Add)
|
||||
{
|
||||
Write32(condition | (0x61 << 20) | (Index << 24) | (Add << 23) | (base << 16) | (dest << 12) | offset);
|
||||
// Qualcomm chipsets get /really/ angry if you don't use index, even if the offset is zero.
|
||||
// Some of these encodings require Index at all times anyway. Doesn't really matter.
|
||||
// bool Index = op2 != 0 ? true : false;
|
||||
bool Index = true;
|
||||
bool Add = false;
|
||||
|
||||
// Special Encoding (misc addressing mode)
|
||||
bool SpecialOp = false;
|
||||
bool Half = false;
|
||||
bool SignedLoad = false;
|
||||
|
||||
if (op == -1)
|
||||
_assert_msg_(DYNA_REC, false, "%s does not support %d", LoadStoreNames[Op], Rm.GetType());
|
||||
|
||||
switch (Op)
|
||||
{
|
||||
case 4: // STRH
|
||||
SpecialOp = true;
|
||||
Half = true;
|
||||
SignedLoad = false;
|
||||
break;
|
||||
case 5: // LDRH
|
||||
SpecialOp = true;
|
||||
Half = true;
|
||||
SignedLoad = false;
|
||||
break;
|
||||
case 6: // LDRSB
|
||||
SpecialOp = true;
|
||||
Half = false;
|
||||
SignedLoad = true;
|
||||
break;
|
||||
case 7: // LDRSH
|
||||
SpecialOp = true;
|
||||
Half = true;
|
||||
SignedLoad = true;
|
||||
break;
|
||||
}
|
||||
switch (Rm.GetType())
|
||||
{
|
||||
case TYPE_IMM:
|
||||
{
|
||||
s32 Temp = (s32)Rm.Value;
|
||||
Data = abs(Temp);
|
||||
// The offset is encoded differently on this one.
|
||||
if (SpecialOp)
|
||||
Data = (Data & 0xF0 << 4) | (Data & 0xF);
|
||||
if (Temp >= 0) Add = true;
|
||||
}
|
||||
break;
|
||||
case TYPE_REG:
|
||||
Data = Rm.GetData();
|
||||
Add = RegAdd;
|
||||
break;
|
||||
case TYPE_IMMSREG:
|
||||
if (!SpecialOp)
|
||||
{
|
||||
Data = Rm.GetData();
|
||||
Add = RegAdd;
|
||||
break;
|
||||
}
|
||||
// Intentional fallthrough: TYPE_IMMSREG not supported for misc addressing.
|
||||
default:
|
||||
// RSR not supported for any of these
|
||||
// We already have the warning above
|
||||
BKPT(0x2);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
if (SpecialOp)
|
||||
{
|
||||
// Add SpecialOp things
|
||||
Data = (0x9 << 4) | (SignedLoad << 6) | (Half << 5) | Data;
|
||||
}
|
||||
Write32(condition | (op << 20) | (Index << 24) | (Add << 23) | (Rn << 16) | (Rt << 12) | Data);
|
||||
}
|
||||
|
||||
void ARMXEmitter::LDR (ARMReg dest, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(1, dest, base, op2, RegAdd);}
|
||||
void ARMXEmitter::LDRB(ARMReg dest, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(3, dest, base, op2, RegAdd);}
|
||||
void ARMXEmitter::LDRH(ARMReg dest, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(5, dest, base, op2, RegAdd);}
|
||||
void ARMXEmitter::LDRSB(ARMReg dest, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(6, dest, base, op2, RegAdd);}
|
||||
void ARMXEmitter::LDRSH(ARMReg dest, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(7, dest, base, op2, RegAdd);}
|
||||
void ARMXEmitter::STR (ARMReg result, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(0, result, base, op2, RegAdd);}
|
||||
void ARMXEmitter::STRH (ARMReg result, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(4, result, base, op2, RegAdd);}
|
||||
void ARMXEmitter::STRB (ARMReg result, ARMReg base, Operand2 op2, bool RegAdd) { WriteStoreOp(2, result, base, op2, RegAdd);}
|
||||
|
||||
void ARMXEmitter::WriteRegStoreOp(u32 op, ARMReg dest, bool WriteBack, u16 RegList)
|
||||
{
|
||||
Write32(condition | (op << 20) | (WriteBack << 21) | (dest << 16) | RegList);
|
||||
@@ -626,19 +784,22 @@ ARMReg ARMXEmitter::SubBase(ARMReg Reg)
|
||||
}
|
||||
return Reg;
|
||||
}
|
||||
|
||||
// NEON Specific
|
||||
void ARMXEmitter::VADD(IntegerSize Size, ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Vd >= Q0, "Pass invalid register to VADD(integer)");
|
||||
_assert_msg_(DYNA_REC, Vd >= D0, "Pass invalid register to VADD(integer)");
|
||||
_assert_msg_(DYNA_REC, cpu_info.bNEON, "Can't use VADD(integer) when CPU doesn't support it");
|
||||
|
||||
bool register_quad = Vd >= Q0;
|
||||
|
||||
// Gets encoded as a double register
|
||||
Vd = SubBase(Vd);
|
||||
Vn = SubBase(Vn);
|
||||
Vm = SubBase(Vm);
|
||||
|
||||
Write32((0xF2 << 24) | ((Vd & 0x10) << 18) | (Size << 20) | ((Vn & 0xF) << 16) \
|
||||
| ((Vd & 0xF) << 12) | (0x8 << 8) | ((Vn & 0x10) << 3) | (1 << 6) \
|
||||
| ((Vd & 0xF) << 12) | (0x8 << 8) | ((Vn & 0x10) << 3) | (register_quad << 6) \
|
||||
| ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
|
||||
}
|
||||
@@ -655,54 +816,66 @@ void ARMXEmitter::VSUB(IntegerSize Size, ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
Write32((0xF3 << 24) | ((Vd & 0x10) << 18) | (Size << 20) | ((Vn & 0xF) << 16) \
|
||||
| ((Vd & 0xF) << 12) | (0x8 << 8) | ((Vn & 0x10) << 3) | (1 << 6) \
|
||||
| ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
|
||||
}
|
||||
|
||||
// VFP Specific
|
||||
|
||||
void ARMXEmitter::VLDR(ARMReg Dest, ARMReg Base, Operand2 op)
|
||||
void ARMXEmitter::VLDR(ARMReg Dest, ARMReg Base, u16 offset)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Dest >= S0 && Dest <= D31, "Passed Invalid dest register to VLDR");
|
||||
_assert_msg_(DYNA_REC, Base <= R15, "Passed invalid Base register to VLDR");
|
||||
_assert_msg_(DYNA_REC, !(op.Imm12() & 4), "Offset needs to be word aligned");
|
||||
_assert_msg_(DYNA_REC, (offset & 0xC03) == 0, "VLDR: Offset needs to be word aligned and small enough");
|
||||
|
||||
if (offset & 0xC03) {
|
||||
ERROR_LOG(DYNA_REC, "VLDR: Bad offset %08x", offset);
|
||||
}
|
||||
|
||||
// ERROR_LOG(DYNA_REC, "VLDR: s%i, r%i + %i", Dest - S0, Base, offset);
|
||||
|
||||
bool single_reg = Dest < D0;
|
||||
|
||||
Dest = SubBase(Dest);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1B << 23) | ((Dest & 0x1) << 22) | (1 << 20) | (Base << 16) \
|
||||
| ((Dest & 0x1E) << 11) | (10 << 8) | (op.Imm12() >> 2));
|
||||
Write32(condition | (0x1B << 23) | ((Dest & 0x1) << 22) | (1 << 20) | (Base << 16) \
|
||||
| ((Dest & 0x1E) << 11) | (10 << 8) | (offset >> 2));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1B << 23) | ((Dest & 0x10) << 18) | (1 << 20) | (Base << 16) \
|
||||
| ((Dest & 0xF) << 12) | (11 << 8) | (op.Imm12() >> 2));
|
||||
Write32(condition | (0x1B << 23) | ((Dest & 0x10) << 18) | (1 << 20) | (Base << 16) \
|
||||
| ((Dest & 0xF) << 12) | (11 << 8) | (offset >> 2));
|
||||
}
|
||||
}
|
||||
void ARMXEmitter::VSTR(ARMReg Src, ARMReg Base, Operand2 op)
|
||||
void ARMXEmitter::VSTR(ARMReg Src, ARMReg Base, u16 offset)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Src >= S0 && Src <= D31, "Passed invalid src register to VSTR");
|
||||
_assert_msg_(DYNA_REC, Base <= R15, "Passed invalid base register to VSTR");
|
||||
_assert_msg_(DYNA_REC, !(op.Imm12() & 4), "Offset needs to be word aligned");
|
||||
_assert_msg_(DYNA_REC, (offset & 0xC03) == 0, "VSTR: Offset needs to be word aligned");
|
||||
|
||||
if (offset & 0xC03) {
|
||||
ERROR_LOG(DYNA_REC, "VSTR: Bad offset %08x", offset);
|
||||
}
|
||||
// ERROR_LOG(DYNA_REC, "VSTR: s%i, r%i + %i", Src - S0, Base, offset);
|
||||
|
||||
bool single_reg = Src < D0;
|
||||
|
||||
Src = SubBase(Src);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1B << 23) | ((Src & 0x1) << 22) | (Base << 16) \
|
||||
| ((Src & 0x1E) << 11) | (10 << 8) | (op.Imm12() >> 2));
|
||||
Write32(condition | (0x1B << 23) | ((Src & 0x1) << 22) | (Base << 16) \
|
||||
| ((Src & 0x1E) << 11) | (10 << 8) | (offset >> 2));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1B << 23) | ((Src & 0x10) << 18) | (Base << 16) \
|
||||
| ((Src & 0xF) << 12) | (11 << 8) | (op.Imm12() >> 2));
|
||||
Write32(condition | (0x1B << 23) | ((Src & 0x10) << 18) | (Base << 16) \
|
||||
| ((Src & 0xF) << 12) | (11 << 8) | (offset >> 2));
|
||||
}
|
||||
}
|
||||
void ARMXEmitter::VCMP(ARMReg Vd, ARMReg Vm)
|
||||
void ARMXEmitter::VCMP(ARMReg Vd, ARMReg Vm, bool E)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Vd < Q0, "Passed invalid Vd to VCMP");
|
||||
bool single_reg = Vd < D0;
|
||||
@@ -712,16 +885,16 @@ void ARMXEmitter::VCMP(ARMReg Vd, ARMReg Vm)
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x34 << 16) | ((Vd & 0x1E) << 11) \
|
||||
| (0x2B << 6) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x34 << 16) | ((Vd & 0x1E) << 11) \
|
||||
| (E << 7) | (0x29 << 6) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x34 << 16) | ((Vd & 0xF) << 12) \
|
||||
| (0x2F << 6) | ((Vm & 0x10) << 1) | (Vm & 0xF));
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x34 << 16) | ((Vd & 0xF) << 12) \
|
||||
| (E << 7) | (0x2C << 6) | ((Vm & 0x10) << 1) | (Vm & 0xF));
|
||||
}
|
||||
}
|
||||
void ARMXEmitter::VCMP(ARMReg Vd)
|
||||
void ARMXEmitter::VCMP(ARMReg Vd, bool E)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Vd < Q0, "Passed invalid Vd to VCMP");
|
||||
bool single_reg = Vd < D0;
|
||||
@@ -730,15 +903,26 @@ void ARMXEmitter::VCMP(ARMReg Vd)
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x35 << 16) | ((Vd & 0x1E) << 11) \
|
||||
| (0x2B << 6));
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x35 << 16) | ((Vd & 0x1E) << 11) \
|
||||
| (E << 7) | (0x29 << 6));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x35 << 16) | ((Vd & 0xF) << 12) \
|
||||
| (0x2F << 6));
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x35 << 16) | ((Vd & 0xF) << 12) \
|
||||
| (E << 7) | (0x2C << 6));
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::VMRS_APSR() {
|
||||
Write32(condition | 0xEF10A10 | (15 << 12));
|
||||
}
|
||||
void ARMXEmitter::VMRS(ARMReg Rt) {
|
||||
Write32(condition | (0xEF << 20) | (1 << 16) | (Rt << 12) | 0xA10);
|
||||
}
|
||||
void ARMXEmitter::VMSR(ARMReg Rt) {
|
||||
Write32(condition | (0xEE << 20) | (1 << 16) | (Rt << 12) | 0xA10);
|
||||
}
|
||||
|
||||
void ARMXEmitter::VDIV(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Vd < Q0, "Pased invalid dest register to VSQRT");
|
||||
@@ -752,13 +936,13 @@ void ARMXEmitter::VDIV(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x1) << 22) | ((Vn & 0x1E) << 16) \
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x1) << 22) | ((Vn & 0x1E) << 15) \
|
||||
| ((Vd & 0x1E) << 11) | (0xA << 8) | ((Vn & 0x1) << 7) | ((Vm & 0x1) << 5) \
|
||||
| (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x10) << 18) | ((Vn & 0xF) << 16) \
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x10) << 18) | ((Vn & 0xF) << 16) \
|
||||
| ((Vd & 0xF) << 12) | (0xB << 8) | ((Vn & 0x10) << 3) | ((Vm & 0x10) << 2) \
|
||||
| (Vm & 0xF));
|
||||
}
|
||||
@@ -774,15 +958,16 @@ void ARMXEmitter::VSQRT(ARMReg Vd, ARMReg Vm)
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x31 << 16) \
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x31 << 16) \
|
||||
| ((Vd & 0x1E) << 11) | (0x2B << 6) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x31 << 16) \
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x31 << 16) \
|
||||
| ((Vd & 0xF) << 12) | (0x2F << 6) | ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
}
|
||||
}
|
||||
|
||||
// VFP and ASIMD
|
||||
void ARMXEmitter::VADD(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
{
|
||||
@@ -798,15 +983,15 @@ void ARMXEmitter::VADD(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1C << 23) | ((Vd & 0x1) << 22) | (0x3 << 20) \
|
||||
| ((Vn & 0x1E) << 15) | ((Vd & 0x1E) << 12) | (0x5 << 9) \
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x1) << 22) | (0x3 << 20) \
|
||||
| ((Vn & 0x1E) << 15) | ((Vd & 0x1E) << 11) | (0x5 << 9) \
|
||||
| ((Vn & 0x1) << 7) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (double_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1C << 23) | ((Vd & 0x10) << 18) | (0x3 << 20) \
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x10) << 18) | (0x3 << 20) \
|
||||
| ((Vn & 0xF) << 16) | ((Vd & 0xF) << 12) | (0xB << 8) \
|
||||
| ((Vn & 0x10) << 3) | ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
}
|
||||
@@ -833,15 +1018,15 @@ void ARMXEmitter::VSUB(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1C << 23) | ((Vd & 0x1) << 22) | (0x3 << 20) \
|
||||
| ((Vn & 0x1E) << 15) | ((Vd & 0x1E) << 12) | (0x5 << 9) \
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x1) << 22) | (0x3 << 20) \
|
||||
| ((Vn & 0x1E) << 15) | ((Vd & 0x1E) << 11) | (0x5 << 9) \
|
||||
| ((Vn & 0x1) << 7) | (1 << 6) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (double_reg)
|
||||
{
|
||||
Write32(NO_COND | (0x1C << 23) | ((Vd & 0x10) << 18) | (0x3 << 20) \
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x10) << 18) | (0x3 << 20) \
|
||||
| ((Vn & 0xF) << 16) | ((Vd & 0xF) << 12) | (0xB << 8) \
|
||||
| ((Vn & 0x10) << 3) | (1 << 6) | ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
}
|
||||
@@ -854,6 +1039,112 @@ void ARMXEmitter::VSUB(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
}
|
||||
}
|
||||
}
|
||||
// VFP and ASIMD
|
||||
void ARMXEmitter::VMUL(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Vd >= S0, "Passed invalid dest register to VADD");
|
||||
_assert_msg_(DYNA_REC, Vn >= S0, "Passed invalid Vn to VADD");
|
||||
_assert_msg_(DYNA_REC, Vm >= S0, "Passed invalid Vm to VADD");
|
||||
bool single_reg = Vd < D0;
|
||||
bool double_reg = Vd < Q0;
|
||||
|
||||
Vd = SubBase(Vd);
|
||||
Vn = SubBase(Vn);
|
||||
Vm = SubBase(Vm);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x1) << 22) | (0x2 << 20) \
|
||||
| ((Vn & 0x1E) << 15) | ((Vd & 0x1E) << 11) | (0x5 << 9) \
|
||||
| ((Vn & 0x1) << 7) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (double_reg)
|
||||
{
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x10) << 18) | (0x2 << 20) \
|
||||
| ((Vn & 0xF) << 16) | ((Vd & 0xF) << 12) | (0xB << 8) \
|
||||
| ((Vn & 0x10) << 3) | ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
}
|
||||
else
|
||||
{
|
||||
_assert_msg_(DYNA_REC, cpu_info.bNEON, "Trying to use VMUL with Quad Reg without support!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::VMLA(ARMReg Vd, ARMReg Vn, ARMReg Vm)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Vd >= S0, "Passed invalid dest register to VMLA");
|
||||
_assert_msg_(DYNA_REC, Vn >= S0, "Passed invalid Vn to VMLA");
|
||||
_assert_msg_(DYNA_REC, Vm >= S0, "Passed invalid Vm to VMLA");
|
||||
bool single_reg = Vd < D0;
|
||||
bool double_reg = Vd < Q0;
|
||||
|
||||
Vd = SubBase(Vd);
|
||||
Vn = SubBase(Vn);
|
||||
Vm = SubBase(Vm);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(condition | (0x1C << 23) | ((Vd & 0x1) << 22) | (0x0 << 20) \
|
||||
| ((Vn & 0x1E) << 15) | ((Vd & 0x1E) << 11) | (0x5 << 9) \
|
||||
| ((Vn & 0x1) << 7) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
_assert_msg_(DYNA_REC, false, "VMLA: Please implement!");
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::VABS(ARMReg Vd, ARMReg Vm)
|
||||
{
|
||||
bool single_reg = Vd < D0;
|
||||
|
||||
Vd = SubBase(Vd);
|
||||
Vm = SubBase(Vm);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x30 << 16) \
|
||||
| ((Vd & 0x1E) << 11) | (0x2B << 6) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x30 << 16) \
|
||||
| ((Vd & 0xF) << 12) | (0x2F << 6) | ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::VNEG(ARMReg Vd, ARMReg Vm)
|
||||
{
|
||||
bool single_reg = Vd < D0;
|
||||
|
||||
Vd = SubBase(Vd);
|
||||
Vm = SubBase(Vm);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x1) << 22) | (0x31 << 16) \
|
||||
| ((Vd & 0x1E) << 11) | (0x29 << 6) | ((Vm & 0x1) << 5) | (Vm >> 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(condition | (0x1D << 23) | ((Vd & 0x10) << 18) | (0x31 << 16) \
|
||||
| ((Vd & 0xF) << 12) | (0x2D << 6) | ((Vm & 0x10) << 2) | (Vm & 0xF));
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::VMOV(ARMReg Dest, ARMReg Src, bool high)
|
||||
{
|
||||
_assert_msg_(DYNA_REC, Src < S0, "This VMOV doesn't support SRC other than ARM Reg");
|
||||
_assert_msg_(DYNA_REC, Dest >= D0, "This VMOV doesn't support DEST other than VFP");
|
||||
|
||||
Dest = SubBase(Dest);
|
||||
|
||||
Write32(condition | (0xE << 24) | (high << 21) | ((Dest & 0xF) << 16) | (Src << 12) \
|
||||
| (11 << 8) | ((Dest & 0x10) << 3) | (1 << 4));
|
||||
}
|
||||
|
||||
void ARMXEmitter::VMOV(ARMReg Dest, ARMReg Src)
|
||||
{
|
||||
@@ -865,7 +1156,7 @@ void ARMXEmitter::VMOV(ARMReg Dest, ARMReg Src)
|
||||
{
|
||||
// Moving to a Neon register FROM ARM Reg
|
||||
Dest = (ARMReg)(Dest - S0);
|
||||
Write32(NO_COND | (0xE0 << 20) | ((Dest & 0x1E) << 15) | (Src << 12) \
|
||||
Write32(condition | (0xE0 << 20) | ((Dest & 0x1E) << 15) | (Src << 12) \
|
||||
| (0xA << 8) | ((Dest & 0x1) << 7) | (1 << 4));
|
||||
return;
|
||||
}
|
||||
@@ -885,7 +1176,7 @@ void ARMXEmitter::VMOV(ARMReg Dest, ARMReg Src)
|
||||
{
|
||||
// Moving to ARM Reg from Neon Register
|
||||
Src = (ARMReg)(Src - S0);
|
||||
Write32(NO_COND | (0xE1 << 20) | ((Src & 0x1E) << 15) | (Dest << 12) \
|
||||
Write32(condition | (0xE1 << 20) | ((Src & 0x1E) << 15) | (Dest << 12) \
|
||||
| (0xA << 8) | ((Src & 0x1) << 7) | (1 << 4));
|
||||
return;
|
||||
}
|
||||
@@ -915,7 +1206,7 @@ void ARMXEmitter::VMOV(ARMReg Dest, ARMReg Src)
|
||||
|
||||
if (Single)
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Dest & 0x1) << 22) | (0x3 << 20) | ((Dest & 0x1E) << 11) \
|
||||
Write32(condition | (0x1D << 23) | ((Dest & 0x1) << 22) | (0x3 << 20) | ((Dest & 0x1E) << 11) \
|
||||
| (0x5 << 9) | (1 << 6) | ((Src & 0x1) << 5) | ((Src & 0x1E) >> 1));
|
||||
}
|
||||
else
|
||||
@@ -932,10 +1223,28 @@ void ARMXEmitter::VMOV(ARMReg Dest, ARMReg Src)
|
||||
}
|
||||
else
|
||||
{
|
||||
Write32(NO_COND | (0x1D << 23) | ((Dest & 0x10) << 18) | (0x3 << 20) | ((Dest & 0xF) << 12) \
|
||||
Write32(condition | (0x1D << 23) | ((Dest & 0x10) << 18) | (0x3 << 20) | ((Dest & 0xF) << 12) \
|
||||
| (0x2D << 6) | ((Src & 0x10) << 1) | (Src & 0xF));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ARMXEmitter::VCVT(ARMReg Dest, ARMReg Source, int flags)
|
||||
{
|
||||
bool single_reg = (Dest < D0) && (Source < D0);
|
||||
int op = ((flags & TO_INT) ? (flags & ROUND_TO_ZERO) : (flags & IS_SIGNED)) ? 1 : 0;
|
||||
int op2 = ((flags & TO_INT) ? (flags & IS_SIGNED) : 0) ? 1 : 0;
|
||||
Dest = SubBase(Dest);
|
||||
Source = SubBase(Source);
|
||||
|
||||
if (single_reg)
|
||||
{
|
||||
Write32(condition | (0x1D << 23) | ((Dest & 0x1) << 22) | (0x7 << 19) | ((flags & TO_INT) << 18) | (op2 << 16) \
|
||||
| ((Dest & 0x1E) << 11) | (op << 7) | (0x29 << 6) | ((Source & 0x1) << 5) | (Source >> 1));
|
||||
} else {
|
||||
Write32(condition | (0x1D << 23) | ((Dest & 0x10) << 18) | (0x7 << 19) | ((flags & TO_INT) << 18) | (op2 << 16) \
|
||||
| ((Dest & 0xF) << 12) | (1 << 8) | (op << 7) | (0x29 << 6) | ((Source & 0x10) << 1) | (Source & 0xF));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+68
-21
@@ -25,6 +25,7 @@
|
||||
#if defined(__SYMBIAN32__) || defined(PANDORA)
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
#undef _IP
|
||||
#undef R0
|
||||
@@ -32,6 +33,12 @@
|
||||
#undef _LR
|
||||
#undef _PC
|
||||
|
||||
// VCVT flags
|
||||
#define TO_FLOAT 0
|
||||
#define TO_INT 1 << 0
|
||||
#define IS_SIGNED 1 << 1
|
||||
#define ROUND_TO_ZERO 1 << 2
|
||||
|
||||
namespace ArmGen
|
||||
{
|
||||
enum ARMReg
|
||||
@@ -171,7 +178,7 @@ public:
|
||||
Value = base;
|
||||
}
|
||||
|
||||
Operand2(u8 shift, ShiftType type, ARMReg base)// For IMM shifted register
|
||||
Operand2(ARMReg base, ShiftType type, u8 shift)// For IMM shifted register
|
||||
{
|
||||
if(shift == 32) shift = 0;
|
||||
switch (type)
|
||||
@@ -327,6 +334,13 @@ struct FixupBranch
|
||||
int type; //0 = B 1 = BL
|
||||
};
|
||||
|
||||
struct LiteralPool
|
||||
{
|
||||
s32 loc;
|
||||
u8* ldr_address;
|
||||
u32 val;
|
||||
};
|
||||
|
||||
typedef const u8* JumpTarget;
|
||||
|
||||
class ARMXEmitter
|
||||
@@ -336,8 +350,9 @@ private:
|
||||
u8 *code, *startcode;
|
||||
u8 *lastCacheFlushEnd;
|
||||
u32 condition;
|
||||
std::vector<LiteralPool> currentLitPool;
|
||||
|
||||
void WriteStoreOp(u32 op, ARMReg dest, ARMReg src, Operand2 op2);
|
||||
void WriteStoreOp(u32 Op, ARMReg Rt, ARMReg Rn, Operand2 op2, bool RegAdd);
|
||||
void WriteRegStoreOp(u32 op, ARMReg dest, bool WriteBack, u16 RegList);
|
||||
void WriteShiftedDataOp(u32 op, bool SetFlags, ARMReg dest, ARMReg src, ARMReg op2);
|
||||
void WriteShiftedDataOp(u32 op, bool SetFlags, ARMReg dest, ARMReg src, Operand2 op2);
|
||||
@@ -373,6 +388,10 @@ public:
|
||||
void FlushIcacheSection(u8 *start, u8 *end);
|
||||
u8 *GetWritableCodePtr();
|
||||
|
||||
void FlushLitPool();
|
||||
void AddNewLit(u32 val);
|
||||
|
||||
CCFlags GetCC() { return CCFlags(condition >> 28); }
|
||||
void SetCC(CCFlags cond = CC_AL);
|
||||
|
||||
// Special purpose instructions
|
||||
@@ -425,8 +444,10 @@ public:
|
||||
void LSL (ARMReg dest, ARMReg src, ARMReg op2);
|
||||
void LSLS(ARMReg dest, ARMReg src, Operand2 op2);
|
||||
void LSLS(ARMReg dest, ARMReg src, ARMReg op2);
|
||||
void LSR (ARMReg dest, ARMReg src, Operand2 op2);
|
||||
void SBC (ARMReg dest, ARMReg src, Operand2 op2);
|
||||
void SBCS(ARMReg dest, ARMReg src, Operand2 op2);
|
||||
void RBIT(ARMReg dest, ARMReg src);
|
||||
void REV (ARMReg dest, ARMReg src);
|
||||
void REV16 (ARMReg dest, ARMReg src);
|
||||
void RSC (ARMReg dest, ARMReg src, Operand2 op2);
|
||||
@@ -457,33 +478,39 @@ public:
|
||||
void UMULL(ARMReg destLo, ARMReg destHi, ARMReg rn, ARMReg rm);
|
||||
void SMULL(ARMReg destLo, ARMReg destHi, ARMReg rn, ARMReg rm);
|
||||
|
||||
void UMLAL(ARMReg destLo, ARMReg destHi, ARMReg rn, ARMReg rm);
|
||||
void SMLAL(ARMReg destLo, ARMReg destHi, ARMReg rn, ARMReg rm);
|
||||
|
||||
void SXTB(ARMReg dest, ARMReg op2);
|
||||
void SXTH(ARMReg dest, ARMReg op2, u8 rotation = 0);
|
||||
void SXTAH(ARMReg dest, ARMReg src, ARMReg op2, u8 rotation = 0);
|
||||
void BFI(ARMReg rd, ARMReg rn, u8 lsb, u8 width);
|
||||
void UBFX(ARMReg dest, ARMReg op2, u8 lsb, u8 width);
|
||||
void CLZ(ARMReg rd, ARMReg rm);
|
||||
|
||||
// Using just MSR here messes with our defines on the PPC side of stuff (when this code was in dolphin...)
|
||||
// Just need to put an underscore here, bit annoying.
|
||||
void _MSR (bool nzcvq, bool g, Operand2 op2);
|
||||
void _MSR (bool nzcvq, bool g, ARMReg src );
|
||||
void _MSR (bool nzcvq, bool g, ARMReg src);
|
||||
void MRS (ARMReg dest);
|
||||
|
||||
// Memory load/store operations
|
||||
void LDR (ARMReg dest, ARMReg src, Operand2 op2 = 0);
|
||||
// Offset adds to the base register in LDR
|
||||
void LDR (ARMReg dest, ARMReg base, ARMReg offset, bool Index, bool Add);
|
||||
void LDRH(ARMReg dest, ARMReg src, Operand2 op = 0);
|
||||
void LDRB(ARMReg dest, ARMReg src, Operand2 op2 = 0);
|
||||
void STR (ARMReg dest, ARMReg src, Operand2 op2 = 0);
|
||||
// Offset adds on to the destination register in STR
|
||||
void STR (ARMReg dest, ARMReg base, ARMReg offset, bool Index, bool Add);
|
||||
void LDR (ARMReg dest, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void LDRB (ARMReg dest, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void LDRH (ARMReg dest, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void LDRSB(ARMReg dest, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void LDRSH(ARMReg dest, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void STR (ARMReg result, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void STRB (ARMReg result, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
void STRH (ARMReg result, ARMReg base, Operand2 op2 = 0, bool RegAdd = true);
|
||||
|
||||
void STRB(ARMReg dest, ARMReg src, Operand2 op2 = 0);
|
||||
void STMFD(ARMReg dest, bool WriteBack, const int Regnum, ...);
|
||||
void LDMFD(ARMReg dest, bool WriteBack, const int Regnum, ...);
|
||||
|
||||
// Exclusive Access operations
|
||||
void LDREX(ARMReg dest, ARMReg base);
|
||||
// dest contains the result if the instruction managed to store the value
|
||||
void STREX(ARMReg dest, ARMReg base, ARMReg op);
|
||||
// result contains the result if the instruction managed to store the value
|
||||
void STREX(ARMReg result, ARMReg base, ARMReg op);
|
||||
void DMB ();
|
||||
void SVC(Operand2 op);
|
||||
|
||||
@@ -499,23 +526,39 @@ public:
|
||||
void VSUB(IntegerSize Size, ARMReg Vd, ARMReg Vn, ARMReg Vm);
|
||||
|
||||
// VFP Only
|
||||
void VLDR(ARMReg Dest, ARMReg Base, Operand2 op);
|
||||
void VSTR(ARMReg Src, ARMReg Base, Operand2 op);
|
||||
void VCMP(ARMReg Vd, ARMReg Vm);
|
||||
void VLDR(ARMReg Dest, ARMReg Base, u16 offset);
|
||||
void VSTR(ARMReg Src, ARMReg Base, u16 offset);
|
||||
void VCMP(ARMReg Vd, ARMReg Vm, bool E);
|
||||
// Compares against zero
|
||||
void VCMP(ARMReg Vd);
|
||||
void VCMP(ARMReg Vd, bool E);
|
||||
void VDIV(ARMReg Vd, ARMReg Vn, ARMReg Vm);
|
||||
void VSQRT(ARMReg Vd, ARMReg Vm);
|
||||
|
||||
// NEON and VFP
|
||||
void VADD(ARMReg Vd, ARMReg Vn, ARMReg Vm);
|
||||
void VSUB(ARMReg Vd, ARMReg Vn, ARMReg Vm);
|
||||
void VABS(ARMReg Vd, ARMReg Vm);
|
||||
void VNEG(ARMReg Vd, ARMReg Vm);
|
||||
void VMUL(ARMReg Vd, ARMReg Vn, ARMReg Vm);
|
||||
void VMLA(ARMReg Vd, ARMReg Vn, ARMReg Vm);
|
||||
void VMOV(ARMReg Dest, ARMReg Src, bool high);
|
||||
void VMOV(ARMReg Dest, ARMReg Src);
|
||||
void VCVT(ARMReg Dest, ARMReg Src, int flags);
|
||||
|
||||
void VMRS_APSR();
|
||||
void VMRS(ARMReg Rt);
|
||||
void VMSR(ARMReg Rt);
|
||||
|
||||
void QuickCallFunction(ARMReg scratchreg, void *func);
|
||||
// Utility functions
|
||||
|
||||
// Wrapper around MOVT/MOVW with fallbacks.
|
||||
void MOVI2R(ARMReg reg, u32 val, bool optimize = true);
|
||||
void ARMABI_MOVI2M(Operand2 op, Operand2 val);
|
||||
void MOVI2F(ARMReg dest, float val, ARMReg tempReg);
|
||||
|
||||
void ANDI2R(ARMReg rd, ARMReg rs, u32 val, ARMReg scratch);
|
||||
void ORI2R(ARMReg rd, ARMReg rs, u32 val, ARMReg scratch);
|
||||
|
||||
|
||||
}; // class ARMXEmitter
|
||||
|
||||
|
||||
@@ -568,7 +611,11 @@ public:
|
||||
// Start over if you need to change the code (call FreeCodeSpace(), AllocCodeSpace()).
|
||||
void WriteProtect()
|
||||
{
|
||||
WriteProtectMemory(region, region_size, true);
|
||||
WriteProtectMemory(region, region_size, true);
|
||||
}
|
||||
void UnWriteProtect()
|
||||
{
|
||||
UnWriteProtectMemory(region, region_size, false);
|
||||
}
|
||||
|
||||
void ResetCodePtr()
|
||||
|
||||
@@ -52,4 +52,6 @@ void ThunkManager::Shutdown()
|
||||
|
||||
void *ThunkManager::ProtectFunction(void *function, int num_params)
|
||||
{
|
||||
_dbg_assert_msg_(JIT, false, "Arm ThunkManager not implemented? Will crash.");
|
||||
return NULL;
|
||||
}
|
||||
@@ -29,14 +29,14 @@
|
||||
#undef _interlockedbittestandreset64
|
||||
#else
|
||||
|
||||
#ifndef _M_GENERIC
|
||||
#if !defined(_M_GENERIC) && !defined(MIPS)
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
|
||||
#if defined __FreeBSD__
|
||||
#include <sys/types.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#else
|
||||
#elif !defined(MIPS)
|
||||
static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
|
||||
unsigned int *ecx, unsigned int *edx)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4100)
|
||||
#endif
|
||||
|
||||
#if defined(ARM)
|
||||
#define _M_ARM32
|
||||
#endif
|
||||
@@ -77,7 +81,9 @@ private:
|
||||
#error needs at least version 1000 of MSC
|
||||
#endif
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
// Memory leak checks
|
||||
#define CHECK_HEAP_INTEGRITY()
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#define SLEEP(x) usleep(x*1000)
|
||||
#endif
|
||||
|
||||
#ifdef IOS
|
||||
#if defined(IOS) || defined(MIPS)
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
@@ -51,8 +51,8 @@ template<> struct CompileTimeAssert<true> {};
|
||||
#ifdef GEKKO
|
||||
#define Crash()
|
||||
#else
|
||||
// Assume !ARM = x86
|
||||
#if !defined(ARM)
|
||||
// Assume !ARM && !MIPS = x86
|
||||
#if !defined(ARM) && !defined(MIPS)
|
||||
#define Crash() {asm ("int $3");}
|
||||
#else
|
||||
#define Crash() {kill( getpid(), SIGINT ) ; }
|
||||
|
||||
+2
-2
@@ -89,9 +89,9 @@ int AES_set_encrypt_key(const unsigned char* userKey, const int bits,
|
||||
int AES_set_decrypt_key(const unsigned char* userKey, const int bits,
|
||||
AES_KEY* key);
|
||||
|
||||
void AES_encrypt(const unsigned char* in, unsigned char* out,
|
||||
void AES_encrypt1(const unsigned char* in, unsigned char* out,
|
||||
const AES_KEY* key);
|
||||
void AES_decrypt(const unsigned char* in, unsigned char* out,
|
||||
void AES_decrypt1(const unsigned char* in, unsigned char* out,
|
||||
const AES_KEY* key);
|
||||
|
||||
void AES_ecb_encrypt(const unsigned char* in, unsigned char* out,
|
||||
|
||||
@@ -75,7 +75,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
for(n=0; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] = in[n] ^ iv[n];
|
||||
AES_encrypt(out, out, key);
|
||||
AES_encrypt1(out, out, key);
|
||||
iv = out;
|
||||
len -= AES_BLOCK_SIZE;
|
||||
in += AES_BLOCK_SIZE;
|
||||
@@ -86,13 +86,13 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
out[n] = in[n] ^ iv[n];
|
||||
for(n=len; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] = iv[n];
|
||||
AES_encrypt(out, out, key);
|
||||
AES_encrypt1(out, out, key);
|
||||
iv = out;
|
||||
}
|
||||
memcpy(ivec,iv,AES_BLOCK_SIZE);
|
||||
} else if (in != out) {
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
AES_decrypt(in, out, key);
|
||||
AES_decrypt1(in, out, key);
|
||||
for(n=0; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] ^= iv[n];
|
||||
iv = in;
|
||||
@@ -101,7 +101,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
out += AES_BLOCK_SIZE;
|
||||
}
|
||||
if (len) {
|
||||
AES_decrypt(in,tmp,key);
|
||||
AES_decrypt1(in,tmp,key);
|
||||
for(n=0; n < len; ++n)
|
||||
out[n] = tmp[n] ^ iv[n];
|
||||
iv = in;
|
||||
@@ -110,7 +110,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
} else {
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
AES_decrypt(in, out, key);
|
||||
AES_decrypt1(in, out, key);
|
||||
for(n=0; n < AES_BLOCK_SIZE; ++n)
|
||||
out[n] ^= ivec[n];
|
||||
memcpy(ivec, tmp, AES_BLOCK_SIZE);
|
||||
@@ -120,7 +120,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
}
|
||||
if (len) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
AES_decrypt(tmp, out, key);
|
||||
AES_decrypt1(tmp, out, key);
|
||||
for(n=0; n < len; ++n)
|
||||
out[n] ^= ivec[n];
|
||||
for(n=len; n < AES_BLOCK_SIZE; ++n)
|
||||
|
||||
@@ -778,7 +778,7 @@ int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
|
||||
* Encrypt a single block
|
||||
* in and out can overlap
|
||||
*/
|
||||
void AES_encrypt(const unsigned char *in, unsigned char *out,
|
||||
void AES_encrypt1(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key) {
|
||||
|
||||
const u32 *rk;
|
||||
@@ -969,7 +969,7 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
|
||||
* Decrypt a single block
|
||||
* in and out can overlap
|
||||
*/
|
||||
void AES_decrypt(const unsigned char *in, unsigned char *out,
|
||||
void AES_decrypt1(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key) {
|
||||
|
||||
const u32 *rk;
|
||||
|
||||
+8
-5
@@ -22,6 +22,7 @@
|
||||
#define WARNING_LEVEL 3 // Something is suspicious.
|
||||
#define INFO_LEVEL 4 // General information.
|
||||
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
|
||||
#define VERBOSE_LEVEL 6 // Noisy debugging - sometimes needed but usually unimportant.
|
||||
|
||||
#if !defined(_WIN32) && !defined(PANDORA)
|
||||
#include <signal.h>
|
||||
@@ -64,6 +65,7 @@ enum LOG_LEVELS {
|
||||
LWARNING = WARNING_LEVEL,
|
||||
LINFO = INFO_LEVEL,
|
||||
LDEBUG = DEBUG_LEVEL,
|
||||
LVERBOSE = VERBOSE_LEVEL,
|
||||
};
|
||||
|
||||
#define LOGTYPES_LEVELS LogTypes::LOG_LEVELS
|
||||
@@ -92,11 +94,12 @@ void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type,
|
||||
GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define ERROR_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) }
|
||||
#define WARN_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) }
|
||||
#define NOTICE_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) }
|
||||
#define INFO_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) }
|
||||
#define DEBUG_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) }
|
||||
#define ERROR_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) }
|
||||
#define WARN_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) }
|
||||
#define NOTICE_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) }
|
||||
#define INFO_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) }
|
||||
#define DEBUG_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) }
|
||||
#define VERBOSE_LOG(t,...) { GENERIC_LOG(LogTypes::t, LogTypes::LVERBOSE, __VA_ARGS__) }
|
||||
|
||||
#if MAX_LOGLEVEL >= DEBUG_LEVEL
|
||||
#define _dbg_assert_(_t_, _a_) \
|
||||
|
||||
+36
-6
@@ -26,9 +26,12 @@
|
||||
#include <e32debug.h>
|
||||
#endif
|
||||
|
||||
// Don't need to savestate this.
|
||||
const char *hleCurrentThreadName = NULL;
|
||||
|
||||
// Unfortunately this is quite slow.
|
||||
// #define LOG_MSC_OUTPUTDEBUG true
|
||||
#define LOG_MSC_OUTPUTDEBUG false
|
||||
// #define LOG_MSC_OUTPUTDEBUG true
|
||||
|
||||
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
||||
const char *file, int line, const char* fmt, ...)
|
||||
@@ -165,15 +168,42 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const
|
||||
if (!log || !log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners())
|
||||
return;
|
||||
|
||||
static const char level_to_char[7] = "-NEWID";
|
||||
static const char level_to_char[8] = "-NEWIDV";
|
||||
char formattedTime[13];
|
||||
Common::Timer::GetTimeFormatted(formattedTime);
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifdef _WIN32
|
||||
static const char sep = '\\';
|
||||
#else
|
||||
static const char sep = '/';
|
||||
#endif
|
||||
const char *fileshort = strrchr(file, sep);
|
||||
if (fileshort != NULL) {
|
||||
do
|
||||
--fileshort;
|
||||
while (fileshort > file && *fileshort != sep);
|
||||
if (fileshort != file)
|
||||
file = fileshort + 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *msgPos = msg;
|
||||
msgPos += sprintf(msgPos, "%s %s:%d %c[%s]: ",
|
||||
formattedTime,
|
||||
file, line, level_to_char[(int)level],
|
||||
log->GetShortName());
|
||||
if (hleCurrentThreadName != NULL)
|
||||
{
|
||||
msgPos += sprintf(msgPos, "%s %-12.12s %c[%s]: %s:%d ",
|
||||
formattedTime,
|
||||
hleCurrentThreadName, level_to_char[(int)level],
|
||||
log->GetShortName(),
|
||||
file, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
msgPos += sprintf(msgPos, "%s %s:%d %c[%s]: ",
|
||||
formattedTime,
|
||||
file, line, level_to_char[(int)level],
|
||||
log->GetShortName());
|
||||
}
|
||||
|
||||
msgPos += vsnprintf(msgPos, MAX_MSGLEN, format, args);
|
||||
// This will include the null terminator.
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#define MAX_MESSAGES 8000
|
||||
#define MAX_MSGLEN 1024
|
||||
|
||||
extern const char *hleCurrentThreadName;
|
||||
|
||||
// pure virtual interface
|
||||
class LogListener
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#ifndef ARM
|
||||
#if !defined(ARM) && !defined(MIPS)
|
||||
#define USE_SSE
|
||||
#endif
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
|
||||
if (low && (!map_hint))
|
||||
map_hint = (char*)round_page(512*1024*1024); /* 0.5 GB rounded up to the next page */
|
||||
#endif
|
||||
void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
||||
MAP_ANON | MAP_PRIVATE
|
||||
#if defined(__x86_64__) && defined(MAP_32BIT)
|
||||
| (low ? MAP_32BIT : 0)
|
||||
|
||||
@@ -21,6 +21,7 @@ set(SRCS
|
||||
ELF/ElfReader.cpp
|
||||
ELF/ParamSFO.cpp
|
||||
ELF/PrxDecrypter.cpp
|
||||
Font/PGF.cpp
|
||||
HLE/HLE.cpp
|
||||
HLE/HLETables.cpp
|
||||
HLE/sceAtrac.cpp
|
||||
@@ -51,6 +52,7 @@ set(SRCS
|
||||
HLE/sceKernelVTimer.cpp
|
||||
HLE/sceMpeg.cpp
|
||||
HLE/sceNet.cpp
|
||||
HLE/sceP3da.cpp
|
||||
HLE/scePower.cpp
|
||||
HLE/scePsmf.cpp
|
||||
HLE/sceRtc.cpp
|
||||
@@ -84,6 +86,7 @@ set(SRCS
|
||||
PSPMixer.cpp
|
||||
System.cpp
|
||||
Core.cpp
|
||||
../git-version.cpp
|
||||
)
|
||||
|
||||
if(ARM)
|
||||
@@ -114,6 +117,17 @@ add_library(core STATIC ${SRCS})
|
||||
target_link_libraries(core general common)
|
||||
target_link_libraries(core general base)
|
||||
|
||||
# Generate git-version.cpp at build time.
|
||||
add_custom_target(GitVersion ALL
|
||||
DEPENDS something_that_never_exists)
|
||||
add_custom_command(OUTPUT something_that_never_exists
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/../git-version.cmake)
|
||||
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../git-version.cpp
|
||||
PROPERTIES GENERATED TRUE)
|
||||
add_dependencies(core GitVersion)
|
||||
|
||||
if(UNIX)
|
||||
add_definitions(-fPIC)
|
||||
add_definitions(-std=gnu++0x)
|
||||
|
||||
+8
-2
@@ -54,6 +54,8 @@ void CConfig::Load(const char *iniFileName)
|
||||
general->Get("IgnoreBadMemAccess", &bIgnoreBadMemAccess, true);
|
||||
general->Get("CurrentDirectory", ¤tDirectory, "");
|
||||
general->Get("ShowDebuggerOnLoad", &bShowDebuggerOnLoad, false);
|
||||
// "default" means let emulator decide, "" means disable.
|
||||
general->Get("ReportHost", &sReportHost, "default");
|
||||
|
||||
IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU");
|
||||
cpu->Get("Jit", &bJit, true);
|
||||
@@ -70,12 +72,12 @@ void CConfig::Load(const char *iniFileName)
|
||||
graphics->Get("SSAA", &SSAntiAliasing, 0);
|
||||
graphics->Get("VBO", &bUseVBO, false);
|
||||
graphics->Get("FrameSkip", &iFrameSkip, 0);
|
||||
graphics->Get("UseMediaEngine", &bUseMediaEngine, true);
|
||||
#ifdef USING_GLES2
|
||||
graphics->Get("AnisotropyLevel", &iAnisotropyLevel, 0);
|
||||
#else
|
||||
graphics->Get("AnisotropyLevel", &iAnisotropyLevel, 8);
|
||||
#endif
|
||||
graphics->Get("DisableG3DLog", &bDisableG3DLog, false);
|
||||
graphics->Get("VertexCache", &bVertexCache, true);
|
||||
graphics->Get("FullScreen", &bFullScreen, false);
|
||||
graphics->Get("StretchToDisplay", &bStretchToDisplay, false);
|
||||
@@ -94,6 +96,7 @@ void CConfig::Load(const char *iniFileName)
|
||||
#endif
|
||||
control->Get("LargeControls", &bLargeControls, false);
|
||||
control->Get("KeyMapping",iMappingMap);
|
||||
control->Get("AccelerometerToAnalogHoriz", &bAccelerometerToAnalogHoriz, false);
|
||||
|
||||
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
|
||||
pspConfig->Get("Language", &ilanguage, PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
|
||||
@@ -121,6 +124,8 @@ void CConfig::Save()
|
||||
general->Set("IgnoreBadMemAccess", bIgnoreBadMemAccess);
|
||||
general->Set("CurrentDirectory", currentDirectory);
|
||||
general->Set("ShowDebuggerOnLoad", bShowDebuggerOnLoad);
|
||||
general->Set("ReportHost", sReportHost);
|
||||
|
||||
IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU");
|
||||
cpu->Set("Jit", bJit);
|
||||
cpu->Set("FastMemory", bFastMemory);
|
||||
@@ -135,8 +140,8 @@ void CConfig::Save()
|
||||
graphics->Set("SSAA", SSAntiAliasing);
|
||||
graphics->Set("VBO", bUseVBO);
|
||||
graphics->Set("FrameSkip", iFrameSkip);
|
||||
graphics->Set("UseMediaEngine", bUseMediaEngine);
|
||||
graphics->Set("AnisotropyLevel", iAnisotropyLevel);
|
||||
graphics->Set("DisableG3DLog", bDisableG3DLog);
|
||||
graphics->Set("VertexCache", bVertexCache);
|
||||
graphics->Set("FullScreen", bFullScreen);
|
||||
graphics->Set("StretchToDisplay", bStretchToDisplay);
|
||||
@@ -150,6 +155,7 @@ void CConfig::Save()
|
||||
control->Set("ShowTouchControls", bShowTouchControls);
|
||||
control->Set("LargeControls", bLargeControls);
|
||||
control->Set("KeyMapping",iMappingMap);
|
||||
control->Set("AccelerometerToAnalogHoriz", bAccelerometerToAnalogHoriz);
|
||||
|
||||
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
|
||||
pspConfig->Set("Language", ilanguage);
|
||||
|
||||
+4
-3
@@ -20,8 +20,7 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#define PPSSPP_VERSION_STR "0.6.1"
|
||||
|
||||
extern const char *PPSSPP_GIT_VERSION;
|
||||
|
||||
struct SState
|
||||
{
|
||||
@@ -50,6 +49,7 @@ public:
|
||||
bool bIgnoreBadMemAccess;
|
||||
bool bFastMemory;
|
||||
bool bJit;
|
||||
std::string sReportHost;
|
||||
|
||||
// GFX
|
||||
bool bDisplayFramebuffer;
|
||||
@@ -60,10 +60,10 @@ public:
|
||||
bool bUseVBO;
|
||||
bool bStretchToDisplay;
|
||||
int iFrameSkip; // 0 = off; 1 = auto; (future: 2 = skip every 2nd frame; 3 = skip every 3rd frame etc).
|
||||
bool bUseMediaEngine;
|
||||
|
||||
int iWindowZoom; // for Windows
|
||||
bool SSAntiAliasing; //for Windows, too
|
||||
bool bDisableG3DLog;
|
||||
bool bVertexCache;
|
||||
bool bFullScreen;
|
||||
int iAnisotropyLevel;
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
bool bShowFPSCounter;
|
||||
bool bShowDebugStats;
|
||||
bool bLargeControls;
|
||||
bool bAccelerometerToAnalogHoriz;
|
||||
|
||||
// Control
|
||||
std::map<int,int> iMappingMap; // Can be used differently depending on systems
|
||||
|
||||
+28
-3
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
@@ -74,6 +74,10 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>../Windows/git-version-gen.cmd</Command>
|
||||
<Message>Updating git-version.cpp</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
@@ -87,6 +91,10 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>../Windows/git-version-gen.cmd</Command>
|
||||
<Message>Updating git-version.cpp</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
@@ -105,6 +113,11 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<CustomBuildStep />
|
||||
<PreBuildEvent>
|
||||
<Command>../Windows/git-version-gen.cmd</Command>
|
||||
<Message>Updating git-version.cpp</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
@@ -121,11 +134,16 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>../Windows/git-version-gen.cmd</Command>
|
||||
<Message>Updating git-version.cpp</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\ext\disarm.cpp" />
|
||||
<ClCompile Include="..\ext\snappy\snappy-c.cpp" />
|
||||
<ClCompile Include="..\ext\snappy\snappy.cpp" />
|
||||
<ClCompile Include="..\git-version.cpp" />
|
||||
<ClCompile Include="Config.cpp" />
|
||||
<ClCompile Include="Core.cpp" />
|
||||
<ClCompile Include="CoreTiming.cpp" />
|
||||
@@ -145,6 +163,7 @@
|
||||
<ClCompile Include="FileSystems\DirectoryFileSystem.cpp" />
|
||||
<ClCompile Include="FileSystems\ISOFileSystem.cpp" />
|
||||
<ClCompile Include="FileSystems\MetaFileSystem.cpp" />
|
||||
<ClCompile Include="Font\PGF.cpp" />
|
||||
<ClCompile Include="HLE\HLE.cpp" />
|
||||
<ClCompile Include="HLE\HLETables.cpp" />
|
||||
<ClCompile Include="HLE\sceAtrac.cpp" />
|
||||
@@ -179,6 +198,8 @@
|
||||
<ClCompile Include="HLE\sceParseUri.cpp" />
|
||||
<ClCompile Include="HLE\scePower.cpp" />
|
||||
<ClCompile Include="HLE\scePsmf.cpp" />
|
||||
<ClCompile Include="HLE\scePspNpDrm_user.cpp" />
|
||||
<ClCompile Include="HLE\sceP3da.cpp" />
|
||||
<ClCompile Include="HLE\sceRtc.cpp" />
|
||||
<ClCompile Include="HLE\sceSas.cpp" />
|
||||
<ClCompile Include="HLE\sceSsl.cpp" />
|
||||
@@ -277,6 +298,7 @@
|
||||
<ClCompile Include="MIPS\x86\RegCache.cpp" />
|
||||
<ClCompile Include="PSPLoaders.cpp" />
|
||||
<ClCompile Include="PSPMixer.cpp" />
|
||||
<ClCompile Include="Reporting.cpp" />
|
||||
<ClCompile Include="SaveState.cpp" />
|
||||
<ClCompile Include="System.cpp" />
|
||||
<ClCompile Include="Util\BlockAllocator.cpp" />
|
||||
@@ -313,6 +335,7 @@
|
||||
<ClInclude Include="FileSystems\FileSystem.h" />
|
||||
<ClInclude Include="FileSystems\ISOFileSystem.h" />
|
||||
<ClInclude Include="FileSystems\MetaFileSystem.h" />
|
||||
<ClInclude Include="Font\PGF.h" />
|
||||
<ClInclude Include="HLE\FunctionWrappers.h" />
|
||||
<ClInclude Include="HLE\HLE.h" />
|
||||
<ClInclude Include="HLE\HLETables.h" />
|
||||
@@ -347,6 +370,8 @@
|
||||
<ClInclude Include="HLE\sceParseUri.h" />
|
||||
<ClInclude Include="HLE\scePower.h" />
|
||||
<ClInclude Include="HLE\scePsmf.h" />
|
||||
<ClInclude Include="HLE\scePspNpDrm_user.h" />
|
||||
<ClInclude Include="HLE\sceP3da.h" />
|
||||
<ClInclude Include="HLE\sceRtc.h" />
|
||||
<ClInclude Include="HLE\sceSas.h" />
|
||||
<ClInclude Include="HLE\sceSsl.h" />
|
||||
@@ -410,10 +435,10 @@
|
||||
<ClInclude Include="MIPS\x86\RegCache.h" />
|
||||
<ClInclude Include="PSPLoaders.h" />
|
||||
<ClInclude Include="PSPMixer.h" />
|
||||
<ClInclude Include="Reporting.h" />
|
||||
<ClInclude Include="SaveState.h" />
|
||||
<ClInclude Include="System.h" />
|
||||
<ClInclude Include="Util\BlockAllocator.h" />
|
||||
<ClInclude Include="Util\Pool.h" />
|
||||
<ClInclude Include="Util\PPGeDraw.h" />
|
||||
<ClInclude Include="Util\ppge_atlas.h" />
|
||||
</ItemGroup>
|
||||
@@ -440,4 +465,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="ELF">
|
||||
@@ -49,6 +49,9 @@
|
||||
<Filter Include="Ext\Snappy">
|
||||
<UniqueIdentifier>{0b77054f-7fc7-4c33-ada3-762aecde69e5}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Font">
|
||||
<UniqueIdentifier>{1c79e88d-1c48-450b-8af6-f22ce7d40c66}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ELF\ElfReader.cpp">
|
||||
@@ -189,6 +192,9 @@
|
||||
<ClCompile Include="HLE\sceMpeg.cpp">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HLE\sceP3da.cpp">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HLE\sceNet.cpp">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClCompile>
|
||||
@@ -376,6 +382,16 @@
|
||||
<Filter>MIPS\ARM</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HLE\sceChnnlsv.cpp" />
|
||||
<ClCompile Include="Font\PGF.cpp">
|
||||
<Filter>Font</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\git-version.cpp" />
|
||||
<ClCompile Include="Reporting.cpp">
|
||||
<Filter>Core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HLE\scePspNpDrm_user.cpp">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ELF\ElfReader.h">
|
||||
@@ -510,6 +526,9 @@
|
||||
<ClInclude Include="HLE\sceMpeg.h">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HLE\sceP3da.h">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HLE\sceNet.h">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClInclude>
|
||||
@@ -534,9 +553,6 @@
|
||||
<ClInclude Include="Util\BlockAllocator.h">
|
||||
<Filter>Util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Util\Pool.h">
|
||||
<Filter>Util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Debugger\Breakpoints.h">
|
||||
<Filter>Debugger</Filter>
|
||||
</ClInclude>
|
||||
@@ -697,6 +713,15 @@
|
||||
<Filter>MIPS\ARM</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HLE\sceChnnlsv.h" />
|
||||
<ClInclude Include="Font\PGF.h">
|
||||
<Filter>Font</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Reporting.h">
|
||||
<Filter>Core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HLE\scePspNpDrm_user.h">
|
||||
<Filter>HLE\Libraries</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="CMakeLists.txt" />
|
||||
@@ -704,4 +729,4 @@
|
||||
<None Include="..\android\jni\Android.mk" />
|
||||
<None Include="GameLogNotes.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -33,6 +33,7 @@ enum GPUCore {
|
||||
|
||||
struct CoreParameter
|
||||
{
|
||||
CoreParameter() : collectEmuLog(0) {}
|
||||
// 0 = Interpreter
|
||||
// 1 = Jit
|
||||
// 2 = JitIL
|
||||
@@ -47,6 +48,7 @@ struct CoreParameter
|
||||
bool disableG3Dlog;
|
||||
bool enableDebugging; // enables breakpoints and other time-consuming debugger features
|
||||
bool printfEmuLog; // writes "emulator:" logging to stdout
|
||||
std::string *collectEmuLog;
|
||||
bool headLess; // Try to avoid messageboxes etc
|
||||
bool useMediaEngine;
|
||||
|
||||
|
||||
+1
-1
@@ -527,7 +527,7 @@ void Idle(int maxIdle)
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(CPU, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(CPU_HZ * 0.001f));
|
||||
VERBOSE_LOG(CPU, "Idle for %i cycles! (%f ms)", cyclesDown, cyclesDown / (float)(CPU_HZ * 0.001f));
|
||||
|
||||
idledCycles += cyclesDown;
|
||||
currentMIPS->downcount -= cyclesDown;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Breakpoints.h"
|
||||
#include "SymbolMap.h"
|
||||
#include "FixedSizeUnorderedSet.h"
|
||||
#include "Core/Host.h"
|
||||
#include "../MIPS/JitCommon/JitCommon.h"
|
||||
#include <cstdio>
|
||||
|
||||
@@ -34,18 +35,19 @@ MemCheck::MemCheck(void)
|
||||
numHits=0;
|
||||
}
|
||||
|
||||
void MemCheck::Action(u32 iValue, u32 addr, bool write, int size, u32 pc)
|
||||
void MemCheck::Action(u32 addr, bool write, int size, u32 pc)
|
||||
{
|
||||
if ((write && bOnWrite) || (!write && bOnRead))
|
||||
{
|
||||
++numHits;
|
||||
|
||||
if (bLog)
|
||||
{
|
||||
char temp[256];
|
||||
sprintf(temp,"CHK %08x %s%i at %08x (%s), PC=%08x (%s)",iValue,write?"Write":"Read",size*8,addr,symbolMap.GetDescription(addr),pc,symbolMap.GetDescription(pc));
|
||||
ERROR_LOG(MEMMAP,"%s",temp);
|
||||
}
|
||||
NOTICE_LOG(MEMMAP, "CHK %s%i at %08x (%s), PC=%08x (%s)", write ? "Write" : "Read", size * 8, addr, symbolMap.GetDescription(addr), pc, symbolMap.GetDescription(pc));
|
||||
if (bBreak)
|
||||
{
|
||||
Core_Pause();
|
||||
host->SetDebugMode(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,20 +88,21 @@ void CBreakPoints::ClearAllBreakPoints()
|
||||
InvalidateJit();
|
||||
}
|
||||
|
||||
MemCheck *CBreakPoints::GetMemCheck(u32 address)
|
||||
MemCheck *CBreakPoints::GetMemCheck(u32 address, int size)
|
||||
{
|
||||
std::vector<MemCheck>::iterator iter;
|
||||
for (iter = MemChecks.begin(); iter != MemChecks.end(); ++iter)
|
||||
{
|
||||
if ((*iter).bRange)
|
||||
MemCheck &check = *iter;
|
||||
if (check.bRange)
|
||||
{
|
||||
if (address >= (*iter).iStartAddress && address <= (*iter).iEndAddress)
|
||||
return &(*iter);
|
||||
if (address >= check.iStartAddress && address + size < check.iEndAddress)
|
||||
return ✓
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((*iter).iStartAddress==address)
|
||||
return &(*iter);
|
||||
if (check.iStartAddress==address)
|
||||
return ✓
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ struct MemCheck
|
||||
|
||||
u32 numHits;
|
||||
|
||||
void Action(u32 _iValue, u32 addr, bool write, int size, u32 pc);
|
||||
void Action(u32 addr, bool write, int size, u32 pc);
|
||||
};
|
||||
|
||||
class CBreakPoints
|
||||
@@ -60,13 +60,14 @@ private:
|
||||
static u32 m_iBreakOnCount;
|
||||
|
||||
public:
|
||||
// WARNING: Not used in interpreter or HLE, only jit CPU memory access.
|
||||
static std::vector<MemCheck> MemChecks;
|
||||
|
||||
// is address breakpoint
|
||||
static bool IsAddressBreakPoint(u32 _iAddress);
|
||||
|
||||
//memory breakpoint
|
||||
static MemCheck *GetMemCheck(u32 address);
|
||||
// WARNING: Not used in interpreter or HLE, only jit CPU memory access.
|
||||
static MemCheck *GetMemCheck(u32 address, int size);
|
||||
|
||||
// is break on count
|
||||
static bool IsBreakOnCount(u32 _iAddress);
|
||||
|
||||
@@ -208,22 +208,13 @@ void SymbolMap::SaveSymbolMap(const char *filename)
|
||||
|
||||
int SymbolMap::GetSymbolNum(unsigned int address, SymbolType symmask)
|
||||
{
|
||||
size_t start=0;
|
||||
|
||||
for (size_t i = 0; i < entries.size(); i++)
|
||||
for (size_t i = 0, n = entries.size(); i < n; i++)
|
||||
{
|
||||
if (address >= entries[i].vaddress)
|
||||
start = i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
unsigned int addr = entries[i].vaddress;
|
||||
if ((address >= addr))
|
||||
MapEntry &entry = entries[i];
|
||||
unsigned int addr = entry.vaddress;
|
||||
if (address >= addr)
|
||||
{
|
||||
if (address < addr+entries[i].size)
|
||||
if (address < addr + entry.size)
|
||||
{
|
||||
if (entries[i].type & symmask)
|
||||
return (int) i;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "../Util/PPGeDraw.h"
|
||||
#include "../HLE/sceCtrl.h"
|
||||
#include "../Core/MemMap.h"
|
||||
#include "Core/Reporting.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
PSPMsgDialog::PSPMsgDialog()
|
||||
@@ -53,6 +54,7 @@ int PSPMsgDialog::Init(unsigned int paramAddr)
|
||||
if(optionsNotCoded)
|
||||
{
|
||||
ERROR_LOG(HLE,"PSPMsgDialog options not coded : 0x%08x",optionsNotCoded);
|
||||
Reporting::ReportMessage("PSPMsgDialog options not coded: 0x%08x", optionsNotCoded);
|
||||
}
|
||||
|
||||
flag = 0;
|
||||
|
||||
@@ -20,15 +20,19 @@
|
||||
#include "../HLE/sceCtrl.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#define NUMKEYROWS 4
|
||||
#define KEYSPERROW 12
|
||||
#define NUMBEROFVALIDCHARS (KEYSPERROW * NUMKEYROWS)
|
||||
const char oskKeys[NUMKEYROWS][KEYSPERROW + 1] =
|
||||
{
|
||||
{'1','2','3','4','5','6','7','8','9','0','-','+','\0'},
|
||||
{'Q','W','E','R','T','Y','U','I','O','P','[',']','\0'},
|
||||
{'A','S','D','F','G','H','J','K','L',';','@','~','\0'},
|
||||
{'Z','X','C','V','B','N','M',',','.','/','?','\\','\0'},
|
||||
{'q','w','e','r','t','y','u','i','o','p','[',']','\0'},
|
||||
{'a','s','d','f','g','h','j','k','l',';','@','~','\0'},
|
||||
{'z','x','c','v','b','n','m',',','.','/','?','\\','\0'},
|
||||
};
|
||||
|
||||
|
||||
@@ -109,8 +113,8 @@ void PSPOskDialog::RenderKeyboard()
|
||||
limit = 16;
|
||||
|
||||
const float keyboardLeftSide = (480.0f - (24.0f * KEYSPERROW)) / 2.0f;
|
||||
float previewLeftSide = (480.0f - (16.0f * limit)) / 2.0f;
|
||||
float title = (480.0f - limit) / 2.0f;
|
||||
float previewLeftSide = (480.0f - (12.0f * limit)) / 2.0f;
|
||||
float title = (480.0f - (0.5f * limit)) / 2.0f;
|
||||
|
||||
PPGeDrawText(oskDesc.c_str(), title , 20, PPGE_ALIGN_CENTER, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
for (u32 i = 0; i < limit; ++i)
|
||||
@@ -126,7 +130,7 @@ void PSPOskDialog::RenderKeyboard()
|
||||
else
|
||||
temp[0] = '_';
|
||||
|
||||
PPGeDrawText(temp, previewLeftSide + (i * 16.0f), 40.0f, 0, 0.5f, color);
|
||||
PPGeDrawText(temp, previewLeftSide + (i * 12.0f), 40.0f, 0, 0.5f, color);
|
||||
}
|
||||
for (int row = 0; row < NUMKEYROWS; ++row)
|
||||
{
|
||||
@@ -167,15 +171,19 @@ int PSPOskDialog::Update()
|
||||
|
||||
StartDraw();
|
||||
RenderKeyboard();
|
||||
PPGeDrawImage(I_CROSS, 100, 220, 20, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Select", 130, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawImage(I_CROSS, 30, 220, 20, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Select", 60, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
|
||||
PPGeDrawImage(I_CIRCLE, 200, 220, 20, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Delete", 230, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawImage(I_CIRCLE, 130, 220, 20, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Delete", 160, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
|
||||
PPGeDrawImage(I_BUTTON, 290, 220, 50, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Start", 305, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Finish", 350, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawImage(I_BUTTON, 230, 220, 50, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Start", 245, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Finish", 290, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
|
||||
PPGeDrawImage(I_BUTTON, 350, 220, 55, 20, 0, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Select", 365, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
PPGeDrawText("Caps", 410, 220, PPGE_ALIGN_LEFT, 0.5f, CalcFadedColor(0xFFFFFFFF));
|
||||
|
||||
if (IsButtonPressed(CTRL_UP))
|
||||
{
|
||||
@@ -203,7 +211,12 @@ int PSPOskDialog::Update()
|
||||
if (IsButtonPressed(CTRL_CROSS))
|
||||
{
|
||||
if (inputChars.size() < limit)
|
||||
inputChars += oskKeys[selectedRow][selectedExtra];
|
||||
inputChars += oskKeys[selectedRow][selectedExtra];
|
||||
}
|
||||
else if (IsButtonPressed(CTRL_SELECT))
|
||||
{
|
||||
if (inputChars.size() < limit)
|
||||
inputChars += toupper(oskKeys[selectedRow][selectedExtra]);
|
||||
}
|
||||
else if (IsButtonPressed(CTRL_CIRCLE))
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "../HLE/sceCtrl.h"
|
||||
#include "../Core/MemMap.h"
|
||||
#include "../Config.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
PSPSaveDialog::PSPSaveDialog()
|
||||
: PSPDialog()
|
||||
@@ -98,6 +99,7 @@ int PSPSaveDialog::Init(int paramAddr)
|
||||
default:
|
||||
{
|
||||
ERROR_LOG(HLE, "Load/Save function %d not coded. Title: %s Save: %s File: %s", param.GetPspParam()->mode, param.GetGameName(param.GetPspParam()).c_str(), param.GetGameName(param.GetPspParam()).c_str(), param.GetFileName(param.GetPspParam()).c_str());
|
||||
Reporting::ReportMessage("Load/Save function %d not coded. Title: %s Save: %s File: %s", param.GetPspParam()->mode, param.GetGameName(param.GetPspParam()).c_str(), param.GetGameName(param.GetPspParam()).c_str(), param.GetFileName(param.GetPspParam()).c_str());
|
||||
param.GetPspParam()->result = 0;
|
||||
status = SCE_UTILITY_STATUS_INITIALIZE;
|
||||
display = DS_NONE;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "ChunkFile.h"
|
||||
#include "FileUtil.h"
|
||||
#include "DirectoryFileSystem.h"
|
||||
|
||||
#include "file/zip_read.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -517,6 +517,19 @@ bool DirectoryFileSystem::GetHostPath(const std::string &inpath, std::string &ou
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#define FILETIME_FROM_UNIX_EPOCH_US 11644473600000000ULL
|
||||
|
||||
void tmFromFiletime(tm &dest, FILETIME &src)
|
||||
{
|
||||
u64 from_1601_us = (((u64) src.dwHighDateTime << 32ULL) + (u64) src.dwLowDateTime) / 10ULL;
|
||||
u64 from_1970_us = from_1601_us - FILETIME_FROM_UNIX_EPOCH_US;
|
||||
|
||||
time_t t = (time_t) (from_1970_us / 1000000UL);
|
||||
localtime_r(&t, &dest);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
std::vector<PSPFileInfo> myVector;
|
||||
#ifdef _WIN32
|
||||
@@ -537,6 +550,9 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
entry.type = FILETYPE_DIRECTORY;
|
||||
else
|
||||
entry.type = FILETYPE_NORMAL;
|
||||
|
||||
// TODO: Make this more correct?
|
||||
entry.access = entry.type == FILETYPE_NORMAL ? 0666 : 0777;
|
||||
// TODO: is this just for .. or all subdirectories? Need to add a directory to the test
|
||||
// to find out. Also why so different than the old test results?
|
||||
if (!strcmp(findData.cFileName, "..") )
|
||||
@@ -544,6 +560,9 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
else
|
||||
entry.size = findData.nFileSizeLow | ((u64)findData.nFileSizeHigh<<32);
|
||||
entry.name = findData.cFileName;
|
||||
tmFromFiletime(entry.atime, findData.ftLastAccessTime);
|
||||
tmFromFiletime(entry.ctime, findData.ftCreationTime);
|
||||
tmFromFiletime(entry.mtime, findData.ftLastWriteTime);
|
||||
myVector.push_back(entry);
|
||||
|
||||
int retval = FindNextFile(hFind, &findData);
|
||||
@@ -595,3 +614,153 @@ void DirectoryFileSystem::DoState(PointerWrap &p) {
|
||||
ERROR_LOG(FILESYS, "FIXME: Open files during savestate, could go badly.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VFSFileSystem::VFSFileSystem(IHandleAllocator *_hAlloc, std::string _basePath) : basePath(_basePath) {
|
||||
INFO_LOG(HLE, "Creating VFS file system");
|
||||
hAlloc = _hAlloc;
|
||||
}
|
||||
|
||||
VFSFileSystem::~VFSFileSystem() {
|
||||
for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
|
||||
delete [] iter->second.fileData;
|
||||
}
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
std::string VFSFileSystem::GetLocalPath(std::string localPath) {
|
||||
return basePath + localPath;
|
||||
}
|
||||
|
||||
bool VFSFileSystem::MkDir(const std::string &dirname) {
|
||||
// NOT SUPPORTED - READ ONLY
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VFSFileSystem::RmDir(const std::string &dirname) {
|
||||
// NOT SUPPORTED - READ ONLY
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VFSFileSystem::RenameFile(const std::string &from, const std::string &to) {
|
||||
// NOT SUPPORTED - READ ONLY
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VFSFileSystem::RemoveFile(const std::string &filename) {
|
||||
// NOT SUPPORTED - READ ONLY
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 VFSFileSystem::OpenFile(std::string filename, FileAccess access) {
|
||||
if (access != FILEACCESS_READ) {
|
||||
ERROR_LOG(HLE, "VFSFileSystem only supports plain reading");
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
const char *fullNameC = fullName.c_str();
|
||||
INFO_LOG(HLE,"VFSFileSystem actually opening %s (%s)", fullNameC, filename.c_str());
|
||||
|
||||
size_t size;
|
||||
u8 *data = VFSReadFile(fullNameC, &size);
|
||||
if (!data) {
|
||||
ERROR_LOG(HLE, "VFSFileSystem failed to open %s", filename.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
OpenFileEntry entry;
|
||||
entry.fileData = data;
|
||||
entry.size = size;
|
||||
entry.seekPos = 0;
|
||||
u32 newHandle = hAlloc->GetNewHandle();
|
||||
entries[newHandle] = entry;
|
||||
return newHandle;
|
||||
}
|
||||
|
||||
PSPFileInfo VFSFileSystem::GetFileInfo(std::string filename) {
|
||||
PSPFileInfo x;
|
||||
x.name = filename;
|
||||
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
INFO_LOG(HLE,"Getting VFS file info %s (%s)", fullName.c_str(), filename.c_str());
|
||||
FileInfo fo;
|
||||
VFSGetFileInfo(fullName.c_str(), &fo);
|
||||
x.exists = fo.exists;
|
||||
if (x.exists) {
|
||||
x.size = fo.size;
|
||||
x.type = fo.isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
|
||||
}
|
||||
INFO_LOG(HLE,"Got VFS file info: size = %i", (int)x.size);
|
||||
return x;
|
||||
}
|
||||
|
||||
void VFSFileSystem::CloseFile(u32 handle) {
|
||||
EntryMap::iterator iter = entries.find(handle);
|
||||
if (iter != entries.end()) {
|
||||
delete [] iter->second.fileData;
|
||||
entries.erase(iter);
|
||||
} else {
|
||||
//This shouldn't happen...
|
||||
ERROR_LOG(HLE,"Cannot close file that hasn't been opened: %08x", handle);
|
||||
}
|
||||
}
|
||||
|
||||
bool VFSFileSystem::OwnsHandle(u32 handle) {
|
||||
EntryMap::iterator iter = entries.find(handle);
|
||||
return (iter != entries.end());
|
||||
}
|
||||
|
||||
size_t VFSFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
|
||||
INFO_LOG(HLE,"VFSFileSystem::ReadFile %08x %p %i", handle, pointer, (u32)size);
|
||||
EntryMap::iterator iter = entries.find(handle);
|
||||
if (iter != entries.end())
|
||||
{
|
||||
size_t bytesRead = size;
|
||||
memcpy(pointer, iter->second.fileData + iter->second.seekPos, size);
|
||||
iter->second.seekPos += size;
|
||||
return bytesRead;
|
||||
} else {
|
||||
ERROR_LOG(HLE,"Cannot read file that hasn't been opened: %08x", handle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t VFSFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
|
||||
// NOT SUPPORTED - READ ONLY
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t VFSFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
|
||||
EntryMap::iterator iter = entries.find(handle);
|
||||
if (iter != entries.end()) {
|
||||
switch (type) {
|
||||
case FILEMOVE_BEGIN: iter->second.seekPos = position; break;
|
||||
case FILEMOVE_CURRENT: iter->second.seekPos += position; break;
|
||||
case FILEMOVE_END: iter->second.seekPos = iter->second.size + position; break;
|
||||
}
|
||||
return iter->second.seekPos;
|
||||
} else {
|
||||
//This shouldn't happen...
|
||||
ERROR_LOG(HLE,"Cannot seek in file that hasn't been opened: %08x", handle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool VFSFileSystem::GetHostPath(const std::string &inpath, std::string &outpath) {
|
||||
// NOT SUPPORTED
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<PSPFileInfo> VFSFileSystem::GetDirListing(std::string path) {
|
||||
std::vector<PSPFileInfo> myVector;
|
||||
// TODO
|
||||
return myVector;
|
||||
}
|
||||
|
||||
void VFSFileSystem::DoState(PointerWrap &p) {
|
||||
if (!entries.empty()) {
|
||||
ERROR_LOG(FILESYS, "FIXME: Open files during savestate, could go badly.");
|
||||
}
|
||||
}
|
||||
@@ -95,3 +95,41 @@ private:
|
||||
bool FixPathCase(std::string &path, FixPathCaseBehavior behavior);
|
||||
#endif
|
||||
};
|
||||
|
||||
// VFSFileSystem: Ability to map in Android APK paths as well! Does not support all features, only meant for fonts.
|
||||
// Very inefficient - always load the whole file on open.
|
||||
class VFSFileSystem : public IFileSystem {
|
||||
public:
|
||||
VFSFileSystem(IHandleAllocator *_hAlloc, std::string _basePath);
|
||||
~VFSFileSystem();
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
std::vector<PSPFileInfo> GetDirListing(std::string path);
|
||||
u32 OpenFile(std::string filename, FileAccess access);
|
||||
void CloseFile(u32 handle);
|
||||
size_t ReadFile(u32 handle, u8 *pointer, s64 size);
|
||||
size_t WriteFile(u32 handle, const u8 *pointer, s64 size);
|
||||
size_t SeekFile(u32 handle, s32 position, FileMove type);
|
||||
PSPFileInfo GetFileInfo(std::string filename);
|
||||
bool OwnsHandle(u32 handle);
|
||||
|
||||
bool MkDir(const std::string &dirname);
|
||||
bool RmDir(const std::string &dirname);
|
||||
bool RenameFile(const std::string &from, const std::string &to);
|
||||
bool RemoveFile(const std::string &filename);
|
||||
bool GetHostPath(const std::string &inpath, std::string &outpath);
|
||||
|
||||
private:
|
||||
struct OpenFileEntry {
|
||||
u8 *fileData;
|
||||
size_t size;
|
||||
size_t seekPos;
|
||||
};
|
||||
|
||||
typedef std::map<u32, OpenFileEntry> EntryMap;
|
||||
EntryMap entries;
|
||||
std::string basePath;
|
||||
IHandleAllocator *hAlloc;
|
||||
|
||||
std::string GetLocalPath(std::string localpath);
|
||||
};
|
||||
@@ -559,7 +559,7 @@ std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path)
|
||||
x.size = e->size;
|
||||
x.type = e->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
|
||||
x.isOnSectorSystem = true;
|
||||
x.startSector = entry->startingPosition/2048;
|
||||
x.startSector = e->startingPosition/2048;
|
||||
myVector.push_back(x);
|
||||
}
|
||||
return myVector;
|
||||
|
||||
@@ -0,0 +1,531 @@
|
||||
// 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/.
|
||||
|
||||
// ============== NOTE!!!!
|
||||
|
||||
// Thanks to the JPCSP project! This sceFont implementation is basically a C++ take on JPCSP's font code.
|
||||
// Some parts, especially in this file, were simply copied, so I guess this really makes this file GPL3.
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/MemMap.h"
|
||||
#include "Core/Font/PGF.h"
|
||||
|
||||
// These fonts, created by ttf2pgf, don't have complete glyph info and need to be identified.
|
||||
static bool isJPCSPFont(const char *fontName) {
|
||||
return !strcmp(fontName, "Liberation") || !strcmp(fontName, "Sazanami") || !strcmp(fontName, "UnDotum");
|
||||
}
|
||||
|
||||
// Gets a number of bits from an offset.
|
||||
// TODO: Make more efficient.
|
||||
static int getBits(int numBits, const u8 *buf, size_t pos) {
|
||||
int v = 0;
|
||||
for (int i = 0; i < numBits; i++) {
|
||||
v = v | (((buf[pos >> 3] >> (pos & 7)) & 1) << i);
|
||||
pos++;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static std::vector<int> getTable(const u8 *buf, int bpe, int length) {
|
||||
std::vector<int> vec;
|
||||
vec.resize(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
vec[i] = getBits(bpe, buf, bpe * i);
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
PGF::PGF()
|
||||
: fontData(0), charMap(0), shadowCharMap(0), charPointerTable(0) {
|
||||
|
||||
}
|
||||
|
||||
PGF::~PGF() {
|
||||
delete [] fontData;
|
||||
delete [] charMap;
|
||||
delete [] shadowCharMap;
|
||||
delete [] charPointerTable;
|
||||
}
|
||||
|
||||
void PGF::DoState(PointerWrap &p) {
|
||||
// TODO!
|
||||
}
|
||||
|
||||
void PGF::ReadPtr(const u8 *ptr, size_t dataSize) {
|
||||
const u8 *const startPtr = ptr;
|
||||
|
||||
INFO_LOG(HLE, "Reading %d bytes of PGF header", (int)sizeof(header));
|
||||
memcpy(&header, ptr, sizeof(header));
|
||||
ptr += sizeof(header);
|
||||
|
||||
if (header.revision == 3) {
|
||||
memcpy(&rev3extra, ptr, sizeof(rev3extra));
|
||||
rev3extra.compCharMapLength1 &= 0xFFFF;
|
||||
rev3extra.compCharMapLength2 &= 0xFFFF;
|
||||
ptr += sizeof(rev3extra);
|
||||
}
|
||||
|
||||
const u32 *wptr = (const u32 *)ptr;
|
||||
dimensionTable[0].resize(header.dimTableLength);
|
||||
dimensionTable[1].resize(header.dimTableLength);
|
||||
for (int i = 0; i < header.dimTableLength; i++) {
|
||||
dimensionTable[0][i] = *wptr++;
|
||||
dimensionTable[1][i] = *wptr++;
|
||||
}
|
||||
|
||||
xAdjustTable[0].resize(header.xAdjustTableLength);
|
||||
xAdjustTable[1].resize(header.xAdjustTableLength);
|
||||
for (int i = 0; i < header.xAdjustTableLength; i++) {
|
||||
xAdjustTable[0][i] = *wptr++;
|
||||
xAdjustTable[1][i] = *wptr++;
|
||||
}
|
||||
|
||||
yAdjustTable[0].resize(header.yAdjustTableLength);
|
||||
yAdjustTable[1].resize(header.yAdjustTableLength);
|
||||
for (int i = 0; i < header.yAdjustTableLength; i++) {
|
||||
yAdjustTable[0][i] = *wptr++;
|
||||
yAdjustTable[1][i] = *wptr++;
|
||||
}
|
||||
|
||||
advanceTable[0].resize(header.advanceTableLength);
|
||||
advanceTable[1].resize(header.advanceTableLength);
|
||||
for (int i = 0; i < header.advanceTableLength; i++) {
|
||||
advanceTable[0][i] = *wptr++;
|
||||
advanceTable[1][i] = *wptr++;
|
||||
}
|
||||
|
||||
const u8 *uptr = (const u8 *)wptr;
|
||||
|
||||
int shadowCharMapSize = ((header.shadowMapLength * header.shadowMapBpe + 31) & ~31) / 8;
|
||||
shadowCharMap = new u8[shadowCharMapSize];
|
||||
for (int i = 0; i < shadowCharMapSize; i++) {
|
||||
shadowCharMap[i] = *uptr++;
|
||||
}
|
||||
|
||||
const u16 *sptr = (const u16 *)uptr;
|
||||
if (header.revision == 3) {
|
||||
charmapCompressionTable1[0].resize(rev3extra.compCharMapLength1);
|
||||
charmapCompressionTable1[1].resize(rev3extra.compCharMapLength1);
|
||||
for (int i = 0; i < rev3extra.compCharMapLength1; i++) {
|
||||
charmapCompressionTable1[0][i] = *sptr++;
|
||||
charmapCompressionTable1[1][i] = *sptr++;
|
||||
}
|
||||
|
||||
charmapCompressionTable2[0].resize(rev3extra.compCharMapLength2);
|
||||
charmapCompressionTable2[1].resize(rev3extra.compCharMapLength2);
|
||||
for (int i = 0; i < rev3extra.compCharMapLength2; i++) {
|
||||
charmapCompressionTable2[0][i] = *sptr++;
|
||||
charmapCompressionTable2[1][i] = *sptr++;
|
||||
}
|
||||
}
|
||||
|
||||
uptr = (const u8 *)sptr;
|
||||
|
||||
int charMapSize = ((header.charMapLength * header.charMapBpe + 31) & ~31) / 8;
|
||||
|
||||
charMap = new u8[charMapSize];
|
||||
for (int i = 0; i < charMapSize; i++) {
|
||||
charMap[i] = *uptr++;
|
||||
}
|
||||
|
||||
int charPointerSize = (((header.charPointerLength * header.charPointerBpe + 31) & ~31) / 8);
|
||||
charPointerTable = new u8[charPointerSize];
|
||||
for (int i = 0; i < charPointerSize; i++) {
|
||||
charPointerTable[i] = *uptr++;
|
||||
}
|
||||
|
||||
// PGF Fontdata.
|
||||
u32 fontDataOffset = uptr - startPtr;
|
||||
|
||||
fontDataSize = dataSize - fontDataOffset;
|
||||
fontData = new u8[fontDataSize];
|
||||
memcpy(fontData, uptr, fontDataSize);
|
||||
|
||||
// charmap.resize();
|
||||
charmap.resize(header.charMapLength);
|
||||
int charmap_compr_len = header.revision == 3 ? 7 : 1;
|
||||
charmap_compr.resize(charmap_compr_len * 4);
|
||||
glyphs.resize(header.charPointerLength);
|
||||
shadowGlyphs.resize(header.shadowMapLength);
|
||||
firstGlyph = header.firstGlyph;
|
||||
|
||||
// Parse out the char map (array where each entry is an irregular number of bits)
|
||||
// BPE = bits per entry, I think.
|
||||
for (int i = 0; i < header.charMapLength; i++) {
|
||||
charmap[i] = getBits(header.charMapBpe, charMap, i * header.charMapBpe);
|
||||
// This check seems a little odd.
|
||||
if ((size_t)charmap[i] >= glyphs.size())
|
||||
charmap[i] = 65535;
|
||||
}
|
||||
|
||||
std::vector<int> charPointers = getTable(charPointerTable, header.charPointerBpe, glyphs.size());
|
||||
std::vector<int> shadowMap = getTable(shadowCharMap, header.shadowMapBpe, shadowGlyphs.size());
|
||||
|
||||
// Pregenerate glyphs.
|
||||
for (size_t i = 0; i < glyphs.size(); i++) {
|
||||
GetGlyph(fontData, charPointers[i] * 4 * 8 /* ??? */, FONT_PGF_CHARGLYPH, glyphs[i]);
|
||||
}
|
||||
|
||||
// And shadow glyphs.
|
||||
for (size_t i = 0; i < shadowGlyphs.size(); i++) {
|
||||
size_t shadowId = glyphs[i].shadowID;
|
||||
if (shadowId < shadowMap.size()) {
|
||||
size_t charId = shadowMap[shadowId];
|
||||
if (charId < glyphs.size()) {
|
||||
// TODO: check for pre existing shadow glyph
|
||||
GetGlyph(fontData, charPointers[charId] * 4 * 8 /* ??? */, FONT_PGF_SHADOWGLYPH, shadowGlyphs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int PGF::GetCharIndex(int charCode, const std::vector<int> &charmapCompressed) {
|
||||
int charIndex = 0;
|
||||
for (size_t i = 0; i < charmapCompressed.size(); i += 2) {
|
||||
if (charCode >= charmapCompressed[i] && charCode < charmapCompressed[i] + charmapCompressed[i + 1]) {
|
||||
charIndex += charCode - charmapCompressed[i];
|
||||
return charIndex;
|
||||
}
|
||||
charIndex += charmapCompressed[i + 1];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo) {
|
||||
Glyph glyph;
|
||||
if (!GetCharGlyph(charCode, FONT_PGF_CHARGLYPH, glyph)) {
|
||||
// Character not in font, return zeroed charInfo as on real PSP.
|
||||
return false;
|
||||
}
|
||||
memset(charInfo, 0, sizeof(*charInfo));
|
||||
|
||||
charInfo->bitmapWidth = glyph.w;
|
||||
charInfo->bitmapHeight = glyph.h;
|
||||
charInfo->bitmapLeft = glyph.left;
|
||||
charInfo->bitmapTop = glyph.top;
|
||||
charInfo->sfp26Width = glyph.dimensionWidth;
|
||||
charInfo->sfp26Height = glyph.dimensionHeight;
|
||||
charInfo->sfp26Ascender = glyph.top << 6;
|
||||
charInfo->sfp26Descender = (glyph.h - glyph.top) << 6;
|
||||
charInfo->sfp26BearingHX = glyph.xAdjustH;
|
||||
charInfo->sfp26BearingHY = glyph.yAdjustH;
|
||||
charInfo->sfp26BearingVX = glyph.xAdjustV;
|
||||
charInfo->sfp26BearingVY = glyph.yAdjustV;
|
||||
charInfo->sfp26AdvanceH = glyph.advanceH;
|
||||
charInfo->sfp26AdvanceV = glyph.advanceV;
|
||||
return true;
|
||||
}
|
||||
|
||||
void PGF::GetFontInfo(PGFFontInfo *fi) {
|
||||
fi->maxGlyphWidthI = header.maxSize[0];
|
||||
fi->maxGlyphHeightI = header.maxSize[1];
|
||||
fi->maxGlyphAscenderI = header.maxAscender;
|
||||
fi->maxGlyphDescenderI = header.maxDescender;
|
||||
fi->maxGlyphLeftXI = header.maxLeftXAdjust;
|
||||
fi->maxGlyphBaseYI = header.maxBaseYAdjust;
|
||||
fi->minGlyphCenterXI = header.minCenterXAdjust;
|
||||
fi->maxGlyphTopYI = header.maxTopYAdjust;
|
||||
fi->maxGlyphAdvanceXI = header.maxAdvance[0];
|
||||
fi->maxGlyphAdvanceYI = header.maxAdvance[1];
|
||||
fi->maxGlyphWidthF = header.maxSize[0] / 64.0f;
|
||||
fi->maxGlyphHeightF = header.maxSize[1] / 64.0f;
|
||||
fi->maxGlyphAscenderF = header.maxAscender / 64.0f;
|
||||
fi->maxGlyphDescenderF = header.maxDescender / 64.0f;
|
||||
fi->maxGlyphLeftXF = header.maxLeftXAdjust / 64.0f;
|
||||
fi->maxGlyphBaseYF = header.maxBaseYAdjust / 64.0f;
|
||||
fi->minGlyphCenterXF = header.minCenterXAdjust / 64.0f;
|
||||
fi->maxGlyphTopYF = header.maxTopYAdjust / 64.0f;
|
||||
fi->maxGlyphAdvanceXF = header.maxAdvance[0] / 64.0f;
|
||||
fi->maxGlyphAdvanceYF = header.maxAdvance[1] / 64.0f;
|
||||
|
||||
fi->maxGlyphWidth = header.maxGlyphWidth;
|
||||
fi->maxGlyphHeight = header.maxGlyphHeight;
|
||||
fi->charMapLength = header.charMapLength;
|
||||
fi->shadowMapLength = 0; // header.shadowMapLength; TODO
|
||||
|
||||
fi->BPP = header.bpp;
|
||||
}
|
||||
|
||||
bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &glyph) {
|
||||
if (glyphType == FONT_PGF_SHADOWGLYPH) {
|
||||
if (charPtr + 96 > fontDataSize * 8)
|
||||
return false;
|
||||
charPtr += getBits(14, fontdata, charPtr) * 8;
|
||||
if (charPtr + 96 > fontDataSize * 8)
|
||||
return false;
|
||||
}
|
||||
charPtr += 14;
|
||||
|
||||
glyph.w = getBits(7, fontdata, charPtr);
|
||||
charPtr += 7;
|
||||
|
||||
glyph.h = getBits(7, fontdata, charPtr);
|
||||
charPtr += 7;
|
||||
|
||||
glyph.left = getBits(7, fontdata, charPtr);
|
||||
charPtr += 7;
|
||||
if (glyph.left >= 64) {
|
||||
glyph.left -= 128;
|
||||
}
|
||||
|
||||
glyph.top = getBits(7, fontdata, charPtr);
|
||||
charPtr += 7;
|
||||
if (glyph.top >= 64) {
|
||||
glyph.top -= 128;
|
||||
}
|
||||
|
||||
glyph.flags = getBits(6, fontdata, charPtr);
|
||||
charPtr += 6;
|
||||
|
||||
if (glyph.flags & FONT_PGF_CHARGLYPH) {
|
||||
// Skip magic number
|
||||
charPtr += 7;
|
||||
|
||||
glyph.shadowID = getBits(9, fontdata, charPtr);
|
||||
charPtr += 9;
|
||||
|
||||
int dimensionIndex = getBits(8, fontdata, charPtr);
|
||||
charPtr += 8;
|
||||
|
||||
int xAdjustIndex = getBits(8, fontdata, charPtr);
|
||||
charPtr += 8;
|
||||
|
||||
int yAdjustIndex = getBits(8, fontdata, charPtr);
|
||||
charPtr += 8;
|
||||
|
||||
charPtr +=
|
||||
((glyph.flags & FONT_PGF_METRIC_FLAG1) ? 0 : 56) +
|
||||
((glyph.flags & FONT_PGF_METRIC_FLAG2) ? 0 : 56) +
|
||||
((glyph.flags & FONT_PGF_METRIC_FLAG3) ? 0 : 56);
|
||||
|
||||
int advanceIndex = getBits(8, fontdata, charPtr);
|
||||
charPtr += 8;
|
||||
|
||||
if (dimensionIndex < header.dimTableLength) {
|
||||
glyph.dimensionWidth = dimensionTable[0][dimensionIndex];
|
||||
glyph.dimensionHeight = dimensionTable[1][dimensionIndex];
|
||||
}
|
||||
|
||||
if (xAdjustIndex < header.xAdjustTableLength) {
|
||||
glyph.xAdjustH = xAdjustTable[0][xAdjustIndex];
|
||||
glyph.xAdjustV = xAdjustTable[1][xAdjustIndex];
|
||||
}
|
||||
|
||||
if (yAdjustIndex < header.xAdjustTableLength) {
|
||||
glyph.yAdjustH = yAdjustTable[0][yAdjustIndex];
|
||||
glyph.yAdjustV = yAdjustTable[1][yAdjustIndex];
|
||||
}
|
||||
|
||||
if (dimensionIndex == 0 && xAdjustIndex == 0 && yAdjustIndex == 0 && isJPCSPFont(fileName.c_str())) {
|
||||
// Fonts created by ttf2pgf do not contain complete Glyph information.
|
||||
// Provide default values.
|
||||
glyph.dimensionWidth = glyph.w << 6;
|
||||
glyph.dimensionHeight = glyph.h << 6;
|
||||
// This stuff doesn't exactly look right.
|
||||
glyph.xAdjustH = glyph.left << 6;
|
||||
glyph.xAdjustV = glyph.left << 6;
|
||||
glyph.yAdjustH = glyph.top << 6;
|
||||
glyph.yAdjustV = glyph.top << 6;
|
||||
}
|
||||
|
||||
if (advanceIndex < header.advanceTableLength) {
|
||||
glyph.advanceH = advanceTable[0][advanceIndex];
|
||||
glyph.advanceV = advanceTable[1][advanceIndex];
|
||||
}
|
||||
} else {
|
||||
glyph.shadowID = 65535;
|
||||
glyph.advanceH = 0;
|
||||
}
|
||||
|
||||
glyph.ptr = (u32)(charPtr / 8);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PGF::GetCharGlyph(int charCode, int glyphType, Glyph &glyph) {
|
||||
if (charCode < firstGlyph)
|
||||
return false;
|
||||
charCode -= firstGlyph;
|
||||
if (charCode < (int)charmap.size()) {
|
||||
charCode = charmap[charCode];
|
||||
}
|
||||
if (glyphType == FONT_PGF_CHARGLYPH) {
|
||||
if (charCode >= (int)glyphs.size())
|
||||
return false;
|
||||
glyph = glyphs[charCode];
|
||||
} else {
|
||||
if (charCode >= (int)shadowGlyphs.size())
|
||||
return false;
|
||||
glyph = shadowGlyphs[charCode];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PGF::DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, int pixelformat, int charCode, int altCharCode, int glyphType) {
|
||||
Glyph glyph;
|
||||
if (!GetCharGlyph(charCode, glyphType, glyph)) {
|
||||
// No Glyph available for this charCode, try to use the alternate char.
|
||||
charCode = altCharCode;
|
||||
if (!GetCharGlyph(charCode, glyphType, glyph)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (glyph.w <= 0 || glyph.h <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((glyph.flags & FONT_PGF_BMP_OVERLAY) != FONT_PGF_BMP_H_ROWS) &&
|
||||
((glyph.flags & FONT_PGF_BMP_OVERLAY) != FONT_PGF_BMP_V_ROWS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
u32 bitPtr = glyph.ptr * 8;
|
||||
int numberPixels = glyph.w * glyph.h;
|
||||
int pixelIndex = 0;
|
||||
|
||||
while (pixelIndex < numberPixels && bitPtr + 8 < fontDataSize * 8) {
|
||||
// This is some kind of nibble based RLE compression.
|
||||
int nibble = getBits(4, fontData, bitPtr);
|
||||
bitPtr += 4;
|
||||
|
||||
int count;
|
||||
int value;
|
||||
if (nibble < 8) {
|
||||
value = getBits(4, fontData, bitPtr);
|
||||
bitPtr += 4;
|
||||
count = nibble + 1;
|
||||
} else {
|
||||
count = 16 - nibble;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count && pixelIndex < numberPixels; i++) {
|
||||
if (nibble >= 8) {
|
||||
value = getBits(4, fontData, bitPtr);
|
||||
bitPtr += 4;
|
||||
}
|
||||
|
||||
int xx, yy;
|
||||
if ((glyph.flags & FONT_PGF_BMP_OVERLAY) == FONT_PGF_BMP_H_ROWS) {
|
||||
xx = pixelIndex % glyph.w;
|
||||
yy = pixelIndex / glyph.w;
|
||||
} else {
|
||||
xx = pixelIndex / glyph.h;
|
||||
yy = pixelIndex % glyph.h;
|
||||
}
|
||||
|
||||
int pixelX = x + xx;
|
||||
int pixelY = y + yy;
|
||||
if (pixelX >= clipX && pixelX < clipX + clipWidth && pixelY >= clipY && pixelY < clipY + clipHeight) {
|
||||
// 4-bit color value
|
||||
int pixelColor = value;
|
||||
switch (pixelformat) {
|
||||
case PSP_FONT_PIXELFORMAT_8:
|
||||
// 8-bit color value
|
||||
pixelColor |= pixelColor << 4;
|
||||
break;
|
||||
case PSP_FONT_PIXELFORMAT_24:
|
||||
// 24-bit color value
|
||||
pixelColor |= pixelColor << 4;
|
||||
pixelColor |= pixelColor << 8;
|
||||
pixelColor |= pixelColor << 8;
|
||||
break;
|
||||
case PSP_FONT_PIXELFORMAT_32:
|
||||
// 32-bit color value
|
||||
pixelColor |= pixelColor << 4;
|
||||
pixelColor |= pixelColor << 8;
|
||||
pixelColor |= pixelColor << 16;
|
||||
break;
|
||||
}
|
||||
|
||||
SetFontPixel(base, bpl, bufWidth, bufHeight, pixelX, pixelY, pixelColor, pixelformat);
|
||||
}
|
||||
|
||||
pixelIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PGF::SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat) {
|
||||
if (x < 0 || x >= bufWidth || y < 0 || y >= bufHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
static const u8 fontPixelSizeInBytes[] = { 0, 0, 1, 3, 4 }; // 0 means 2 pixels per byte
|
||||
int pixelBytes = fontPixelSizeInBytes[pixelformat];
|
||||
int bufMaxWidth = (pixelBytes == 0 ? bpl * 2 : bpl / pixelBytes);
|
||||
if (x >= bufMaxWidth) {
|
||||
return;
|
||||
}
|
||||
|
||||
int framebufferAddr = base + (y * bpl) + (pixelBytes == 0 ? x / 2 : x * pixelBytes);
|
||||
|
||||
switch (pixelformat) {
|
||||
case PSP_FONT_PIXELFORMAT_4:
|
||||
case PSP_FONT_PIXELFORMAT_4_REV:
|
||||
{
|
||||
int oldColor = Memory::Read_U8(framebufferAddr);
|
||||
int newColor;
|
||||
if ((x & 1) != pixelformat) {
|
||||
newColor = (pixelColor << 4) | (oldColor & 0xF);
|
||||
} else {
|
||||
newColor = (oldColor & 0xF0) | pixelColor;
|
||||
}
|
||||
Memory::Write_U8(newColor, framebufferAddr);
|
||||
break;
|
||||
}
|
||||
case PSP_FONT_PIXELFORMAT_8:
|
||||
{
|
||||
Memory::Write_U8((u8)pixelColor, framebufferAddr);
|
||||
break;
|
||||
}
|
||||
case PSP_FONT_PIXELFORMAT_24:
|
||||
{
|
||||
Memory::Write_U8(pixelColor & 0xFF, framebufferAddr + 0);
|
||||
Memory::Write_U8(pixelColor >> 8, framebufferAddr + 1);
|
||||
Memory::Write_U8(pixelColor >> 16, framebufferAddr + 2);
|
||||
break;
|
||||
}
|
||||
case PSP_FONT_PIXELFORMAT_32:
|
||||
{
|
||||
Memory::Write_U32(pixelColor, framebufferAddr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetFontPixelColor(int color, int pixelformat) {
|
||||
switch (pixelformat) {
|
||||
case PSP_FONT_PIXELFORMAT_4:
|
||||
case PSP_FONT_PIXELFORMAT_4_REV:
|
||||
// Use only 4-bit alpha
|
||||
color = (color >> 28) & 0xF;
|
||||
break;
|
||||
case PSP_FONT_PIXELFORMAT_8:
|
||||
// Use only 8-bit alpha
|
||||
color = (color >> 24) & 0xFF;
|
||||
break;
|
||||
case PSP_FONT_PIXELFORMAT_24:
|
||||
// Use RGB with 8-bit values
|
||||
color = color & 0x00FFFFFF;
|
||||
break;
|
||||
case PSP_FONT_PIXELFORMAT_32:
|
||||
// Use RGBA with 8-bit values
|
||||
break;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
// 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/.
|
||||
|
||||
// Thanks to the JPCSP project! This sceFont implementation is basically a C++ take on JPCSP's font code.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Log.h"
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
enum {
|
||||
FONT_FILETYPE_PGF = 0x00,
|
||||
FONT_FILETYPE_BWFON = 0x01,
|
||||
};
|
||||
|
||||
enum {
|
||||
FONT_PGF_BMP_H_ROWS = 0x01,
|
||||
FONT_PGF_BMP_V_ROWS = 0x02,
|
||||
FONT_PGF_BMP_OVERLAY = 0x03,
|
||||
FONT_PGF_METRIC_FLAG1 = 0x04,
|
||||
FONT_PGF_METRIC_FLAG2 = 0x08,
|
||||
FONT_PGF_METRIC_FLAG3 = 0x10,
|
||||
FONT_PGF_CHARGLYPH = 0x20,
|
||||
FONT_PGF_SHADOWGLYPH = 0x40,
|
||||
};
|
||||
|
||||
enum Family {
|
||||
FONT_FAMILY_SANS_SERIF = 1,
|
||||
FONT_FAMILY_SERIF = 2,
|
||||
};
|
||||
|
||||
enum Style {
|
||||
FONT_STYLE_REGULAR = 1,
|
||||
FONT_STYLE_ITALIC = 2,
|
||||
FONT_STYLE_BOLD = 5,
|
||||
FONT_STYLE_BOLD_ITALIC = 6,
|
||||
FONT_STYLE_DB = 103, // Demi-Bold / semi-bold
|
||||
};
|
||||
|
||||
enum Language {
|
||||
FONT_LANGUAGE_JAPANESE = 1,
|
||||
FONT_LANGUAGE_LATIN = 2,
|
||||
FONT_LANGUAGE_KOREAN = 3,
|
||||
FONT_LANGUAGE_CHINESE = 4,
|
||||
};
|
||||
|
||||
enum FontPixelFormat {
|
||||
PSP_FONT_PIXELFORMAT_4 = 0, // 2 pixels packed in 1 byte (natural order)
|
||||
PSP_FONT_PIXELFORMAT_4_REV = 1, // 2 pixels packed in 1 byte (reversed order)
|
||||
PSP_FONT_PIXELFORMAT_8 = 2, // 1 pixel in 1 byte
|
||||
PSP_FONT_PIXELFORMAT_24 = 3, // 1 pixel in 3 bytes (RGB)
|
||||
PSP_FONT_PIXELFORMAT_32 = 4, // 1 pixel in 4 bytes (RGBA)
|
||||
};
|
||||
|
||||
|
||||
struct PGFFontStyle {
|
||||
float fontH;
|
||||
float fontV;
|
||||
float fontHRes;
|
||||
float fontVRes;
|
||||
float fontWeight;
|
||||
u16 fontFamily;
|
||||
u16 fontStyle;
|
||||
// Check.
|
||||
u16 fontStyleSub;
|
||||
u16 fontLanguage;
|
||||
u16 fontRegion;
|
||||
u16 fontCountry;
|
||||
char fontName[64];
|
||||
char fontFileName[64];
|
||||
u32 fontAttributes;
|
||||
u32 fontExpire;
|
||||
};
|
||||
|
||||
|
||||
class Glyph {
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
int left;
|
||||
int top;
|
||||
int flags;
|
||||
int shadowID;
|
||||
int advanceH;
|
||||
int advanceV;
|
||||
int dimensionWidth, dimensionHeight;
|
||||
int xAdjustH, xAdjustV;
|
||||
int yAdjustH, yAdjustV;
|
||||
u32 ptr;
|
||||
};
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct PGFHeader
|
||||
{
|
||||
u16 headerOffset;
|
||||
u16 headerSize;
|
||||
|
||||
char PGFMagic[4];
|
||||
int revision;
|
||||
int version;
|
||||
|
||||
int charMapLength;
|
||||
int charPointerLength;
|
||||
int charMapBpe;
|
||||
int charPointerBpe;
|
||||
|
||||
u8 pad1[2];
|
||||
u8 bpp;
|
||||
u8 pad2[1];
|
||||
|
||||
int hSize;
|
||||
int vSize;
|
||||
int hResolution;
|
||||
int vResolution;
|
||||
|
||||
u8 pad3[1];
|
||||
char fontName[64];
|
||||
char fontType[64];
|
||||
u8 pad4[1];
|
||||
|
||||
u16 firstGlyph;
|
||||
u16 lastGlyph;
|
||||
|
||||
u8 pad5[26];
|
||||
|
||||
int maxAscender;
|
||||
int maxDescender;
|
||||
int maxLeftXAdjust;
|
||||
int maxBaseYAdjust;
|
||||
int minCenterXAdjust;
|
||||
int maxTopYAdjust;
|
||||
|
||||
int maxAdvance[2];
|
||||
int maxSize[2];
|
||||
u16 maxGlyphWidth;
|
||||
u16 maxGlyphHeight;
|
||||
u8 pad6[2];
|
||||
|
||||
u8 dimTableLength;
|
||||
u8 xAdjustTableLength;
|
||||
u8 yAdjustTableLength;
|
||||
u8 advanceTableLength;
|
||||
u8 pad7[102];
|
||||
|
||||
int shadowMapLength;
|
||||
int shadowMapBpe;
|
||||
float unknown1;
|
||||
int shadowScale[2];
|
||||
u8 pad8[8];
|
||||
};
|
||||
|
||||
struct PGFHeaderRev3Extra {
|
||||
int compCharMapBpe1;
|
||||
int compCharMapLength1;
|
||||
int compCharMapBpe2;
|
||||
int compCharMapLength2;
|
||||
u32 unknown;
|
||||
};
|
||||
|
||||
struct PGFCharInfo {
|
||||
u32 bitmapWidth;
|
||||
u32 bitmapHeight;
|
||||
u32 bitmapLeft;
|
||||
u32 bitmapTop;
|
||||
// Glyph metrics (in 26.6 signed fixed-point).
|
||||
u32 sfp26Width;
|
||||
u32 sfp26Height;
|
||||
s32 sfp26Ascender;
|
||||
s32 sfp26Descender;
|
||||
s32 sfp26BearingHX;
|
||||
s32 sfp26BearingHY;
|
||||
s32 sfp26BearingVX;
|
||||
s32 sfp26BearingVY;
|
||||
s32 sfp26AdvanceH;
|
||||
s32 sfp26AdvanceV;
|
||||
u8 pad[4];
|
||||
};
|
||||
|
||||
struct PGFFontInfo {
|
||||
// Glyph metrics (in 26.6 signed fixed-point).
|
||||
int maxGlyphWidthI;
|
||||
int maxGlyphHeightI;
|
||||
int maxGlyphAscenderI;
|
||||
int maxGlyphDescenderI;
|
||||
int maxGlyphLeftXI;
|
||||
int maxGlyphBaseYI;
|
||||
int minGlyphCenterXI;
|
||||
int maxGlyphTopYI;
|
||||
int maxGlyphAdvanceXI;
|
||||
int maxGlyphAdvanceYI;
|
||||
|
||||
// Glyph metrics (replicated as float).
|
||||
float maxGlyphWidthF;
|
||||
float maxGlyphHeightF;
|
||||
float maxGlyphAscenderF;
|
||||
float maxGlyphDescenderF;
|
||||
float maxGlyphLeftXF;
|
||||
float maxGlyphBaseYF;
|
||||
float minGlyphCenterXF;
|
||||
float maxGlyphTopYF;
|
||||
float maxGlyphAdvanceXF;
|
||||
float maxGlyphAdvanceYF;
|
||||
|
||||
// Bitmap dimensions.
|
||||
short maxGlyphWidth;
|
||||
short maxGlyphHeight;
|
||||
int charMapLength; // Number of elements in the font's charmap.
|
||||
int shadowMapLength; // Number of elements in the font's shadow charmap.
|
||||
|
||||
// Font style (used by font comparison functions).
|
||||
PGFFontStyle fontStyle;
|
||||
|
||||
int BPP; // Font's BPP.
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
class PGF {
|
||||
public:
|
||||
PGF();
|
||||
~PGF();
|
||||
|
||||
void ReadPtr(const u8 *ptr, size_t dataSize);
|
||||
|
||||
bool GetCharInfo(int charCode, PGFCharInfo *ci);
|
||||
void GetFontInfo(PGFFontInfo *fi);
|
||||
void DrawCharacter(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int clipX, int clipY, int clipWidth, int clipHeight, int pixelformat, int charCode, int altCharCode, int glyphType);
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
|
||||
PGFHeader header;
|
||||
|
||||
private:
|
||||
bool GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &glyph);
|
||||
bool GetCharGlyph(int charCode, int glyphType, Glyph &glyph);
|
||||
|
||||
// Unused
|
||||
int GetCharIndex(int charCode, const std::vector<int> &charmapCompressed);
|
||||
|
||||
void SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat);
|
||||
|
||||
PGFHeaderRev3Extra rev3extra;
|
||||
|
||||
// Font character image data
|
||||
u8 *fontData;
|
||||
size_t fontDataSize;
|
||||
|
||||
std::string fileName;
|
||||
|
||||
std::vector<int> dimensionTable[2];
|
||||
std::vector<int> xAdjustTable[2];
|
||||
std::vector<int> yAdjustTable[2];
|
||||
std::vector<int> advanceTable[2];
|
||||
|
||||
// Unused
|
||||
std::vector<int> charmapCompressionTable1[2];
|
||||
std::vector<int> charmapCompressionTable2[2];
|
||||
|
||||
u8 *charMap;
|
||||
u8 *shadowCharMap;
|
||||
u8 *charPointerTable;
|
||||
|
||||
std::vector<int> charmap_compr;
|
||||
std::vector<int> charmap;
|
||||
|
||||
std::vector<Glyph> glyphs;
|
||||
std::vector<Glyph> shadowGlyphs;
|
||||
int firstGlyph;
|
||||
};
|
||||
@@ -96,6 +96,11 @@ template<float func()> void WrapF_V() {
|
||||
RETURNF(func());
|
||||
}
|
||||
|
||||
// TODO: Not sure about the floating point parameter passing
|
||||
template<float func(int, float, u32)> void WrapF_IFU() {
|
||||
RETURNF(func(PARAM(0), PARAMF(0), PARAM(1)));
|
||||
}
|
||||
|
||||
template<u32 func(u32)> void WrapU_U() {
|
||||
u32 retval = func(PARAM(0));
|
||||
RETURN(retval);
|
||||
@@ -133,7 +138,7 @@ template<int func(u32, u32)> void WrapI_UU() {
|
||||
|
||||
template<int func(u32, float, float)> void WrapI_UFF() {
|
||||
// Not sure about the float arguments.
|
||||
int retval = func(PARAM(0), currentMIPS->f[0], currentMIPS->f[1]);
|
||||
int retval = func(PARAM(0), currentMIPS->f[12], currentMIPS->f[13]);
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
@@ -142,6 +147,11 @@ template<int func(u32, u32, u32)> void WrapI_UUU() {
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
template<int func(u32, u32, u32, int)> void WrapI_UUUI() {
|
||||
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
template<int func(u32, u32, u32, int, int, int,int )> void WrapI_UUUIIII() {
|
||||
int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5), PARAM(6));
|
||||
RETURN(retval);
|
||||
@@ -313,6 +323,11 @@ template<int func(int, int, int, int)> void WrapI_IIII() {
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
template<int func(int, const char *, int, u32, u32)> void WrapI_ICIUU() {
|
||||
int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4));
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
template<int func(int, int, u32)> void WrapI_IIU() {
|
||||
int retval = func(PARAM(0), PARAM(1), PARAM(2));
|
||||
RETURN(retval);
|
||||
@@ -481,6 +496,11 @@ template<u32 func(u32, u32, u32, u32)> void WrapU_UUUU() {
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
template<u32 func(u32, const char *, u32, u32)> void WrapU_UCUU() {
|
||||
u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3));
|
||||
RETURN(retval);
|
||||
}
|
||||
|
||||
template<u32 func(u32, u32, u32, int)> void WrapU_UUUI() {
|
||||
u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3));
|
||||
RETURN(retval);
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <vector>
|
||||
#include "../MemMap.h"
|
||||
#include "../Config.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "HLETables.h"
|
||||
#include "../System.h"
|
||||
@@ -54,12 +56,29 @@ enum
|
||||
static std::vector<HLEModule> moduleDB;
|
||||
static std::vector<Syscall> unresolvedSyscalls;
|
||||
static std::vector<Syscall> exportedCalls;
|
||||
static int delayedResultEvent = -1;
|
||||
static int hleAfterSyscall = HLE_AFTER_NOTHING;
|
||||
static const char *hleAfterSyscallReschedReason;
|
||||
|
||||
void hleDelayResultFinish(u64 userdata, int cycleslate)
|
||||
{
|
||||
u32 error;
|
||||
SceUID threadID = (SceUID) userdata;
|
||||
SceUID verify = __KernelGetWaitID(threadID, WAITTYPE_DELAY, error);
|
||||
// The top 32 bits of userdata are the top 32 bits of the 64 bit result.
|
||||
// We can't just put it all in userdata because we need to know the threadID...
|
||||
u64 result = (userdata & 0xFFFFFFFF00000000ULL) | __KernelGetWaitValue(threadID, error);
|
||||
|
||||
if (error == 0 && verify == 1)
|
||||
__KernelResumeThreadFromWait(threadID, result);
|
||||
else
|
||||
WARN_LOG(HLE, "Someone else woke up HLE-blocked thread?");
|
||||
}
|
||||
|
||||
void HLEInit()
|
||||
{
|
||||
RegisterAllModules();
|
||||
delayedResultEvent = CoreTiming::RegisterEvent("HLEDelayedResult", hleDelayResultFinish);
|
||||
}
|
||||
|
||||
void HLEDoState(PointerWrap &p)
|
||||
@@ -67,6 +86,8 @@ void HLEDoState(PointerWrap &p)
|
||||
Syscall sc = {""};
|
||||
p.Do(unresolvedSyscalls, sc);
|
||||
p.Do(exportedCalls, sc);
|
||||
p.Do(delayedResultEvent);
|
||||
CoreTiming::RestoreRegisterEvent(delayedResultEvent, "HLEDelayedResult", hleDelayResultFinish);
|
||||
p.DoMarker("HLE");
|
||||
}
|
||||
|
||||
@@ -164,6 +185,7 @@ u32 GetSyscallOp(const char *moduleName, u32 nib)
|
||||
else
|
||||
{
|
||||
INFO_LOG(HLE, "Syscall (%s, %08x) unknown", moduleName, nib);
|
||||
Reporting::ReportMessage("Unknown syscall in known module: %s 0x%08x", moduleName, nib);
|
||||
return (0x0003FFCC | (modindex<<18)); // invalid syscall
|
||||
}
|
||||
}
|
||||
@@ -308,6 +330,27 @@ bool hleExecuteDebugBreak(const HLEFunction &func)
|
||||
return true;
|
||||
}
|
||||
|
||||
u32 hleDelayResult(u32 result, const char *reason, int usec)
|
||||
{
|
||||
CoreTiming::ScheduleEvent(usToCycles(usec), delayedResultEvent, __KernelGetCurThread());
|
||||
__KernelWaitCurThread(WAITTYPE_DELAY, 1, result, 0, false, reason);
|
||||
return result;
|
||||
}
|
||||
|
||||
u64 hleDelayResult(u64 result, const char *reason, int usec)
|
||||
{
|
||||
u64 param = (result & 0xFFFFFFFF00000000) | __KernelGetCurThread();
|
||||
CoreTiming::ScheduleEvent(usToCycles(usec), delayedResultEvent, param);
|
||||
__KernelWaitCurThread(WAITTYPE_DELAY, 1, (u32) result, 0, false, reason);
|
||||
return result;
|
||||
}
|
||||
|
||||
void hleEatMicro(int usec)
|
||||
{
|
||||
// Maybe this should Idle, at least for larger delays? Could that cause issues?
|
||||
currentMIPS->downcount -= (int) usToCycles(usec);
|
||||
}
|
||||
|
||||
inline void hleFinishSyscall(int modulenum, int funcnum)
|
||||
{
|
||||
if ((hleAfterSyscall & HLE_AFTER_CURRENT_CALLBACKS) != 0)
|
||||
|
||||
@@ -53,6 +53,7 @@ struct Syscall
|
||||
};
|
||||
|
||||
#define PARAM(n) currentMIPS->r[4+n]
|
||||
#define PARAMF(n) currentMIPS->f[12+n]
|
||||
#define RETURN(n) currentMIPS->r[2]=n
|
||||
#define RETURNF(fl) currentMIPS->f[0]=fl
|
||||
|
||||
@@ -86,6 +87,21 @@ void hleRunInterrupts();
|
||||
// Pause emulation after the syscall finishes.
|
||||
void hleDebugBreak();
|
||||
|
||||
// Delays the result for usec microseconds, allowing other threads to run during this time.
|
||||
u32 hleDelayResult(u32 result, const char *reason, int usec);
|
||||
u64 hleDelayResult(u64 result, const char *reason, int usec);
|
||||
void hleEatMicro(int usec);
|
||||
|
||||
inline int hleDelayResult(int result, const char *reason, int usec)
|
||||
{
|
||||
return hleDelayResult((u32) result, reason, usec);
|
||||
}
|
||||
|
||||
inline s64 hleDelayResult(s64 result, const char *reason, int usec)
|
||||
{
|
||||
return hleDelayResult((u64) result, reason, usec);
|
||||
}
|
||||
|
||||
void HLEInit();
|
||||
void HLEDoState(PointerWrap &p);
|
||||
void HLEShutdown();
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "sceUsb.h"
|
||||
#include "sceChnnlsv.h"
|
||||
#include "scePspNpDrm_user.h"
|
||||
#include "sceP3da.h"
|
||||
|
||||
#define N(s) s
|
||||
|
||||
@@ -247,6 +248,8 @@ void RegisterAllModules() {
|
||||
Register_sceVaudio();
|
||||
Register_sceUsb();
|
||||
Register_sceChnnlsv();
|
||||
Register_sceNpDrm();
|
||||
Register_sceP3da();
|
||||
|
||||
for (int i = 0; i < numModules; i++)
|
||||
{
|
||||
|
||||
+19
-6
@@ -27,8 +27,9 @@
|
||||
#include "sceKernel.h"
|
||||
#include "sceUtility.h"
|
||||
|
||||
#define ATRAC_ERROR_API_FAIL 0x80630002
|
||||
#define ATRAC_ERROR_ALL_DATA_DECODED 0x80630024
|
||||
#define ATRAC_ERROR_API_FAIL 0x80630002
|
||||
#define ATRAC_ERROR_ALL_DATA_DECODED 0x80630024
|
||||
#define ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED 0x80630022
|
||||
|
||||
#define AT3_MAGIC 0x0270
|
||||
#define AT3_PLUS_MAGIC 0xFFFE
|
||||
@@ -132,6 +133,11 @@ void Atrac::Analyze()
|
||||
ERROR_LOG(HLE, "Atrac buffer very small: %d", first.size);
|
||||
return;
|
||||
}
|
||||
if (!Memory::IsValidAddress(first.addr))
|
||||
{
|
||||
WARN_LOG(HLE, "Atrac buffer at invalid address: %08x-%08x", first.addr, first.size);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Validate stuff.
|
||||
|
||||
@@ -141,6 +147,12 @@ void Atrac::Analyze()
|
||||
u32 offset = 12;
|
||||
while (first.size > offset + 8)
|
||||
{
|
||||
if (!Memory::IsValidAddress(first.addr + offset))
|
||||
{
|
||||
ERROR_LOG(HLE, "Atrac buffer %08x-%08x not valid at %08x", first.addr, first.addr + first.size, first.addr + offset);
|
||||
return;
|
||||
}
|
||||
|
||||
u32 magic = Memory::Read_U32(first.addr + offset);
|
||||
u32 size = Memory::Read_U32(first.addr + offset + 4);
|
||||
offset += 8;
|
||||
@@ -173,7 +185,7 @@ u32 sceAtracAddStreamData(int atracID, u32 bytesToAdd)
|
||||
|
||||
u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishFlagAddr, u32 remainAddr)
|
||||
{
|
||||
ERROR_LOG(HLE, "FAKE sceAtracDecodeData(%i, %08x, %08x, %08x, %08x)", atracID, outAddr, numSamplesAddr, finishFlagAddr, remainAddr);
|
||||
DEBUG_LOG(HLE, "FAKE sceAtracDecodeData(%i, %08x, %08x, %08x, %08x)", atracID, outAddr, numSamplesAddr, finishFlagAddr, remainAddr);
|
||||
Atrac *atrac = getAtrac(atracID);
|
||||
|
||||
u32 ret = 0;
|
||||
@@ -371,9 +383,10 @@ u32 sceAtracGetSecondBufferInfo(int atracID, u32 outposAddr, u32 outBytesAddr)
|
||||
if (!atrac) {
|
||||
//return -1;
|
||||
}
|
||||
Memory::Write_U32(0, outposAddr); // outpos
|
||||
Memory::Write_U32(0x10000, outBytesAddr); // outBytes
|
||||
return 0;
|
||||
Memory::Write_U32(0, outposAddr);
|
||||
Memory::Write_U32(0x10000, outBytesAddr);
|
||||
// TODO: Maybe don't write the above?
|
||||
return ATRAC_ERROR_SECOND_BUFFER_NOT_NEEDED;
|
||||
}
|
||||
|
||||
u32 sceAtracGetSoundSample(int atracID, u32 outEndSampleAddr, u32 outLoopStartSampleAddr, u32 outLoopEndSampleAddr)
|
||||
|
||||
@@ -184,6 +184,7 @@ u32 sceAudioChRelease(u32 chan) {
|
||||
return SCE_ERROR_AUDIO_CHANNEL_NOT_RESERVED;
|
||||
}
|
||||
DEBUG_LOG(HLE, "sceAudioChRelease(%i)", chan);
|
||||
chans[chan].clear();
|
||||
chans[chan].reserved = false;
|
||||
return 1;
|
||||
}
|
||||
@@ -271,6 +272,7 @@ u32 sceAudioOutput2GetRestSample(){
|
||||
|
||||
u32 sceAudioOutput2Release(){
|
||||
DEBUG_LOG(HLE,"sceAudioOutput2Release()");
|
||||
chans[0].clear();
|
||||
chans[0].reserved = false;
|
||||
return 0;
|
||||
}
|
||||
@@ -302,6 +304,7 @@ u32 sceAudioSRCChReserve(u32 sampleCount, u32 freq, u32 format) {
|
||||
|
||||
u32 sceAudioSRCChRelease() {
|
||||
DEBUG_LOG(HLE, "sceAudioSRCChRelease()");
|
||||
chans[src].clear();
|
||||
chans[src].reserved = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ void __CtrlInit()
|
||||
ctrlCurrent.analog[0] = 128;
|
||||
ctrlCurrent.analog[1] = 128;
|
||||
|
||||
for (int i = 0; i < NUM_CTRL_BUFFERS; i++)
|
||||
for (u32 i = 0; i < NUM_CTRL_BUFFERS; i++)
|
||||
memcpy(&ctrlBufs[i], &ctrlCurrent, sizeof(_ctrl_data));
|
||||
}
|
||||
|
||||
|
||||
+115
-82
@@ -82,16 +82,20 @@ static int enterVblankEvent = -1;
|
||||
static int leaveVblankEvent = -1;
|
||||
static int afterFlipEvent = -1;
|
||||
|
||||
static int hCount;
|
||||
static int hCountTotal; //unused
|
||||
// hCount is computed now.
|
||||
static int vCount;
|
||||
static int isVblank;
|
||||
static int numSkippedFrames;
|
||||
static bool hasSetMode;
|
||||
static int mode;
|
||||
static int width;
|
||||
static int height;
|
||||
// Don't include this in the state, time increases regardless of state.
|
||||
static double curFrameTime;
|
||||
static double nextFrameTime;
|
||||
|
||||
static u64 frameStartTicks;
|
||||
|
||||
std::vector<WaitVBlankInfo> vblankWaitingThreads;
|
||||
|
||||
// STATE END
|
||||
@@ -115,6 +119,9 @@ void hleAfterFlip(u64 userdata, int cyclesLate);
|
||||
void __DisplayInit() {
|
||||
gpuStats.reset();
|
||||
hasSetMode = false;
|
||||
mode = 0;
|
||||
width = 480;
|
||||
height = 272;
|
||||
numSkippedFrames = 0;
|
||||
framebufIsLatched = false;
|
||||
framebuf.topaddr = 0x04000000;
|
||||
@@ -128,8 +135,6 @@ void __DisplayInit() {
|
||||
CoreTiming::ScheduleEvent(msToCycles(frameMs - vblankMs), enterVblankEvent, 0);
|
||||
isVblank = 0;
|
||||
vCount = 0;
|
||||
hCount = 0;
|
||||
hCountTotal = 0;
|
||||
curFrameTime = 0.0;
|
||||
nextFrameTime = 0.0;
|
||||
|
||||
@@ -140,11 +145,13 @@ void __DisplayDoState(PointerWrap &p) {
|
||||
p.Do(framebuf);
|
||||
p.Do(latchedFramebuf);
|
||||
p.Do(framebufIsLatched);
|
||||
p.Do(hCount);
|
||||
p.Do(hCountTotal);
|
||||
p.Do(frameStartTicks);
|
||||
p.Do(vCount);
|
||||
p.Do(isVblank);
|
||||
p.Do(hasSetMode);
|
||||
p.Do(mode);
|
||||
p.Do(width);
|
||||
p.Do(height);
|
||||
WaitVBlankInfo wvi(0);
|
||||
p.Do(vblankWaitingThreads, wvi);
|
||||
|
||||
@@ -189,7 +196,7 @@ void __DisplayFireVblank() {
|
||||
}
|
||||
}
|
||||
|
||||
float calculateFPS()
|
||||
void CalculateFPS()
|
||||
{
|
||||
static double highestFps = 0.0;
|
||||
static int lastFpsFrame = 0;
|
||||
@@ -208,7 +215,22 @@ float calculateFPS()
|
||||
lastFpsFrame = gpuStats.numFrames;
|
||||
lastFpsTime = now;
|
||||
}
|
||||
return fps;
|
||||
|
||||
char stats[50];
|
||||
sprintf(stats, "VPS: %0.1f", fps);
|
||||
|
||||
#ifdef USING_GLES2
|
||||
float zoom = 0.7f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.7f;
|
||||
#else
|
||||
float zoom = 0.5f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.5f;
|
||||
#endif
|
||||
PPGeBegin();
|
||||
PPGeDrawText(stats, 476 + soff, 4 + soff, PPGE_ALIGN_RIGHT, zoom, 0xCC000000);
|
||||
PPGeDrawText(stats, 476 + -soff, 4 -soff, PPGE_ALIGN_RIGHT, zoom, 0xCC000000);
|
||||
PPGeDrawText(stats, 476, 4, PPGE_ALIGN_RIGHT, zoom, 0xFF30FF30);
|
||||
PPGeEnd();
|
||||
}
|
||||
|
||||
void DebugStats()
|
||||
@@ -257,8 +279,13 @@ void DebugStats()
|
||||
gpuStats.numShaders
|
||||
);
|
||||
|
||||
float zoom = 0.3f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.3f;
|
||||
#ifdef USING_GLES2
|
||||
float zoom = 0.5f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.5f;
|
||||
#else
|
||||
float zoom = 0.3f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.3f;
|
||||
#endif
|
||||
PPGeBegin();
|
||||
PPGeDrawText(stats, soff, soff, 0, zoom, 0xCC000000);
|
||||
PPGeDrawText(stats, -soff, -soff, 0, zoom, 0xCC000000);
|
||||
@@ -270,13 +297,12 @@ void DebugStats()
|
||||
}
|
||||
|
||||
// Let's collect all the throttling and frameskipping logic here.
|
||||
void DoFrameTiming(bool &throttle, bool &skipFrame, bool &skipFlip) {
|
||||
void DoFrameTiming(bool &throttle, bool &skipFrame) {
|
||||
#ifdef _WIN32
|
||||
throttle = !GetAsyncKeyState(VK_TAB);
|
||||
#else
|
||||
throttle = false;
|
||||
throttle = true;
|
||||
#endif
|
||||
skipFlip = false;
|
||||
skipFrame = false;
|
||||
if (PSP_CoreParameter().headLess)
|
||||
throttle = false;
|
||||
@@ -296,8 +322,7 @@ void DoFrameTiming(bool &throttle, bool &skipFrame, bool &skipFlip) {
|
||||
if (curFrameTime > nextFrameTime && doFrameSkip) {
|
||||
// Argh, we are falling behind! Let's skip a frame and see if we catch up.
|
||||
skipFrame = true;
|
||||
skipFlip = true;
|
||||
INFO_LOG(HLE,"FRAMESKIP %i", numSkippedFrames);
|
||||
// INFO_LOG(HLE,"FRAMESKIP %i", numSkippedFrames);
|
||||
}
|
||||
|
||||
if (curFrameTime < nextFrameTime && throttle)
|
||||
@@ -324,10 +349,10 @@ void DoFrameTiming(bool &throttle, bool &skipFrame, bool &skipFlip) {
|
||||
nextFrameTime = nextFrameTime + 1.0 / 60.0;
|
||||
}
|
||||
|
||||
// Max 6 skipped frames in a row - 10 fps is really the bare minimum for playability.
|
||||
if (numSkippedFrames >= 4) {
|
||||
// Max 4 skipped frames in a row - 15 fps is really the bare minimum for playability.
|
||||
// We check for 3 here so it's 3 skipped frames, 1 non skipped, 3 skipped, etc.
|
||||
if (numSkippedFrames >= 3) {
|
||||
skipFrame = false;
|
||||
skipFlip = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,6 +363,7 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
|
||||
DEBUG_LOG(HLE, "Enter VBlank %i", vbCount);
|
||||
|
||||
isVblank = 1;
|
||||
vCount++; // // vCount increases at each VBLANK.
|
||||
|
||||
// Fire the vblank listeners before we wake threads.
|
||||
__DisplayFireVblank();
|
||||
@@ -371,22 +397,14 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
|
||||
}
|
||||
|
||||
if (g_Config.bShowFPSCounter) {
|
||||
char stats[50];
|
||||
CalculateFPS();
|
||||
}
|
||||
|
||||
sprintf(stats, "%0.1f", calculateFPS());
|
||||
bool skipFlip = false;
|
||||
|
||||
#ifdef USING_GLES2
|
||||
float zoom = 0.7f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.7f;
|
||||
#else
|
||||
float zoom = 0.5f; /// g_Config.iWindowZoom;
|
||||
float soff = 0.5f;
|
||||
#endif
|
||||
PPGeBegin();
|
||||
PPGeDrawText(stats, 476 + soff, 4 + soff, PPGE_ALIGN_RIGHT, zoom, 0xCC000000);
|
||||
PPGeDrawText(stats, 476 + -soff, 4 -soff, PPGE_ALIGN_RIGHT, zoom, 0xCC000000);
|
||||
PPGeDrawText(stats, 476, 4, PPGE_ALIGN_RIGHT, zoom, 0xFF30FF30);
|
||||
PPGeEnd();
|
||||
// This frame was skipped, so no need to flip.
|
||||
if (gstate_c.skipDrawReason & SKIPDRAW_SKIPFRAME) {
|
||||
skipFlip = true;
|
||||
}
|
||||
|
||||
// Draw screen overlays before blitting. Saves and restores the Ge context.
|
||||
@@ -395,11 +413,10 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
|
||||
// anything to draw here.
|
||||
gstate_c.skipDrawReason &= ~SKIPDRAW_SKIPFRAME;
|
||||
|
||||
bool throttle, skipFrame, skipFlip;
|
||||
bool throttle, skipFrame;
|
||||
|
||||
DoFrameTiming(throttle, skipFrame, skipFlip);
|
||||
DoFrameTiming(throttle, skipFrame);
|
||||
|
||||
// Setting CORE_NEXTFRAME causes a swap.
|
||||
if (skipFrame) {
|
||||
gstate_c.skipDrawReason |= SKIPDRAW_SKIPFRAME;
|
||||
numSkippedFrames++;
|
||||
@@ -408,11 +425,11 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
|
||||
}
|
||||
|
||||
if (!skipFlip) {
|
||||
// Might've just quit / been paused.
|
||||
if (coreState == CORE_RUNNING) {
|
||||
// Setting CORE_NEXTFRAME causes a swap.
|
||||
// Check first though, might've just quit / been paused.
|
||||
if (coreState == CORE_RUNNING && gpu->FramebufferDirty()) {
|
||||
coreState = CORE_NEXTFRAME;
|
||||
}
|
||||
CoreTiming::ScheduleEvent(0 - cyclesLate, afterFlipEvent, 0);
|
||||
|
||||
gpu->CopyDisplayToOutput();
|
||||
}
|
||||
@@ -420,6 +437,7 @@ void hleEnterVblank(u64 userdata, int cyclesLate) {
|
||||
// Returning here with coreState == CORE_NEXTFRAME causes a buffer flip to happen (next frame).
|
||||
// Right after, we regain control for a little bit in hleAfterFlip. I think that's a great
|
||||
// place to do housekeeping.
|
||||
CoreTiming::ScheduleEvent(0 - cyclesLate, afterFlipEvent, 0);
|
||||
}
|
||||
|
||||
void hleAfterFlip(u64 userdata, int cyclesLate)
|
||||
@@ -433,36 +451,32 @@ void hleAfterFlip(u64 userdata, int cyclesLate)
|
||||
void hleLeaveVblank(u64 userdata, int cyclesLate) {
|
||||
isVblank = 0;
|
||||
DEBUG_LOG(HLE,"Leave VBlank %i", (int)userdata - 1);
|
||||
vCount++;
|
||||
hCount = 0;
|
||||
frameStartTicks = CoreTiming::GetTicks();
|
||||
CoreTiming::ScheduleEvent(msToCycles(frameMs - vblankMs) - cyclesLate, enterVblankEvent, userdata);
|
||||
}
|
||||
|
||||
void sceDisplayIsVblank() {
|
||||
u32 sceDisplayIsVblank() {
|
||||
DEBUG_LOG(HLE,"%i=sceDisplayIsVblank()",isVblank);
|
||||
RETURN(isVblank);
|
||||
return isVblank;
|
||||
}
|
||||
|
||||
u32 sceDisplaySetMode(u32 unknown, u32 xres, u32 yres) {
|
||||
DEBUG_LOG(HLE,"sceDisplaySetMode(%d,%d,%d)",unknown,xres,yres);
|
||||
u32 sceDisplaySetMode(int displayMode, int displayWidth, int displayHeight) {
|
||||
DEBUG_LOG(HLE,"sceDisplaySetMode(%i, %i, %i)", displayMode, displayWidth, displayHeight);
|
||||
host->BeginFrame();
|
||||
|
||||
if (!hasSetMode) {
|
||||
gpu->InitClear();
|
||||
hasSetMode = true;
|
||||
}
|
||||
|
||||
mode = displayMode;
|
||||
width = displayWidth;
|
||||
height = displayHeight;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceDisplaySetFramebuf() {
|
||||
u32 topaddr = PARAM(0);
|
||||
int linesize = PARAM(1);
|
||||
int pixelformat = PARAM(2);
|
||||
int sync = PARAM(3);
|
||||
|
||||
u32 sceDisplaySetFramebuf(u32 topaddr, int linesize, int pixelformat, int sync) {
|
||||
FrameBufferState fbstate;
|
||||
DEBUG_LOG(HLE,"sceDisplaySetFramebuf(topaddr=%08x,linesize=%d,pixelsize=%d,sync=%d)",topaddr,linesize,pixelformat,sync);
|
||||
DEBUG_LOG(HLE,"sceDisplaySetFramebuf(topaddr=%08x,linesize=%d,pixelsize=%d,sync=%d)", topaddr, linesize, pixelformat, sync);
|
||||
if (topaddr == 0) {
|
||||
DEBUG_LOG(HLE,"- screen off");
|
||||
} else {
|
||||
@@ -502,8 +516,7 @@ bool __DisplayGetFramebuf(u8 **topaddr, u32 *linesize, u32 *pixelFormat, int mod
|
||||
|
||||
u32 sceDisplayGetFramebuf(u32 topaddrPtr, u32 linesizePtr, u32 pixelFormatPtr, int mode) {
|
||||
const FrameBufferState &fbState = mode == 1 ? latchedFramebuf : framebuf;
|
||||
DEBUG_LOG(HLE,"sceDisplayGetFramebuf(*%08x = %08x, *%08x = %08x, *%08x = %08x, %i)",
|
||||
topaddrPtr, fbState.topaddr, linesizePtr, fbState.pspFramebufLinesize, pixelFormatPtr, fbState.pspFramebufFormat, mode);
|
||||
DEBUG_LOG(HLE,"sceDisplayGetFramebuf(*%08x = %08x, *%08x = %08x, *%08x = %08x, %i)", topaddrPtr, fbState.topaddr, linesizePtr, fbState.pspFramebufLinesize, pixelFormatPtr, fbState.pspFramebufFormat, mode);
|
||||
|
||||
if (Memory::IsValidAddress(topaddrPtr))
|
||||
Memory::Write_U32(fbState.topaddr, topaddrPtr);
|
||||
@@ -516,7 +529,7 @@ u32 sceDisplayGetFramebuf(u32 topaddrPtr, u32 linesizePtr, u32 pixelFormatPtr, i
|
||||
}
|
||||
|
||||
u32 sceDisplayWaitVblankStart() {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblankStart()");
|
||||
VERBOSE_LOG(HLE,"sceDisplayWaitVblankStart()");
|
||||
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread()));
|
||||
__KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, false, "vblank start waited");
|
||||
return 0;
|
||||
@@ -524,18 +537,19 @@ u32 sceDisplayWaitVblankStart() {
|
||||
|
||||
u32 sceDisplayWaitVblank() {
|
||||
if (!isVblank) {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblank()");
|
||||
VERBOSE_LOG(HLE,"sceDisplayWaitVblank()");
|
||||
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread()));
|
||||
__KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, false, "vblank waited");
|
||||
return 0;
|
||||
} else {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblank() - not waiting since in vBlank");
|
||||
hleEatMicro(5);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceDisplayWaitVblankStartMulti(int vblanks) {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblankStartMulti()");
|
||||
VERBOSE_LOG(HLE,"sceDisplayWaitVblankStartMulti()");
|
||||
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread(), vblanks));
|
||||
__KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, false, "vblank start multi waited");
|
||||
return 0;
|
||||
@@ -543,52 +557,55 @@ u32 sceDisplayWaitVblankStartMulti(int vblanks) {
|
||||
|
||||
u32 sceDisplayWaitVblankCB() {
|
||||
if (!isVblank) {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblankCB()");
|
||||
VERBOSE_LOG(HLE,"sceDisplayWaitVblankCB()");
|
||||
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread()));
|
||||
__KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, true, "vblank waited");
|
||||
return 0;
|
||||
} else {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblank() - not waiting since in vBlank");
|
||||
hleEatMicro(5);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceDisplayWaitVblankStartCB() {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblankStartCB()");
|
||||
VERBOSE_LOG(HLE,"sceDisplayWaitVblankStartCB()");
|
||||
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread()));
|
||||
__KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, true, "vblank start waited");
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceDisplayWaitVblankStartMultiCB(int vblanks) {
|
||||
DEBUG_LOG(HLE,"sceDisplayWaitVblankStartMultiCB()");
|
||||
VERBOSE_LOG(HLE,"sceDisplayWaitVblankStartMultiCB()");
|
||||
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread(), vblanks));
|
||||
__KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, true, "vblank start multi waited");
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceDisplayGetVcount() {
|
||||
// Too spammy
|
||||
// DEBUG_LOG(HLE,"%i=sceDisplayGetVcount()", vCount);
|
||||
VERBOSE_LOG(HLE,"%i=sceDisplayGetVcount()", vCount);
|
||||
|
||||
// Puyo Puyo Fever polls this as a substitute for waiting for vblank.
|
||||
// As a result, the game never gets to reschedule so it doesn't mix audio and things break.
|
||||
// Need to find a better hack as this breaks games like Project Diva.
|
||||
// hleReSchedule("sceDisplayGetVcount hack"); // Puyo puyo hack?
|
||||
|
||||
CoreTiming::Idle(1000000);
|
||||
hleEatMicro(2);
|
||||
return vCount;
|
||||
}
|
||||
|
||||
void sceDisplayGetCurrentHcount() {
|
||||
RETURN(hCount++);
|
||||
u32 sceDisplayGetCurrentHcount() {
|
||||
u32 currentHCount = (CoreTiming::GetTicks() - frameStartTicks) / ((u64)CoreTiming::GetClockFrequencyMHz() * 1000000 / 60 / 272);
|
||||
DEBUG_LOG(HLE,"%i=sceDisplayGetCurrentHcount()", currentHCount);
|
||||
return currentHCount;
|
||||
}
|
||||
|
||||
void sceDisplayGetAccumulatedHcount() {
|
||||
// Just do an estimate
|
||||
u32 accumHCount = CoreTiming::GetTicks() / (CoreTiming::GetClockFrequencyMHz() * 1000000 / 60 / 272);
|
||||
u32 sceDisplayAdjustAccumulatedHcount() {
|
||||
ERROR_LOG(HLE,"UNIMPL sceDisplayAdjustAccumulatedHcount()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceDisplayGetAccumulatedHcount() {
|
||||
float hCountPerVblank = 285.72f; // insprired by jpcsp
|
||||
u32 currentHCount = (CoreTiming::GetTicks() - frameStartTicks) / ((u64)CoreTiming::GetClockFrequencyMHz() * 1000000 / 60 / 272);
|
||||
u32 accumHCount = currentHCount + (u32) (vCount * hCountPerVblank);
|
||||
DEBUG_LOG(HLE,"%i=sceDisplayGetAccumulatedHcount()", accumHCount);
|
||||
RETURN(accumHCount);
|
||||
return accumHCount;
|
||||
}
|
||||
|
||||
float sceDisplayGetFramePerSec() {
|
||||
@@ -597,9 +614,25 @@ float sceDisplayGetFramePerSec() {
|
||||
return fps; // (9MHz * 1)/(525 * 286)
|
||||
}
|
||||
|
||||
u32 sceDisplayIsForeground() {
|
||||
ERROR_LOG(HLE,"UNIMPL sceDisplayIsForeground()");
|
||||
return 1; // return value according to JPCSP comment
|
||||
}
|
||||
|
||||
u32 sceDisplayGetMode(u32 modeAddr, u32 widthAddr, u32 heightAddr) {
|
||||
DEBUG_LOG(HLE,"sceDisplayGetMode(%08x, %08x, %08x)", modeAddr, widthAddr, heightAddr);
|
||||
if (Memory::IsValidAddress(modeAddr))
|
||||
Memory::Write_U32(mode, modeAddr);
|
||||
if (Memory::IsValidAddress(widthAddr))
|
||||
Memory::Write_U32(width, widthAddr);
|
||||
if (Memory::IsValidAddress(heightAddr))
|
||||
Memory::Write_U32(height, heightAddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const HLEFunction sceDisplay[] = {
|
||||
{0x0E20F177,WrapU_UUU<sceDisplaySetMode>, "sceDisplaySetMode"},
|
||||
{0x289D82FE,WrapU_V<sceDisplaySetFramebuf>, "sceDisplaySetFramebuf"},
|
||||
{0x0E20F177,WrapU_III<sceDisplaySetMode>, "sceDisplaySetMode"},
|
||||
{0x289D82FE,WrapU_UIII<sceDisplaySetFramebuf>, "sceDisplaySetFramebuf"},
|
||||
{0xEEDA2E54,WrapU_UUUI<sceDisplayGetFramebuf>,"sceDisplayGetFrameBuf"},
|
||||
{0x36CDFADE,WrapU_V<sceDisplayWaitVblank>, "sceDisplayWaitVblank"},
|
||||
{0x984C27E7,WrapU_V<sceDisplayWaitVblankStart>, "sceDisplayWaitVblankStart"},
|
||||
@@ -608,17 +641,17 @@ const HLEFunction sceDisplay[] = {
|
||||
{0x46F186C3,WrapU_V<sceDisplayWaitVblankStartCB>, "sceDisplayWaitVblankStartCB"},
|
||||
{0x77ed8b3a,WrapU_I<sceDisplayWaitVblankStartMultiCB>,"sceDisplayWaitVblankStartMultiCB"},
|
||||
{0xdba6c4c4,WrapF_V<sceDisplayGetFramePerSec>,"sceDisplayGetFramePerSec"},
|
||||
{0x773dd3a3,sceDisplayGetCurrentHcount,"sceDisplayGetCurrentHcount"},
|
||||
{0x210eab3a,sceDisplayGetAccumulatedHcount,"sceDisplayGetAccumulatedHcount"},
|
||||
{0xA83EF139,0,"sceDisplayAdjustAccumulatedHcount"},
|
||||
{0x773dd3a3,WrapU_V<sceDisplayGetCurrentHcount>,"sceDisplayGetCurrentHcount"},
|
||||
{0x210eab3a,WrapU_V<sceDisplayGetAccumulatedHcount>,"sceDisplayGetAccumulatedHcount"},
|
||||
{0xA83EF139,WrapU_V<sceDisplayAdjustAccumulatedHcount>,"sceDisplayAdjustAccumulatedHcount"},
|
||||
{0x9C6EAAD7,WrapU_V<sceDisplayGetVcount>,"sceDisplayGetVcount"},
|
||||
{0xDEA197D4,0,"sceDisplayGetMode"},
|
||||
{0xDEA197D4,WrapU_UUU<sceDisplayGetMode>,"sceDisplayGetMode"},
|
||||
{0x7ED59BC4,0,"sceDisplaySetHoldMode"},
|
||||
{0xA544C486,0,"sceDisplaySetResumeMode"},
|
||||
{0xBF79F646,0,"sceDisplayGetResumeMode"},
|
||||
{0xB4F378FA,0,"sceDisplayIsForeground"},
|
||||
{0xB4F378FA,WrapU_V<sceDisplayIsForeground>,"sceDisplayIsForeground"},
|
||||
{0x31C4BAA8,0,"sceDisplayGetBrightness"},
|
||||
{0x4D4E10EC,sceDisplayIsVblank,"sceDisplayIsVblank"},
|
||||
{0x4D4E10EC,WrapU_V<sceDisplayIsVblank>,"sceDisplayIsVblank"},
|
||||
{0x21038913,0,"sceDisplayIsVsync"},
|
||||
};
|
||||
|
||||
|
||||
+856
-853
File diff suppressed because it is too large.
Load diff
@@ -5,6 +5,7 @@ class PointerWrap;
|
||||
void Register_sceFont();
|
||||
|
||||
void __FontInit();
|
||||
void __FontShutdown();
|
||||
void __FontDoState(PointerWrap &p);
|
||||
|
||||
typedef u32 FontLibraryHandle;
|
||||
|
||||
+2
-2
@@ -220,7 +220,7 @@ u32 sceGeDrawSync(u32 mode)
|
||||
|
||||
int sceGeContinue()
|
||||
{
|
||||
//ERROR_LOG(HLE, "UNIMPL sceGeContinue");
|
||||
DEBUG_LOG(HLE, "UNIMPL sceGeContinue");
|
||||
// no arguments
|
||||
return 0;
|
||||
}
|
||||
@@ -228,7 +228,7 @@ int sceGeContinue()
|
||||
int sceGeBreak(u32 mode)
|
||||
{
|
||||
//mode => 0 : current dlist 1: all drawing
|
||||
//ERROR_LOG(HLE, "UNIMPL sceGeBreak(mode=%d)", mode);
|
||||
DEBUG_LOG(HLE, "UNIMPL sceGeBreak(mode=%d)", mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+394
-217
@@ -25,6 +25,8 @@
|
||||
#include "HLE.h"
|
||||
#include "../MIPS/MIPS.h"
|
||||
#include "../HW/MemoryStick.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "../FileSystems/FileSystem.h"
|
||||
#include "../FileSystems/MetaFileSystem.h"
|
||||
@@ -44,11 +46,11 @@ extern "C" {
|
||||
// For headless screenshots.
|
||||
#include "sceDisplay.h"
|
||||
|
||||
#define ERROR_ERRNO_FILE_NOT_FOUND 0x80010002
|
||||
|
||||
#define ERROR_MEMSTICK_DEVCTL_BAD_PARAMS 0x80220081
|
||||
#define ERROR_MEMSTICK_DEVCTL_TOO_MANY_CALLBACKS 0x80220082
|
||||
#define ERROR_KERNEL_BAD_FILE_DESCRIPTOR 0x80020323
|
||||
const int ERROR_ERRNO_FILE_NOT_FOUND = 0x80010002;
|
||||
const int ERROR_ERRNO_FILE_ALREADY_EXISTS = 0x80010011;
|
||||
const int ERROR_MEMSTICK_DEVCTL_BAD_PARAMS = 0x80220081;
|
||||
const int ERROR_MEMSTICK_DEVCTL_TOO_MANY_CALLBACKS = 0x80220082;
|
||||
const int ERROR_KERNEL_BAD_FILE_DESCRIPTOR = 0x80020323;
|
||||
|
||||
#define PSP_DEV_TYPE_ALIAS 0x20
|
||||
|
||||
@@ -87,9 +89,7 @@ typedef s32 SceMode;
|
||||
typedef s64 SceOff;
|
||||
typedef u64 SceIores;
|
||||
|
||||
typedef u32 (*DeferredAction)(SceUID id, int param);
|
||||
DeferredAction defAction = 0;
|
||||
u32 defParam = 0;
|
||||
int asyncNotifyEvent = -1;
|
||||
|
||||
#define SCE_STM_FDIR 0x1000
|
||||
#define SCE_STM_FREG 0x2000
|
||||
@@ -133,7 +133,7 @@ struct dirent {
|
||||
|
||||
class FileNode : public KernelObject {
|
||||
public:
|
||||
FileNode() : callbackID(0), callbackArg(0), asyncResult(0), closePending(false), pendingAsyncResult(false), sectorBlockMode(false) {}
|
||||
FileNode() : callbackID(0), callbackArg(0), asyncResult(0), pendingAsyncResult(false), sectorBlockMode(false), closePending(false), npdrm(0), pgdInfo(NULL) {}
|
||||
~FileNode() {
|
||||
pspFileSystem.CloseFile(handle);
|
||||
}
|
||||
@@ -156,6 +156,9 @@ public:
|
||||
p.Do(closePending);
|
||||
p.Do(info);
|
||||
p.Do(openMode);
|
||||
|
||||
// TODO: Savestate PGD files?
|
||||
|
||||
p.DoMarker("File");
|
||||
}
|
||||
|
||||
@@ -165,10 +168,11 @@ public:
|
||||
u32 callbackID;
|
||||
u32 callbackArg;
|
||||
|
||||
u32 asyncResult;
|
||||
|
||||
s64 asyncResult;
|
||||
bool pendingAsyncResult;
|
||||
|
||||
bool sectorBlockMode;
|
||||
// TODO: Use an enum instead?
|
||||
bool closePending;
|
||||
|
||||
PSPFileInfo info;
|
||||
@@ -184,20 +188,57 @@ public:
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void __IoCompleteAsyncIO(SceUID id);
|
||||
|
||||
static void TellFsThreadEnded (SceUID threadID) {
|
||||
pspFileSystem.ThreadEnded(threadID);
|
||||
}
|
||||
|
||||
// Async IO seems to work roughly like this:
|
||||
// 1. Game calls SceIo*Async() to start the process.
|
||||
// 2. This runs a thread with a customizable priority.
|
||||
// 3. The operation runs, which takes an inconsistent amount of time from UMD.
|
||||
// 4. Once done (regardless of other syscalls), the fd-registered callback is notified.
|
||||
// 5. The game can find out via *CB() or sceKernelCheckCallback().
|
||||
// 6. At this point, the fd is STILL not usable.
|
||||
// 7. One must call sceIoWaitAsync / sceIoWaitAsyncCB / sceIoPollAsync / possibly sceIoGetAsyncStat.
|
||||
// 8. Finally, the fd is usable (or closed via sceIoCloseAsync.) Presumably the io thread has joined now.
|
||||
|
||||
// TODO: Closed files are a bit special: until the fd is reused (?), the async result is still available.
|
||||
// Clearly a buffer is used, it doesn't seem like they are actually kernel objects.
|
||||
|
||||
// TODO: We don't do any of that yet.
|
||||
// For now, let's at least delay the callback mnotification.
|
||||
void __IoAsyncNotify(u64 userdata, int cyclesLate) {
|
||||
SceUID threadID = userdata >> 32;
|
||||
SceUID fd = (SceUID) (userdata & 0xFFFFFFFF);
|
||||
__IoCompleteAsyncIO(fd);
|
||||
|
||||
u32 error;
|
||||
SceUID waitID = __KernelGetWaitID(threadID, WAITTYPE_IO, error);
|
||||
u32 address = __KernelGetWaitValue(threadID, error);
|
||||
if (waitID == fd && error == 0) {
|
||||
__KernelResumeThreadFromWait(threadID, 0);
|
||||
|
||||
FileNode *f = kernelObjects.Get<FileNode>(fd, error);
|
||||
if (Memory::IsValidAddress(address) && f) {
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __IoInit() {
|
||||
INFO_LOG(HLE, "Starting up I/O...");
|
||||
|
||||
MemoryStick_SetFatState(PSP_FAT_MEMORYSTICK_STATE_ASSIGNED);
|
||||
|
||||
asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR], file[_MAX_FNAME], ext[_MAX_EXT];
|
||||
char memstickpath[_MAX_PATH];
|
||||
char flashpath[_MAX_PATH];
|
||||
char flash0path[_MAX_PATH];
|
||||
|
||||
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
|
||||
|
||||
@@ -209,40 +250,36 @@ void __IoInit() {
|
||||
_splitpath_s(path_buffer, drive, dir, file, ext );
|
||||
|
||||
// Mount a couple of filesystems
|
||||
sprintf(memstickpath, "%s%sMemStick\\", drive, dir);
|
||||
sprintf(flashpath, "%s%sFlash\\", drive, dir);
|
||||
sprintf(memstickpath, "%s%smemstick\\", drive, dir);
|
||||
sprintf(flash0path, "%s%sflash0\\", drive, dir);
|
||||
|
||||
#else
|
||||
// TODO
|
||||
std::string memstickpath = g_Config.memCardDirectory;
|
||||
std::string flashpath = g_Config.flashDirectory;
|
||||
std::string flash0path = g_Config.flashDirectory;
|
||||
#endif
|
||||
|
||||
DirectoryFileSystem *memstick;
|
||||
DirectoryFileSystem *flash;
|
||||
|
||||
memstick = new DirectoryFileSystem(&pspFileSystem, memstickpath);
|
||||
flash = new DirectoryFileSystem(&pspFileSystem, flashpath);
|
||||
DirectoryFileSystem *memstick = new DirectoryFileSystem(&pspFileSystem, memstickpath);
|
||||
#ifdef ANDROID
|
||||
VFSFileSystem *flash0 = new VFSFileSystem(&pspFileSystem, "flash0");
|
||||
#else
|
||||
DirectoryFileSystem *flash0 = new DirectoryFileSystem(&pspFileSystem, flash0path);
|
||||
#endif
|
||||
pspFileSystem.Mount("ms0:", memstick);
|
||||
pspFileSystem.Mount("fatms0:", memstick);
|
||||
pspFileSystem.Mount("fatms:", memstick);
|
||||
pspFileSystem.Mount("flash0:", flash);
|
||||
pspFileSystem.Mount("flash1:", flash);
|
||||
pspFileSystem.Mount("flash0:", flash0);
|
||||
|
||||
__KernelListenThreadEnd(&TellFsThreadEnded);
|
||||
}
|
||||
|
||||
void __IoDoState(PointerWrap &p) {
|
||||
// TODO: defAction is hard to save, and not the right way anyway.
|
||||
// Should probbly be an enum and on the FileNode anyway.
|
||||
if (defAction != NULL) {
|
||||
WARN_LOG(HLE, "FIXME: Savestate failure: deferred IO not saved yet.");
|
||||
}
|
||||
p.Do(asyncNotifyEvent);
|
||||
CoreTiming::RestoreRegisterEvent(asyncNotifyEvent, "IoAsyncNotify", __IoAsyncNotify);
|
||||
}
|
||||
|
||||
void __IoShutdown() {
|
||||
defAction = 0;
|
||||
defParam = 0;
|
||||
}
|
||||
|
||||
u32 __IoGetFileHandleFromId(u32 id, u32 &outError)
|
||||
@@ -269,7 +306,7 @@ u32 sceIoAssign(u32 alias_addr, u32 physical_addr, u32 filesystem_addr, int mode
|
||||
perm = "IOASSIGN_RDONLY";
|
||||
break;
|
||||
default:
|
||||
perm = "unhandled " + mode;
|
||||
perm = "unhandled";
|
||||
break;
|
||||
}
|
||||
DEBUG_LOG(HLE, "sceIoAssign(%s, %s, %s, %s, %08x, %i)", alias.c_str(), physical_dev.c_str(), filesystem_dev.c_str(), perm.c_str(), arg_addr, argSize);
|
||||
@@ -304,6 +341,7 @@ void __IoCompleteAsyncIO(SceUID id) {
|
||||
if (f->callbackID) {
|
||||
__KernelNotifyCallback(THREAD_CALLBACK_IO, f->callbackID, f->callbackArg);
|
||||
}
|
||||
f->pendingAsyncResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +375,17 @@ void __IoGetStat(SceIoStat *stat, PSPFileInfo &info) {
|
||||
stat->st_private[0] = info.startSector;
|
||||
}
|
||||
|
||||
void __IoSchedAsync(FileNode *f, SceUID fd, int usec) {
|
||||
u64 param = ((u64)__KernelGetCurThread()) << 32 | fd;
|
||||
CoreTiming::ScheduleEvent(usToCycles(usec), asyncNotifyEvent, param);
|
||||
|
||||
f->pendingAsyncResult = true;
|
||||
}
|
||||
|
||||
u32 sceIoGetstat(const char *filename, u32 addr) {
|
||||
// TODO: Improve timing (although this seems normally slow..)
|
||||
int usec = 1000;
|
||||
|
||||
SceIoStat stat;
|
||||
PSPFileInfo info = pspFileSystem.GetFileInfo(filename);
|
||||
if (info.exists) {
|
||||
@@ -345,14 +393,14 @@ u32 sceIoGetstat(const char *filename, u32 addr) {
|
||||
if (Memory::IsValidAddress(addr)) {
|
||||
Memory::WriteStruct(addr, &stat);
|
||||
DEBUG_LOG(HLE, "sceIoGetstat(%s, %08x) : sector = %08x", filename, addr, info.startSector);
|
||||
return 0;
|
||||
return hleDelayResult(0, "io getstat", usec);
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoGetstat(%s, %08x) : bad address", filename, addr);
|
||||
return -1;
|
||||
return hleDelayResult(-1, "io getstat", usec);
|
||||
}
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "sceIoGetstat(%s, %08x) : FILE NOT FOUND", filename, addr);
|
||||
return ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
return hleDelayResult(ERROR_ERRNO_FILE_NOT_FOUND, "io getstat", usec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,8 +440,7 @@ u32 npdrmRead(FileNode *f, u8 *data, int size) {
|
||||
return size;
|
||||
}
|
||||
|
||||
//Not sure about wrapping it or not, since the log seems to take the address of the data var
|
||||
u32 sceIoRead(int id, u32 data_addr, int size) {
|
||||
int __IoRead(int id, u32 data_addr, int size) {
|
||||
if (id == 3) {
|
||||
DEBUG_LOG(HLE, "sceIoRead STDIN");
|
||||
return 0; //stdin
|
||||
@@ -409,15 +456,15 @@ u32 sceIoRead(int id, u32 data_addr, int size) {
|
||||
else if (Memory::IsValidAddress(data_addr)) {
|
||||
u8 *data = (u8*) Memory::GetPointer(data_addr);
|
||||
if(f->npdrm){
|
||||
f->asyncResult = (u32) npdrmRead(f, data, size);
|
||||
return npdrmRead(f, data, size);
|
||||
}else{
|
||||
f->asyncResult = (u32) pspFileSystem.ReadFile(f->handle, data, size);
|
||||
return (int) pspFileSystem.ReadFile(f->handle, data, size);
|
||||
}
|
||||
DEBUG_LOG(HLE, "%i=sceIoRead(%d, %08x , %i)", f->asyncResult, id, data_addr, size);
|
||||
return f->asyncResult;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoRead Reading into bad pointer %08x", data_addr);
|
||||
return -1;
|
||||
// TODO: Returning 0 because it wasn't being sign-extended in async result before.
|
||||
// What should this do?
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoRead ERROR: no file open");
|
||||
@@ -425,8 +472,33 @@ u32 sceIoRead(int id, u32 data_addr, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceIoWrite(int id, void *data_ptr, int size)
|
||||
{
|
||||
u32 sceIoRead(int id, u32 data_addr, int size) {
|
||||
int result = __IoRead(id, data_addr, size);
|
||||
if (result >= 0) {
|
||||
DEBUG_LOG(HLE, "%x=sceIoRead(%d, %08x, %x)", result, id, data_addr, size);
|
||||
// TODO: Timing is probably not very accurate, low estimate.
|
||||
return hleDelayResult(result, "io read", result / 100);
|
||||
}
|
||||
else
|
||||
return result;
|
||||
}
|
||||
|
||||
u32 sceIoReadAsync(int id, u32 data_addr, int size) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
f->asyncResult = __IoRead(id, data_addr, size);
|
||||
// TODO: Not sure what the correct delay is (and technically we shouldn't read into the buffer yet...)
|
||||
__IoSchedAsync(f, id, size / 100);
|
||||
DEBUG_LOG(HLE, "%llx=sceIoReadAsync(%d, %08x, %x)", f->asyncResult, id, data_addr, size);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoReadAsync: bad file %d", id);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
int __IoWrite(int id, void *data_ptr, int size) {
|
||||
if (id == 2) {
|
||||
//stderr!
|
||||
const char *str = (const char*) data_ptr;
|
||||
@@ -444,28 +516,40 @@ u32 sceIoWrite(int id, void *data_ptr, int size)
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
if(!(f->openMode & FILEACCESS_WRITE))
|
||||
{
|
||||
if(!(f->openMode & FILEACCESS_WRITE)) {
|
||||
return ERROR_KERNEL_BAD_FILE_DESCRIPTOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8 *data = (u8*) data_ptr;
|
||||
f->asyncResult = (u32) pspFileSystem.WriteFile(f->handle, data, size);
|
||||
return f->asyncResult;
|
||||
}
|
||||
return (int) pspFileSystem.WriteFile(f->handle, (u8*) data_ptr, size);
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoWrite ERROR: no file open");
|
||||
return error;
|
||||
return (s32) error;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceIoWriteAsync(int id, void *data_ptr, int size)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoWriteAsync(%d)", id);
|
||||
sceIoWrite(id, data_ptr, size);
|
||||
__IoCompleteAsyncIO(id);
|
||||
return 0;
|
||||
u32 sceIoWrite(int id, u32 data_addr, int size) {
|
||||
int result = __IoWrite(id, Memory::GetPointer(data_addr), size);
|
||||
if (result >= 0) {
|
||||
DEBUG_LOG(HLE, "%x=sceIoWrite(%d, %08x, %x)", result, id, data_addr, size);
|
||||
// TODO: Timing is probably not very accurate, low estimate.
|
||||
return hleDelayResult(result, "io write", result / 100);
|
||||
}
|
||||
else
|
||||
return result;
|
||||
}
|
||||
|
||||
u32 sceIoWriteAsync(int id, u32 data_addr, int size) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
f->asyncResult = __IoWrite(id, Memory::GetPointer(data_addr), size);
|
||||
// TODO: Not sure what the correct delay is (and technically we shouldn't read into the buffer yet...)
|
||||
__IoSchedAsync(f, id, size / 100);
|
||||
DEBUG_LOG(HLE, "%llx=sceIoWriteAsync(%d, %08x, %x)", f->asyncResult, id, data_addr, size);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoWriteAsync: bad file %d", id);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceIoGetDevType(int id)
|
||||
@@ -490,7 +574,7 @@ u32 sceIoCancel(int id)
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
f->closePending = true;
|
||||
// TODO: Cancel the async operation if possible?
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoCancel: unknown id %d", id);
|
||||
error = ERROR_KERNEL_BAD_FILE_DESCRIPTOR;
|
||||
@@ -521,12 +605,12 @@ u32 npdrmLseek(FileNode *f, s32 where, FileMove whence)
|
||||
return newPos;
|
||||
}
|
||||
|
||||
s64 sceIoLseek(int id, s64 offset, int whence) {
|
||||
s64 __IoLseek(SceUID id, s64 offset, int whence) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
FileMove seek = FILEMOVE_BEGIN;
|
||||
bool outOfBound = false;
|
||||
|
||||
s64 newPos = 0;
|
||||
switch (whence) {
|
||||
case 0:
|
||||
@@ -541,59 +625,77 @@ s64 sceIoLseek(int id, s64 offset, int whence) {
|
||||
seek = FILEMOVE_END;
|
||||
break;
|
||||
}
|
||||
if(newPos < 0)
|
||||
// Yes, -1 is the correct return code for this case.
|
||||
if (newPos < 0)
|
||||
return -1;
|
||||
|
||||
if(f->npdrm){
|
||||
f->asyncResult = npdrmLseek(f, (s32)offset, seek);
|
||||
return npdrmLseek(f, (s32)offset, seek);
|
||||
}else{
|
||||
f->asyncResult = (u32) pspFileSystem.SeekFile(f->handle, (s32) offset, seek);
|
||||
return pspFileSystem.SeekFile(f->handle, (s32) offset, seek);
|
||||
}
|
||||
DEBUG_LOG(HLE, "%i = sceIoLseek(%d,%i,%i)", f->asyncResult, id, (int) offset, whence);
|
||||
return f->asyncResult;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoLseek(%d, %i, %i) - ERROR: invalid file", id, (int) offset, whence);
|
||||
return error;
|
||||
return (s32) error;
|
||||
}
|
||||
}
|
||||
|
||||
s64 sceIoLseek(int id, s64 offset, int whence) {
|
||||
s64 result = __IoLseek(id, offset, whence);
|
||||
if (result >= 0) {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoLseek(%d, %llx, %i)", result, id, offset, whence);
|
||||
// Educated guess at timing.
|
||||
return hleDelayResult(result, "io seek", 100);
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoLseek(%d, %llx, %i) - ERROR: invalid file", id, offset, whence);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceIoLseek32(int id, int offset, int whence) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
FileMove seek = FILEMOVE_BEGIN;
|
||||
bool outOfBound = false;
|
||||
s64 newPos = 0;
|
||||
switch (whence) {
|
||||
case 0:
|
||||
newPos = offset;
|
||||
break;
|
||||
case 1:
|
||||
newPos = pspFileSystem.GetSeekPos(f->handle) + offset;
|
||||
seek = FILEMOVE_CURRENT;
|
||||
break;
|
||||
case 2:
|
||||
newPos = f->info.size + offset;
|
||||
seek = FILEMOVE_END;
|
||||
break;
|
||||
}
|
||||
if(newPos < 0)
|
||||
return -1;
|
||||
|
||||
if(f->npdrm){
|
||||
f->asyncResult = npdrmLseek(f, (s32)offset, seek);
|
||||
}else{
|
||||
f->asyncResult = (u32) pspFileSystem.SeekFile(f->handle, (s32) offset, seek);
|
||||
}
|
||||
DEBUG_LOG(HLE, "%i = sceIoLseek32(%d,%i,%i)", f->asyncResult, id, (int) offset, whence);
|
||||
return f->asyncResult;
|
||||
s32 result = (s32) __IoLseek(id, offset, whence);
|
||||
if (result >= 0) {
|
||||
DEBUG_LOG(HLE, "%i = sceIoLseek(%d, %x, %i)", result, id, offset, whence);
|
||||
// Educated guess at timing.
|
||||
return hleDelayResult(result, "io seek", 100);
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoLseek32(%d, %i, %i) - ERROR: invalid file", id, (int) offset, whence);
|
||||
return error;
|
||||
ERROR_LOG(HLE, "sceIoLseek(%d, %x, %i) - ERROR: invalid file", id, offset, whence);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceIoOpen(const char* filename, int flags, int mode) {
|
||||
u32 sceIoLseekAsync(int id, s64 offset, int whence) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get<FileNode>(id, error);
|
||||
if (f) {
|
||||
f->asyncResult = __IoLseek(id, offset, whence);
|
||||
// Educated guess at timing.
|
||||
__IoSchedAsync(f, id, 100);
|
||||
DEBUG_LOG(HLE, "%lli = sceIoLseekAsync(%d, %llx, %i)", f->asyncResult, id, offset, whence);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoLseekAsync(%d, %llx, %i) - ERROR: invalid file", id, offset, whence);
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceIoLseek32Async(int id, int offset, int whence) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get<FileNode>(id, error);
|
||||
if (f) {
|
||||
f->asyncResult = __IoLseek(id, offset, whence);
|
||||
// Educated guess at timing.
|
||||
__IoSchedAsync(f, id, 100);
|
||||
DEBUG_LOG(HLE, "%lli = sceIoLseek32Async(%d, %x, %i)", f->asyncResult, id, offset, whence);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "sceIoLseek32Async(%d, %x, %i) - ERROR: invalid file", id, offset, whence);
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FileNode *__IoOpen(const char* filename, int flags, int mode) {
|
||||
//memory stick filename
|
||||
int access = FILEACCESS_NONE;
|
||||
if (flags & O_RDONLY)
|
||||
@@ -607,11 +709,8 @@ u32 sceIoOpen(const char* filename, int flags, int mode) {
|
||||
|
||||
PSPFileInfo info = pspFileSystem.GetFileInfo(filename);
|
||||
u32 h = pspFileSystem.OpenFile(filename, (FileAccess) access);
|
||||
if (h == 0)
|
||||
{
|
||||
ERROR_LOG(HLE,
|
||||
"ERROR_ERRNO_FILE_NOT_FOUND=sceIoOpen(%s, %08x, %08x) - file not found", filename, flags, mode);
|
||||
return ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
if (h == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FileNode *f = new FileNode();
|
||||
@@ -619,49 +718,66 @@ u32 sceIoOpen(const char* filename, int flags, int mode) {
|
||||
f->handle = h;
|
||||
f->fullpath = filename;
|
||||
f->asyncResult = id;
|
||||
f->info = pspFileSystem.GetFileInfo(filename);
|
||||
f->info = info;
|
||||
f->openMode = access;
|
||||
|
||||
f->npdrm = (flags & O_NPDRM)? true: false;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
u32 sceIoOpen(const char* filename, int flags, int mode) {
|
||||
FileNode *f = __IoOpen(filename, flags, mode);
|
||||
if (f == NULL) {
|
||||
ERROR_LOG(HLE, "ERROR_ERRNO_FILE_NOT_FOUND=sceIoOpen(%s, %08x, %08x) - file not found", filename, flags, mode);
|
||||
// Timing is not accurate, aiming low for now.
|
||||
return hleDelayResult(ERROR_ERRNO_FILE_NOT_FOUND, "file opened", 100);
|
||||
}
|
||||
|
||||
SceUID id = f->GetUID();
|
||||
DEBUG_LOG(HLE, "%i=sceIoOpen(%s, %08x, %08x)", id, filename, flags, mode);
|
||||
return id;
|
||||
// Timing is not accurate, aiming low for now.
|
||||
return hleDelayResult(id, "file opened", 100);
|
||||
}
|
||||
|
||||
u32 sceIoClose(int id) {
|
||||
u32 error;
|
||||
DEBUG_LOG(HLE, "sceIoClose(%d)", id);
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
FileNode *f = kernelObjects.Get<FileNode>(id, error);
|
||||
if(f && f->npdrm){
|
||||
pgd_close(f->pgdInfo);
|
||||
}
|
||||
return kernelObjects.Destroy < FileNode > (id);
|
||||
// Timing is not accurate, aiming low for now.
|
||||
return hleDelayResult(kernelObjects.Destroy<FileNode>(id), "file closed", 100);
|
||||
}
|
||||
|
||||
u32 sceIoRemove(const char *filename) {
|
||||
DEBUG_LOG(HLE, "sceIoRemove(%s)", filename);
|
||||
|
||||
// TODO: This timing isn't necessarily accurate, low end for now.
|
||||
if(!pspFileSystem.GetFileInfo(filename).exists)
|
||||
return ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
return hleDelayResult(ERROR_ERRNO_FILE_NOT_FOUND, "file removed", 100);
|
||||
|
||||
pspFileSystem.RemoveFile(filename);
|
||||
return 0;
|
||||
return hleDelayResult(0, "file removed", 100);
|
||||
}
|
||||
|
||||
u32 sceIoMkdir(const char *dirname, int mode) {
|
||||
DEBUG_LOG(HLE, "sceIoMkdir(%s, %i)", dirname, mode);
|
||||
// TODO: Improve timing.
|
||||
if (pspFileSystem.MkDir(dirname))
|
||||
return 0;
|
||||
return hleDelayResult(0, "mkdir", 1000);
|
||||
else
|
||||
return -1;
|
||||
return hleDelayResult(ERROR_ERRNO_FILE_ALREADY_EXISTS, "mkdir", 1000);
|
||||
}
|
||||
|
||||
u32 sceIoRmdir(const char *dirname) {
|
||||
DEBUG_LOG(HLE, "sceIoRmdir(%s)", dirname);
|
||||
// TODO: Improve timing.
|
||||
if (pspFileSystem.RmDir(dirname))
|
||||
return 0;
|
||||
return hleDelayResult(0, "rmdir", 1000);
|
||||
else
|
||||
return -1;
|
||||
return hleDelayResult(ERROR_ERRNO_FILE_NOT_FOUND, "rmdir", 1000);
|
||||
}
|
||||
|
||||
u32 sceIoSync(const char *devicename, int flag) {
|
||||
@@ -685,22 +801,37 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
|
||||
// UMD checks
|
||||
switch (cmd) {
|
||||
case 0x01F20001: // Get Disc Type.
|
||||
if (Memory::IsValidAddress(outPtr)) {
|
||||
Memory::Write_U32(0x10, outPtr); // Game disc
|
||||
if (Memory::IsValidAddress(outPtr + 4)) {
|
||||
Memory::Write_U32(0x10, outPtr + 4); // Game disc
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 0x01F20002: // Get current LBA.
|
||||
return -1;
|
||||
case 0x01F20002: // Get last sector number.
|
||||
case 0x01F20003: // Seems identical?
|
||||
if (Memory::IsValidAddress(outPtr)) {
|
||||
Memory::Write_U32(0, outPtr); // Game disc
|
||||
PSPFileInfo info = pspFileSystem.GetFileInfo("umd1:");
|
||||
Memory::Write_U32((u32) (info.size / 2048) - 1, outPtr);
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
return -1;
|
||||
case 0x01F100A3: // Seek
|
||||
// Timing is just a rough guess, probably takes longer.
|
||||
return hleDelayResult(0, "dev seek", 100);
|
||||
case 0x01F100A4: // Cache
|
||||
return 0;
|
||||
case 0x01F300A5: // Cache + status
|
||||
if (Memory::IsValidAddress(outPtr)) {
|
||||
Memory::Write_U32(1, outPtr);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
// TODO: What does these do? Seem to require a u32 in, no output.
|
||||
case 0x01F100A6:
|
||||
case 0x01F100A8:
|
||||
case 0x01F100A9:
|
||||
case 0x01F300A7:
|
||||
Reporting::ReportMessage("sceIoDevctl(\"%s\", %08x, %08x, %i, %08x, %i)", name, cmd, argAddr, argLen, outPtr, outLen);
|
||||
ERROR_LOG(HLE, "UNIMPL sceIoDevctl(\"%s\", %08x, %08x, %i, %08x, %i)", name, cmd, argAddr, argLen, outPtr, outLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -773,6 +904,15 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
|
||||
ERROR_LOG(HLE, "memstick size query: bad params");
|
||||
return ERROR_MEMSTICK_DEVCTL_BAD_PARAMS;
|
||||
}
|
||||
|
||||
case 0x02425824: // Check if write protected
|
||||
if (Memory::IsValidAddress(outPtr) && outLen == 4) {
|
||||
Memory::Write_U32(0, outPtr);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "Failed 0x02425824 fat");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,6 +962,16 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02425824: // Check if write protected
|
||||
if (Memory::IsValidAddress(outPtr) && outLen == 4) {
|
||||
Memory::Write_U32(0, outPtr);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "Failed 0x02425824 fat");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02425818: // Get memstick size etc
|
||||
// Pretend we have a 2GB memory stick.
|
||||
{
|
||||
@@ -858,13 +1008,14 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
|
||||
case 2: // EMULATOR_DEVCTL__SEND_OUTPUT
|
||||
{
|
||||
std::string data(Memory::GetCharPointer(argAddr), argLen);
|
||||
if (PSP_CoreParameter().printfEmuLog)
|
||||
{
|
||||
if (PSP_CoreParameter().printfEmuLog) {
|
||||
host->SendDebugOutput(data.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(HLE, "%s", data.c_str());
|
||||
} else {
|
||||
if (PSP_CoreParameter().collectEmuLog) {
|
||||
*PSP_CoreParameter().collectEmuLog += data;
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "%s", data.c_str());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -907,12 +1058,13 @@ u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 outPtr,
|
||||
u32 sceIoRename(const char *from, const char *to) {
|
||||
DEBUG_LOG(HLE, "sceIoRename(%s, %s)", from, to);
|
||||
|
||||
if(!pspFileSystem.GetFileInfo(from).exists)
|
||||
return ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
// TODO: Timing isn't terribly accurate.
|
||||
if (!pspFileSystem.GetFileInfo(from).exists)
|
||||
return hleDelayResult(ERROR_ERRNO_FILE_NOT_FOUND, "file renamed", 1000);
|
||||
|
||||
if(!pspFileSystem.RenameFile(from, to))
|
||||
WARN_LOG(HLE, "Could not move %s to %s\n",from, to);
|
||||
return 0;
|
||||
if (!pspFileSystem.RenameFile(from, to))
|
||||
WARN_LOG(HLE, "Could not move %s to %s", from, to);
|
||||
return hleDelayResult(0, "file renamed", 1000);
|
||||
}
|
||||
|
||||
u32 sceIoChdir(const char *dirname) {
|
||||
@@ -927,29 +1079,21 @@ int sceIoChangeAsyncPriority(int id, int priority)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 __IoClose(SceUID actedFd, int closedFd)
|
||||
{
|
||||
DEBUG_LOG(HLE, "Deferred IoClose(%d, %d)", actedFd, closedFd);
|
||||
__IoCompleteAsyncIO(closedFd);
|
||||
return kernelObjects.Destroy < FileNode > (closedFd);
|
||||
}
|
||||
|
||||
int sceIoCloseAsync(int id)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoCloseAsync(%d)", id);
|
||||
//sceIoClose();
|
||||
// TODO: Not sure this is a good solution. Seems like you can defer one per fd.
|
||||
defAction = &__IoClose;
|
||||
defParam = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceIoLseekAsync(int id, s64 offset, int whence)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoLseekAsync(%d) sorta implemented", id);
|
||||
sceIoLseek(id, offset, whence);
|
||||
__IoCompleteAsyncIO(id);
|
||||
return 0;
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get<FileNode>(id, error);
|
||||
if (f)
|
||||
{
|
||||
f->closePending = true;
|
||||
f->asyncResult = 0;
|
||||
// TODO: Rough estimate.
|
||||
__IoSchedAsync(f, id, 100);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return error;
|
||||
}
|
||||
|
||||
u32 sceIoSetAsyncCallback(int id, u32 clbckId, u32 clbckArg)
|
||||
@@ -960,7 +1104,6 @@ u32 sceIoSetAsyncCallback(int id, u32 clbckId, u32 clbckArg)
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f)
|
||||
{
|
||||
// TODO: Check replacing / updating?
|
||||
f->callbackID = clbckId;
|
||||
f->callbackArg = clbckArg;
|
||||
return 0;
|
||||
@@ -971,41 +1114,34 @@ u32 sceIoSetAsyncCallback(int id, u32 clbckId, u32 clbckArg)
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceIoLseek32Async(int id, int offset, int whence)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoLseek32Async(%d) sorta implemented", id);
|
||||
sceIoLseek32(id, offset, whence);
|
||||
__IoCompleteAsyncIO(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceIoOpenAsync(const char *filename, int flags, int mode)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoOpenAsync() sorta implemented");
|
||||
u32 fd = sceIoOpen(filename, flags, mode);
|
||||
|
||||
// TODO: This can't actually have a callback yet, but if it's set before waiting, it should be called.
|
||||
__IoCompleteAsyncIO(fd);
|
||||
FileNode *f = __IoOpen(filename, flags, mode);
|
||||
SceUID fd;
|
||||
|
||||
// We have to return an fd here, which may have been destroyed when we reach Wait if it failed.
|
||||
if (fd == ERROR_ERRNO_FILE_NOT_FOUND)
|
||||
if (f == NULL)
|
||||
{
|
||||
FileNode *f = new FileNode();
|
||||
ERROR_LOG(HLE, "ERROR_ERRNO_FILE_NOT_FOUND=sceIoOpenAsync(%s, %08x, %08x) - file not found", filename, flags, mode);
|
||||
|
||||
f = new FileNode();
|
||||
fd = kernelObjects.Create(f);
|
||||
f->handle = 0;
|
||||
f->handle = fd;
|
||||
f->fullpath = filename;
|
||||
f->asyncResult = ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
f->closePending = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = f->GetUID();
|
||||
DEBUG_LOG(HLE, "%x=sceIoOpenAsync(%s, %08x, %08x)", fd, filename, flags, mode);
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
// TODO: Timing is very inconsistent. From ms0, 10ms - 20ms depending on filesize/dir depth? From umd, can take > 1s.
|
||||
// For now let's aim low.
|
||||
__IoSchedAsync(f, fd, 100);
|
||||
|
||||
u32 sceIoReadAsync(int id, u32 data_addr, int size)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoReadAsync(%d)", id);
|
||||
sceIoRead(id, data_addr, size);
|
||||
__IoCompleteAsyncIO(id);
|
||||
return 0;
|
||||
return fd;
|
||||
}
|
||||
|
||||
u32 sceIoGetAsyncStat(int id, u32 poll, u32 address)
|
||||
@@ -1014,10 +1150,22 @@ u32 sceIoGetAsyncStat(int id, u32 poll, u32 address)
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f)
|
||||
{
|
||||
Memory::Write_U64(f->asyncResult, address);
|
||||
DEBUG_LOG(HLE, "%i = sceIoGetAsyncStat(%i, %i, %08x) (HACK)", (u32) f->asyncResult, id, poll, address);
|
||||
if (!poll)
|
||||
hleReSchedule("io waited");
|
||||
if (f->pendingAsyncResult) {
|
||||
if (poll) {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoGetAsyncStat(%i, %i, %08x): not ready", f->asyncResult, id, poll, address);
|
||||
return 1;
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoGetAsyncStat(%i, %i, %08x): waiting", f->asyncResult, id, poll, address);
|
||||
__KernelWaitCurThread(WAITTYPE_IO, id, address, 0, false, "io waited");
|
||||
}
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoGetAsyncStat(%i, %i, %08x)", f->asyncResult, id, poll, address);
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
|
||||
if (f->closePending) {
|
||||
kernelObjects.Destroy<FileNode>(id);
|
||||
}
|
||||
}
|
||||
return 0; //completed
|
||||
}
|
||||
else
|
||||
@@ -1031,14 +1179,17 @@ int sceIoWaitAsync(int id, u32 address) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
u64 res = f->asyncResult;
|
||||
if (defAction) {
|
||||
res = defAction(id, defParam);
|
||||
defAction = 0;
|
||||
if (f->pendingAsyncResult) {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoWaitAsync(%i, %08x): waiting", f->asyncResult, id, address);
|
||||
__KernelWaitCurThread(WAITTYPE_IO, id, address, 0, false, "io waited");
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoWaitAsync(%i, %08x)", f->asyncResult, id, address);
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
|
||||
if (f->closePending) {
|
||||
kernelObjects.Destroy<FileNode>(id);
|
||||
}
|
||||
}
|
||||
Memory::Write_U64(res, address);
|
||||
DEBUG_LOG(HLE, "%i = sceIoWaitAsync(%i, %08x) (HACK)", (u32) res, id, address);
|
||||
hleReSchedule("io waited");
|
||||
return 0; //completed
|
||||
} else {
|
||||
ERROR_LOG(HLE, "ERROR - sceIoWaitAsync waiting for invalid id %i", id);
|
||||
@@ -1051,15 +1202,18 @@ int sceIoWaitAsyncCB(int id, u32 address) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
u64 res = f->asyncResult;
|
||||
if (defAction) {
|
||||
res = defAction(id, defParam);
|
||||
defAction = 0;
|
||||
}
|
||||
Memory::Write_U64(res, address);
|
||||
DEBUG_LOG(HLE, "%i = sceIoWaitAsyncCB(%i, %08x) (HACK)", (u32) res, id, address);
|
||||
hleCheckCurrentCallbacks();
|
||||
hleReSchedule(true, "io waited");
|
||||
if (f->pendingAsyncResult) {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoWaitAsyncCB(%i, %08x): waiting", f->asyncResult, id, address);
|
||||
__KernelWaitCurThread(WAITTYPE_IO, id, address, 0, false, "io waited");
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoWaitAsyncCB(%i, %08x)", f->asyncResult, id, address);
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
|
||||
if (f->closePending) {
|
||||
kernelObjects.Destroy<FileNode>(id);
|
||||
}
|
||||
}
|
||||
return 0; //completed
|
||||
} else {
|
||||
ERROR_LOG(HLE, "ERROR - sceIoWaitAsyncCB waiting for invalid id %i", id);
|
||||
@@ -1071,14 +1225,18 @@ u32 sceIoPollAsync(int id, u32 address) {
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
u64 res = f->asyncResult;
|
||||
if (defAction) {
|
||||
res = defAction(id, defParam);
|
||||
defAction = 0;
|
||||
if (f->pendingAsyncResult) {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoPollAsync(%i, %08x): not ready", f->asyncResult, id, address);
|
||||
return 1;
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "%lli = sceIoPollAsync(%i, %08x)", f->asyncResult, id, address);
|
||||
Memory::Write_U64((u64) f->asyncResult, address);
|
||||
|
||||
if (f->closePending) {
|
||||
kernelObjects.Destroy<FileNode>(id);
|
||||
}
|
||||
return 0; //completed
|
||||
}
|
||||
Memory::Write_U64(res, address);
|
||||
DEBUG_LOG(HLE, "%i = sceIoPollAsync(%i, %08x) (HACK)", (u32) res, id, address);
|
||||
return 0; //completed
|
||||
} else {
|
||||
ERROR_LOG(HLE, "ERROR - sceIoPollAsync waiting for invalid id %i", id);
|
||||
return -1; // TODO: correct error code
|
||||
@@ -1114,7 +1272,6 @@ public:
|
||||
u32 sceIoDopen(const char *path) {
|
||||
DEBUG_LOG(HLE, "sceIoDopen(\"%s\")", path);
|
||||
|
||||
|
||||
if(!pspFileSystem.GetFileInfo(path).exists)
|
||||
{
|
||||
return ERROR_ERRNO_FILE_NOT_FOUND;
|
||||
@@ -1127,6 +1284,7 @@ u32 sceIoDopen(const char *path) {
|
||||
dir->index = 0;
|
||||
dir->name = std::string(path);
|
||||
|
||||
// TODO: The result is delayed only from the memstick, it seems.
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -1150,7 +1308,10 @@ u32 sceIoDread(int id, u32 dirent_addr) {
|
||||
entry->d_private = 0xC0DEBABE;
|
||||
DEBUG_LOG(HLE, "sceIoDread( %d %08x ) = %s", id, dirent_addr, entry->d_name);
|
||||
|
||||
dir->index++;
|
||||
// TODO: Improve timing. Only happens on the *first* entry read, ms and umd.
|
||||
if (dir->index++ == 0) {
|
||||
return hleDelayResult(1, "readdir", 1000);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
DEBUG_LOG(HLE, "sceIoDread - invalid listing %i, error %08x", id, error);
|
||||
@@ -1163,11 +1324,12 @@ u32 sceIoDclose(int id) {
|
||||
return kernelObjects.Destroy<DirListing>(id);
|
||||
}
|
||||
|
||||
u32 sceIoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen)
|
||||
int __IoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen)
|
||||
{
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get<FileNode>(id, error);
|
||||
if (error) {
|
||||
ERROR_LOG(HLE, "UNIMPL %08x=sceIoIoctl id: %08x, cmd %08x, bad file", error, id, cmd);
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -1185,12 +1347,12 @@ u32 sceIoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 ou
|
||||
u8 keybuf[16];
|
||||
u8 pgd_header[0x90];
|
||||
u8 pgd_magic[4] = {0x00, 0x50, 0x47, 0x44};
|
||||
INFO_LOG(HLE, "Decrypting PGD DRM files");
|
||||
memcpy(keybuf, Memory::GetPointer(indataPtr), 16);
|
||||
pspFileSystem.ReadFile(f->handle, pgd_header, 0x90);
|
||||
|
||||
f->pgdInfo = pgd_open(pgd_header, 2, keybuf);
|
||||
if(f->pgdInfo==NULL){
|
||||
DEBUG_LOG(HLE, "Not a valid PGD file. Open as normal file.");
|
||||
ERROR_LOG(HLE, "Not a valid PGD file. Open as normal file.");
|
||||
f->npdrm = false;
|
||||
pspFileSystem.SeekFile(f->handle, (s32)0, FILEMOVE_BEGIN);
|
||||
if(memcmp(pgd_header, pgd_magic, 4)==0){
|
||||
@@ -1241,19 +1403,34 @@ u32 sceIoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 ou
|
||||
break;
|
||||
|
||||
default:
|
||||
Reporting::ReportMessage("sceIoIoctl(%s, %08x, %x, %08x, %x)", f->fullpath.c_str(), indataPtr, inlen, outdataPtr, outlen);
|
||||
ERROR_LOG(HLE, "UNIMPL 0=sceIoIoctl id: %08x, cmd %08x, indataPtr %08x, inlen %08x, outdataPtr %08x, outLen %08x", id,cmd,indataPtr,inlen,outdataPtr,outlen);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceIoIoctl(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen)
|
||||
{
|
||||
int result = __IoIoctl(id, cmd, indataPtr, inlen, outdataPtr, outlen);
|
||||
// Just a low estimate on timing.
|
||||
return hleDelayResult(0, "io ctrl command", 100);
|
||||
}
|
||||
|
||||
u32 sceIoIoctlAsync(u32 id, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceIoIoctlAsync(%08x, %08x, %08x, %08x, %08x, %08x)", id, cmd, indataPtr, inlen, outdataPtr, outlen);
|
||||
sceIoIoctl(id, cmd, indataPtr, inlen, outdataPtr, outlen);
|
||||
__IoCompleteAsyncIO(id);
|
||||
return 0;
|
||||
u32 error;
|
||||
FileNode *f = kernelObjects.Get < FileNode > (id, error);
|
||||
if (f) {
|
||||
DEBUG_LOG(HLE, "sceIoIoctlAsync(%08x, %08x, %08x, %08x, %08x, %08x)", id, cmd, indataPtr, inlen, outdataPtr, outlen);
|
||||
f->asyncResult = __IoIoctl(id, cmd, indataPtr, inlen, outdataPtr, outlen);
|
||||
__IoSchedAsync(f, id, 100);
|
||||
return 0;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "UNIMPL %08x=sceIoIoctl id: %08x, cmd %08x, bad file", error, id, cmd);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
KernelObject *__KernelFileNodeObject() {
|
||||
@@ -1297,8 +1474,8 @@ const HLEFunction IoFileMgrForUser[] = {
|
||||
{ 0xA12A0514, &WrapU_IUU<sceIoSetAsyncCallback>, "sceIoSetAsyncCallback" },
|
||||
{ 0xab96437f, &WrapU_CI<sceIoSync>, "sceIoSync" },
|
||||
{ 0x6d08a871, &WrapU_C<sceIoUnassign>, "sceIoUnassign" },
|
||||
{ 0x42EC03AC, &WrapU_IVI<sceIoWrite>, "sceIoWrite" }, //(int fd, void *data, int size);
|
||||
{ 0x0facab19, &WrapU_IVI<sceIoWriteAsync>, "sceIoWriteAsync" },
|
||||
{ 0x42EC03AC, &WrapU_IUI<sceIoWrite>, "sceIoWrite" }, //(int fd, void *data, int size);
|
||||
{ 0x0facab19, &WrapU_IUI<sceIoWriteAsync>, "sceIoWriteAsync" },
|
||||
{ 0x35dbd746, &WrapI_IU<sceIoWaitAsyncCB>, "sceIoWaitAsyncCB" },
|
||||
{ 0xe23eec33, &WrapI_IU<sceIoWaitAsync>, "sceIoWaitAsync" },
|
||||
};
|
||||
|
||||
+57
-11
@@ -20,6 +20,7 @@
|
||||
#include "../MIPS/MIPSCodeUtils.h"
|
||||
#include "../MIPS/MIPSInt.h"
|
||||
|
||||
#include "Common/LogManager.h"
|
||||
#include "../FileSystems/FileSystem.h"
|
||||
#include "../FileSystems/MetaFileSystem.h"
|
||||
#include "../PSPLoaders.h"
|
||||
@@ -29,7 +30,6 @@
|
||||
#include "../../GPU/GPUInterface.h"
|
||||
#include "../../GPU/GPUState.h"
|
||||
|
||||
|
||||
#include "__sceAudio.h"
|
||||
#include "sceAtrac.h"
|
||||
#include "sceAudio.h"
|
||||
@@ -88,6 +88,7 @@ void __KernelInit()
|
||||
__KernelMemoryInit();
|
||||
__KernelThreadingInit();
|
||||
__KernelAlarmInit();
|
||||
__KernelVTimerInit();
|
||||
__KernelEventFlagInit();
|
||||
__KernelMbxInit();
|
||||
__KernelMutexInit();
|
||||
@@ -108,6 +109,7 @@ void __KernelInit()
|
||||
__ImposeInit();
|
||||
__UsbInit();
|
||||
__FontInit();
|
||||
|
||||
SaveState::Init(); // Must be after IO, as it may create a directory
|
||||
|
||||
// "Internal" PSP libraries
|
||||
@@ -126,8 +128,11 @@ void __KernelShutdown()
|
||||
}
|
||||
kernelObjects.List();
|
||||
INFO_LOG(HLE, "Shutting down kernel - %i kernel objects alive", kernelObjects.GetCount());
|
||||
hleCurrentThreadName = NULL;
|
||||
kernelObjects.Clear();
|
||||
|
||||
__FontShutdown();
|
||||
|
||||
__MpegShutdown();
|
||||
__PsmfShutdown();
|
||||
__PPGeShutdown();
|
||||
@@ -162,6 +167,7 @@ void __KernelDoState(PointerWrap &p)
|
||||
__KernelMemoryDoState(p);
|
||||
__KernelThreadingDoState(p);
|
||||
__KernelAlarmDoState(p);
|
||||
__KernelVTimerDoState(p);
|
||||
__KernelEventFlagDoState(p);
|
||||
__KernelMbxDoState(p);
|
||||
__KernelModuleDoState(p);
|
||||
@@ -437,7 +443,10 @@ void KernelObjectPool::DoState(PointerWrap &p)
|
||||
ERROR_LOG(HLE, "Unable to load state: different kernel object storage.");
|
||||
|
||||
if (p.mode == p.MODE_READ)
|
||||
{
|
||||
hleCurrentThreadName = NULL;
|
||||
kernelObjects.Clear();
|
||||
}
|
||||
|
||||
p.DoArray(occupied, maxCount);
|
||||
for (int i = 0; i < maxCount; ++i)
|
||||
@@ -520,20 +529,57 @@ struct SystemStatus {
|
||||
SceUInt perfcounter3;
|
||||
};
|
||||
|
||||
u32 sceKernelReferSystemStatus(u32 statusPtr)
|
||||
{
|
||||
int sceKernelReferSystemStatus(u32 statusPtr) {
|
||||
DEBUG_LOG(HLE, "sceKernelReferSystemStatus(%08x)", statusPtr);
|
||||
if (Memory::IsValidAddress(statusPtr)) {
|
||||
SystemStatus status;
|
||||
memset(&status, 0, sizeof(SystemStatus));
|
||||
status.size = sizeof(SystemStatus);
|
||||
// TODO: Fill in the struct!
|
||||
Memory::WriteStruct(statusPtr, &status);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelReferGlobalProfiler(u32 statusPtr) {
|
||||
DEBUG_LOG(HLE, "sceKernelReferGlobalProfiler(%08x)", statusPtr);
|
||||
struct DebugProfilerRegs {
|
||||
u32 enable;
|
||||
u32 systemck;
|
||||
u32 cpuck;
|
||||
u32 internal;
|
||||
u32 memory;
|
||||
u32 copz;
|
||||
u32 vfpu;
|
||||
u32 sleep;
|
||||
u32 bus_access;
|
||||
u32 uncached_load;
|
||||
u32 uncached_store;
|
||||
u32 cached_load;
|
||||
u32 cached_store;
|
||||
u32 i_miss;
|
||||
u32 d_miss;
|
||||
u32 d_writeback;
|
||||
u32 cop0_inst;
|
||||
u32 fpu_inst;
|
||||
u32 vfpu_inst;
|
||||
u32 local_bus;
|
||||
};
|
||||
|
||||
u32 sceKernelReferThreadProfiler(u32 statusPtr) {
|
||||
ERROR_LOG(HLE, "FAKE sceKernelReferThreadProfiler()");
|
||||
|
||||
// Can we confirm that the struct above is the right struct?
|
||||
// If so, re-enable this code.
|
||||
//DebugProfilerRegs regs;
|
||||
//memset(®s, 0, sizeof(regs));
|
||||
// TODO: fill the struct.
|
||||
//if (Memory::IsValidAddress(statusPtr)) {
|
||||
// Memory::WriteStruct(statusPtr, ®s);
|
||||
//}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sceKernelReferGlobalProfiler(u32 statusPtr) {
|
||||
DEBUG_LOG(HLE, "UNIMPL sceKernelReferGlobalProfiler(%08x)", statusPtr);
|
||||
// Ignore for now
|
||||
return 0;
|
||||
}
|
||||
@@ -579,8 +625,8 @@ const HLEFunction ThreadManForUser[] =
|
||||
{0x9fa03cd3,WrapI_I<sceKernelDeleteThread>,"sceKernelDeleteThread"},
|
||||
{0xBD123D9E,sceKernelDelaySysClockThread,"sceKernelDelaySysClockThread"},
|
||||
{0x1181E963,sceKernelDelaySysClockThreadCB,"sceKernelDelaySysClockThreadCB"},
|
||||
{0xceadeb47,sceKernelDelayThread,"sceKernelDelayThread"},
|
||||
{0x68da9e36,sceKernelDelayThreadCB,"sceKernelDelayThreadCB"},
|
||||
{0xceadeb47,WrapI_U<sceKernelDelayThread>,"sceKernelDelayThread"},
|
||||
{0x68da9e36,WrapI_U<sceKernelDelayThreadCB>,"sceKernelDelayThreadCB"},
|
||||
{0xaa73c935,sceKernelExitThread,"sceKernelExitThread"},
|
||||
{0x809ce29b,sceKernelExitDeleteThread,"sceKernelExitDeleteThread"},
|
||||
{0x94aa61ee,sceKernelGetThreadCurrentPriority,"sceKernelGetThreadCurrentPriority"},
|
||||
@@ -598,7 +644,7 @@ const HLEFunction ThreadManForUser[] =
|
||||
{0x82826f70,sceKernelSleepThreadCB,"sceKernelSleepThreadCB"},
|
||||
{0xF475845D,&WrapI_IUU<sceKernelStartThread>,"sceKernelStartThread"},
|
||||
{0x9944f31f,sceKernelSuspendThread,"sceKernelSuspendThread"},
|
||||
{0x616403ba,WrapI_U<sceKernelTerminateThread>,"sceKernelTerminateThread"},
|
||||
{0x616403ba,WrapI_I<sceKernelTerminateThread>,"sceKernelTerminateThread"},
|
||||
{0x383f7bcc,WrapI_I<sceKernelTerminateDeleteThread>,"sceKernelTerminateDeleteThread"},
|
||||
{0x840E8133,WrapI_IU<sceKernelWaitThreadEndCB>,"sceKernelWaitThreadEndCB"},
|
||||
{0xd13bde95,sceKernelCheckThreadStack,"sceKernelCheckThreadStack"},
|
||||
@@ -611,9 +657,9 @@ const HLEFunction ThreadManForUser[] =
|
||||
{0xdb738f35,WrapI_U<sceKernelGetSystemTime>,"sceKernelGetSystemTime"},
|
||||
{0x369ed59d,WrapU_V<sceKernelGetSystemTimeLow>,"sceKernelGetSystemTimeLow"},
|
||||
|
||||
{0x8218B4DD,&WrapU_U<sceKernelReferGlobalProfiler>,"sceKernelReferGlobalProfiler"},
|
||||
{0x627E6F3A,&WrapU_U<sceKernelReferSystemStatus>,"sceKernelReferSystemStatus"},
|
||||
{0x64D4540E,0,"sceKernelReferThreadProfiler"},
|
||||
{0x8218B4DD,WrapI_U<sceKernelReferGlobalProfiler>,"sceKernelReferGlobalProfiler"},
|
||||
{0x627E6F3A,WrapI_U<sceKernelReferSystemStatus>,"sceKernelReferSystemStatus"},
|
||||
{0x64D4540E,WrapU_U<sceKernelReferThreadProfiler>,"sceKernelReferThreadProfiler"},
|
||||
|
||||
//Fifa Street 2 uses alarms
|
||||
{0x6652b8ca,WrapI_UUU<sceKernelSetAlarm>,"sceKernelSetAlarm"},
|
||||
|
||||
@@ -87,6 +87,7 @@ enum
|
||||
SCE_KERNEL_ERROR_ILLEGAL_CHUNK_ID = 0x800200de,
|
||||
SCE_KERNEL_ERROR_NOCHUNK = 0x800200df,
|
||||
SCE_KERNEL_ERROR_NO_FREECHUNK = 0x800200e0,
|
||||
SCE_ERROR_KERNEL_ILLEGAL_ALIGNMENT_SIZE = 0x800200e4,
|
||||
SCE_KERNEL_ERROR_LINKERR = 0x8002012c,
|
||||
SCE_KERNEL_ERROR_ILLEGAL_OBJECT = 0x8002012d,
|
||||
SCE_KERNEL_ERROR_UNKNOWN_MODULE = 0x8002012e,
|
||||
|
||||
@@ -66,7 +66,7 @@ static bool inInterrupt;
|
||||
|
||||
void sceKernelCpuSuspendIntr()
|
||||
{
|
||||
//LOG(HLE,"sceKernelCpuSuspendIntr"); // very spammy
|
||||
VERBOSE_LOG(HLE, "sceKernelCpuSuspendIntr");
|
||||
int returnValue;
|
||||
if (__InterruptsEnabled())
|
||||
{
|
||||
@@ -82,7 +82,7 @@ void sceKernelCpuSuspendIntr()
|
||||
|
||||
void sceKernelCpuResumeIntr(u32 enable)
|
||||
{
|
||||
//LOG(HLE,"sceKernelCpuResumeIntr(%i)", enable); // very spammy
|
||||
VERBOSE_LOG(HLE, "sceKernelCpuResumeIntr(%i)", enable);
|
||||
if (enable)
|
||||
{
|
||||
__EnableInterrupts();
|
||||
@@ -411,7 +411,7 @@ SubIntrHandler *__RegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32
|
||||
return subIntrHandler;
|
||||
}
|
||||
|
||||
u32 __ReleaseSubIntrHandler(u32 intrNumber, u32 subIntrNumber)
|
||||
int __ReleaseSubIntrHandler(int intrNumber, int subIntrNumber)
|
||||
{
|
||||
if (!intrHandlers[intrNumber]->has(subIntrNumber))
|
||||
return -1;
|
||||
@@ -446,9 +446,9 @@ u32 sceKernelRegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32 handl
|
||||
return error;
|
||||
}
|
||||
|
||||
u32 sceKernelReleaseSubIntrHandler(u32 intrNumber, u32 subIntrNumber)
|
||||
int sceKernelReleaseSubIntrHandler(int intrNumber, int subIntrNumber)
|
||||
{
|
||||
DEBUG_LOG(HLE,"sceKernelReleaseSubIntrHandler(%i, %i)", PARAM(0), PARAM(1));
|
||||
DEBUG_LOG(HLE, "sceKernelReleaseSubIntrHandler(%i, %i)", intrNumber, subIntrNumber);
|
||||
|
||||
if (intrNumber >= PSP_NUMBER_INTERRUPTS)
|
||||
return -1;
|
||||
@@ -567,7 +567,7 @@ void Register_Kernel_Library()
|
||||
const HLEFunction InterruptManager[] =
|
||||
{
|
||||
{0xCA04A2B9, WrapU_UUUU<sceKernelRegisterSubIntrHandler>, "sceKernelRegisterSubIntrHandler"},
|
||||
{0xD61E6961, WrapU_UU<sceKernelReleaseSubIntrHandler>, "sceKernelReleaseSubIntrHandler"},
|
||||
{0xD61E6961, WrapI_II<sceKernelReleaseSubIntrHandler>, "sceKernelReleaseSubIntrHandler"},
|
||||
{0xFB8E22EC, WrapU_UU<sceKernelEnableSubIntr>, "sceKernelEnableSubIntr"},
|
||||
{0x8A389411, WrapU_UU<sceKernelDisableSubIntr>, "sceKernelDisableSubIntr"},
|
||||
{0x5CB5A78B, 0, "sceKernelSuspendSubIntr"},
|
||||
|
||||
@@ -139,10 +139,10 @@ void __KernelReturnFromInterrupt();
|
||||
|
||||
void __RegisterIntrHandler(u32 intrNumber, IntrHandler* handler);
|
||||
SubIntrHandler *__RegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32 &error);
|
||||
u32 __ReleaseSubIntrHandler(u32 intrNumber, u32 subIntrNumber);
|
||||
int __ReleaseSubIntrHandler(int intrNumber, int subIntrNumber);
|
||||
|
||||
u32 sceKernelRegisterSubIntrHandler(u32 intrNumber, u32 subIntrNumber, u32 handler, u32 handlerArg);
|
||||
u32 sceKernelReleaseSubIntrHandler(u32 intrNumber, u32 subIntrNumber);
|
||||
int sceKernelReleaseSubIntrHandler(int intrNumber, int subIntrNumber);
|
||||
u32 sceKernelEnableSubIntr(u32 intrNumber, u32 subIntrNumber);
|
||||
|
||||
void Register_Kernel_Library();
|
||||
|
||||
@@ -390,6 +390,14 @@ void sceKernelReferFplStatus()
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//00:49:12 <TyRaNiD> ector, well the partitions are 1 = kernel, 2 = user, 3 = me, 4 = kernel mirror :)
|
||||
|
||||
enum MemblockType
|
||||
{
|
||||
PSP_SMEM_Low = 0,
|
||||
PSP_SMEM_High = 1,
|
||||
PSP_SMEM_Addr = 2,
|
||||
PSP_SMEM_LowAligned = 3,
|
||||
PSP_SMEM_HighAligned = 4,
|
||||
};
|
||||
|
||||
class PartitionMemoryBlock : public KernelObject
|
||||
{
|
||||
@@ -401,23 +409,34 @@ public:
|
||||
int sz = alloc->GetBlockSizeFromAddress(address);
|
||||
sprintf(ptr, "MemPart: %08x - %08x size: %08x", address, address + sz, sz);
|
||||
}
|
||||
static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_MPPID; } /// ????
|
||||
static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_UID; }
|
||||
int GetIDType() const { return PPSSPP_KERNEL_TMID_PMB; }
|
||||
|
||||
PartitionMemoryBlock(BlockAllocator *_alloc, u32 size, bool fromEnd)
|
||||
PartitionMemoryBlock(BlockAllocator *_alloc, const char *_name, u32 size, MemblockType type, u32 alignment)
|
||||
{
|
||||
alloc = _alloc;
|
||||
strncpy(name, _name, 32);
|
||||
name[31] = '\0';
|
||||
|
||||
// 0 is used for save states to wake up.
|
||||
if (size != 0)
|
||||
{
|
||||
address = alloc->Alloc(size, fromEnd, "PMB");
|
||||
if (type == PSP_SMEM_Addr)
|
||||
{
|
||||
alignment &= ~0xFF;
|
||||
address = alloc->AllocAt(alignment, size, name);
|
||||
}
|
||||
else if (type == PSP_SMEM_LowAligned || type == PSP_SMEM_HighAligned)
|
||||
address = alloc->AllocAligned(size, 0x100, alignment, type == PSP_SMEM_HighAligned, name);
|
||||
else
|
||||
address = alloc->Alloc(size, type == PSP_SMEM_High, name);
|
||||
alloc->ListBlocks();
|
||||
}
|
||||
}
|
||||
~PartitionMemoryBlock()
|
||||
{
|
||||
alloc->Free(address);
|
||||
if (address != (u32)-1)
|
||||
alloc->Free(address);
|
||||
}
|
||||
bool IsValid() {return address != (u32)-1;}
|
||||
BlockAllocator *alloc;
|
||||
@@ -449,54 +468,78 @@ void sceKernelTotalFreeMemSize()
|
||||
RETURN(retVal);
|
||||
}
|
||||
|
||||
void sceKernelAllocPartitionMemory()
|
||||
int sceKernelAllocPartitionMemory(int partition, const char *name, int type, u32 size, u32 addr)
|
||||
{
|
||||
int partid = PARAM(0);
|
||||
const char *name = Memory::GetCharPointer(PARAM(1));
|
||||
int type = PARAM(2);
|
||||
u32 size = PARAM(3);
|
||||
int addr = PARAM(4); //only if type includes ADDR
|
||||
if (name == NULL)
|
||||
{
|
||||
WARN_LOG(HLE, "%08x=sceKernelAllocPartitionMemory(): invalid name", SCE_KERNEL_ERROR_ERROR);
|
||||
return SCE_KERNEL_ERROR_ERROR;
|
||||
}
|
||||
if (size == 0)
|
||||
{
|
||||
WARN_LOG(HLE, "%08x=sceKernelAllocPartitionMemory(): invalid size %x", SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED, size);
|
||||
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
|
||||
}
|
||||
if (partition < 1 || partition > 9 || partition == 7)
|
||||
{
|
||||
WARN_LOG(HLE, "%08x=sceKernelAllocPartitionMemory(): invalid partition %x", SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, partition);
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
// We only support user right now.
|
||||
if (partition != 2 && partition != 5 && partition != 6)
|
||||
{
|
||||
WARN_LOG(HLE, "%08x=sceKernelAllocPartitionMemory(): invalid partition %x", SCE_KERNEL_ERROR_ILLEGAL_PARTITION, partition);
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_PARTITION;
|
||||
}
|
||||
if (type < PSP_SMEM_Low || type > PSP_SMEM_HighAligned)
|
||||
{
|
||||
WARN_LOG(HLE, "%08x=sceKernelAllocPartitionMemory(): invalid type %x", SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCKTYPE, type);
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCKTYPE;
|
||||
}
|
||||
// Alignment is only allowed for powers of 2.
|
||||
if ((type == PSP_SMEM_LowAligned || type == PSP_SMEM_HighAligned) && ((addr & (addr - 1)) != 0 || addr == 0))
|
||||
{
|
||||
WARN_LOG(HLE, "%08x=sceKernelAllocPartitionMemory(): invalid alignment %x", SCE_ERROR_KERNEL_ILLEGAL_ALIGNMENT_SIZE, addr);
|
||||
return SCE_ERROR_KERNEL_ILLEGAL_ALIGNMENT_SIZE;
|
||||
}
|
||||
|
||||
PartitionMemoryBlock *block = new PartitionMemoryBlock(&userMemory, size, type==1);
|
||||
PartitionMemoryBlock *block = new PartitionMemoryBlock(&userMemory, name, size, (MemblockType)type, addr);
|
||||
if (!block->IsValid())
|
||||
{
|
||||
delete block;
|
||||
ERROR_LOG(HLE, "ARGH! sceKernelAllocPartitionMemory failed");
|
||||
RETURN(-1);
|
||||
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
|
||||
}
|
||||
SceUID uid = kernelObjects.Create(block);
|
||||
strncpy(block->name, name, 32);
|
||||
|
||||
DEBUG_LOG(HLE,"%i = sceKernelAllocPartitionMemory(partition = %i, %s, type= %i, size= %i, addr= %08x)",
|
||||
uid, partid,name,type,size,addr);
|
||||
uid, partition, name, type, size, addr);
|
||||
if (type == 2)
|
||||
ERROR_LOG(HLE, "ARGH! sceKernelAllocPartitionMemory wants a specific address");
|
||||
|
||||
RETURN(uid); //for now
|
||||
return uid;
|
||||
}
|
||||
|
||||
void sceKernelFreePartitionMemory()
|
||||
int sceKernelFreePartitionMemory(SceUID id)
|
||||
{
|
||||
SceUID id = PARAM(0);
|
||||
DEBUG_LOG(HLE,"sceKernelFreePartitionMemory(%d)",id);
|
||||
|
||||
RETURN(kernelObjects.Destroy<PartitionMemoryBlock>(id));
|
||||
return kernelObjects.Destroy<PartitionMemoryBlock>(id);
|
||||
}
|
||||
|
||||
void sceKernelGetBlockHeadAddr()
|
||||
u32 sceKernelGetBlockHeadAddr(SceUID id)
|
||||
{
|
||||
SceUID id = PARAM(0);
|
||||
|
||||
u32 error;
|
||||
PartitionMemoryBlock *block = kernelObjects.Get<PartitionMemoryBlock>(id, error);
|
||||
if (block)
|
||||
{
|
||||
DEBUG_LOG(HLE,"%08x = sceKernelGetBlockHeadAddr(%i)", block->address, id);
|
||||
RETURN(block->address);
|
||||
return block->address;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(HLE,"sceKernelGetBlockHeadAddr failed(%i)", id);
|
||||
RETURN(error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,7 +762,7 @@ KernelObject *__KernelMemoryVPLObject()
|
||||
KernelObject *__KernelMemoryPMBObject()
|
||||
{
|
||||
// TODO: We could theoretically handle kernelMemory too, but we don't support that now anyway.
|
||||
return new PartitionMemoryBlock(&userMemory, 0, true);
|
||||
return new PartitionMemoryBlock(&userMemory, "", 0, PSP_SMEM_Low, 0);
|
||||
}
|
||||
|
||||
// VPL = variable length memory pool
|
||||
@@ -843,7 +886,7 @@ SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize
|
||||
// We ignore the upalign to 256 and do it ourselves by 8.
|
||||
u32 allocSize = vplSize;
|
||||
u32 memBlockPtr = userMemory.Alloc(allocSize, (attr & PSP_VPL_ATTR_HIGHMEM) != 0, "VPL");
|
||||
if (memBlockPtr == -1)
|
||||
if (memBlockPtr == (u32)-1)
|
||||
{
|
||||
ERROR_LOG(HLE, "sceKernelCreateVpl: Failed to allocate %i bytes of pool data", vplSize);
|
||||
return SCE_KERNEL_ERROR_NO_MEMORY;
|
||||
@@ -903,7 +946,7 @@ bool __KernelAllocateVpl(SceUID uid, u32 size, u32 addrPtr, u32 &error, const ch
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE, "%s(vpl=%i, size=%i, ptrout=%08x)", funcname, uid, size, addrPtr);
|
||||
VERBOSE_LOG(HLE, "%s(vpl=%i, size=%i, ptrout=%08x)", funcname, uid, size, addrPtr);
|
||||
// Padding (normally used to track the allocation.)
|
||||
u32 allocSize = size + 8;
|
||||
u32 addr = vpl->alloc.Alloc(allocSize, true);
|
||||
@@ -1030,7 +1073,7 @@ int sceKernelFreeVpl(SceUID uid, u32 addr)
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE, "sceKernelFreeVpl(%i, %08x)", uid, addr);
|
||||
VERBOSE_LOG(HLE, "sceKernelFreeVpl(%i, %08x)", uid, addr);
|
||||
u32 error;
|
||||
VPL *vpl = kernelObjects.Get<VPL>(uid, error);
|
||||
if (vpl)
|
||||
@@ -1135,9 +1178,9 @@ const HLEFunction SysMemUserForUser[] = {
|
||||
{0xA291F107,sceKernelMaxFreeMemSize,"sceKernelMaxFreeMemSize"},
|
||||
{0xF919F628,sceKernelTotalFreeMemSize,"sceKernelTotalFreeMemSize"},
|
||||
{0x3FC9AE6A,WrapU_V<sceKernelDevkitVersion>,"sceKernelDevkitVersion"},
|
||||
{0x237DBD4F,sceKernelAllocPartitionMemory,"sceKernelAllocPartitionMemory"}, //(int size) ?
|
||||
{0xB6D61D02,sceKernelFreePartitionMemory,"sceKernelFreePartitionMemory"}, //(void *ptr) ?
|
||||
{0x9D9A5BA1,sceKernelGetBlockHeadAddr,"sceKernelGetBlockHeadAddr"}, //(void *ptr) ?
|
||||
{0x237DBD4F,WrapI_ICIUU<sceKernelAllocPartitionMemory>,"sceKernelAllocPartitionMemory"}, //(int size) ?
|
||||
{0xB6D61D02,WrapI_I<sceKernelFreePartitionMemory>,"sceKernelFreePartitionMemory"}, //(void *ptr) ?
|
||||
{0x9D9A5BA1,WrapU_I<sceKernelGetBlockHeadAddr>,"sceKernelGetBlockHeadAddr"}, //(void *ptr) ?
|
||||
{0x13a5abef,sceKernelPrintf,"sceKernelPrintf 0x13a5abef"},
|
||||
{0x7591c7db,&WrapV_I<sceKernelSetCompiledSdkVersion>,"sceKernelSetCompiledSdkVersion"},
|
||||
{0x342061E5,&WrapV_I<sceKernelSetCompiledSdkVersion370>,"sceKernelSetCompiledSdkVersion370"},
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "../FileSystems/FileSystem.h"
|
||||
#include "../FileSystems/MetaFileSystem.h"
|
||||
#include "../Util/BlockAllocator.h"
|
||||
#include "../CoreTiming.h"
|
||||
#include "../PSPLoaders.h"
|
||||
#include "../System.h"
|
||||
#include "../MemMap.h"
|
||||
@@ -559,6 +560,10 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, std::string *erro
|
||||
}
|
||||
|
||||
module->nm.entry_addr = reader.GetEntryPoint();
|
||||
|
||||
// use module_start_func instead of entry_addr if entry_addr is 0
|
||||
if (module->nm.entry_addr == 0)
|
||||
module->nm.entry_addr = module->nm.module_start_func;
|
||||
|
||||
if (newptr)
|
||||
{
|
||||
@@ -644,7 +649,7 @@ Module *__KernelLoadModule(u8 *fileptr, SceKernelLMOption *options, std::string
|
||||
|
||||
void __KernelStartModule(Module *m, int args, const char *argp, SceKernelSMOption *options)
|
||||
{
|
||||
if (m->nm.module_start_func != 0 && m->nm.module_start_func != -1)
|
||||
if (m->nm.module_start_func != 0 && m->nm.module_start_func != (u32)-1)
|
||||
{
|
||||
if (m->nm.module_start_func != m->nm.entry_addr)
|
||||
WARN_LOG(LOADER, "Main module has start func (%08x) different from entry (%08x)?", m->nm.module_start_func, m->nm.entry_addr);
|
||||
@@ -755,10 +760,12 @@ int sceKernelLoadExec(const char *filename, u32 paramPtr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelLoadModule(const char *name, u32 flags)
|
||||
u32 sceKernelLoadModule(const char *name, u32 flags, u32 optionAddr)
|
||||
{
|
||||
if(!name)
|
||||
return 0;
|
||||
if (!name) {
|
||||
ERROR_LOG(LOADER, "sceKernelLoadModule(NULL, %08x): Bad name", flags);
|
||||
return SCE_KERNEL_ERROR_ILLEGAL_ADDR;
|
||||
}
|
||||
|
||||
PSPFileInfo info = pspFileSystem.GetFileInfo(name);
|
||||
std::string error_string;
|
||||
@@ -779,8 +786,8 @@ u32 sceKernelLoadModule(const char *name, u32 flags)
|
||||
SceKernelLMOption *lmoption = 0;
|
||||
int position = 0;
|
||||
// TODO: Use position to decide whether to load high or low
|
||||
if (PARAM(2)) {
|
||||
lmoption = (SceKernelLMOption *)Memory::GetPointer(PARAM(2));
|
||||
if (optionAddr) {
|
||||
lmoption = (SceKernelLMOption *)Memory::GetPointer(optionAddr);
|
||||
}
|
||||
|
||||
Module *module = 0;
|
||||
@@ -806,7 +813,8 @@ u32 sceKernelLoadModule(const char *name, u32 flags)
|
||||
INFO_LOG(HLE,"%i=sceKernelLoadModule(name=%s,flag=%08x,(...))", module->GetUID(), name, flags);
|
||||
}
|
||||
|
||||
return module->GetUID();
|
||||
// TODO: This is not the right timing and probably not the right wait type, just an approximation.
|
||||
return hleDelayResult(module->GetUID(), "module loaded", 500);
|
||||
}
|
||||
|
||||
void sceKernelStartModule(u32 moduleId, u32 argsize, u32 argAddr, u32 returnValueAddr, u32 optionAddr)
|
||||
@@ -837,9 +845,9 @@ void sceKernelStartModule(u32 moduleId, u32 argsize, u32 argAddr, u32 returnValu
|
||||
moduleId,argsize,argAddr,returnValueAddr,optionAddr);
|
||||
|
||||
u32 entryAddr = module->nm.entry_addr;
|
||||
if (entryAddr == -1 || entryAddr == module->memoryBlockAddr - 1) {
|
||||
if (entryAddr == (u32)-1 || entryAddr == module->memoryBlockAddr - 1) {
|
||||
// TODO: Do these always take effect, or do they not override optionAddr?
|
||||
if (module->nm.module_start_func != 0 && module->nm.module_start_func != -1) {
|
||||
if (module->nm.module_start_func != 0 && module->nm.module_start_func != (u32)-1) {
|
||||
entryAddr = module->nm.module_start_func;
|
||||
priority = module->nm.module_start_thread_priority;
|
||||
attr = module->nm.module_start_thread_attr;
|
||||
@@ -861,13 +869,12 @@ void sceKernelStartModule(u32 moduleId, u32 argsize, u32 argAddr, u32 returnValu
|
||||
RETURN(moduleId);
|
||||
}
|
||||
|
||||
void sceKernelStopModule(u32 moduleId, u32 argSize, u32 argAddr, u32 returnValueAddr, u32 optionAddr)
|
||||
u32 sceKernelStopModule(u32 moduleId, u32 argSize, u32 argAddr, u32 returnValueAddr, u32 optionAddr)
|
||||
{
|
||||
ERROR_LOG(HLE,"UNIMPL sceKernelStopModule(%i, %i, %08x, %08x, %08x)",
|
||||
moduleId, argSize, argAddr, returnValueAddr, optionAddr);
|
||||
ERROR_LOG(HLE,"UNIMPL sceKernelStopModule(%08x, %08x, %08x, %08x, %08x)", moduleId, argSize, argAddr, returnValueAddr, optionAddr);
|
||||
|
||||
// We should call the "stop" entry point and return the value in returnValueAddr. See StartModule.
|
||||
RETURN(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelUnloadModule(u32 moduleId)
|
||||
@@ -890,7 +897,7 @@ u32 sceKernelStopUnloadSelfModuleWithStatus(u32 moduleId, u32 argSize, u32 argp,
|
||||
|
||||
u32 sceKernelGetModuleIdByAddress(u32 moduleAddr)
|
||||
{
|
||||
ERROR_LOG(HLE,"HACKIMPL sceKernelGetModuleIdByAddress(%08x)", PARAM(0));
|
||||
ERROR_LOG(HLE,"HACKIMPL sceKernelGetModuleIdByAddress(%08x)", moduleAddr);
|
||||
|
||||
if ((moduleAddr & 0xFFFF0000) == 0x08800000)
|
||||
{
|
||||
@@ -924,7 +931,7 @@ u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr)
|
||||
{
|
||||
u32 error;
|
||||
u32 handle = __IoGetFileHandleFromId(id, error);
|
||||
if (handle == -1) {
|
||||
if (handle == (u32)-1) {
|
||||
ERROR_LOG(HLE,"sceKernelLoadModuleByID(%08x, %08x, %08x): could not open file id",id,flags,lmoptionPtr);
|
||||
return error;
|
||||
}
|
||||
@@ -997,11 +1004,11 @@ u32 sceKernelQueryModuleInfo(u32 uid, u32 infoAddr)
|
||||
|
||||
const HLEFunction ModuleMgrForUser[] =
|
||||
{
|
||||
{0x977DE386,&WrapU_CU<sceKernelLoadModule>,"sceKernelLoadModule"},
|
||||
{0x977DE386,&WrapU_CUU<sceKernelLoadModule>,"sceKernelLoadModule"},
|
||||
{0xb7f46618,&WrapU_UUU<sceKernelLoadModuleByID>,"sceKernelLoadModuleByID"},
|
||||
{0x50F0C1EC,&WrapV_UUUUU<sceKernelStartModule>,"sceKernelStartModule"},
|
||||
{0xD675EBB8,&sceKernelExitGame,"sceKernelSelfStopUnloadModule"}, //HACK
|
||||
{0xd1ff982a,&WrapV_UUUUU<sceKernelStopModule>,"sceKernelStopModule"},
|
||||
{0xd1ff982a,&WrapU_UUUUU<sceKernelStopModule>,"sceKernelStopModule"},
|
||||
{0x2e0911aa,WrapU_U<sceKernelUnloadModule>,"sceKernelUnloadModule"},
|
||||
{0x710F61B5,0,"sceKernelLoadModuleMs"},
|
||||
{0xF9275D98,0,"sceKernelLoadModuleBufferUsbWlan"}, ///???
|
||||
|
||||
@@ -839,7 +839,7 @@ int sceKernelTryLockLwMutex_600(u32 workareaPtr, int count)
|
||||
|
||||
int sceKernelLockLwMutex(u32 workareaPtr, int count, u32 timeoutPtr)
|
||||
{
|
||||
//DEBUG_LOG(HLE, "sceKernelLockLwMutex(%08x, %i, %08x)", workareaPtr, count, timeoutPtr);
|
||||
VERBOSE_LOG(HLE, "sceKernelLockLwMutex(%08x, %i, %08x)", workareaPtr, count, timeoutPtr);
|
||||
|
||||
NativeLwMutexWorkarea workarea;
|
||||
Memory::ReadStruct(workareaPtr, &workarea);
|
||||
@@ -874,7 +874,7 @@ int sceKernelLockLwMutex(u32 workareaPtr, int count, u32 timeoutPtr)
|
||||
|
||||
int sceKernelLockLwMutexCB(u32 workareaPtr, int count, u32 timeoutPtr)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceKernelLockLwMutexCB(%08x, %i, %08x)", workareaPtr, count, timeoutPtr);
|
||||
VERBOSE_LOG(HLE, "sceKernelLockLwMutexCB(%08x, %i, %08x)", workareaPtr, count, timeoutPtr);
|
||||
|
||||
NativeLwMutexWorkarea workarea;
|
||||
Memory::ReadStruct(workareaPtr, &workarea);
|
||||
@@ -898,7 +898,7 @@ int sceKernelLockLwMutexCB(u32 workareaPtr, int count, u32 timeoutPtr)
|
||||
if (std::find(mutex->waitingThreads.begin(), mutex->waitingThreads.end(), threadID) == mutex->waitingThreads.end())
|
||||
mutex->waitingThreads.push_back(threadID);
|
||||
__KernelWaitLwMutex(mutex, timeoutPtr);
|
||||
__KernelWaitCurThread(WAITTYPE_LWMUTEX, workarea.uid, count, timeoutPtr, true, "lwmutex waited");
|
||||
__KernelWaitCurThread(WAITTYPE_LWMUTEX, workarea.uid, count, timeoutPtr, true, "lwmutex cb waited");
|
||||
|
||||
// Return value will be overwritten by wait.
|
||||
return 0;
|
||||
@@ -910,7 +910,7 @@ int sceKernelLockLwMutexCB(u32 workareaPtr, int count, u32 timeoutPtr)
|
||||
|
||||
int sceKernelUnlockLwMutex(u32 workareaPtr, int count)
|
||||
{
|
||||
//DEBUG_LOG(HLE, "sceKernelUnlockLwMutex(%08x, %i)", workareaPtr, count);
|
||||
VERBOSE_LOG(HLE, "sceKernelUnlockLwMutex(%08x, %i)", workareaPtr, count);
|
||||
|
||||
NativeLwMutexWorkarea workarea;
|
||||
Memory::ReadStruct(workareaPtr, &workarea);
|
||||
|
||||
+110
-35
@@ -20,6 +20,7 @@
|
||||
#include <queue>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Common/LogManager.h"
|
||||
#include "HLE.h"
|
||||
#include "HLETables.h"
|
||||
#include "../MIPS/MIPSInt.h"
|
||||
@@ -155,22 +156,21 @@ struct ThreadWaitInfo {
|
||||
class MipsCallManager {
|
||||
public:
|
||||
MipsCallManager() : idGen_(0) {}
|
||||
int add(MipsCall *call) {
|
||||
int id = genId();
|
||||
u32 add(MipsCall *call) {
|
||||
u32 id = genId();
|
||||
calls_.insert(std::pair<int, MipsCall *>(id, call));
|
||||
return id;
|
||||
}
|
||||
MipsCall *get(int id) {
|
||||
MipsCall *get(u32 id) {
|
||||
return calls_[id];
|
||||
}
|
||||
MipsCall *pop(int id) {
|
||||
MipsCall *pop(u32 id) {
|
||||
MipsCall *temp = calls_[id];
|
||||
calls_.erase(id);
|
||||
return temp;
|
||||
}
|
||||
void clear() {
|
||||
std::map<int, MipsCall *>::iterator it, end;
|
||||
for (it = calls_.begin(), end = calls_.end(); it != end; ++it) {
|
||||
for (auto it = calls_.begin(), end = calls_.end(); it != end; ++it) {
|
||||
delete it->second;
|
||||
}
|
||||
calls_.clear();
|
||||
@@ -204,10 +204,10 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int genId() { return ++idGen_; }
|
||||
std::map<int, MipsCall *> calls_;
|
||||
u32 genId() { return ++idGen_; }
|
||||
std::map<u32, MipsCall *> calls_;
|
||||
std::vector<ActionCreator> types_;
|
||||
int idGen_;
|
||||
u32 idGen_;
|
||||
};
|
||||
|
||||
class ActionAfterMipsCall : public Action
|
||||
@@ -372,6 +372,7 @@ public:
|
||||
|
||||
ActionAfterMipsCall *getRunningCallbackAction();
|
||||
void setReturnValue(u32 retval);
|
||||
void setReturnValue(u64 retval);
|
||||
void resumeFromWait();
|
||||
bool isWaitingFor(WaitType type, int id);
|
||||
int getWaitID(WaitType type);
|
||||
@@ -425,7 +426,7 @@ public:
|
||||
std::set<SceUID> registeredCallbacks[THREAD_CALLBACK_NUM_TYPES];
|
||||
std::list<SceUID> readyCallbacks[THREAD_CALLBACK_NUM_TYPES];
|
||||
|
||||
std::list<int> pendingMipsCalls;
|
||||
std::list<u32> pendingMipsCalls;
|
||||
|
||||
u32 stackBlock;
|
||||
};
|
||||
@@ -492,7 +493,7 @@ struct ThreadList
|
||||
}
|
||||
};
|
||||
|
||||
void __KernelExecuteMipsCallOnCurrentThread(int callId, bool reschedAfter);
|
||||
void __KernelExecuteMipsCallOnCurrentThread(u32 callId, bool reschedAfter);
|
||||
|
||||
|
||||
Thread *__KernelCreateThread(SceUID &id, SceUID moduleID, const char *name, u32 entryPoint, u32 priority, int stacksize, u32 attr);
|
||||
@@ -588,6 +589,12 @@ void MipsCall::setReturnValue(u32 value)
|
||||
savedV0 = value;
|
||||
}
|
||||
|
||||
void MipsCall::setReturnValue(u64 value)
|
||||
{
|
||||
savedV0 = value & 0xFFFFFFFF;
|
||||
savedV1 = (value >> 32) & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
// TODO: Should move to this wrapper so we can keep the current thread as a SceUID instead
|
||||
// of a dangerous raw pointer.
|
||||
Thread *__GetCurrentThread() {
|
||||
@@ -685,6 +692,8 @@ void __KernelThreadingDoState(PointerWrap &p)
|
||||
p.Do(actionAfterCallback);
|
||||
__KernelRestoreActionType(actionAfterCallback, ActionAfterCallback::Create);
|
||||
|
||||
hleCurrentThreadName = __KernelGetThreadName(currentThread);
|
||||
|
||||
p.DoMarker("sceKernelThread");
|
||||
}
|
||||
|
||||
@@ -834,6 +843,7 @@ void __KernelThreadingShutdown()
|
||||
currentThread = 0;
|
||||
intReturnHackAddr = 0;
|
||||
curModule = 0;
|
||||
hleCurrentThreadName = NULL;
|
||||
}
|
||||
|
||||
const char *__KernelGetThreadName(SceUID threadID)
|
||||
@@ -1055,7 +1065,24 @@ u32 __KernelResumeThreadFromWait(SceUID threadID)
|
||||
}
|
||||
}
|
||||
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID, int retval)
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID, u32 retval)
|
||||
{
|
||||
u32 error;
|
||||
Thread *t = kernelObjects.Get<Thread>(threadID, error);
|
||||
if (t)
|
||||
{
|
||||
t->resumeFromWait();
|
||||
t->setReturnValue(retval);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(HLE, "__KernelResumeThreadFromWait(%d): bad thread: %08x", threadID, error);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID, u64 retval)
|
||||
{
|
||||
u32 error;
|
||||
Thread *t = kernelObjects.Get<Thread>(threadID, error);
|
||||
@@ -1088,7 +1115,7 @@ bool __KernelTriggerWait(WaitType type, int id, bool useRetVal, int retVal, cons
|
||||
// This thread was waiting for the triggered object.
|
||||
t->resumeFromWait();
|
||||
if (useRetVal)
|
||||
t->setReturnValue(retVal);
|
||||
t->setReturnValue((u32)retVal);
|
||||
doneAnything = true;
|
||||
}
|
||||
}
|
||||
@@ -1117,6 +1144,12 @@ bool __KernelTriggerWait(WaitType type, int id, int retVal, const char *reason,
|
||||
// makes the current thread wait for an event
|
||||
void __KernelWaitCurThread(WaitType type, SceUID waitID, u32 waitValue, u32 timeoutPtr, bool processCallbacks, const char *reason)
|
||||
{
|
||||
if (!dispatchEnabled)
|
||||
{
|
||||
WARN_LOG(HLE, "Ignoring wait, dispatching disabled... right thing to do?");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Need to defer if in callback?
|
||||
if (g_inCbCount > 0)
|
||||
WARN_LOG(HLE, "UNTESTED - waiting within a callback, probably bad mojo.");
|
||||
@@ -1203,7 +1236,10 @@ u32 __KernelDeleteThread(SceUID threadID, int exitStatus, const char *reason, bo
|
||||
__KernelTriggerWait(WAITTYPE_THREADEND, threadID, exitStatus, reason, dontSwitch);
|
||||
|
||||
if (currentThread == threadID)
|
||||
{
|
||||
currentThread = 0;
|
||||
hleCurrentThreadName = NULL;
|
||||
}
|
||||
if (currentCallbackThreadID == threadID)
|
||||
{
|
||||
currentCallbackThreadID = 0;
|
||||
@@ -1427,6 +1463,7 @@ void __KernelSetupRootThread(SceUID moduleID, int args, const char *argp, int pr
|
||||
if (prevThread && prevThread->isRunning())
|
||||
__KernelChangeReadyState(currentThread, true);
|
||||
currentThread = id;
|
||||
hleCurrentThreadName = "root";
|
||||
thread->nt.status = THREADSTATUS_RUNNING; // do not schedule
|
||||
|
||||
strcpy(thread->nt.name, "root");
|
||||
@@ -1668,6 +1705,7 @@ u32 sceKernelResumeDispatchThread(u32 suspended)
|
||||
u32 oldDispatchSuspended = !dispatchEnabled;
|
||||
dispatchEnabled = !suspended;
|
||||
DEBUG_LOG(HLE,"%i=sceKernelResumeDispatchThread(%i)", oldDispatchSuspended, suspended);
|
||||
hleReSchedule("dispatch resumed");
|
||||
return oldDispatchSuspended;
|
||||
}
|
||||
|
||||
@@ -1757,7 +1795,7 @@ int sceKernelTerminateDeleteThread(int threadno)
|
||||
}
|
||||
}
|
||||
|
||||
int sceKernelTerminateThread(u32 threadID)
|
||||
int sceKernelTerminateThread(SceUID threadID)
|
||||
{
|
||||
if (threadID != currentThread)
|
||||
{
|
||||
@@ -1853,26 +1891,26 @@ void sceKernelChangeThreadPriority()
|
||||
}
|
||||
}
|
||||
|
||||
void sceKernelDelayThreadCB()
|
||||
int sceKernelDelayThreadCB(u32 usec)
|
||||
{
|
||||
u32 usec = PARAM(0);
|
||||
if (usec < 200) usec = 200;
|
||||
DEBUG_LOG(HLE,"sceKernelDelayThreadCB(%i usec)",usec);
|
||||
|
||||
SceUID curThread = __KernelGetCurThread();
|
||||
__KernelScheduleWakeup(curThread, usec);
|
||||
__KernelWaitCurThread(WAITTYPE_DELAY, curThread, 0, 0, true, "thread delayed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sceKernelDelayThread()
|
||||
int sceKernelDelayThread(u32 usec)
|
||||
{
|
||||
u32 usec = PARAM(0);
|
||||
if (usec < 200) usec = 200;
|
||||
DEBUG_LOG(HLE,"sceKernelDelayThread(%i usec)",usec);
|
||||
|
||||
SceUID curThread = __KernelGetCurThread();
|
||||
__KernelScheduleWakeup(curThread, usec);
|
||||
__KernelWaitCurThread(WAITTYPE_DELAY, curThread, 0, 0, false, "thread delayed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sceKernelDelaySysClockThreadCB()
|
||||
@@ -1982,11 +2020,12 @@ static void __KernelSleepThread(bool doCallbacks) {
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE,"sceKernelSleepThread() - wakeupCount decremented to %i", thread->nt.wakeupCount);
|
||||
if (thread->nt.wakeupCount > 0) {
|
||||
thread->nt.wakeupCount--;
|
||||
DEBUG_LOG(HLE, "sceKernelSleepThread() - wakeupCount decremented to %i", thread->nt.wakeupCount);
|
||||
RETURN(0);
|
||||
} else {
|
||||
VERBOSE_LOG(HLE, "sceKernelSleepThread()");
|
||||
RETURN(0);
|
||||
__KernelWaitCurThread(WAITTYPE_SLEEP, 0, 0, 0, doCallbacks, "thread slept");
|
||||
}
|
||||
@@ -2000,7 +2039,7 @@ void sceKernelSleepThread()
|
||||
//the homebrew PollCallbacks
|
||||
void sceKernelSleepThreadCB()
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceKernelSleepThreadCB()");
|
||||
VERBOSE_LOG(HLE, "sceKernelSleepThreadCB()");
|
||||
__KernelSleepThread(true);
|
||||
__KernelCheckCallbacks();
|
||||
}
|
||||
@@ -2256,7 +2295,7 @@ void Thread::setReturnValue(u32 retval)
|
||||
{
|
||||
if (this->GetUID() == currentThread) {
|
||||
if (g_inCbCount) {
|
||||
int callId = this->currentCallbackId;
|
||||
u32 callId = this->currentCallbackId;
|
||||
MipsCall *call = mipsCalls.get(callId);
|
||||
if (call) {
|
||||
call->setReturnValue(retval);
|
||||
@@ -2271,6 +2310,27 @@ void Thread::setReturnValue(u32 retval)
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::setReturnValue(u64 retval)
|
||||
{
|
||||
if (this->GetUID() == currentThread) {
|
||||
if (g_inCbCount) {
|
||||
u32 callId = this->currentCallbackId;
|
||||
MipsCall *call = mipsCalls.get(callId);
|
||||
if (call) {
|
||||
call->setReturnValue(retval);
|
||||
} else {
|
||||
ERROR_LOG(HLE, "Failed to inject return value %08llx in thread", retval);
|
||||
}
|
||||
} else {
|
||||
currentMIPS->r[2] = retval & 0xFFFFFFFF;
|
||||
currentMIPS->r[3] = (retval >> 32) & 0xFFFFFFFF;
|
||||
}
|
||||
} else {
|
||||
context.r[2] = retval & 0xFFFFFFFF;
|
||||
context.r[3] = (retval >> 32) & 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::resumeFromWait()
|
||||
{
|
||||
// Do we need to "inject" it?
|
||||
@@ -2342,7 +2402,7 @@ ThreadWaitInfo Thread::getWaitInfo()
|
||||
void __KernelSwitchContext(Thread *target, const char *reason)
|
||||
{
|
||||
u32 oldPC = 0;
|
||||
u32 oldUID = 0;
|
||||
SceUID oldUID = 0;
|
||||
const char *oldName = "(none)";
|
||||
|
||||
Thread *cur = __GetCurrentThread();
|
||||
@@ -2361,12 +2421,18 @@ void __KernelSwitchContext(Thread *target, const char *reason)
|
||||
__KernelChangeReadyState(cur, oldUID, true);
|
||||
}
|
||||
|
||||
currentThread = target->GetUID();
|
||||
if (target)
|
||||
{
|
||||
currentThread = target->GetUID();
|
||||
hleCurrentThreadName = target->nt.name;
|
||||
__KernelChangeReadyState(target, currentThread, false);
|
||||
target->nt.status = (target->nt.status | THREADSTATUS_RUNNING) & ~THREADSTATUS_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentThread = 0;
|
||||
hleCurrentThreadName = NULL;
|
||||
}
|
||||
|
||||
__KernelLoadContext(&target->context);
|
||||
|
||||
@@ -2375,7 +2441,7 @@ void __KernelSwitchContext(Thread *target, const char *reason)
|
||||
if (!(fromIdle && toIdle))
|
||||
{
|
||||
DEBUG_LOG(HLE,"Context switched: %s -> %s (%s) (%i - pc: %08x -> %i - pc: %08x)",
|
||||
oldName, target->GetName(),
|
||||
oldName, hleCurrentThreadName,
|
||||
reason,
|
||||
oldUID, oldPC, currentThread, currentMIPS->pc);
|
||||
}
|
||||
@@ -2384,7 +2450,7 @@ void __KernelSwitchContext(Thread *target, const char *reason)
|
||||
target->nt.waitType = WAITTYPE_NONE;
|
||||
target->nt.waitID = 0;
|
||||
|
||||
__KernelExecutePendingMipsCalls(true);
|
||||
__KernelExecutePendingMipsCalls(target, true);
|
||||
}
|
||||
|
||||
void __KernelChangeThreadState(Thread *thread, ThreadStatus newStatus) {
|
||||
@@ -2448,7 +2514,7 @@ void __KernelCallAddress(Thread *thread, u32 entryPoint, Action *afterAction, co
|
||||
call->tag = "callAddress";
|
||||
call->cbId = cbId;
|
||||
|
||||
int callId = mipsCalls.add(call);
|
||||
u32 callId = mipsCalls.add(call);
|
||||
|
||||
bool called = false;
|
||||
if (!thread || thread == __GetCurrentThread()) {
|
||||
@@ -2475,7 +2541,7 @@ void __KernelDirectMipsCall(u32 entryPoint, Action *afterAction, u32 args[], int
|
||||
__KernelCallAddress(__GetCurrentThread(), entryPoint, afterAction, args, numargs, reschedAfter, 0);
|
||||
}
|
||||
|
||||
void __KernelExecuteMipsCallOnCurrentThread(int callId, bool reschedAfter)
|
||||
void __KernelExecuteMipsCallOnCurrentThread(u32 callId, bool reschedAfter)
|
||||
{
|
||||
Thread *cur = __GetCurrentThread();
|
||||
if (cur == NULL)
|
||||
@@ -2524,7 +2590,7 @@ void __KernelReturnFromMipsCall()
|
||||
return;
|
||||
}
|
||||
|
||||
int callId = cur->currentCallbackId;
|
||||
u32 callId = cur->currentCallbackId;
|
||||
if (currentMIPS->r[MIPS_REG_CALL_ID] != callId)
|
||||
WARN_LOG(HLE, "__KernelReturnFromMipsCall(): s0 is %08x != %08x", currentMIPS->r[MIPS_REG_CALL_ID], callId);
|
||||
|
||||
@@ -2553,7 +2619,7 @@ void __KernelReturnFromMipsCall()
|
||||
currentCallbackThreadID = 0;
|
||||
|
||||
// yeah! back in the real world, let's keep going. Should we process more callbacks?
|
||||
if (!__KernelExecutePendingMipsCalls(call->reschedAfter))
|
||||
if (!__KernelExecutePendingMipsCalls(cur, call->reschedAfter))
|
||||
{
|
||||
// Sometimes, we want to stay on the thread.
|
||||
int threadReady = cur->nt.status & (THREADSTATUS_READY | THREADSTATUS_RUNNING);
|
||||
@@ -2564,9 +2630,10 @@ void __KernelReturnFromMipsCall()
|
||||
delete call;
|
||||
}
|
||||
|
||||
bool __KernelExecutePendingMipsCalls(bool reschedAfter)
|
||||
// First arg must be current thread, passed to avoid perf cost of a lookup.
|
||||
bool __KernelExecutePendingMipsCalls(Thread *thread, bool reschedAfter)
|
||||
{
|
||||
Thread *thread = __GetCurrentThread();
|
||||
_dbg_assert_msg_(HLE, thread->GetUID() == __KernelGetCurThread(), "__KernelExecutePendingMipsCalls() should be called only with the current thread.");
|
||||
|
||||
if (thread->pendingMipsCalls.empty()) {
|
||||
// Nothing to do
|
||||
@@ -2576,7 +2643,7 @@ bool __KernelExecutePendingMipsCalls(bool reschedAfter)
|
||||
if (__CanExecuteCallbackNow(thread))
|
||||
{
|
||||
// Pop off the first pending mips call
|
||||
int callId = thread->pendingMipsCalls.front();
|
||||
u32 callId = thread->pendingMipsCalls.front();
|
||||
thread->pendingMipsCalls.pop_front();
|
||||
__KernelExecuteMipsCallOnCurrentThread(callId, reschedAfter);
|
||||
return true;
|
||||
@@ -2642,7 +2709,7 @@ void ActionAfterCallback::run(MipsCall &call) {
|
||||
// Returns true if any callbacks were processed on the current thread.
|
||||
bool __KernelCheckThreadCallbacks(Thread *thread, bool force)
|
||||
{
|
||||
if (!thread->isProcessingCallbacks && !force)
|
||||
if (!thread || (!thread->isProcessingCallbacks && !force))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < THREAD_CALLBACK_NUM_TYPES; i++) {
|
||||
@@ -2691,17 +2758,25 @@ bool __KernelCheckCallbacks() {
|
||||
// } while (processed && currentThread == __KernelGetCurThread());
|
||||
|
||||
if (processed)
|
||||
return __KernelExecutePendingMipsCalls(true);
|
||||
return __KernelExecutePendingMipsCalls(__GetCurrentThread(), true);
|
||||
return processed;
|
||||
}
|
||||
|
||||
bool __KernelForceCallbacks()
|
||||
{
|
||||
// Let's not check every thread all the time, callbacks are fairly uncommon.
|
||||
if (readyCallbacksCount == 0) {
|
||||
return false;
|
||||
}
|
||||
if (readyCallbacksCount < 0) {
|
||||
ERROR_LOG(HLE, "readyCallbacksCount became negative: %i", readyCallbacksCount);
|
||||
}
|
||||
|
||||
Thread *curThread = __GetCurrentThread();
|
||||
|
||||
bool callbacksProcessed = __KernelCheckThreadCallbacks(curThread, true);
|
||||
if (callbacksProcessed)
|
||||
__KernelExecutePendingMipsCalls(false);
|
||||
__KernelExecutePendingMipsCalls(curThread, false);
|
||||
|
||||
return callbacksProcessed;
|
||||
}
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
#include "sceKernelModule.h"
|
||||
#include "HLE.h"
|
||||
|
||||
|
||||
void sceKernelChangeThreadPriority();
|
||||
int __KernelCreateThread(const char *threadName, SceUID moduleID, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr);
|
||||
int sceKernelCreateThread(const char *threadName, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr);
|
||||
void sceKernelDelayThread();
|
||||
void sceKernelDelayThreadCB();
|
||||
int sceKernelDelayThread(u32 usec);
|
||||
int sceKernelDelayThreadCB(u32 usec);
|
||||
void sceKernelDelaySysClockThread();
|
||||
void sceKernelDelaySysClockThreadCB();
|
||||
int sceKernelDeleteThread(int threadHandle);
|
||||
@@ -53,7 +52,7 @@ void sceKernelResumeThread();
|
||||
void sceKernelWakeupThread();
|
||||
void sceKernelCancelWakeupThread();
|
||||
int sceKernelTerminateDeleteThread(int threadno);
|
||||
int sceKernelTerminateThread(u32 threadID);
|
||||
int sceKernelTerminateThread(SceUID threadID);
|
||||
int sceKernelWaitThreadEndCB(SceUID threadID, u32 timeoutPtr);
|
||||
void sceKernelGetThreadExitStatus();
|
||||
u32 sceKernelGetThreadmanIdType(u32);
|
||||
@@ -84,6 +83,7 @@ enum WaitType //probably not the real values
|
||||
WAITTYPE_MUTEX = 13,
|
||||
WAITTYPE_LWMUTEX = 14,
|
||||
WAITTYPE_CTRL = 15,
|
||||
WAITTYPE_IO = 16,
|
||||
};
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ KernelObject *__KernelCallbackObject();
|
||||
|
||||
void __KernelScheduleWakeup(int threadnumber, s64 usFromNow);
|
||||
SceUID __KernelGetCurThread();
|
||||
const char *__KernelGetThreadName(SceUID threadID);
|
||||
|
||||
void __KernelSaveContext(ThreadContext *ctx);
|
||||
void __KernelLoadContext(ThreadContext *ctx);
|
||||
@@ -126,7 +127,18 @@ void __KernelLoadContext(ThreadContext *ctx);
|
||||
bool __KernelTriggerWait(WaitType type, int id, const char *reason, bool dontSwitch = false);
|
||||
bool __KernelTriggerWait(WaitType type, int id, int retVal, const char *reason, bool dontSwitch);
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID); // can return an error value
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID, int retval);
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID, u32 retval);
|
||||
u32 __KernelResumeThreadFromWait(SceUID threadID, u64 retval);
|
||||
|
||||
inline u32 __KernelResumeThreadFromWait(SceUID threadID, int retval)
|
||||
{
|
||||
return __KernelResumeThreadFromWait(threadID, (u32)retval);
|
||||
}
|
||||
|
||||
inline u32 __KernelResumeThreadFromWait(SceUID threadID, s64 retval)
|
||||
{
|
||||
return __KernelResumeThreadFromWait(threadID, (u64)retval);
|
||||
}
|
||||
|
||||
u32 __KernelGetWaitValue(SceUID threadID, u32 &error);
|
||||
u32 __KernelGetWaitTimeoutPtr(SceUID threadID, u32 &error);
|
||||
@@ -194,7 +206,7 @@ bool __KernelCheckCallbacks();
|
||||
bool __KernelForceCallbacks();
|
||||
class Thread;
|
||||
void __KernelSwitchContext(Thread *target, const char *reason);
|
||||
bool __KernelExecutePendingMipsCalls(bool reschedAfter);
|
||||
bool __KernelExecutePendingMipsCalls(Thread *currentThread, bool reschedAfter);
|
||||
void __KernelNotifyCallback(RegisteredCallbackType type, SceUID cbId, int notifyArg);
|
||||
|
||||
// Switch to an idle / non-user thread, if not already on one.
|
||||
@@ -230,6 +242,15 @@ struct MipsCall {
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
void setReturnValue(u32 value);
|
||||
void setReturnValue(u64 value);
|
||||
inline void setReturnValue(int value)
|
||||
{
|
||||
setReturnValue((u32)value);
|
||||
}
|
||||
inline void setReturnValue(s64 value)
|
||||
{
|
||||
setReturnValue((u64)value);
|
||||
}
|
||||
};
|
||||
|
||||
class Action
|
||||
|
||||
+326
-133
@@ -15,24 +15,26 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "Core/CoreTiming.h"
|
||||
#include "sceKernel.h"
|
||||
#include "sceKernelThread.h"
|
||||
#include "sceKernelInterrupt.h"
|
||||
#include "sceKernelMemory.h"
|
||||
#include "sceKernelVTimer.h"
|
||||
#include "HLE.h"
|
||||
#include "ChunkFile.h"
|
||||
|
||||
// Using ERROR_LOG liberally when this is in development. When done,
|
||||
// should be changed to DEBUG_LOG wherever applicable.
|
||||
static int vtimerTimer = -1;
|
||||
static std::list<SceUID> vtimers;
|
||||
|
||||
struct NativeVTimer {
|
||||
SceSize size;
|
||||
char name[KERNELOBJECT_MAX_NAME_LENGTH+1];
|
||||
int running;
|
||||
SceKernelSysClock basetime;
|
||||
SceKernelSysClock curtime;
|
||||
SceKernelSysClock scheduletime;
|
||||
int active;
|
||||
u64 base;
|
||||
u64 current;
|
||||
u64 schedule;
|
||||
u32 handlerAddr;
|
||||
u32 argument;
|
||||
u32 commonAddr;
|
||||
};
|
||||
|
||||
struct VTimer : public KernelObject {
|
||||
@@ -43,198 +45,389 @@ struct VTimer : public KernelObject {
|
||||
|
||||
virtual void DoState(PointerWrap &p) {
|
||||
p.Do(nvt);
|
||||
p.Do(memoryPtr);
|
||||
p.DoMarker("VTimer");
|
||||
}
|
||||
|
||||
NativeVTimer nvt;
|
||||
u32 memoryPtr;
|
||||
};
|
||||
|
||||
KernelObject *__KernelVTimerObject() {
|
||||
return new VTimer;
|
||||
}
|
||||
|
||||
u32 sceKernelCreateVTimer(const char *name, u32 optParamAddr) {
|
||||
ERROR_LOG(HLE,"FAKE sceKernelCreateVTimer(%s, %08x)", name, optParamAddr);
|
||||
u64 __getVTimerRunningTime(VTimer *vt) {
|
||||
if (!vt->nvt.active)
|
||||
return 0;
|
||||
|
||||
VTimer *vt = new VTimer();
|
||||
|
||||
SceUID uid = kernelObjects.Create(vt);
|
||||
memset(&vt->nvt, 0, sizeof(vt->nvt));
|
||||
if (name)
|
||||
strncpy(vt->nvt.name, name, 32);
|
||||
vt->nvt.running = 1;
|
||||
return uid; //TODO: return timer ID
|
||||
return cyclesToUs(CoreTiming::GetTicks()) - vt->nvt.base;
|
||||
}
|
||||
|
||||
u32 sceKernelDeleteVTimer(u32 uid) {
|
||||
ERROR_LOG(HLE,"FAKE sceKernelDeleteVTimer(%i)", uid);
|
||||
u64 __getVTimerTime(VTimer* vt) {
|
||||
return vt->nvt.current + __getVTimerRunningTime(vt);
|
||||
}
|
||||
|
||||
void __cancelVTimer(SceUID id) {
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(id, error);
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
CoreTiming::UnscheduleEvent(vtimerTimer, id);
|
||||
vt->nvt.schedule = 0;
|
||||
vt->nvt.handlerAddr = 0;
|
||||
vt->nvt.commonAddr = 0;
|
||||
}
|
||||
|
||||
void __KernelScheduleVTimer(VTimer *vt, u64 schedule) {
|
||||
CoreTiming::UnscheduleEvent(vtimerTimer, vt->GetUID());
|
||||
|
||||
vt->nvt.schedule = schedule;
|
||||
|
||||
if (vt->nvt.active == 1)
|
||||
// this delay makes the test pass, not sure if it's right
|
||||
CoreTiming::ScheduleEvent(usToCycles(vt->nvt.schedule + 372), vtimerTimer, vt->GetUID());
|
||||
}
|
||||
|
||||
void __rescheduleVTimer(SceUID id, u32 delay) {
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(id, error);
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
if (delay < 0)
|
||||
delay = 100;
|
||||
|
||||
vt->nvt.schedule += delay;
|
||||
|
||||
__KernelScheduleVTimer(vt, vt->nvt.schedule);
|
||||
}
|
||||
|
||||
class VTimerIntrHandler : public IntrHandler
|
||||
{
|
||||
public:
|
||||
VTimerIntrHandler() : IntrHandler(PSP_SYSTIMER1_INTR) {}
|
||||
|
||||
virtual bool run(PendingInterrupt &pend) {
|
||||
u32 error;
|
||||
SceUID vtimerID = vtimers.front();
|
||||
|
||||
VTimer *vtimer = kernelObjects.Get<VTimer>(vtimerID, error);
|
||||
|
||||
if (error)
|
||||
return false;
|
||||
|
||||
if (vtimer->memoryPtr == 0) {
|
||||
u32 size = 16;
|
||||
vtimer->memoryPtr = kernelMemory.Alloc(size, true, "VTimer");
|
||||
}
|
||||
|
||||
Memory::Write_U64(vtimer->nvt.schedule, vtimer->memoryPtr);
|
||||
Memory::Write_U64(__getVTimerTime(vtimer), vtimer->memoryPtr + 8);
|
||||
|
||||
currentMIPS->pc = vtimer->nvt.handlerAddr;
|
||||
currentMIPS->r[MIPS_REG_A0] = vtimer->GetUID();
|
||||
currentMIPS->r[MIPS_REG_A1] = vtimer->memoryPtr;
|
||||
currentMIPS->r[MIPS_REG_A2] = vtimer->memoryPtr + 8;
|
||||
currentMIPS->r[MIPS_REG_A3] = vtimer->nvt.commonAddr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void handleResult(PendingInterrupt &pend) {
|
||||
int result = currentMIPS->r[MIPS_REG_V0];
|
||||
|
||||
int vtimerID = vtimers.front();
|
||||
vtimers.pop_front();
|
||||
|
||||
if (result == 0)
|
||||
__cancelVTimer(vtimerID);
|
||||
else
|
||||
__rescheduleVTimer(vtimerID, result);
|
||||
}
|
||||
};
|
||||
|
||||
void __KernelTriggerVTimer(u64 userdata, int cyclesLate) {
|
||||
SceUID uid = (SceUID) userdata;
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
if (vt) {
|
||||
vtimers.push_back(uid);
|
||||
__TriggerInterrupt(PSP_INTR_IMMEDIATE, PSP_SYSTIMER1_INTR);
|
||||
}
|
||||
}
|
||||
|
||||
void __KernelVTimerDoState(PointerWrap &p) {
|
||||
p.Do(vtimerTimer);
|
||||
p.Do(vtimers);
|
||||
CoreTiming::RestoreRegisterEvent(vtimerTimer, "VTimer", __KernelTriggerVTimer);
|
||||
p.DoMarker("sceKernelVTimer");
|
||||
}
|
||||
|
||||
void __KernelVTimerInit() {
|
||||
vtimers.clear();
|
||||
__RegisterIntrHandler(PSP_SYSTIMER1_INTR, new VTimerIntrHandler());
|
||||
vtimerTimer = CoreTiming::RegisterEvent("VTimer", __KernelTriggerVTimer);
|
||||
}
|
||||
|
||||
u32 sceKernelCreateVTimer(const char *name, u32 optParamAddr) {
|
||||
DEBUG_LOG(HLE, "sceKernelCreateVTimer(%s, %08x)", name, optParamAddr);
|
||||
if (optParamAddr != 0)
|
||||
WARN_LOG(HLE, "sceKernelCreateVTimer: unsupported options parameter %08x", optParamAddr);
|
||||
|
||||
VTimer *vtimer = new VTimer;
|
||||
SceUID id = kernelObjects.Create(vtimer);
|
||||
|
||||
memset(&vtimer->nvt, 0, sizeof(NativeVTimer));
|
||||
vtimer->nvt.size = sizeof(NativeVTimer);
|
||||
strncpy(vtimer->nvt.name, name, KERNELOBJECT_MAX_NAME_LENGTH);
|
||||
vtimer->nvt.name[KERNELOBJECT_MAX_NAME_LENGTH] = '\0';
|
||||
vtimer->memoryPtr = 0;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
u32 sceKernelDeleteVTimer(u32 uid) {
|
||||
DEBUG_LOG(HLE, "sceKernelDeleteVTimer(%08x)", uid);
|
||||
|
||||
u32 error;
|
||||
VTimer* vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelDeleteVTimer(%08x)", error, uid);
|
||||
return error;
|
||||
}
|
||||
// TODO: Deschedule events here. Might share code with Stop.
|
||||
|
||||
for (std::list<SceUID>::iterator it = vtimers.begin(); it != vtimers.end(); ++it) {
|
||||
if (*it == vt->GetUID()) {
|
||||
vtimers.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (vt->memoryPtr != 0)
|
||||
kernelMemory.Free(vt->memoryPtr);
|
||||
|
||||
return kernelObjects.Destroy<VTimer>(uid);
|
||||
}
|
||||
|
||||
u32 sceKernelStartVTimer(u32 uid) {
|
||||
ERROR_LOG(HLE,"FAKE sceKernelStartVTimer(%i)", uid);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
return error;
|
||||
}
|
||||
if (vt->nvt.running) {
|
||||
// Already running
|
||||
return 1;
|
||||
} else {
|
||||
vt->nvt.running = 1;
|
||||
// TODO: Schedule events etc.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceKernelStopVTimer(u32 uid) {
|
||||
ERROR_LOG(HLE,"FAKE sceKernelStartVTimer(%i)", uid);
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
return error;
|
||||
}
|
||||
if (vt->nvt.running) {
|
||||
// Already running
|
||||
return 0;
|
||||
} else {
|
||||
vt->nvt.running = 0;
|
||||
// TODO: Deschedule events etc.
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 sceKernelSetVTimerHandler(u32 uid, u32 scheduleAddr, u32 handlerFuncAddr, u32 commonAddr) {
|
||||
ERROR_LOG(HLE,"UNIMPL sceKernelSetVTimerHandler(%i, %08x, %08x, %08x)",
|
||||
uid, scheduleAddr, handlerFuncAddr, commonAddr);
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
return error;
|
||||
}
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelSetVTimerHandlerWide(u32 uid, u64 schedule, u32 handlerFuncAddr, u32 commonAddr) {
|
||||
ERROR_LOG(HLE,"UNIMPL sceKernelSetVTimerHandlerWide(%i, %llu, %08x, %08x)",
|
||||
uid, schedule, handlerFuncAddr, commonAddr);
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
return error;
|
||||
}
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelCancelVTimerHandler(u32 uid) {
|
||||
ERROR_LOG(HLE,"UNIMPL sceKernelCancelVTimerHandler(%i)", uid);
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
return error;
|
||||
}
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelReferVTimerStatus(u32 uid, u32 statusAddr) {
|
||||
ERROR_LOG(HLE,"sceKernelReferVTimerStatus(%i, %08x)", uid, statusAddr);
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
return error;
|
||||
}
|
||||
// TODO: possibly update time values here?
|
||||
Memory::WriteStruct(statusAddr, &vt->nvt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelGetVTimerBase(u32 uid, u32 baseClockAddr) {
|
||||
ERROR_LOG(HLE,"sceKernelGetVTimerBase(%i, %08x)", uid, baseClockAddr);
|
||||
DEBUG_LOG(HLE, "sceKernelGetVTimerBase(%08x, %08x)", uid, baseClockAddr);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelGetVTimerBase(%08x, %08x)", error, uid, baseClockAddr);
|
||||
return error;
|
||||
}
|
||||
Memory::WriteStruct(baseClockAddr, &vt->nvt.basetime);
|
||||
|
||||
if (Memory::IsValidAddress(baseClockAddr))
|
||||
Memory::Write_U64(vt->nvt.base, baseClockAddr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 sceKernelGetVTimerBaseWide(u32 uid) {
|
||||
ERROR_LOG(HLE,"sceKernelGetVTimerWide(%i)", uid);
|
||||
DEBUG_LOG(HLE, "sceKernelGetVTimerBaseWide(%08x)", uid);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelGetVTimerBaseWide(%08x)", error, uid);
|
||||
return error;
|
||||
}
|
||||
// TODO: probably update the timer somehow?
|
||||
u64 t = vt->nvt.curtime.lo;
|
||||
t |= (u64)(vt->nvt.curtime.hi) << 32;
|
||||
return t;
|
||||
|
||||
return vt->nvt.base;
|
||||
}
|
||||
|
||||
u32 sceKernelGetVTimerTime(u32 uid, u32 timeClockAddr) {
|
||||
ERROR_LOG(HLE,"sceKernelGetVTimerTime(%i, %08x)", uid, timeClockAddr);
|
||||
DEBUG_LOG(HLE, "sceKernelGetVTimerTime(%08x, %08x)", uid, timeClockAddr);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelGetVTimerTime(%08x, %08x)", error, uid, timeClockAddr);
|
||||
return error;
|
||||
}
|
||||
// TODO: probably update the timer somehow?
|
||||
Memory::WriteStruct(timeClockAddr, &vt->nvt.curtime);
|
||||
|
||||
u64 time = __getVTimerTime(vt);
|
||||
if (Memory::IsValidAddress(timeClockAddr))
|
||||
Memory::Write_U64(time, timeClockAddr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 sceKernelGetVTimerTimeWide(u32 uid) {
|
||||
ERROR_LOG(HLE,"sceKernelGetVTimerTimeWide(%i)", uid);
|
||||
DEBUG_LOG(HLE, "sceKernelGetVTimerTimeWide(%08x)", uid);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelGetVTimerTimeWide(%08x)", error, uid);
|
||||
return error;
|
||||
}
|
||||
// TODO: probably update the timer somehow?
|
||||
u64 t = vt->nvt.curtime.lo;
|
||||
t |= (u64)(vt->nvt.curtime.hi) << 32;
|
||||
return t;
|
||||
|
||||
u64 time = __getVTimerTime(vt);
|
||||
return time;
|
||||
}
|
||||
|
||||
void __setVTimer(VTimer *vt, u64 time) {
|
||||
vt->nvt.current = time - __getVTimerRunningTime(vt);
|
||||
}
|
||||
|
||||
u32 sceKernelSetVTimerTime(u32 uid, u32 timeClockAddr) {
|
||||
ERROR_LOG(HLE,"sceKernelSetVTimerTime(%i, %08x)", uid, timeClockAddr);
|
||||
DEBUG_LOG(HLE, "sceKernelSetVTimerTime(%08x, %08x)", uid, timeClockAddr);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelSetVTimerTime(%08x, %08x)", error, uid, timeClockAddr);
|
||||
return error;
|
||||
}
|
||||
Memory::ReadStruct(timeClockAddr, &vt->nvt.curtime);
|
||||
|
||||
u64 time = Memory::Read_U64(timeClockAddr);
|
||||
__setVTimer(vt, time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelSetVTimerTimeWide(u32 uid, u64 timeClock) {
|
||||
ERROR_LOG(HLE,"sceKernelSetVTimerTime(%i, %llu)", uid, timeClock);
|
||||
DEBUG_LOG(HLE, "sceKernelSetVTimerTimeWide(%08x, %llu", uid, timeClock);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
if (!vt) {
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelSetVTimerTimeWide(%08x, %llu)", error, uid, timeClock);
|
||||
return error;
|
||||
}
|
||||
vt->nvt.curtime.lo = timeClock & 0xFFFFFFFF;
|
||||
vt->nvt.curtime.hi = timeClock >> 32;
|
||||
|
||||
__setVTimer(vt, timeClock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __startVTimer(VTimer *vt) {
|
||||
vt->nvt.active = 1;
|
||||
vt->nvt.base = cyclesToUs(CoreTiming::GetTicks());
|
||||
|
||||
if (vt->nvt.schedule != 0 && vt->nvt.handlerAddr != 0)
|
||||
__KernelScheduleVTimer(vt, vt->nvt.schedule);
|
||||
}
|
||||
|
||||
u32 sceKernelStartVTimer(u32 uid) {
|
||||
DEBUG_LOG(HLE, "sceKernelStartVTimer(%08x)", uid);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
|
||||
if (vt) {
|
||||
if (vt->nvt.active)
|
||||
return 1;
|
||||
|
||||
__startVTimer(vt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void __stopVTimer(VTimer *vt) {
|
||||
vt->nvt.current += __getVTimerRunningTime(vt);
|
||||
vt->nvt.active = 0;
|
||||
}
|
||||
|
||||
u32 sceKernelStopVTimer(u32 uid) {
|
||||
DEBUG_LOG(HLE, "sceKernelStopVTimer(%08x)", uid);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
|
||||
if (vt) {
|
||||
if (vt->nvt.active == 0)
|
||||
return 0;
|
||||
|
||||
__stopVTimer(vt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
u32 sceKernelSetVTimerHandler(u32 uid, u32 scheduleAddr, u32 handlerFuncAddr, u32 commonAddr) {
|
||||
DEBUG_LOG(HLE, "sceKernelSetVTimerHandler(%08x, %08x, %08x, %08x)", uid, scheduleAddr, handlerFuncAddr, commonAddr);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelSetVTimerHandler(%08x, %08x, %08x, %08x)", error, uid, scheduleAddr, handlerFuncAddr, commonAddr);
|
||||
return error;
|
||||
}
|
||||
|
||||
u64 schedule = Memory::Read_U64(scheduleAddr);
|
||||
vt->nvt.handlerAddr = handlerFuncAddr;
|
||||
vt->nvt.commonAddr = commonAddr;
|
||||
|
||||
__KernelScheduleVTimer(vt, schedule);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelSetVTimerHandlerWide(u32 uid, u64 schedule, u32 handlerFuncAddr, u32 commonAddr) {
|
||||
DEBUG_LOG(HLE, "sceKernelSetVTimerHandlerWide(%08x, %llu, %08x, %08x)", uid, schedule, handlerFuncAddr, commonAddr);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelSetVTimerHandlerWide(%08x, %llu, %08x, %08x)", error, uid, schedule, handlerFuncAddr, commonAddr);
|
||||
return error;
|
||||
}
|
||||
|
||||
vt->nvt.handlerAddr = handlerFuncAddr;
|
||||
vt->nvt.commonAddr = commonAddr;
|
||||
|
||||
__KernelScheduleVTimer(vt, schedule);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelCancelVTimerHandler(u32 uid) {
|
||||
DEBUG_LOG(HLE, "sceKernelCancelVTimerHandler(%08x)", uid);
|
||||
|
||||
//__cancelVTimer checks if uid is valid
|
||||
__cancelVTimer(uid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceKernelReferVTimerStatus(u32 uid, u32 statusAddr) {
|
||||
DEBUG_LOG(HLE, "sceKernelReferVTimerStatus(%08x, %08x)", uid, statusAddr);
|
||||
|
||||
u32 error;
|
||||
VTimer *vt = kernelObjects.Get<VTimer>(uid, error);
|
||||
|
||||
if (error) {
|
||||
WARN_LOG(HLE, "%08x=sceKernelReferVTimerStatus(%08x, %08x)", error, uid, statusAddr);
|
||||
return error;
|
||||
}
|
||||
|
||||
if (Memory::IsValidAddress(statusAddr))
|
||||
Memory::WriteStruct(statusAddr, &vt->nvt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Not sure why this is exposed...
|
||||
void _sceKernelReturnFromTimerHandler()
|
||||
{
|
||||
void _sceKernelReturnFromTimerHandler() {
|
||||
ERROR_LOG(HLE,"_sceKernelReturnFromTimerHandler - should not be called!");
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,6 @@ u32 sceKernelSetVTimerTimeWide(u32 uid, u64 timeClock);
|
||||
// TODO
|
||||
void _sceKernelReturnFromTimerHandler();
|
||||
|
||||
void __KernelVTimerInit();
|
||||
void __KernelVTimerDoState(PointerWrap &p);
|
||||
KernelObject *__KernelVTimerObject();
|
||||
+83
-18
@@ -23,6 +23,7 @@
|
||||
#include "sceKernelThread.h"
|
||||
#include "HLE.h"
|
||||
#include "../HW/MediaEngine.h"
|
||||
#include "../../Core/Config.h"
|
||||
|
||||
static bool useMediaEngine;
|
||||
|
||||
@@ -125,9 +126,9 @@ struct Mp3Context {
|
||||
p.DoMarker("Mp3Context");
|
||||
}
|
||||
|
||||
int mp3StreamStart;
|
||||
int mp3StreamEnd;
|
||||
int mp3StreamPosition;
|
||||
u64 mp3StreamStart;
|
||||
u64 mp3StreamEnd;
|
||||
u64 mp3StreamPosition;
|
||||
u32 mp3Buf;
|
||||
int mp3BufSize;
|
||||
int mp3BufPendingSize;
|
||||
@@ -398,6 +399,11 @@ void __MpegShutdown() {
|
||||
|
||||
u32 sceMpegInit()
|
||||
{
|
||||
if (!g_Config.bUseMediaEngine){
|
||||
WARN_LOG(HLE, "Media Engine disabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
WARN_LOG(HLE, "sceMpegInit()");
|
||||
return 0;
|
||||
}
|
||||
@@ -420,6 +426,11 @@ u32 sceMpegRingbufferConstruct(u32 ringbufferAddr, u32 numPackets, u32 data, u32
|
||||
|
||||
u32 sceMpegCreate(u32 mpegAddr, u32 dataPtr, u32 size, u32 ringbufferAddr, u32 frameWidth, u32 mode, u32 ddrTop)
|
||||
{
|
||||
if (!g_Config.bUseMediaEngine){
|
||||
WARN_LOG(HLE, "Media Engine disabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (size < MPEG_MEMSIZE) {
|
||||
WARN_LOG(HLE, "ERROR_MPEG_NO_MEMORY=sceMpegCreate(%08x, %08x, %i, %08x, %i, %i, %i)",
|
||||
mpegAddr, dataPtr, size, ringbufferAddr, frameWidth, mode, ddrTop);
|
||||
@@ -427,6 +438,7 @@ u32 sceMpegCreate(u32 mpegAddr, u32 dataPtr, u32 size, u32 ringbufferAddr, u32 f
|
||||
}
|
||||
|
||||
SceMpegRingBuffer ringbuffer;
|
||||
if(ringbufferAddr != 0){
|
||||
Memory::ReadStruct(ringbufferAddr, &ringbuffer);
|
||||
if (ringbuffer.packetSize == 0) {
|
||||
ringbuffer.packetsFree = 0;
|
||||
@@ -435,6 +447,7 @@ u32 sceMpegCreate(u32 mpegAddr, u32 dataPtr, u32 size, u32 ringbufferAddr, u32 f
|
||||
}
|
||||
ringbuffer.mpeg = mpegAddr;
|
||||
Memory::WriteStruct(ringbufferAddr, &ringbuffer);
|
||||
}
|
||||
|
||||
// Generate, and write mpeg handle into mpeg data, for some reason
|
||||
int mpegHandle = dataPtr + 0x30;
|
||||
@@ -453,7 +466,7 @@ u32 sceMpegCreate(u32 mpegAddr, u32 dataPtr, u32 size, u32 ringbufferAddr, u32 f
|
||||
ctx->videoFrameCount = 0;
|
||||
ctx->audioFrameCount = 0;
|
||||
// TODO: What's the actual default?
|
||||
ctx->videoPixelMode = 0;
|
||||
ctx->videoPixelMode = TPSM_PIXEL_STORAGE_MODE_32BIT_ABGR8888;
|
||||
ctx->avcRegistered = false;
|
||||
ctx->atracRegistered = false;
|
||||
ctx->pcmRegistered = false;
|
||||
@@ -532,14 +545,18 @@ int sceMpegQueryStreamOffset(u32 mpeg, u32 bufferAddr, u32 offsetAddr)
|
||||
|
||||
if (ctx->mpegMagic != PSMF_MAGIC) {
|
||||
ERROR_LOG(HLE, "sceMpegQueryStreamOffset: Bad PSMF magic");
|
||||
Memory::Write_U32(0, offsetAddr);
|
||||
return ERROR_MPEG_INVALID_VALUE;
|
||||
} else if (ctx->mpegVersion < 0) {
|
||||
ERROR_LOG(HLE, "sceMpegQueryStreamOffset: Bad version");
|
||||
Memory::Write_U32(0, offsetAddr);
|
||||
return ERROR_MPEG_BAD_VERSION;
|
||||
} else if ((ctx->mpegOffset & 2047) != 0 || ctx->mpegOffset == 0) {
|
||||
ERROR_LOG(HLE, "sceMpegQueryStreamOffset: Bad offset");
|
||||
Memory::Write_U32(0, offsetAddr);
|
||||
return ERROR_MPEG_INVALID_VALUE;
|
||||
}
|
||||
|
||||
Memory::Write_U32(ctx->mpegOffset, offsetAddr);
|
||||
return 0;
|
||||
}
|
||||
@@ -548,22 +565,22 @@ u32 sceMpegQueryStreamSize(u32 bufferAddr, u32 sizeAddr)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceMpegQueryStreamSize(%08x, %08x)", bufferAddr, sizeAddr);
|
||||
|
||||
MpegContext temp;
|
||||
temp.mediaengine = new MediaEngine();
|
||||
MpegContext ctx;
|
||||
ctx.mediaengine = new MediaEngine();
|
||||
|
||||
AnalyzeMpeg(bufferAddr, &temp);
|
||||
AnalyzeMpeg(bufferAddr, &ctx);
|
||||
|
||||
if (temp.mpegMagic != PSMF_MAGIC) {
|
||||
if (ctx.mpegMagic != PSMF_MAGIC) {
|
||||
ERROR_LOG(HLE, "sceMpegQueryStreamOffset: Bad PSMF magic");
|
||||
Memory::Write_U32(0, sizeAddr);
|
||||
return ERROR_MPEG_INVALID_VALUE;
|
||||
} else if (temp.mpegVersion < 0) {
|
||||
ERROR_LOG(HLE, "sceMpegQueryStreamOffset: Bad version");
|
||||
return ERROR_MPEG_BAD_VERSION;
|
||||
} else if ((temp.mpegOffset & 2047) != 0 || temp.mpegOffset == 0) {
|
||||
} else if ((ctx.mpegOffset & 2047) != 0 ) {
|
||||
ERROR_LOG(HLE, "sceMpegQueryStreamOffset: Bad offset");
|
||||
Memory::Write_U32(0, sizeAddr);
|
||||
return ERROR_MPEG_INVALID_VALUE;
|
||||
}
|
||||
Memory::Write_U32(temp.mpegStreamSize, sizeAddr);
|
||||
|
||||
Memory::Write_U32(ctx.mpegStreamSize, sizeAddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -648,6 +665,11 @@ int sceMpegFreeAvcEsBuf(u32 mpeg, int esBuf)
|
||||
|
||||
u32 sceMpegAvcDecode(u32 mpeg, u32 auAddr, u32 frameWidth, u32 bufferAddr, u32 initAddr)
|
||||
{
|
||||
if (!g_Config.bUseMediaEngine){
|
||||
WARN_LOG(HLE, "Media Engine disabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MpegContext *ctx = getMpegCtx(mpeg);
|
||||
if (!ctx) {
|
||||
WARN_LOG(HLE, "sceMpegAvcDecode(%08x, %08x, %d, %08x, %08x): bad mpeg handle", mpeg, auAddr, frameWidth, bufferAddr, initAddr);
|
||||
@@ -831,6 +853,11 @@ u32 sceMpegAvcDecodeStopYCbCr(u32 mpeg, u32 bufferAddr, u32 statusAddr)
|
||||
|
||||
int sceMpegAvcDecodeYCbCr(u32 mpeg, u32 auAddr, u32 bufferAddr, u32 initAddr)
|
||||
{
|
||||
if (!g_Config.bUseMediaEngine){
|
||||
WARN_LOG(HLE, "Media Engine disabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MpegContext *ctx = getMpegCtx(mpeg);
|
||||
if (!ctx) {
|
||||
WARN_LOG(HLE, "sceMpegAvcDecodeYCbCr(%08x, %08x, %08x, %08x): bad mpeg handle", mpeg, auAddr, bufferAddr, initAddr);
|
||||
@@ -1012,7 +1039,8 @@ void PostPutAction::run(MipsCall &call) {
|
||||
u32 sceMpegRingbufferPut(u32 ringbufferAddr, u32 numPackets, u32 available)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceMpegRingbufferPut(%08x, %i, %i)", ringbufferAddr, numPackets, available);
|
||||
if (numPackets < 0) {
|
||||
numPackets = std::min(numPackets, available);
|
||||
if (numPackets <= 0) {
|
||||
ERROR_LOG(HLE, "sub-zero number of packets put");
|
||||
return 0;
|
||||
}
|
||||
@@ -1020,8 +1048,6 @@ u32 sceMpegRingbufferPut(u32 ringbufferAddr, u32 numPackets, u32 available)
|
||||
SceMpegRingBuffer ringbuffer;
|
||||
Memory::ReadStruct(ringbufferAddr, &ringbuffer);
|
||||
|
||||
numPackets = std::min(numPackets, available);
|
||||
|
||||
MpegContext *ctx = getMpegCtx(ringbuffer.mpeg);
|
||||
if (!ctx) {
|
||||
WARN_LOG(HLE, "sceMpegRingbufferPut(%08x, %i, %i): bad mpeg handle %08x", ringbufferAddr, numPackets, available, ringbuffer.mpeg);
|
||||
@@ -1266,7 +1292,7 @@ u32 sceMpegAvcCopyYCbCr(u32 mpeg, u32 sourceAddr, u32 YCbCrAddr)
|
||||
|
||||
u32 sceMpegAtracDecode(u32 mpeg, u32 auAddr, u32 bufferAddr, int init)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL sceMpegAtracDecode(%08x, %08x, %08x, %i)", mpeg, auAddr, bufferAddr, init);
|
||||
DEBUG_LOG(HLE, "UNIMPL sceMpegAtracDecode(%08x, %08x, %08x, %i)", mpeg, auAddr, bufferAddr, init);
|
||||
if (Memory::IsValidAddress(bufferAddr))
|
||||
Memory::Memset(bufferAddr, 0, MPEG_ATRAC_ES_OUTPUT_SIZE);
|
||||
return 0;
|
||||
@@ -1319,6 +1345,40 @@ u32 sceMpegQueryUserdataEsSize(u32 mpeg, u32 esSizeAddr, u32 outSizeAddr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
u32 sceMpegAvcResourceGetAvcDecTopAddr(u32 mpeg)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL sceMpegAvcResourceGetAvcDecTopAddr(%08x)", mpeg);
|
||||
// it's just a random address
|
||||
return 0x12345678;
|
||||
}
|
||||
|
||||
u32 sceMpegAvcResourceFinish(u32 mpeg)
|
||||
{
|
||||
DEBUG_LOG(HLE,"sceMpegAvcResourceFinish(%08x)", mpeg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceMpegAvcResourceGetAvcEsBuf(u32 mpeg)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL sceMpegAvcResourceGetAvcEsBuf(%08x)", mpeg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceMpegAvcResourceInit(u32 mpeg)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL sceMpegAvcResourceInit(%08x)", mpeg);
|
||||
if (mpeg != 1) {
|
||||
return ERROR_MPEG_INVALID_VALUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sceMpegAvcConvertToYuv420(u32 mpeg, u32 bufferOutput, u32 unknown1, int unknown2)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL sceMpegAvcConvertToYuv420(%08x, %08x, %08x, %08x)", mpeg, bufferOutput, unknown1, unknown2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* MP3 */
|
||||
int sceMp3Decode(u32 mp3, u32 outPcmPtr)
|
||||
@@ -1343,7 +1403,7 @@ int sceMp3Decode(u32 mp3, u32 outPcmPtr)
|
||||
// TODO: Actually decode the data
|
||||
#ifdef _DEBUG
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%i.mp3", ctx->mp3StreamPosition);
|
||||
sprintf(fileName, "%lli.mp3", ctx->mp3StreamPosition);
|
||||
|
||||
FILE * file = fopen(fileName, "wb");
|
||||
if(file) {
|
||||
@@ -1690,6 +1750,11 @@ const HLEFunction sceMpeg[] =
|
||||
{0xC02CF6B5,WrapI_UUU<sceMpegQueryPcmEsSize>,"sceMpegQueryPcmEsSize"},
|
||||
{0xC45C99CC,WrapU_UUU<sceMpegQueryUserdataEsSize>,"sceMpegQueryUserdataEsSize"},
|
||||
{0x234586AE,WrapU_UUI<sceMpegChangeGetAvcAuMode>,"sceMpegChangeGetAvcAuMode"},
|
||||
{0x63B9536A,WrapU_U<sceMpegAvcResourceGetAvcDecTopAddr>,"sceMpegAvcResourceGetAvcDecTopAddr"},
|
||||
{0x8160a2fe,WrapU_U<sceMpegAvcResourceFinish>,"sceMpegAvcResourceFinish"},
|
||||
{0xaf26bb01,WrapU_U<sceMpegAvcResourceGetAvcEsBuf>,"sceMpegAvcResourceGetAvcEsBuf"},
|
||||
{0xfcbdb5ad,WrapU_U<sceMpegAvcResourceInit>,"sceMpegAvcResourceInit"},
|
||||
{0xF5E7EA31,WrapI_UUUI<sceMpegAvcConvertToYuv420>,"sceMpegAvcConvertToYuv420"},
|
||||
};
|
||||
|
||||
const HLEFunction sceMp3[] =
|
||||
|
||||
+6
-1
@@ -96,9 +96,14 @@ const HLEFunction sceNetAdhoc[] =
|
||||
{0x7a662d6b, 0, "sceNetAdhocPollSocket"},
|
||||
};
|
||||
|
||||
int sceNetAdhocMatchingInit(u32 memsize) {
|
||||
ERROR_LOG(HLE, "UNIMPL sceNetAdhocMatchingInit(%08x)", memsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const HLEFunction sceNetAdhocMatching[] =
|
||||
{
|
||||
{0x2a2a1e07, 0, "sceNetAdhocMatchingInit"},
|
||||
{0x2a2a1e07, WrapI_U<sceNetAdhocMatchingInit>, "sceNetAdhocMatchingInit"},
|
||||
{0x7945ecda, 0, "sceNetAdhocMatchingTerm"},
|
||||
{0xca5eda6f, 0, "sceNetAdhocMatchingCreate"},
|
||||
{0x93ef3843, 0, "sceNetAdhocMatchingStart"},
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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/.
|
||||
|
||||
#include "HLE.h"
|
||||
|
||||
|
||||
u32 sceP3daBridgeInit(u32 channelsNum, u32 samplesNum)
|
||||
{
|
||||
DEBUG_LOG(HLE, "UNIMPL sceP3daBridgeInit(%08x, %08x)", channelsNum, samplesNum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceP3daBridgeExit()
|
||||
{
|
||||
DEBUG_LOG(HLE, "UNIMPL sceP3daBridgeExit()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 sceP3daBridgeCore(u32 p3daCoreAddr, u32 channelsNum, u32 samplesNum, u32 inputAddr, u32 outputAddr)
|
||||
{
|
||||
DEBUG_LOG(HLE, "UNIMPL sceP3daBridgeCore(%08x, %08x, %08x, %08x, %08x)", p3daCoreAddr, channelsNum, samplesNum, inputAddr, outputAddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const HLEFunction sceP3da[] =
|
||||
{
|
||||
{0x374500a5, WrapU_UU<sceP3daBridgeInit>, "sceP3daBridgeInit"},
|
||||
{0x43F756a2, WrapU_V<sceP3daBridgeExit>, "sceP3daBridgeExit"},
|
||||
{0x013016f3, WrapU_UUUUU<sceP3daBridgeCore>, "sceP3daBridgeCore"},
|
||||
};
|
||||
|
||||
void Register_sceP3da()
|
||||
{
|
||||
RegisterModule("sceP3da", ARRAY_SIZE(sceP3da), sceP3da);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HLE.h"
|
||||
|
||||
void Register_sceP3da();
|
||||
+23
-12
@@ -43,6 +43,10 @@ const int numberOfCBPowerSlotsPrivate = 32;
|
||||
static bool volatileMemLocked;
|
||||
static int powerCbSlots[numberOfCBPowerSlots];
|
||||
|
||||
// this should belong here on in CoreTiming?
|
||||
static int pllFreq = 222;
|
||||
static int busFreq = 111;
|
||||
|
||||
void __PowerInit() {
|
||||
memset(powerCbSlots, 0, sizeof(powerCbSlots));
|
||||
volatileMemLocked = false;
|
||||
@@ -213,9 +217,12 @@ int sceKernelVolatileMemLock(int type, int paddr, int psize) {
|
||||
}
|
||||
|
||||
|
||||
void scePowerSetClockFrequency(u32 cpufreq, u32 busfreq, u32 gpufreq) {
|
||||
u32 scePowerSetClockFrequency(u32 pllfreq, u32 cpufreq, u32 busfreq) {
|
||||
CoreTiming::SetClockFrequencyMHz(cpufreq);
|
||||
INFO_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i)", cpufreq, busfreq, gpufreq);
|
||||
pllFreq = pllfreq;
|
||||
busFreq = busfreq;
|
||||
INFO_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i)", pllfreq, cpufreq, busfreq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 scePowerSetCpuClockFrequency(u32 cpufreq) {
|
||||
@@ -225,6 +232,7 @@ u32 scePowerSetCpuClockFrequency(u32 cpufreq) {
|
||||
}
|
||||
|
||||
u32 scePowerSetBusClockFrequency(u32 busfreq) {
|
||||
busFreq = busfreq;
|
||||
DEBUG_LOG(HLE,"scePowerSetBusClockFrequency(%i)", busfreq);
|
||||
return 0;
|
||||
}
|
||||
@@ -236,15 +244,18 @@ u32 scePowerGetCpuClockFrequencyInt() {
|
||||
}
|
||||
|
||||
u32 scePowerGetPllClockFrequencyInt() {
|
||||
int freq = CoreTiming::GetClockFrequencyMHz() / 2;
|
||||
INFO_LOG(HLE,"%i=scePowerGetPllClockFrequencyInt()", freq);
|
||||
return freq;
|
||||
INFO_LOG(HLE,"%i=scePowerGetPllClockFrequencyInt()", pllFreq);
|
||||
return pllFreq;
|
||||
}
|
||||
|
||||
float scePowerGetPllClockFrequencyFloat() {
|
||||
INFO_LOG(HLE, "%f=scePowerGetPllClockFrequencyFloat()", (float)pllFreq);
|
||||
return (float) pllFreq;
|
||||
}
|
||||
|
||||
u32 scePowerGetBusClockFrequencyInt() {
|
||||
int freq = CoreTiming::GetClockFrequencyMHz() / 2;
|
||||
INFO_LOG(HLE,"%i=scePowerGetBusClockFrequencyInt()", freq);
|
||||
return freq;
|
||||
INFO_LOG(HLE,"%i=scePowerGetBusClockFrequencyInt()", busFreq);
|
||||
return busFreq;
|
||||
}
|
||||
|
||||
// a85880d0, unknown name
|
||||
@@ -297,11 +308,11 @@ static const HLEFunction scePower[] = {
|
||||
{0xBD681969,WrapU_V<scePowerGetBusClockFrequencyInt>,"scePowerGetBusClockFrequencyInt"},
|
||||
{0xB1A52C83,0,"scePowerGetCpuClockFrequencyFloat"},
|
||||
{0x9BADB3EB,0,"scePowerGetBusClockFrequencyFloat"},
|
||||
{0x737486F2,WrapV_UUU<scePowerSetClockFrequency>,"scePowerSetClockFrequency"},
|
||||
{0x737486F2,WrapU_UUU<scePowerSetClockFrequency>,"scePowerSetClockFrequency"},
|
||||
{0x34f9c463,WrapU_V<scePowerGetPllClockFrequencyInt>,"scePowerGetPllClockFrequencyInt"},
|
||||
{0xea382a27,0,"scePowerGetPllClockFrequencyFloat"},
|
||||
{0xebd177d6,WrapV_UUU<scePowerSetClockFrequency>,"scePower_driver_EBD177D6"}, //TODO: used in a few places, jpcsp says is the same as scePowerSetClockFrequency
|
||||
{0x469989ad,WrapV_UUU<scePowerSetClockFrequency>,"scePower_469989ad"}, // This is also the same as SetClockFrequency
|
||||
{0xea382a27,WrapF_V<scePowerGetPllClockFrequencyFloat>,"scePowerGetPllClockFrequencyFloat"},
|
||||
{0xebd177d6,WrapU_UUU<scePowerSetClockFrequency>,"scePower_driver_EBD177D6"}, //TODO: used in a few places, jpcsp says is the same as scePowerSetClockFrequency
|
||||
{0x469989ad,WrapU_UUU<scePowerSetClockFrequency>,"scePower_469989ad"}, // This is also the same as SetClockFrequency
|
||||
{0xa85880d0,WrapU_V<IsPSPNonFat>,"scePower_a85880d0_IsPSPNonFat"},
|
||||
};
|
||||
|
||||
|
||||
+47
-24
@@ -164,6 +164,7 @@ public:
|
||||
|
||||
SceMpegAu psmfPlayerAtracAu;
|
||||
SceMpegAu psmfPlayerAvcAu;
|
||||
PsmfPlayerStatus status;
|
||||
};
|
||||
|
||||
class PsmfStream {
|
||||
@@ -260,6 +261,7 @@ PsmfPlayer::PsmfPlayer(u32 data) {
|
||||
playMode = Memory::Read_U32(data+ 16);
|
||||
playSpeed = Memory::Read_U32(data + 20);
|
||||
psmfPlayerLastTimestamp = bswap32(Memory::Read_U32(data + PSMF_LAST_TIMESTAMP_OFFSET)) ;
|
||||
status = PSMF_PLAYER_STATUS_INIT;
|
||||
}
|
||||
|
||||
void Psmf::DoState(PointerWrap &p) {
|
||||
@@ -310,8 +312,6 @@ void PsmfPlayer::DoState(PointerWrap &p) {
|
||||
|
||||
static std::map<u32, Psmf *> psmfMap;
|
||||
static std::map<u32, PsmfPlayer *> psmfPlayerMap;
|
||||
// TODO: Should have a map.
|
||||
static PsmfPlayerStatus psmfPlayerStatus = PSMF_PLAYER_STATUS_NONE;
|
||||
|
||||
Psmf *getPsmf(u32 psmf)
|
||||
{
|
||||
@@ -333,7 +333,6 @@ PsmfPlayer *getPsmfPlayer(u32 psmfplayer)
|
||||
|
||||
void __PsmfInit()
|
||||
{
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_NONE;
|
||||
}
|
||||
|
||||
void __PsmfDoState(PointerWrap &p)
|
||||
@@ -347,9 +346,6 @@ void __PsmfPlayerDoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(psmfPlayerMap);
|
||||
|
||||
// TODO: Actually load this from a map.
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_NONE;
|
||||
|
||||
p.DoMarker("scePsmfPlayer");
|
||||
}
|
||||
|
||||
@@ -357,7 +353,10 @@ void __PsmfShutdown()
|
||||
{
|
||||
for (auto it = psmfMap.begin(), end = psmfMap.end(); it != end; ++it)
|
||||
delete it->second;
|
||||
for (auto it = psmfPlayerMap.begin(), end = psmfPlayerMap.end(); it != end; ++it)
|
||||
delete it->second;
|
||||
psmfMap.clear();
|
||||
psmfPlayerMap.clear();
|
||||
}
|
||||
|
||||
u32 scePsmfSetPsmf(u32 psmfStruct, u32 psmfData)
|
||||
@@ -623,35 +622,43 @@ int scePsmfPlayerCreate(u32 psmfPlayer, u32 psmfPlayerDataAddr)
|
||||
}
|
||||
|
||||
psmfplayer->psmfMaxAheadTimestamp = getMaxAheadTimestamp(581);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_INIT;
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_INIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerStop(u32 psmfPlayer)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerStop(%08x)", psmfPlayer);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_STANDBY;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_STANDBY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerBreak(u32 psmfPlayer)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerBreak(%08x)", psmfPlayer);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_STANDBY;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_STANDBY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerSetPsmf(u32 psmfPlayer, const char *filename)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerSetPsmf(%08x, %s)", psmfPlayer, filename);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_STANDBY;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_STANDBY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerSetPsmfCB(u32 psmfPlayer, const char *filename)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerSetPsmfCB(%08x, %s)", psmfPlayer, filename);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_STANDBY;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_STANDBY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -686,14 +693,16 @@ int scePsmfPlayerStart(u32 psmfPlayer, u32 psmfPlayerData, int initPts)
|
||||
psmfplayer->psmfPlayerAvcAu.dts = initPts;
|
||||
psmfplayer->psmfPlayerAvcAu.pts = initPts;
|
||||
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_PLAYING;
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_PLAYING;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerDelete(u32 psmfPlayer)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerDelete(%08x)", psmfPlayer);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_NONE;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -708,25 +717,32 @@ int scePsmfPlayerUpdate(u32 psmfPlayer)
|
||||
|
||||
if (psmfplayer->psmfPlayerAvcAu.pts > 0) {
|
||||
if (psmfplayer->psmfPlayerAvcAu.pts > psmfplayer->psmfPlayerLastTimestamp) {
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_PLAYING_FINISHED;
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_PLAYING_FINISHED;
|
||||
}
|
||||
}
|
||||
// TODO: Once we start increasing pts somewhere, and actually know the last timestamp, do this better.
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_PLAYING_FINISHED;
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_PLAYING_FINISHED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerReleasePsmf(u32 psmfPlayer)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerReleasePsmf(%08x)", psmfPlayer);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_INIT;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_INIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerGetCurrentStatus(u32 psmfPlayer)
|
||||
{
|
||||
ERROR_LOG(HLE, "scePsmfPlayerGetCurrentStatus(%08x)", psmfPlayer);
|
||||
return psmfPlayerStatus;
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (!psmfplayer) {
|
||||
ERROR_LOG(HLE, "scePsmfPlayerUpdate - invalid psmf");
|
||||
return ERROR_PSMF_NOT_FOUND;
|
||||
}
|
||||
return psmfplayer->status;
|
||||
}
|
||||
|
||||
u32 scePsmfPlayerGetCurrentPts(u32 psmfPlayer, u32 currentPtsAddr)
|
||||
@@ -737,7 +753,7 @@ u32 scePsmfPlayerGetCurrentPts(u32 psmfPlayer, u32 currentPtsAddr)
|
||||
ERROR_LOG(HLE, "scePsmfPlayerGetCurrentPts - invalid psmf");
|
||||
return ERROR_PSMF_NOT_FOUND;
|
||||
}
|
||||
if (psmfPlayerStatus < PSMF_PLAYER_STATUS_STANDBY) {
|
||||
if (psmfplayer->status < PSMF_PLAYER_STATUS_STANDBY) {
|
||||
return ERROR_PSMFPLAYER_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
@@ -759,7 +775,7 @@ u32 scePsmfPlayerGetPsmfInfo(u32 psmfPlayer, u32 psmfInfoAddr)
|
||||
ERROR_LOG(HLE, "scePsmfPlayerGetPsmfInfo - invalid psmf");
|
||||
return ERROR_PSMF_NOT_FOUND;
|
||||
}
|
||||
if (psmfPlayerStatus < PSMF_PLAYER_STATUS_STANDBY) {
|
||||
if (psmfplayer->status < PSMF_PLAYER_STATUS_STANDBY) {
|
||||
return ERROR_PSMFPLAYER_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
@@ -820,10 +836,12 @@ u32 scePsmfPlayerGetCurrentAudioStream(u32 psmfPlayer, u32 audioCodecAddr, u32 a
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scePsmfPlayerSetTempBuf(u32 psmfPlayer)
|
||||
int scePsmfPlayerSetTempBuf(u32 psmfPlayer, u32 tempBufAddr, u32 tempBufSize)
|
||||
{
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerSetTempBuf(%08x)", psmfPlayer);
|
||||
psmfPlayerStatus = PSMF_PLAYER_STATUS_INIT;
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfPlayerSetTempBuf(%08x, %08x, %08x)", psmfPlayer, tempBufAddr, tempBufSize);
|
||||
PsmfPlayer *psmfplayer = getPsmfPlayer(psmfPlayer);
|
||||
if (psmfplayer)
|
||||
psmfplayer->status = PSMF_PLAYER_STATUS_INIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -911,13 +929,18 @@ u32 scePsmfPlayerConfigPlayer(u32 psmfPlayer, int configMode, int configAttr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 scePsmfSpecifyStream(u32 psmfPlayer, int streamNum) {
|
||||
ERROR_LOG(HLE, "UNIMPL scePsmfSpecifyStream(%08x, %i)", psmfPlayer, streamNum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const HLEFunction scePsmf[] = {
|
||||
{0xc22c8327, WrapU_UU<scePsmfSetPsmf>, "scePsmfSetPsmf"},
|
||||
{0xC7DB3A5B, WrapU_UUU<scePsmfGetCurrentStreamType>, "scePsmfGetCurrentStreamType"},
|
||||
{0x28240568, WrapU_U<scePsmfGetCurrentStreamNumber>, "scePsmfGetCurrentStreamNumber"},
|
||||
{0x1E6D9013, WrapU_UUU<scePsmfSpecifyStreamWithStreamType>, "scePsmfSpecifyStreamWithStreamType"},
|
||||
{0x0C120E1D, WrapU_UUU<scePsmfSpecifyStreamWithStreamTypeNumber>, "scePsmfSpecifyStreamWithStreamTypeNumber"},
|
||||
{0x4BC9BDE0, 0, "scePsmfSpecifyStream"},
|
||||
{0x4BC9BDE0, WrapU_UI<scePsmfSpecifyStream>, "scePsmfSpecifyStream"},
|
||||
{0x76D3AEBA, WrapU_UU<scePsmfGetPresentationStartTime>, "scePsmfGetPresentationStartTime"},
|
||||
{0xBD8AE0D8, WrapU_UU<scePsmfGetPresentationEndTime>, "scePsmfGetPresentationEndTime"},
|
||||
{0xEAED89CD, WrapU_U<scePsmfGetNumberOfStreams>, "scePsmfGetNumberOfStreams"},
|
||||
@@ -963,7 +986,7 @@ const HLEFunction scePsmfPlayer[] =
|
||||
{0xe792cd94, WrapI_U<scePsmfPlayerReleasePsmf>, "scePsmfPlayerReleasePsmf"},
|
||||
{0xf3efaa91, WrapU_UUU<scePsmfPlayerGetCurrentPlayMode>, "scePsmfPlayerGetCurrentPlayMode"},
|
||||
{0xf8ef08a6, WrapI_U<scePsmfPlayerGetCurrentStatus>, "scePsmfPlayerGetCurrentStatus"},
|
||||
{0x2D0E4E0A, WrapI_U<scePsmfPlayerSetTempBuf>, "scePsmfPlayerSetTempBuf"},
|
||||
{0x2D0E4E0A, WrapI_UUU<scePsmfPlayerSetTempBuf>, "scePsmfPlayerSetTempBuf"},
|
||||
};
|
||||
|
||||
void Register_scePsmf() {
|
||||
|
||||
@@ -65,4 +65,6 @@ const HLEFunction sceNpDrm[] =
|
||||
void Register_sceNpDrm()
|
||||
{
|
||||
RegisterModule("sceNpDrm", ARRAY_SIZE(sceNpDrm), sceNpDrm);
|
||||
RegisterModule("scePspNpDrm_user", ARRAY_SIZE(sceNpDrm), sceNpDrm);
|
||||
}
|
||||
|
||||
+7
-4
@@ -28,6 +28,7 @@
|
||||
#include "HLE.h"
|
||||
#include "../MIPS/MIPS.h"
|
||||
#include "../HW/SasAudio.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "sceSas.h"
|
||||
#include "sceKernel.h"
|
||||
@@ -142,7 +143,8 @@ u32 sceSasSetVoice(u32 core, int voiceNum, u32 vagAddr, int size, int loop) {
|
||||
|
||||
u32 sceSasSetVoicePCM(u32 core, int voiceNum, u32 pcmAddr, int size, int loop)
|
||||
{
|
||||
INFO_LOG(HLE,"PLEASE REPORT issue #505 sceSasSetVoicePCM(%08x, %i, %08x, %i, %i)", core, voiceNum, pcmAddr, size, loop);
|
||||
INFO_LOG(HLE,"sceSasSetVoicePCM(%08x, %i, %08x, %i, %i)", core, voiceNum, pcmAddr, size, loop);
|
||||
Reporting::ReportMessage("sceSasSetVoicePCM(%x, %i)", core, voiceNum);
|
||||
|
||||
if (voiceNum >= PSP_SAS_VOICES_MAX || voiceNum < 0) {
|
||||
WARN_LOG(HLE, "%s: invalid voicenum %d", __FUNCTION__, voiceNum);
|
||||
@@ -160,12 +162,13 @@ u32 sceSasSetVoicePCM(u32 core, int voiceNum, u32 pcmAddr, int size, int loop)
|
||||
}
|
||||
|
||||
SasVoice &v = sas->voices[voiceNum];
|
||||
u32 prevPcmAddr = v.pcmAddr;
|
||||
v.type = VOICETYPE_PCM;
|
||||
v.pcmAddr = pcmAddr;
|
||||
v.pcmSize = size;
|
||||
v.loop = loop ? false : true;
|
||||
v.playing = true;
|
||||
v.ChangedParams(true);
|
||||
v.ChangedParams(pcmAddr == prevPcmAddr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -203,8 +206,8 @@ u32 sceSasSetVolume(u32 core, int voiceNum, int leftVol, int rightVol, int effec
|
||||
}
|
||||
|
||||
SasVoice &v = sas->voices[voiceNum];
|
||||
v.volumeLeft = (leftVol << 3);
|
||||
v.volumeRight = (rightVol << 3);
|
||||
v.volumeLeft = leftVol;
|
||||
v.volumeRight = rightVol;
|
||||
v.effectLeft = effectLeftVol;
|
||||
v.effectRight = effectRightVol;
|
||||
return 0;
|
||||
|
||||
+82
-33
@@ -24,6 +24,8 @@
|
||||
|
||||
const int PSP_ERROR_UMD_INVALID_PARAM = 0x80010016;
|
||||
|
||||
const u64 MICRO_DELAY_ACTIVATE = 4000;
|
||||
|
||||
#define UMD_NOT_PRESENT 0x01
|
||||
#define UMD_PRESENT 0x02
|
||||
#define UMD_CHANGED 0x04
|
||||
@@ -31,12 +33,27 @@ const int PSP_ERROR_UMD_INVALID_PARAM = 0x80010016;
|
||||
#define UMD_READY 0x10
|
||||
#define UMD_READABLE 0x20
|
||||
|
||||
struct UmdWaitingThread
|
||||
{
|
||||
SceUID threadID;
|
||||
u32 stat;
|
||||
|
||||
inline static UmdWaitingThread Make(SceUID threadID, u32 stat)
|
||||
{
|
||||
UmdWaitingThread th;
|
||||
th.threadID = threadID;
|
||||
th.stat = stat;
|
||||
return th;
|
||||
}
|
||||
};
|
||||
|
||||
static u8 umdActivated = 1;
|
||||
static u32 umdStatus = 0;
|
||||
static u32 umdErrorStat = 0;
|
||||
static int driveCBId = -1;
|
||||
static int umdStatTimer = -1;
|
||||
static int umdStatTimeoutEvent = -1;
|
||||
static int umdStatChangeEvent = -1;
|
||||
static std::vector<UmdWaitingThread> umdWaitingThreads;
|
||||
|
||||
|
||||
#define PSP_UMD_TYPE_GAME 0x10
|
||||
@@ -49,10 +66,12 @@ struct PspUmdInfo {
|
||||
};
|
||||
|
||||
void __UmdStatTimeout(u64 userdata, int cyclesLate);
|
||||
void __UmdStatChange(u64 userdata, int cyclesLate);
|
||||
|
||||
void __UmdInit()
|
||||
{
|
||||
umdStatTimer = CoreTiming::RegisterEvent("UmdTimeout", __UmdStatTimeout);
|
||||
umdStatTimeoutEvent = CoreTiming::RegisterEvent("UmdTimeout", __UmdStatTimeout);
|
||||
umdStatChangeEvent = CoreTiming::RegisterEvent("UmdChange", __UmdStatChange);
|
||||
umdActivated = 1;
|
||||
umdStatus = 0;
|
||||
umdErrorStat = 0;
|
||||
@@ -65,8 +84,11 @@ void __UmdDoState(PointerWrap &p)
|
||||
p.Do(umdStatus);
|
||||
p.Do(umdErrorStat);
|
||||
p.Do(driveCBId);
|
||||
p.Do(umdStatTimer);
|
||||
CoreTiming::RestoreRegisterEvent(umdStatTimer, "UmdTimeout", __UmdStatTimeout);
|
||||
p.Do(umdStatTimeoutEvent);
|
||||
CoreTiming::RestoreRegisterEvent(umdStatTimeoutEvent, "UmdTimeout", __UmdStatTimeout);
|
||||
p.Do(umdStatChangeEvent);
|
||||
CoreTiming::RestoreRegisterEvent(umdStatChangeEvent, "UmdChange", __UmdStatChange);
|
||||
p.Do(umdWaitingThreads);
|
||||
p.DoMarker("sceUmd");
|
||||
}
|
||||
|
||||
@@ -83,24 +105,55 @@ u8 __KernelUmdGetState()
|
||||
return state;
|
||||
}
|
||||
|
||||
void __UmdStatChange(u64 userdata, int cyclesLate)
|
||||
{
|
||||
// TODO: Why not a bool anyway?
|
||||
umdActivated = userdata & 0xFF;
|
||||
|
||||
// Wake anyone waiting on this.
|
||||
for (size_t i = 0; i < umdWaitingThreads.size(); ++i)
|
||||
{
|
||||
UmdWaitingThread &info = umdWaitingThreads[i];
|
||||
|
||||
u32 error;
|
||||
SceUID waitID = __KernelGetWaitID(info.threadID, WAITTYPE_UMD, error);
|
||||
bool keep = false;
|
||||
if (waitID == 1)
|
||||
{
|
||||
if ((info.stat & __KernelUmdGetState()) != 0)
|
||||
__KernelResumeThreadFromWait(info.threadID, 0);
|
||||
// Only if they are still waiting do we keep them in the list.
|
||||
else
|
||||
keep = true;
|
||||
}
|
||||
|
||||
if (!keep)
|
||||
umdWaitingThreads.erase(umdWaitingThreads.begin() + i--);
|
||||
}
|
||||
}
|
||||
|
||||
void __KernelUmdActivate()
|
||||
{
|
||||
umdActivated = 1;
|
||||
u32 notifyArg = UMD_PRESENT | UMD_READABLE;
|
||||
__KernelNotifyCallbackType(THREAD_CALLBACK_UMD, -1, notifyArg);
|
||||
|
||||
// Don't activate immediately, take time to "spin up."
|
||||
CoreTiming::RemoveAllEvents(umdStatChangeEvent);
|
||||
CoreTiming::ScheduleEvent(usToCycles(MICRO_DELAY_ACTIVATE), umdStatChangeEvent, 1);
|
||||
}
|
||||
|
||||
void __KernelUmdDeactivate()
|
||||
{
|
||||
umdActivated = 0;
|
||||
u32 notifyArg = UMD_PRESENT | UMD_READY;
|
||||
__KernelNotifyCallbackType(THREAD_CALLBACK_UMD, -1, notifyArg);
|
||||
|
||||
CoreTiming::RemoveAllEvents(umdStatChangeEvent);
|
||||
__UmdStatChange(0, 0);
|
||||
}
|
||||
|
||||
// typedef int (*UmdCallback)(int unknown, int event);
|
||||
|
||||
|
||||
//int sceUmdCheckMedium(int a);
|
||||
int sceUmdCheckMedium()
|
||||
{
|
||||
DEBUG_LOG(HLE,"1=sceUmdCheckMedium(?)");
|
||||
//ignore PARAM(0)
|
||||
DEBUG_LOG(HLE, "1=sceUmdCheckMedium()");
|
||||
return 1; //non-zero: disc in drive
|
||||
}
|
||||
|
||||
@@ -139,9 +192,6 @@ int sceUmdActivate(u32 unknown, const char *name)
|
||||
ERROR_LOG(HLE, "UNTESTED 0=sceUmdActivate(%d, %s)", unknown, name);
|
||||
}
|
||||
|
||||
u32 notifyArg = UMD_PRESENT | UMD_READABLE;
|
||||
__KernelNotifyCallbackType(THREAD_CALLBACK_UMD, -1, notifyArg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -162,9 +212,6 @@ int sceUmdDeactivate(u32 unknown, const char *name)
|
||||
ERROR_LOG(HLE, "UNTESTED 0=sceUmdDeactivate(%d, %s)", unknown, name);
|
||||
}
|
||||
|
||||
u32 notifyArg = UMD_PRESENT | UMD_READY;
|
||||
__KernelNotifyCallbackType(THREAD_CALLBACK_UMD, -1, notifyArg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -189,9 +236,9 @@ u32 sceUmdRegisterUMDCallBack(u32 cbId)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
u32 sceUmdUnRegisterUMDCallBack(u32 cbId)
|
||||
int sceUmdUnRegisterUMDCallBack(int cbId)
|
||||
{
|
||||
u32 retVal;
|
||||
int retVal;
|
||||
|
||||
if (cbId != driveCBId)
|
||||
retVal = PSP_ERROR_UMD_INVALID_PARAM;
|
||||
@@ -223,6 +270,12 @@ void __UmdStatTimeout(u64 userdata, int cyclesLate)
|
||||
// Assuming it's still waiting.
|
||||
if (waitID == 1)
|
||||
__KernelResumeThreadFromWait(threadID, SCE_KERNEL_ERROR_WAIT_TIMEOUT);
|
||||
|
||||
for (size_t i = 0; i < umdWaitingThreads.size(); ++i)
|
||||
{
|
||||
if (umdWaitingThreads[i].threadID == threadID)
|
||||
umdWaitingThreads.erase(umdWaitingThreads.begin() + i--);
|
||||
}
|
||||
}
|
||||
|
||||
void __UmdWaitStat(u32 timeout)
|
||||
@@ -233,7 +286,7 @@ void __UmdWaitStat(u32 timeout)
|
||||
else if (timeout <= 215)
|
||||
timeout = 250;
|
||||
|
||||
CoreTiming::ScheduleEvent(usToCycles((int) timeout), umdStatTimer, __KernelGetCurThread());
|
||||
CoreTiming::ScheduleEvent(usToCycles((int) timeout), umdStatTimeoutEvent, __KernelGetCurThread());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +301,10 @@ int sceUmdWaitDriveStat(u32 stat)
|
||||
DEBUG_LOG(HLE,"0=sceUmdWaitDriveStat(stat = %08x)", stat);
|
||||
|
||||
if ((stat & __KernelUmdGetState()) == 0)
|
||||
{
|
||||
umdWaitingThreads.push_back(UmdWaitingThread::Make(__KernelGetCurThread(), stat));
|
||||
__KernelWaitCurThread(WAITTYPE_UMD, 1, stat, 0, 0, "umd stat waited");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -260,7 +316,8 @@ int sceUmdWaitDriveStatWithTimer(u32 stat, u32 timeout)
|
||||
if ((stat & __KernelUmdGetState()) == 0)
|
||||
{
|
||||
__UmdWaitStat(timeout);
|
||||
__KernelWaitCurThread(WAITTYPE_UMD, 1, stat, 0, 0, "umd stat waited");
|
||||
umdWaitingThreads.push_back(UmdWaitingThread::Make(__KernelGetCurThread(), stat));
|
||||
__KernelWaitCurThread(WAITTYPE_UMD, 1, stat, 0, 0, "umd stat waited with timer");
|
||||
}
|
||||
else
|
||||
hleReSchedule("umd stat waited with timer");
|
||||
@@ -270,14 +327,7 @@ int sceUmdWaitDriveStatWithTimer(u32 stat, u32 timeout)
|
||||
|
||||
int sceUmdWaitDriveStatCB(u32 stat, u32 timeout)
|
||||
{
|
||||
if (driveCBId != -1)
|
||||
{
|
||||
DEBUG_LOG(HLE,"0=sceUmdWaitDriveStatCB(stat = %08x, timeout = %d)", stat, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN_LOG(HLE, "0=sceUmdWaitDriveStatCB(stat = %08x, timeout = %d) without callback", stat, timeout);
|
||||
}
|
||||
DEBUG_LOG(HLE,"0=sceUmdWaitDriveStatCB(stat = %08x, timeout = %d)", stat, timeout);
|
||||
|
||||
hleCheckCurrentCallbacks();
|
||||
if ((stat & __KernelUmdGetState()) == 0)
|
||||
@@ -286,6 +336,7 @@ int sceUmdWaitDriveStatCB(u32 stat, u32 timeout)
|
||||
timeout = 8000;
|
||||
|
||||
__UmdWaitStat(timeout);
|
||||
umdWaitingThreads.push_back(UmdWaitingThread::Make(__KernelGetCurThread(), stat));
|
||||
__KernelWaitCurThread(WAITTYPE_UMD, 1, stat, 0, true, "umd stat waited");
|
||||
}
|
||||
else
|
||||
@@ -322,8 +373,6 @@ u32 sceUmdReplacePermit()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const HLEFunction sceUmdUser[] =
|
||||
{
|
||||
{0xC6183D47,WrapI_UC<sceUmdActivate>,"sceUmdActivate"},
|
||||
@@ -338,7 +387,7 @@ const HLEFunction sceUmdUser[] =
|
||||
{0x20628E6F,&WrapU_V<sceUmdGetErrorStat>,"sceUmdGetErrorStat"},
|
||||
{0x340B7686,WrapU_U<sceUmdGetDiscInfo>,"sceUmdGetDiscInfo"},
|
||||
{0xAEE7404D,&WrapU_U<sceUmdRegisterUMDCallBack>,"sceUmdRegisterUMDCallBack"},
|
||||
{0xBD2BDE07,&WrapU_U<sceUmdUnRegisterUMDCallBack>,"sceUmdUnRegisterUMDCallBack"},
|
||||
{0xBD2BDE07,&WrapI_I<sceUmdUnRegisterUMDCallBack>,"sceUmdUnRegisterUMDCallBack"},
|
||||
{0x87533940,WrapU_V<sceUmdReplaceProhibit>,"sceUmdReplaceProhibit"},
|
||||
{0x87533940,WrapU_V<sceUmdReplacePermit>,"sceUmdReplacePermit"},
|
||||
};
|
||||
|
||||
+43
-10
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "HLE.h"
|
||||
#include "../MIPS/MIPS.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "sceKernel.h"
|
||||
#include "sceKernelThread.h"
|
||||
@@ -29,6 +30,9 @@
|
||||
#include "../Dialog/PSPPlaceholderDialog.h"
|
||||
#include "../Dialog/PSPOskDialog.h"
|
||||
|
||||
const int SCE_ERROR_MODULE_BAD_ID = 0x80111101;
|
||||
const int SCE_ERROR_AV_MODULE_BAD_ID = 0x80110F01;
|
||||
|
||||
PSPSaveDialog saveDialog;
|
||||
PSPMsgDialog msgDialog;
|
||||
PSPOskDialog oskDialog;
|
||||
@@ -90,30 +94,59 @@ int sceUtilitySavedataUpdate(int animSpeed)
|
||||
|
||||
u32 sceUtilityLoadAvModule(u32 module)
|
||||
{
|
||||
if (module > 7)
|
||||
{
|
||||
ERROR_LOG(HLE, "sceUtilityLoadAvModule(%i): invalid module id", module);
|
||||
Reporting::ReportMessage("sceUtilityLoadAvModule(%i): invalid module id", module);
|
||||
return SCE_ERROR_AV_MODULE_BAD_ID;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE,"sceUtilityLoadAvModule(%i)", module);
|
||||
hleReSchedule("utilityloadavmodule");
|
||||
return 0;
|
||||
return hleDelayResult(0, "utility av module loaded", 25000);
|
||||
}
|
||||
|
||||
u32 sceUtilityUnloadAvModule(u32 module)
|
||||
{
|
||||
DEBUG_LOG(HLE,"sceUtilityUnloadAvModule(%i)", module);
|
||||
hleReSchedule("utilityunloadavmodule");
|
||||
return 0;
|
||||
return hleDelayResult(0, "utility av module unloaded", 800);
|
||||
}
|
||||
|
||||
u32 sceUtilityLoadModule(u32 module)
|
||||
{
|
||||
DEBUG_LOG(HLE,"sceUtilityLoadModule(%i)", module);
|
||||
hleReSchedule("utilityloadmodule");
|
||||
return 0;
|
||||
// TODO: Not all modules between 0x100 and 0x601 are valid.
|
||||
if (module < 0x100 || module > 0x601)
|
||||
{
|
||||
ERROR_LOG(HLE, "sceUtilityLoadModule(%i): invalid module id", module);
|
||||
Reporting::ReportMessage("sceUtilityLoadModule(%i): invalid module id", module);
|
||||
return SCE_ERROR_MODULE_BAD_ID;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE, "sceUtilityLoadModule(%i)", module);
|
||||
// TODO: Each module has its own timing, technically, but this is a low-end.
|
||||
// Note: Some modules have dependencies, but they still resched.
|
||||
if (module == 0x3FF)
|
||||
return hleDelayResult(0, "utility module loaded", 130);
|
||||
else
|
||||
return hleDelayResult(0, "utility module loaded", 25000);
|
||||
}
|
||||
|
||||
u32 sceUtilityUnloadModule(u32 module)
|
||||
{
|
||||
DEBUG_LOG(HLE,"sceUtilityUnloadModule(%i)", module);
|
||||
hleReSchedule("utilityunloadmodule");
|
||||
return 0;
|
||||
// TODO: Not all modules between 0x100 and 0x601 are valid.
|
||||
if (module < 0x100 || module > 0x601)
|
||||
{
|
||||
ERROR_LOG(HLE, "sceUtilityUnloadModule(%i): invalid module id", module);
|
||||
Reporting::ReportMessage("sceUtilityUnloadModule(%i): invalid module id", module);
|
||||
return SCE_ERROR_MODULE_BAD_ID;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE, "sceUtilityUnloadModule(%i)", module);
|
||||
// TODO: Each module has its own timing, technically, but this is a low-end.
|
||||
// Note: If not loaded, it should not reschedule actually...
|
||||
if (module == 0x3FF)
|
||||
return hleDelayResult(0, "utility module unloaded", 110);
|
||||
else
|
||||
return hleDelayResult(0, "utility module unloaded", 400);
|
||||
}
|
||||
|
||||
int sceUtilityMsgDialogInitStart(u32 structAddr)
|
||||
|
||||
+32
-5
@@ -313,10 +313,10 @@ void SasInstance::Mix(u32 outAddr) {
|
||||
// We mix into this 32-bit temp buffer and clip in a second loop
|
||||
// Ideally, the shift right should be there too but for now I'm concerned about
|
||||
// not overflowing.
|
||||
mixBuffer[i * 2] += sample * voice.volumeLeft >> 15;
|
||||
mixBuffer[i * 2 + 1] += sample * voice.volumeRight >> 15;
|
||||
sendBuffer[i * 2] += sample * voice.volumeLeftSend >> 15;
|
||||
sendBuffer[i * 2 + 1] += sample * voice.volumeRightSend >> 15;
|
||||
mixBuffer[i * 2] += sample * voice.volumeLeft >> 12;
|
||||
mixBuffer[i * 2 + 1] += sample * voice.volumeRight >> 12;
|
||||
sendBuffer[i * 2] += sample * voice.volumeLeftSend >> 12;
|
||||
sendBuffer[i * 2 + 1] += sample * voice.volumeRightSend >> 12;
|
||||
voice.envelope.Step();
|
||||
}
|
||||
voice.sampleFrac = sampleFrac;
|
||||
@@ -330,7 +330,34 @@ void SasInstance::Mix(u32 outAddr) {
|
||||
}
|
||||
}
|
||||
else if (voice.type == VOICETYPE_PCM && voice.pcmAddr != 0) {
|
||||
// PCM mixing should be easy, can share code with VAG
|
||||
resampleBuffer[0] = voice.resampleHist[0];
|
||||
resampleBuffer[1] = voice.resampleHist[1];
|
||||
u32 numSamples = voice.sampleFrac + grainSize ;
|
||||
if ((int)numSamples > grainSize * 4) {
|
||||
ERROR_LOG(SAS, "numSamples too large, clamping: %i vs %i", numSamples, grainSize * 4);
|
||||
numSamples = grainSize * 4;
|
||||
}
|
||||
resampleBuffer[2 + numSamples] = resampleBuffer[2 + numSamples - 1];
|
||||
voice.resampleHist[0] = resampleBuffer[2 + numSamples - 2];
|
||||
voice.resampleHist[1] = resampleBuffer[2 + numSamples - 1];
|
||||
u32 sampleFrac = voice.sampleFrac;
|
||||
for (int i = 0; i < grainSize; i++) {
|
||||
int sample = resampleBuffer[sampleFrac + 2];
|
||||
int envelopeValue = voice.envelope.GetHeight();
|
||||
envelopeValue = ((envelopeValue >> 15) + 1) >> 1;
|
||||
sample = sample * envelopeValue >> 15;
|
||||
mixBuffer[i * 2] += sample * voice.volumeLeft >> 15;
|
||||
mixBuffer[i * 2 + 1] += sample * voice.volumeRight >> 15;
|
||||
sendBuffer[i * 2] += sample * voice.volumeLeftSend >> 15;
|
||||
sendBuffer[i * 2 + 1] += sample * voice.volumeRightSend >> 15;
|
||||
voice.envelope.Step();
|
||||
}
|
||||
voice.sampleFrac = sampleFrac;
|
||||
voice.sampleFrac -= numSamples ;
|
||||
if (voice.envelope.HasEnded()) {
|
||||
NOTICE_LOG(SAS, "Hit end of envelope");
|
||||
voice.playing = false;
|
||||
}
|
||||
}
|
||||
else if (voice.type == VOICETYPE_NOISE && voice.noiseFreq != 0) {
|
||||
// Generate noise?
|
||||
|
||||
+1
-4
@@ -21,7 +21,6 @@
|
||||
#include <string>
|
||||
#include "../Globals.h"
|
||||
|
||||
|
||||
class PMixer
|
||||
{
|
||||
public:
|
||||
@@ -30,8 +29,6 @@ public:
|
||||
virtual int Mix(short *stereoout, int numSamples) {memset(stereoout,0,numSamples*2*sizeof(short)); return numSamples;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Host
|
||||
{
|
||||
public:
|
||||
@@ -44,7 +41,7 @@ public:
|
||||
|
||||
virtual void SetDebugMode(bool mode) { }
|
||||
|
||||
virtual void InitGL() = 0;
|
||||
virtual bool InitGL(std::string *error_string) = 0;
|
||||
virtual void BeginFrame() {}
|
||||
virtual void ShutdownGL() = 0;
|
||||
|
||||
|
||||
@@ -117,6 +117,9 @@ void Jit::GenerateFixedCode()
|
||||
MOVI2R(R10, (u32)mips_);
|
||||
MOVI2R(R9, (u32)GetBlockCache()->GetCodePointers());
|
||||
|
||||
MovFromPC(R0);
|
||||
outerLoopPCInR0 = GetCodePtr();
|
||||
MovToPC(R0);
|
||||
outerLoop = GetCodePtr();
|
||||
QuickCallFunction(R0, (void *)&CoreTiming::Advance);
|
||||
FixupBranch skipToRealDispatch = B(); //skip the sync and compare first time
|
||||
@@ -133,6 +136,9 @@ void Jit::GenerateFixedCode()
|
||||
FixupBranch badCoreState = B_CC(CC_NEQ);
|
||||
FixupBranch skipToRealDispatch2 = B(); //skip the sync and compare first time
|
||||
|
||||
dispatcherPCInR0 = GetCodePtr();
|
||||
MovToPC(R0);
|
||||
|
||||
// At this point : flags = EQ. Fine for the next check, no need to jump over it.
|
||||
dispatcher = GetCodePtr();
|
||||
|
||||
@@ -149,17 +155,21 @@ void Jit::GenerateFixedCode()
|
||||
// MOV(R0, R13);
|
||||
// QuickCallFunction(R1, (void *)&ShowPC);
|
||||
|
||||
LDR(R0, R10, offsetof(MIPSState, pc));
|
||||
LDR(R0, CTXREG, offsetof(MIPSState, pc));
|
||||
BIC(R0, R0, Operand2(0xC0, 4)); // &= 0x3FFFFFFF
|
||||
LDR(R0, R11, R0, true, true);
|
||||
LDR(R0, R11, R0);
|
||||
AND(R1, R0, Operand2(0xFC, 4)); // rotation is to the right, in 2-bit increments.
|
||||
BIC(R0, R0, Operand2(0xFC, 4));
|
||||
CMP(R1, Operand2(MIPS_EMUHACK_OPCODE >> 24, 4));
|
||||
SetCC(CC_EQ);
|
||||
// IDEA - we have 26 bits, why not just use offsets from base of code?
|
||||
// Another idea: Shift the bloc number left by two in the op, this would let us do
|
||||
// LDR(R0, R9, R0, true, true); here, replacing the two next instructions.
|
||||
ADD(R0, R9, Operand2(2, ST_LSL, R0));
|
||||
// LDR(R0, R9, R0); here, replacing the next instructions.
|
||||
#ifdef IOS
|
||||
// TODO: Fix me, I'm ugly.
|
||||
MOVI2R(R9, (u32)GetBlockCache()->GetCodePointers());
|
||||
#endif
|
||||
ADD(R0, R9, Operand2(R0, ST_LSL, 2));
|
||||
LDR(R0, R0);
|
||||
B(R0);
|
||||
SetCC(CC_AL);
|
||||
@@ -191,6 +201,7 @@ void Jit::GenerateFixedCode()
|
||||
// INFO_LOG(HLE, "END OF THE DISASM ========================");
|
||||
|
||||
// Don't forget to zap the instruction cache!
|
||||
FlushLitPool();
|
||||
FlushIcache();
|
||||
}
|
||||
|
||||
|
||||
+361
-77
@@ -16,6 +16,7 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include "ArmJit.h"
|
||||
#include "Common/CPUDetect.h"
|
||||
|
||||
using namespace MIPSAnalyst;
|
||||
#define _RS ((op>>21) & 0x1F)
|
||||
@@ -28,13 +29,20 @@ using namespace MIPSAnalyst;
|
||||
#define _POS ((op>>6 ) & 0x1F)
|
||||
#define _SIZE ((op>>11 ) & 0x1F)
|
||||
|
||||
#define DISABLE Comp_Generic(op); return;
|
||||
// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
|
||||
// Currently known non working ones should have DISABLE.
|
||||
|
||||
//#define CONDITIONAL_DISABLE { Comp_Generic(op); return; }
|
||||
#define CONDITIONAL_DISABLE ;
|
||||
#define DISABLE { Comp_Generic(op); return; }
|
||||
|
||||
namespace MIPSComp
|
||||
{
|
||||
static u32 EvalOr(u32 a, u32 b) { return a | b; }
|
||||
static u32 EvalXor(u32 a, u32 b) { return a ^ b; }
|
||||
static u32 EvalEor(u32 a, u32 b) { return a ^ b; }
|
||||
static u32 EvalAnd(u32 a, u32 b) { return a & b; }
|
||||
static u32 EvalAdd(u32 a, u32 b) { return a + b; }
|
||||
static u32 EvalSub(u32 a, u32 b) { return a - b; }
|
||||
|
||||
void Jit::CompImmLogic(int rs, int rt, u32 uimm, void (ARMXEmitter::*arith)(ARMReg dst, ARMReg src, Operand2 op2), u32 (*eval)(u32 a, u32 b))
|
||||
{
|
||||
@@ -55,6 +63,7 @@ namespace MIPSComp
|
||||
|
||||
void Jit::Comp_IType(u32 op)
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
s32 simm = (s32)(s16)(op & 0xFFFF); // sign extension
|
||||
u32 uimm = op & 0xFFFF;
|
||||
u32 suimm = (u32)(s32)simm;
|
||||
@@ -62,6 +71,10 @@ namespace MIPSComp
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
|
||||
// noop, won't write to ZERO.
|
||||
if (rt == 0)
|
||||
return;
|
||||
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 8: // same as addiu?
|
||||
@@ -69,8 +82,6 @@ namespace MIPSComp
|
||||
{
|
||||
if (gpr.IsImm(rs)) {
|
||||
gpr.SetImm(rt, gpr.GetImm(rs) + simm);
|
||||
} else if (rs == 0) { // add to zero register = immediate
|
||||
gpr.SetImm(rt, (u32)simm);
|
||||
} else {
|
||||
gpr.MapDirtyIn(rt, rs);
|
||||
Operand2 op2;
|
||||
@@ -90,7 +101,7 @@ namespace MIPSComp
|
||||
|
||||
case 12: CompImmLogic(rs, rt, uimm, &ARMXEmitter::AND, &EvalAnd); break;
|
||||
case 13: CompImmLogic(rs, rt, uimm, &ARMXEmitter::ORR, &EvalOr); break;
|
||||
case 14: CompImmLogic(rs, rt, uimm, &ARMXEmitter::EOR, &EvalXor); break;
|
||||
case 14: CompImmLogic(rs, rt, uimm, &ARMXEmitter::EOR, &EvalEor); break;
|
||||
|
||||
case 10: // R(rt) = (s32)R(rs) < simm; break; //slti
|
||||
{
|
||||
@@ -148,56 +159,154 @@ namespace MIPSComp
|
||||
|
||||
void Jit::Comp_RType2(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
int rs = _RS;
|
||||
int rd = _RD;
|
||||
|
||||
// Don't change $zr.
|
||||
if (rd == 0)
|
||||
return;
|
||||
|
||||
switch (op & 63)
|
||||
{
|
||||
case 22: //clz
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
CLZ(gpr.R(rd), gpr.R(rs));
|
||||
break;
|
||||
case 23: //clo
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
MVN(R0, gpr.R(rs));
|
||||
CLZ(gpr.R(rd), R0);
|
||||
break;
|
||||
default:
|
||||
DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::CompType3(int rd, int rs, int rt, void (ARMXEmitter::*arith)(ARMReg dst, ARMReg rm, Operand2 rn), u32 (*eval)(u32 a, u32 b), bool isSub)
|
||||
{
|
||||
if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
|
||||
gpr.SetImm(rd, (*eval)(gpr.GetImm(rs), gpr.GetImm(rt)));
|
||||
} else if (gpr.IsImm(rt)) {
|
||||
u32 rtImm = gpr.GetImm(rt);
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
Operand2 op2;
|
||||
if (TryMakeOperand2(rtImm, op2)) {
|
||||
(this->*arith)(gpr.R(rd), gpr.R(rs), op2);
|
||||
} else {
|
||||
MOVI2R(R0, rtImm);
|
||||
(this->*arith)(gpr.R(rd), gpr.R(rs), R0);
|
||||
}
|
||||
} else if (gpr.IsImm(rs)) {
|
||||
u32 rsImm = gpr.GetImm(rs);
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
// TODO: Special case when rsImm can be represented as an Operand2
|
||||
MOVI2R(R0, rsImm);
|
||||
(this->*arith)(gpr.R(rd), R0, gpr.R(rt));
|
||||
} else {
|
||||
// Generic solution
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
(this->*arith)(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_RType3(u32 op)
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
int rd = _RD;
|
||||
|
||||
// noop, won't write to ZERO.
|
||||
if (rd == 0)
|
||||
return;
|
||||
|
||||
switch (op & 63)
|
||||
{
|
||||
//case 10: if (!R(rt)) R(rd) = R(rs); break; //movz
|
||||
//case 11: if (R(rt)) R(rd) = R(rs); break; //movn
|
||||
case 10: //if (!R(rt)) R(rd) = R(rs); break; //movz
|
||||
if (rd == rs)
|
||||
break;
|
||||
if (!gpr.IsImm(rt))
|
||||
{
|
||||
gpr.MapDirtyInIn(rd, rt, rs, false);
|
||||
CMP(gpr.R(rt), Operand2(0));
|
||||
SetCC(CC_EQ);
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rs)));
|
||||
SetCC(CC_AL);
|
||||
}
|
||||
else if (gpr.GetImm(rt) == 0)
|
||||
{
|
||||
// Yes, this actually happens.
|
||||
if (gpr.IsImm(rs))
|
||||
gpr.SetImm(rd, gpr.GetImm(rs));
|
||||
else
|
||||
{
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rs)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 11:// if (R(rt)) R(rd) = R(rs); break; //movn
|
||||
if (rd == rs)
|
||||
break;
|
||||
if (!gpr.IsImm(rt))
|
||||
{
|
||||
gpr.MapDirtyInIn(rd, rt, rs, false);
|
||||
CMP(gpr.R(rt), Operand2(0));
|
||||
SetCC(CC_NEQ);
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rs)));
|
||||
SetCC(CC_AL);
|
||||
}
|
||||
else if (gpr.GetImm(rt) != 0)
|
||||
{
|
||||
// Yes, this actually happens.
|
||||
if (gpr.IsImm(rs))
|
||||
gpr.SetImm(rd, gpr.GetImm(rs));
|
||||
else
|
||||
{
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rs)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// case 32: //R(rd) = R(rs) + R(rt); break; //add
|
||||
case 33: //R(rd) = R(rs) + R(rt); break; //addu
|
||||
case 32: //R(rd) = R(rs) + R(rt); break; //add
|
||||
case 33: //R(rd) = R(rs) + R(rt); break; //addu
|
||||
// Some optimized special cases
|
||||
if (rs == 0) {
|
||||
if (gpr.IsImm(rs) && gpr.GetImm(rs) == 0) {
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
MOV(gpr.R(rd), gpr.R(rt));
|
||||
} else if (rt == 0) {
|
||||
} else if (gpr.IsImm(rt) && gpr.GetImm(rt) == 0) {
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
MOV(gpr.R(rd), gpr.R(rs));
|
||||
} else {
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
ADD(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
CompType3(rd, rs, rt, &ARMXEmitter::ADD, &EvalAdd);
|
||||
}
|
||||
break;
|
||||
case 34: //R(rd) = R(rs) - R(rt); break; //sub
|
||||
case 35:
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
SUB(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
|
||||
case 34: //R(rd) = R(rs) - R(rt); break; //sub
|
||||
case 35: //R(rd) = R(rs) - R(rt); break; //subu
|
||||
CompType3(rd, rs, rt, &ARMXEmitter::SUB, &EvalSub, true);
|
||||
break;
|
||||
case 36: //R(rd) = R(rs) & R(rt); break; //and
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
AND(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
case 36: //R(rd) = R(rs) & R(rt); break; //and
|
||||
CompType3(rd, rs, rt, &ARMXEmitter::AND, &EvalAnd);
|
||||
break;
|
||||
case 37: //R(rd) = R(rs) | R(rt); break; //or
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
ORR(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
case 37: //R(rd) = R(rs) | R(rt); break; //or
|
||||
CompType3(rd, rs, rt, &ARMXEmitter::ORR, &EvalOr);
|
||||
break;
|
||||
case 38: //R(rd) = R(rs) ^ R(rt); break; //xor/eor
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
EOR(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
case 38: //R(rd) = R(rs) ^ R(rt); break; //xor/eor
|
||||
CompType3(rd, rs, rt, &ARMXEmitter::EOR, &EvalEor);
|
||||
break;
|
||||
|
||||
case 39: // R(rd) = ~(R(rs) | R(rt)); //nor
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
ORR(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
MVN(gpr.R(rd), gpr.R(rd));
|
||||
case 39: // R(rd) = ~(R(rs) | R(rt)); break; //nor
|
||||
if (gpr.IsImm(rt) && gpr.GetImm(rt) == 0) {
|
||||
gpr.MapDirtyIn(rd, rs);
|
||||
MVN(gpr.R(rd), gpr.R(rs));
|
||||
} else {
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
ORR(gpr.R(rd), gpr.R(rs), gpr.R(rt));
|
||||
MVN(gpr.R(rd), gpr.R(rd));
|
||||
}
|
||||
break;
|
||||
|
||||
case 42: //R(rd) = (int)R(rs) < (int)R(rt); break; //slt
|
||||
@@ -210,7 +319,7 @@ namespace MIPSComp
|
||||
SetCC(CC_AL);
|
||||
break;
|
||||
|
||||
case 43: //R(rd) = R(rs) < R(rt); break; //sltu
|
||||
case 43: //R(rd) = R(rs) < R(rt); break; //sltu
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
CMP(gpr.R(rs), gpr.R(rt));
|
||||
SetCC(CC_LO);
|
||||
@@ -220,14 +329,27 @@ namespace MIPSComp
|
||||
SetCC(CC_AL);
|
||||
break;
|
||||
|
||||
// case 44: R(rd) = (R(rs) > R(rt)) ? R(rs) : R(rt); break; //max
|
||||
// CMP(a,b); CMOVLT(a,b)
|
||||
case 44: //R(rd) = max(R(rs), R(rt); break; //max
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
CMP(gpr.R(rs), gpr.R(rt));
|
||||
SetCC(CC_GT);
|
||||
MOV(gpr.R(rd), gpr.R(rs));
|
||||
SetCC(CC_LE);
|
||||
MOV(gpr.R(rd), gpr.R(rt));
|
||||
SetCC(CC_AL);
|
||||
break;
|
||||
|
||||
// case 45: R(rd) = (R(rs) < R(rt)) ? R(rs) : R(rt); break; //min
|
||||
// CMP(a,b); CMOVGT(a,b)
|
||||
case 45: //R(rd) = min(R(rs), R(rt)); break; //min
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
CMP(gpr.R(rs), gpr.R(rt));
|
||||
SetCC(CC_LT);
|
||||
MOV(gpr.R(rd), gpr.R(rs));
|
||||
SetCC(CC_GE);
|
||||
MOV(gpr.R(rd), gpr.R(rt));
|
||||
SetCC(CC_AL);
|
||||
break;
|
||||
|
||||
default:
|
||||
// gpr.UnlockAll();
|
||||
Comp_Generic(op);
|
||||
break;
|
||||
}
|
||||
@@ -240,81 +362,182 @@ namespace MIPSComp
|
||||
int sa = _SA;
|
||||
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
MOV(gpr.R(rd), Operand2(sa, shiftType, gpr.R(rt)));
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rt), shiftType, sa));
|
||||
}
|
||||
|
||||
// "over-shifts" work the same as on x86 - only bottom 5 bits are used to get the shift value
|
||||
/*
|
||||
void Jit::CompShiftVar(u32 op, void (XEmitter::*shift)(int, OpArg, OpArg))
|
||||
void Jit::CompShiftVar(u32 op, ArmGen::ShiftType shiftType)
|
||||
{
|
||||
int rd = _RD;
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
gpr.FlushLockX(ECX);
|
||||
gpr.Lock(rd, rt, rs);
|
||||
gpr.BindToRegister(rd, true, true);
|
||||
if (rd != rt)
|
||||
MOV(32, gpr.R(rd), gpr.R(rt));
|
||||
MOV(32, R(ECX), gpr.R(rs)); // Only ECX can be used for variable shifts.
|
||||
AND(32, R(ECX), Imm32(0x1f));
|
||||
(this->*shift)(32, gpr.R(rd), R(ECX));
|
||||
gpr.UnlockAll();
|
||||
gpr.UnlockAllX();
|
||||
if (gpr.IsImm(rs))
|
||||
{
|
||||
int sa = gpr.GetImm(rs) & 0x1F;
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rt), shiftType, sa));
|
||||
return;
|
||||
}
|
||||
gpr.MapDirtyInIn(rd, rs, rt);
|
||||
AND(R0, gpr.R(rs), Operand2(0x1F));
|
||||
MOV(gpr.R(rd), Operand2(gpr.R(rt), shiftType, R0));
|
||||
}
|
||||
*/
|
||||
|
||||
void Jit::Comp_ShiftType(u32 op)
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
int rs = _RS;
|
||||
int rd = _RD;
|
||||
int fd = _FD;
|
||||
// WARNIGN : ROTR
|
||||
|
||||
// noop, won't write to ZERO.
|
||||
if (rd == 0)
|
||||
return;
|
||||
|
||||
// WARNING : ROTR
|
||||
switch (op & 0x3f)
|
||||
{
|
||||
case 0: CompShiftImm(op, ST_LSL); break;
|
||||
case 2: CompShiftImm(op, rs == 1 ? ST_ROR : ST_LSR); break; // srl
|
||||
case 3: CompShiftImm(op, ST_ASR); break; // sra
|
||||
|
||||
// case 4: CompShiftVar(op, &XEmitter::SHL); break; // R(rd) = R(rt) << R(rs); break; //sllv
|
||||
// case 6: CompShiftVar(op, fd == 1 ? &XEmitter::ROR : &XEmitter::SHR); break; // R(rd) = R(rt) >> R(rs); break; //srlv
|
||||
// case 7: CompShiftVar(op, &XEmitter::SAR); break; // R(rd) = ((s32)R(rt)) >> R(rs); break; //srav
|
||||
case 0: CompShiftImm(op, ST_LSL); break; //sll
|
||||
case 2: CompShiftImm(op, rs == 1 ? ST_ROR : ST_LSR); break; //srl
|
||||
case 3: CompShiftImm(op, ST_ASR); break; //sra
|
||||
case 4: CompShiftVar(op, ST_LSL); break; //sllv
|
||||
case 6: CompShiftVar(op, fd == 1 ? ST_ROR : ST_LSR); break; //srlv
|
||||
case 7: CompShiftVar(op, ST_ASR); break; //srav
|
||||
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
//_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_Special3(u32 op)
|
||||
{
|
||||
// ext, ins
|
||||
DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
bool useUBFXandBFI = false;
|
||||
|
||||
if (!cpu_info.bArmV7) {
|
||||
// useUBFXandBFI = true;
|
||||
}
|
||||
|
||||
int rs = _RS;
|
||||
int rt = _RT;
|
||||
|
||||
int pos = _POS;
|
||||
int size = _SIZE + 1;
|
||||
u32 mask = 0xFFFFFFFFUL >> (32 - size);
|
||||
|
||||
// Don't change $zr.
|
||||
if (rt == 0)
|
||||
return;
|
||||
|
||||
switch (op & 0x3f)
|
||||
{
|
||||
case 0x0: //ext
|
||||
if (gpr.IsImm(rs))
|
||||
{
|
||||
gpr.SetImm(rt, (gpr.GetImm(rs) >> pos) & mask);
|
||||
return;
|
||||
}
|
||||
|
||||
// Reported to break Disgaea.
|
||||
DISABLE;
|
||||
|
||||
gpr.MapDirtyIn(rt, rs);
|
||||
if (useUBFXandBFI) {
|
||||
UBFX(gpr.R(rt), gpr.R(rs), pos, size);
|
||||
} else {
|
||||
MOV(gpr.R(rt), Operand2(gpr.R(rs), ST_LSR, pos));
|
||||
ANDI2R(gpr.R(rt), gpr.R(rt), mask, R0);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x4: //ins
|
||||
{
|
||||
u32 sourcemask = mask >> pos;
|
||||
u32 destmask = ~(sourcemask << pos);
|
||||
if (gpr.IsImm(rs))
|
||||
{
|
||||
u32 inserted = (gpr.GetImm(rs) & sourcemask) << pos;
|
||||
if (gpr.IsImm(rt))
|
||||
{
|
||||
gpr.SetImm(rt, (gpr.GetImm(rt) & destmask) | inserted);
|
||||
return;
|
||||
}
|
||||
|
||||
gpr.MapReg(rt, MAP_DIRTY);
|
||||
ANDI2R(gpr.R(rt), gpr.R(rt), destmask, R0);
|
||||
ORI2R(gpr.R(rt), gpr.R(rt), inserted, R0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (useUBFXandBFI) {
|
||||
gpr.MapDirtyIn(rt, rs, false);
|
||||
BFI(gpr.R(rt), gpr.R(rs), pos, size);
|
||||
} else {
|
||||
gpr.MapDirtyIn(rt, rs, false);
|
||||
ANDI2R(R0, gpr.R(rs), sourcemask, R1);
|
||||
MOV(R0, Operand2(R0, ST_LSL, pos));
|
||||
ANDI2R(gpr.R(rt), gpr.R(rt), destmask, R1);
|
||||
ORR(gpr.R(rt), gpr.R(rt), R0);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_Allegrex(u32 op)
|
||||
{
|
||||
DISABLE
|
||||
CONDITIONAL_DISABLE;
|
||||
int rt = _RT;
|
||||
int rd = _RD;
|
||||
// Don't change $zr.
|
||||
if (rd == 0)
|
||||
return;
|
||||
|
||||
switch ((op >> 6) & 31)
|
||||
{
|
||||
case 16: // seb // R(rd) = (u32)(s32)(s8)(u8)R(rt);
|
||||
/*
|
||||
gpr.Lock(rd, rt);
|
||||
gpr.BindToRegister(rd, true, true);
|
||||
MOV(32, R(EAX), gpr.R(rt)); // work around the byte-register addressing problem
|
||||
MOVSX(32, 8, gpr.RX(rd), R(EAX));
|
||||
gpr.UnlockAll();*/
|
||||
if (gpr.IsImm(rt))
|
||||
{
|
||||
gpr.SetImm(rd, (s32)(s8)(u8)gpr.GetImm(rt));
|
||||
return;
|
||||
}
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
SXTB(gpr.R(rd), gpr.R(rt));
|
||||
break;
|
||||
|
||||
case 24: // seh
|
||||
/*
|
||||
gpr.Lock(rd, rt);
|
||||
gpr.BindToRegister(rd, true, true);
|
||||
MOVSX(32, 16, gpr.RX(rd), gpr.R(rt));
|
||||
gpr.UnlockAll();*/
|
||||
if (gpr.IsImm(rt))
|
||||
{
|
||||
gpr.SetImm(rd, (s32)(s16)(u16)gpr.GetImm(rt));
|
||||
return;
|
||||
}
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
SXTH(gpr.R(rd), gpr.R(rt));
|
||||
break;
|
||||
|
||||
|
||||
case 20: //bitrev
|
||||
if (gpr.IsImm(rt))
|
||||
{
|
||||
// http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
|
||||
u32 v = gpr.GetImm(rt);
|
||||
v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1); // odd<->even
|
||||
v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2); // pair<->pair
|
||||
v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4); // nibb<->nibb
|
||||
v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8); // byte<->byte
|
||||
v = ( v >> 16 ) | ( v << 16); // hword<->hword
|
||||
gpr.SetImm(rd, v);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cpu_info.bArmV7) {
|
||||
gpr.MapDirtyIn(rd, rt);
|
||||
RBIT(gpr.R(rd), gpr.R(rt));
|
||||
} else {
|
||||
Comp_Generic(op);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
@@ -323,7 +546,7 @@ namespace MIPSComp
|
||||
|
||||
void Jit::Comp_MulDivType(u32 op)
|
||||
{
|
||||
// DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
int rd = _RD;
|
||||
@@ -358,6 +581,67 @@ namespace MIPSComp
|
||||
case 25: //multu (2nd) lo,hi = unsigned mul (rs * rt)
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt);
|
||||
UMULL(gpr.R(MIPSREG_LO), gpr.R(MIPSREG_HI), gpr.R(rs), gpr.R(rt));
|
||||
break;
|
||||
|
||||
case 26: //div
|
||||
DISABLE;
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt);
|
||||
if (cpu_info.bIDIVa)
|
||||
{
|
||||
SDIV(gpr.R(MIPSREG_LO), gpr.R(rs), gpr.R(rt));
|
||||
MUL(R0, gpr.R(rt), gpr.R(MIPSREG_LO));
|
||||
SUB(gpr.R(MIPSREG_HI), gpr.R(rs), Operand2(R0));
|
||||
} else {
|
||||
VMOV(S0, gpr.R(rs));
|
||||
VMOV(S1, gpr.R(rt));
|
||||
VCVT(D0, S0, TO_FLOAT | IS_SIGNED);
|
||||
VCVT(D1, S1, TO_FLOAT | IS_SIGNED);
|
||||
VDIV(D0, D0, D1);
|
||||
VCVT(gpr.R(MIPSREG_LO), D0, TO_INT | IS_SIGNED);
|
||||
MUL(R0, gpr.R(rt), gpr.R(MIPSREG_LO));
|
||||
SUB(gpr.R(MIPSREG_HI), gpr.R(rs), Operand2(R0));
|
||||
}
|
||||
break;
|
||||
|
||||
case 27: //divu
|
||||
DISABLE;
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt);
|
||||
if (cpu_info.bIDIVa)
|
||||
{
|
||||
UDIV(gpr.R(MIPSREG_LO), gpr.R(rs), gpr.R(rt));
|
||||
MUL(R0, gpr.R(rt), gpr.R(MIPSREG_LO));
|
||||
SUB(gpr.R(MIPSREG_HI), gpr.R(rs), Operand2(R0));
|
||||
} else {
|
||||
VMOV(S0, gpr.R(rs));
|
||||
VMOV(S1, gpr.R(rt));
|
||||
VCVT(D0, S0, TO_FLOAT);
|
||||
VCVT(D1, S1, TO_FLOAT);
|
||||
VDIV(D0, D0, D1);
|
||||
VCVT(gpr.R(MIPSREG_LO), D0, TO_INT);
|
||||
MUL(R0, gpr.R(rt), gpr.R(MIPSREG_LO));
|
||||
SUB(gpr.R(MIPSREG_HI), gpr.R(rs), Operand2(R0));
|
||||
}
|
||||
break;
|
||||
|
||||
case 28: //madd
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt, false);
|
||||
SMLAL(gpr.R(MIPSREG_LO), gpr.R(MIPSREG_HI), gpr.R(rs), gpr.R(rt));
|
||||
break;
|
||||
|
||||
case 29: //maddu
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt, false);
|
||||
UMLAL(gpr.R(MIPSREG_LO), gpr.R(MIPSREG_HI), gpr.R(rs), gpr.R(rt));
|
||||
break;
|
||||
|
||||
case 46: // msub
|
||||
DISABLE;
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt, false);
|
||||
break;
|
||||
|
||||
case 47: // msubu
|
||||
DISABLE;
|
||||
gpr.MapDirtyDirtyInIn(MIPSREG_LO, MIPSREG_HI, rs, rt, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
DISABLE;
|
||||
|
||||
@@ -63,51 +63,46 @@ void Jit::BranchRSRTComp(u32 op, ArmGen::CCFlags cc, bool likely)
|
||||
if (!likely && delaySlotIsNice)
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
|
||||
// The delay slot being nice doesn't really matter though...
|
||||
|
||||
if (rt == 0)
|
||||
{
|
||||
if (gpr.IsImm(rt) && gpr.GetImm(rt) == 0)
|
||||
{
|
||||
gpr.MapReg(rs);
|
||||
CMP(gpr.R(rs), Operand2(0, TYPE_IMM));
|
||||
}
|
||||
else if (rs == 0 && (cc == CC_EQ || cc == CC_NEQ)) // only these are easily 'flippable'
|
||||
}
|
||||
else if (gpr.IsImm(rs) && gpr.GetImm(rs) == 0 && (cc == CC_EQ || cc == CC_NEQ)) // only these are easily 'flippable'
|
||||
{
|
||||
gpr.MapReg(rt);
|
||||
CMP(gpr.R(rt), Operand2(0, TYPE_IMM));
|
||||
}
|
||||
else
|
||||
{
|
||||
gpr.SpillLock(rs, rt);
|
||||
gpr.MapReg(rs);
|
||||
gpr.MapReg(rt);
|
||||
gpr.ReleaseSpillLocks();
|
||||
gpr.MapInIn(rs, rt);
|
||||
CMP(gpr.R(rs), gpr.R(rt));
|
||||
}
|
||||
}
|
||||
|
||||
ArmGen::FixupBranch ptr;
|
||||
if (!likely)
|
||||
{
|
||||
ArmGen::FixupBranch ptr;
|
||||
if (!likely)
|
||||
{
|
||||
if (!delaySlotIsNice)
|
||||
CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
|
||||
else
|
||||
FlushAll();
|
||||
ptr = B_CC(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = B_CC(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
FlushAll();
|
||||
ptr = B_CC(cc);
|
||||
CompileDelaySlot(DELAYSLOT_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
// Take the branch
|
||||
WriteExit(targetAddr, 0);
|
||||
// Take the branch
|
||||
WriteExit(targetAddr, 0);
|
||||
|
||||
SetJumpTarget(ptr);
|
||||
// Not taken
|
||||
WriteExit(js.compilerPC+8, 1);
|
||||
SetJumpTarget(ptr);
|
||||
// Not taken
|
||||
WriteExit(js.compilerPC+8, 1);
|
||||
|
||||
js.compiling = false;
|
||||
js.compiling = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,30 +123,29 @@ void Jit::BranchRSZeroComp(u32 op, ArmGen::CCFlags cc, bool andLink, bool likely
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
|
||||
gpr.MapReg(rs);
|
||||
CMP(gpr.R(rs), Operand2(0, TYPE_IMM));
|
||||
CMP(gpr.R(rs), Operand2(0, TYPE_IMM));
|
||||
|
||||
ArmGen::FixupBranch ptr;
|
||||
if (!likely)
|
||||
{
|
||||
{
|
||||
if (!delaySlotIsNice)
|
||||
CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
|
||||
else
|
||||
FlushAll();
|
||||
ptr = B_CC(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
FlushAll();
|
||||
ptr = B_CC(cc);
|
||||
CompileDelaySlot(DELAYSLOT_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
// Take the branch
|
||||
if (andLink)
|
||||
{
|
||||
ADD(R1, R10, MIPS_REG_RA * 4); // compute address of RA in ram
|
||||
MOVI2R(R0, js.compilerPC + 8);
|
||||
STR(R1, R0);
|
||||
STR(R0, CTXREG, MIPS_REG_RA * 4);
|
||||
}
|
||||
|
||||
WriteExit(targetAddr, 0);
|
||||
@@ -213,10 +207,10 @@ void Jit::BranchFPFlag(u32 op, ArmGen::CCFlags cc, bool likely)
|
||||
ERROR_LOG(JIT, "Branch in delay slot at %08x", js.compilerPC);
|
||||
return;
|
||||
}
|
||||
int offset = (signed short)(op & 0xFFFF) << 2;
|
||||
u32 targetAddr = js.compilerPC + offset + 4;
|
||||
int offset = (signed short)(op & 0xFFFF) << 2;
|
||||
u32 targetAddr = js.compilerPC + offset + 4;
|
||||
|
||||
u32 delaySlotOp = Memory::ReadUnchecked_U32(js.compilerPC + 4);
|
||||
u32 delaySlotOp = Memory::ReadUnchecked_U32(js.compilerPC + 4);
|
||||
bool delaySlotIsNice = IsDelaySlotNiceFPU(op, delaySlotOp);
|
||||
CONDITIONAL_NICE_DELAYSLOT;
|
||||
if (!likely && delaySlotIsNice)
|
||||
@@ -224,29 +218,29 @@ void Jit::BranchFPFlag(u32 op, ArmGen::CCFlags cc, bool likely)
|
||||
|
||||
FlushAll();
|
||||
|
||||
LDR(R0, R10, offsetof(MIPSState, fpcond));
|
||||
TST(R0, Operand2(1, TYPE_IMM));
|
||||
LDR(R0, CTXREG, offsetof(MIPSState, fpcond));
|
||||
TST(R0, Operand2(1, TYPE_IMM));
|
||||
|
||||
ArmGen::FixupBranch ptr;
|
||||
if (!likely)
|
||||
{
|
||||
ArmGen::FixupBranch ptr;
|
||||
if (!likely)
|
||||
{
|
||||
if (!delaySlotIsNice)
|
||||
CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
|
||||
ptr = B_CC(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = B_CC(cc);
|
||||
ptr = B_CC(cc);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = B_CC(cc);
|
||||
CompileDelaySlot(DELAYSLOT_FLUSH);
|
||||
}
|
||||
}
|
||||
|
||||
// Take the branch
|
||||
WriteExit(targetAddr, 0);
|
||||
// Take the branch
|
||||
WriteExit(targetAddr, 0);
|
||||
|
||||
SetJumpTarget(ptr);
|
||||
// Not taken
|
||||
WriteExit(js.compilerPC + 8, 1);
|
||||
js.compiling = false;
|
||||
SetJumpTarget(ptr);
|
||||
// Not taken
|
||||
WriteExit(js.compilerPC + 8, 1);
|
||||
js.compiling = false;
|
||||
}
|
||||
|
||||
void Jit::Comp_FPUBranch(u32 op)
|
||||
@@ -311,8 +305,8 @@ void Jit::BranchVFPUFlag(u32 op, ArmGen::CCFlags cc, bool likely)
|
||||
|
||||
void Jit::Comp_VBranch(u32 op)
|
||||
{
|
||||
switch ((op >> 16) & 3)
|
||||
{
|
||||
switch ((op >> 16) & 3)
|
||||
{
|
||||
case 0: BranchVFPUFlag(op, CC_NEQ, false); break; // bvf
|
||||
case 1: BranchVFPUFlag(op, CC_EQ, false); break; // bvt
|
||||
case 2: BranchVFPUFlag(op, CC_NEQ, true); break; // bvfl
|
||||
@@ -321,10 +315,6 @@ void Jit::Comp_VBranch(u32 op)
|
||||
js.compiling = false;
|
||||
}
|
||||
|
||||
void PrintAtExit() {
|
||||
INFO_LOG(HLE, "at jump");
|
||||
}
|
||||
|
||||
void Jit::Comp_Jump(u32 op)
|
||||
{
|
||||
if (js.inDelaySlot) {
|
||||
@@ -333,19 +323,20 @@ void Jit::Comp_Jump(u32 op)
|
||||
}
|
||||
u32 off = ((op & 0x03FFFFFF) << 2);
|
||||
u32 targetAddr = (js.compilerPC & 0xF0000000) | off;
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
FlushAll();
|
||||
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 2: //j
|
||||
WriteExit(targetAddr, 0);
|
||||
break;
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
FlushAll();
|
||||
WriteExit(targetAddr, 0);
|
||||
break;
|
||||
|
||||
case 3: //jal
|
||||
ADD(R1, R10, MIPS_REG_RA * 4); // compute address of RA in ram
|
||||
MOVI2R(R0, js.compilerPC + 8);
|
||||
STR(R1, R0);
|
||||
gpr.MapReg(MIPS_REG_RA, MAP_NOINIT | MAP_DIRTY);
|
||||
MOVI2R(gpr.R(MIPS_REG_RA), js.compilerPC + 8);
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
FlushAll();
|
||||
WriteExit(targetAddr, 0);
|
||||
break;
|
||||
|
||||
@@ -392,16 +383,15 @@ void Jit::Comp_JumpReg(u32 op)
|
||||
case 8: //jr
|
||||
break;
|
||||
case 9: //jalr
|
||||
ADD(R1, R10, MIPS_REG_RA * 4); // compute address of RA in ram
|
||||
MOVI2R(R0, js.compilerPC + 8);
|
||||
STR(R1, R0);
|
||||
STR(R0, CTXREG, MIPS_REG_RA * 4);
|
||||
break;
|
||||
default:
|
||||
_dbg_assert_msg_(CPU,0,"Trying to compile instruction that can't be compiled");
|
||||
break;
|
||||
}
|
||||
|
||||
WriteExitDestInR(R8);
|
||||
WriteExitDestInR(R8);
|
||||
js.compiling = false;
|
||||
}
|
||||
|
||||
|
||||
+229
-126
@@ -19,95 +19,85 @@
|
||||
#include "ArmJit.h"
|
||||
#include "ArmRegCache.h"
|
||||
|
||||
#define _RS ((op>>21) & 0x1F)
|
||||
#define _RT ((op>>16) & 0x1F)
|
||||
#define _RD ((op>>11) & 0x1F)
|
||||
#define _FS ((op>>11) & 0x1F)
|
||||
#define _FT ((op>>16) & 0x1F)
|
||||
#define _FD ((op>>6 ) & 0x1F)
|
||||
#define _POS ((op>>6 ) & 0x1F)
|
||||
#define _SIZE ((op>>11 ) & 0x1F)
|
||||
#define _RS ((op>>21) & 0x1F)
|
||||
#define _RT ((op>>16) & 0x1F)
|
||||
#define _RD ((op>>11) & 0x1F)
|
||||
#define _FS ((op>>11) & 0x1F)
|
||||
#define _FT ((op>>16) & 0x1F)
|
||||
#define _FD ((op>>6 ) & 0x1F)
|
||||
#define _POS ((op>>6 ) & 0x1F)
|
||||
#define _SIZE ((op>>11) & 0x1F)
|
||||
|
||||
// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
|
||||
// Currently known non working ones should have DISABLE.
|
||||
|
||||
//#define CONDITIONAL_DISABLE { Comp_Generic(op); return; }
|
||||
#define CONDITIONAL_DISABLE ;
|
||||
#define DISABLE Comp_Generic(op); return;
|
||||
#define DISABLE { Comp_Generic(op); return; }
|
||||
|
||||
namespace MIPSComp
|
||||
{
|
||||
/*
|
||||
void Jit::CompFPTriArith(u32 op, void (XEmitter::*arith)(X64Reg reg, OpArg), bool orderMatters)
|
||||
{
|
||||
int ft = _FT;
|
||||
int fs = _FS;
|
||||
int fd = _FD;
|
||||
fpr.Lock(ft, fs, fd);
|
||||
|
||||
if (false && fs == fd)
|
||||
{
|
||||
fpr.BindToRegister(fd, true, true);
|
||||
(this->*arith)(fpr.RX(fd), fpr.R(ft));
|
||||
}
|
||||
else
|
||||
{
|
||||
MOVSS(XMM0, fpr.R(fs));
|
||||
MOVSS(XMM1, fpr.R(ft));
|
||||
fpr.BindToRegister(fd, true, true);
|
||||
(this->*arith)(XMM0, R(XMM1));
|
||||
MOVSS(fpr.RX(fd), R(XMM0));
|
||||
}
|
||||
fpr.UnlockAll();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
void Jit::Comp_FPU3op(u32 op)
|
||||
{
|
||||
DISABLE
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
int ft = _FT;
|
||||
int fs = _FS;
|
||||
int fd = _FD;
|
||||
|
||||
fpr.MapDirtyInIn(fd, fs, ft);
|
||||
switch (op & 0x3f)
|
||||
{
|
||||
//case 0: CompFPTriArith(op, &XEmitter::ADDSS, false); break; //F(fd) = F(fs) + F(ft); //add
|
||||
//case 1: CompFPTriArith(op, &XEmitter::SUBSS, true); break; //F(fd) = F(fs) - F(ft); //sub
|
||||
//case 2: CompFPTriArith(op, &XEmitter::MULSS, false); break; //F(fd) = F(fs) * F(ft); //mul
|
||||
//case 3: CompFPTriArith(op, &XEmitter::DIVSS, true); break; //F(fd) = F(fs) / F(ft); //div
|
||||
case 0: VADD(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) + F(ft); //add
|
||||
case 1: VSUB(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) - F(ft); //sub
|
||||
case 2: VMUL(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) * F(ft); //mul
|
||||
case 3: VDIV(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) / F(ft); //div
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
DISABLE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
extern int logBlocks;
|
||||
|
||||
void Jit::Comp_FPULS(u32 op)
|
||||
{
|
||||
DISABLE
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
s32 offset = (s16)(op&0xFFFF);
|
||||
int ft = ((op>>16)&0x1f);
|
||||
s32 offset = (s16)(op & 0xFFFF);
|
||||
int ft = _FT;
|
||||
int rs = _RS;
|
||||
// u32 addr = R(rs) + offset;
|
||||
|
||||
// logBlocks = 1;
|
||||
switch(op >> 26)
|
||||
{
|
||||
/*
|
||||
case 49: //FI(ft) = Memory::Read_U32(addr); break; //lwc1
|
||||
gpr.Lock(rs);
|
||||
fpr.Lock(ft);
|
||||
fpr.BindToRegister(ft, false, true);
|
||||
MOV(32, R(EAX), gpr.R(rs));
|
||||
AND(32, R(EAX), Imm32(Memory::MEMVIEW32_MASK));
|
||||
MOVSS(fpr.RX(ft), MDisp(EAX, (u32)Memory::base + offset));
|
||||
gpr.UnlockAll();
|
||||
fpr.UnlockAll();
|
||||
fpr.MapReg(ft, MAP_NOINIT | MAP_DIRTY);
|
||||
if (gpr.IsImm(rs)) {
|
||||
u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
|
||||
MOVI2R(R0, addr + (u32)Memory::base);
|
||||
} else {
|
||||
gpr.MapReg(rs);
|
||||
SetR0ToEffectiveAddress(rs, offset);
|
||||
ADD(R0, R0, R11);
|
||||
}
|
||||
VLDR(fpr.R(ft), R0, 0);
|
||||
break;
|
||||
|
||||
case 57: //Memory::Write_U32(FI(ft), addr); break; //swc1
|
||||
gpr.Lock(rs);
|
||||
fpr.Lock(ft);
|
||||
fpr.BindToRegister(ft, true, false);
|
||||
MOV(32, R(EAX), gpr.R(rs));
|
||||
AND(32, R(EAX), Imm32(Memory::MEMVIEW32_MASK));
|
||||
MOVSS(MDisp(EAX, (u32)Memory::base + offset), fpr.RX(ft));
|
||||
gpr.UnlockAll();
|
||||
fpr.UnlockAll();
|
||||
fpr.MapReg(ft);
|
||||
if (gpr.IsImm(rs)) {
|
||||
u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
|
||||
MOVI2R(R0, addr + (u32)Memory::base);
|
||||
} else {
|
||||
gpr.MapReg(rs);
|
||||
SetR0ToEffectiveAddress(rs, offset);
|
||||
ADD(R0, R0, R11);
|
||||
}
|
||||
VSTR(fpr.R(ft), R0, 0);
|
||||
break;
|
||||
*/
|
||||
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
@@ -115,101 +105,214 @@ void Jit::Comp_FPULS(u32 op)
|
||||
}
|
||||
|
||||
void Jit::Comp_FPUComp(u32 op) {
|
||||
DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
int opc = op & 0xF;
|
||||
if (opc >= 8) opc -= 8; // alias
|
||||
if (opc == 0)//f, sf (signalling false)
|
||||
{
|
||||
MOVI2R(R0, 0);
|
||||
STR(R0, CTXREG, offsetof(MIPSState, fpcond));
|
||||
return;
|
||||
}
|
||||
|
||||
int fs = _FS;
|
||||
int ft = _FT;
|
||||
fpr.MapInIn(fs, ft);
|
||||
VCMP(fpr.R(fs), fpr.R(ft), false);
|
||||
VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
|
||||
switch(opc)
|
||||
{
|
||||
case 1: // un, ngle (unordered)
|
||||
SetCC(CC_VS);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_VC);
|
||||
break;
|
||||
case 2: // eq, seq (equal, ordered)
|
||||
SetCC(CC_EQ);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_NEQ);
|
||||
break;
|
||||
case 3: // ueq, ngl (equal, unordered)
|
||||
SetCC(CC_EQ);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_NEQ);
|
||||
MOVI2R(R0, 0);
|
||||
SetCC(CC_VS);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_AL);
|
||||
STR(R0, CTXREG, offsetof(MIPSState, fpcond));
|
||||
return;
|
||||
case 4: // olt, lt (less than, ordered)
|
||||
SetCC(CC_LO);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_HS);
|
||||
break;
|
||||
case 5: // ult, nge (less than, unordered)
|
||||
SetCC(CC_LT);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_GE);
|
||||
break;
|
||||
case 6: // ole, le (less equal, ordered)
|
||||
SetCC(CC_LS);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_HI);
|
||||
break;
|
||||
case 7: // ule, ngt (less equal, unordered)
|
||||
SetCC(CC_LE);
|
||||
MOVI2R(R0, 1);
|
||||
SetCC(CC_GT);
|
||||
break;
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
}
|
||||
MOVI2R(R0, 0);
|
||||
SetCC(CC_AL);
|
||||
STR(R0, CTXREG, offsetof(MIPSState, fpcond));
|
||||
}
|
||||
|
||||
void Jit::Comp_FPU2op(u32 op)
|
||||
{
|
||||
DISABLE
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
int fs = _FS;
|
||||
int fd = _FD;
|
||||
// logBlocks = 1;
|
||||
|
||||
switch (op & 0x3f)
|
||||
{
|
||||
/*
|
||||
case 5: //F(fd) = fabsf(F(fs)); break; //abs
|
||||
fpr.Lock(fd, fs);
|
||||
fpr.BindToRegister(fd, fd == fs, true);
|
||||
MOVSS(fpr.RX(fd), fpr.R(fs));
|
||||
PAND(fpr.RX(fd), M((void *)ssNoSignMask));
|
||||
fpr.UnlockAll();
|
||||
case 4: //F(fd) = sqrtf(F(fs)); break; //sqrt
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VSQRT(fpr.R(fd), fpr.R(fs));
|
||||
break;
|
||||
|
||||
case 6: //F(fd) = F(fs); break; //mov
|
||||
if (fd != fs) {
|
||||
fpr.Lock(fd, fs);
|
||||
fpr.BindToRegister(fd, fd == fs, true);
|
||||
MOVSS(fpr.RX(fd), fpr.R(fs));
|
||||
fpr.UnlockAll();
|
||||
}
|
||||
case 5: //F(fd) = fabsf(F(fs)); break; //abs
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VABS(fpr.R(fd), fpr.R(fs));
|
||||
break;
|
||||
|
||||
case 7: //F(fd) = -F(fs); break; //neg
|
||||
fpr.Lock(fd, fs);
|
||||
fpr.BindToRegister(fd, fd == fs, true);
|
||||
MOVSS(fpr.RX(fd), fpr.R(fs));
|
||||
PXOR(fpr.RX(fd), M((void *)ssSignBits2));
|
||||
fpr.UnlockAll();
|
||||
case 6: //F(fd) = F(fs); break; //mov
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VMOV(fpr.R(fd), fpr.R(fs));
|
||||
break;
|
||||
case 7: //F(fd) = -F(fs); break; //neg
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VNEG(fpr.R(fd), fpr.R(fs));
|
||||
break;
|
||||
|
||||
case 12: //FsI(fd) = (int)floorf(F(fs)+0.5f); break; //round.w.s
|
||||
|
||||
case 4: //F(fd) = sqrtf(F(fs)); break; //sqrt
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
|
||||
case 13: //FsI(fd) = F(fs)>=0 ? (int)floorf(F(fs)) : (int)ceilf(F(fs)); break;//trunc.w.s
|
||||
fpr.Lock(fs, fd);
|
||||
fpr.StoreFromRegister(fd);
|
||||
CVTTSS2SI(EAX, fpr.R(fs));
|
||||
MOV(32, fpr.R(fd), R(EAX));
|
||||
fpr.UnlockAll();
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED);
|
||||
break;
|
||||
case 13: //FsI(fd) = Rto0(F(fs))); break; //trunc.w.s
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED | ROUND_TO_ZERO);
|
||||
break;
|
||||
case 14: //FsI(fd) = (int)ceilf (F(fs)); break; //ceil.w.s
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
MOVI2F(S0, 0.5f, R0);
|
||||
VADD(S0,fpr.R(fs),S0);
|
||||
VCVT(fpr.R(fd), S0, TO_INT | IS_SIGNED);
|
||||
break;
|
||||
case 15: //FsI(fd) = (int)floorf(F(fs)); break; //floor.w.s
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
MOVI2F(S0, 0.5f, R0);
|
||||
VSUB(S0,fpr.R(fs),S0);
|
||||
VCVT(fpr.R(fd), S0, TO_INT | IS_SIGNED);
|
||||
break;
|
||||
case 32: //F(fd) = (float)FsI(fs); break; //cvt.s.w
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
VCVT(fpr.R(fd), fpr.R(fs), TO_FLOAT | IS_SIGNED);
|
||||
break;
|
||||
case 36: //FsI(fd) = (int) F(fs); break; //cvt.w.s
|
||||
fpr.MapDirtyIn(fd, fs);
|
||||
LDR(R0, CTXREG, offsetof(MIPSState, fcr31));
|
||||
AND(R0, R0, Operand2(3));
|
||||
// MIPS Rounding Mode:
|
||||
// 0: Round nearest
|
||||
// 1: Round to zero
|
||||
// 2: Round up (ceil)
|
||||
// 3: Round down (floor)
|
||||
CMP(R0, Operand2(2));
|
||||
SetCC(CC_GE); MOVI2F(S0, 0.5f, R1);
|
||||
SetCC(CC_GT); VSUB(S0,fpr.R(fs),S0);
|
||||
SetCC(CC_EQ); VADD(S0,fpr.R(fs),S0);
|
||||
SetCC(CC_GE); VCVT(fpr.R(fd), S0, TO_INT | IS_SIGNED); /* 2,3 */
|
||||
SetCC(CC_AL);
|
||||
CMP(R0, Operand2(1));
|
||||
SetCC(CC_EQ); VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED | ROUND_TO_ZERO); /* 1 */
|
||||
SetCC(CC_LT); VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED); /* 0 */
|
||||
SetCC(CC_AL);
|
||||
break;
|
||||
|
||||
case 14: //FsI(fd) = (int)ceilf (F(fs)); break; //ceil.w.s
|
||||
case 15: //FsI(fd) = (int)floorf(F(fs)); break; //floor.w.s
|
||||
case 32: //F(fd) = (float)FsI(fs); break; //cvt.s.w
|
||||
case 36: //FsI(fd) = (int) F(fs); break; //cvt.w.s
|
||||
*/
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_mxc1(u32 op)
|
||||
{
|
||||
DISABLE
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
int fs = _FS;
|
||||
int rt = _RT;
|
||||
|
||||
switch((op >> 21) & 0x1f)
|
||||
{
|
||||
/*
|
||||
case 0: // R(rt) = FI(fs); break; //mfc1
|
||||
// Cross move! slightly tricky
|
||||
fpr.StoreFromRegister(fs);
|
||||
gpr.Lock(rt);
|
||||
gpr.BindToRegister(rt, false, true);
|
||||
MOV(32, gpr.R(rt), fpr.R(fs));
|
||||
gpr.UnlockAll();
|
||||
// Let's just go through RAM for now.
|
||||
fpr.FlushR(fs);
|
||||
gpr.MapReg(rt, MAP_DIRTY | MAP_NOINIT);
|
||||
LDR(gpr.R(rt), CTXREG, fpr.GetMipsRegOffset(fs));
|
||||
return;
|
||||
|
||||
case 2: // R(rt) = currentMIPS->ReadFCR(fs); break; //cfc1
|
||||
Comp_Generic(op);
|
||||
case 2: //cfc1
|
||||
if (fs == 31)
|
||||
{
|
||||
gpr.MapReg(rt, MAP_DIRTY | MAP_NOINIT);
|
||||
LDR(R0, CTXREG, offsetof(MIPSState, fpcond));
|
||||
AND(R0,R0, Operand2(1)); // Just in case
|
||||
LDR(gpr.R(rt), CTXREG, offsetof(MIPSState, fcr31));
|
||||
BIC(gpr.R(rt), gpr.R(rt), Operand2(0x1 << 23));
|
||||
ORR(gpr.R(rt), gpr.R(rt), Operand2(R0, ST_LSL, 23));
|
||||
}
|
||||
else if (fs == 0)
|
||||
{
|
||||
gpr.MapReg(rt, MAP_DIRTY | MAP_NOINIT);
|
||||
LDR(gpr.R(rt), CTXREG, offsetof(MIPSState, fcr0));
|
||||
}
|
||||
return;
|
||||
|
||||
case 4: //FI(fs) = R(rt); break; //mtc1
|
||||
// Cross move! slightly tricky
|
||||
gpr.StoreFromRegister(rt);
|
||||
fpr.Lock(fs);
|
||||
fpr.BindToRegister(fs, false, true);
|
||||
MOVSS(fpr.RX(fs), gpr.R(rt));
|
||||
fpr.UnlockAll();
|
||||
// Let's just go through RAM for now.
|
||||
gpr.FlushR(rt);
|
||||
fpr.MapReg(fs, MAP_DIRTY | MAP_NOINIT);
|
||||
VLDR(fpr.R(fs), CTXREG, gpr.GetMipsRegOffset(rt));
|
||||
return;
|
||||
*/
|
||||
case 6: //currentMIPS->WriteFCR(fs, R(rt)); break; //ctc1
|
||||
Comp_Generic(op);
|
||||
|
||||
case 6: //ctc1
|
||||
if (fs == 31)
|
||||
{
|
||||
gpr.MapReg(rt, 0);
|
||||
// Hardware rounding method.
|
||||
// Left here in case it is faster than conditional method.
|
||||
/*
|
||||
AND(R0, gpr.R(rt), Operand2(3));
|
||||
// MIPS Rounding Mode <-> ARM Rounding Mode
|
||||
// 0, 1, 2, 3 <-> 0, 3, 1, 2
|
||||
CMP(R0, Operand2(1));
|
||||
SetCC(CC_EQ); ADD(R0, R0, Operand2(2));
|
||||
SetCC(CC_GT); SUB(R0, R0, Operand2(1));
|
||||
SetCC(CC_AL);
|
||||
|
||||
// Load and Store RM to FPSCR
|
||||
VMRS(R1);
|
||||
BIC(R1, R1, Operand2(0x3 << 22));
|
||||
ORR(R1, R1, Operand2(R0, ST_LSL, 22));
|
||||
VMSR(R1);
|
||||
*/
|
||||
// Update MIPS state
|
||||
STR(gpr.R(rt), CTXREG, offsetof(MIPSState, fcr31));
|
||||
MOV(R0, Operand2(gpr.R(rt), ST_LSR, 23));
|
||||
AND(R0, R0, Operand2(1));
|
||||
STR(R0, CTXREG, offsetof(MIPSState, fpcond));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,15 @@
|
||||
#define _POS ((op>>6 ) & 0x1F)
|
||||
#define _SIZE ((op>>11 ) & 0x1F)
|
||||
|
||||
#define DISABLE Comp_Generic(op); return;
|
||||
// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
|
||||
// Currently known non working ones should have DISABLE.
|
||||
|
||||
// #define CONDITIONAL_DISABLE { Comp_Generic(op); return; }
|
||||
#define CONDITIONAL_DISABLE ;
|
||||
#define DISABLE { Comp_Generic(op); return; }
|
||||
|
||||
namespace MIPSComp
|
||||
{
|
||||
|
||||
void Jit::SetR0ToEffectiveAddress(int rs, s16 offset) {
|
||||
Operand2 op2;
|
||||
if (offset) {
|
||||
@@ -84,7 +88,9 @@ namespace MIPSComp
|
||||
|
||||
void Jit::Comp_ITypeMem(u32 op)
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
int offset = (signed short)(op&0xFFFF);
|
||||
bool load = false;
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
int o = op>>26;
|
||||
@@ -92,103 +98,114 @@ namespace MIPSComp
|
||||
// Don't load anything into $zr
|
||||
return;
|
||||
}
|
||||
|
||||
switch (o)
|
||||
{
|
||||
case 37: //R(rt) = ReadMem16(addr); break; //lhu
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
|
||||
case 35: //R(rt) = ReadMem32(addr); //lw
|
||||
case 36: //R(rt) = ReadMem8 (addr); break; //lbu
|
||||
if (g_Config.bFastMemory) {
|
||||
if (gpr.IsImm(rs)) {
|
||||
// We can compute the full address at compile time. Kickass.
|
||||
u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
|
||||
gpr.MapReg(rt, MAP_NOINIT | MAP_DIRTY); // must be OK even if rs == rt since we have the value from imm already.
|
||||
MOVI2R(R0, addr);
|
||||
} else {
|
||||
gpr.MapDirtyIn(rt, rs);
|
||||
SetR0ToEffectiveAddress(rs, offset);
|
||||
}
|
||||
if (o == 35) {
|
||||
LDR(gpr.R(rt), R11, R0, true, true);
|
||||
} else if (o == 36) {
|
||||
ADD(R0, R0, R11); // TODO: Merge with next instruction
|
||||
LDRB(gpr.R(rt), R0);
|
||||
}
|
||||
} else {
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 41: //WriteMem16(addr, R(rt)); break; //sh
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
|
||||
case 32: //lb
|
||||
case 33: //lh
|
||||
case 35: //lw
|
||||
case 36: //lbu
|
||||
case 37: //lhu
|
||||
load = true;
|
||||
case 40: //sb
|
||||
case 43: //WriteMem32(addr, R(rt)); break; //sw
|
||||
case 41: //sh
|
||||
case 43: //sw
|
||||
if (g_Config.bFastMemory) {
|
||||
if (gpr.IsImm(rs)) {
|
||||
// We can compute the full address at compile time. Kickass.
|
||||
u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
|
||||
gpr.MapReg(rt);
|
||||
// Must be OK even if rs == rt since we have the value from imm already.
|
||||
gpr.MapReg(rt, load ? MAP_NOINIT | MAP_DIRTY : 0);
|
||||
MOVI2R(R0, addr);
|
||||
} else {
|
||||
gpr.MapInIn(rt, rs);
|
||||
load ? gpr.MapDirtyIn(rt, rs) : gpr.MapInIn(rt, rs);
|
||||
SetR0ToEffectiveAddress(rs, offset);
|
||||
}
|
||||
if (o == 43) {
|
||||
STR(R0, gpr.R(rt), R11, true, true);
|
||||
} else if (o == 40) {
|
||||
ADD(R0, R0, R11);
|
||||
STRB(R0, gpr.R(rt));
|
||||
switch (o)
|
||||
{
|
||||
// Load
|
||||
case 35: LDR (gpr.R(rt), R11, R0); break;
|
||||
case 37: LDRH (gpr.R(rt), R11, R0); break;
|
||||
case 33: LDRSH(gpr.R(rt), R11, R0); break;
|
||||
case 36: LDRB (gpr.R(rt), R11, R0); break;
|
||||
case 32: LDRSB(gpr.R(rt), R11, R0); break;
|
||||
// Store
|
||||
case 43: STR (gpr.R(rt), R11, R0); break;
|
||||
case 41: STRH (gpr.R(rt), R11, R0); break;
|
||||
case 40: STRB (gpr.R(rt), R11, R0); break;
|
||||
}
|
||||
} else {
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
// break;
|
||||
/*
|
||||
case 34: //lwl
|
||||
{
|
||||
Crash();
|
||||
//u32 shift = (addr & 3) << 3;
|
||||
//u32 mem = ReadMem32(addr & 0xfffffffc);
|
||||
//R(rt) = ( u32(R(rt)) & (0x00ffffff >> shift) ) | ( mem << (24 - shift) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 38: //lwr
|
||||
{
|
||||
Crash();
|
||||
//u32 shift = (addr & 3) << 3;
|
||||
//u32 mem = ReadMem32(addr & 0xfffffffc);
|
||||
|
||||
//R(rt) = ( u32(rt) & (0xffffff00 << (24 - shift)) ) | ( mem >> shift );
|
||||
}
|
||||
break;
|
||||
|
||||
load = true;
|
||||
case 42: //swl
|
||||
{
|
||||
Crash();
|
||||
//u32 shift = (addr & 3) << 3;
|
||||
//u32 mem = ReadMem32(addr & 0xfffffffc);
|
||||
//WriteMem32((addr & 0xfffffffc), ( ( u32(R(rt)) >> (24 - shift) ) ) |
|
||||
// ( mem & (0xffffff00 << shift) ));
|
||||
case 46: //swr
|
||||
if (!js.inDelaySlot) {
|
||||
// Optimisation: Combine to single unaligned load/store
|
||||
bool isLeft = (o == 34 || o == 42);
|
||||
u32 nextOp = Memory::Read_Instruction(js.compilerPC + 4);
|
||||
// Find a matching shift in opposite direction with opposite offset.
|
||||
if (nextOp == (isLeft ? (op + (4<<26) - 3)
|
||||
: (op - (4<<26) + 3)))
|
||||
{
|
||||
EatInstruction(nextOp);
|
||||
nextOp = ((load ? 35 : 43) << 26) | ((isLeft ? nextOp : op) & 0x3FFFFFF); //lw, sw
|
||||
Comp_ITypeMem(nextOp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DISABLE; // Disabled until crashes are resolved.
|
||||
if (g_Config.bFastMemory) {
|
||||
int shift;
|
||||
if (gpr.IsImm(rs)) {
|
||||
u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
|
||||
shift = (addr & 3) << 3;
|
||||
addr &= 0xfffffffc;
|
||||
load ? gpr.MapReg(rt, MAP_DIRTY) : gpr.MapReg(rt, 0);
|
||||
MOVI2R(R0, addr);
|
||||
} else {
|
||||
load ? gpr.MapDirtyIn(rt, rs, false) : gpr.MapInIn(rt, rs);
|
||||
shift = (offset & 3) << 3; // Should be addr. Difficult as we don't know it yet.
|
||||
offset &= 0xfffffffc;
|
||||
SetR0ToEffectiveAddress(rs, offset);
|
||||
}
|
||||
switch (o)
|
||||
{
|
||||
// Load
|
||||
case 34:
|
||||
AND(gpr.R(rt), gpr.R(rt), 0x00ffffff >> shift);
|
||||
LDR(R0, R11, R0);
|
||||
ORR(gpr.R(rt), gpr.R(rt), Operand2(R0, ST_LSL, 24 - shift));
|
||||
break;
|
||||
case 38:
|
||||
AND(gpr.R(rt), gpr.R(rt), 0xffffff00 << (24 - shift));
|
||||
LDR(R0, R11, R0);
|
||||
ORR(gpr.R(rt), gpr.R(rt), Operand2(R0, ST_LSR, shift));
|
||||
break;
|
||||
// Store
|
||||
case 42:
|
||||
LDR(R1, R11, R0);
|
||||
AND(R1, R1, 0xffffff00 << shift);
|
||||
ORR(R1, R1, Operand2(gpr.R(rt), ST_LSR, 24 - shift));
|
||||
STR(R1, R11, R0);
|
||||
break;
|
||||
case 46:
|
||||
LDR(R1, R11, R0);
|
||||
AND(R1, R1, 0x00ffffff >> (24 - shift));
|
||||
ORR(R1, R1, Operand2(gpr.R(rt), ST_LSL, shift));
|
||||
STR(R1, R11, R0);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Comp_Generic(op);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 46: //swr
|
||||
{
|
||||
Crash();
|
||||
// u32 shift = (addr & 3) << 3;
|
||||
// u32 mem = ReadMem32(addr & 0xfffffffc);
|
||||
//
|
||||
// WriteMem32((addr & 0xfffffffc), ( ( u32(R(rt)) << shift ) |
|
||||
// (mem & (0x00ffffff >> (24 - shift)) ) ) );
|
||||
}
|
||||
break;*/
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
return ;
|
||||
|
||||
+595
-14
@@ -1,5 +1,23 @@
|
||||
// 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/.
|
||||
|
||||
#include "../../MemMap.h"
|
||||
#include "../MIPSAnalyst.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "ArmJit.h"
|
||||
#include "ArmRegCache.h"
|
||||
@@ -14,53 +32,616 @@
|
||||
#define _POS ((op>>6 ) & 0x1F)
|
||||
#define _SIZE ((op>>11 ) & 0x1F)
|
||||
|
||||
// #define CONDITIONAL_DISABLE Comp_Generic(op); return;
|
||||
// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
|
||||
// Currently known non working ones should have DISABLE.
|
||||
|
||||
// #define CONDITIONAL_DISABLE { fpr.ReleaseSpillLocks(); Comp_Generic(op); return; }
|
||||
#define CONDITIONAL_DISABLE ;
|
||||
#define DISABLE Comp_Generic(op); return;
|
||||
#define DISABLE { fpr.ReleaseSpillLocks(); Comp_Generic(op); return; }
|
||||
|
||||
namespace MIPSComp
|
||||
{
|
||||
// Vector regs can overlap in all sorts of swizzled ways.
|
||||
// This does allow a single overlap in sregs[i].
|
||||
bool IsOverlapSafeAllowS(int dreg, int di, int sn, u8 sregs[], int tn = 0, u8 tregs[] = NULL)
|
||||
{
|
||||
for (int i = 0; i < sn; ++i)
|
||||
{
|
||||
if (sregs[i] == dreg && i != di)
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < tn; ++i)
|
||||
{
|
||||
if (tregs[i] == dreg)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Hurray, no overlap, we can write directly.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsOverlapSafe(int dreg, int di, int sn, u8 sregs[], int tn = 0, u8 tregs[] = NULL)
|
||||
{
|
||||
return IsOverlapSafeAllowS(dreg, di, sn, sregs, tn, tregs) && sregs[di] != dreg;
|
||||
}
|
||||
|
||||
void Jit::Comp_VPFX(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
int data = op & 0xFFFFF;
|
||||
int regnum = (op >> 24) & 3;
|
||||
switch (regnum) {
|
||||
case 0: // S
|
||||
js.prefixS = data;
|
||||
js.prefixSFlag = ArmJitState::PREFIX_KNOWN_DIRTY;
|
||||
break;
|
||||
case 1: // T
|
||||
js.prefixT = data;
|
||||
js.prefixTFlag = ArmJitState::PREFIX_KNOWN_DIRTY;
|
||||
break;
|
||||
case 2: // D
|
||||
js.prefixD = data;
|
||||
js.prefixDFlag = ArmJitState::PREFIX_KNOWN_DIRTY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz) {
|
||||
if (prefix == 0xE4) return;
|
||||
|
||||
int n = GetNumVectorElements(sz);
|
||||
u8 origV[4];
|
||||
static const float constantArray[8] = {0.f, 1.f, 2.f, 0.5f, 3.f, 1.f/3.f, 0.25f, 1.f/6.f};
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
origV[i] = vregs[i];
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int regnum = (prefix >> (i*2)) & 3;
|
||||
int abs = (prefix >> (8+i)) & 1;
|
||||
int negate = (prefix >> (16+i)) & 1;
|
||||
int constants = (prefix >> (12+i)) & 1;
|
||||
|
||||
// Unchanged, hurray.
|
||||
if (!constants && regnum == i && !abs && !negate)
|
||||
continue;
|
||||
|
||||
// This puts the value into a temp reg, so we won't write the modified value back.
|
||||
vregs[i] = fpr.GetTempV();
|
||||
fpr.MapRegV(vregs[i], MAP_NOINIT | MAP_DIRTY);
|
||||
|
||||
if (!constants) {
|
||||
// Prefix may say "z, z, z, z" but if this is a pair, we force to x.
|
||||
// TODO: But some ops seem to use const 0 instead?
|
||||
if (regnum >= n) {
|
||||
ERROR_LOG(CPU, "Invalid VFPU swizzle: %08x / %d", prefix, sz);
|
||||
Reporting::ReportMessage("Invalid VFPU swizzle: %08x / %d", prefix, sz);
|
||||
regnum = 0;
|
||||
}
|
||||
|
||||
if (abs) {
|
||||
VABS(fpr.V(vregs[i]), fpr.V(origV[regnum]));
|
||||
} else {
|
||||
VMOV(fpr.V(vregs[i]), fpr.V(origV[regnum]));
|
||||
}
|
||||
} else {
|
||||
// TODO: There is VMOV s, imm on ARM, that can generate some of these constants. Not 1/3 or 1/6 though.
|
||||
MOVI2F(fpr.V(vregs[i]), constantArray[regnum + (abs<<2)], R0);
|
||||
}
|
||||
|
||||
// TODO: This can be integrated into the VABS / VMOV above, and also the constants.
|
||||
if (negate)
|
||||
VNEG(fpr.V(vregs[i]), fpr.V(vregs[i]));
|
||||
|
||||
// TODO: This probably means it will swap out soon, inefficiently...
|
||||
fpr.ReleaseSpillLockV(vregs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::GetVectorRegsPrefixD(u8 *regs, VectorSize sz, int vectorReg) {
|
||||
_assert_(js.prefixDFlag & ArmJitState::PREFIX_KNOWN);
|
||||
|
||||
GetVectorRegs(regs, sz, vectorReg);
|
||||
if (js.prefixD == 0)
|
||||
return;
|
||||
|
||||
int n = GetNumVectorElements(sz);
|
||||
for (int i = 0; i < n; i++) {
|
||||
// Hopefully this is rare, we'll just write it into a reg we drop.
|
||||
if (js.VfpuWriteMask(i))
|
||||
regs[i] = fpr.GetTempV();
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::ApplyPrefixD(const u8 *vregs, VectorSize sz) {
|
||||
_assert_(js.prefixDFlag & ArmJitState::PREFIX_KNOWN);
|
||||
if (!js.prefixD) return;
|
||||
|
||||
int n = GetNumVectorElements(sz);
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (js.VfpuWriteMask(i))
|
||||
continue;
|
||||
|
||||
int sat = (js.prefixD >> (i * 2)) & 3;
|
||||
if (sat == 1) {
|
||||
fpr.MapRegV(vregs[i], MAP_DIRTY);
|
||||
// ARGH this is a pain - no MIN/MAX in non-NEON VFP!
|
||||
// NEON does have min/max though so this should only be a fallback.
|
||||
MOVI2F(S0, 0.0, R0);
|
||||
MOVI2F(S1, 1.0, R0);
|
||||
VCMP(fpr.V(vregs[i]), S1);
|
||||
VMRS_APSR();
|
||||
SetCC(CC_GE);
|
||||
VMOV(fpr.V(vregs[i]), S1);
|
||||
FixupBranch skip = B();
|
||||
SetCC(CC_AL);
|
||||
VCMP(fpr.V(vregs[i]), S0);
|
||||
VMRS_APSR();
|
||||
SetCC(CC_LE);
|
||||
VMOV(fpr.V(vregs[i]), S0);
|
||||
SetCC(CC_AL);
|
||||
SetJumpTarget(skip);
|
||||
} else if (sat == 3) {
|
||||
fpr.MapRegV(vregs[i], MAP_DIRTY);
|
||||
MOVI2F(S0, -1.0, R0);
|
||||
MOVI2F(S1, 1.0, R0);
|
||||
VCMP(fpr.V(vregs[i]), S1);
|
||||
VMRS_APSR();
|
||||
SetCC(CC_GE);
|
||||
VMOV(fpr.V(vregs[i]), S1);
|
||||
FixupBranch skip = B();
|
||||
SetCC(CC_AL);
|
||||
VCMP(fpr.V(vregs[i]), S0);
|
||||
VMRS_APSR();
|
||||
SetCC(CC_LE);
|
||||
VMOV(fpr.V(vregs[i]), S0);
|
||||
SetCC(CC_AL);
|
||||
SetJumpTarget(skip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_SV(u32 op) {
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
s32 imm = (signed short)(op&0xFFFC);
|
||||
int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5);
|
||||
int rs = _RS;
|
||||
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 50: //lv.s // VI(vt) = Memory::Read_U32(addr);
|
||||
{
|
||||
gpr.MapReg(rs);
|
||||
SetR0ToEffectiveAddress(rs, imm);
|
||||
ADD(R0, R0, R11);
|
||||
fpr.MapRegV(vt, MAP_DIRTY | MAP_NOINIT);
|
||||
fpr.ReleaseSpillLocks();
|
||||
VLDR(fpr.V(vt), R0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case 58: //sv.s // Memory::Write_U32(VI(vt), addr);
|
||||
{
|
||||
gpr.MapReg(rs);
|
||||
SetR0ToEffectiveAddress(rs, imm);
|
||||
ADD(R0, R0, R11);
|
||||
fpr.MapRegV(vt);
|
||||
fpr.ReleaseSpillLocks();
|
||||
VSTR(fpr.V(vt), R0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_SVQ(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
int imm = (signed short)(op&0xFFFC);
|
||||
int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5);
|
||||
int rs = _RS;
|
||||
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 54: //lv.q
|
||||
{
|
||||
gpr.MapReg(rs);
|
||||
SetR0ToEffectiveAddress(rs, imm);
|
||||
ADD(R0, R0, R11);
|
||||
|
||||
u8 vregs[4];
|
||||
GetVectorRegs(vregs, V_Quad, vt);
|
||||
fpr.MapRegsV(vregs, V_Quad, MAP_DIRTY | MAP_NOINIT);
|
||||
fpr.ReleaseSpillLocks();
|
||||
for (int i = 0; i < 4; i++)
|
||||
VLDR(fpr.V(vregs[i]), R0, i * 4);
|
||||
}
|
||||
break;
|
||||
|
||||
case 62: //sv.q
|
||||
{
|
||||
gpr.MapReg(rs);
|
||||
SetR0ToEffectiveAddress(rs, imm);
|
||||
ADD(R0, R0, R11);
|
||||
|
||||
u8 vregs[4];
|
||||
GetVectorRegs(vregs, V_Quad, vt);
|
||||
fpr.MapRegsV(vregs, V_Quad, 0);
|
||||
fpr.ReleaseSpillLocks();
|
||||
for (int i = 0; i < 4; i++)
|
||||
VSTR(fpr.V(vregs[i]), R0, i * 4);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DISABLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_VVectorInit(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
// WARNING: No prefix support!
|
||||
if (js.MayHavePrefix()) {
|
||||
Comp_Generic(op);
|
||||
js.EatPrefix();
|
||||
return;
|
||||
}
|
||||
|
||||
switch ((op >> 16) & 0xF)
|
||||
{
|
||||
case 6: // v=zeros; break; //vzero
|
||||
MOVI2F(S0, 0.0f, R0);
|
||||
break;
|
||||
case 7: // v=ones; break; //vone
|
||||
MOVI2F(S0, 1.0f, R0);
|
||||
break;
|
||||
default:
|
||||
DISABLE;
|
||||
break;
|
||||
}
|
||||
|
||||
VectorSize sz = GetVecSize(op);
|
||||
int n = GetNumVectorElements(sz);
|
||||
|
||||
u8 dregs[4];
|
||||
GetVectorRegsPrefixD(dregs, sz, _VD);
|
||||
fpr.MapRegsV(dregs, sz, MAP_NOINIT | MAP_DIRTY);
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
VMOV(fpr.V(dregs[i]), S0);
|
||||
|
||||
ApplyPrefixD(dregs, sz);
|
||||
fpr.ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
void Jit::Comp_VDot(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
// DISABLE;
|
||||
CONDITIONAL_DISABLE;
|
||||
// WARNING: No prefix support!
|
||||
if (js.MayHavePrefix()) {
|
||||
Comp_Generic(op);
|
||||
js.EatPrefix();
|
||||
return;
|
||||
}
|
||||
|
||||
int vd = _VD;
|
||||
int vs = _VS;
|
||||
int vt = _VT;
|
||||
VectorSize sz = GetVecSize(op);
|
||||
|
||||
// TODO: Force read one of them into regs? probably not.
|
||||
u8 sregs[4], tregs[4];
|
||||
GetVectorRegs(sregs, sz, vs);
|
||||
GetVectorRegs(tregs, sz, vt);
|
||||
|
||||
// TODO: applyprefixST here somehow (shuffle, etc...)
|
||||
fpr.MapRegsV(sregs, sz, 0);
|
||||
fpr.MapRegsV(tregs, sz, 0);
|
||||
VMUL(S0, fpr.V(sregs[0]), fpr.V(tregs[0]));
|
||||
|
||||
int n = GetNumVectorElements(sz);
|
||||
for (int i = 1; i < n; i++) {
|
||||
// sum += s[i]*t[i];
|
||||
VMLA(S0, fpr.V(sregs[i]), fpr.V(tregs[i]));
|
||||
}
|
||||
fpr.ReleaseSpillLocks();
|
||||
|
||||
fpr.MapRegV(vd, MAP_NOINIT | MAP_DIRTY);
|
||||
|
||||
// TODO: applyprefixD here somehow (write mask etc..)
|
||||
VMOV(fpr.V(vd), S0);
|
||||
|
||||
fpr.ReleaseSpillLocks();
|
||||
|
||||
js.EatPrefix();
|
||||
}
|
||||
|
||||
void Jit::Comp_VecDo3(u32 op)
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
DISABLE;
|
||||
// WARNING: No prefix support!
|
||||
if (js.MayHavePrefix())
|
||||
{
|
||||
Comp_Generic(op);
|
||||
js.EatPrefix();
|
||||
return;
|
||||
}
|
||||
|
||||
int vd = _VD;
|
||||
int vs = _VS;
|
||||
int vt = _VT;
|
||||
|
||||
void (ARMXEmitter::*triop)(ARMReg, ARMReg, ARMReg) = NULL;
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 24: //VFPU0
|
||||
switch ((op >> 23)&7)
|
||||
{
|
||||
case 0: // d[i] = s[i] + t[i]; break; //vadd
|
||||
triop = &ARMXEmitter::VADD;
|
||||
break;
|
||||
case 1: // d[i] = s[i] - t[i]; break; //vsub
|
||||
triop = &ARMXEmitter::VSUB;
|
||||
break;
|
||||
case 7: // d[i] = s[i] / t[i]; break; //vdiv
|
||||
triop = &ARMXEmitter::VDIV;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 25: //VFPU1
|
||||
switch ((op >> 23)&7)
|
||||
{
|
||||
case 0: // d[i] = s[i] * t[i]; break; //vmul
|
||||
triop = &ARMXEmitter::VMUL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!triop) {
|
||||
DISABLE;
|
||||
}
|
||||
|
||||
VectorSize sz = GetVecSize(op);
|
||||
int n = GetNumVectorElements(sz);
|
||||
|
||||
u8 sregs[4], tregs[4], dregs[4];
|
||||
GetVectorRegsPrefixS(sregs, sz, _VS);
|
||||
GetVectorRegsPrefixT(tregs, sz, _VT);
|
||||
GetVectorRegsPrefixD(dregs, sz, _VD);
|
||||
|
||||
MIPSReg tempregs[4];
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (!IsOverlapSafeAllowS(dregs[i], i, n, sregs, n, tregs)) {
|
||||
tempregs[i] = fpr.GetTempV();
|
||||
} else {
|
||||
fpr.MapRegV(dregs[i], (dregs[i] == sregs[i] || dregs[i] == tregs[i] ? 0 : MAP_NOINIT) | MAP_DIRTY);
|
||||
tempregs[i] = dregs[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
fpr.SpillLockV(sregs[i]);
|
||||
fpr.SpillLockV(tregs[i]);
|
||||
fpr.MapRegV(sregs[i]);
|
||||
fpr.MapRegV(tregs[i]);
|
||||
fpr.MapRegV(tempregs[i]);
|
||||
(this->*triop)(fpr.V(tempregs[i]), fpr.V(sregs[i]), fpr.V(tregs[i]));
|
||||
fpr.ReleaseSpillLockV(sregs[i]);
|
||||
fpr.ReleaseSpillLockV(tregs[i]);
|
||||
}
|
||||
|
||||
fpr.MapRegsV(dregs, sz, MAP_DIRTY);
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (dregs[i] != tempregs[i])
|
||||
VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
|
||||
}
|
||||
ApplyPrefixD(dregs, sz);
|
||||
|
||||
fpr.ReleaseSpillLocks();
|
||||
|
||||
js.EatPrefix();
|
||||
}
|
||||
|
||||
void Jit::Comp_VV2Op(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
}
|
||||
void Jit::Comp_VV2Op(u32 op) {
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
DISABLE;
|
||||
|
||||
if (js.HasUnknownPrefix())
|
||||
DISABLE;
|
||||
|
||||
VectorSize sz = GetVecSize(op);
|
||||
int n = GetNumVectorElements(sz);
|
||||
|
||||
u8 sregs[4], dregs[4];
|
||||
GetVectorRegsPrefixS(sregs, sz, _VS);
|
||||
GetVectorRegsPrefixD(dregs, sz, _VD);
|
||||
|
||||
ARMReg tempxregs[4];
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (!IsOverlapSafeAllowS(dregs[i], i, n, sregs))
|
||||
{
|
||||
int reg = fpr.GetTempV();
|
||||
fpr.MapRegV(reg, MAP_NOINIT | MAP_DIRTY);
|
||||
fpr.SpillLockV(reg);
|
||||
tempxregs[i] = fpr.V(reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
fpr.MapRegV(dregs[i], (dregs[i] == sregs[i] ? 0 : MAP_NOINIT) | MAP_DIRTY);
|
||||
fpr.SpillLockV(dregs[i]);
|
||||
tempxregs[i] = fpr.V(dregs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Warning: sregs[i] and tempxregs[i] may be the same reg.
|
||||
// Helps for vmov, hurts for vrcp, etc.
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
switch ((op >> 16) & 0x1f)
|
||||
{
|
||||
case 0: // d[i] = s[i]; break; //vmov
|
||||
// Probably for swizzle.
|
||||
VMOV(tempxregs[i], fpr.V(sregs[i]));
|
||||
break;
|
||||
case 1: // d[i] = fabsf(s[i]); break; //vabs
|
||||
//if (!fpr.V(sregs[i]).IsSimpleReg(tempxregs[i]))
|
||||
VABS(tempxregs[i], fpr.V(sregs[i]));
|
||||
break;
|
||||
case 2: // d[i] = -s[i]; break; //vneg
|
||||
VNEG(tempxregs[i], fpr.V(sregs[i]));
|
||||
break;
|
||||
case 4: // if (s[i] < 0) d[i] = 0; else {if(s[i] > 1.0f) d[i] = 1.0f; else d[i] = s[i];} break; // vsat0
|
||||
DISABLE;
|
||||
break;
|
||||
case 5: // if (s[i] < -1.0f) d[i] = -1.0f; else {if(s[i] > 1.0f) d[i] = 1.0f; else d[i] = s[i];} break; // vsat1
|
||||
DISABLE;
|
||||
break;
|
||||
case 16: // d[i] = 1.0f / s[i]; break; //vrcp
|
||||
MOVI2R(R0, 0x3F800000); // 1.0f
|
||||
VMOV(S0, R0);
|
||||
VDIV(tempxregs[i], S0, fpr.V(sregs[i]));
|
||||
break;
|
||||
case 17: // d[i] = 1.0f / sqrtf(s[i]); break; //vrsq
|
||||
MOVI2R(R0, 0x3F800000); // 1.0f
|
||||
VMOV(S0, R0);
|
||||
VSQRT(S1, fpr.V(sregs[i]));
|
||||
VDIV(tempxregs[i], S0, S1);
|
||||
break;
|
||||
case 18: // d[i] = sinf((float)M_PI_2 * s[i]); break; //vsin
|
||||
DISABLE;
|
||||
break;
|
||||
case 19: // d[i] = cosf((float)M_PI_2 * s[i]); break; //vcos
|
||||
DISABLE;
|
||||
break;
|
||||
case 20: // d[i] = powf(2.0f, s[i]); break; //vexp2
|
||||
DISABLE;
|
||||
break;
|
||||
case 21: // d[i] = logf(s[i])/log(2.0f); break; //vlog2
|
||||
DISABLE;
|
||||
break;
|
||||
case 22: // d[i] = sqrtf(s[i]); break; //vsqrt
|
||||
VSQRT(tempxregs[i], fpr.V(sregs[i]));
|
||||
VABS(tempxregs[i], tempxregs[i]);
|
||||
break;
|
||||
case 23: // d[i] = asinf(s[i] * (float)M_2_PI); break; //vasin
|
||||
DISABLE;
|
||||
break;
|
||||
case 24: // d[i] = -1.0f / s[i]; break; // vnrcp
|
||||
MOVI2R(R0, 0x80000000 | 0x3F800000); // -1.0f
|
||||
VMOV(S0, R0);
|
||||
VDIV(tempxregs[i], S0, fpr.V(sregs[i]));
|
||||
break;
|
||||
case 26: // d[i] = -sinf((float)M_PI_2 * s[i]); break; // vnsin
|
||||
DISABLE;
|
||||
break;
|
||||
case 28: // d[i] = 1.0f / expf(s[i] * (float)M_LOG2E); break; // vrexp2
|
||||
DISABLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fpr.MapRegsV(dregs, sz, MAP_NOINIT | MAP_DIRTY);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
VMOV(fpr.V(dregs[i]), tempxregs[i]);
|
||||
}
|
||||
|
||||
ApplyPrefixD(dregs, sz);
|
||||
|
||||
fpr.ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
void Jit::Comp_Mftv(u32 op)
|
||||
{
|
||||
DISABLE;
|
||||
}
|
||||
CONDITIONAL_DISABLE;
|
||||
|
||||
void Jit::Comp_SV(u32 op) {
|
||||
DISABLE;
|
||||
int imm = op & 0xFF;
|
||||
int rt = _RT;
|
||||
switch ((op >> 21) & 0x1f)
|
||||
{
|
||||
case 3: //mfv / mfvc
|
||||
// rt = 0, imm = 255 appears to be used as a CPU interlock by some games.
|
||||
if (rt != 0) {
|
||||
if (imm < 128) { //R(rt) = VI(imm);
|
||||
fpr.FlushV(imm);
|
||||
gpr.MapReg(rt, MAP_NOINIT | MAP_DIRTY);
|
||||
LDR(gpr.R(rt), CTXREG, fpr.GetMipsRegOffsetV(imm));
|
||||
} else if (imm < 128 + VFPU_CTRL_MAX) { //mtvc
|
||||
DISABLE;
|
||||
// In case we have a saved prefix.
|
||||
//FlushPrefixV();
|
||||
//gpr.BindToRegister(rt, false, true);
|
||||
//MOV(32, gpr.R(rt), M(¤tMIPS->vfpuCtrl[imm - 128]));
|
||||
} else {
|
||||
//ERROR - maybe need to make this value too an "interlock" value?
|
||||
_dbg_assert_msg_(CPU,0,"mfv - invalid register");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 7: //mtv
|
||||
if (imm < 128) {
|
||||
gpr.FlushR(rt);
|
||||
fpr.MapRegV(imm, MAP_DIRTY | MAP_NOINIT);
|
||||
VLDR(fpr.V(imm), CTXREG, gpr.GetMipsRegOffset(rt));
|
||||
} else if (imm < 128 + VFPU_CTRL_MAX) { //mtvc //currentMIPS->vfpuCtrl[imm - 128] = R(rt);
|
||||
DISABLE;
|
||||
//gpr.BindToRegister(rt, true, false);
|
||||
//MOV(32, M(¤tMIPS->vfpuCtrl[imm - 128]), gpr.R(rt));
|
||||
|
||||
// TODO: Optimization if rt is Imm?
|
||||
//if (imm - 128 == VFPU_CTRL_SPREFIX) {
|
||||
//js.prefixSFlag = JitState::PREFIX_UNKNOWN;
|
||||
//} else if (imm - 128 == VFPU_CTRL_TPREFIX) {
|
||||
// js.prefixTFlag = JitState::PREFIX_UNKNOWN;
|
||||
//} else if (imm - 128 == VFPU_CTRL_DPREFIX) {
|
||||
// js.prefixDFlag = JitState::PREFIX_UNKNOWN;
|
||||
//}
|
||||
} else {
|
||||
//ERROR
|
||||
_dbg_assert_msg_(CPU,0,"mtv - invalid register");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_Vmtvc(u32 op) {
|
||||
DISABLE;
|
||||
|
||||
int vs = _VS;
|
||||
int imm = op & 0xFF;
|
||||
if (imm >= 128 && imm < 128 + VFPU_CTRL_MAX) {
|
||||
fpr.MapRegV(vs, 0);
|
||||
ADD(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[0]) + (imm - 128) * 4);
|
||||
VSTR(fpr.V(vs), R0, 0);
|
||||
fpr.ReleaseSpillLocks();
|
||||
|
||||
if (imm - 128 == VFPU_CTRL_SPREFIX) {
|
||||
js.prefixSFlag = ArmJitState::PREFIX_UNKNOWN;
|
||||
} else if (imm - 128 == VFPU_CTRL_TPREFIX) {
|
||||
js.prefixTFlag = ArmJitState::PREFIX_UNKNOWN;
|
||||
} else if (imm - 128 == VFPU_CTRL_DPREFIX) {
|
||||
js.prefixDFlag = ArmJitState::PREFIX_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_Vmmov(u32 op) {
|
||||
|
||||
+94
-25
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "ArmRegCache.h"
|
||||
#include "ArmJit.h"
|
||||
#include "CPUDetect.h"
|
||||
|
||||
#include "../../../ext/disarm.h"
|
||||
|
||||
@@ -55,24 +56,60 @@ void DisassembleArm(const u8 *data, int size) {
|
||||
namespace MIPSComp
|
||||
{
|
||||
|
||||
Jit::Jit(MIPSState *mips) : blocks(mips), gpr(mips), mips_(mips)
|
||||
Jit::Jit(MIPSState *mips) : blocks(mips), gpr(mips), fpr(mips), mips_(mips)
|
||||
{
|
||||
blocks.Init();
|
||||
gpr.SetEmitter(this);
|
||||
//fpr.SetEmitter(this);
|
||||
fpr.SetEmitter(this);
|
||||
AllocCodeSpace(1024 * 1024 * 16); // 32MB is the absolute max because that's what an ARM branch instruction can reach, backwards and forwards.
|
||||
GenerateFixedCode();
|
||||
|
||||
js.startDefaultPrefix = true;
|
||||
}
|
||||
|
||||
void Jit::DoState(PointerWrap &p)
|
||||
{
|
||||
p.Do(js.startDefaultPrefix);
|
||||
p.DoMarker("Jit");
|
||||
}
|
||||
|
||||
// This is here so the savestate matches between jit and non-jit.
|
||||
void Jit::DoDummyState(PointerWrap &p)
|
||||
{
|
||||
bool dummy = false;
|
||||
p.Do(dummy);
|
||||
p.DoMarker("Jit");
|
||||
}
|
||||
|
||||
void Jit::FlushAll()
|
||||
{
|
||||
gpr.FlushAll();
|
||||
//fpr.Flush(FLUSH_ALL);
|
||||
fpr.FlushAll();
|
||||
FlushPrefixV();
|
||||
}
|
||||
|
||||
void Jit::FlushPrefixV()
|
||||
{
|
||||
if ((js.prefixSFlag & ArmJitState::PREFIX_DIRTY) != 0)
|
||||
{
|
||||
MOVI2R(R0, js.prefixS);
|
||||
STR(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[VFPU_CTRL_SPREFIX]));
|
||||
js.prefixSFlag = (ArmJitState::PrefixState) (js.prefixSFlag & ~ArmJitState::PREFIX_DIRTY);
|
||||
}
|
||||
|
||||
if ((js.prefixTFlag & ArmJitState::PREFIX_DIRTY) != 0)
|
||||
{
|
||||
MOVI2R(R0, js.prefixT);
|
||||
STR(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[VFPU_CTRL_TPREFIX]));
|
||||
js.prefixTFlag = (ArmJitState::PrefixState) (js.prefixTFlag & ~ArmJitState::PREFIX_DIRTY);
|
||||
}
|
||||
|
||||
if ((js.prefixDFlag & ArmJitState::PREFIX_DIRTY) != 0)
|
||||
{
|
||||
MOVI2R(R0, js.prefixD);
|
||||
STR(R0, CTXREG, offsetof(MIPSState, vfpuCtrl[VFPU_CTRL_DPREFIX]));
|
||||
js.prefixDFlag = (ArmJitState::PrefixState) (js.prefixDFlag & ~ArmJitState::PREFIX_DIRTY);
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::ClearCache()
|
||||
@@ -94,6 +131,16 @@ void Jit::CompileAt(u32 addr)
|
||||
MIPSCompileOp(op);
|
||||
}
|
||||
|
||||
void Jit::EatInstruction(u32 op)
|
||||
{
|
||||
u32 info = MIPSGetInfo(op);
|
||||
_dbg_assert_msg_(JIT, !(info & DELAYSLOT), "Never eat a branch op.");
|
||||
_dbg_assert_msg_(JIT, !js.inDelaySlot, "Never eat an instruction inside a delayslot.");
|
||||
|
||||
js.compilerPC += 4;
|
||||
js.downcountAmount += MIPSGetInstructionCycleEstimate(op);
|
||||
}
|
||||
|
||||
void Jit::CompileDelaySlot(int flags)
|
||||
{
|
||||
// preserve flag around the delay slot! Maybe this is not always necessary on ARM where
|
||||
@@ -123,6 +170,17 @@ void Jit::Compile(u32 em_address)
|
||||
int block_num = blocks.AllocateBlock(em_address);
|
||||
ArmJitBlock *b = blocks.GetBlock(block_num);
|
||||
blocks.FinalizeBlock(block_num, jo.enableBlocklink, DoJit(em_address, b));
|
||||
|
||||
// Drat. The VFPU hit an uneaten prefix at the end of a block.
|
||||
if (js.startDefaultPrefix && js.MayHavePrefix())
|
||||
{
|
||||
js.startDefaultPrefix = false;
|
||||
// Our assumptions are all wrong so it's clean-slate time.
|
||||
ClearCache();
|
||||
|
||||
// Let's try that one more time. We won't get back here because we toggled the value.
|
||||
Compile(em_address);
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::RunLoopUntil(u64 globalticks)
|
||||
@@ -130,6 +188,8 @@ void Jit::RunLoopUntil(u64 globalticks)
|
||||
// TODO: copy globalticks somewhere
|
||||
((void (*)())enterCode)();
|
||||
}
|
||||
static int dontLogBlocks = 20;
|
||||
int logBlocks = 40;
|
||||
|
||||
const u8 *Jit::DoJit(u32 em_address, ArmJitBlock *b)
|
||||
{
|
||||
@@ -139,14 +199,14 @@ const u8 *Jit::DoJit(u32 em_address, ArmJitBlock *b)
|
||||
js.curBlock = b;
|
||||
js.compiling = true;
|
||||
js.inDelaySlot = false;
|
||||
js.PrefixStart();
|
||||
|
||||
// We add a check before the block, used when entering from a linked block.
|
||||
b->checkedEntry = GetCodePtr();
|
||||
// Downcount flag check. The last block decremented downcounter, and the flag should still be available.
|
||||
SetCC(CC_LT);
|
||||
MOVI2R(R0, js.blockStart);
|
||||
MovToPC(R0);
|
||||
B((const void *)outerLoop);
|
||||
B((const void *)outerLoopPCInR0);
|
||||
SetCC(CC_AL);
|
||||
|
||||
b->normalEntry = GetCodePtr();
|
||||
@@ -154,39 +214,45 @@ const u8 *Jit::DoJit(u32 em_address, ArmJitBlock *b)
|
||||
MIPSAnalyst::AnalysisResults analysis; // = MIPSAnalyst::Analyze(em_address);
|
||||
|
||||
gpr.Start(analysis);
|
||||
fpr.Start(analysis);
|
||||
|
||||
int numInstructions = 0;
|
||||
int cycles = 0;
|
||||
static int dontLogBlocks = 20;
|
||||
static int logBlocks = 40;
|
||||
int partialFlushOffset = 0;
|
||||
if (logBlocks > 0) logBlocks--;
|
||||
if (dontLogBlocks > 0) dontLogBlocks--;
|
||||
|
||||
#define LOGASM
|
||||
// #define LOGASM
|
||||
#ifdef LOGASM
|
||||
char temp[256];
|
||||
#endif
|
||||
while (js.compiling)
|
||||
{
|
||||
gpr.SetCompilerPC(js.compilerPC); // Let it know for log messages
|
||||
fpr.SetCompilerPC(js.compilerPC);
|
||||
u32 inst = Memory::Read_Instruction(js.compilerPC);
|
||||
#ifdef LOGASM
|
||||
if (logBlocks > 0 && dontLogBlocks == 0) {
|
||||
MIPSDisAsm(inst, js.compilerPC, temp, true);
|
||||
INFO_LOG(DYNA_REC, "M: %08x %s", js.compilerPC, temp);
|
||||
}
|
||||
#endif
|
||||
js.downcountAmount += MIPSGetInstructionCycleEstimate(inst);
|
||||
|
||||
MIPSCompileOp(inst);
|
||||
// FlushAll(); ///HACKK
|
||||
|
||||
js.compilerPC += 4;
|
||||
numInstructions++;
|
||||
if (!cpu_info.bArmV7 && (GetCodePtr() - b->checkedEntry - partialFlushOffset) > 4020)
|
||||
{
|
||||
// We need to prematurely flush as we are out of range
|
||||
FixupBranch skip = B_CC(CC_AL);
|
||||
FlushLitPool();
|
||||
SetJumpTarget(skip);
|
||||
partialFlushOffset = GetCodePtr() - b->checkedEntry;
|
||||
}
|
||||
}
|
||||
FlushLitPool();
|
||||
#ifdef LOGASM
|
||||
if (logBlocks > 0 && dontLogBlocks == 0) {
|
||||
MIPSDisAsm(Memory::Read_Instruction(js.compilerPC), js.compilerPC, temp, true);
|
||||
INFO_LOG(DYNA_REC, "M: %08x %s", js.compilerPC, temp);
|
||||
for (u32 cpc = em_address; cpc != js.compilerPC + 4; cpc += 4) {
|
||||
MIPSDisAsm(Memory::Read_Instruction(cpc), cpc, temp, true);
|
||||
INFO_LOG(DYNA_REC, "M: %08x %s", cpc, temp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -224,31 +290,35 @@ void Jit::Comp_Generic(u32 op)
|
||||
MOVI2R(R0, op);
|
||||
QuickCallFunction(R1, (void *)func);
|
||||
}
|
||||
|
||||
// Might have eaten prefixes, hard to tell...
|
||||
if ((MIPSGetInfo(op) & IS_VFPU) != 0)
|
||||
js.PrefixStart();
|
||||
}
|
||||
|
||||
void Jit::MovFromPC(ARMReg r) {
|
||||
LDR(r, R10, offsetof(MIPSState, pc));
|
||||
LDR(r, CTXREG, offsetof(MIPSState, pc));
|
||||
}
|
||||
|
||||
void Jit::MovToPC(ARMReg r) {
|
||||
STR(R10, r, offsetof(MIPSState, pc));
|
||||
STR(r, CTXREG, offsetof(MIPSState, pc));
|
||||
}
|
||||
|
||||
void Jit::WriteDownCount(int offset)
|
||||
{
|
||||
int theDowncount = js.downcountAmount + offset;
|
||||
LDR(R1, R10, offsetof(MIPSState, downcount));
|
||||
LDR(R1, CTXREG, offsetof(MIPSState, downcount));
|
||||
Operand2 op2;
|
||||
if (TryMakeOperand2(theDowncount, op2)) // We can enlarge this if we used rotations
|
||||
{
|
||||
SUBS(R1, R1, op2);
|
||||
STR(R10, R1, offsetof(MIPSState, downcount));
|
||||
STR(R1, CTXREG, offsetof(MIPSState, downcount));
|
||||
} else {
|
||||
// Should be fine to use R2 here, flushed the regcache anyway.
|
||||
// If js.downcountAmount can be expressed as an Imm8, we don't need this anyway.
|
||||
MOVI2R(R2, theDowncount);
|
||||
SUBS(R1, R1, R2);
|
||||
STR(R10, R1, offsetof(MIPSState, downcount));
|
||||
STR(R1, CTXREG, offsetof(MIPSState, downcount));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,8 +342,7 @@ void Jit::WriteExit(u32 destination, int exit_num)
|
||||
b->linkStatus[exit_num] = true;
|
||||
} else {
|
||||
MOVI2R(R0, destination);
|
||||
MovToPC(R0);
|
||||
B((const void *)dispatcher);
|
||||
B((const void *)dispatcherPCInR0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +373,7 @@ void Jit::Comp_DoNothing(u32 op) { }
|
||||
#define _FS ((op>>11) & 0x1F)
|
||||
#define _FT ((op>>16) & 0x1F)
|
||||
#define _FD ((op>>6) & 0x1F)
|
||||
#define _POS ((op>>6) & 0x1F)
|
||||
#define _POS ((op>>6) & 0x1F)
|
||||
#define _SIZE ((op>>11) & 0x1F)
|
||||
|
||||
//memory regions:
|
||||
|
||||
+94
-4
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "ArmJitCache.h"
|
||||
#include "ArmRegCache.h"
|
||||
#include "ArmRegCacheFPU.h"
|
||||
#include "ArmAsm.h"
|
||||
|
||||
namespace MIPSComp
|
||||
@@ -38,6 +39,14 @@ struct ArmJitOptions
|
||||
|
||||
struct ArmJitState
|
||||
{
|
||||
enum PrefixState
|
||||
{
|
||||
PREFIX_UNKNOWN = 0x00,
|
||||
PREFIX_KNOWN = 0x01,
|
||||
PREFIX_DIRTY = 0x10,
|
||||
PREFIX_KNOWN_DIRTY = 0x11,
|
||||
};
|
||||
|
||||
u32 compilerPC;
|
||||
u32 blockStart;
|
||||
bool cancel;
|
||||
@@ -45,6 +54,66 @@ struct ArmJitState
|
||||
int downcountAmount;
|
||||
bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block
|
||||
ArmJitBlock *curBlock;
|
||||
|
||||
// VFPU prefix magic
|
||||
bool startDefaultPrefix;
|
||||
u32 prefixS;
|
||||
u32 prefixT;
|
||||
u32 prefixD;
|
||||
PrefixState prefixSFlag;
|
||||
PrefixState prefixTFlag;
|
||||
PrefixState prefixDFlag;
|
||||
void PrefixStart() {
|
||||
if (startDefaultPrefix) {
|
||||
EatPrefix();
|
||||
} else {
|
||||
PrefixUnknown();
|
||||
}
|
||||
}
|
||||
void PrefixUnknown() {
|
||||
prefixSFlag = PREFIX_UNKNOWN;
|
||||
prefixTFlag = PREFIX_UNKNOWN;
|
||||
prefixDFlag = PREFIX_UNKNOWN;
|
||||
}
|
||||
bool MayHavePrefix() const {
|
||||
if (HasUnknownPrefix()) {
|
||||
return true;
|
||||
} else if (prefixS != 0xE4 || prefixT != 0xE4 || prefixD != 0) {
|
||||
return true;
|
||||
} else if (VfpuWriteMask() != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool HasUnknownPrefix() const {
|
||||
if (!(prefixSFlag & PREFIX_KNOWN) || !(prefixTFlag & PREFIX_KNOWN) || !(prefixDFlag & PREFIX_KNOWN)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void EatPrefix() {
|
||||
if ((prefixSFlag & PREFIX_KNOWN) == 0 || prefixS != 0xE4) {
|
||||
prefixSFlag = PREFIX_KNOWN_DIRTY;
|
||||
prefixS = 0xE4;
|
||||
}
|
||||
if ((prefixTFlag & PREFIX_KNOWN) == 0 || prefixT != 0xE4) {
|
||||
prefixTFlag = PREFIX_KNOWN_DIRTY;
|
||||
prefixT = 0xE4;
|
||||
}
|
||||
if ((prefixDFlag & PREFIX_KNOWN) == 0 || prefixD != 0x0 || VfpuWriteMask() != 0) {
|
||||
prefixDFlag = PREFIX_KNOWN_DIRTY;
|
||||
prefixD = 0x0;
|
||||
}
|
||||
}
|
||||
u8 VfpuWriteMask() const {
|
||||
_assert_(prefixDFlag & PREFIX_KNOWN);
|
||||
return (prefixD >> 8) & 0xF;
|
||||
}
|
||||
bool VfpuWriteMask(int i) const {
|
||||
_assert_(prefixDFlag & PREFIX_KNOWN);
|
||||
return (prefixD >> (8 + i)) & 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -65,6 +134,7 @@ class Jit : public ArmGen::ARMXCodeBlock
|
||||
public:
|
||||
Jit(MIPSState *mips);
|
||||
void DoState(PointerWrap &p);
|
||||
static void DoDummyState(PointerWrap &p);
|
||||
|
||||
// Compiled ops should ignore delay slots
|
||||
// the compiler will take care of them by itself
|
||||
@@ -78,6 +148,7 @@ public:
|
||||
|
||||
void CompileDelaySlot(int flags);
|
||||
void CompileAt(u32 addr);
|
||||
void EatInstruction(u32 op);
|
||||
void Comp_RunBlock(u32 op);
|
||||
|
||||
// Ops
|
||||
@@ -130,6 +201,7 @@ public:
|
||||
private:
|
||||
void GenerateFixedCode();
|
||||
void FlushAll();
|
||||
void FlushPrefixV();
|
||||
|
||||
void WriteDownCount(int offset = 0);
|
||||
void MovFromPC(ARMReg r);
|
||||
@@ -147,16 +219,32 @@ private:
|
||||
|
||||
// Utilities to reduce duplicated code
|
||||
void CompImmLogic(int rs, int rt, u32 uimm, void (ARMXEmitter::*arith)(ARMReg dst, ARMReg src, Operand2 op2), u32 (*eval)(u32 a, u32 b));
|
||||
void CompType3(int rd, int rs, int rt, void (ARMXEmitter::*arithOp2)(ARMReg dst, ARMReg rm, Operand2 rn), u32 (*eval)(u32 a, u32 b), bool isSub = false);
|
||||
|
||||
void CompShiftImm(u32 op, ArmGen::ShiftType shiftType);
|
||||
void CompShiftVar(u32 op, ArmGen::ShiftType shiftType);
|
||||
|
||||
void LogBlockNumber();
|
||||
/*
|
||||
|
||||
void ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz);
|
||||
void ApplyPrefixD(const u8 *vregs, VectorSize sz);
|
||||
void GetVectorRegsPrefixS(u8 *regs, VectorSize sz, int vectorReg) {
|
||||
_assert_(js.prefixSFlag & ArmJitState::PREFIX_KNOWN);
|
||||
GetVectorRegs(regs, sz, vectorReg);
|
||||
ApplyPrefixST(regs, js.prefixS, sz);
|
||||
}
|
||||
void GetVectorRegsPrefixT(u8 *regs, VectorSize sz, int vectorReg) {
|
||||
_assert_(js.prefixTFlag & ArmJitState::PREFIX_KNOWN);
|
||||
GetVectorRegs(regs, sz, vectorReg);
|
||||
ApplyPrefixST(regs, js.prefixT, sz);
|
||||
}
|
||||
void GetVectorRegsPrefixD(u8 *regs, VectorSize sz, int vectorReg);
|
||||
|
||||
/*
|
||||
void CompImmLogic(u32 op, void (ARMXEmitter::*arith)(int, const OpArg &, const OpArg &));
|
||||
void CompTriArith(u32 op, void (ARMXEmitter::*arith)(int, const OpArg &, const OpArg &));
|
||||
void CompShiftImm(u32 op, void (ARMXEmitter::*shift)(int, OpArg, OpArg));
|
||||
void CompShiftVar(u32 op, void (XEmitter::*shift)(int, OpArg, OpArg));
|
||||
|
||||
void CompFPTriArith(u32 op, void (XEmitter::*arith)(X64Reg reg, OpArg), bool orderMatters);
|
||||
*/
|
||||
|
||||
// Utils
|
||||
@@ -167,7 +255,7 @@ private:
|
||||
ArmJitState js;
|
||||
|
||||
ArmRegCache gpr;
|
||||
// FPURegCache fpr;
|
||||
ArmRegCacheFPU fpr;
|
||||
|
||||
MIPSState *mips_;
|
||||
|
||||
@@ -176,7 +264,9 @@ public:
|
||||
const u8 *enterCode;
|
||||
|
||||
const u8 *outerLoop;
|
||||
const u8 *outerLoopPCInR0;
|
||||
const u8 *dispatcherCheckCoreState;
|
||||
const u8 *dispatcherPCInR0;
|
||||
const u8 *dispatcher;
|
||||
const u8 *dispatcherNoCheck;
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ void ArmJitBlockCache::DestroyBlock(int block_num, bool invalidate)
|
||||
// checkedEntry is the only "linked" entrance so it's enough to overwrite that.
|
||||
ARMXEmitter emit((u8 *)b.checkedEntry);
|
||||
emit.MOVI2R(R0, b.originalAddress);
|
||||
emit.STR(R10, R0, offsetof(MIPSState, pc));
|
||||
emit.STR(R0, CTXREG, offsetof(MIPSState, pc));
|
||||
emit.B(MIPSComp::jit->dispatcher);
|
||||
emit.FlushIcache();
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
using namespace ArmGen;
|
||||
|
||||
#define CTXREG (R10)
|
||||
|
||||
ArmRegCache::ArmRegCache(MIPSState *mips) : mips_(mips) {
|
||||
}
|
||||
|
||||
@@ -30,7 +28,7 @@ void ArmRegCache::Init(ARMXEmitter *emitter) {
|
||||
}
|
||||
|
||||
void ArmRegCache::Start(MIPSAnalyst::AnalysisResults &stats) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int i = 0; i < NUM_ARMREG; i++) {
|
||||
ar[i].mipsReg = -1;
|
||||
ar[i].isDirty = false;
|
||||
}
|
||||
@@ -46,16 +44,18 @@ static const ARMReg *GetMIPSAllocationOrder(int &count) {
|
||||
// Note that R0 is reserved as scratch for now.
|
||||
// R1 could be used as it's only used for scratch outside "regalloc space" now.
|
||||
// R12 is also potentially usable.
|
||||
// R4-R7 are registers we could use for static allocation.
|
||||
// R4-R7 are registers we could use for static allocation or downcount.
|
||||
// R8 is used to preserve flags in nasty branches.
|
||||
// R9 and upwards are reserved for jit basics.
|
||||
static const ARMReg allocationOrder[] = {
|
||||
R2, R3, R4, R5, R6, R7
|
||||
R2, R3, R4, R5, R6, R7, R12,
|
||||
};
|
||||
count = sizeof(allocationOrder) / sizeof(const int);
|
||||
return allocationOrder;
|
||||
}
|
||||
|
||||
// TODO: Somewhat smarter spilling - currently simply spills the first available, should do
|
||||
// round robin or FIFO or something.
|
||||
ARMReg ArmRegCache::MapReg(MIPSReg mipsReg, int mapFlags) {
|
||||
// Let's see if it's already mapped. If so we just need to update the dirty flag.
|
||||
// We don't need to check for ML_NOINIT because we assume that anyone who maps
|
||||
@@ -67,7 +67,7 @@ ARMReg ArmRegCache::MapReg(MIPSReg mipsReg, int mapFlags) {
|
||||
if (mapFlags & MAP_DIRTY) {
|
||||
ar[mr[mipsReg].reg].isDirty = true;
|
||||
}
|
||||
return mr[mipsReg].reg;
|
||||
return (ARMReg)mr[mipsReg].reg;
|
||||
}
|
||||
|
||||
// Okay, not mapped, so we need to allocate an ARM register.
|
||||
@@ -135,16 +135,16 @@ void ArmRegCache::MapInIn(MIPSReg rd, MIPSReg rs) {
|
||||
|
||||
void ArmRegCache::MapDirtyIn(MIPSReg rd, MIPSReg rs, bool avoidLoad) {
|
||||
SpillLock(rd, rs);
|
||||
bool overlap = avoidLoad && rd == rs;
|
||||
MapReg(rd, MAP_DIRTY | (overlap ? 0 : MAP_NOINIT));
|
||||
bool load = !avoidLoad || rd == rs;
|
||||
MapReg(rd, MAP_DIRTY | (load ? 0 : MAP_NOINIT));
|
||||
MapReg(rs);
|
||||
ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
void ArmRegCache::MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoad) {
|
||||
SpillLock(rd, rs, rt);
|
||||
bool overlap = avoidLoad && (rd == rs || rd == rt);
|
||||
MapReg(rd, MAP_DIRTY | (overlap ? 0 : MAP_NOINIT));
|
||||
bool load = !avoidLoad || (rd == rs || rd == rt);
|
||||
MapReg(rd, MAP_DIRTY | (load ? 0 : MAP_NOINIT));
|
||||
MapReg(rt);
|
||||
MapReg(rs);
|
||||
ReleaseSpillLocks();
|
||||
@@ -152,10 +152,10 @@ void ArmRegCache::MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoa
|
||||
|
||||
void ArmRegCache::MapDirtyDirtyInIn(MIPSReg rd1, MIPSReg rd2, MIPSReg rs, MIPSReg rt, bool avoidLoad) {
|
||||
SpillLock(rd1, rd2, rs, rt);
|
||||
bool overlap1 = avoidLoad && (rd1 == rs || rd1 == rt);
|
||||
bool overlap2 = avoidLoad && (rd2 == rs || rd2 == rt);
|
||||
MapReg(rd1, MAP_DIRTY | (overlap1 ? 0 : MAP_NOINIT));
|
||||
MapReg(rd2, MAP_DIRTY | (overlap2 ? 0 : MAP_NOINIT));
|
||||
bool load1 = !avoidLoad || (rd1 == rs || rd1 == rt);
|
||||
bool load2 = !avoidLoad || (rd2 == rs || rd2 == rt);
|
||||
MapReg(rd1, MAP_DIRTY | (load1 ? 0 : MAP_NOINIT));
|
||||
MapReg(rd2, MAP_DIRTY | (load2 ? 0 : MAP_NOINIT));
|
||||
MapReg(rt);
|
||||
MapReg(rs);
|
||||
ReleaseSpillLocks();
|
||||
@@ -168,7 +168,7 @@ void ArmRegCache::FlushArmReg(ARMReg r) {
|
||||
}
|
||||
if (ar[r].mipsReg != -1) {
|
||||
if (ar[r].isDirty && mr[ar[r].mipsReg].loc == ML_ARMREG)
|
||||
emit->STR(CTXREG, r, GetMipsRegOffset(ar[r].mipsReg));
|
||||
emit->STR(r, CTXREG, GetMipsRegOffset(ar[r].mipsReg));
|
||||
// IMMs won't be in an ARM reg.
|
||||
mr[ar[r].mipsReg].loc = ML_MEM;
|
||||
mr[ar[r].mipsReg].reg = INVALID_REG;
|
||||
@@ -180,20 +180,20 @@ void ArmRegCache::FlushArmReg(ARMReg r) {
|
||||
ar[r].mipsReg = -1;
|
||||
}
|
||||
|
||||
void ArmRegCache::FlushMipsReg(MIPSReg r) {
|
||||
void ArmRegCache::FlushR(MIPSReg r) {
|
||||
switch (mr[r].loc) {
|
||||
case ML_IMM:
|
||||
// IMM is always "dirty".
|
||||
emit->MOVI2R(R0, mr[r].imm);
|
||||
emit->STR(CTXREG, R0, GetMipsRegOffset(r));
|
||||
emit->STR(R0, CTXREG, GetMipsRegOffset(r));
|
||||
break;
|
||||
|
||||
case ML_ARMREG:
|
||||
if (mr[r].reg == INVALID_REG) {
|
||||
if (mr[r].reg == (int)INVALID_REG) {
|
||||
ERROR_LOG(HLE, "FlushMipsReg: MipsReg had bad ArmReg");
|
||||
}
|
||||
if (ar[mr[r].reg].isDirty) {
|
||||
emit->STR(CTXREG, mr[r].reg, GetMipsRegOffset(r));
|
||||
emit->STR((ARMReg)mr[r].reg, CTXREG, GetMipsRegOffset(r));
|
||||
ar[mr[r].reg].isDirty = false;
|
||||
}
|
||||
ar[mr[r].reg].mipsReg = -1;
|
||||
@@ -214,7 +214,7 @@ void ArmRegCache::FlushMipsReg(MIPSReg r) {
|
||||
|
||||
void ArmRegCache::FlushAll() {
|
||||
for (int i = 0; i < NUM_MIPSREG; i++) {
|
||||
FlushMipsReg(i);
|
||||
FlushR(i);
|
||||
}
|
||||
// Sanity check
|
||||
for (int i = 0; i < NUM_ARMREG; i++) {
|
||||
@@ -225,6 +225,9 @@ void ArmRegCache::FlushAll() {
|
||||
}
|
||||
|
||||
void ArmRegCache::SetImm(MIPSReg r, u32 immVal) {
|
||||
if (r == 0)
|
||||
ERROR_LOG(JIT, "Trying to set immediate %08x to r0", immVal);
|
||||
|
||||
// Zap existing value if cached in a reg
|
||||
if (mr[r].loc == ML_ARMREG) {
|
||||
ar[mr[r].reg].mipsReg = -1;
|
||||
@@ -236,10 +239,12 @@ void ArmRegCache::SetImm(MIPSReg r, u32 immVal) {
|
||||
}
|
||||
|
||||
bool ArmRegCache::IsImm(MIPSReg r) const {
|
||||
if (r == 0) return true;
|
||||
return mr[r].loc == ML_IMM;
|
||||
}
|
||||
|
||||
u32 ArmRegCache::GetImm(MIPSReg r) const {
|
||||
if (r == 0) return 0;
|
||||
if (mr[r].loc != ML_IMM) {
|
||||
ERROR_LOG(JIT, "Trying to get imm from non-imm register %i", r);
|
||||
}
|
||||
@@ -274,7 +279,7 @@ void ArmRegCache::ReleaseSpillLocks() {
|
||||
|
||||
ARMReg ArmRegCache::R(int mipsReg) {
|
||||
if (mr[mipsReg].loc == ML_ARMREG) {
|
||||
return mr[mipsReg].reg;
|
||||
return (ARMReg)mr[mipsReg].reg;
|
||||
} else {
|
||||
ERROR_LOG(JIT, "Reg %i not in arm reg. compilerPC = %08x", mipsReg, compilerPC_);
|
||||
return INVALID_REG; // BAAAD
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
using namespace ArmGen;
|
||||
|
||||
#define CTXREG (R10)
|
||||
|
||||
// R2 to R8: mapped MIPS regs
|
||||
// R9 = code pointers
|
||||
// R10 = MIPS context
|
||||
@@ -53,7 +55,7 @@ struct RegMIPS {
|
||||
RegMIPSLoc loc;
|
||||
// Data (only one of these is used, depending on loc. Could make a union).
|
||||
u32 imm;
|
||||
ARMReg reg;
|
||||
ARMReg reg; // reg index
|
||||
bool spillLock; // if true, this register cannot be spilled.
|
||||
// If loc == ML_MEM, it's back in its location in the CPU context struct.
|
||||
};
|
||||
@@ -91,7 +93,7 @@ public:
|
||||
void MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoad = true);
|
||||
void MapDirtyDirtyInIn(MIPSReg rd1, MIPSReg rd2, MIPSReg rs, MIPSReg rt, bool avoidLoad = true);
|
||||
void FlushArmReg(ARMReg r);
|
||||
void FlushMipsReg(MIPSReg r);
|
||||
void FlushR(MIPSReg r);
|
||||
|
||||
void FlushAll();
|
||||
|
||||
@@ -102,8 +104,9 @@ public:
|
||||
// For better log output only.
|
||||
void SetCompilerPC(u32 compilerPC) { compilerPC_ = compilerPC; }
|
||||
|
||||
private:
|
||||
int GetMipsRegOffset(MIPSReg r);
|
||||
|
||||
private:
|
||||
MIPSState *mips_;
|
||||
ARMXEmitter *emit;
|
||||
u32 compilerPC_;
|
||||
|
||||
@@ -18,3 +18,317 @@
|
||||
#include "Common/ArmEmitter.h"
|
||||
#include "Core/MIPS/ARM/ArmRegCacheFPU.h"
|
||||
|
||||
|
||||
using namespace ArmGen;
|
||||
|
||||
|
||||
ArmRegCacheFPU::ArmRegCacheFPU(MIPSState *mips) : mips_(mips), vr(mr + 32) {
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::Init(ARMXEmitter *emitter) {
|
||||
emit = emitter;
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::Start(MIPSAnalyst::AnalysisResults &stats) {
|
||||
for (int i = 0; i < NUM_ARMFPUREG; i++) {
|
||||
ar[i].mipsReg = -1;
|
||||
ar[i].isDirty = false;
|
||||
}
|
||||
for (int i = 0; i < NUM_MIPSFPUREG; i++) {
|
||||
mr[i].loc = ML_MEM;
|
||||
mr[i].reg = INVALID_REG;
|
||||
mr[i].spillLock = false;
|
||||
mr[i].tempLock = false;
|
||||
}
|
||||
}
|
||||
|
||||
static const ARMReg *GetMIPSAllocationOrder(int &count) {
|
||||
// We conservatively reserve both S0 and S1 as scratch for now.
|
||||
// Will probably really only need one, if that.
|
||||
static const ARMReg allocationOrder[] = {
|
||||
S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15
|
||||
};
|
||||
// With NEON, we'll have many more.
|
||||
static const ARMReg allocationOrderNEON[] = {
|
||||
S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15,
|
||||
S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31
|
||||
};
|
||||
bool useNEON = false; // TODO: Use cpu detect
|
||||
if (useNEON) {
|
||||
count = sizeof(allocationOrderNEON) / sizeof(const int);
|
||||
return allocationOrderNEON;
|
||||
} else {
|
||||
count = sizeof(allocationOrder) / sizeof(const int);
|
||||
return allocationOrder;
|
||||
}
|
||||
}
|
||||
|
||||
ARMReg ArmRegCacheFPU::MapReg(MIPSReg mipsReg, int mapFlags) {
|
||||
// Let's see if it's already mapped. If so we just need to update the dirty flag.
|
||||
// We don't need to check for ML_NOINIT because we assume that anyone who maps
|
||||
// with that flag immediately writes a "known" value to the register.
|
||||
if (mr[mipsReg].loc == ML_ARMREG) {
|
||||
if (ar[mr[mipsReg].reg].mipsReg != mipsReg) {
|
||||
ERROR_LOG(HLE, "Register mapping out of sync! %i", mipsReg);
|
||||
}
|
||||
if (mapFlags & MAP_DIRTY) {
|
||||
ar[mr[mipsReg].reg].isDirty = true;
|
||||
}
|
||||
//INFO_LOG(HLE, "Already mapped %i to %i", mipsReg, mr[mipsReg].reg);
|
||||
return (ARMReg)(mr[mipsReg].reg + S0);
|
||||
}
|
||||
|
||||
// Okay, not mapped, so we need to allocate an ARM register.
|
||||
|
||||
int allocCount;
|
||||
const ARMReg *allocOrder = GetMIPSAllocationOrder(allocCount);
|
||||
|
||||
allocate:
|
||||
for (int i = 0; i < allocCount; i++) {
|
||||
int reg = allocOrder[i] - S0;
|
||||
|
||||
if (ar[reg].mipsReg == -1) {
|
||||
// That means it's free. Grab it, and load the value into it (if requested).
|
||||
ar[reg].isDirty = (mapFlags & MAP_DIRTY) ? true : false;
|
||||
if (!(mapFlags & MAP_NOINIT)) {
|
||||
if (mr[mipsReg].loc == ML_MEM && mipsReg < TEMP0) {
|
||||
emit->VLDR((ARMReg)(reg + S0), CTXREG, GetMipsRegOffset(mipsReg));
|
||||
}
|
||||
}
|
||||
ar[reg].mipsReg = mipsReg;
|
||||
mr[mipsReg].loc = ML_ARMREG;
|
||||
mr[mipsReg].reg = reg;
|
||||
//INFO_LOG(HLE, "Mapped %i to %i", mipsReg, mr[mipsReg].reg);
|
||||
return (ARMReg)(reg + S0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Still nothing. Let's spill a reg and goto 10.
|
||||
// TODO: Use age or something to choose which register to spill?
|
||||
// TODO: Spill dirty regs first? or opposite?
|
||||
int bestToSpill = -1;
|
||||
for (int i = 0; i < allocCount; i++) {
|
||||
int reg = allocOrder[i] - S0;
|
||||
if (ar[reg].mipsReg != -1 && (mr[ar[reg].mipsReg].spillLock || mr[ar[reg].mipsReg].tempLock))
|
||||
continue;
|
||||
bestToSpill = reg;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bestToSpill != -1) {
|
||||
FlushArmReg((ARMReg)(S0 + bestToSpill));
|
||||
goto allocate;
|
||||
}
|
||||
|
||||
// Uh oh, we have all them spilllocked....
|
||||
ERROR_LOG(JIT, "Out of spillable registers at PC %08x!!!", mips_->pc);
|
||||
return INVALID_REG;
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::MapInIn(MIPSReg rd, MIPSReg rs) {
|
||||
SpillLock(rd, rs);
|
||||
MapReg(rd);
|
||||
MapReg(rs);
|
||||
ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::MapDirtyIn(MIPSReg rd, MIPSReg rs, bool avoidLoad) {
|
||||
SpillLock(rd, rs);
|
||||
bool overlap = avoidLoad && rd == rs;
|
||||
MapReg(rd, MAP_DIRTY | (overlap ? 0 : MAP_NOINIT));
|
||||
MapReg(rs);
|
||||
ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoad) {
|
||||
SpillLock(rd, rs, rt);
|
||||
bool overlap = avoidLoad && (rd == rs || rd == rt);
|
||||
MapReg(rd, MAP_DIRTY | (overlap ? 0 : MAP_NOINIT));
|
||||
MapReg(rt);
|
||||
MapReg(rs);
|
||||
ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::SpillLockV(const u8 *v, VectorSize sz) {
|
||||
for (int i = 0; i < GetNumVectorElements(sz); i++) {
|
||||
vr[v[i]].spillLock = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::SpillLockV(int vec, VectorSize sz) {
|
||||
u8 v[4];
|
||||
GetVectorRegs(v, sz, vec);
|
||||
SpillLockV(v, sz);
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::MapRegV(int vreg, int flags) {
|
||||
MapReg(vreg + 32, flags);
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::MapRegsV(int vec, VectorSize sz, int flags) {
|
||||
u8 v[4];
|
||||
GetVectorRegs(v, sz, vec);
|
||||
SpillLockV(v, sz);
|
||||
for (int i = 0; i < GetNumVectorElements(sz); i++) {
|
||||
MapRegV(v[i], flags);
|
||||
}
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::MapRegsV(const u8 *v, VectorSize sz, int flags) {
|
||||
SpillLockV(v, sz);
|
||||
for (int i = 0; i < GetNumVectorElements(sz); i++) {
|
||||
MapRegV(v[i], flags);
|
||||
}
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::FlushArmReg(ARMReg r) {
|
||||
int reg = r - S0;
|
||||
if (ar[reg].mipsReg == -1) {
|
||||
// Nothing to do, reg not mapped.
|
||||
return;
|
||||
}
|
||||
if (ar[reg].mipsReg != -1) {
|
||||
if (ar[reg].isDirty && mr[ar[reg].mipsReg].loc == ML_ARMREG)
|
||||
{
|
||||
//INFO_LOG(HLE, "Flushing ARM reg %i", reg);
|
||||
emit->VSTR(r, CTXREG, GetMipsRegOffset(ar[reg].mipsReg));
|
||||
}
|
||||
// IMMs won't be in an ARM reg.
|
||||
mr[ar[reg].mipsReg].loc = ML_MEM;
|
||||
mr[ar[reg].mipsReg].reg = INVALID_REG;
|
||||
} else {
|
||||
ERROR_LOG(HLE, "Dirty but no mipsreg?");
|
||||
}
|
||||
ar[reg].isDirty = false;
|
||||
ar[reg].mipsReg = -1;
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::FlushR(MIPSReg r) {
|
||||
switch (mr[r].loc) {
|
||||
case ML_IMM:
|
||||
// IMM is always "dirty".
|
||||
// IMM is not allowed for FP (yet).
|
||||
ERROR_LOG(HLE, "Imm in FP register?");
|
||||
break;
|
||||
|
||||
case ML_ARMREG:
|
||||
if (mr[r].reg == (int)INVALID_REG) {
|
||||
ERROR_LOG(HLE, "FlushR: MipsReg had bad ArmReg");
|
||||
}
|
||||
if (ar[mr[r].reg].isDirty) {
|
||||
//INFO_LOG(HLE, "Flushing dirty reg %i", mr[r].reg);
|
||||
emit->VSTR((ARMReg)(mr[r].reg + S0), CTXREG, GetMipsRegOffset(r));
|
||||
ar[mr[r].reg].isDirty = false;
|
||||
}
|
||||
ar[mr[r].reg].mipsReg = -1;
|
||||
break;
|
||||
|
||||
case ML_MEM:
|
||||
// Already there, nothing to do.
|
||||
break;
|
||||
|
||||
default:
|
||||
//BAD
|
||||
break;
|
||||
}
|
||||
mr[r].loc = ML_MEM;
|
||||
mr[r].reg = (int)INVALID_REG;
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::DiscardR(MIPSReg r) {
|
||||
switch (mr[r].loc) {
|
||||
case ML_IMM:
|
||||
// IMM is always "dirty".
|
||||
// IMM is not allowed for FP (yet).
|
||||
ERROR_LOG(HLE, "Imm in FP register?");
|
||||
break;
|
||||
|
||||
case ML_ARMREG:
|
||||
if (mr[r].reg == (int)INVALID_REG) {
|
||||
ERROR_LOG(HLE, "DiscardR: MipsReg had bad ArmReg");
|
||||
}
|
||||
// Note that we DO NOT write it back here. That's the whole point of Discard.
|
||||
ar[mr[r].reg].isDirty = false;
|
||||
ar[mr[r].reg].mipsReg = -1;
|
||||
break;
|
||||
|
||||
case ML_MEM:
|
||||
// Already there, nothing to do.
|
||||
break;
|
||||
|
||||
default:
|
||||
//BAD
|
||||
break;
|
||||
}
|
||||
mr[r].loc = ML_MEM;
|
||||
mr[r].reg = (int)INVALID_REG;
|
||||
mr[r].tempLock = false;
|
||||
// spill lock?
|
||||
}
|
||||
|
||||
|
||||
bool ArmRegCacheFPU::IsTempX(ARMReg r) const {
|
||||
return ar[r - S0].mipsReg >= TEMP0;
|
||||
}
|
||||
|
||||
int ArmRegCacheFPU::GetTempR() {
|
||||
for (int r = TEMP0; r < TEMP0 + NUM_TEMPS; ++r) {
|
||||
if (mr[r].loc == ML_MEM && !mr[r].tempLock) {
|
||||
mr[r].tempLock = true;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
_assert_msg_(DYNA_REC, 0, "Regcache ran out of temp regs, might need to DiscardR() some.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void ArmRegCacheFPU::FlushAll() {
|
||||
// Discard temps!
|
||||
for (int i = TEMP0; i < TEMP0 + NUM_TEMPS; i++) {
|
||||
DiscardR(i);
|
||||
}
|
||||
for (int i = 0; i < NUM_MIPSFPUREG; i++) {
|
||||
FlushR(i);
|
||||
}
|
||||
// Sanity check
|
||||
for (int i = 0; i < NUM_ARMFPUREG; i++) {
|
||||
if (ar[i].mipsReg != -1) {
|
||||
ERROR_LOG(JIT, "Flush fail: ar[%i].mipsReg=%i", i, ar[i].mipsReg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ArmRegCacheFPU::GetMipsRegOffset(MIPSReg r) {
|
||||
// These are offsets within the MIPSState structure. First there are the GPRS, then FPRS, then the "VFPURs".
|
||||
if (r < 32 + 128 + NUM_TEMPS)
|
||||
return (r + 32) << 2;
|
||||
ERROR_LOG(JIT, "bad mips register %i", r);
|
||||
return 0; // or what?
|
||||
}
|
||||
|
||||
void ArmRegCacheFPU::SpillLock(MIPSReg r1, MIPSReg r2, MIPSReg r3, MIPSReg r4) {
|
||||
mr[r1].spillLock = true;
|
||||
if (r2 != -1) mr[r2].spillLock = true;
|
||||
if (r3 != -1) mr[r3].spillLock = true;
|
||||
if (r4 != -1) mr[r4].spillLock = true;
|
||||
}
|
||||
|
||||
// This is actually pretty slow with all the 160 regs...
|
||||
void ArmRegCacheFPU::ReleaseSpillLocks() {
|
||||
for (int i = 0; i < NUM_MIPSFPUREG; i++)
|
||||
mr[i].spillLock = false;
|
||||
for (int i = TEMP0; i < TEMP0 + NUM_TEMPS; ++i)
|
||||
DiscardR(i);
|
||||
}
|
||||
|
||||
ARMReg ArmRegCacheFPU::R(int mipsReg) {
|
||||
if (mr[mipsReg].loc == ML_ARMREG) {
|
||||
return (ARMReg)(mr[mipsReg].reg + S0);
|
||||
} else {
|
||||
ERROR_LOG(JIT, "Reg %i not in arm reg. compilerPC = %08x", mipsReg, compilerPC_);
|
||||
return INVALID_REG; // BAAAD
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,119 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../MIPS.h"
|
||||
#include "../MIPSAnalyst.h"
|
||||
#include "Common/ArmEmitter.h"
|
||||
#include "Core/MIPS/ARM/ArmRegCache.h"
|
||||
#include "Core/MIPS/MIPSVFPUUtils.h"
|
||||
|
||||
using namespace ArmGen;
|
||||
|
||||
enum {
|
||||
NUM_TEMPS = 16,
|
||||
TEMP0 = 32 + 128,
|
||||
TOTAL_MAPPABLE_MIPSFPUREGS = 32 + 128 + NUM_TEMPS,
|
||||
};
|
||||
|
||||
struct FPURegARM {
|
||||
int mipsReg; // if -1, no mipsreg attached.
|
||||
bool isDirty; // Should the register be written back?
|
||||
};
|
||||
|
||||
struct FPURegMIPS {
|
||||
// Where is this MIPS register?
|
||||
RegMIPSLoc loc;
|
||||
// Data (only one of these is used, depending on loc. Could make a union).
|
||||
int reg;
|
||||
bool spillLock; // if true, this register cannot be spilled.
|
||||
bool tempLock;
|
||||
// If loc == ML_MEM, it's back in its location in the CPU context struct.
|
||||
};
|
||||
|
||||
|
||||
// The PSP has 160 FP registers: 32 FPRs + 128 VFPU registers.
|
||||
|
||||
|
||||
class FPURegCache {
|
||||
class ArmRegCacheFPU
|
||||
{
|
||||
public:
|
||||
ArmRegCacheFPU(MIPSState *mips);
|
||||
~ArmRegCacheFPU() {}
|
||||
|
||||
};
|
||||
void Init(ARMXEmitter *emitter);
|
||||
void Start(MIPSAnalyst::AnalysisResults &stats);
|
||||
|
||||
// Protect the arm register containing a MIPS register from spilling, to ensure that
|
||||
// it's being kept allocated.
|
||||
void SpillLock(MIPSReg reg, MIPSReg reg2 = -1, MIPSReg reg3 = -1, MIPSReg reg4 = -1);
|
||||
void SpillLockV(MIPSReg r) { SpillLock(r + 32); }
|
||||
|
||||
void ReleaseSpillLocks();
|
||||
void ReleaseSpillLock(int mipsreg)
|
||||
{
|
||||
mr[mipsreg].spillLock = false;
|
||||
}
|
||||
void ReleaseSpillLockV(int mipsreg) {
|
||||
ReleaseSpillLock(mipsreg + 32);
|
||||
}
|
||||
|
||||
void SetImm(MIPSReg reg, u32 immVal);
|
||||
bool IsImm(MIPSReg reg) const;
|
||||
u32 GetImm(MIPSReg reg) const;
|
||||
|
||||
// Returns an ARM register containing the requested MIPS register.
|
||||
ARMReg MapReg(MIPSReg reg, int mapFlags = 0);
|
||||
void MapInIn(MIPSReg rd, MIPSReg rs);
|
||||
void MapDirty(MIPSReg rd);
|
||||
void MapDirtyIn(MIPSReg rd, MIPSReg rs, bool avoidLoad = true);
|
||||
void MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoad = true);
|
||||
void FlushArmReg(ARMReg r);
|
||||
void FlushR(MIPSReg r);
|
||||
void FlushV(MIPSReg r) { FlushR(r + 32); }
|
||||
void DiscardR(MIPSReg r);
|
||||
void DiscardV(MIPSReg r) { DiscardR(r + 32);}
|
||||
bool IsTempX(ARMReg r) const;
|
||||
|
||||
MIPSReg GetTempR();
|
||||
MIPSReg GetTempV() { return GetTempR() - 32; }
|
||||
|
||||
void FlushAll();
|
||||
|
||||
ARMReg R(int preg); // Returns a cached register
|
||||
|
||||
// VFPU registers
|
||||
|
||||
ARMReg V(int vreg) { return R(vreg + 32); }
|
||||
|
||||
void MapRegV(int vreg, int flags = 0);
|
||||
|
||||
// NOTE: These require you to release spill locks manually!
|
||||
void MapRegsV(int vec, VectorSize vsz, int flags);
|
||||
void MapRegsV(const u8 *v, VectorSize vsz, int flags);
|
||||
|
||||
void SpillLockV(const u8 *v, VectorSize vsz);
|
||||
void SpillLockV(int vec, VectorSize vsz);
|
||||
|
||||
void SetEmitter(ARMXEmitter *emitter) { emit = emitter; }
|
||||
|
||||
// For better log output only.
|
||||
void SetCompilerPC(u32 compilerPC) { compilerPC_ = compilerPC; }
|
||||
|
||||
int GetMipsRegOffset(MIPSReg r);
|
||||
int GetMipsRegOffsetV(MIPSReg r) {
|
||||
return GetMipsRegOffset(r + 32);
|
||||
}
|
||||
|
||||
private:
|
||||
MIPSState *mips_;
|
||||
ARMXEmitter *emit;
|
||||
u32 compilerPC_;
|
||||
|
||||
enum {
|
||||
NUM_ARMFPUREG = 16, // TODO: Support 32, which you have with NEON
|
||||
NUM_MIPSFPUREG = TOTAL_MAPPABLE_MIPSFPUREGS,
|
||||
};
|
||||
|
||||
RegARM ar[NUM_ARMFPUREG];
|
||||
FPURegMIPS mr[NUM_MIPSFPUREG];
|
||||
FPURegMIPS *vr;
|
||||
};
|
||||
@@ -112,6 +112,8 @@ void MIPSState::DoState(PointerWrap &p)
|
||||
Reset();
|
||||
if (MIPSComp::jit)
|
||||
MIPSComp::jit->DoState(p);
|
||||
else
|
||||
MIPSComp::Jit::DoDummyState(p);
|
||||
|
||||
p.DoArray(r, sizeof(r) / sizeof(r[0]));
|
||||
p.DoArray(f, sizeof(f) / sizeof(f[0]));
|
||||
|
||||
+43
-10
@@ -40,6 +40,22 @@ u32 disPC;
|
||||
|
||||
namespace MIPSDis
|
||||
{
|
||||
// One shot, not re-entrant.
|
||||
const char *SignedHex(int i)
|
||||
{
|
||||
static char temp[32];
|
||||
int offset = 0;
|
||||
if (i < 0)
|
||||
{
|
||||
temp[0] = '-';
|
||||
offset = 1;
|
||||
i = -i;
|
||||
}
|
||||
|
||||
sprintf(&temp[offset], "0x%X", i);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void Dis_Generic(u32 op, char *out)
|
||||
{
|
||||
sprintf(out, "%s\t --- unknown ---", MIPSGetName(op));
|
||||
@@ -76,7 +92,7 @@ namespace MIPSDis
|
||||
int ft = _FT;
|
||||
int rs = _RS;
|
||||
const char *name = MIPSGetName(op);
|
||||
sprintf(out, "%s\t%s, 0x%X(%s)",name,FN(ft),offset,RN(rs));
|
||||
sprintf(out, "%s\t%s, %s(%s)",name,FN(ft),SignedHex(offset),RN(rs));
|
||||
}
|
||||
void Dis_FPUComp(u32 op, char *out)
|
||||
{
|
||||
@@ -147,30 +163,47 @@ namespace MIPSDis
|
||||
|
||||
void Dis_IType(u32 op, char *out)
|
||||
{
|
||||
int imm = (signed short)(op&0xFFFF);
|
||||
s32 simm = (s32)(s16)(op & 0xFFFF);
|
||||
u32 uimm = (u32)(u16)(op & 0xFFFF);
|
||||
u32 suimm = (u32)simm;
|
||||
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
const char *name = MIPSGetName(op);
|
||||
sprintf(out, "%s\t%s, %s, 0x%X",name,RN(rt),RN(rs),imm);
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 8: //addi
|
||||
case 9: //addiu
|
||||
case 10: //slti
|
||||
sprintf(out, "%s\t%s, %s, %s",name,RN(rt),RN(rs),SignedHex(simm));
|
||||
break;
|
||||
case 11: //sltiu
|
||||
sprintf(out, "%s\t%s, %s, 0x%X",name,RN(rt),RN(rs),suimm);
|
||||
break;
|
||||
default:
|
||||
sprintf(out, "%s\t%s, %s, 0x%X",name,RN(rt),RN(rs),uimm);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void Dis_ori(u32 op, char *out)
|
||||
{
|
||||
int imm = (signed short)(op&0xFFFF);
|
||||
s32 simm = (s32)(s16)(op & 0xFFFF);
|
||||
u32 uimm = (u32)(u16)(op & 0xFFFF);
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
const char *name = MIPSGetName(op);
|
||||
if (rs == 0)
|
||||
sprintf(out, "li\t%s, 0x%X",RN(rt),imm);
|
||||
sprintf(out, "li\t%s, 0x%X",RN(rt),uimm);
|
||||
else
|
||||
sprintf(out, "%s\t%s, %s, 0x%X",name,RN(rt),RN(rs),imm);
|
||||
sprintf(out, "%s\t%s, %s, 0x%X",name,RN(rt),RN(rs),uimm);
|
||||
}
|
||||
|
||||
void Dis_IType1(u32 op, char *out)
|
||||
{
|
||||
int imm = (signed short)(op&0xFFFF);
|
||||
u32 uimm = (u32)(u16)(op & 0xFFFF);
|
||||
int rt = _RT;
|
||||
const char *name = MIPSGetName(op);
|
||||
sprintf(out, "%s\t%s, 0x%X",name,RN(rt),imm);
|
||||
sprintf(out, "%s\t%s, 0x%X",name,RN(rt),uimm);
|
||||
}
|
||||
|
||||
void Dis_addi(u32 op, char *out)
|
||||
@@ -179,7 +212,7 @@ namespace MIPSDis
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
if (rs == 0)
|
||||
sprintf(out, "li\t%s, 0x%X",RN(rt),imm);
|
||||
sprintf(out, "li\t%s, %s",RN(rt),SignedHex(imm));
|
||||
else
|
||||
Dis_IType(op,out);
|
||||
}
|
||||
@@ -190,7 +223,7 @@ namespace MIPSDis
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
const char *name = MIPSGetName(op);
|
||||
sprintf(out, "%s\t%s, 0x%X(%s)",name,RN(rt),imm,RN(rs));
|
||||
sprintf(out, "%s\t%s, %s(%s)",name,RN(rt),SignedHex(imm),RN(rs));
|
||||
}
|
||||
|
||||
void Dis_RType2(u32 op, char *out)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "MIPS.h"
|
||||
#include "MIPSInt.h"
|
||||
#include "MIPSTables.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "../HLE/HLE.h"
|
||||
#include "../System.h"
|
||||
@@ -149,6 +150,10 @@ namespace MIPSInt
|
||||
|
||||
// It appears that a cache line is 0x40 (64) bytes.
|
||||
switch (func) {
|
||||
case 24:
|
||||
// "Create Dirty Exclusive" - for avoiding a cacheline fill before writing to it.
|
||||
// Will cause garbage on the real machine so we just ignore it, the app will overwrite the cacheline.
|
||||
break;
|
||||
case 25: // Hit Invalidate - zaps the line if present in cache. Should not writeback???? scary.
|
||||
// No need to do anything.
|
||||
break;
|
||||
@@ -186,6 +191,7 @@ namespace MIPSInt
|
||||
|
||||
void Int_Break(u32 op)
|
||||
{
|
||||
Reporting::ReportMessage("BREAK instruction hit");
|
||||
ERROR_LOG(CPU, "BREAK!");
|
||||
Core_UpdateState(CORE_STEPPING);
|
||||
PC += 4;
|
||||
@@ -505,7 +511,7 @@ namespace MIPSInt
|
||||
void Int_FPULS(u32 op)
|
||||
{
|
||||
s32 offset = (s16)(op&0xFFFF);
|
||||
int ft = ((op>>16)&0x1f);
|
||||
int ft = _FT;
|
||||
int rs = _RS;
|
||||
u32 addr = R(rs) + offset;
|
||||
|
||||
@@ -960,6 +966,7 @@ namespace MIPSInt
|
||||
{
|
||||
case 0:
|
||||
if (!reported) {
|
||||
Reporting::ReportMessage("INTERRUPT instruction hit");
|
||||
WARN_LOG(CPU,"Disable/Enable Interrupt CPU instruction");
|
||||
reported = 1;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
// sv.s
|
||||
|
||||
#include "../Core.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@@ -90,6 +91,9 @@ using std::isinf;
|
||||
#define isnan _isnan
|
||||
#define isinf(x) (!_finite(x) && !_isnan(x))
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
using __captured::isinf;
|
||||
#endif
|
||||
|
||||
// Preserves NaN in first param, takes sign of equal second param.
|
||||
// Technically, std::max may do this but it's undefined.
|
||||
@@ -139,6 +143,7 @@ void ApplyPrefixST(float *v, u32 data, VectorSize size)
|
||||
if (regnum >= n)
|
||||
{
|
||||
ERROR_LOG(CPU, "Invalid VFPU swizzle: %08x / %d", data, size);
|
||||
Reporting::ReportMessage("Invalid VFPU swizzle: %08x / %d", data, size);
|
||||
regnum = 0;
|
||||
}
|
||||
|
||||
@@ -923,6 +928,7 @@ namespace MIPSInt
|
||||
break;
|
||||
default:
|
||||
_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
||||
oz = V_Single;
|
||||
break;
|
||||
}
|
||||
ApplyPrefixD((float*)d,oz);
|
||||
@@ -1601,11 +1607,11 @@ namespace MIPSInt
|
||||
// negative NAN seems different? TODO
|
||||
switch ((op >> 23) & 3) {
|
||||
case 2: // vmin
|
||||
for (int i = 0; i < GetNumVectorElements(sz); i++)
|
||||
for (int i = 0; i < numElements; i++)
|
||||
d[i] = isnan(t[i]) ? s[i] : (isnan(s[i]) ? t[i] : std::min(s[i], t[i]));
|
||||
break;
|
||||
case 3: // vmax
|
||||
for (int i = 0; i < GetNumVectorElements(sz); i++)
|
||||
for (int i = 0; i < numElements; i++)
|
||||
d[i] = isnan(t[i]) ? t[i] : (isnan(s[i]) ? s[i] : std::max(s[i], t[i]));
|
||||
break;
|
||||
default:
|
||||
@@ -1818,22 +1824,26 @@ bad:
|
||||
void Int_Vlgb(u32 op)
|
||||
{
|
||||
// S & D valid
|
||||
Reporting::ReportMessage("vlgb not implemented");
|
||||
_dbg_assert_msg_(CPU,0,"vlgb not implemented");
|
||||
}
|
||||
|
||||
void Int_Vwbn(u32 op)
|
||||
{
|
||||
// S & D valid
|
||||
Reporting::ReportMessage("vwbn not implemented");
|
||||
_dbg_assert_msg_(CPU,0,"vwbn not implemented");
|
||||
}
|
||||
|
||||
void Int_Vsbn(u32 op)
|
||||
{
|
||||
Reporting::ReportMessage("vsbn not implemented");
|
||||
_dbg_assert_msg_(CPU,0,"vsbn not implemented");
|
||||
}
|
||||
|
||||
void Int_Vsbz(u32 op)
|
||||
{
|
||||
Reporting::ReportMessage("vsbz not implemented");
|
||||
_dbg_assert_msg_(CPU,0,"vsbz not implemented");
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,6 @@ void WriteMatrix(const float *rd, MatrixSize size, int reg) {
|
||||
}
|
||||
|
||||
int transpose = (reg>>5)&1;
|
||||
|
||||
if (currentMIPS->VfpuWriteMask() != 0) {
|
||||
ERROR_LOG(CPU, "Write mask used with vfpu matrix instruction.");
|
||||
}
|
||||
|
||||
@@ -55,8 +55,9 @@ namespace MIPSComp
|
||||
void Jit::Comp_IType(u32 op)
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
s32 simm = (s16)(op & 0xFFFF);
|
||||
u32 uimm = (u16)(op & 0xFFFF);
|
||||
s32 simm = (s32)(s16)(op & 0xFFFF); // sign extension
|
||||
u32 uimm = op & 0xFFFF;
|
||||
u32 suimm = (u32)(s32)simm;
|
||||
|
||||
int rt = _RT;
|
||||
int rs = _RS;
|
||||
@@ -68,7 +69,7 @@ namespace MIPSComp
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 8: // same as addiu?
|
||||
case 9: //R(rt) = R(rs) + simm; break; //addiu
|
||||
case 9: // R(rt) = R(rs) + simm; break; //addiu
|
||||
{
|
||||
if (gpr.IsImmediate(rs))
|
||||
{
|
||||
@@ -508,8 +509,14 @@ namespace MIPSComp
|
||||
{
|
||||
CONDITIONAL_DISABLE;
|
||||
int rs = _RS;
|
||||
int rd = _RD;
|
||||
int fd = _FD;
|
||||
// WARNIGN : ROTR
|
||||
|
||||
// noop, won't write to ZERO.
|
||||
if (rd == 0)
|
||||
return;
|
||||
|
||||
// WARNING : ROTR
|
||||
switch (op & 0x3f)
|
||||
{
|
||||
case 0: CompShiftImm(op, &XEmitter::SHL, &ShiftType_ImmLogicalLeft); break;
|
||||
@@ -522,7 +529,6 @@ namespace MIPSComp
|
||||
|
||||
default:
|
||||
Comp_Generic(op);
|
||||
//_dbg_assert_msg_(CPU,0,"Trying to interpret instruction that can't be interpreted");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -532,8 +538,8 @@ namespace MIPSComp
|
||||
CONDITIONAL_DISABLE;
|
||||
int rs = _RS;
|
||||
int rt = _RT;
|
||||
int pos = _POS;
|
||||
|
||||
int pos = _POS;
|
||||
int size = _SIZE + 1;
|
||||
u32 mask = 0xFFFFFFFFUL >> (32 - size);
|
||||
|
||||
@@ -600,6 +606,10 @@ namespace MIPSComp
|
||||
CONDITIONAL_DISABLE
|
||||
int rt = _RT;
|
||||
int rd = _RD;
|
||||
// Don't change $zr.
|
||||
if (rd == 0)
|
||||
return;
|
||||
|
||||
switch ((op >> 6) & 31)
|
||||
{
|
||||
case 16: // seb // R(rd) = (u32)(s32)(s8)(u8)R(rt);
|
||||
|
||||
@@ -409,18 +409,21 @@ void Jit::Comp_Jump(u32 op)
|
||||
}
|
||||
u32 off = ((op & 0x3FFFFFF) << 2);
|
||||
u32 targetAddr = (js.compilerPC & 0xF0000000) | off;
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
FlushAll();
|
||||
|
||||
switch (op >> 26)
|
||||
{
|
||||
case 2: //j
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
FlushAll();
|
||||
CONDITIONAL_LOG_EXIT(targetAddr);
|
||||
WriteExit(targetAddr, 0);
|
||||
break;
|
||||
break;
|
||||
|
||||
case 3: //jal
|
||||
MOV(32, M(&mips_->r[MIPS_REG_RA]), Imm32(js.compilerPC + 8)); // Save return address
|
||||
gpr.BindToRegister(MIPS_REG_RA, false, true);
|
||||
MOV(32, gpr.R(MIPS_REG_RA), Imm32(js.compilerPC + 8)); // Save return address
|
||||
CompileDelaySlot(DELAYSLOT_NICE);
|
||||
FlushAll();
|
||||
CONDITIONAL_LOG_EXIT(targetAddr);
|
||||
WriteExit(targetAddr, 0);
|
||||
break;
|
||||
|
||||
@@ -106,7 +106,7 @@ void Jit::Comp_FPULS(u32 op)
|
||||
|
||||
JitSafeMem safe(this, rs, offset);
|
||||
OpArg src;
|
||||
if (safe.PrepareRead(src))
|
||||
if (safe.PrepareRead(src, 4))
|
||||
MOVSS(fpr.RX(ft), src);
|
||||
if (safe.PrepareSlowRead((void *) &Memory::Read_U32))
|
||||
{
|
||||
@@ -127,7 +127,7 @@ void Jit::Comp_FPULS(u32 op)
|
||||
|
||||
JitSafeMem safe(this, rs, offset);
|
||||
OpArg dest;
|
||||
if (safe.PrepareWrite(dest))
|
||||
if (safe.PrepareWrite(dest, 4))
|
||||
MOVSS(dest, fpr.RX(ft));
|
||||
if (safe.PrepareSlowWrite())
|
||||
{
|
||||
@@ -147,6 +147,7 @@ void Jit::Comp_FPULS(u32 op)
|
||||
}
|
||||
}
|
||||
|
||||
static const u64 GC_ALIGNED16(ssOneBits[2]) = {0x0000000100000001ULL, 0x0000000100000001ULL};
|
||||
static const u64 GC_ALIGNED16(ssSignBits2[2]) = {0x8000000080000000ULL, 0x8000000080000000ULL};
|
||||
static const u64 GC_ALIGNED16(ssNoSignMask[2]) = {0x7FFFFFFF7FFFFFFFULL, 0x7FFFFFFF7FFFFFFFULL};
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace MIPSComp
|
||||
|
||||
JitSafeMem safe(this, rs, offset);
|
||||
OpArg src;
|
||||
if (safe.PrepareRead(src))
|
||||
if (safe.PrepareRead(src, 4))
|
||||
(this->*mov)(32, bits, gpr.RX(rt), src);
|
||||
if (safe.PrepareSlowRead(safeFunc))
|
||||
(this->*mov)(32, bits, gpr.RX(rt), R(EAX));
|
||||
@@ -83,7 +83,7 @@ namespace MIPSComp
|
||||
|
||||
JitSafeMem safe(this, rs, offset);
|
||||
OpArg dest;
|
||||
if (safe.PrepareWrite(dest))
|
||||
if (safe.PrepareWrite(dest, 4))
|
||||
{
|
||||
if (needSwap)
|
||||
{
|
||||
|
||||
+22
-23
@@ -18,12 +18,13 @@
|
||||
#include "../../MemMap.h"
|
||||
#include "../../Config.h"
|
||||
#include "../MIPSAnalyst.h"
|
||||
#include "Core/Reporting.h"
|
||||
|
||||
#include "Jit.h"
|
||||
#include "../MIPSVFPUUtils.h"
|
||||
#include "RegCache.h"
|
||||
|
||||
// VERY UNFINISHED
|
||||
// VERY UNFINISHED!
|
||||
|
||||
// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
|
||||
// Currently known non working ones should have DISABLE.
|
||||
@@ -105,6 +106,7 @@ void Jit::ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz) {
|
||||
// TODO: But some ops seem to use const 0 instead?
|
||||
if (regnum >= n) {
|
||||
ERROR_LOG(CPU, "Invalid VFPU swizzle: %08x / %d", prefix, sz);
|
||||
Reporting::ReportMessage("Invalid VFPU swizzle: %08x / %d", prefix, sz);
|
||||
regnum = 0;
|
||||
}
|
||||
MOVSS(fpr.VX(vregs[i]), fpr.V(origV[regnum]));
|
||||
@@ -208,7 +210,7 @@ void Jit::Comp_SV(u32 op) {
|
||||
JitSafeMem safe(this, rs, imm);
|
||||
safe.SetFar();
|
||||
OpArg src;
|
||||
if (safe.PrepareRead(src))
|
||||
if (safe.PrepareRead(src, 4))
|
||||
{
|
||||
MOVSS(fpr.VX(vt), safe.NextFastAddress(0));
|
||||
}
|
||||
@@ -234,7 +236,7 @@ void Jit::Comp_SV(u32 op) {
|
||||
JitSafeMem safe(this, rs, imm);
|
||||
safe.SetFar();
|
||||
OpArg dest;
|
||||
if (safe.PrepareWrite(dest))
|
||||
if (safe.PrepareWrite(dest, 4))
|
||||
{
|
||||
MOVSS(safe.NextFastAddress(0), fpr.VX(vt));
|
||||
}
|
||||
@@ -276,7 +278,7 @@ void Jit::Comp_SVQ(u32 op)
|
||||
JitSafeMem safe(this, rs, imm);
|
||||
safe.SetFar();
|
||||
OpArg src;
|
||||
if (safe.PrepareRead(src))
|
||||
if (safe.PrepareRead(src, 16))
|
||||
{
|
||||
// Just copy 4 words the easiest way while not wasting registers.
|
||||
for (int i = 0; i < 4; i++)
|
||||
@@ -310,7 +312,7 @@ void Jit::Comp_SVQ(u32 op)
|
||||
JitSafeMem safe(this, rs, imm);
|
||||
safe.SetFar();
|
||||
OpArg dest;
|
||||
if (safe.PrepareWrite(dest))
|
||||
if (safe.PrepareWrite(dest, 16))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
MOVSS(safe.NextFastAddress(i * 4), fpr.VX(vregs[i]));
|
||||
@@ -342,29 +344,26 @@ void Jit::Comp_VVectorInit(u32 op) {
|
||||
if (js.HasUnknownPrefix())
|
||||
DISABLE;
|
||||
|
||||
switch ((op >> 16) & 0xF)
|
||||
{
|
||||
case 6: // v=zeros; break; //vzero
|
||||
MOVSS(XMM0, M((void *) &zero));
|
||||
break;
|
||||
case 7: // v=ones; break; //vone
|
||||
MOVSS(XMM0, M((void *) &one));
|
||||
break;
|
||||
default:
|
||||
DISABLE;
|
||||
break;
|
||||
}
|
||||
|
||||
VectorSize sz = GetVecSize(op);
|
||||
int n = GetNumVectorElements(sz);
|
||||
|
||||
u8 dregs[4];
|
||||
GetVectorRegsPrefixD(dregs, sz, _VD);
|
||||
fpr.MapRegsV(dregs, sz, MAP_NOINIT | MAP_DIRTY);
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
switch ((op >> 16) & 0xF)
|
||||
{
|
||||
case 6: // v=zeros; break; //vzero
|
||||
MOVSS(fpr.VX(dregs[i]), M((void *) &zero));
|
||||
break;
|
||||
case 7: // v=ones; break; //vone
|
||||
MOVSS(fpr.VX(dregs[i]), M((void *) &one));
|
||||
break;
|
||||
default:
|
||||
DISABLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MOVSS(fpr.VX(dregs[i]), R(XMM0));
|
||||
ApplyPrefixD(dregs, sz);
|
||||
|
||||
fpr.ReleaseSpillLocks();
|
||||
@@ -734,4 +733,4 @@ void Jit::Comp_Vmmov(u32 op) {
|
||||
fpr.ReleaseSpillLocks();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+152
-31
@@ -115,6 +115,14 @@ void Jit::DoState(PointerWrap &p)
|
||||
p.DoMarker("Jit");
|
||||
}
|
||||
|
||||
// This is here so the savestate matches between jit and non-jit.
|
||||
void Jit::DoDummyState(PointerWrap &p)
|
||||
{
|
||||
bool dummy = false;
|
||||
p.Do(dummy);
|
||||
p.DoMarker("Jit");
|
||||
}
|
||||
|
||||
void Jit::FlushAll()
|
||||
{
|
||||
gpr.Flush();
|
||||
@@ -240,6 +248,7 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b)
|
||||
js.curBlock = b;
|
||||
js.compiling = true;
|
||||
js.inDelaySlot = false;
|
||||
js.afterOp = JitState::AFTER_NONE;
|
||||
js.PrefixStart();
|
||||
|
||||
// We add a check before the block, used when entering from a linked block.
|
||||
@@ -269,6 +278,22 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b)
|
||||
|
||||
MIPSCompileOp(inst);
|
||||
|
||||
if (js.afterOp & JitState::AFTER_CORE_STATE)
|
||||
{
|
||||
// TODO: Save/restore?
|
||||
FlushAll();
|
||||
CMP(32, M((void*)&coreState), Imm32(0));
|
||||
FixupBranch skipCheck = J_CC(CC_E);
|
||||
if (js.afterOp & JitState::AFTER_REWIND_PC_BAD_STATE)
|
||||
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
||||
else
|
||||
MOV(32, M(&mips_->pc), Imm32(js.compilerPC + 4));
|
||||
WriteSyscallExit();
|
||||
SetJumpTarget(skipCheck);
|
||||
|
||||
js.afterOp = JitState::AFTER_NONE;
|
||||
}
|
||||
|
||||
js.compilerPC += 4;
|
||||
js.numInstructions++;
|
||||
}
|
||||
@@ -314,6 +339,18 @@ void Jit::Comp_Generic(u32 op)
|
||||
|
||||
void Jit::WriteExit(u32 destination, int exit_num)
|
||||
{
|
||||
// If we need to verify coreState and rewind, we may not jump yet.
|
||||
if (js.afterOp & (JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE))
|
||||
{
|
||||
CMP(32, M((void*)&coreState), Imm32(0));
|
||||
FixupBranch skipCheck = J_CC(CC_E);
|
||||
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
||||
WriteSyscallExit();
|
||||
SetJumpTarget(skipCheck);
|
||||
|
||||
js.afterOp = JitState::AFTER_NONE;
|
||||
}
|
||||
|
||||
WriteDowncount();
|
||||
|
||||
//If nobody has taken care of this yet (this can be removed when all branches are done)
|
||||
@@ -338,15 +375,28 @@ void Jit::WriteExitDestInEAX()
|
||||
{
|
||||
// TODO: Some wasted potential, dispatcher will always read this back into EAX.
|
||||
MOV(32, M(&mips_->pc), R(EAX));
|
||||
|
||||
// If we need to verify coreState and rewind, we may not jump yet.
|
||||
if (js.afterOp & (JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE))
|
||||
{
|
||||
CMP(32, M((void*)&coreState), Imm32(0));
|
||||
FixupBranch skipCheck = J_CC(CC_E);
|
||||
MOV(32, M(&mips_->pc), Imm32(js.compilerPC));
|
||||
WriteSyscallExit();
|
||||
SetJumpTarget(skipCheck);
|
||||
|
||||
js.afterOp = JitState::AFTER_NONE;
|
||||
}
|
||||
|
||||
WriteDowncount();
|
||||
|
||||
// Validate the jump to avoid a crash?
|
||||
if (!g_Config.bFastMemory)
|
||||
{
|
||||
CMP(32, R(EAX), Imm32(PSP_GetKernelMemoryBase()));
|
||||
FixupBranch tooLow = J_CC(CC_L);
|
||||
FixupBranch tooLow = J_CC(CC_B);
|
||||
CMP(32, R(EAX), Imm32(PSP_GetUserMemoryEnd()));
|
||||
FixupBranch tooHigh = J_CC(CC_GE);
|
||||
FixupBranch tooHigh = J_CC(CC_AE);
|
||||
|
||||
// Need to set neg flag again if necessary.
|
||||
SUB(32, M(¤tMIPS->downcount), Imm32(0));
|
||||
@@ -401,7 +451,7 @@ Jit::JitSafeMem::JitSafeMem(Jit *jit, int raddr, s32 offset)
|
||||
: jit_(jit), raddr_(raddr), offset_(offset), needsCheck_(false), needsSkip_(false)
|
||||
{
|
||||
// This makes it more instructions, so let's play it safe and say we need a far jump.
|
||||
far_ = !g_Config.bIgnoreBadMemAccess;
|
||||
far_ = !g_Config.bIgnoreBadMemAccess || !CBreakPoints::MemChecks.empty();
|
||||
if (jit_->gpr.IsImmediate(raddr_))
|
||||
iaddr_ = jit_->gpr.GetImmediate32(raddr_) + offset_;
|
||||
else
|
||||
@@ -414,13 +464,16 @@ void Jit::JitSafeMem::SetFar()
|
||||
far_ = true;
|
||||
}
|
||||
|
||||
bool Jit::JitSafeMem::PrepareWrite(OpArg &dest)
|
||||
bool Jit::JitSafeMem::PrepareWrite(OpArg &dest, int size)
|
||||
{
|
||||
size_ = size;
|
||||
// If it's an immediate, we can do the write if valid.
|
||||
if (iaddr_ != (u32) -1)
|
||||
{
|
||||
if (Memory::IsValidAddress(iaddr_))
|
||||
if (ImmValid())
|
||||
{
|
||||
MemCheckImm(MEM_WRITE);
|
||||
|
||||
#ifdef _M_IX86
|
||||
dest = M(Memory::base + (iaddr_ & Memory::MEMVIEW32_MASK));
|
||||
#else
|
||||
@@ -433,16 +486,19 @@ bool Jit::JitSafeMem::PrepareWrite(OpArg &dest)
|
||||
}
|
||||
// Otherwise, we always can do the write (conditionally.)
|
||||
else
|
||||
dest = PrepareMemoryOpArg();
|
||||
dest = PrepareMemoryOpArg(MEM_WRITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Jit::JitSafeMem::PrepareRead(OpArg &src)
|
||||
bool Jit::JitSafeMem::PrepareRead(OpArg &src, int size)
|
||||
{
|
||||
size_ = size;
|
||||
if (iaddr_ != (u32) -1)
|
||||
{
|
||||
if (Memory::IsValidAddress(iaddr_))
|
||||
if (ImmValid())
|
||||
{
|
||||
MemCheckImm(MEM_READ);
|
||||
|
||||
#ifdef _M_IX86
|
||||
src = M(Memory::base + (iaddr_ & Memory::MEMVIEW32_MASK));
|
||||
#else
|
||||
@@ -454,7 +510,7 @@ bool Jit::JitSafeMem::PrepareRead(OpArg &src)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
src = PrepareMemoryOpArg();
|
||||
src = PrepareMemoryOpArg(MEM_READ);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -478,7 +534,7 @@ OpArg Jit::JitSafeMem::NextFastAddress(int suboffset)
|
||||
#endif
|
||||
}
|
||||
|
||||
OpArg Jit::JitSafeMem::PrepareMemoryOpArg()
|
||||
OpArg Jit::JitSafeMem::PrepareMemoryOpArg(ReadType type)
|
||||
{
|
||||
// We may not even need to move into EAX as a temporary.
|
||||
// TODO: Except on x86 in fastmem mode.
|
||||
@@ -493,13 +549,15 @@ OpArg Jit::JitSafeMem::PrepareMemoryOpArg()
|
||||
xaddr_ = EAX;
|
||||
}
|
||||
|
||||
MemCheckAsm(type);
|
||||
|
||||
if (!g_Config.bFastMemory)
|
||||
{
|
||||
// Is it in physical ram?
|
||||
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetKernelMemoryBase() - offset_));
|
||||
tooLow_ = jit_->J_CC(CC_L);
|
||||
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetUserMemoryEnd() - offset_));
|
||||
tooHigh_ = jit_->J_CC(CC_GE);
|
||||
tooLow_ = jit_->J_CC(CC_B);
|
||||
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetUserMemoryEnd() - offset_ - (size_ - 1)));
|
||||
tooHigh_ = jit_->J_CC(CC_AE);
|
||||
|
||||
// We may need to jump back up here.
|
||||
safe_ = jit_->GetCodePtr();
|
||||
@@ -532,9 +590,9 @@ void Jit::JitSafeMem::PrepareSlowAccess()
|
||||
|
||||
// Might also be the scratchpad.
|
||||
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetScratchpadMemoryBase() - offset_));
|
||||
FixupBranch tooLow = jit_->J_CC(CC_L);
|
||||
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetScratchpadMemoryEnd() - offset_));
|
||||
jit_->J_CC(CC_L, safe_);
|
||||
FixupBranch tooLow = jit_->J_CC(CC_B);
|
||||
jit_->CMP(32, R(xaddr_), Imm32(PSP_GetScratchpadMemoryEnd() - offset_ - (size_ - 1)));
|
||||
jit_->J_CC(CC_B, safe_);
|
||||
jit_->SetJumpTarget(tooLow);
|
||||
}
|
||||
|
||||
@@ -542,7 +600,7 @@ bool Jit::JitSafeMem::PrepareSlowWrite()
|
||||
{
|
||||
// If it's immediate, we only need a slow write on invalid.
|
||||
if (iaddr_ != (u32) -1)
|
||||
return !g_Config.bFastMemory && !Memory::IsValidAddress(iaddr_);
|
||||
return !g_Config.bFastMemory && !ImmValid();
|
||||
|
||||
if (!g_Config.bFastMemory)
|
||||
{
|
||||
@@ -571,7 +629,7 @@ bool Jit::JitSafeMem::PrepareSlowRead(void *safeFunc)
|
||||
if (iaddr_ != (u32) -1)
|
||||
{
|
||||
// No slow read necessary.
|
||||
if (Memory::IsValidAddress(iaddr_))
|
||||
if (ImmValid())
|
||||
return false;
|
||||
jit_->MOV(32, R(EAX), Imm32(iaddr_));
|
||||
}
|
||||
@@ -599,7 +657,7 @@ void Jit::JitSafeMem::NextSlowRead(void *safeFunc, int suboffset)
|
||||
|
||||
if (jit_->gpr.IsImmediate(raddr_))
|
||||
{
|
||||
_dbg_assert_msg_(JIT, !Memory::IsValidAddress(iaddr_), "NextSlowRead() for a valid immediate address?");
|
||||
_dbg_assert_msg_(JIT, !Memory::IsValidAddress(iaddr_ + suboffset), "NextSlowRead() for a valid immediate address?");
|
||||
|
||||
jit_->MOV(32, R(EAX), Imm32(iaddr_ + suboffset));
|
||||
}
|
||||
@@ -610,22 +668,85 @@ void Jit::JitSafeMem::NextSlowRead(void *safeFunc, int suboffset)
|
||||
jit_->ABI_CallFunctionA(jit_->thunks.ProtectFunction(safeFunc, 1), R(EAX));
|
||||
}
|
||||
|
||||
bool Jit::JitSafeMem::ImmValid()
|
||||
{
|
||||
return iaddr_ != (u32) -1 && Memory::IsValidAddress(iaddr_) && Memory::IsValidAddress(iaddr_ + size_ - 1);
|
||||
}
|
||||
|
||||
void Jit::JitSafeMem::Finish()
|
||||
{
|
||||
if (needsCheck_)
|
||||
{
|
||||
// Memory::Read_U32/etc. may have tripped coreState.
|
||||
if (!g_Config.bIgnoreBadMemAccess)
|
||||
{
|
||||
jit_->CMP(32, M((void*)&coreState), Imm32(0));
|
||||
FixupBranch skipCheck = jit_->J_CC(CC_E);
|
||||
jit_->MOV(32, M(¤tMIPS->pc), Imm32(jit_->js.compilerPC + 4));
|
||||
jit_->WriteSyscallExit();
|
||||
jit_->SetJumpTarget(skipCheck);
|
||||
}
|
||||
}
|
||||
// Memory::Read_U32/etc. may have tripped coreState.
|
||||
if (needsCheck_ && !g_Config.bIgnoreBadMemAccess)
|
||||
jit_->js.afterOp = JitState::AFTER_CORE_STATE;
|
||||
if (needsSkip_)
|
||||
jit_->SetJumpTarget(skip_);
|
||||
for (auto it = skipChecks_.begin(), end = skipChecks_.end(); it != end; ++it)
|
||||
jit_->SetJumpTarget(*it);
|
||||
}
|
||||
|
||||
void JitMemCheck(u32 addr, int size, int isWrite)
|
||||
{
|
||||
MemCheck *check = CBreakPoints::GetMemCheck(addr, size);
|
||||
if (check)
|
||||
check->Action(addr, isWrite == 1, size, currentMIPS->pc);
|
||||
}
|
||||
|
||||
void Jit::JitSafeMem::MemCheckImm(ReadType type)
|
||||
{
|
||||
MemCheck *check = CBreakPoints::GetMemCheck(iaddr_, size_);
|
||||
if (check)
|
||||
{
|
||||
if (!check->bOnRead && type == MEM_READ)
|
||||
return;
|
||||
if (!check->bOnWrite && type == MEM_WRITE)
|
||||
return;
|
||||
|
||||
jit_->MOV(32, M(&jit_->mips_->pc), Imm32(jit_->js.compilerPC));
|
||||
jit_->ABI_CallFunctionCCC(jit_->thunks.ProtectFunction((void *)&JitMemCheck, 3), iaddr_, size_, type == MEM_WRITE ? 1 : 0);
|
||||
|
||||
jit_->CMP(32, M((void*)&coreState), Imm32(0));
|
||||
skipChecks_.push_back(jit_->J_CC(CC_NE, true));
|
||||
jit_->js.afterOp = JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::JitSafeMem::MemCheckAsm(ReadType type)
|
||||
{
|
||||
for (auto it = CBreakPoints::MemChecks.begin(), end = CBreakPoints::MemChecks.end(); it != end; ++it)
|
||||
{
|
||||
if (!it->bOnRead && type == MEM_READ)
|
||||
continue;
|
||||
if (!it->bOnWrite && type == MEM_WRITE)
|
||||
continue;
|
||||
|
||||
FixupBranch skipNext, skipNextRange;
|
||||
if (it->bRange)
|
||||
{
|
||||
jit_->CMP(32, R(xaddr_), Imm32(it->iStartAddress - offset_));
|
||||
skipNext = jit_->J_CC(CC_B);
|
||||
jit_->CMP(32, R(xaddr_), Imm32(it->iEndAddress - offset_ - size_));
|
||||
skipNextRange = jit_->J_CC(CC_AE);
|
||||
}
|
||||
else
|
||||
{
|
||||
jit_->CMP(32, R(xaddr_), Imm32(it->iStartAddress - offset_));
|
||||
skipNext = jit_->J_CC(CC_NE);
|
||||
}
|
||||
|
||||
jit_->PUSH(xaddr_);
|
||||
jit_->MOV(32, M(&jit_->mips_->pc), Imm32(jit_->js.compilerPC));
|
||||
jit_->ADD(32, R(xaddr_), Imm32(offset_));
|
||||
jit_->ABI_CallFunctionACC(jit_->thunks.ProtectFunction((void *)&JitMemCheck, 3), R(xaddr_), size_, type == MEM_WRITE ? 1 : 0);
|
||||
jit_->POP(xaddr_);
|
||||
|
||||
jit_->CMP(32, M((void*)&coreState), Imm32(0));
|
||||
skipChecks_.push_back(jit_->J_CC(CC_NE, true));
|
||||
jit_->js.afterOp = JitState::AFTER_CORE_STATE | JitState::AFTER_REWIND_PC_BAD_STATE;
|
||||
|
||||
jit_->SetJumpTarget(skipNext);
|
||||
if (it->bRange)
|
||||
jit_->SetJumpTarget(skipNextRange);
|
||||
}
|
||||
}
|
||||
|
||||
void Jit::Comp_DoNothing(u32 op) { }
|
||||
|
||||
+24
-3
@@ -56,10 +56,19 @@ struct JitState
|
||||
PREFIX_KNOWN_DIRTY = 0x11,
|
||||
};
|
||||
|
||||
enum AfterOp
|
||||
{
|
||||
AFTER_NONE = 0x00,
|
||||
AFTER_CORE_STATE = 0x01,
|
||||
AFTER_REWIND_PC_BAD_STATE = 0x02,
|
||||
};
|
||||
|
||||
u32 compilerPC;
|
||||
u32 blockStart;
|
||||
bool cancel;
|
||||
bool inDelaySlot;
|
||||
// See JitState::AfterOp for values.
|
||||
int afterOp;
|
||||
int downcountAmount;
|
||||
int numInstructions;
|
||||
bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block
|
||||
@@ -143,6 +152,7 @@ class Jit : public Gen::XCodeBlock
|
||||
public:
|
||||
Jit(MIPSState *mips);
|
||||
void DoState(PointerWrap &p);
|
||||
static void DoDummyState(PointerWrap &p);
|
||||
|
||||
// Compiled ops should ignore delay slots
|
||||
// the compiler will take care of them by itself
|
||||
@@ -268,14 +278,14 @@ private:
|
||||
JitSafeMem(Jit *jit, int raddr, s32 offset);
|
||||
|
||||
// Emit code necessary for a memory write, returns true if MOV to dest is needed.
|
||||
bool PrepareWrite(OpArg &dest);
|
||||
bool PrepareWrite(OpArg &dest, int size);
|
||||
// Emit code proceeding a slow write call, returns true if slow write is needed.
|
||||
bool PrepareSlowWrite();
|
||||
// Emit a slow write from src.
|
||||
void DoSlowWrite(void *safeFunc, const OpArg src, int suboffset = 0);
|
||||
|
||||
// Emit code necessary for a memory read, returns true if MOV from src is needed.
|
||||
bool PrepareRead(OpArg &src);
|
||||
bool PrepareRead(OpArg &src, int size);
|
||||
// Emit code for a slow read call, and returns true if result is in EAX.
|
||||
bool PrepareSlowRead(void *safeFunc);
|
||||
|
||||
@@ -290,18 +300,29 @@ private:
|
||||
void NextSlowRead(void *safeFunc, int suboffset);
|
||||
|
||||
private:
|
||||
OpArg PrepareMemoryOpArg();
|
||||
enum ReadType
|
||||
{
|
||||
MEM_READ,
|
||||
MEM_WRITE,
|
||||
};
|
||||
|
||||
OpArg PrepareMemoryOpArg(ReadType type);
|
||||
void PrepareSlowAccess();
|
||||
void MemCheckImm(ReadType type);
|
||||
void MemCheckAsm(ReadType type);
|
||||
bool ImmValid();
|
||||
|
||||
Jit *jit_;
|
||||
int raddr_;
|
||||
s32 offset_;
|
||||
int size_;
|
||||
bool needsCheck_;
|
||||
bool needsSkip_;
|
||||
bool far_;
|
||||
u32 iaddr_;
|
||||
X64Reg xaddr_;
|
||||
FixupBranch tooLow_, tooHigh_, skip_;
|
||||
std::vector<FixupBranch> skipChecks_;
|
||||
const u8 *safe_;
|
||||
};
|
||||
friend class JitSafeMem;
|
||||
|
||||
@@ -93,6 +93,29 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string)
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT.DAT").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/EBOOT.DAT";
|
||||
}
|
||||
// bypass more patchers
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT.BI").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/EBOOT.BI";
|
||||
}
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT.LLD").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/EBOOT.LLD";
|
||||
}
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/OLD_EBOOT.BIN").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/OLD_EBOOT.BIN";
|
||||
}
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT.123").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/EBOOT.123";
|
||||
}
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/EBOOT_LRC_CH.BIN").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/EBOOT_LRC_CH.BIN";
|
||||
}
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/BOOT0.OLD").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/BOOT0.OLD";
|
||||
}
|
||||
if (pspFileSystem.GetFileInfo("disc0:/PSP_GAME/SYSDIR/BOOT1.OLD").exists) {
|
||||
bootpath = "disc0:/PSP_GAME/SYSDIR/BOOT1.OLD";
|
||||
}
|
||||
|
||||
bool hasEncrypted = false;
|
||||
u32 fd;
|
||||
if ((fd = pspFileSystem.OpenFile(bootpath, FILEACCESS_READ)) != 0)
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
// 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/.
|
||||
|
||||
#include "Common/StdThread.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include "net/http_client.h"
|
||||
#include "net/resolve.h"
|
||||
#include "base/buffer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <cstdarg>
|
||||
|
||||
namespace Reporting
|
||||
{
|
||||
const int DEFAULT_PORT = 80;
|
||||
const u32 SPAM_LIMIT = 100;
|
||||
const int PAYLOAD_BUFFER_SIZE = 100;
|
||||
|
||||
// Internal limiter on number of requests per instance.
|
||||
static u32 spamProtectionCount = 0;
|
||||
// Temporarily stores a reference to the hostname.
|
||||
static std::string lastHostname;
|
||||
|
||||
enum RequestType
|
||||
{
|
||||
MESSAGE,
|
||||
};
|
||||
|
||||
struct Payload
|
||||
{
|
||||
RequestType type;
|
||||
std::string string1;
|
||||
std::string string2;
|
||||
};
|
||||
static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE];
|
||||
static int payloadBufferPos = 0;
|
||||
|
||||
static size_t ServerHostnameLength()
|
||||
{
|
||||
if (g_Config.sReportHost.empty())
|
||||
return g_Config.sReportHost.npos;
|
||||
|
||||
// IPv6 literal?
|
||||
if (g_Config.sReportHost[0] == '[')
|
||||
{
|
||||
size_t length = g_Config.sReportHost.find("]:");
|
||||
if (length != g_Config.sReportHost.npos)
|
||||
++length;
|
||||
return length;
|
||||
}
|
||||
else
|
||||
return g_Config.sReportHost.find(':');
|
||||
}
|
||||
|
||||
static const char *ServerHostname()
|
||||
{
|
||||
if (g_Config.sReportHost.empty())
|
||||
return NULL;
|
||||
// Disabled by default for now.
|
||||
if (g_Config.sReportHost.compare("default") == 0)
|
||||
return NULL;
|
||||
|
||||
size_t length = ServerHostnameLength();
|
||||
if (length == g_Config.sReportHost.npos)
|
||||
return g_Config.sReportHost.c_str();
|
||||
|
||||
lastHostname = g_Config.sReportHost.substr(0, length);
|
||||
return lastHostname.c_str();
|
||||
}
|
||||
|
||||
static int ServerPort()
|
||||
{
|
||||
if (g_Config.sReportHost.empty())
|
||||
return 0;
|
||||
// Disabled by default for now.
|
||||
if (g_Config.sReportHost.compare("default") == 0)
|
||||
return 0;
|
||||
|
||||
size_t offset = ServerHostnameLength();
|
||||
if (offset == g_Config.sReportHost.npos)
|
||||
return DEFAULT_PORT;
|
||||
|
||||
// Skip the colon.
|
||||
std::string port = g_Config.sReportHost.substr(offset + 1);
|
||||
return atoi(port.c_str());
|
||||
}
|
||||
|
||||
// Should only be called once per request.
|
||||
bool CheckSpamLimited()
|
||||
{
|
||||
return ++spamProtectionCount >= SPAM_LIMIT;
|
||||
}
|
||||
|
||||
bool SendReportRequest(const char *uri, const std::string &data, Buffer *output = NULL)
|
||||
{
|
||||
bool result = false;
|
||||
http::Client http;
|
||||
Buffer theVoid;
|
||||
|
||||
if (output == NULL)
|
||||
output = &theVoid;
|
||||
|
||||
net::Init();
|
||||
if (http.Resolve(ServerHostname(), ServerPort()))
|
||||
{
|
||||
http.Connect();
|
||||
http.POST("/report/message", data, "application/x-www-urlencoded", output);
|
||||
http.Disconnect();
|
||||
result = true;
|
||||
}
|
||||
net::Shutdown();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int Process(int pos)
|
||||
{
|
||||
Payload &payload = payloadBuffer[pos];
|
||||
|
||||
const int PARAM_BUFFER_SIZE = 4096;
|
||||
char temp[PARAM_BUFFER_SIZE];
|
||||
|
||||
// TODO: Need to escape these values, add more.
|
||||
snprintf(temp, PARAM_BUFFER_SIZE - 1, "version=%s&game=%s_%s",
|
||||
PPSSPP_GIT_VERSION,
|
||||
g_paramSFO.GetValueString("DISC_ID").c_str(),
|
||||
g_paramSFO.GetValueString("DISC_VERSION").c_str());
|
||||
|
||||
std::string data;
|
||||
switch (payload.type)
|
||||
{
|
||||
case MESSAGE:
|
||||
// TODO: Escape.
|
||||
data = std::string(temp) + "&message=" + payload.string1 + "&value=" + payload.string2;
|
||||
payload.string1.clear();
|
||||
payload.string2.clear();
|
||||
|
||||
SendReportRequest("/report/message", data);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ReportMessage(const char *message, ...)
|
||||
{
|
||||
if (g_Config.sReportHost.empty() || CheckSpamLimited())
|
||||
return;
|
||||
// Disabled by default for now.
|
||||
if (g_Config.sReportHost.compare("default") == 0)
|
||||
return;
|
||||
|
||||
const int MESSAGE_BUFFER_SIZE = 32768;
|
||||
char temp[MESSAGE_BUFFER_SIZE];
|
||||
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
vsnprintf(temp, MESSAGE_BUFFER_SIZE - 1, message, args);
|
||||
temp[MESSAGE_BUFFER_SIZE - 1] = '\0';
|
||||
va_end(args);
|
||||
|
||||
int pos = payloadBufferPos++ % PAYLOAD_BUFFER_SIZE;
|
||||
Payload &payload = payloadBuffer[pos];
|
||||
payload.type = MESSAGE;
|
||||
payload.string1 = message;
|
||||
payload.string2 = temp;
|
||||
|
||||
std::thread th(Process, pos);
|
||||
th.detach();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// 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/.
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
namespace Reporting
|
||||
{
|
||||
void ReportMessage(const char *message, ...);
|
||||
}
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "HLE/sceKernel.h"
|
||||
#include "HLE/sceKernelMemory.h"
|
||||
#include "HLE/sceAudio.h"
|
||||
#include "Config.h"
|
||||
#include "Core.h"
|
||||
#include "CoreTiming.h"
|
||||
#include "CoreParameter.h"
|
||||
@@ -47,6 +48,8 @@ static PSPMixer *mixer;
|
||||
|
||||
bool PSP_Init(const CoreParameter &coreParam, std::string *error_string)
|
||||
{
|
||||
INFO_LOG(HLE, "PPSSPP %s", PPSSPP_GIT_VERSION);
|
||||
|
||||
coreParameter = coreParam;
|
||||
currentCPU = &mipsr4k;
|
||||
numCPUs = 1;
|
||||
|
||||
Loaded 100 of 197 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user