diff --git a/.gitignore b/.gitignore index ce3a06d2d1..3f4019915c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Blackberry/bar-descriptor.xml b/Blackberry/bar-descriptor.xml index 47adeae27f..1a90a982cb 100644 --- a/Blackberry/bar-descriptor.xml +++ b/Blackberry/bar-descriptor.xml @@ -3,8 +3,8 @@ com.Qtness.PPSSPP PPSSPP PPSSPPBlackberry - 0.6.1 - 2 + 0.7.0 + 1 Playstation portable emulator. Qtness @@ -20,6 +20,7 @@ PPSSPPBlackberry icon-114.png assets + assets/flash core.games diff --git a/CMakeLists.txt b/CMakeLists.txt index 960e9f6f0b..ed7d97f5fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $ - 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) diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index afaf6b777b..eabeee915c 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -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; diff --git a/Common/ArmEmitter.cpp b/Common/ArmEmitter.cpp index e4306c0324..7cdc3b4045 100644 --- a/Common/ArmEmitter.cpp +++ b/Common/ArmEmitter.cpp @@ -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::iterator it = currentLitPool.begin(); it != currentLitPool.end(); ++it) { + // Search for duplicates + for(std::vector::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)); + } +} + } diff --git a/Common/ArmEmitter.h b/Common/ArmEmitter.h index e050cd53f4..a31e1753a2 100644 --- a/Common/ArmEmitter.h +++ b/Common/ArmEmitter.h @@ -25,6 +25,7 @@ #if defined(__SYMBIAN32__) || defined(PANDORA) #include #endif +#include #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 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() diff --git a/Common/ArmThunk.cpp b/Common/ArmThunk.cpp index 98cee1683d..207676dca5 100644 --- a/Common/ArmThunk.cpp +++ b/Common/ArmThunk.cpp @@ -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; } diff --git a/Common/CPUDetect.cpp b/Common/CPUDetect.cpp index c43c7fc5d7..62176d6c17 100644 --- a/Common/CPUDetect.cpp +++ b/Common/CPUDetect.cpp @@ -29,14 +29,14 @@ #undef _interlockedbittestandreset64 #else -#ifndef _M_GENERIC +#if !defined(_M_GENERIC) && !defined(MIPS) #include #endif #if defined __FreeBSD__ #include #include -#else +#elif !defined(MIPS) static inline void do_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { diff --git a/Common/Common.h b/Common/Common.h index d87443e3f9..16b0fd342f 100644 --- a/Common/Common.h +++ b/Common/Common.h @@ -25,6 +25,10 @@ #include #include +#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() diff --git a/Common/CommonFuncs.h b/Common/CommonFuncs.h index e256aab5dd..89631e5e74 100644 --- a/Common/CommonFuncs.h +++ b/Common/CommonFuncs.h @@ -24,7 +24,7 @@ #define SLEEP(x) usleep(x*1000) #endif -#ifdef IOS +#if defined(IOS) || defined(MIPS) #include #endif @@ -51,8 +51,8 @@ template<> struct CompileTimeAssert {}; #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 ) ; } diff --git a/Common/Crypto/aes.h b/Common/Crypto/aes.h index 8d5059e1be..c3006a775c 100644 --- a/Common/Crypto/aes.h +++ b/Common/Crypto/aes.h @@ -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, diff --git a/Common/Crypto/aes_cbc.cpp b/Common/Crypto/aes_cbc.cpp index 780c35a88d..954878a5bb 100644 --- a/Common/Crypto/aes_cbc.cpp +++ b/Common/Crypto/aes_cbc.cpp @@ -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) diff --git a/Common/Crypto/aes_core.cpp b/Common/Crypto/aes_core.cpp index ad54bc6006..2bce4429a9 100644 --- a/Common/Crypto/aes_core.cpp +++ b/Common/Crypto/aes_core.cpp @@ -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; diff --git a/Common/Log.h b/Common/Log.h index b027fc2962..c01835df7d 100644 --- a/Common/Log.h +++ b/Common/Log.h @@ -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 @@ -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_) \ diff --git a/Common/LogManager.cpp b/Common/LogManager.cpp index 69d0b3ce01..421a37c1d2 100644 --- a/Common/LogManager.cpp +++ b/Common/LogManager.cpp @@ -26,9 +26,12 @@ #include #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. diff --git a/Common/LogManager.h b/Common/LogManager.h index 20b9130c47..faf94f798a 100644 --- a/Common/LogManager.h +++ b/Common/LogManager.h @@ -30,6 +30,7 @@ #define MAX_MESSAGES 8000 #define MAX_MSGLEN 1024 +extern const char *hleCurrentThreadName; // pure virtual interface class LogListener diff --git a/Common/MathUtil.h b/Common/MathUtil.h index 99e6d77a5c..1f594e4a6a 100644 --- a/Common/MathUtil.h +++ b/Common/MathUtil.h @@ -20,7 +20,7 @@ #include "Common.h" -#ifndef ARM +#if !defined(ARM) && !defined(MIPS) #define USE_SSE #endif diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index a7119b307c..d474ed633e 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -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) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 3706931498..982b314f03 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -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) diff --git a/Core/Config.cpp b/Core/Config.cpp index 1352c3fb0c..f3bdc009c3 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -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); diff --git a/Core/Config.h b/Core/Config.h index 842a93b10c..214addab08 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -20,8 +20,7 @@ #include #include -#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 iMappingMap; // Can be used differently depending on systems diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index ddcc0190f6..7803763a2c 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -1,4 +1,4 @@ - + @@ -74,6 +74,10 @@ true + + ../Windows/git-version-gen.cmd + Updating git-version.cpp + @@ -87,6 +91,10 @@ true + + ../Windows/git-version-gen.cmd + Updating git-version.cpp + @@ -105,6 +113,11 @@ true true + + + ../Windows/git-version-gen.cmd + Updating git-version.cpp + @@ -121,11 +134,16 @@ true true + + ../Windows/git-version-gen.cmd + Updating git-version.cpp + + @@ -145,6 +163,7 @@ + @@ -179,6 +198,8 @@ + + @@ -277,6 +298,7 @@ + @@ -313,6 +335,7 @@ + @@ -347,6 +370,8 @@ + + @@ -410,10 +435,10 @@ + - @@ -440,4 +465,4 @@ - \ No newline at end of file + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index aa18c230f8..56df4f8f97 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -49,6 +49,9 @@ {0b77054f-7fc7-4c33-ada3-762aecde69e5} + + {1c79e88d-1c48-450b-8af6-f22ce7d40c66} + @@ -189,6 +192,9 @@ HLE\Libraries + + HLE\Libraries + HLE\Libraries @@ -376,6 +382,16 @@ MIPS\ARM + + Font + + + + Core + + + HLE\Libraries + @@ -510,6 +526,9 @@ HLE\Libraries + + HLE\Libraries + HLE\Libraries @@ -534,9 +553,6 @@ Util - - Util - Debugger @@ -697,6 +713,15 @@ MIPS\ARM + + Font + + + Core + + + HLE\Libraries + @@ -704,4 +729,4 @@ - \ No newline at end of file + diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index 3357fc027d..1cd6e08f3f 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -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; diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index 77776468b5..ea33031d7e 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -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; diff --git a/Core/Debugger/Breakpoints.cpp b/Core/Debugger/Breakpoints.cpp index c3ae09d5d6..ccc814cafd 100644 --- a/Core/Debugger/Breakpoints.cpp +++ b/Core/Debugger/Breakpoints.cpp @@ -19,6 +19,7 @@ #include "Breakpoints.h" #include "SymbolMap.h" #include "FixedSizeUnorderedSet.h" +#include "Core/Host.h" #include "../MIPS/JitCommon/JitCommon.h" #include @@ -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::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 ✓ } } diff --git a/Core/Debugger/Breakpoints.h b/Core/Debugger/Breakpoints.h index d3ac2298b2..223dab3895 100644 --- a/Core/Debugger/Breakpoints.h +++ b/Core/Debugger/Breakpoints.h @@ -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 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); diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index 91dce38025..a7aae29a5b 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -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; diff --git a/Core/Dialog/PSPMsgDialog.cpp b/Core/Dialog/PSPMsgDialog.cpp index 23473a6fda..993fdb4b8a 100644 --- a/Core/Dialog/PSPMsgDialog.cpp +++ b/Core/Dialog/PSPMsgDialog.cpp @@ -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; diff --git a/Core/Dialog/PSPOskDialog.cpp b/Core/Dialog/PSPOskDialog.cpp index be6ed1cbeb..f1173e19c0 100644 --- a/Core/Dialog/PSPOskDialog.cpp +++ b/Core/Dialog/PSPOskDialog.cpp @@ -20,15 +20,19 @@ #include "../HLE/sceCtrl.h" #include "ChunkFile.h" +#ifndef _WIN32 +#include +#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)) { diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index ecb032d694..2849d3a592 100644 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -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; diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 00a163fc5c..bc9aeed86d 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -18,7 +18,7 @@ #include "ChunkFile.h" #include "FileUtil.h" #include "DirectoryFileSystem.h" - +#include "file/zip_read.h" #ifdef _WIN32 #include @@ -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 DirectoryFileSystem::GetDirListing(std::string path) { std::vector myVector; #ifdef _WIN32 @@ -537,6 +550,9 @@ std::vector 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 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 VFSFileSystem::GetDirListing(std::string path) { + std::vector myVector; + // TODO + return myVector; +} + +void VFSFileSystem::DoState(PointerWrap &p) { + if (!entries.empty()) { + ERROR_LOG(FILESYS, "FIXME: Open files during savestate, could go badly."); + } +} diff --git a/Core/FileSystems/DirectoryFileSystem.h b/Core/FileSystems/DirectoryFileSystem.h index 61ee605406..1ee0ac474a 100644 --- a/Core/FileSystems/DirectoryFileSystem.h +++ b/Core/FileSystems/DirectoryFileSystem.h @@ -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 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 EntryMap; + EntryMap entries; + std::string basePath; + IHandleAllocator *hAlloc; + + std::string GetLocalPath(std::string localpath); +}; diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 0a91212a64..09de15ea4d 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -559,7 +559,7 @@ std::vector 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; diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp new file mode 100644 index 0000000000..635d1021f0 --- /dev/null +++ b/Core/Font/PGF.cpp @@ -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 getTable(const u8 *buf, int bpe, int length) { + std::vector 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 charPointers = getTable(charPointerTable, header.charPointerBpe, glyphs.size()); + std::vector 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 &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; +} \ No newline at end of file diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h new file mode 100644 index 0000000000..bba9f29d3d --- /dev/null +++ b/Core/Font/PGF.h @@ -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 +#include + +#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 &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 dimensionTable[2]; + std::vector xAdjustTable[2]; + std::vector yAdjustTable[2]; + std::vector advanceTable[2]; + + // Unused + std::vector charmapCompressionTable1[2]; + std::vector charmapCompressionTable2[2]; + + u8 *charMap; + u8 *shadowCharMap; + u8 *charPointerTable; + + std::vector charmap_compr; + std::vector charmap; + + std::vector glyphs; + std::vector shadowGlyphs; + int firstGlyph; +}; diff --git a/Core/HLE/FunctionWrappers.h b/Core/HLE/FunctionWrappers.h index 85468754b8..7bd718a4cb 100644 --- a/Core/HLE/FunctionWrappers.h +++ b/Core/HLE/FunctionWrappers.h @@ -96,6 +96,11 @@ template void WrapF_V() { RETURNF(func()); } +// TODO: Not sure about the floating point parameter passing +template void WrapF_IFU() { + RETURNF(func(PARAM(0), PARAMF(0), PARAM(1))); +} + template void WrapU_U() { u32 retval = func(PARAM(0)); RETURN(retval); @@ -133,7 +138,7 @@ template void WrapI_UU() { template 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 void WrapI_UUU() { RETURN(retval); } +template void WrapI_UUUI() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + template 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 void WrapI_IIII() { RETURN(retval); } +template void WrapI_ICIUU() { + int retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3), PARAM(4)); + RETURN(retval); +} + template void WrapI_IIU() { int retval = func(PARAM(0), PARAM(1), PARAM(2)); RETURN(retval); @@ -481,6 +496,11 @@ template void WrapU_UUUU() { RETURN(retval); } +template void WrapU_UCUU() { + u32 retval = func(PARAM(0), Memory::GetCharPointer(PARAM(1)), PARAM(2), PARAM(3)); + RETURN(retval); +} + template void WrapU_UUUI() { u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); RETURN(retval); diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index cc9e98ca6a..3519600556 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -21,6 +21,8 @@ #include #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 moduleDB; static std::vector unresolvedSyscalls; static std::vector 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) diff --git a/Core/HLE/HLE.h b/Core/HLE/HLE.h index 3b5558fbe5..2f51492e1b 100644 --- a/Core/HLE/HLE.h +++ b/Core/HLE/HLE.h @@ -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(); diff --git a/Core/HLE/HLETables.cpp b/Core/HLE/HLETables.cpp index bd2302fa58..97663a72f8 100644 --- a/Core/HLE/HLETables.cpp +++ b/Core/HLE/HLETables.cpp @@ -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++) { diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 6e05803c5b..decae6627c 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -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) diff --git a/Core/HLE/sceAudio.cpp b/Core/HLE/sceAudio.cpp index 0d7e1eedc8..888db3ef05 100644 --- a/Core/HLE/sceAudio.cpp +++ b/Core/HLE/sceAudio.cpp @@ -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; } diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 348bdce8d2..b79c9733db 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -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)); } diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 152b322fed..98ffbcb991 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -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 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"}, - {0x289D82FE,WrapU_V, "sceDisplaySetFramebuf"}, + {0x0E20F177,WrapU_III, "sceDisplaySetMode"}, + {0x289D82FE,WrapU_UIII, "sceDisplaySetFramebuf"}, {0xEEDA2E54,WrapU_UUUI,"sceDisplayGetFrameBuf"}, {0x36CDFADE,WrapU_V, "sceDisplayWaitVblank"}, {0x984C27E7,WrapU_V, "sceDisplayWaitVblankStart"}, @@ -608,17 +641,17 @@ const HLEFunction sceDisplay[] = { {0x46F186C3,WrapU_V, "sceDisplayWaitVblankStartCB"}, {0x77ed8b3a,WrapU_I,"sceDisplayWaitVblankStartMultiCB"}, {0xdba6c4c4,WrapF_V,"sceDisplayGetFramePerSec"}, - {0x773dd3a3,sceDisplayGetCurrentHcount,"sceDisplayGetCurrentHcount"}, - {0x210eab3a,sceDisplayGetAccumulatedHcount,"sceDisplayGetAccumulatedHcount"}, - {0xA83EF139,0,"sceDisplayAdjustAccumulatedHcount"}, + {0x773dd3a3,WrapU_V,"sceDisplayGetCurrentHcount"}, + {0x210eab3a,WrapU_V,"sceDisplayGetAccumulatedHcount"}, + {0xA83EF139,WrapU_V,"sceDisplayAdjustAccumulatedHcount"}, {0x9C6EAAD7,WrapU_V,"sceDisplayGetVcount"}, - {0xDEA197D4,0,"sceDisplayGetMode"}, + {0xDEA197D4,WrapU_UUU,"sceDisplayGetMode"}, {0x7ED59BC4,0,"sceDisplaySetHoldMode"}, {0xA544C486,0,"sceDisplaySetResumeMode"}, {0xBF79F646,0,"sceDisplayGetResumeMode"}, - {0xB4F378FA,0,"sceDisplayIsForeground"}, + {0xB4F378FA,WrapU_V,"sceDisplayIsForeground"}, {0x31C4BAA8,0,"sceDisplayGetBrightness"}, - {0x4D4E10EC,sceDisplayIsVblank,"sceDisplayIsVblank"}, + {0x4D4E10EC,WrapU_V,"sceDisplayIsVblank"}, {0x21038913,0,"sceDisplayIsVsync"}, }; diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 5c247cb767..9f6118cfe3 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -1,394 +1,72 @@ - +#include "sceFont.h" #include "base/timeutil.h" -#include "../Config.h" -#include "../Host.h" -#include "../SaveState.h" +#include +#include +#include +#include + #include "HLE.h" #include "../MIPS/MIPS.h" - -#include "../FileSystems/FileSystem.h" -#include "../FileSystems/MetaFileSystem.h" -#include "../System.h" - - - -#include "sceFont.h" - -/******************************************************************************/ - -static int get_value(int bpe, u8 *buf, int *pos) -{ - int i, v; - - v = 0; - for(i=0; i> ((*pos)%8) ) &1 ) << i; - (*pos)++; - } - - return v; -} - -static int read_table(u8 *buf, int *table, int num, int bpe) -{ - int i, p, len; - - len = ((num*bpe+31)/32)*4; - - p = 0; - for(i=0; ibuf; - n_charmap = ph->charmap_len; - - for(i=0; icharmap[i]==ptr){ - return i+ph->charmap_min; - } - } - - return 0xffff; -} - -static u32 ucs2ptr(PGF_FONT *pgft, int ucs) -{ - PGF_HEADER *ph; - int ptr; - - ph = (PGF_HEADER*)pgft->buf; - ucs -= ph->charmap_min; - ptr = pgft->charmap[ucs]; - - return ptr; -} - -static int have_shadow(PGF_FONT *pgft, u32 ucs) -{ - PGF_HEADER *ph; - int i, n_shadowmap; - - ph = (PGF_HEADER*)pgft->buf; - n_shadowmap = ph->shadowmap_len; - - for(i=0; ishadowmap[i]==ucs){ - return 1; - } - } - - return 0; -} - -static void get_bitmap(PGF_GLYPH *glyph) -{ - int i, j, p, nb, data, len; - u8 *bmp, temp_buf[64*64]; - - i = 0; - p = 0; - len = glyph->width * glyph->height; - if((glyph->flag&3)==2){ - bmp = temp_buf; - }else{ - bmp = glyph->bmp; - } - - while(idata, &p); - if(nb<8){ - data = get_value(4, glyph->data, &p); - for(j=0; jdata, &p); - bmp[i] = data; - i++; - } - } - } - - if((glyph->flag&3)==2){ - int h, v; - - i = 0; - for(h=0; hwidth; h++){ - for(v=0; vheight; v++){ - glyph->bmp[v*glyph->width+h] = bmp[i]; - i++; - } - } - } - -} - -static void load_shadow_glyph(u8 *ptr, PGF_GLYPH *glyph) -{ - int pos; - - pos = 0; - - glyph->size = get_value(14, ptr, &pos); - glyph->width = get_value(7, ptr, &pos); - glyph->height = get_value(7, ptr, &pos); - glyph->left = get_value(7, ptr, &pos); - glyph->top = get_value(7, ptr, &pos); - glyph->flag = get_value(6, ptr, &pos); - - if(glyph->left>63) glyph->left |= 0xffffff80; - if(glyph->top >63) glyph->top |= 0xffffff80; - - glyph->data = ptr+(pos/8); - glyph->bmp = (u8*)malloc(glyph->width*glyph->height); - get_bitmap(glyph); -} - -static void load_char_glyph(PGF_FONT *pgft, int index, PGF_GLYPH *glyph) -{ - int id, pos; - u8 *ptr; - - ptr = pgft->glyphdata + pgft->charptr[index]; - pos = 0; - - glyph->index = index; - glyph->have_shadow = have_shadow(pgft, glyph->ucs); - - glyph->size = get_value(14, ptr, &pos); - glyph->width = get_value( 7, ptr, &pos); - glyph->height = get_value( 7, ptr, &pos); - glyph->left = get_value( 7, ptr, &pos); - glyph->top = get_value( 7, ptr, &pos); - glyph->flag = get_value( 6, ptr, &pos); - - if(glyph->left>63) glyph->left |= 0xffffff80; - if(glyph->top >63) glyph->top |= 0xffffff80; - - /* read extension info */ - glyph->shadow_flag = get_value(7, ptr, &pos); - glyph->shadow_id = get_value(9, ptr, &pos); - if(glyph->flag&0x04){ - id = get_value(8, ptr, &pos); - glyph->dimension.h = pgft->dimension[id].h; - glyph->dimension.v = pgft->dimension[id].v; - }else{ - glyph->dimension.h = get_value(32, ptr, &pos); - glyph->dimension.v = get_value(32, ptr, &pos); - } - if(glyph->flag&0x08){ - id = get_value(8, ptr, &pos); - glyph->bearingX.h = pgft->bearingX[id].h; - glyph->bearingX.v = pgft->bearingX[id].v; - }else{ - glyph->bearingX.h = get_value(32, ptr, &pos); - glyph->bearingX.v = get_value(32, ptr, &pos); - } - if(glyph->flag&0x10){ - id = get_value(8, ptr, &pos); - glyph->bearingY.h = pgft->bearingY[id].h; - glyph->bearingY.v = pgft->bearingY[id].v; - }else{ - glyph->bearingY.h = get_value(32, ptr, &pos); - glyph->bearingY.v = get_value(32, ptr, &pos); - } - if(glyph->flag&0x20){ - id = get_value(8, ptr, &pos); - glyph->advance.h = pgft->advance[id].h; - glyph->advance.v = pgft->advance[id].v; - }else{ - glyph->advance.h = get_value(32, ptr, &pos); - glyph->advance.v = get_value(32, ptr, &pos); - } - - glyph->data = ptr+(pos/8); - glyph->bmp = (u8*)malloc(glyph->width*glyph->height); - get_bitmap(glyph); - - if(glyph->have_shadow){ - id = glyph->shadow_id; - pgft->shadow_glyph[id] = (PGF_GLYPH*)malloc(sizeof(PGF_GLYPH)); - memset(pgft->shadow_glyph[id], 0, sizeof(PGF_GLYPH)); - load_shadow_glyph(ptr+glyph->size, pgft->shadow_glyph[id]); - } - -} - - -int load_all_glyph(PGF_FONT *pgft) -{ - PGF_GLYPH *glyph; - PGF_HEADER *ph; - int i, n_chars, ucs; - - ph = (PGF_HEADER*)pgft->buf; - n_chars = ph->charptr_len; - - for(i=0; iucs = ucs; - pgft->char_glyph[ucs] = glyph; - load_char_glyph(pgft, i, glyph); - } - - return 0; -} - - - -PGF_FONT *load_pgf_from_buf(u8 *buf, int length) -{ - PGF_FONT *pgft; - PGF_HEADER *ph; - int i; - - pgft = (PGF_FONT*)malloc(sizeof(PGF_FONT)); - memset(pgft, 0, sizeof(PGF_FONT)); - - pgft->buf = buf; - - /* pgf header */ - ph = (PGF_HEADER*)buf; - buf += ph->header_len; - - /* dimension table */ - pgft->dimension = (F26_PAIRS*)buf; - buf += (ph->dimension_len*8); - - /* left bearing table */ - pgft->bearingX = (F26_PAIRS*)buf; - buf += (ph->bearingX_len*8); - - /* top bearing table */ - pgft->bearingY = (F26_PAIRS*)buf; - buf += (ph->bearingY_len*8); - - /* advance table */ - pgft->advance = (F26_PAIRS*)buf; - buf += (ph->advance_len*8); - - /* read shadowmap table */ - if(ph->shadowmap_len){ - pgft->shadowmap = (int*)malloc(ph->shadowmap_len*4); - buf += read_table(buf, pgft->shadowmap, ph->shadowmap_len, ph->shadowmap_bpe); - } - - /* read charmap table */ - pgft->charmap = (int*)malloc(ph->charmap_len*4); - buf += read_table(buf, pgft->charmap, ph->charmap_len, ph->charmap_bpe); - - /* read charptr table */ - pgft->charptr = (int*)malloc(ph->charptr_len*4); - buf += read_table(buf, pgft->charptr, ph->charptr_len, ph->charptr_bpe); - for(i=0; icharptr_len; i++){ - pgft->charptr[i] *= ph->charptr_scale; - } - - /* font glyph data */ - pgft->glyphdata = buf; - - //load_all_glyph(pgft); - - return pgft; -} - -PGF_FONT *load_pgf_from_file(const char *filename) -{ - u32 h = pspFileSystem.OpenFile(filename, FILEACCESS_READ); - if (h == 0){ - ERROR_LOG(HLE, "load_pgf_from_file: %s not found", filename); - return NULL; - } - - PSPFileInfo info = pspFileSystem.GetFileInfo(filename); - u8 *buf = (u8*)malloc((size_t)info.size); - pspFileSystem.ReadFile(h, buf, info.size); - pspFileSystem.CloseFile(h); - - PGF_FONT *pgft = load_pgf_from_buf(buf, (int)info.size); - - return pgft; -} - -PGF_GLYPH *get_glyph(PGF_FONT *pgft, u32 ucs) -{ - PGF_GLYPH *gh; - PGF_HEADER *ph; - int ptr; - - ph = (PGF_HEADER*)pgft->buf; - - gh = pgft->char_glyph[ucs]; - if(gh==NULL){ - ptr = ucs2ptr(pgft, ucs); - if(ptr>ph->charptr_len) - ptr = ucs2ptr(pgft, '?'); - - gh = (PGF_GLYPH*)malloc(sizeof(PGF_GLYPH)); - memset(gh, 0, sizeof(PGF_GLYPH)); - gh->ucs = ucs; - pgft->char_glyph[ucs] = gh; - load_char_glyph(pgft, ptr, gh); - } - - return gh; -} - -void free_glyph(PGF_FONT *pgft, PGF_GLYPH *glyph) -{ - int ucs; - - ucs = glyph->ucs; - free(glyph->bmp); - free(glyph); - pgft->char_glyph[ucs] = 0; -} - -void free_pgf_font(PGF_FONT *pgft) -{ - PGF_HEADER *ph; - int i; - - ph = (PGF_HEADER*)pgft->buf; - - for(i=0; i<65536; i++){ - if(pgft->char_glyph[i]) - free_glyph(pgft, pgft->char_glyph[i]); - } - - for(i=0; i<512; i++){ - if(pgft->shadow_glyph[i]){ - free(pgft->shadow_glyph[i]->bmp); - free(pgft->shadow_glyph[i]); - } - } - - if(ph->shadowmap_len){ - free(pgft->shadowmap); - } - free(pgft->charmap); - free(pgft->charptr); - - free(pgft->buf); - free(pgft); -} - -/******************************************************************************/ +#include "ChunkFile.h" +#include "Core/FileSystems/FileSystem.h" +#include "Core/System.h" +#include "Core/HLE/sceKernel.h" +#include "Core/Font/PGF.h" +#include "Core/HLE/sceKernelThread.h" + +enum { + ERROR_FONT_INVALID_LIBID = 0x80460002, + ERROR_FONT_INVALID_PARAMETER = 0x80460003, + ERROR_FONT_TOO_MANY_OPEN_FONTS = 0x80460009, +}; + +enum { + FONT_IS_CLOSED = 0, + FONT_IS_OPEN = 1, +}; + +// Actions +static int actionPostAllocCallback; +static int actionPostOpenCallback; + +// Monster Hunter sequence: +// 36:46:998 c:\dev\ppsspp\core\hle\scefont.cpp:469 E[HLE]: sceFontNewLib 89ad4a0, 9fff5cc +// 36:46:998 c:\dev\ppsspp\core\hle\scefont.cpp:699 E[HLE]: UNIMPL sceFontGetNumFontList 1, 9fff5cc +// 36:46:998 c:\dev\ppsspp\core\hle\scefont.cpp:526 E[HLE]: sceFontFindOptimumFont 1, 9fff524, 9fff5cc +// 36:46:999 c:\dev\ppsspp\core\hle\scefont.cpp:490 E[HLE]: sceFontOpenFont 1, 1, 0, 9fff5cc +// 36:46:999 c:\dev\ppsspp\core\hle\scefont.cpp:542 E[HLE]: sceFontGetFontInfo 1, 997140c + +typedef u32 FontLibraryHandle; +typedef u32 FontHandle; + +struct FontNewLibParams { + u32 userDataAddr; + u32 numFonts; + u32 cacheDataAddr; + + // Driver callbacks. + u32 allocFuncAddr; + u32 freeFuncAddr; + u32 openFuncAddr; + u32 closeFuncAddr; + u32 readFuncAddr; + u32 seekFuncAddr; + u32 errorFuncAddr; + u32 ioFinishFuncAddr; +}; + +struct GlyphImage { + FontPixelFormat pixelFormat; + s32 xPos64; + s32 yPos64; + u16 bufWidth; + u16 bufHeight; + u16 bytesPerLine; + u16 pad; + u32 bufferPtr; +}; struct FontRegistryEntry { int hSize; @@ -410,518 +88,837 @@ struct FontRegistryEntry { }; static const FontRegistryEntry fontRegistry[] = { - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_DB, 0, FONT_LANGUAGE_JAPANESE, 0, 1, "jpn0.pgf", "FTT-NewRodin Pro DB", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn0.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn1.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn2.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn3.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn4.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn5.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn6.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn7.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn8.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn9.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn10.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn11.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn12.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn13.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn14.pgf", "FTT-NewRodin Pro Latin", 0, 0}, - {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn15.pgf", "FTT-Matisse Pro Latin", 0, 0}, - {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_KOREAN, 0, 3, "kr0.pgf", "AsiaNHH(512Johab)", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_DB, 0, FONT_LANGUAGE_JAPANESE, 0, 1, "jpn0.pgf", "FTT-NewRodin Pro DB", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn0.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn1.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn2.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn3.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn4.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn5.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn6.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn7.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn8.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn9.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn10.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn11.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn12.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn13.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn14.pgf", "FTT-NewRodin Pro Latin", 0, 0}, + {0x1c0, 0x1c0, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SERIF, FONT_STYLE_BOLD_ITALIC, 0, FONT_LANGUAGE_LATIN, 0, 1, "ltn15.pgf", "FTT-Matisse Pro Latin", 0, 0}, + {0x288, 0x288, 0x2000, 0x2000, 0, 0, FONT_FAMILY_SANS_SERIF, FONT_STYLE_REGULAR, 0, FONT_LANGUAGE_KOREAN, 0, 3, "kr0.pgf", "AsiaNHH(512Johab)", 0, 0}, }; -static const char *font_list[18] = { - "flash0:/font/jpn0.pgf", - "flash0:/font/ltn0.pgf", - "flash0:/font/ltn1.pgf", - "flash0:/font/ltn2.pgf", - "flash0:/font/ltn3.pgf", - "flash0:/font/ltn4.pgf", - "flash0:/font/ltn5.pgf", - "flash0:/font/ltn6.pgf", - "flash0:/font/ltn7.pgf", - "flash0:/font/ltn8.pgf", - "flash0:/font/ltn9.pgf", - "flash0:/font/ltn10.pgf", - "flash0:/font/ltn11.pgf", - "flash0:/font/ltn12.pgf", - "flash0:/font/ltn13.pgf", - "flash0:/font/ltn14.pgf", - "flash0:/font/ltn15.pgf", - "flash0:/font/kr0.pgf", -}; -static int font_num = 18; +static const float pointDPI = 72.f; -static PGF_FONT *font_slot[8] = {NULL, }; +class LoadedFont; +class FontLib; +class Font; +int GetInternalFontIndex(Font *font); -static int get_font_slot(void) -{ - int i; +// These should not need to be state saved. +static std::vector internalFonts; +// However, these we must save - but we could take a shortcut +// for LoadedFonts that point to internal fonts. +static std::map fontMap; +static std::map fontLibMap; +// We keep this list to avoid ptr references, even before alloc is called. +static std::vector fontLibList; - for(i=0; i<8; i++){ - if(font_slot[i]==NULL) - return i; +// TODO: Merge this class with PGF? That'd make it harder to support .bwfon +// fonts though, unless that's added directly to PGF. +class Font { +public: + // For savestates only. + Font() { } - return -1; -} + Font(const u8 *data, size_t dataSize) { + pgf_.ReadPtr(data, dataSize); + style_.fontH = pgf_.header.hSize / 64.0f; + style_.fontV = pgf_.header.vSize / 64.0f; + style_.fontHRes = pgf_.header.hResolution / 64.0f; + style_.fontVRes = pgf_.header.vResolution / 64.0f; + } -static float f26_float(int value) -{ - float f, t; + Font(const u8 *data, size_t dataSize, const FontRegistryEntry &entry) { + pgf_.ReadPtr(data, dataSize); + style_.fontH = entry.hSize / 64.f; + style_.fontV = entry.vSize / 64.f; + style_.fontHRes = entry.hResolution / 64.f; + style_.fontVRes = entry.vResolution / 64.f; + style_.fontWeight = (float)entry.weight; + style_.fontFamily = (u16)entry.familyCode; + style_.fontStyle = (u16)entry.style; + style_.fontStyleSub = (u16)entry.styleSub; + style_.fontLanguage = (u16)entry.languageCode; + style_.fontRegion = (u16)entry.regionCode; + style_.fontCountry = (u16)entry.countryCode; + strncpy(style_.fontName, entry.fontName, sizeof(style_.fontName)); + strncpy(style_.fontFileName, entry.fileName, sizeof(style_.fontFileName)); + style_.fontAttributes = entry.extraAttributes; + style_.fontExpire = entry.expireDate; + } - f = (float)(value>>6); - t = (float)(value&0x3f); - f += t/64; + const PGFFontStyle &GetFontStyle() const { return style_; } - return f; -} + bool MatchesStyle(const PGFFontStyle &style, bool optimum) const { + // TODO + return true; + } -void show_style_info(struct FontStyle *s) -{ - INFO_LOG(HLE, "FontStyle: H=%f V=%f Hres=%f Vres=%f Weight=%f", s->fontH, s->fontV, s->fontHRes, s->fontVRes, s->fontWeight); - INFO_LOG(HLE, "FontStyle: family=%d style=%d substyle=%d", s->fontFamily, s->fontStyle, s->fontStyleSub); - INFO_LOG(HLE, "FontStyle: language=%d region=%d country=%d", s->fontLanguage, s->fontRegion, s->fontCountry); - INFO_LOG(HLE, "FontStyle: fontname=%s filename=%s", s->fontName, s->fontFileName); -} + PGF *GetPGF() { return &pgf_; } -int match_font(struct FontStyle *s) -{ - int i; - int score, max_score, font_index; + void DoState(PointerWrap &p) { + p.Do(pgf_); + p.Do(style_); + p.DoMarker("Font"); + } - max_score = -1; - for(i=0; ifontLanguage) - score += 0x01000000; - if(fontRegistry[i].familyCode==s->fontFamily) - score += 0x00100000; - if(fontRegistry[i].style==s->fontStyle) - score += 0x00010000; - if(fontRegistry[i].hSize==s->fontH) - score += 0x00001000; +class LoadedFont { +public: + // For savestates only. + LoadedFont() { + } - if(score>max_score){ - max_score = score; - font_index = i; + LoadedFont(Font *font, u32 fontLibID, u32 handle) + : fontLibID_(fontLibID), font_(font), handle_(handle) {} + + Font *GetFont() { return font_; } + FontLib *GetFontLib() { if (!IsOpen()) return NULL; return fontLibList[fontLibID_]; } + u32 Handle() const { return handle_; } + + bool IsOpen() const { return fontLibID_ != (u32)-1; } + void Close() { + fontLibID_ = (u32)-1; + // We keep the rest around until deleted, as some queries are allowed + // on closed fonts (which is rather strange). + } + + void DoState(PointerWrap &p) { + int numInternalFonts = (int)internalFonts.size(); + p.Do(numInternalFonts); + if (numInternalFonts != (int)internalFonts.size()) { + ERROR_LOG(HLE, "Unable to load state: different internal font count."); + return; + } + + p.Do(fontLibID_); + int internalFont = GetInternalFontIndex(font_); + p.Do(internalFont); + if (internalFont == -1) { + p.Do(font_); + } else if (p.mode == p.MODE_READ) { + font_ = internalFonts[internalFont]; + } + p.Do(handle_); + p.DoMarker("LoadedFont"); + } + +private: + u32 fontLibID_; + Font *font_; + u32 handle_; + DISALLOW_COPY_AND_ASSIGN(LoadedFont); +}; + +class PostAllocCallback : public Action { +public: + PostAllocCallback() {} + static Action *Create() { return new PostAllocCallback(); } + void DoState(PointerWrap &p) { p.Do(fontLibID_); p.DoMarker("PostAllocCallback"); } + void run(MipsCall &call); + void SetFontLib(u32 fontLibID) { fontLibID_ = fontLibID; } + +private: + u32 fontLibID_; +}; + +class PostOpenCallback : public Action { +public: + PostOpenCallback() {} + static Action *Create() { return new PostOpenCallback(); } + void DoState(PointerWrap &p) { p.Do(fontLibID_); p.DoMarker("PostOpenCallback"); } + void run(MipsCall &call); + void SetFontLib(u32 fontLibID) { fontLibID_ = fontLibID; } + +private: + u32 fontLibID_; +}; + +// A "fontLib" is a container of loaded fonts. +// One can open either "internal" fonts or custom fonts into a fontlib. +class FontLib { +public: + FontLib() { + // For save states only. + } + + FontLib(u32 paramPtr) : fontHRes_(128.0f), fontVRes_(128.0f) { + Memory::ReadStruct(paramPtr, ¶ms_); + fakeAlloc_ = 0x13370; + // We use the same strange scheme that JPCSP uses. + u32 allocSize = 4 + 4 * params_.numFonts; + PostAllocCallback *action = (PostAllocCallback*) __KernelCreateAction(actionPostAllocCallback); + action->SetFontLib(GetListID()); + + if (false) { + // This fails in dissidia. The function at 088ff320 (params_.allocFuncAddr) calls some malloc function, the second one returns 0 which causes + // bad stores later. So we just ignore this with if (false) and fake it. + u32 args[2] = { params_.userDataAddr, allocSize }; + __KernelDirectMipsCall(params_.allocFuncAddr, action, args, 2, false); + } else { + AllocDone(fakeAlloc_); + fakeAlloc_ += allocSize; + fontLibMap[handle()] = GetListID(); + INFO_LOG(HLE, "Leaving PostAllocCallback::run"); } } - return font_index; + u32 GetListID() { + return (u32)(std::find(fontLibList.begin(), fontLibList.end(), this) - fontLibList.begin()); + } + + void Close() { + __KernelDirectMipsCall(params_.closeFuncAddr, 0, 0, 0, false); + } + + void Done() { + for (size_t i = 0; i < fonts_.size(); i++) { + if (isfontopen_[i] == FONT_IS_OPEN) { + fontMap[fonts_[i]]->Close(); + delete fontMap[fonts_[i]]; + fontMap.erase(fonts_[i]); + } + } + u32 args[2] = { params_.userDataAddr, (u32)handle_ }; + __KernelDirectMipsCall(params_.freeFuncAddr, 0, args, 2, false); + handle_ = 0; + fonts_.clear(); + isfontopen_.clear(); + } + + void AllocDone(u32 allocatedAddr) { + handle_ = allocatedAddr; + fonts_.resize(params_.numFonts); + isfontopen_.resize(params_.numFonts); + for (size_t i = 0; i < fonts_.size(); i++) { + u32 addr = allocatedAddr + 4 + i * 4; + isfontopen_[i] = 0; + fonts_[i] = addr; + } + } + + u32 handle() const { return handle_; } + int numFonts() const { return params_.numFonts; } + + void SetResolution(float hres, float vres) { + fontHRes_ = hres; + fontVRes_ = vres; + } + + float FontHRes() const { return fontHRes_; } + float FontVRes() const { return fontVRes_; } + + void SetAltCharCode(int charCode) { altCharCode_ = charCode; } + + int GetFontHandle(int index) { + return fonts_[index]; + } + + LoadedFont *OpenFont(Font *font) { + int freeFontIndex = -1; + for (size_t i = 0; i < fonts_.size(); i++) { + if (isfontopen_[i] == 0) { + freeFontIndex = (int)i; + break; + } + } + if (freeFontIndex < 0) { + ERROR_LOG(HLE, "Too many fonts opened in FontLib"); + return 0; + } + LoadedFont *loadedFont = new LoadedFont(font, GetListID(), fonts_[freeFontIndex]); + isfontopen_[freeFontIndex] = 1; + return loadedFont; + } + + void CloseFont(LoadedFont *font) { + for (size_t i = 0; i < fonts_.size(); i++) { + if (fonts_[i] == font->Handle()) { + isfontopen_[i] = 0; + + } + } + font->Close(); + } + + void DoState(PointerWrap &p) { + p.Do(fonts_); + p.Do(isfontopen_); + p.Do(params_); + p.Do(fontHRes_); + p.Do(fontVRes_); + p.Do(fileFontHandle_); + p.Do(handle_); + p.Do(altCharCode_); + p.Do(fakeAlloc_); + p.DoMarker("FontLib"); + } + + void SetFileFontHandle(u32 handle) { + fileFontHandle_ = handle; + } + + u32 GetAltCharCode() const { return altCharCode_; } + +private: + std::vector fonts_; + std::vector isfontopen_; + + FontNewLibParams params_; + float fontHRes_; + float fontVRes_; + int fileFontHandle_; + int handle_; + int altCharCode_; + + u32 fakeAlloc_; + DISALLOW_COPY_AND_ASSIGN(FontLib); +}; + + +void PostAllocCallback::run(MipsCall &call) { + INFO_LOG(HLE, "Entering PostAllocCallback::run"); + u32 v0 = currentMIPS->r[0]; + FontLib *fontLib = fontLibList[fontLibID_]; + fontLib->AllocDone(call.savedV0); + fontLibMap[fontLib->handle()] = fontLibID_; + call.setReturnValue(fontLib->handle()); + INFO_LOG(HLE, "Leaving PostAllocCallback::run"); } -/******************************************************************************/ - - -FontNewLibParams fontLib; - -void __FontInit() -{ - memset(&fontLib, 0, sizeof(fontLib)); +void PostOpenCallback::run(MipsCall &call) { + FontLib *fontLib = fontLibList[fontLibID_]; + fontLib->SetFileFontHandle(call.savedV0); } -void __FontDoState(PointerWrap &p) -{ - p.Do(fontLib); +FontLib *GetFontLib(u32 handle) { + if (fontLibMap.find(handle) != fontLibMap.end()) { + return fontLibList[fontLibMap[handle]]; + } else { + ERROR_LOG(HLE, "No fontlib with handle %08x", handle); + return 0; + } +} + +LoadedFont *GetLoadedFont(u32 handle, bool allowClosed) { + auto iter = fontMap.find(handle); + if (iter != fontMap.end()) { + if (iter->second->IsOpen() || allowClosed) { + return fontMap[handle]; + } else { + ERROR_LOG(HLE, "Font exists but is closed, which was not allowed in this call."); + return 0; + } + } else { + ERROR_LOG(HLE, "No font with handle %08x", handle); + return 0; + } +} + +void __LoadInternalFonts() { + if (internalFonts.size()) { + // Fonts already loaded. + return; + } + std::string fontPath = "flash0:/font/"; + if (!pspFileSystem.GetFileInfo(fontPath).exists) { + pspFileSystem.MkDir(fontPath); + } + for (size_t i = 0; i < ARRAY_SIZE(fontRegistry); i++) { + const FontRegistryEntry &entry = fontRegistry[i]; + std::string fontFilename = fontPath + entry.fileName; + PSPFileInfo info = pspFileSystem.GetFileInfo(fontFilename); + if (info.exists) { + INFO_LOG(HLE, "Loading font %s (%i bytes)", fontFilename.c_str(), (int)info.size); + u8 *buffer = new u8[(size_t)info.size]; + u32 handle = pspFileSystem.OpenFile(fontFilename, FILEACCESS_READ); + if (!handle) { + ERROR_LOG(HLE, "Failed opening font"); + delete [] buffer; + continue; + } + pspFileSystem.ReadFile(handle, buffer, info.size); + pspFileSystem.CloseFile(handle); + + internalFonts.push_back(new Font(buffer, (size_t)info.size, entry)); + + delete [] buffer; + INFO_LOG(HLE, "Loaded font %s", fontFilename.c_str()); + } else { + INFO_LOG(HLE, "Font file not found: %s", fontFilename.c_str()); + } + } +} + +Style FontStyleFromString(const std::string &str) { + if (str == "Regular") + return FONT_STYLE_REGULAR; + else if (str == "Italic") + return FONT_STYLE_ITALIC; + else if (str == "Bold") + return FONT_STYLE_BOLD; + else if (str == "Bold Italic") + return FONT_STYLE_BOLD_ITALIC; + return FONT_STYLE_REGULAR; +} + +Font *GetOptimumFont(const PGFFontStyle &requestedStyle, Font *optimumFont, Font *candidateFont) { + if (!optimumFont) + return candidateFont; + PGFFontStyle optimumStyle = optimumFont->GetFontStyle(); + PGFFontStyle candidateStyle = candidateFont->GetFontStyle(); + + bool testH = requestedStyle.fontH != 0.0f || requestedStyle.fontV == 0.0f; + if (testH && fabsf(requestedStyle.fontH - optimumStyle.fontH) > fabsf(requestedStyle.fontH - candidateStyle.fontH)) { + return candidateFont; + } + + // Check the fontV if it is specified or both fontH and fontV are unspecified + bool testV = requestedStyle.fontV != 0.f || requestedStyle.fontH == 0.f; + if (testV && fabsf(requestedStyle.fontV - optimumStyle.fontV) > fabsf(requestedStyle.fontV - candidateStyle.fontV)) { + return candidateFont; + } + + return optimumFont; +} + +int GetInternalFontIndex(Font *font) { + for (size_t i = 0; i < internalFonts.size(); i++) { + if (internalFonts[i] == font) + return i; + } + return -1; +} + +void __FontInit() { + actionPostAllocCallback = __KernelRegisterActionType(PostAllocCallback::Create); + actionPostOpenCallback = __KernelRegisterActionType(PostOpenCallback::Create); +} + +void __FontShutdown() { + for (auto iter = fontMap.begin(); iter != fontMap.end(); iter++) { + FontLib *fontLib = iter->second->GetFontLib(); + if (fontLib) + fontLib->CloseFont(iter->second); + } + fontMap.clear(); + for (auto iter = fontLibList.begin(); iter != fontLibList.end(); iter++) { + delete *iter; + } + fontLibList.clear(); + fontLibMap.clear(); + for (auto iter = internalFonts.begin(); iter != internalFonts.end(); ++iter) { + delete *iter; + } + internalFonts.clear(); +} + +void __FontDoState(PointerWrap &p) { + __LoadInternalFonts(); + + p.Do(fontLibList); + p.Do(fontLibMap); + p.Do(fontMap); + + p.Do(actionPostAllocCallback); + __KernelRestoreActionType(actionPostAllocCallback, PostAllocCallback::Create); + p.Do(actionPostOpenCallback); + __KernelRestoreActionType(actionPostOpenCallback, PostOpenCallback::Create); p.DoMarker("sceFont"); } -u32 sceFontNewLib(u32 FontNewLibParamsPtr, u32 errorCodePtr) -{ - DEBUG_LOG(HLE, "sceFontNewLib %x, %x", FontNewLibParamsPtr, errorCodePtr); +u32 sceFontNewLib(u32 paramPtr, u32 errorCodePtr) { + // Lazy load internal fonts, only when font library first inited. + __LoadInternalFonts(); + INFO_LOG(HLE, "sceFontNewLib(%08x, %08x)", paramPtr, errorCodePtr); - if (Memory::IsValidAddress(FontNewLibParamsPtr)&&Memory::IsValidAddress(errorCodePtr)) + if (Memory::IsValidAddress(paramPtr) && Memory::IsValidAddress(errorCodePtr)) { + Memory::Write_U32(0, errorCodePtr); + + FontLib *newLib = new FontLib(paramPtr); + fontLibList.push_back(newLib); + // The game should never see this value, the return value is replaced + // by the action. Except if we disable the alloc, in this case we return + // the handle correctly here. + return newLib->handle(); + } + + return 0; +} + +int sceFontDoneLib(u32 fontLibHandle) { + INFO_LOG(HLE, "sceFontDoneLib(%08x)", fontLibHandle); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + fl->Done(); + } + return 0; +} + +// Open internal font into a FontLib +u32 sceFontOpen(u32 libHandle, u32 index, u32 mode, u32 errorCodePtr) { + INFO_LOG(HLE, "sceFontOpen(%x, %x, %x, %x)", libHandle, index, mode, errorCodePtr); + if (!Memory::IsValidAddress(errorCodePtr)) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; + } + + FontLib *fontLib = GetFontLib(libHandle); + if (index >= internalFonts.size()) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; + } + + LoadedFont *font = fontLib->OpenFont(internalFonts[index]); + if (font) { + fontMap[font->Handle()] = font; + Memory::Write_U32(0, errorCodePtr); + return font->Handle(); + } else { + Memory::Write_U32(ERROR_FONT_TOO_MANY_OPEN_FONTS, errorCodePtr); + return 0; + } +} + +// Open a user font in RAM into a FontLib +u32 sceFontOpenUserMemory(u32 libHandle, u32 memoryFontAddrPtr, u32 memoryFontLength, u32 errorCodePtr) { + ERROR_LOG(HLE, "sceFontOpenUserMemory %x, %x, %x, %x", libHandle, memoryFontAddrPtr, memoryFontLength, errorCodePtr); + if (!Memory::IsValidAddress(errorCodePtr) || !Memory::IsValidAddress(memoryFontAddrPtr)) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; + } + + FontLib *fontLib = GetFontLib(libHandle); + if (!fontLib) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; + } + + const u8 *fontData = Memory::GetPointer(memoryFontAddrPtr); + LoadedFont *font = fontLib->OpenFont(new Font(fontData, memoryFontLength)); + if (font) { + fontMap[font->Handle()] = font; + Memory::Write_U32(0, errorCodePtr); + return font->Handle(); + } else { + Memory::Write_U32(ERROR_FONT_TOO_MANY_OPEN_FONTS, errorCodePtr); + return 0; + } +} + +// Open a user font in a file into a FontLib +u32 sceFontOpenUserFile(u32 libHandle, const char *fileName, u32 mode, u32 errorCodePtr) { + ERROR_LOG(HLE, "sceFontOpenUserFile(%08x, %s, %08x, %08x)", libHandle, fileName, mode, errorCodePtr); + if (!Memory::IsValidAddress(errorCodePtr)) + return ERROR_FONT_INVALID_PARAMETER; + + PSPFileInfo info = pspFileSystem.GetFileInfo(fileName); + if (!info.exists) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; + } + + FontLib *fontLib = GetFontLib(libHandle); + if (!fontLib) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; + } + + u8 *buffer = new u8[(size_t)info.size]; + + u32 fileHandle = pspFileSystem.OpenFile(fileName, FILEACCESS_READ); + pspFileSystem.ReadFile(fileHandle, buffer, info.size); + pspFileSystem.CloseFile(fileHandle); + + LoadedFont *font = fontLib->OpenFont(new Font(buffer, (size_t)info.size)); + if (font) { + fontMap[font->Handle()] = font; + Memory::Write_U32(0, errorCodePtr); + return font->Handle(); + } else { + Memory::Write_U32(ERROR_FONT_TOO_MANY_OPEN_FONTS, errorCodePtr); + return 0; + } +} + +int sceFontClose(u32 fontHandle) { + LoadedFont *font = GetLoadedFont(fontHandle, false); + if (font) { - Memory::Write_U32(0, errorCodePtr); - Memory::ReadStruct(FontNewLibParamsPtr, &fontLib); + INFO_LOG(HLE, "sceFontClose(%x)", fontHandle); + FontLib *fontLib = font->GetFontLib(); + if (fontLib) + fontLib->CloseFont(font); } - - return 1; -} - -int sceFontDoneLib(u32 FontLibraryHandlePtr) -{ - DEBUG_LOG(HLE, "sceFontDoneLib %x", FontLibraryHandlePtr); + else + ERROR_LOG(HLE, "sceFontClose(%x) - font not open?", fontHandle); return 0; } - -u32 sceFontOpen(u32 libHandle, u32 index, u32 mode, u32 errorCodePtr) - { - int slot; - - INFO_LOG(HLE, "sceFontOpen %x, %x, %x, %x", libHandle, index, mode, errorCodePtr); - - slot = get_font_slot(); - if(slot==-1){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); +int sceFontFindOptimumFont(u32 libHandlePtr, u32 fontStylePtr, u32 errorCodePtr) { + ERROR_LOG(HLE, "sceFontFindOptimumFont(%08x, %08x, %08x)", libHandlePtr, fontStylePtr, errorCodePtr); + if (!fontStylePtr) return 0; - } - index -= 1; - - font_slot[slot] = load_pgf_from_file(font_list[index]); - if(font_slot[slot]==NULL){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); - } - - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(0, errorCodePtr); - - return slot+1; -} - -u32 sceFontOpenUserMemory(u32 libHandle, u32 memoryFontAddrPtr, u32 memoryFontLength, u32 errorCodePtr) -{ - int retv, slot; - u8 *buf; - - INFO_LOG(HLE, "sceFontOpenUserMemory %x, %x, %x, %x", libHandle, memoryFontAddrPtr, memoryFontLength, errorCodePtr); - - retv = 0; - slot = get_font_slot(); - if(slot==-1){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); - return 0; - } - - if (!Memory::IsValidAddress(memoryFontAddrPtr)){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); - return 0; - } - buf = (u8*) Memory::GetPointer(memoryFontAddrPtr); - - font_slot[slot] = load_pgf_from_buf(buf, memoryFontLength); - - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(0, errorCodePtr); - - return slot+1; -} - -u32 sceFontOpenUserFile(u32 libHandle, u32 fileNamePtr, u32 mode, u32 errorCodePtr) -{ - int slot; - char *filename; - - INFO_LOG(HLE, "sceFontOpenUserFile %x, %x, %x, %x", libHandle, fileNamePtr, mode, errorCodePtr); - - slot = get_font_slot(); - if(slot==-1){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); - return 0; - } - - if (!Memory::IsValidAddress(fileNamePtr)){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); - return 0; - } - filename = (char*) Memory::GetPointer(fileNamePtr); - - font_slot[slot] = load_pgf_from_file(filename); - if(font_slot[slot]==NULL){ - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(-1, errorCodePtr); - } - - if (Memory::IsValidAddress(errorCodePtr)) - Memory::Write_U32(0, errorCodePtr); - - return slot+1; -} - -int sceFontClose(u32 fontHandle) -{ - int slot; - - INFO_LOG(HLE, "sceFontClose %x", fontHandle); - - slot = fontHandle-1; - free_pgf_font(font_slot[slot]); - font_slot[slot] = NULL; - - return 0; -} - -int sceFontFindOptimumFont(u32 libHandlePtr, u32 fontStylePtr, u32 errorCodePtr) -{ - int font_index; - - INFO_LOG(HLE, "sceFontFindOptimumFont %x, %x, %x", libHandlePtr, fontStylePtr, errorCodePtr); - - FontStyle s; + if (!Memory::IsValidAddress(errorCodePtr)) + return SCE_KERNEL_ERROR_INVALID_ARGUMENT; - Memory::ReadStruct(fontStylePtr, &s); - show_style_info(&s); + PGFFontStyle requestedStyle; + Memory::ReadStruct(fontStylePtr, &requestedStyle); - font_index = match_font(&s); - INFO_LOG(HLE, "sceFontFindOptimumFont: match %s", font_list[font_index]); - - if (Memory::IsValidAddress(errorCodePtr)){ - Memory::Write_U32(0, errorCodePtr); - } - - return font_index+1; -} - -int sceFontFindFont(u32 libHandlePtr, u32 fontStylePtr, u32 errorCodePtr) -{ - INFO_LOG(HLE, "sceFontFindFont %x, %x, %x", libHandlePtr, fontStylePtr, errorCodePtr); - if (Memory::IsValidAddress(errorCodePtr)){ - Memory::Write_U32(0, errorCodePtr); - } - return 1; -} - -int sceFontGetFontInfo(u32 fontHandle, u32 fontInfoPtr) -{ - PGF_FONT *pgft; - PGF_HEADER *ph; - int slot; - - INFO_LOG(HLE, "sceFontGetFontInfo %x, %x", fontHandle, fontInfoPtr); - - slot = fontHandle-1; - pgft = font_slot[slot]; - ph = (PGF_HEADER*)pgft->buf; - - FontInfo fi; - memset (&fi, 0, sizeof(fi)); - if (Memory::IsValidAddress(fontInfoPtr)) - { - fi.BPP = 4; - fi.charMapLength = ph->charmap_len; - fi.shadowMapLength = ph->shadowmap_len; - - fi.maxInfoI.width = ph->max_glyph_w<<6; - fi.maxInfoI.height = ph->max_glyph_h<<6; - fi.maxInfoI.ascender = ph->ascender; - fi.maxInfoI.descender = ph->descender; - fi.maxInfoI.h_bearingX = ph->max_h_bearingX; - fi.maxInfoI.h_bearingY = ph->max_h_bearingY; - fi.maxInfoI.v_bearingX = ph->min_v_bearingX; - fi.maxInfoI.v_bearingY = ph->max_v_bearingY; - fi.maxInfoI.h_advance = ph->max_h_advance; - fi.maxInfoI.v_advance = ph->max_v_advance; - - fi.maxInfoF.width = (float)(ph->max_glyph_w); - fi.maxInfoF.height = (float)(ph->max_glyph_h); - fi.maxInfoF.ascender = f26_float(ph->ascender); - fi.maxInfoF.descender = f26_float(ph->descender); - fi.maxInfoF.h_bearingX = f26_float(ph->max_h_bearingX); - fi.maxInfoF.h_bearingY = f26_float(ph->max_h_bearingY); - fi.maxInfoF.v_bearingX = f26_float(ph->min_v_bearingX); - fi.maxInfoF.v_bearingY = f26_float(ph->max_v_bearingY); - fi.maxInfoF.h_advance = f26_float(ph->max_h_advance); - fi.maxInfoF.v_advance = f26_float(ph->max_v_advance); - - fi.maxGlyphHeight = ph->max_glyph_h; - fi.maxGlyphWidth = ph->max_glyph_w; - - fi.fontStyle.fontAttributes = 1; - fi.fontStyle.fontCountry = 1; - fi.fontStyle.fontExpire = 1; - fi.fontStyle.fontFamily = 1; - fi.fontStyle.fontH = f26_float(ph->h_size); - fi.fontStyle.fontHRes = f26_float(ph->h_res); - fi.fontStyle.fontLanguage = 1; - fi.fontStyle.fontRegion = 9; - fi.fontStyle.fontV = f26_float(ph->v_size); - fi.fontStyle.fontVRes = f26_float(ph->v_res); - fi.fontStyle.fontWeight = 32; - strcpy(fi.fontStyle.fontFileName, font_list[slot]); - strcpy(fi.fontStyle.fontName, (const char*)ph->font_name); - - Memory::WriteStruct(fontInfoPtr, &fi); - } - - return 0; -} - -int sceFontGetFontInfoByIndexNumber(u32 libHandle, u32 fontInfoPtr, u32 fontIndex) -{ - ERROR_LOG(HLE, "HACK sceFontGetFontInfoByIndexNumber %x, %x, %x", libHandle, fontInfoPtr, fontIndex); - // clearly wrong.. - return -1; - -} - -int sceFontGetCharInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) -{ - PGF_FONT *pgft; - PGF_HEADER *ph; - PGF_GLYPH *gh; - int slot; - - INFO_LOG(HLE, "HACK sceFontGetCharInfo %x, %x, %x", fontHandle, charCode, charInfoPtr); - - slot = fontHandle-1; - pgft = font_slot[slot]; - if(pgft==NULL) - return -1; - - ph = (PGF_HEADER*)pgft->buf; - gh = get_glyph(pgft, charCode); - - if (Memory::IsValidAddress(charInfoPtr)) { - CharInfo pspCharInfo; - memset(&pspCharInfo, 0, sizeof(pspCharInfo)); - - pspCharInfo.bitmapWidth = gh->width; - pspCharInfo.bitmapHeight = gh->height; - pspCharInfo.bitmapLeft = gh->left; - pspCharInfo.bitmapTop = gh->top; - - pspCharInfo.info.width = gh->dimension.h; - pspCharInfo.info.height = gh->dimension.v; - pspCharInfo.info.ascender = ph->ascender; - pspCharInfo.info.descender = ph->descender; - pspCharInfo.info.h_bearingX = gh->bearingX.h; - pspCharInfo.info.h_bearingY = gh->bearingY.h; - pspCharInfo.info.v_bearingX = gh->bearingX.v; - pspCharInfo.info.v_bearingY = gh->bearingY.v; - pspCharInfo.info.h_advance = gh->advance.h; - pspCharInfo.info.v_advance = gh->advance.v; - - Memory::WriteStruct(charInfoPtr, &pspCharInfo); - } - return 0; -} - -int sceFontGetCharImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) -{ - PGF_FONT *pgft; - PGF_GLYPH *gh; - int slot; - - INFO_LOG(HLE, "HACK sceFontGetCharImageRect %x, %x (%c)", fontHandle, charRectPtr, charCode); - - slot = fontHandle-1; - pgft = font_slot[slot]; - if(pgft==NULL) - return -1; - - gh = get_glyph(pgft, charCode); - - if (Memory::IsValidAddress(charRectPtr)) { - Memory::Write_U16(gh->width, charRectPtr); // character bitmap width in pixels - Memory::Write_U16(gh->width, charRectPtr+2); // character bitmap height in pixels - } - - return 0; -} - -int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) -{ - PGF_FONT *pgft; - PGF_GLYPH *gh; - int slot; - u8 line_buf[512]; - - INFO_LOG(HLE, "HACK sceFontGetCharGlyphImage %x, %x, %x (%c)", fontHandle, charCode, glyphImagePtr, charCode); - - slot = fontHandle-1; - pgft = font_slot[slot]; - if(pgft==NULL) - return -1; - - gh = get_glyph(pgft, charCode); - - int pixelFormat = Memory::Read_U32(glyphImagePtr); - int xPos64 = Memory::Read_U32(glyphImagePtr+4); - int yPos64 = Memory::Read_U32(glyphImagePtr+8); - int bufWidth = Memory::Read_U16(glyphImagePtr+12); - int bufHeight = Memory::Read_U16(glyphImagePtr+14); - int bytesPerLine = Memory::Read_U16(glyphImagePtr+16); - int buffer = Memory::Read_U32(glyphImagePtr+20); - - xPos64 = (xPos64+32)>>6; - yPos64 = (yPos64+32)>>6; - - int line = buffer + yPos64*bytesPerLine; - u8 *src = gh->bmp; - - for (int y=0; yheight; y++) { - Memory::Memcpy(line_buf, line, bytesPerLine); - int xp = xPos64; - for (int x=0; xwidth; x++) { - if(xp&1){ - line_buf[xp/2] &= 0x0f; - line_buf[xp/2] |= (*src)<<4; - }else{ - line_buf[xp/2] &= 0xf0; - line_buf[xp/2] |= (*src); - } - xp += 1; - src += 1; + Font *optimumFont = 0; + for (size_t i = 0; i < internalFonts.size(); i++) { + if (internalFonts[i]->MatchesStyle(requestedStyle, true)) { + optimumFont = GetOptimumFont(requestedStyle, optimumFont, internalFonts[i]); + break; } - Memory::Memcpy(line, line_buf, bytesPerLine); - line += bytesPerLine; + } + if (optimumFont) { + Memory::Write_U32(0, errorCodePtr); + return GetInternalFontIndex(optimumFont); + } else { + Memory::Write_U32(0, errorCodePtr); + return 0; + } +} + +// Returns the font index, not handle +int sceFontFindFont(u32 libHandlePtr, u32 fontStylePtr, u32 errorCodePtr) { + ERROR_LOG(HLE, "sceFontFindFont(%x, %x, %x)", libHandlePtr, fontStylePtr, errorCodePtr); + if (!Memory::IsValidAddress(errorCodePtr)) { + Memory::Write_U32(ERROR_FONT_INVALID_PARAMETER, errorCodePtr); + return 0; } + PGFFontStyle style; + Memory::ReadStruct(fontStylePtr, &style); + + for (size_t i = 0; i < internalFonts.size(); i++) { + if (internalFonts[i]->MatchesStyle(style, false)) { + Memory::Write_U32(0, errorCodePtr); + return i; + } + } + return -1; +} + +int sceFontGetFontInfo(u32 fontHandle, u32 fontInfoPtr) { + ERROR_LOG(HLE, "sceFontGetFontInfo(%x, %x)", fontHandle, fontInfoPtr); + + PGFFontInfo fi; + memset (&fi, 0, sizeof(fi)); + if (!Memory::IsValidAddress(fontInfoPtr)) + return 0; + + LoadedFont *font = GetLoadedFont(fontHandle, true); + if (!font) + return 0; + PGF *pgf = font->GetFont()->GetPGF(); + pgf->GetFontInfo(&fi); + fi.fontStyle = font->GetFont()->GetFontStyle(); + + Memory::WriteStruct(fontInfoPtr, &fi); return 0; } -int sceFontGetCharGlyphImage_Clip(u32 libHandler, u32 charCode, u32 glyphImagePtr, int clipXPos, int clipYPos, int clipWidth, int clipHeight) -{ - INFO_LOG(HLE, "sceFontGetCharGlyphImage_Clip %x, %x, %x (%c)", libHandler, charCode, glyphImagePtr, charCode); - return sceFontGetCharGlyphImage(libHandler, charCode, glyphImagePtr); +int sceFontGetFontInfoByIndexNumber(u32 libHandle, u32 fontInfoPtr, u32 unknown, u32 fontIndex) { + INFO_LOG(HLE, "sceFontGetFontInfoByIndexNumber(%x, %x, %i, %i)", libHandle, fontInfoPtr, unknown, fontIndex); + FontLib *fl = GetFontLib(libHandle); + u32 fontHandle = fl->GetFontHandle(fontIndex); + return sceFontGetFontInfo(fontHandle, fontInfoPtr); } -int sceFontSetAltCharacterCode(u32 libHandle, u32 charCode) -{ - DEBUG_LOG(HLE, "sceFontSetAltCharacterCode %x (%c)", libHandle, charCode); +int sceFontGetCharInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) { + INFO_LOG(HLE, "sceFontGetCharInfo(%08x, %i, %08x)", fontHandle, charCode, charInfoPtr); + if (!Memory::IsValidAddress(charInfoPtr)) + return -1; + + PGFCharInfo charInfo; + memset(&charInfo, 0, sizeof(charInfo)); + LoadedFont *font = GetLoadedFont(fontHandle, false); + if (font) { + font->GetFont()->GetPGF()->GetCharInfo(charCode, &charInfo); + } else { + ERROR_LOG(HLE, "sceFontGetCharInfo - invalid font"); + } + Memory::WriteStruct(charInfoPtr, &charInfo); return 0; } -int sceFontFlush(u32 fontHandle) -{ +// Not sure about the arguments. +int sceFontGetShadowInfo(u32 fontHandle, u32 charCode, u32 shadowCharInfoPtr) { + ERROR_LOG(HLE, "UNIMPL sceFontGetShadowInfo(%08x, %i, %08x)", fontHandle, charCode, shadowCharInfoPtr); + // TODO + return 0; +} + +int sceFontGetCharImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) { + INFO_LOG(HLE, "sceFontGetCharImageRect(%08x, %i, %08x)", fontHandle, charCode, charRectPtr); + if (!Memory::IsValidAddress(charRectPtr)) + return -1; + + PGFCharInfo charInfo; + LoadedFont *font = GetLoadedFont(fontHandle, false); + if (font) { + font->GetFont()->GetPGF()->GetCharInfo(charCode, &charInfo); + Memory::Write_U16(charInfo.bitmapWidth, charRectPtr); // character bitmap width in pixels + Memory::Write_U16(charInfo.bitmapHeight, charRectPtr + 2); // character bitmap height in pixels + } else { + ERROR_LOG(HLE, "sceFontGetCharImageRect - invalid font"); + } + return 0; +} + +int sceFontGetShadowImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) { + ERROR_LOG(HLE, "UNIMPL sceFontGetShadowImageRect()"); + return 0; +} + +int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) { + INFO_LOG(HLE, "sceFontGetCharGlyphImage(%x, %x, %x)", fontHandle, charCode, glyphImagePtr); + + int pixelFormat = Memory::Read_U32(glyphImagePtr); + int xPos64 = Memory::Read_U32(glyphImagePtr+4); + int yPos64 = Memory::Read_U32(glyphImagePtr+8); + int bufWidth = Memory::Read_U16(glyphImagePtr+12); + int bufHeight = Memory::Read_U16(glyphImagePtr+14); + int bytesPerLine = Memory::Read_U16(glyphImagePtr+16); + int buffer = Memory::Read_U32(glyphImagePtr+20); + + LoadedFont *font = GetLoadedFont(fontHandle, false); + if (!font) { + ERROR_LOG(HLE, "%08x is not a valid font handle!", fontHandle); + return 0; + } + int altCharCode = font->GetFontLib()->GetAltCharCode(); + font->GetFont()->GetPGF()->DrawCharacter(buffer, bytesPerLine, bufWidth, bufHeight, xPos64 >> 6, yPos64 >> 6, 0, 0, 8192, 8192, pixelFormat, charCode, altCharCode, FONT_PGF_CHARGLYPH); + return 0; +} + +int sceFontGetCharGlyphImage_Clip(u32 fontHandle, u32 charCode, u32 glyphImagePtr, int clipXPos, int clipYPos, int clipWidth, int clipHeight) { + INFO_LOG(HLE, "sceFontGetCharGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i)", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight); + + int pixelFormat = Memory::Read_U32(glyphImagePtr); + int xPos64 = Memory::Read_U32(glyphImagePtr+4); + int yPos64 = Memory::Read_U32(glyphImagePtr+8); + int bufWidth = Memory::Read_U16(glyphImagePtr+12); + int bufHeight = Memory::Read_U16(glyphImagePtr+14); + int bytesPerLine = Memory::Read_U16(glyphImagePtr+16); + int buffer = Memory::Read_U32(glyphImagePtr+20); + + LoadedFont *font = GetLoadedFont(fontHandle, false); + if (!font) { + ERROR_LOG(HLE, "%08x is not a valid font handle!", fontHandle); + return 0; + } + int altCharCode = font->GetFontLib()->GetAltCharCode(); + font->GetFont()->GetPGF()->DrawCharacter(buffer, bytesPerLine, bufWidth, bufHeight, xPos64 >> 6, yPos64 >> 6, clipXPos, clipYPos, clipXPos + clipWidth, clipYPos + clipHeight, pixelFormat, charCode, altCharCode, FONT_PGF_CHARGLYPH); + return 0; +} + +int sceFontSetAltCharacterCode(u32 fontLibHandle, u32 charCode) { + INFO_LOG(HLE, "sceFontSetAltCharacterCode(%08x) (%08x)", fontLibHandle, charCode); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + fl->SetAltCharCode(charCode); + } + return 0; +} + +int sceFontFlush(u32 fontHandle) { INFO_LOG(HLE, "sceFontFlush(%i)", fontHandle); + // Probably don't need to do anything here. return 0; } -int sceFontGetFontList(u32 fontLibHandle, u32 fontStylePtr, u32 numFonts) -{ - DEBUG_LOG(HLE, "sceFontGetFontList %x, %x, %x", fontLibHandle, fontStylePtr, numFonts); - - FontStyle style; - memset(&style, 0, sizeof (style)); - - style.fontH = 20 / 64.f; - style.fontV = 20 / 64.f; - style.fontHRes = 20 / 64.f; - style.fontVRes = 20 / 64.f; - style.fontStyle = 1; - //style.fontFamily - +// One would think that this should loop through the fonts loaded in the fontLibHandle, +// but it seems not. +int sceFontGetFontList(u32 fontLibHandle, u32 fontStylePtr, u32 numFonts) { + ERROR_LOG(HLE, "sceFontGetFontList(%08x, %08x, %i)", fontLibHandle, fontStylePtr, numFonts); + numFonts = std::min(numFonts, (u32)internalFonts.size()); for (u32 i = 0; i < numFonts; i++) { - Memory::WriteStruct(fontStylePtr + (sizeof(style)) * i, &style); + PGFFontStyle style = internalFonts[i]->GetFontStyle(); + Memory::WriteStruct(fontStylePtr, &style); + fontStylePtr += sizeof(style); } return 0; } -int sceFontGetNumFontList(u32 libHandle, u32 errorCodePtr) -{ - DEBUG_LOG(HLE, "UNIMPL sceFontGetNumFontList %x, %x", libHandle, errorCodePtr); +int sceFontGetNumFontList(u32 fontLibHandle, u32 errorCodePtr) { + INFO_LOG(HLE, "sceFontGetNumFontList(%08x, %08x)", fontLibHandle, errorCodePtr); if (Memory::IsValidAddress(errorCodePtr)) - { Memory::Write_U32(0, errorCodePtr); - } - return font_num; + return internalFonts.size(); } -int sceFontSetResolution(u32 fontLibHandle, float hRes, float vRes) -{ - ERROR_LOG(HLE, "UNIMPL sceFontSetResolution(%i, %f, %f)", fontLibHandle, hRes, vRes); +int sceFontSetResolution(u32 fontLibHandle, float hRes, float vRes) { + INFO_LOG(HLE, "sceFontSetResolution(%08x, %f, %f)", fontLibHandle, hRes, vRes); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + fl->SetResolution(hRes, vRes); + } + return 0; +} + +float sceFontPixelToPointH(int fontLibHandle, float fontPixelsH, u32 errorCodePtr) { + INFO_LOG(HLE, "sceFontPixelToPointH(%08x, %f, %08x)", fontLibHandle, fontPixelsH, errorCodePtr); + if (Memory::IsValidAddress(errorCodePtr)) + Memory::Write_U32(0, errorCodePtr); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + return fontPixelsH * pointDPI / fl->FontHRes(); + } + return 0; +} + +float sceFontPixelToPointV(int fontLibHandle, float fontPixelsV, u32 errorCodePtr) { + INFO_LOG(HLE, "UNIMPL sceFontPixelToPointV(%08x, %f, %08x)", fontLibHandle, fontPixelsV, errorCodePtr); + if (Memory::IsValidAddress(errorCodePtr)) + Memory::Write_U32(0, errorCodePtr); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + return fontPixelsV * pointDPI / fl->FontVRes(); + } + return 0; +} + +float sceFontPointToPixelH(int fontLibHandle, float fontPointsH, u32 errorCodePtr) { + INFO_LOG(HLE, "UNIMPL sceFontPointToPixelH(%08x, %f, %08x)", fontLibHandle, fontPointsH, errorCodePtr); + if (Memory::IsValidAddress(errorCodePtr)) + Memory::Write_U32(0, errorCodePtr); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + return fontPointsH * fl->FontHRes() / pointDPI; + } + return 0; +} + +float sceFontPointToPixelV(int fontLibHandle, float fontPointsV, u32 errorCodePtr) { + INFO_LOG(HLE, "UNIMPL sceFontPointToPixelV(%08x, %f, %08x)", fontLibHandle, fontPointsV, errorCodePtr); + if (Memory::IsValidAddress(errorCodePtr)) + Memory::Write_U32(0, errorCodePtr); + FontLib *fl = GetFontLib(fontLibHandle); + if (fl) { + return fontPointsV * fl->FontVRes() / pointDPI; + } return 0; } @@ -930,10 +927,17 @@ int sceFontCalcMemorySize() { return 0; } +int sceFontGetShadowGlyphImage() { + ERROR_LOG(HLE, "UNIMPL sceFontGetShadowGlyphImage()"); + return 0; +} +int sceFontGetShadowGlyphImage_Clip() { + ERROR_LOG(HLE, "UNIMPL sceFontGetShadowGlyphImage_Clip()"); + return 0; +} -const HLEFunction sceLibFont[] = -{ +const HLEFunction sceLibFont[] = { {0x67f17ed7, WrapU_UU, "sceFontNewLib"}, {0x574b6fbc, WrapI_U, "sceFontDoneLib"}, {0x48293280, WrapI_UFF, "sceFontSetResolution"}, @@ -942,30 +946,29 @@ const HLEFunction sceLibFont[] = {0x099ef33c, WrapI_UUU, "sceFontFindOptimumFont"}, {0x681e61a7, WrapI_UUU, "sceFontFindFont"}, {0x2f67356a, WrapI_V, "sceFontCalcMemorySize"}, - {0x5333322d, WrapI_UUU, "sceFontGetFontInfoByIndexNumber"}, + {0x5333322d, WrapI_UUUU, "sceFontGetFontInfoByIndexNumber"}, {0xa834319d, WrapU_UUUU, "sceFontOpen"}, - {0x57fcb733, WrapU_UUUU, "sceFontOpenUserFile"}, + {0x57fcb733, WrapU_UCUU, "sceFontOpenUserFile"}, {0xbb8e7fe6, WrapU_UUUU, "sceFontOpenUserMemory"}, {0x3aea8cb6, WrapI_U, "sceFontClose"}, {0x0da7535e, WrapI_UU, "sceFontGetFontInfo"}, {0xdcc80c2f, WrapI_UUU, "sceFontGetCharInfo"}, + {0xaa3de7b5, WrapI_UUU, "sceFontGetShadowInfo"}, {0x5c3e4a9e, WrapI_UUU, "sceFontGetCharImageRect"}, + {0x48b06520, WrapI_UUU, "sceFontGetShadowImageRect"}, {0x980f4895, WrapI_UUU, "sceFontGetCharGlyphImage"}, {0xca1e6945, WrapI_UUUIIII, "sceFontGetCharGlyphImage_Clip"}, - {0x74b21701, 0, "sceFontPixelToPointH"}, - {0xf8f0752e, 0, "sceFontPixelToPointV"}, - {0x472694cd, 0, "sceFontPointToPixelH"}, - {0x3c4b7e82, 0, "sceFontPointToPixelV"}, + {0x74b21701, WrapF_IFU, "sceFontPixelToPointH"}, + {0xf8f0752e, WrapF_IFU, "sceFontPixelToPointV"}, + {0x472694cd, WrapF_IFU, "sceFontPointToPixelH"}, + {0x3c4b7e82, WrapF_IFU, "sceFontPointToPixelV"}, {0xee232411, WrapI_UU, "sceFontSetAltCharacterCode"}, - {0xaa3de7b5, 0, "sceFontGetShadowInfo"}, - {0x48b06520, 0, "sceFontGetShadowImageRect"}, - {0x568be516, 0, "sceFontGetShadowGlyphImage"}, - {0x5dcf6858, 0, "sceFontGetShadowGlyphImage_Clip"}, + {0x568be516, WrapI_V, "sceFontGetShadowGlyphImage"}, + {0x5dcf6858, WrapI_V, "sceFontGetShadowGlyphImage_Clip"}, {0x02d7f94b, WrapI_U, "sceFontFlush"}, - }; -void Register_sceFont() -{ + +void Register_sceFont() { RegisterModule("sceLibFont", ARRAY_SIZE(sceLibFont), sceLibFont); } diff --git a/Core/HLE/sceFont.h b/Core/HLE/sceFont.h index a29bb89fd2..84158df418 100644 --- a/Core/HLE/sceFont.h +++ b/Core/HLE/sceFont.h @@ -5,6 +5,7 @@ class PointerWrap; void Register_sceFont(); void __FontInit(); +void __FontShutdown(); void __FontDoState(PointerWrap &p); typedef u32 FontLibraryHandle; diff --git a/Core/HLE/sceGe.cpp b/Core/HLE/sceGe.cpp index 9056c6b0e2..43bdbccf5a 100644 --- a/Core/HLE/sceGe.cpp +++ b/Core/HLE/sceGe.cpp @@ -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; } diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index ceaac0b6a1..2bb1ea52b7 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -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(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(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(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(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(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(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(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(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(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(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(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(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" }, { 0xab96437f, &WrapU_CI, "sceIoSync" }, { 0x6d08a871, &WrapU_C, "sceIoUnassign" }, - { 0x42EC03AC, &WrapU_IVI, "sceIoWrite" }, //(int fd, void *data, int size); - { 0x0facab19, &WrapU_IVI, "sceIoWriteAsync" }, + { 0x42EC03AC, &WrapU_IUI, "sceIoWrite" }, //(int fd, void *data, int size); + { 0x0facab19, &WrapU_IUI, "sceIoWriteAsync" }, { 0x35dbd746, &WrapI_IU, "sceIoWaitAsyncCB" }, { 0xe23eec33, &WrapI_IU, "sceIoWaitAsync" }, }; diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 0fc342f1c3..7f82ee5a8d 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -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"}, {0xBD123D9E,sceKernelDelaySysClockThread,"sceKernelDelaySysClockThread"}, {0x1181E963,sceKernelDelaySysClockThreadCB,"sceKernelDelaySysClockThreadCB"}, - {0xceadeb47,sceKernelDelayThread,"sceKernelDelayThread"}, - {0x68da9e36,sceKernelDelayThreadCB,"sceKernelDelayThreadCB"}, + {0xceadeb47,WrapI_U,"sceKernelDelayThread"}, + {0x68da9e36,WrapI_U,"sceKernelDelayThreadCB"}, {0xaa73c935,sceKernelExitThread,"sceKernelExitThread"}, {0x809ce29b,sceKernelExitDeleteThread,"sceKernelExitDeleteThread"}, {0x94aa61ee,sceKernelGetThreadCurrentPriority,"sceKernelGetThreadCurrentPriority"}, @@ -598,7 +644,7 @@ const HLEFunction ThreadManForUser[] = {0x82826f70,sceKernelSleepThreadCB,"sceKernelSleepThreadCB"}, {0xF475845D,&WrapI_IUU,"sceKernelStartThread"}, {0x9944f31f,sceKernelSuspendThread,"sceKernelSuspendThread"}, - {0x616403ba,WrapI_U,"sceKernelTerminateThread"}, + {0x616403ba,WrapI_I,"sceKernelTerminateThread"}, {0x383f7bcc,WrapI_I,"sceKernelTerminateDeleteThread"}, {0x840E8133,WrapI_IU,"sceKernelWaitThreadEndCB"}, {0xd13bde95,sceKernelCheckThreadStack,"sceKernelCheckThreadStack"}, @@ -611,9 +657,9 @@ const HLEFunction ThreadManForUser[] = {0xdb738f35,WrapI_U,"sceKernelGetSystemTime"}, {0x369ed59d,WrapU_V,"sceKernelGetSystemTimeLow"}, - {0x8218B4DD,&WrapU_U,"sceKernelReferGlobalProfiler"}, - {0x627E6F3A,&WrapU_U,"sceKernelReferSystemStatus"}, - {0x64D4540E,0,"sceKernelReferThreadProfiler"}, + {0x8218B4DD,WrapI_U,"sceKernelReferGlobalProfiler"}, + {0x627E6F3A,WrapI_U,"sceKernelReferSystemStatus"}, + {0x64D4540E,WrapU_U,"sceKernelReferThreadProfiler"}, //Fifa Street 2 uses alarms {0x6652b8ca,WrapI_UUU,"sceKernelSetAlarm"}, diff --git a/Core/HLE/sceKernel.h b/Core/HLE/sceKernel.h index 17911153d9..65df209f35 100644 --- a/Core/HLE/sceKernel.h +++ b/Core/HLE/sceKernel.h @@ -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, diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 299a67b40a..468243ad1d 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -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"}, - {0xD61E6961, WrapU_UU, "sceKernelReleaseSubIntrHandler"}, + {0xD61E6961, WrapI_II, "sceKernelReleaseSubIntrHandler"}, {0xFB8E22EC, WrapU_UU, "sceKernelEnableSubIntr"}, {0x8A389411, WrapU_UU, "sceKernelDisableSubIntr"}, {0x5CB5A78B, 0, "sceKernelSuspendSubIntr"}, diff --git a/Core/HLE/sceKernelInterrupt.h b/Core/HLE/sceKernelInterrupt.h index b1e27ab125..7c0ef381ce 100644 --- a/Core/HLE/sceKernelInterrupt.h +++ b/Core/HLE/sceKernelInterrupt.h @@ -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(); diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index b4d8f9d9d9..b49b777613 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -390,6 +390,14 @@ void sceKernelReferFplStatus() ////////////////////////////////////////////////////////////////////////// //00:49:12 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(id)); + return kernelObjects.Destroy(id); } -void sceKernelGetBlockHeadAddr() +u32 sceKernelGetBlockHeadAddr(SceUID id) { - SceUID id = PARAM(0); - u32 error; PartitionMemoryBlock *block = kernelObjects.Get(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(uid, error); if (vpl) @@ -1135,9 +1178,9 @@ const HLEFunction SysMemUserForUser[] = { {0xA291F107,sceKernelMaxFreeMemSize,"sceKernelMaxFreeMemSize"}, {0xF919F628,sceKernelTotalFreeMemSize,"sceKernelTotalFreeMemSize"}, {0x3FC9AE6A,WrapU_V,"sceKernelDevkitVersion"}, - {0x237DBD4F,sceKernelAllocPartitionMemory,"sceKernelAllocPartitionMemory"}, //(int size) ? - {0xB6D61D02,sceKernelFreePartitionMemory,"sceKernelFreePartitionMemory"}, //(void *ptr) ? - {0x9D9A5BA1,sceKernelGetBlockHeadAddr,"sceKernelGetBlockHeadAddr"}, //(void *ptr) ? + {0x237DBD4F,WrapI_ICIUU,"sceKernelAllocPartitionMemory"}, //(int size) ? + {0xB6D61D02,WrapI_I,"sceKernelFreePartitionMemory"}, //(void *ptr) ? + {0x9D9A5BA1,WrapU_I,"sceKernelGetBlockHeadAddr"}, //(void *ptr) ? {0x13a5abef,sceKernelPrintf,"sceKernelPrintf 0x13a5abef"}, {0x7591c7db,&WrapV_I,"sceKernelSetCompiledSdkVersion"}, {0x342061E5,&WrapV_I,"sceKernelSetCompiledSdkVersion370"}, diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 294b789a52..bb23a869df 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -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"}, + {0x977DE386,&WrapU_CUU,"sceKernelLoadModule"}, {0xb7f46618,&WrapU_UUU,"sceKernelLoadModuleByID"}, {0x50F0C1EC,&WrapV_UUUUU,"sceKernelStartModule"}, {0xD675EBB8,&sceKernelExitGame,"sceKernelSelfStopUnloadModule"}, //HACK - {0xd1ff982a,&WrapV_UUUUU,"sceKernelStopModule"}, + {0xd1ff982a,&WrapU_UUUUU,"sceKernelStopModule"}, {0x2e0911aa,WrapU_U,"sceKernelUnloadModule"}, {0x710F61B5,0,"sceKernelLoadModuleMs"}, {0xF9275D98,0,"sceKernelLoadModuleBufferUsbWlan"}, ///??? diff --git a/Core/HLE/sceKernelMutex.cpp b/Core/HLE/sceKernelMutex.cpp index e652adfeae..173e5bb88f 100644 --- a/Core/HLE/sceKernelMutex.cpp +++ b/Core/HLE/sceKernelMutex.cpp @@ -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); diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index aa093cc09c..525f04680d 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -20,6 +20,7 @@ #include #include +#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(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::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 calls_; + u32 genId() { return ++idGen_; } + std::map calls_; std::vector 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 registeredCallbacks[THREAD_CALLBACK_NUM_TYPES]; std::list readyCallbacks[THREAD_CALLBACK_NUM_TYPES]; - std::list pendingMipsCalls; + std::list 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(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(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; } diff --git a/Core/HLE/sceKernelThread.h b/Core/HLE/sceKernelThread.h index 1415f2bf00..07883a7570 100644 --- a/Core/HLE/sceKernelThread.h +++ b/Core/HLE/sceKernelThread.h @@ -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 diff --git a/Core/HLE/sceKernelVTimer.cpp b/Core/HLE/sceKernelVTimer.cpp index 45ea5ecb3c..0f7e24f34c 100644 --- a/Core/HLE/sceKernelVTimer.cpp +++ b/Core/HLE/sceKernelVTimer.cpp @@ -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 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(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(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(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(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(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::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(uid); } -u32 sceKernelStartVTimer(u32 uid) { - ERROR_LOG(HLE,"FAKE sceKernelStartVTimer(%i)", uid); - - u32 error; - VTimer *vt = kernelObjects.Get(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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!"); -} +} \ No newline at end of file diff --git a/Core/HLE/sceKernelVTimer.h b/Core/HLE/sceKernelVTimer.h index 9cde7913e5..9153af3c06 100644 --- a/Core/HLE/sceKernelVTimer.h +++ b/Core/HLE/sceKernelVTimer.h @@ -35,4 +35,6 @@ u32 sceKernelSetVTimerTimeWide(u32 uid, u64 timeClock); // TODO void _sceKernelReturnFromTimerHandler(); +void __KernelVTimerInit(); +void __KernelVTimerDoState(PointerWrap &p); KernelObject *__KernelVTimerObject(); diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index c1afe5c0fe..218e230244 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -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"}, {0xC45C99CC,WrapU_UUU,"sceMpegQueryUserdataEsSize"}, {0x234586AE,WrapU_UUI,"sceMpegChangeGetAvcAuMode"}, + {0x63B9536A,WrapU_U,"sceMpegAvcResourceGetAvcDecTopAddr"}, + {0x8160a2fe,WrapU_U,"sceMpegAvcResourceFinish"}, + {0xaf26bb01,WrapU_U,"sceMpegAvcResourceGetAvcEsBuf"}, + {0xfcbdb5ad,WrapU_U,"sceMpegAvcResourceInit"}, + {0xF5E7EA31,WrapI_UUUI,"sceMpegAvcConvertToYuv420"}, }; const HLEFunction sceMp3[] = diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 66034051b1..c4fd1c3a2c 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -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"}, {0x7945ecda, 0, "sceNetAdhocMatchingTerm"}, {0xca5eda6f, 0, "sceNetAdhocMatchingCreate"}, {0x93ef3843, 0, "sceNetAdhocMatchingStart"}, diff --git a/Core/HLE/sceP3da.cpp b/Core/HLE/sceP3da.cpp new file mode 100644 index 0000000000..1cbfd63a5c --- /dev/null +++ b/Core/HLE/sceP3da.cpp @@ -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"}, + {0x43F756a2, WrapU_V, "sceP3daBridgeExit"}, + {0x013016f3, WrapU_UUUUU, "sceP3daBridgeCore"}, +}; + +void Register_sceP3da() +{ + RegisterModule("sceP3da", ARRAY_SIZE(sceP3da), sceP3da); +} diff --git a/Core/HLE/sceP3da.h b/Core/HLE/sceP3da.h new file mode 100644 index 0000000000..b8d4e5b705 --- /dev/null +++ b/Core/HLE/sceP3da.h @@ -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(); diff --git a/Core/HLE/scePower.cpp b/Core/HLE/scePower.cpp index 625aab9720..1061004bc1 100644 --- a/Core/HLE/scePower.cpp +++ b/Core/HLE/scePower.cpp @@ -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"}, {0xB1A52C83,0,"scePowerGetCpuClockFrequencyFloat"}, {0x9BADB3EB,0,"scePowerGetBusClockFrequencyFloat"}, - {0x737486F2,WrapV_UUU,"scePowerSetClockFrequency"}, + {0x737486F2,WrapU_UUU,"scePowerSetClockFrequency"}, {0x34f9c463,WrapU_V,"scePowerGetPllClockFrequencyInt"}, - {0xea382a27,0,"scePowerGetPllClockFrequencyFloat"}, - {0xebd177d6,WrapV_UUU,"scePower_driver_EBD177D6"}, //TODO: used in a few places, jpcsp says is the same as scePowerSetClockFrequency - {0x469989ad,WrapV_UUU,"scePower_469989ad"}, // This is also the same as SetClockFrequency + {0xea382a27,WrapF_V,"scePowerGetPllClockFrequencyFloat"}, + {0xebd177d6,WrapU_UUU,"scePower_driver_EBD177D6"}, //TODO: used in a few places, jpcsp says is the same as scePowerSetClockFrequency + {0x469989ad,WrapU_UUU,"scePower_469989ad"}, // This is also the same as SetClockFrequency {0xa85880d0,WrapU_V,"scePower_a85880d0_IsPSPNonFat"}, }; diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index 2251335003..73f3a6f9c6 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -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 psmfMap; static std::map 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"}, {0xC7DB3A5B, WrapU_UUU, "scePsmfGetCurrentStreamType"}, {0x28240568, WrapU_U, "scePsmfGetCurrentStreamNumber"}, {0x1E6D9013, WrapU_UUU, "scePsmfSpecifyStreamWithStreamType"}, {0x0C120E1D, WrapU_UUU, "scePsmfSpecifyStreamWithStreamTypeNumber"}, - {0x4BC9BDE0, 0, "scePsmfSpecifyStream"}, + {0x4BC9BDE0, WrapU_UI, "scePsmfSpecifyStream"}, {0x76D3AEBA, WrapU_UU, "scePsmfGetPresentationStartTime"}, {0xBD8AE0D8, WrapU_UU, "scePsmfGetPresentationEndTime"}, {0xEAED89CD, WrapU_U, "scePsmfGetNumberOfStreams"}, @@ -963,7 +986,7 @@ const HLEFunction scePsmfPlayer[] = {0xe792cd94, WrapI_U, "scePsmfPlayerReleasePsmf"}, {0xf3efaa91, WrapU_UUU, "scePsmfPlayerGetCurrentPlayMode"}, {0xf8ef08a6, WrapI_U, "scePsmfPlayerGetCurrentStatus"}, - {0x2D0E4E0A, WrapI_U, "scePsmfPlayerSetTempBuf"}, + {0x2D0E4E0A, WrapI_UUU, "scePsmfPlayerSetTempBuf"}, }; void Register_scePsmf() { diff --git a/Core/HLE/scePspNpDrm_user.cpp b/Core/HLE/scePspNpDrm_user.cpp index f47f4e56a0..a9086911a4 100644 --- a/Core/HLE/scePspNpDrm_user.cpp +++ b/Core/HLE/scePspNpDrm_user.cpp @@ -65,4 +65,6 @@ const HLEFunction sceNpDrm[] = void Register_sceNpDrm() { RegisterModule("sceNpDrm", ARRAY_SIZE(sceNpDrm), sceNpDrm); + RegisterModule("scePspNpDrm_user", ARRAY_SIZE(sceNpDrm), sceNpDrm); } + \ No newline at end of file diff --git a/Core/HLE/sceSas.cpp b/Core/HLE/sceSas.cpp index 16f3fec15d..59f4897c5c 100644 --- a/Core/HLE/sceSas.cpp +++ b/Core/HLE/sceSas.cpp @@ -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; diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index b382185811..b54947382d 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -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 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"}, @@ -338,7 +387,7 @@ const HLEFunction sceUmdUser[] = {0x20628E6F,&WrapU_V,"sceUmdGetErrorStat"}, {0x340B7686,WrapU_U,"sceUmdGetDiscInfo"}, {0xAEE7404D,&WrapU_U,"sceUmdRegisterUMDCallBack"}, - {0xBD2BDE07,&WrapU_U,"sceUmdUnRegisterUMDCallBack"}, + {0xBD2BDE07,&WrapI_I,"sceUmdUnRegisterUMDCallBack"}, {0x87533940,WrapU_V,"sceUmdReplaceProhibit"}, {0x87533940,WrapU_V,"sceUmdReplacePermit"}, }; diff --git a/Core/HLE/sceUtility.cpp b/Core/HLE/sceUtility.cpp index 8a1fa235c2..677b271fac 100644 --- a/Core/HLE/sceUtility.cpp +++ b/Core/HLE/sceUtility.cpp @@ -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) diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index ce79551865..1abdf4e74b 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -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? diff --git a/Core/Host.h b/Core/Host.h index 01573a1e65..747a8037c2 100644 --- a/Core/Host.h +++ b/Core/Host.h @@ -21,7 +21,6 @@ #include #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; diff --git a/Core/MIPS/ARM/ArmAsm.cpp b/Core/MIPS/ARM/ArmAsm.cpp index d7d1e4b907..e26ce21be7 100644 --- a/Core/MIPS/ARM/ArmAsm.cpp +++ b/Core/MIPS/ARM/ArmAsm.cpp @@ -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(); } diff --git a/Core/MIPS/ARM/ArmCompALU.cpp b/Core/MIPS/ARM/ArmCompALU.cpp index cf2752a56f..20a4f27449 100644 --- a/Core/MIPS/ARM/ArmCompALU.cpp +++ b/Core/MIPS/ARM/ArmCompALU.cpp @@ -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; diff --git a/Core/MIPS/ARM/ArmCompBranch.cpp b/Core/MIPS/ARM/ArmCompBranch.cpp index f3b149c6c7..42b130593c 100644 --- a/Core/MIPS/ARM/ArmCompBranch.cpp +++ b/Core/MIPS/ARM/ArmCompBranch.cpp @@ -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; } diff --git a/Core/MIPS/ARM/ArmCompFPU.cpp b/Core/MIPS/ARM/ArmCompFPU.cpp index 78a1aa39f0..2ef6bab6f5 100644 --- a/Core/MIPS/ARM/ArmCompFPU.cpp +++ b/Core/MIPS/ARM/ArmCompFPU.cpp @@ -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; } } diff --git a/Core/MIPS/ARM/ArmCompLoadStore.cpp b/Core/MIPS/ARM/ArmCompLoadStore.cpp index fff481a295..e8c7a4a4fb 100644 --- a/Core/MIPS/ARM/ArmCompLoadStore.cpp +++ b/Core/MIPS/ARM/ArmCompLoadStore.cpp @@ -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 ; diff --git a/Core/MIPS/ARM/ArmCompVFPU.cpp b/Core/MIPS/ARM/ArmCompVFPU.cpp index e599aacf23..8a0dc74d26 100644 --- a/Core/MIPS/ARM/ArmCompVFPU.cpp +++ b/Core/MIPS/ARM/ArmCompVFPU.cpp @@ -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) { diff --git a/Core/MIPS/ARM/ArmJit.cpp b/Core/MIPS/ARM/ArmJit.cpp index 273b3e1bdd..f2e57473b9 100644 --- a/Core/MIPS/ARM/ArmJit.cpp +++ b/Core/MIPS/ARM/ArmJit.cpp @@ -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: diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h index 3cd6673991..1da53982ad 100644 --- a/Core/MIPS/ARM/ArmJit.h +++ b/Core/MIPS/ARM/ArmJit.h @@ -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; diff --git a/Core/MIPS/ARM/ArmJitCache.cpp b/Core/MIPS/ARM/ArmJitCache.cpp index 62ec8fc496..c0b95c543e 100644 --- a/Core/MIPS/ARM/ArmJitCache.cpp +++ b/Core/MIPS/ARM/ArmJitCache.cpp @@ -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(); } diff --git a/Core/MIPS/ARM/ArmRegCache.cpp b/Core/MIPS/ARM/ArmRegCache.cpp index 6463e1349c..f3054a7c22 100644 --- a/Core/MIPS/ARM/ArmRegCache.cpp +++ b/Core/MIPS/ARM/ArmRegCache.cpp @@ -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 diff --git a/Core/MIPS/ARM/ArmRegCache.h b/Core/MIPS/ARM/ArmRegCache.h index a06d61a32c..3cbe27f4da 100644 --- a/Core/MIPS/ARM/ArmRegCache.h +++ b/Core/MIPS/ARM/ArmRegCache.h @@ -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_; diff --git a/Core/MIPS/ARM/ArmRegCacheFPU.cpp b/Core/MIPS/ARM/ArmRegCacheFPU.cpp index 59314f3d5f..98a0f5bca8 100644 --- a/Core/MIPS/ARM/ArmRegCacheFPU.cpp +++ b/Core/MIPS/ARM/ArmRegCacheFPU.cpp @@ -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 + } +} diff --git a/Core/MIPS/ARM/ArmRegCacheFPU.h b/Core/MIPS/ARM/ArmRegCacheFPU.h index 6b9fef2345..c22cbecf9e 100644 --- a/Core/MIPS/ARM/ArmRegCacheFPU.h +++ b/Core/MIPS/ARM/ArmRegCacheFPU.h @@ -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() {} -}; \ No newline at end of file + 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; +}; diff --git a/Core/MIPS/MIPS.cpp b/Core/MIPS/MIPS.cpp index f7fc64a752..706b95f1e9 100644 --- a/Core/MIPS/MIPS.cpp +++ b/Core/MIPS/MIPS.cpp @@ -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])); diff --git a/Core/MIPS/MIPSDis.cpp b/Core/MIPS/MIPSDis.cpp index 638f84ecdf..3aaac33b4e 100644 --- a/Core/MIPS/MIPSDis.cpp +++ b/Core/MIPS/MIPSDis.cpp @@ -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) diff --git a/Core/MIPS/MIPSInt.cpp b/Core/MIPS/MIPSInt.cpp index c8abb81931..8d423db81f 100644 --- a/Core/MIPS/MIPSInt.cpp +++ b/Core/MIPS/MIPSInt.cpp @@ -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; } diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index 0267af829e..1955ccb43c 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -36,6 +36,7 @@ // sv.s #include "../Core.h" +#include "Core/Reporting.h" #include @@ -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"); } } diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index 626eab23de..457d4310fa 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -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."); } diff --git a/Core/MIPS/x86/CompALU.cpp b/Core/MIPS/x86/CompALU.cpp index 7b447674f2..f14343240f 100644 --- a/Core/MIPS/x86/CompALU.cpp +++ b/Core/MIPS/x86/CompALU.cpp @@ -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); diff --git a/Core/MIPS/x86/CompBranch.cpp b/Core/MIPS/x86/CompBranch.cpp index d5c76463aa..168a11de96 100644 --- a/Core/MIPS/x86/CompBranch.cpp +++ b/Core/MIPS/x86/CompBranch.cpp @@ -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; diff --git a/Core/MIPS/x86/CompFPU.cpp b/Core/MIPS/x86/CompFPU.cpp index bee31435cc..e154df5170 100644 --- a/Core/MIPS/x86/CompFPU.cpp +++ b/Core/MIPS/x86/CompFPU.cpp @@ -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}; diff --git a/Core/MIPS/x86/CompLoadStore.cpp b/Core/MIPS/x86/CompLoadStore.cpp index f0dc88e1d2..2ab903c4d0 100644 --- a/Core/MIPS/x86/CompLoadStore.cpp +++ b/Core/MIPS/x86/CompLoadStore.cpp @@ -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) { diff --git a/Core/MIPS/x86/CompVFPU.cpp b/Core/MIPS/x86/CompVFPU.cpp index 670c9df44c..a2b0f34779 100644 --- a/Core/MIPS/x86/CompVFPU.cpp +++ b/Core/MIPS/x86/CompVFPU.cpp @@ -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(); } -} \ No newline at end of file +} diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp index 6a5bb0ac54..0dfa1ff0d9 100644 --- a/Core/MIPS/x86/Jit.cpp +++ b/Core/MIPS/x86/Jit.cpp @@ -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) { } diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index f5bf0bdf53..0f05e32eba 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -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 skipChecks_; const u8 *safe_; }; friend class JitSafeMem; diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index e1beb4cade..2e582d22d1 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -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) diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp new file mode 100644 index 0000000000..a64528c61e --- /dev/null +++ b/Core/Reporting.cpp @@ -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 +#include +#include + +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(); + } + +} \ No newline at end of file diff --git a/Core/Reporting.h b/Core/Reporting.h new file mode 100644 index 0000000000..52de51a385 --- /dev/null +++ b/Core/Reporting.h @@ -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, ...); +} \ No newline at end of file diff --git a/Core/System.cpp b/Core/System.cpp index 11fa6032a6..8a0581b7bf 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -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; diff --git a/Core/Util/BlockAllocator.cpp b/Core/Util/BlockAllocator.cpp index 227d28f1ab..4c3af44b32 100644 --- a/Core/Util/BlockAllocator.cpp +++ b/Core/Util/BlockAllocator.cpp @@ -1,3 +1,20 @@ +// 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 "Log.h" #include "BlockAllocator.h" #include "ChunkFile.h" @@ -28,7 +45,7 @@ void BlockAllocator::Shutdown() blocks.clear(); } -u32 BlockAllocator::AllocAligned(u32 &size, u32 grain, bool fromTop, const char *tag) +u32 BlockAllocator::AllocAligned(u32 &size, u32 sizeGrain, u32 grain, bool fromTop, const char *tag) { // Sanity check if (size == 0 || size > rangeSize_) { @@ -39,17 +56,21 @@ u32 BlockAllocator::AllocAligned(u32 &size, u32 grain, bool fromTop, const char // It could be off step, but the grain should generally be a power of 2. if (grain < grain_) grain = grain_; + if (sizeGrain < grain_) + sizeGrain = grain_; // upalign size to grain - size = (size + grain - 1) & ~(grain - 1); + size = (size + sizeGrain - 1) & ~(sizeGrain - 1); if (!fromTop) { //Allocate from bottom of mem for (std::list::iterator iter = blocks.begin(); iter != blocks.end(); iter++) { - BlockAllocator::Block &b = *iter; + Block &b = *iter; u32 offset = b.start % grain; + if (offset != 0) + offset = grain - offset; u32 needed = offset + size; if (b.taken == false && b.size >= needed) { @@ -75,9 +96,8 @@ u32 BlockAllocator::AllocAligned(u32 &size, u32 grain, bool fromTop, const char // Allocate from top of mem. for (std::list::reverse_iterator iter = blocks.rbegin(); iter != blocks.rend(); ++iter) { - std::list::reverse_iterator hey = iter; - BlockAllocator::Block &b = *((++hey).base()); //yes, confusing syntax. reverse_iterators are confusing - u32 offset = b.start % grain; + Block &b = *iter; + u32 offset = (b.start + b.size - size) % grain; u32 needed = offset + size; if (b.taken == false && b.size >= needed) { @@ -85,16 +105,17 @@ u32 BlockAllocator::AllocAligned(u32 &size, u32 grain, bool fromTop, const char { b.taken = true; b.SetTag(tag); - return b.start + offset; + return b.start; } else { - blocks.insert(hey.base(), Block(b.start, b.size - needed, false)); + std::list::iterator pos = iter.base(); + blocks.insert(--pos, Block(b.start, b.size - needed, false)); b.taken = true; b.start += b.size - needed; b.size = needed; b.SetTag(tag); - return b.start + offset; + return b.start; } } } @@ -109,7 +130,7 @@ u32 BlockAllocator::AllocAligned(u32 &size, u32 grain, bool fromTop, const char u32 BlockAllocator::Alloc(u32 &size, bool fromTop, const char *tag) { // We want to make sure it's aligned in case AllocAt() was used. - return AllocAligned(size, grain_, fromTop, tag); + return AllocAligned(size, grain_, grain_, fromTop, tag); } u32 BlockAllocator::AllocAt(u32 position, u32 size, const char *tag) @@ -290,7 +311,7 @@ void BlockAllocator::ListBlocks() for (std::list::const_iterator iter = blocks.begin(); iter != blocks.end(); iter++) { const Block &b = *iter; - INFO_LOG(HLE, "Block: %08x - %08x size %08x taken=%i tag=%s", b.start, b.start+b.size, b.size, b.taken ? 1:0, b.tag); + INFO_LOG(HLE, "Block: %08x - %08x size %08x taken=%i tag=%s", b.start, b.start+b.size, b.size, b.taken ? 1:0, b.tag); } } diff --git a/Core/Util/BlockAllocator.h b/Core/Util/BlockAllocator.h index 98cb3e1cd2..a4354b6dbb 100644 --- a/Core/Util/BlockAllocator.h +++ b/Core/Util/BlockAllocator.h @@ -1,3 +1,19 @@ +// 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 @@ -9,8 +25,7 @@ class PointerWrap; -// Generic allocator thingy -// Allocates blocks from a range +// Generic allocator thingy. Allocates blocks from a range. class BlockAllocator { @@ -25,7 +40,7 @@ public: // WARNING: size can be modified upwards! u32 Alloc(u32 &size, bool fromTop = false, const char *tag = 0); - u32 AllocAligned(u32 &size, u32 grain, bool fromTop = false, const char *tag = 0); + u32 AllocAligned(u32 &size, u32 sizeGrain, u32 grain, bool fromTop = false, const char *tag = 0); u32 AllocAt(u32 position, u32 size, const char *tag = 0); bool Free(u32 position); diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 4a77375ac2..c920d73018 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -100,7 +100,7 @@ static void EndVertexDataAndDraw(int prim) { static u32 __PPGeDoAlloc(u32 &size, bool fromTop, const char *name) { u32 ptr = kernelMemory.Alloc(size, fromTop, name); // Didn't get it. - if (ptr == -1) + if (ptr == (u32)-1) return 0; return ptr; } @@ -199,15 +199,19 @@ void PPGeBegin() dataWritePtr = dataPtr; // Set up the correct states for UI drawing + WriteCmd(GE_CMD_OFFSETADDR, 0); WriteCmd(GE_CMD_ALPHABLENDENABLE, 1); WriteCmd(GE_CMD_BLENDMODE, 2 | (3 << 4)); WriteCmd(GE_CMD_ALPHATESTENABLE, 0); WriteCmd(GE_CMD_COLORTESTENABLE, 0); WriteCmd(GE_CMD_ZTESTENABLE, 0); + WriteCmd(GE_CMD_LIGHTINGENABLE, 0); WriteCmd(GE_CMD_FOGENABLE, 0); WriteCmd(GE_CMD_STENCILTESTENABLE, 0); WriteCmd(GE_CMD_CULLFACEENABLE, 0); WriteCmd(GE_CMD_CLEARMODE, 0); // Normal mode + WriteCmd(GE_CMD_MASKRGB, 0); + WriteCmd(GE_CMD_MASKALPHA, 0); PPGeSetDefaultTexture(); diff --git a/Core/Util/Pool.h b/Core/Util/Pool.h deleted file mode 100644 index dee8633c10..0000000000 --- a/Core/Util/Pool.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "../../Globals.h" - -// pool allocator -template -class Pool -{ - T pool[size]; - int count; -public: - Pool() - { - Reset(); - } - void Reset() - { - count=0; - } - T* Alloc() - { - _dbg_assert_msg_(CPU,countdirtyAfterDisplay; + } + return true; +} + void GLES_GPU::CopyDisplayToOutput() { + glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); transformDraw_.Flush(); - if (!g_Config.bBufferedRendering) - return; EndDebugDraw(); framebufferManager_.CopyDisplayToOutput(); + framebufferManager_.EndFrame(); shaderManager_->DirtyShader(); shaderManager_->DirtyUniform(DIRTY_ALL); @@ -287,7 +299,7 @@ void GLES_GPU::PreExecuteOp(u32 op, u32 diff) { if (flushBeforeCommand_[cmd] == 1 || (diff && flushBeforeCommand_[cmd] == 2)) { if (dumpThisFrame_) { - NOTICE_LOG(G3D, "================ FLUSH ================"); + NOTICE_LOG(HLE, "================ FLUSH ================"); } transformDraw_.Flush(); } @@ -312,10 +324,13 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { case GE_CMD_PRIM: { - if (gstate_c.skipDrawReason) - return; + // This drives all drawing. All other state we just buffer up, then we apply it only + // when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization. + // This also make skipping drawing very effective. framebufferManager_.SetRenderFrameBuffer(); + if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) + return; u32 count = data & 0xFFFF; u32 type = data >> 16; @@ -649,6 +664,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { { // TODO: Here we should check if the transfer overlaps a framebuffer or any textures, // and take appropriate action. This is a block transfer between RAM and VRAM, or vice versa. + // Can we skip this on SkipDraw? DoBlockTransfer(); break; } diff --git a/GPU/GLES/DisplayListInterpreter.h b/GPU/GLES/DisplayListInterpreter.h index 048aab400b..9b30cab7b5 100644 --- a/GPU/GLES/DisplayListInterpreter.h +++ b/GPU/GLES/DisplayListInterpreter.h @@ -63,6 +63,7 @@ public: { return textureCache_.DecodeTexture(dest, state); } + virtual bool FramebufferDirty(); std::vector GetFramebufferList(); diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index 3394acc5e2..27680ac4e4 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -38,10 +38,34 @@ // GL_NV_shader_framebuffer_fetch looks interesting.... +static bool IsAlphaTestTriviallyTrue() { + int alphaTestFunc = gstate.alphatest & 7; + int alphaTestRef = (gstate.alphatest >> 8) & 0xFF; + + switch (alphaTestFunc) { + case GE_COMP_ALWAYS: + return true; + case GE_COMP_GEQUAL: + if (alphaTestRef == 0) + return true; + + // This breaks the trees in MotoGP, for example. + // case GE_COMP_GREATER: + //if (alphaTestRef == 0 && (gstate.alphaBlendEnable & 1) && gstate.getBlendFuncA() == GE_SRCBLEND_SRCALPHA && gstate.getBlendFuncB() == GE_SRCBLEND_INVSRCALPHA) + // return true; + + case GE_COMP_LEQUAL: + if (alphaTestRef == 255) + return true; + default: + return false; + } +} + + // Here we must take all the bits of the gstate that determine what the fragment shader will // look like, and concatenate them together into an ID. -void ComputeFragmentShaderID(FragmentShaderID *id) -{ +void ComputeFragmentShaderID(FragmentShaderID *id) { memset(&id->d[0], 0, sizeof(id->d)); bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear(); int lmode = (gstate.lmode & 1) && (gstate.lightingEnable & 1); @@ -49,6 +73,8 @@ void ComputeFragmentShaderID(FragmentShaderID *id) // We only need one clear shader, so let's ignore the rest of the bits. id->d[0] = 1; } else { + bool enableAlphaTest = (gstate.alphaTestEnable & 1) && !IsAlphaTestTriviallyTrue(); + bool enableColorTest = (gstate.colorTestEnable & 1); // id->d[0] |= (gstate.clearmode & 1); if (gstate.textureMapEnable & 1) { id->d[0] |= 1 << 1; @@ -58,11 +84,11 @@ void ComputeFragmentShaderID(FragmentShaderID *id) } id->d[0] |= (lmode & 1) << 7; id->d[0] |= (gstate.alphaTestEnable & 1) << 8; - if (gstate.alphaTestEnable & 1) + if (enableAlphaTest) id->d[0] |= (gstate.alphatest & 0x7) << 9; // alpha test func id->d[0] |= (gstate.colorTestEnable & 1) << 12; - if (gstate.colorTestEnable & 1) - id->d[0] |= (gstate.colortest & 0x3) << 13; // alpha test func + if (enableColorTest) + id->d[0] |= (gstate.colortest & 0x3) << 13; // color test func id->d[0] |= (enableFog & 1) << 15; } } @@ -71,8 +97,7 @@ void ComputeFragmentShaderID(FragmentShaderID *id) // Also, logic ops etc, of course. Urgh. // We could do all this with booleans, but I don't trust the shader compilers on // Android devices to be anything but stupid. -void GenerateFragmentShader(char *buffer) -{ +void GenerateFragmentShader(char *buffer) { char *p = buffer; @@ -86,8 +111,9 @@ void GenerateFragmentShader(char *buffer) int doTexture = (gstate.textureMapEnable & 1) && !(gstate.clearmode & 1); bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear(); - bool enableAlphaTest = (gstate.alphaTestEnable & 1) && !gstate.isModeClear(); + bool enableAlphaTest = (gstate.alphaTestEnable & 1) && !gstate.isModeClear() && !IsAlphaTestTriviallyTrue(); bool enableColorTest = (gstate.colorTestEnable & 1) && !gstate.isModeClear(); + bool enableColorDoubling = (gstate.texfunc & 0x10000) != 0; if (doTexture) @@ -170,16 +196,16 @@ void GenerateFragmentShader(char *buffer) // No texture mapping WRITE(p, " vec4 v = v_color0 %s;\n", secondary); } - // Color doubling - if (gstate.texfunc & 0x10000) { + + if (enableColorDoubling) { WRITE(p, " v = v * 2.0;\n"); } if (enableAlphaTest) { int alphaTestFunc = gstate.alphatest & 7; - const char *alphaTestFuncs[] = { "#", "#", " == ", " != ", " < ", " <= ", " > ", " >= " }; // never/always don't make sense + const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " }; // never/always don't make sense if (alphaTestFuncs[alphaTestFunc][0] != '#') - WRITE(p, " if (!(v.a %s u_alphacolorref.a)) discard;\n", alphaTestFuncs[alphaTestFunc]); + WRITE(p, " if (v.a %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]); } // Disabled for now until we actually find a need for it. @@ -191,7 +217,8 @@ void GenerateFragmentShader(char *buffer) int colorTestMask = gstate.colormask; if (colorTestFuncs[colorTestFunc][0] != '#') WRITE(p, "if (!(v.rgb %s (u_alphacolorref.rgb & u_colormask.rgb)) discard;\n", colorTestFuncs[colorTestFunc]); - }*/ + }*/ + if (enableFog) { WRITE(p, " float fogCoef = clamp(v_fogdepth, 0.0, 1.0);\n"); WRITE(p, " gl_FragColor = mix(vec4(u_fogcolor, v.a), v, fogCoef);\n"); diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index f4caeaf647..514ad018be 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -30,6 +30,7 @@ #include "GPU/GLES/Framebuffer.h" #include "GPU/GLES/TextureCache.h" +#include "GPU/GLES/ShaderManager.h" static const char tex_fs[] = "#ifdef GL_ES\n" @@ -64,8 +65,8 @@ static bool MaskedEqual(u32 addr1, u32 addr2) { return (addr1 & 0x3FFFFFF) == (addr2 & 0x3FFFFFF); } -static void CenterRect(float *x, float *y, float *w, float *h, - float origW, float origH, float frameW, float frameH) +void CenterRect(float *x, float *y, float *w, float *h, + float origW, float origH, float frameW, float frameH) { if (g_Config.bStretchToDisplay) { @@ -258,16 +259,32 @@ VirtualFramebuffer *FramebufferManager::GetDisplayFBO() { return 0; } -void GetViewportDimensions(int *w, int *h) { +void GetViewportDimensions(int &w, int &h) { float vpXa = getFloat24(gstate.viewportx1); float vpYa = getFloat24(gstate.viewporty1); - *w = (int)fabsf(vpXa * 2); - *h = (int)fabsf(vpYa * 2); + w = (int)fabsf(vpXa * 2); + h = (int)fabsf(vpYa * 2); +} + +// Heuristics to figure out the size of FBO to create. +void GuessDrawingSize(int &drawing_width, int &drawing_height) { + GetViewportDimensions(drawing_width, drawing_height); + + // HACK for first frame where some games don't init things right + if (drawing_width <= 1 && drawing_height <= 1) { + drawing_width = 480; + drawing_height = 272; + } + + // Now, cap using scissor. Hm, no, this doesn't work so well. + /* + if (drawing_width > gstate.getScissorX2() + 1) + drawing_width = gstate.getScissorX2() + 1; + if (drawing_height > gstate.getScissorY2() + 1) + drawing_height = gstate.getScissorY2() + 1;*/ } void FramebufferManager::SetRenderFrameBuffer() { - if (!g_Config.bBufferedRendering) - return; // Get parameters u32 fb_address = (gstate.fbptr & 0xFFE000) | ((gstate.fbwidth & 0xFF0000) << 8); int fb_stride = gstate.fbwidth & 0x3C0; @@ -275,10 +292,6 @@ void FramebufferManager::SetRenderFrameBuffer() { u32 z_address = (gstate.zbptr & 0xFFE000) | ((gstate.zbwidth & 0xFF0000) << 8); int z_stride = gstate.zbwidth & 0x3C0; - // We guess that the viewport size during the first draw call is an appropriate - // size for a render target. - //UpdateViewportAndProjection(); - // Yeah this is not completely right. but it'll do for now. //int drawing_width = ((gstate.region2) & 0x3FF) + 1; //int drawing_height = ((gstate.region2 >> 10) & 0x3FF) + 1; @@ -286,18 +299,11 @@ void FramebufferManager::SetRenderFrameBuffer() { // As there are no clear "framebuffer width" and "framebuffer height" registers, // we need to infer the size of the current framebuffer somehow. Let's try the viewport. - int drawing_width, drawing_height; - GetViewportDimensions(&drawing_width, &drawing_height); - - // HACK for first frame where some games don't init things right - - if (drawing_width <= 1 && drawing_height <= 1) { - drawing_width = 480; - drawing_height = 272; - } - int fmt = gstate.framebufpixformat & 3; + int drawing_width, drawing_height; + GuessDrawingSize(drawing_width, drawing_height); + // Find a matching framebuffer VirtualFramebuffer *vfb = 0; for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) { @@ -328,102 +334,157 @@ void FramebufferManager::SetRenderFrameBuffer() { vfb->renderHeight = (u16)(drawing_height * renderHeightFactor); vfb->format = fmt; vfb->usageFlags = FB_USAGE_RENDERTARGET; + vfb->dirtyAfterDisplay = true; - switch (fmt) { - case GE_FORMAT_4444: vfb->colorDepth = FBO_4444; break; - case GE_FORMAT_5551: vfb->colorDepth = FBO_5551; break; - case GE_FORMAT_565: vfb->colorDepth = FBO_565; break; - case GE_FORMAT_8888: vfb->colorDepth = FBO_8888; break; - default: vfb->colorDepth = FBO_8888; break; - } - - if (g_Config.bTrueColor) + if (g_Config.bTrueColor) { vfb->colorDepth = FBO_8888; + } else { + switch (fmt) { + case GE_FORMAT_4444: + vfb->colorDepth = FBO_4444; + break; + case GE_FORMAT_5551: + vfb->colorDepth = FBO_5551; + break; + case GE_FORMAT_565: + vfb->colorDepth = FBO_565; + break; + case GE_FORMAT_8888: + vfb->colorDepth = FBO_8888; + break; + default: + vfb->colorDepth = FBO_8888; + break; + } + } //#ifdef ANDROID // vfb->colorDepth = FBO_8888; //#endif - vfb->fbo = fbo_create(vfb->renderWidth, vfb->renderHeight, 1, true, vfb->colorDepth); + if (g_Config.bBufferedRendering) { + vfb->fbo = fbo_create(vfb->renderWidth, vfb->renderHeight, 1, true, vfb->colorDepth); + fbo_bind_as_render_target(vfb->fbo); + } else { + vfb->fbo = 0; + fbo_unbind(); + // Let's ignore rendering to targets that have not (yet) been displayed. + gstate_c.skipDrawReason |= SKIPDRAW_NON_DISPLAYED_FB; + } + textureCache_->NotifyFramebuffer(vfb->fb_address, vfb); vfb->last_frame_used = gpuStats.numFrames; vfbs_.push_back(vfb); - - fbo_bind_as_render_target(vfb->fbo); - glEnable(GL_DITHER); - glstate.viewport.set(0, 0, vfb->renderWidth, vfb->renderHeight); - currentRenderVfb_ = vfb; glstate.depthWrite.set(GL_TRUE); glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - INFO_LOG(HLE, "Creating FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format); - return; - } + glEnable(GL_DITHER); + currentRenderVfb_ = vfb; - if (vfb != currentRenderVfb_) { + INFO_LOG(HLE, "Creating FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format); + + // We already have it! + } else if (vfb != currentRenderVfb_) { // Use it as a render target. DEBUG_LOG(HLE, "Switching render target to FBO for %08x", vfb->fb_address); + vfb->usageFlags |= FB_USAGE_RENDERTARGET; gstate_c.textureChanged = true; - if (vfb->last_frame_used != gpuStats.numFrames) { - // Android optimization - //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - } vfb->last_frame_used = gpuStats.numFrames; - - fbo_bind_as_render_target(vfb->fbo); + vfb->dirtyAfterDisplay = true; + if (g_Config.bBufferedRendering && vfb->fbo) { + fbo_bind_as_render_target(vfb->fbo); + } else { + fbo_unbind(); + + // Let's ignore rendering to targets that have not (yet) been displayed. + if (vfb->usageFlags & FB_USAGE_DISPLAYED_FRAMEBUFFER) + gstate_c.skipDrawReason &= ~SKIPDRAW_NON_DISPLAYED_FB; + else + gstate_c.skipDrawReason |= SKIPDRAW_NON_DISPLAYED_FB; + + /* + if (drawing_width == 480 && drawing_height == 272) { + gstate_c.skipDrawReason &= ~SKIPDRAW_SKIPNONFB; + // OK! + } else { + gstate_c.skipDrawReason |= ~SKIPDRAW_SKIPNONFB; + }*/ + } textureCache_->NotifyFramebuffer(vfb->fb_address, vfb); + #ifdef USING_GLES2 // Some tiled mobile GPUs benefit IMMENSELY from clearing an FBO before rendering // to it. This broke stuff before, so now it only clears on the first use of an // FBO in a frame. This means that some games won't be able to avoid the on-some-GPUs // performance-crushing framebuffer reloads from RAM, but we'll have to live with that. - if (vfb->last_frame_used != gpuStats.numFrames) - { + if (vfb->last_frame_used != gpuStats.numFrames) { glstate.depthWrite.set(GL_TRUE); glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } #endif - glstate.viewport.set(0, 0, vfb->renderWidth, vfb->renderHeight); currentRenderVfb_ = vfb; + } else { + vfb->last_frame_used = gpuStats.numFrames; + } + + // ugly... + if (gstate_c.curRTWidth != vfb->width || gstate_c.curRTHeight != vfb->height) { + shaderManager_->DirtyUniform(DIRTY_PROJTHROUGHMATRIX); + gstate_c.curRTWidth = vfb->width; + gstate_c.curRTHeight = vfb->height; } } - void FramebufferManager::CopyDisplayToOutput() { fbo_unbind(); VirtualFramebuffer *vfb = GetDisplayFBO(); if (!vfb) { - DEBUG_LOG(HLE, "Found no FBO! displayFBPtr = %08x", displayFramebufPtr_); - // No framebuffer to display! Clear to black. - glstate.depthWrite.set(GL_TRUE); - glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glClearColor(0,0,0,1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + if (Memory::IsValidAddress(displayFramebufPtr_)) { + // The game is displaying something directly from RAM. In GTA, it's decoded video. + DrawPixels(Memory::GetPointer(displayFramebufPtr_), displayFormat_, displayStride_); + } else { + DEBUG_LOG(HLE, "Found no FBO to display! displayFBPtr = %08x", displayFramebufPtr_); + // No framebuffer to display! Clear to black. + glstate.depthWrite.set(GL_TRUE); + glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glClearColor(0,0,0,1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + } return; } + vfb->usageFlags |= FB_USAGE_DISPLAYED_FRAMEBUFFER; + vfb->dirtyAfterDisplay = false; + prevPrevDisplayFramebuf_ = prevDisplayFramebuf_; prevDisplayFramebuf_ = displayFramebuf_; displayFramebuf_ = vfb; - glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); - currentRenderVfb_ = 0; - DEBUG_LOG(HLE, "Displaying FBO %08x", vfb->fb_address); - glstate.blend.disable(); - glstate.cullFace.disable(); - glstate.depthTest.disable(); - glstate.scissorTest.disable(); - glstate.stencilTest.disable(); + if (vfb->fbo) { + glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); + DEBUG_LOG(HLE, "Displaying FBO %08x", vfb->fb_address); + glstate.blend.disable(); + glstate.cullFace.disable(); + glstate.depthTest.disable(); + glstate.scissorTest.disable(); + glstate.stencilTest.disable(); + + fbo_bind_color_as_texture(vfb->fbo, 0); - fbo_bind_color_as_texture(vfb->fbo, 0); + // These are in the output display coordinates + float x, y, w, h; + CenterRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight); + DrawActiveTexture(x, y, w, h, true); + glBindTexture(GL_TEXTURE_2D, 0); + } if (resized_) { glstate.depthWrite.set(GL_TRUE); @@ -431,11 +492,9 @@ void FramebufferManager::CopyDisplayToOutput() { glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } - // These are in the output display coordinates - float x, y, w, h; - CenterRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight); - DrawActiveTexture(x, y, w, h, true); +} +void FramebufferManager::EndFrame() { if (resized_) { DestroyAllFBOs(); glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); @@ -461,18 +520,16 @@ void FramebufferManager::BeginFrame() { } void FramebufferManager::SetDisplayFramebuffer(u32 framebuf, u32 stride, int format) { - if (framebuf & 0x04000000) { - //DEBUG_LOG(G3D, "Switch display framebuffer %08x", framebuf); - displayFramebufPtr_ = framebuf; - displayStride_ = stride; - displayFormat_ = format; - } else { - ERROR_LOG(HLE, "Bogus framebuffer address: %08x", framebuf); + displayFramebufPtr_ = framebuf; + displayStride_ = stride; + displayFormat_ = format; + + if ((framebuf & 0x04000000) == 0) { + DEBUG_LOG(HLE, "Non-VRAM display framebuffer address set: %08x", framebuf); } } -std::vector FramebufferManager::GetFramebufferList() -{ +std::vector FramebufferManager::GetFramebufferList() { std::vector list; for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) { @@ -492,16 +549,21 @@ std::vector FramebufferManager::GetFramebufferList() } void FramebufferManager::DecimateFBOs() { + fbo_unbind(); for (auto iter = vfbs_.begin(); iter != vfbs_.end();) { VirtualFramebuffer *vfb = *iter; if (vfb == displayFramebuf_ || vfb == prevDisplayFramebuf_ || vfb == prevPrevDisplayFramebuf_) { ++iter; continue; } - if ((*iter)->last_frame_used + FBO_OLD_AGE < gpuStats.numFrames) { - INFO_LOG(HLE, "Destroying FBO for %08x (%i x %i x %i)", vfb->fb_address, vfb->width, vfb->height, vfb->format) - textureCache_->NotifyFramebufferDestroyed(vfb->fb_address, vfb); - fbo_destroy(vfb->fbo); + int age = gpuStats.numFrames - (*iter)->last_frame_used; + if (age > FBO_OLD_AGE) { + INFO_LOG(HLE, "Decimating FBO for %08x (%i x %i x %i), age %i", vfb->fb_address, vfb->width, vfb->height, vfb->format) + if (vfb->fbo) { + textureCache_->NotifyFramebufferDestroyed(vfb->fb_address, vfb); + fbo_destroy(vfb->fbo); + vfb->fbo = 0; + } delete vfb; vfbs_.erase(iter++); } @@ -511,10 +573,15 @@ void FramebufferManager::DecimateFBOs() { } void FramebufferManager::DestroyAllFBOs() { + fbo_unbind(); for (auto iter = vfbs_.begin(); iter != vfbs_.end(); ++iter) { VirtualFramebuffer *vfb = *iter; textureCache_->NotifyFramebufferDestroyed(vfb->fb_address, vfb); - fbo_destroy(vfb->fbo); + if (vfb->fbo) { + INFO_LOG(HLE, "Destroying FBO for %08x : %i x %i x %i", vfb->fb_address, vfb->width, vfb->height, vfb->format); + fbo_destroy(vfb->fbo); + vfb->fbo = 0; + } delete vfb; } vfbs_.clear(); diff --git a/GPU/GLES/Framebuffer.h b/GPU/GLES/Framebuffer.h index c40fcc7c24..5f9785b0f2 100644 --- a/GPU/GLES/Framebuffer.h +++ b/GPU/GLES/Framebuffer.h @@ -39,8 +39,9 @@ enum PspDisplayPixelFormat { }; enum { - FB_USAGE_RENDERTARGET = 1, - FB_USAGE_TEXTURE = 2, + FB_USAGE_DISPLAYED_FRAMEBUFFER = 1, + FB_USAGE_RENDERTARGET = 2, + FB_USAGE_TEXTURE = 4, }; @@ -63,8 +64,14 @@ struct VirtualFramebuffer { int format; // virtual, right now they are all RGBA8888 FBOColorDepth colorDepth; FBO *fbo; + + bool dirtyAfterDisplay; }; +void CenterRect(float *x, float *y, float *w, float *h, + float origW, float origH, float frameW, float frameH); + +class ShaderManager; class FramebufferManager { public: @@ -74,6 +81,9 @@ public: void SetTextureCache(TextureCache *tc) { textureCache_ = tc; } + void SetShaderManager(ShaderManager *sm) { + shaderManager_ = sm; + } void DrawPixels(const u8 *framebuf, int pixelFormat, int linesize); void DrawActiveTexture(float x, float y, float w, float h, bool flip = false); @@ -82,6 +92,7 @@ public: void DecimateFBOs(); void BeginFrame(); + void EndFrame(); void Resized(); void CopyDisplayToOutput(); void SetRenderFrameBuffer(); // Uses parameters computed from gstate @@ -120,6 +131,7 @@ private: TextureCache *textureCache_; + ShaderManager *shaderManager_; bool resized_; }; diff --git a/GPU/GLES/ShaderManager.cpp b/GPU/GLES/ShaderManager.cpp index ac789f5726..26ea5e2ded 100644 --- a/GPU/GLES/ShaderManager.cpp +++ b/GPU/GLES/ShaderManager.cpp @@ -244,7 +244,7 @@ void LinkedShader::updateUniforms() { if (u_proj_through != -1 && (dirtyUniforms & DIRTY_PROJTHROUGHMATRIX)) { Matrix4x4 proj_through; - proj_through.setOrtho(0.0f, 480, 272, 0, 0, 1); + proj_through.setOrtho(0.0f, gstate_c.curRTWidth, gstate_c.curRTHeight, 0, 0, 1); glUniformMatrix4fv(u_proj_through, 1, GL_FALSE, proj_through.getReadPtr()); } if (u_texenv != -1 && (dirtyUniforms & DIRTY_TEXENV)) { @@ -376,8 +376,7 @@ void ShaderManager::DirtyShader() } -LinkedShader *ShaderManager::ApplyShader(int prim) -{ +LinkedShader *ShaderManager::ApplyShader(int prim) { if (globalDirty) { if (lastShader) lastShader->dirtyUniforms |= globalDirty; diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index a0c7a51360..47b28784e6 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -1,3 +1,20 @@ +// 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 "StateMapping.h" #include "native/gfx_es2/gl_state.h" @@ -9,8 +26,9 @@ #include "DisplayListInterpreter.h" #include "ShaderManager.h" #include "TextureCache.h" +#include "Framebuffer.h" -const GLint aLookup[11] = { +static const GLushort aLookup[11] = { GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, @@ -24,7 +42,7 @@ const GLint aLookup[11] = { GL_CONSTANT_COLOR, // FIXA }; -const GLint bLookup[11] = { +static const GLushort bLookup[11] = { GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, @@ -38,7 +56,7 @@ const GLint bLookup[11] = { GL_CONSTANT_COLOR, // FIXB }; -const GLint eqLookup[] = { +static const GLushort eqLookup[] = { GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT, @@ -52,18 +70,17 @@ const GLint eqLookup[] = { GL_FUNC_ADD, // should be abs(diff) }; -const GLint cullingMode[] = { +static const GLushort cullingMode[] = { GL_BACK, GL_FRONT, }; -const GLuint ztests[] = -{ +static const GLushort ztests[] = { GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL, }; -const GLuint stencilOps[] = { +static const GLushort stencilOps[] = { GL_KEEP, GL_ZERO, GL_REPLACE, @@ -84,11 +101,17 @@ void TransformDrawEngine::ApplyDrawState(int prim) { gstate_c.textureChanged = false; } + // Set cull + bool wantCull = !gstate.isModeClear() && !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); + glstate.cullFace.set(wantCull); + if (wantCull) + glstate.cullFaceMode.set(cullingMode[gstate.getCullMode()]); + // TODO: The top bit of the alpha channel should be written to the stencil bit somehow. This appears to require very expensive multipass rendering :( Alternatively, one could do a // single fullscreen pass that converts alpha to stencil (or 2 passes, to set both the 0 and 1 values) very easily. // Set blend - bool wantBlend = !gstate.isModeClear() && (gstate.alphaBlendEnable & 1); + bool wantBlend = !gstate.isModeClear() && gstate.isAlphaBlendEnabled(); glstate.blend.set(wantBlend); if (wantBlend) { // This can't be done exactly as there are several PSP blend modes that are impossible to do on OpenGL ES 2.0, and some even on regular OpenGL for desktop. @@ -159,10 +182,11 @@ void TransformDrawEngine::ApplyDrawState(int prim) { } } - // Dither - glstate.dither.set(gstate.ditherEnable & 1); - // Set cull + // Set Dither + glstate.dither.set(gstate.isDitherEnabled()); + + // Set ColorMask/Stencil/Depth if (gstate.isModeClear()) { bool colorMask = (gstate.clearmode >> 8) & 1; bool alphaMask = (gstate.clearmode >> 9) & 1; @@ -177,12 +201,8 @@ void TransformDrawEngine::ApplyDrawState(int prim) { glstate.depthTest.enable(); glstate.depthFunc.set(GL_ALWAYS); glstate.depthWrite.set(depthMask ? GL_TRUE : GL_FALSE); - } else { - u8 cullMode = gstate.getCullMode(); - bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); - glstate.cullFace.set(wantCull); - glstate.cullFaceMode.set(cullingMode[cullMode]); + } else { if (gstate.isDepthTestEnabled()) { glstate.depthTest.enable(); glstate.depthFunc.set(ztests[gstate.getDepthTestFunc()]); @@ -211,34 +231,67 @@ void TransformDrawEngine::ApplyDrawState(int prim) { glstate.stencilTest.disable(); } } -} -void TransformDrawEngine::UpdateViewportAndProjection() { - int renderWidth, renderHeight; + float renderWidthFactor, renderHeightFactor; + float renderWidth, renderHeight; + float renderX, renderY; if (g_Config.bBufferedRendering) { + renderX = 0; + renderY = 0; renderWidth = framebufferManager_->GetRenderWidth(); renderHeight = framebufferManager_->GetRenderHeight(); + renderWidthFactor = (float)renderWidth / framebufferManager_->GetTargetWidth(); + renderHeightFactor = (float)renderHeight / framebufferManager_->GetTargetHeight(); } else { // TODO: Aspect-ratio aware and centered - renderWidth = PSP_CoreParameter().pixelWidth; - renderHeight = PSP_CoreParameter().pixelHeight; + float pixelW = PSP_CoreParameter().pixelWidth; + float pixelH = PSP_CoreParameter().pixelHeight; + CenterRect(&renderX, &renderY, &renderWidth, &renderHeight, 480, 272, pixelW, pixelH); + renderWidthFactor = renderWidth / 480.f; + renderHeightFactor = renderHeight / 272.f; } - float renderWidthFactor = (float)renderWidth / framebufferManager_->GetTargetWidth(); - float renderHeightFactor = (float)renderHeight / framebufferManager_->GetTargetHeight(); + bool throughmode = (gstate.vertType & GE_VTYPE_THROUGH_MASK) != 0; - // We can probably use these to simply set scissors? Maybe we need to offset by regionX1/Y1 + // Scissor + int scissorX1 = gstate.scissor1 & 0x3FF; + int scissorY1 = (gstate.scissor1 >> 10) & 0x3FF; + int scissorX2 = gstate.scissor2 & 0x3FF; + int scissorY2 = (gstate.scissor2 >> 10) & 0x3FF; + + // This is a bit of a hack as the render buffer isn't always that size + if (scissorX1 == 0 && scissorY1 == 0 && scissorX2 == 480 && scissorY2 == 272) { + glstate.scissorTest.disable(); + } else { + glstate.scissorTest.enable(); + glstate.scissorRect.set( + renderX + scissorX1 * renderWidthFactor, + renderY + renderHeight - (scissorY2 * renderHeightFactor), + (scissorX2 - scissorX1) * renderWidthFactor, + (scissorY2 - scissorY1) * renderHeightFactor); + } + + /* int regionX1 = gstate.region1 & 0x3FF; int regionY1 = (gstate.region1 >> 10) & 0x3FF; int regionX2 = (gstate.region2 & 0x3FF) + 1; int regionY2 = ((gstate.region2 >> 10) & 0x3FF) + 1; + */ + int regionX1 = 0; + int regionY1 = 0; + int regionX2 = gstate_c.curRTWidth; + int regionY2 = gstate_c.curRTHeight; float offsetX = (float)(gstate.offsetx & 0xFFFF) / 16.0f; float offsetY = (float)(gstate.offsety & 0xFFFF) / 16.0f; if (throughmode) { // No viewport transform here. Let's experiment with using region. - glstate.viewport.set((0 + regionX1) * renderWidthFactor, (0 - regionY1) * renderHeightFactor, (regionX2 - regionX1) * renderWidthFactor, (regionY2 - regionY1) * renderHeightFactor); + glstate.viewport.set( + renderX + (0 + regionX1) * renderWidthFactor, + renderY + (0 - regionY1) * renderHeightFactor, + (regionX2 - regionX1) * renderWidthFactor, + (regionY2 - regionY1) * renderHeightFactor); glstate.depthRange.set(0.0f, 1.0f); } else { // These we can turn into a glViewport call, offset by offsetX and offsetY. Math after. @@ -268,7 +321,7 @@ void TransformDrawEngine::UpdateViewportAndProjection() { // Flip vpY0 to match the OpenGL coordinate system. vpY0 = renderHeight - (vpY0 + vpHeight); - glstate.viewport.set(vpX0, vpY0, vpWidth, vpHeight); + glstate.viewport.set(vpX0 + renderX, vpY0 + renderY, vpWidth, vpHeight); // Sadly, as glViewport takes integers, we will not be able to support sub pixel offsets this way. But meh. // shaderManager_->DirtyUniform(DIRTY_PROJMATRIX); diff --git a/GPU/GLES/StateMapping.h b/GPU/GLES/StateMapping.h index dc720e8eee..f40c6423ee 100644 --- a/GPU/GLES/StateMapping.h +++ b/GPU/GLES/StateMapping.h @@ -1,9 +1,3 @@ +#pragma once + #include "../native/gfx/gl_common.h" - -extern const GLint aLookup[]; -extern const GLint bLookup[]; -extern const GLint eqLookup[]; -extern const GLint cullingMode[]; -extern const GLuint ztests[]; - - diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 32d404896c..3a090a175b 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -80,7 +80,7 @@ void TextureCache::Clear(bool delete_them) { // Removes old textures. void TextureCache::Decimate() { glBindTexture(GL_TEXTURE_2D, 0); - for (TexCache::iterator iter = cache.begin(), end = cache.end(); iter != end; ) { + for (TexCache::iterator iter = cache.begin(); iter != cache.end(); ) { if (iter->second.lastFrame + TEXTURE_KILL_AGE < gpuStats.numFrames) { glDeleteTextures(1, &iter->second.texture); cache.erase(iter++); @@ -138,16 +138,15 @@ void TextureCache::NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffe if (entry) { DEBUG_LOG(HLE, "Render to texture detected at %08x!", address); if (!entry->framebuffer) - entry->framebuffer= framebuffer; + entry->framebuffer = framebuffer; // TODO: Delete the original non-fbo texture too. } } void TextureCache::NotifyFramebufferDestroyed(u32 address, VirtualFramebuffer *fbo) { TexCacheEntry *entry = GetEntryAt(address | 0x04000000); - if (entry && entry->framebuffer) { + if (entry) entry->framebuffer = 0; - } } static u32 GetClutAddr(u32 clutEntrySize) { @@ -695,13 +694,25 @@ void TextureCache::SetTexture() { TexCache::iterator iter = cache.find(cachekey); TexCacheEntry *entry = NULL; gstate_c.flipTexture = false; + gstate_c.skipDrawReason &= ~SKIPDRAW_BAD_FB_TEXTURE; if (iter != cache.end()) { entry = &iter->second; // Check for FBO - slow! if (entry->framebuffer) { - fbo_bind_color_as_texture(entry->framebuffer->fbo, 0); - UpdateSamplingParams(*entry, false); + entry->framebuffer->usageFlags |= FB_USAGE_TEXTURE; + if (!g_Config.bBufferedRendering) { + glBindTexture(GL_TEXTURE_2D, 0); + entry->lastFrame = gpuStats.numFrames; + } else { + if (entry->framebuffer->fbo) { + fbo_bind_color_as_texture(entry->framebuffer->fbo, 0); + } else { + glBindTexture(GL_TEXTURE_2D, 0); + gstate_c.skipDrawReason |= SKIPDRAW_BAD_FB_TEXTURE; + } + UpdateSamplingParams(*entry, false); + } // This isn't right. gstate_c.curTextureWidth = entry->framebuffer->width; diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index ee9687fd05..d00cdde942 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -639,8 +639,12 @@ void TransformDrawEngine::SoftwareTransformAndDraw( memcpy(&transformed[index].x, v, 3 * sizeof(float)); transformed[index].fog = fogCoef; memcpy(&transformed[index].u, uv, 2 * sizeof(float)); - if (gstate_c.flipTexture) - transformed[index].v = 1.0f - transformed[index].v; //(float)gstate_c.actualTextureHeight / gstate_c.curTextureHeight - transformed[index].v; + if (gstate_c.flipTexture) { + //if (throughmode) + // transformed[index].v = (float)gstate_c.actualTextureHeight / gstate_c.curTextureHeight - transformed[index].v; + //else + transformed[index].v = 1.0f - transformed[index].v; // * 2.0f; + } for (int i = 0; i < 4; i++) { transformed[index].color0[i] = c0[i] * 255.0f; } @@ -933,7 +937,6 @@ void TransformDrawEngine::Flush() { int prim = prevPrim_; ApplyDrawState(prim); - UpdateViewportAndProjection(); LinkedShader *program = shaderManager_->ApplyShader(prim); diff --git a/GPU/GLES/TransformPipeline.h b/GPU/GLES/TransformPipeline.h index 816440427d..4c37b8b9ba 100644 --- a/GPU/GLES/TransformPipeline.h +++ b/GPU/GLES/TransformPipeline.h @@ -120,7 +120,6 @@ public: private: void SoftwareTransformAndDraw(int prim, u8 *decoded, LinkedShader *program, int vertexCount, u32 vertexType, void *inds, int indexType, const DecVtxFormat &decVtxFormat, int maxIndex); void ApplyDrawState(int prim); - void UpdateViewportAndProjection(); // drawcall ID u32 ComputeFastDCID(); diff --git a/GPU/GLES/VertexShaderGenerator.cpp b/GPU/GLES/VertexShaderGenerator.cpp index bddcd1ab19..ed2f74d266 100644 --- a/GPU/GLES/VertexShaderGenerator.cpp +++ b/GPU/GLES/VertexShaderGenerator.cpp @@ -133,6 +133,13 @@ void GenerateVertexShader(int prim, char *buffer) { WRITE(p, "precision highp float;\n"); #elif !defined(FORCE_OPENGL_2_0) WRITE(p, "#version 110\n"); + // Remove lowp/mediump in non-mobile implementations + WRITE(p, "#define lowp\n"); + WRITE(p, "#define mediump\n"); +#else + // Need to remove lowp/mediump for Mac + WRITE(p, "#define lowp\n"); + WRITE(p, "#define mediump\n"); #endif int lmode = (gstate.lmode & 1) && (gstate.lightingEnable & 1); @@ -169,13 +176,13 @@ void GenerateVertexShader(int prim, char *buffer) { if (doTexture) WRITE(p, "attribute vec2 a_texcoord;\n"); if (hasColor) { - WRITE(p, "attribute vec4 a_color0;\n"); + WRITE(p, "attribute lowp vec4 a_color0;\n"); if (lmode && !hwXForm) // only software transform supplies color1 as vertex data - WRITE(p, "attribute vec3 a_color1;\n"); + WRITE(p, "attribute lowp vec3 a_color1;\n"); } if (hwXForm && hasNormal) - WRITE(p, "attribute vec3 a_normal;\n"); + WRITE(p, "attribute mediump vec3 a_normal;\n"); if (gstate.isModeThrough()) { WRITE(p, "uniform mat4 u_proj_through;\n"); @@ -185,7 +192,7 @@ void GenerateVertexShader(int prim, char *buffer) { } if (hwXForm || !hasColor) - WRITE(p, "uniform vec4 u_matambientalpha;\n"); // matambient + matalpha + WRITE(p, "uniform lowp vec4 u_matambientalpha;\n"); // matambient + matalpha if (enableFog) { WRITE(p, "uniform vec2 u_fogcoef;\n"); @@ -206,12 +213,12 @@ void GenerateVertexShader(int prim, char *buffer) { } } if (gstate.lightingEnable & 1) { - WRITE(p, "uniform vec4 u_ambient;\n"); + WRITE(p, "uniform lowp vec4 u_ambient;\n"); if ((gstate.materialupdate & 2) == 0) - WRITE(p, "uniform vec3 u_matdiffuse;\n"); + WRITE(p, "uniform lowp vec3 u_matdiffuse;\n"); // if ((gstate.materialupdate & 4) == 0) - WRITE(p, "uniform vec4 u_matspecular;\n"); // Specular coef is contained in alpha - WRITE(p, "uniform vec3 u_matemissive;\n"); + WRITE(p, "uniform lowp vec4 u_matspecular;\n"); // Specular coef is contained in alpha + WRITE(p, "uniform lowp vec3 u_matemissive;\n"); } for (int i = 0; i < 4; i++) { if (doLight[i] != LIGHT_OFF) { @@ -222,15 +229,15 @@ void GenerateVertexShader(int prim, char *buffer) { } if (doLight[i] == LIGHT_FULL) { // These are needed for the full thing - WRITE(p, "uniform vec3 u_lightambient%i;\n", i); - WRITE(p, "uniform vec3 u_lightdiffuse%i;\n", i); - WRITE(p, "uniform vec3 u_lightspecular%i;\n", i); + WRITE(p, "uniform lowp vec3 u_lightambient%i;\n", i); + WRITE(p, "uniform lowp vec3 u_lightdiffuse%i;\n", i); + WRITE(p, "uniform lowp vec3 u_lightspecular%i;\n", i); } } } - WRITE(p, "varying vec4 v_color0;\n"); - if (lmode) WRITE(p, "varying vec3 v_color1;\n"); + WRITE(p, "varying lowp vec4 v_color0;\n"); + if (lmode) WRITE(p, "varying lowp vec3 v_color1;\n"); if (doTexture) WRITE(p, "varying vec2 v_texcoord;\n"); if (enableFog) WRITE(p, "varying float v_fogdepth;\n"); @@ -290,9 +297,9 @@ void GenerateVertexShader(int prim, char *buffer) { // Step 2: Color/Lighting if (hasColor) { - WRITE(p, " vec3 unlitColor = a_color0.rgb;\n"); + WRITE(p, " lowp vec3 unlitColor = a_color0.rgb;\n"); } else { - WRITE(p, " vec3 unlitColor = vec3(1.0, 1.0, 1.0);\n"); + WRITE(p, " lowp vec3 unlitColor = vec3(1.0, 1.0, 1.0);\n"); } // TODO: Declare variables for dots for shade mapping if needed. @@ -301,8 +308,8 @@ void GenerateVertexShader(int prim, char *buffer) { const char *specular = (gstate.materialupdate & 4) ? "unlitColor" : "u_matspecular.rgb"; if (gstate.lightingEnable & 1) { - WRITE(p, " vec4 lightSum0 = u_ambient * %s + vec4(u_matemissive, 0.0);\n", ambient); - WRITE(p, " vec3 lightSum1 = vec3(0.0);\n"); + WRITE(p, " lowp vec4 lightSum0 = u_ambient * %s + vec4(u_matemissive, 0.0);\n", ambient); + WRITE(p, " lowp vec3 lightSum1 = vec3(0.0);\n"); } // Calculate lights if needed. If shade mapping is enabled, lights may need to be diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 8d710972ff..5c5f98b38b 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -107,7 +107,7 @@ bool GPUCommon::InterpretList(DisplayList &list) if (dumpThisFrame_) { char temp[256]; GeDisassembleOp(list.pc, op, prev, temp); - NOTICE_LOG(G3D, "%s", temp); + NOTICE_LOG(HLE, "%s", temp); } gstate.cmdmem[cmd] = op; // crashes if I try to put the whole op there?? diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 8feb9cb569..88aa151a8d 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -23,6 +23,7 @@ public: virtual u32 EnqueueList(u32 listpc, u32 stall, int subIntrBase, bool head); virtual int listStatus(int listid); virtual void DoState(PointerWrap &p); + virtual bool FramebufferDirty() { return true; } protected: typedef std::deque DisplayListQueue; diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index 4edb5de1c5..f558e3ceb8 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -102,6 +102,7 @@ public: // Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*. virtual void Resized() = 0; + virtual bool FramebufferDirty() = 0; // Debugging virtual void DumpNextFrame() = 0; diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 6522ae567f..ce96b58a70 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -209,6 +209,8 @@ struct GPUgstate int getDepthTestFunc() const { return ztestfunc & 0x7; } bool isFogEnabled() const { return fogEnable & 1; } bool isStencilTestEnabled() const { return stencilTestEnable & 1; } + bool isAlphaBlendEnabled() const { return alphaBlendEnable & 1; } + bool isDitherEnabled() const { return ditherEnable & 1; } // UV gen int getUVGenMode() const { return texmapmode & 3;} // 2 bits @@ -216,6 +218,11 @@ struct GPUgstate int getUVLS0() const { return texshade & 0x3; } // 2 bits int getUVLS1() const { return (texshade >> 8) & 0x3; } // 2 bits + int getScissorX1() const { return scissor1 & 0x3FF; } + int getScissorY1() const { return (scissor1 >> 10) & 0x3FF; } + int getScissorX2() const { return scissor2 & 0x3FF; } + int getScissorY2() const { return (scissor2 >> 10) & 0x3FF; } + // Vertex type bool isModeThrough() const { return (vertType & GE_VTYPE_THROUGH) != 0; } int getNumBoneWeights() const { @@ -227,6 +234,8 @@ struct GPUgstate enum SkipDrawReasonFlags { SKIPDRAW_SKIPFRAME = 1, + SKIPDRAW_NON_DISPLAYED_FB = 2, // Skip drawing to FBO:s that have not been displayed. + SKIPDRAW_BAD_FB_TEXTURE = 4, }; // The rest is cached simplified/converted data for fast access. @@ -260,6 +269,9 @@ struct GPUStateCache float vpWidth; float vpHeight; + u32 curRTWidth; + u32 curRTHeight; + u32 getRelativeAddress(u32 data) const; }; diff --git a/GPU/ge_constants.h b/GPU/ge_constants.h index 78a90fe26c..c2980adf77 100644 --- a/GPU/ge_constants.h +++ b/GPU/ge_constants.h @@ -471,10 +471,10 @@ enum GELogicOp enum GEPaletteFormat { - GE_CMODE_16BIT_BGR5650, - GE_CMODE_16BIT_ABGR5551, - GE_CMODE_16BIT_ABGR4444, - GE_CMODE_32BIT_ABGR8888 + GE_CMODE_16BIT_BGR5650, + GE_CMODE_16BIT_ABGR5551, + GE_CMODE_16BIT_ABGR4444, + GE_CMODE_32BIT_ABGR8888 }; #endif diff --git a/Qt/Core.pro b/Qt/Core.pro index bd22ca070a..aa21dee9c0 100755 --- a/Qt/Core.pro +++ b/Qt/Core.pro @@ -4,6 +4,15 @@ TARGET = Core TEMPLATE = lib CONFIG += staticlib +version.target = ../git-version.cpp +contains(QMAKE_HOST.os, "Windows") { version.commands = $$PWD/../Windows/git-version-gen.cmd } +else { version.commands = $$PWD/git-version-gen.sh } +version.depends = ../.git + +QMAKE_EXTRA_TARGETS += version +PRE_TARGETDEPS += ../git-version.cpp +SOURCES += ../git-version.cpp + include(Settings.pri) INCLUDEPATH += ../native ../Core/MIPS ../ @@ -33,12 +42,14 @@ SOURCES += ../Core/CPU.cpp \ # Core ../Core/MemMapFunctions.cpp \ ../Core/PSPLoaders.cpp \ ../Core/PSPMixer.cpp \ + ../Core/Reporting.cpp \ ../Core/SaveState.cpp \ ../Core/System.cpp \ ../Core/Debugger/*.cpp \ ../Core/Dialog/*.cpp \ ../Core/ELF/*.cpp \ ../Core/FileSystems/*.cpp \ + ../Core/Font/*.cpp \ ../Core/HLE/*.cpp \ ../Core/HW/*.cpp \ ../Core/MIPS/*.cpp \ @@ -62,12 +73,14 @@ HEADERS += ../Core/CPU.h \ ../Core/MemMap.h \ ../Core/PSPLoaders.h \ ../Core/PSPMixer.h \ + ../Core/Reporting.h \ ../Core/SaveState.h \ ../Core/System.h \ ../Core/Debugger/*.h \ ../Core/Dialog/*.h \ ../Core/ELF/*.h \ ../Core/FileSystems/*.h \ + ../Core/Font/*.h \ ../Core/HLE/*.h \ ../Core/HW/*.h \ ../Core/MIPS/*.h \ diff --git a/Qt/EmuThread.cpp b/Qt/EmuThread.cpp index 4dd3a64570..1e5924b277 100644 --- a/Qt/EmuThread.cpp +++ b/Qt/EmuThread.cpp @@ -150,7 +150,7 @@ void EmuThread::run() setCurrentThreadName("EmuThread"); host->UpdateUI(); - host->InitGL(); + host->InitGL(0); EmuThread_LockDraw(true); diff --git a/Qt/PPSSPP.pro b/Qt/PPSSPP.pro index 64c09839d2..eea0696da9 100755 --- a/Qt/PPSSPP.pro +++ b/Qt/PPSSPP.pro @@ -3,6 +3,7 @@ TARGET = PPSSPPQt QT += core gui opengl CONFIG += mobility MOBILITY += multimedia +symbian: MOBILITY += sensors win32: QT += multimedia include(Settings.pri) @@ -29,8 +30,6 @@ linux:!mobile_platform { } } -TRANSLATIONS = $$files(languages/ppsspp_*.ts) - # Main SOURCES += ../native/base/QtMain.cpp HEADERS += ../native/base/QtMain.h @@ -39,6 +38,7 @@ HEADERS += ../native/base/QtMain.h SOURCES += ../android/jni/EmuScreen.cpp \ ../android/jni/MenuScreens.cpp \ ../android/jni/GamepadEmu.cpp \ + ../android/jni/TestRunner.cpp \ ../android/jni/UIShader.cpp \ ../android/jni/ui_atlas.cpp @@ -58,10 +58,21 @@ mobile_platform { INCLUDEPATH += ../Qt } +# Translations +TRANSLATIONS = $$files(languages/ppsspp_*.ts) + +lang.name = lrelease ${QMAKE_FILE_IN} +lang.input = TRANSLATIONS +lang.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.qm +lang.commands = $$[QT_INSTALL_BINS]/lrelease ${QMAKE_FILE_IN} +lang.CONFIG = no_link +QMAKE_EXTRA_COMPILERS += lang +PRE_TARGETDEPS += compiler_lang_make_all + # Packaging symbian { - deploy.pkg_prerules = "$${LITERAL_HASH}{\"PPSSPP\"}, (0xE0095B1D), 0, 6, 1, TYPE=SA" "%{\"Qtness\"}" ":\"Qtness\"" - assets.sources = ../android/assets/ui_atlas.zim ../assets/ppge_atlas.zim + deploy.pkg_prerules = "$${LITERAL_HASH}{\"PPSSPP\"}, (0xE0095B1D), 0, 7, 0, TYPE=SA" "%{\"Qtness\"}" ":\"Qtness\"" + assets.sources = ../android/assets/ui_atlas.zim ../assets/ppge_atlas.zim ../assets/flash assets.path = E:/PPSSPP DEPLOYMENT += deploy assets ICON = ../assets/icon.svg diff --git a/Qt/QtHost.cpp b/Qt/QtHost.cpp index 4295edf126..ffd4b30f86 100644 --- a/Qt/QtHost.cpp +++ b/Qt/QtHost.cpp @@ -33,7 +33,7 @@ QtHost::QtHost(MainWindow *mainWindow_) QObject::connect(this,SIGNAL(BootDoneSignal()),mainWindow,SLOT(Boot())); } -void QtHost::InitGL() +bool QtHost::InitGL(std::string *error_string) { } @@ -43,7 +43,7 @@ void QtHost::ShutdownGL() void QtHost::SetWindowTitle(const char *message) { - QString title = "PPSSPP " + QString(PPSSPP_VERSION_STR) + " - " + QString::fromUtf8(message); + QString title = "PPSSPP " + QString(PPSSPP_GIT_VERSION) + " - " + QString::fromUtf8(message); mainWindow->setWindowTitle(title); } diff --git a/Qt/QtHost.h b/Qt/QtHost.h index 3e9305694d..1aacbc10c8 100644 --- a/Qt/QtHost.h +++ b/Qt/QtHost.h @@ -34,7 +34,7 @@ public: void AddSymbol(std::string name, u32 addr, u32 size, int type); - void InitGL(); + bool InitGL(std::string *error_string); void BeginFrame(); void EndFrame(); void ShutdownGL(); diff --git a/Qt/Settings.pri b/Qt/Settings.pri index 9956e529eb..7b9a238008 100644 --- a/Qt/Settings.pri +++ b/Qt/Settings.pri @@ -1,5 +1,4 @@ DEFINES += USING_QT_UI -blackberry|symbian|contains(MEEGO_EDITION,harmattan): CONFIG += mobile_platform unix:!blackberry:!symbian:!macx: CONFIG += linux # Global specific @@ -17,7 +16,8 @@ win32-msvc* { } # Arch specific -contains(QT_ARCH, i686)|contains(QT_ARCH, x86)|contains(QT_ARCH, x86_64)|contains(QT_ARCH, windows): { +xarch = $$find(QT_ARCH, "86") +contains(QT_ARCH, windows)|count(xarch, 1) { !win32-msvc*: QMAKE_CXXFLAGS += -msse2 CONFIG += x86 } @@ -25,8 +25,13 @@ else { # Assume ARM DEFINES += ARM CONFIG += arm } -mobile_platform: DEFINES += USING_GLES2 +gleslib = $$lower($$QMAKE_LIBS_OPENGL) +gleslib = $$find(gleslib, "gles") +!count(gleslib,0) { + DEFINES += USING_GLES2 + CONFIG += mobile_platform +} # Platform specific contains(MEEGO_EDITION,harmattan): DEFINES += MEEGO_EDITION_HARMATTAN "_SYS_UCONTEXT_H=1" diff --git a/Qt/git-version-gen.sh b/Qt/git-version-gen.sh new file mode 100755 index 0000000000..d441c38379 --- /dev/null +++ b/Qt/git-version-gen.sh @@ -0,0 +1,52 @@ +#!/bin/bash +## 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/. + +GIT_VERSION_FILE=$(dirname $0)/../git-version.cpp + +if [ -e "$GIT_VERSION_FILE" ]; then + # Skip updating the file if PPSSPP_GIT_VERSION_NO_UPDATE is 1. + results=$(grep '^#define PPSSPP_GIT_VERSION_NO_UPDATE 1' "$GIT_VERSION_FILE") + if [ "$results" != "" ]; then + exit 0 + fi +fi + +GIT_VERSION=$(git describe --always) +if [ "$GIT_VERSION" == "" ]; then + echo "Unable to update git-version.cpp, git not on path." 1>&2 + + echo "// This is a generated file." > "$GIT_VERSION_FILE" + echo >> "$GIT_VERSION_FILE" + echo 'const char *PPSSPP_GIT_VERSION = "unknown";' >> "$GIT_VERSION_FILE" + exit 0 +fi + +# Don't modify the file if it already has the current version. +if [ -e "$GIT_VERSION_FILE" ]; then + results=$(grep "$GIT_VERSION" "$GIT_VERSION_FILE") + if [ "$results" != "" ]; then + exit 0 + fi +fi + +echo "// This is a generated file." > "$GIT_VERSION_FILE" +echo >> "$GIT_VERSION_FILE" +echo 'const char *PPSSPP_GIT_VERSION = "'"$GIT_VERSION"'";' >> "$GIT_VERSION_FILE" +echo >> "$GIT_VERSION_FILE" +echo "// If you don't want this file to update/recompile, change to 1." >> "$GIT_VERSION_FILE" +echo "#define PPSSPP_GIT_VERSION_NO_UPDATE 0" >> "$GIT_VERSION_FILE" diff --git a/Qt/languages/ppsspp_cn.ts b/Qt/languages/ppsspp_cn.ts index 0185206b1a..b1ca0f3c6e 100644 --- a/Qt/languages/ppsspp_cn.ts +++ b/Qt/languages/ppsspp_cn.ts @@ -13,108 +13,133 @@ CtrlDisAsmView - + Copy &address (&A)复制地址 - + Copy instruction (&hex) (&H)复制指令(十六进制型) - + Copy instruction (&disasm) (&D)复制指令(汇编型) - + &Run to here (&R)执行到此处 - + &Set Next Statement (&S)设置下一语句 - + &Toggle breakpoint (&T)锁定断点 - + &Follow branch (&F)跟随分支 - + Go to in &Memory View (&M)转到内存视图 - + &Rename function... (&R)重命名函数... - + New function name 新函数名称 - + New function name: 新函数名称: + + + Warning + 警告 + + + + No symbol selected + + CtrlMemView - + Go to in &disasm (&D)转到汇编视图 - + &Copy value (&C)复制值 - + + C&hange value + + + + Dump... 转储... + + + Set new value + 设置新值 + + + + Set new value: + 设置新值: + CtrlRegisterList - + Go to in &memory view (&M)转到内存视图 - + Go to in &disasm (&D)转到汇编视图 - + &Copy value (&C)复制值 - + C&hange... (&H)更改... - + Set new value 设置新值 - + Set new value: 设置新值: @@ -219,13 +244,13 @@ - + Id Id - + Status 状态 @@ -240,32 +265,30 @@ 当前地址 - Run - 执行 + 执行 - Step - 单步执行 + 单步执行 - + Threads 线程 - + Name 名称 - + Current PC 当前PC寄存器 - + Entry point 入口点 @@ -275,29 +298,246 @@ 移除断点 - + Go to entry point 转到入口点 - + + Change status + + + + Running 执行中 - + Wait 等待 - + Suspend 挂起 - Show code - 显示代码 + 显示代码 + + + + Debugger_DisplayList + + + Dialog + 对话框 + + + + DisplayList + + + + + Id + Id + + + + Status + 状态 + + + + Start Address + 起始地址 + + + + Current Address + 当前地址 + + + + Run + 执行 + + + + Stop + 停止 + + + + Next DL + + + + + Commands + + + + + Step + 单步执行 + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + 地址 + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + @@ -333,6 +573,64 @@ 内存查看器 - %1 + + Debugger_MemoryTex + + + Dialog + 对话框 + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + Debugger_VFPU @@ -425,59 +723,59 @@ 按下手柄按键来确认键位映射: - - + + <b>No gamepad</b> <b>未发现手柄</b> - + <b>Unknown gamepad</b> <b>未识别的手柄</b> - + Buttons 按钮 - - + + Button %1 按钮 %1 - + Axes 摇杆 - + %1 Neg %1 Neg - + Axes %1 Neg Axes %1 Neg - + %1 Pos %1 Pos - + Axes %1 Pos Axes %1 Pos - + Hats Hats - + <b>Current gamepad: %1</b> <b>当前手柄: %1</b> @@ -505,420 +803,439 @@ (&G)调试 - + &Options (&O)选项 - + G3D - + HLE - + Default 默认 - + Lo&g Levels (&G)日志级别 - + &Language (&L)语言选择 - + &Video (&V)视频 - + &Anisotropic filtering (&A)各向异性过滤 - + &Zoom (&Z)缩放 - + Co&ntrols (&N)控制 - + &Core (&C)核心 - + &Help (&H)帮助 - + &Open... (&O)打开... - + &Close (&C)关闭 - + - - - + Quickload state 快速读档 - + F4 F4 - + Quicksave state 快速存档 - + F2 F2 - + &Load State File... (&L)读取存档... - + &Save State File... (&S)保存存档... - + E&xit (&X)退出 - + &Run (&R)运行 - + F7 F7 - + &Pause (&P)暂停 - + F8 F8 - + R&eset (&E)重置 - + &Interpreter (&I)解释器 - &Slightly Faster Interpreter - (&S)较快的解释器 + (&S)较快的解释器 - + &Dynarec (&D)动态重编译 - + Load &Map File... (&M)读取Map文件... - + &Save Map File... (&S)保存Map文件... - + &Reset Symbol Table (&R)重置符号表 - + &Disassembly (&D)汇编视图 - + Ctrl+D Ctrl+D - + &Log Console (&L)查看控制台日志 - + Ctrl+L Ctrl+L - + Memory &View... (&V)内存视图... - + Ctrl+M Ctrl+M - + &Keyboard (&K)键盘 - + &Toggle fullscreen (&T)全屏 - + Show &debug statistics (&D)显示调试信息 - + I&gnore illegal reads/writes (&G)忽略非法读写 - + &Gamepad (&G)手柄 - + Run on loa&d (&D)载入时运行 - + Show &FPS counter (&F)显示帧率计数器 - + S&tretch to display (&T)拉伸显示 - + &Sound emulation (&S)模拟声音 - + F12 F12 - + &Buffered Rendering (&B)渲染缓冲 - + F5 F5 - + &Hardware Transform (&H)硬件加速 - + F6 F6 - + &Linear Filtering (&L)线性过滤 - + &Wireframe (experimental) (&W)使用线框 (实验性选项) - + &Display Raw Framebuffer (&D)显示 Raw 原始缓冲 - + Screen &1x &1倍窗口 - + Ctrl+1 Ctrl+1 - + Screen &2x &2倍窗口 - + Ctrl+2 Ctrl+2 - + Screen &3x &3倍窗口 - + Ctrl+3 Ctrl+3 - + Screen &4x &4倍窗口 - + Ctrl+4 Ctrl+4 - + &Fast Memory (dynarec, unstable) (&F)高速闪存 (动态重编译,不稳定) - + &Go to http://www.ppsspp.org/ (&G)转到 http://www.ppsspp.org/ - + &About PPSSPP... (&A)关于 PPSSPP... - + &Use VBO (&U)使用 VBO - - - + + + Debug 调试 - - - + + + Warning 警告 - - - + + + Error 错误 - - - + + + Info 信息 - + D&ump next frame to log (&U)将下一帧转储至日志 - + &Vertex Cache (&V)顶点缓存 - + Memory View Texture... 内存纹理视图... - + + DisplayList... + + + + Simple 2xAA - + Off 关闭 - + 2x 2x - + 4x 4x - + 8x 8x - + 16x 16x - + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + No translations 未翻译 diff --git a/Qt/languages/ppsspp_de.ts b/Qt/languages/ppsspp_de.ts index d079c15859..5521af2c41 100644 --- a/Qt/languages/ppsspp_de.ts +++ b/Qt/languages/ppsspp_de.ts @@ -7,114 +7,139 @@ Controls Controls window title - + Einstellungen CtrlDisAsmView - + Copy &address - + Copy instruction (&hex) - + Copy instruction (&disasm) - + &Run to here - + &Set Next Statement - + &Toggle breakpoint - + &Follow branch - + Go to in &Memory View - + &Rename function... - + New function name - + New function name: + + + Warning + + + + + No symbol selected + + CtrlMemView - + Go to in &disasm - + &Copy value - + + C&hange value + + + + Dump... + + + Set new value + + + + + Set new value: + + CtrlRegisterList - + Go to in &memory view - + Go to in &disasm - + &Copy value - + C&hange... - + Set new value - + Set new value: @@ -219,13 +244,13 @@ - + Id - + Status @@ -240,32 +265,22 @@ - - Run - - - - - Step - - - - + Threads - + Name - + Current PC - + Entry point @@ -275,28 +290,241 @@ - + Go to entry point - + + Change status + + + + Running - + Wait - + Suspend + + + Debugger_DisplayList - - Show code + + Dialog + + + + + DisplayList + + + + + Id + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Run + Start + + + + Stop + Stop + + + + Next DL + + + + + Commands + + + + + Step + + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + + + + + + Width + Weite + + + + + Height + Höhe + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + Werte + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture @@ -310,22 +538,22 @@ Goto: - + Gehe zu: Mode - + Modus Normal - + Normal Symbols - + Symbole @@ -333,6 +561,64 @@ + + Debugger_MemoryTex + + + Dialog + + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + Lesen + + Debugger_VFPU @@ -424,59 +710,59 @@ - - + + <b>No gamepad</b> - + <b>Unknown gamepad</b> - + Buttons - - + + Button %1 - + Axes - + %1 Neg - + Axes %1 Neg - + %1 Pos - + Axes %1 Pos - + Hats - + <b>Current gamepad: %1</b> @@ -486,17 +772,17 @@ PPSSPP - + PPSSPP &File - &Datei + &Datei &Emulation - + &Emulation @@ -504,422 +790,441 @@ - + &Options - &Optionen + &Optionen - + G3D - + G3D - + HLE - + HLE - + Default - Standard + Standard - + Lo&g Levels - + &Language - + &Sprache - + &Video - + &Video - + &Anisotropic filtering - + &Anisotrope Filterung - + &Zoom - + &Zoom - + Co&ntrols - + Ta&stenbelegung - + &Core - + &Help - &Hilfe + &Hilfe - + &Open... - &Öffnen... + &Öffnen... - + &Close - &Schließen + &Schließen - + - - + Quickload state - Schnellladen + Schnellladen - + F4 - + F4 - + Quicksave state - Schnellspeichern + Schnellspeichern - + F2 - + F2 - + &Load State File... - &Lade Spielstand... + &Lade Spielstand... - + &Save State File... - &Speichere Spielstand... + &Speichere Spielstand... - + E&xit - + B&ende - + &Run - &Starte + &Starte - + F7 - + F7 - + &Pause - + &Pause - + F8 - + F8 - + R&eset - + Z&urücksetzen - + &Interpreter - + &Interpreter - &Slightly Faster Interpreter - &etwas scnellerer Interpreter + &etwas scnellerer Interpreter - + &Dynarec - + &Dynarec - + Load &Map File... - Lade &Map Dateien... + Lade &Map Dateien... - + &Save Map File... - &Speichere Map Dateien... + &Speichere Map Dateien... - + &Reset Symbol Table - &Setze Symboltabelle zurück + &Setze Symboltabelle zurück - + &Disassembly - + Ctrl+D - + Strg+D - + &Log Console - &Log Konsole + &Log Konsole - + Ctrl+L - + Strg+L - + Memory &View... - + Ctrl+M - + Strg+M - + &Keyboard - + &Tastatur - + &Toggle fullscreen - + &Vollbild - + Show &debug statistics - + Zeige &debug Statistiken - + I&gnore illegal reads/writes - + &Gamepad - + &Gamepad - + Run on loa&d - + Starte nach dem La&den - + Show &FPS counter - + Zeige &FPS - + S&tretch to display - + S&trecke auf Bildschirm - + &Sound emulation - + &Ton emulation - + F12 - + F12 - + &Buffered Rendering - + &Buffered Rendering - + F5 - + F5 - + &Hardware Transform - + &Hardware Transformation - + F6 - + F6 - + &Linear Filtering - + &Lineare Filterung - + &Wireframe (experimental) - + - + &Display Raw Framebuffer - + - + Screen &1x - + Anzeigegröße &1x - + Ctrl+1 - + Strg+1 - + Screen &2x - + Anzeigegröße &2x - + Ctrl+2 - + Strg+2 - + Screen &3x - + Anzeigegröße &3x - + Ctrl+3 - + Strg+3 - + Screen &4x - + Anzeigegröße &4x - + Ctrl+4 - + Strg+4 - + &Fast Memory (dynarec, unstable) - + &Fast Memory (dynarec, unstable) - + &Go to http://www.ppsspp.org/ - + &Besuche http://www.ppsspp.org - + &About PPSSPP... - + &Über PPSSPP... - + &Use VBO - + &Nutze VBO - - - + + + Debug - + Debug - - - + + + Warning - + Warnung - - - + + + Error - + Fehler - - - + + + Info - + Info - + D&ump next frame to log - + - + &Vertex Cache - + &Vertex Cache - + Memory View Texture... - + - + + DisplayList... + + + + Simple 2xAA - + Einfaches 2xAA - + Off - + Aus - + 2x - + 2x - + 4x - + 4x - + 8x - + 8x - + 16x - + 16x - + + Frameskip + Frameskip + + + + Gamepad + Gamepad + + + + You need to compile with SDL to have Gamepad support. + + + + No translations - + Keine Übersetzung vorhanden @@ -927,87 +1232,87 @@ Cross - Kreuz + Kreuz Circle - Kreis + Kreis Square - Viereck + Viereck Triangle - Dreieck + Dreieck Left Trigger - Linke Schultertaste + Linke Schultertaste Right Trigger - Rechte Schultertaste + Rechte Schultertaste Start - Start + Start Select - Select + Select Up - Hoch + Hoch Down - Runter + Runter Left - Links + Links Right - Rechts + Rechts Home - Home + Home Stick left - Analogstick links + Analogstick links Stick right - Analogstick rechts + Analogstick rechts Stick up - Analogstick oben + Analogstick oben Stick bottom - Analogstick unten + Analogstick unten diff --git a/Qt/languages/ppsspp_en.ts b/Qt/languages/ppsspp_en.ts index 47519c0180..0e85ed802e 100644 --- a/Qt/languages/ppsspp_en.ts +++ b/Qt/languages/ppsspp_en.ts @@ -13,108 +13,133 @@ CtrlDisAsmView - + Copy &address - + Copy instruction (&hex) - + Copy instruction (&disasm) - + &Run to here - + &Set Next Statement - + &Toggle breakpoint - + &Follow branch - + Go to in &Memory View - + &Rename function... - + New function name - + New function name: + + + Warning + + + + + No symbol selected + + CtrlMemView - + Go to in &disasm - + &Copy value - + + C&hange value + + + + Dump... + + + Set new value + + + + + Set new value: + + CtrlRegisterList - + Go to in &memory view - + Go to in &disasm - + &Copy value - + C&hange... - + Set new value - + Set new value: @@ -219,13 +244,13 @@ - + Id - + Status @@ -240,32 +265,22 @@ - - Run - - - - - Step - - - - + Threads - + Name - + Current PC - + Entry point @@ -275,28 +290,241 @@ - + Go to entry point - + + Change status + + + + Running - + Wait - + Suspend + + + Debugger_DisplayList - - Show code + + Dialog + + + + + DisplayList + + + + + Id + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Run + + + + + Stop + + + + + Next DL + + + + + Commands + + + + + Step + + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture @@ -333,6 +561,64 @@ + + Debugger_MemoryTex + + + Dialog + + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + Debugger_VFPU @@ -424,59 +710,59 @@ - - + + <b>No gamepad</b> - + <b>Unknown gamepad</b> - + Buttons - - + + Button %1 - + Axes - + %1 Neg - + Axes %1 Neg - + %1 Pos - + Axes %1 Pos - + Hats - + <b>Current gamepad: %1</b> @@ -504,420 +790,435 @@ - + &Options - + G3D - + HLE - + Default - + Lo&g Levels - + &Language - + &Video - + &Anisotropic filtering - + &Zoom - + Co&ntrols - + &Core - + &Help - + &Open... - + &Close - + - - + Quickload state - + F4 - + Quicksave state - + F2 - + &Load State File... - + &Save State File... - + E&xit - + &Run - + F7 - + &Pause - + F8 - + R&eset - + &Interpreter - - &Slightly Faster Interpreter - - - - + &Dynarec - + Load &Map File... - + &Save Map File... - + &Reset Symbol Table - + &Disassembly - + Ctrl+D - + &Log Console - + Ctrl+L - + Memory &View... - + Ctrl+M - + &Keyboard - + &Toggle fullscreen - + Show &debug statistics - + I&gnore illegal reads/writes - + &Gamepad - + Run on loa&d - + Show &FPS counter - + S&tretch to display - + &Sound emulation - + F12 - + &Buffered Rendering - + F5 - + &Hardware Transform - + F6 - + &Linear Filtering - + &Wireframe (experimental) - + &Display Raw Framebuffer - + Screen &1x - + Ctrl+1 - + Screen &2x - + Ctrl+2 - + Screen &3x - + Ctrl+3 - + Screen &4x - + Ctrl+4 - + &Fast Memory (dynarec, unstable) - + &Go to http://www.ppsspp.org/ - + &About PPSSPP... - + &Use VBO - - - + + + Debug - - - + + + Warning - - - + + + Error - - - + + + Info - + D&ump next frame to log - + &Vertex Cache - + Memory View Texture... - + + DisplayList... + + + + Simple 2xAA - + Off - + 2x - + 4x - + 8x - + 16x - + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + No translations diff --git a/Qt/languages/ppsspp_fr.ts b/Qt/languages/ppsspp_fr.ts index ce5006357e..e5ed92fcbd 100644 --- a/Qt/languages/ppsspp_fr.ts +++ b/Qt/languages/ppsspp_fr.ts @@ -7,114 +7,139 @@ Controls Controls window title - + Contrôles CtrlDisAsmView - + Copy &address - + Copy instruction (&hex) - + Copy instruction (&disasm) - + &Run to here - + &Set Next Statement - + &Toggle breakpoint - + &Follow branch - + Go to in &Memory View - + &Rename function... - + New function name - + New function name: + + + Warning + Avertissement + + + + No symbol selected + + CtrlMemView - + Go to in &disasm - + &Copy value - + + C&hange value + + + + Dump... + + + Set new value + + + + + Set new value: + + CtrlRegisterList - + Go to in &memory view - + Go to in &disasm - + &Copy value - + C&hange... - + Set new value - + Set new value: @@ -219,13 +244,13 @@ - + Id - + Status @@ -240,32 +265,22 @@ - - Run - - - - - Step - - - - + Threads - + Name - + Current PC - + Entry point @@ -275,28 +290,241 @@ - + Go to entry point - + + Change status + + + + Running - + Wait - + Suspend + + + Debugger_DisplayList - - Show code + + Dialog + + + + + DisplayList + + + + + Id + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Run + + + + + Stop + + + + + Next DL + + + + + Commands + + + + + Step + + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture @@ -333,6 +561,64 @@ + + Debugger_MemoryTex + + + Dialog + + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + Debugger_VFPU @@ -376,22 +662,22 @@ Gamepad Configuration - + Configuration du pad GamePad List - + Liste des controlleurs de jeu Refresh - + Rafraîchir Select - + Sélectionner @@ -406,77 +692,77 @@ Assign Gamepad input - + Assigner la touche du pad to PSP button/axis - + au boutton PSP Assign - + Assigner Press buttons on your gamePad to verify mapping : - + Vérifier les contrôles en appuyant sur les bouttons du pad : - - + + <b>No gamepad</b> - + <b>Unknown gamepad</b> - + Buttons - - + + Button %1 - + Axes - + %1 Neg - + Axes %1 Neg - + %1 Pos - + Axes %1 Pos - + Hats - + <b>Current gamepad: %1</b> @@ -504,510 +790,530 @@ Debu&g - + &Options &Options - + G3D - + G3D - + HLE - + HLE - + Default Défaut - + Lo&g Levels - + Op&tions du journal - + &Language - + &Langue - + &Video - + &Video - + &Anisotropic filtering - + &Filtrage anisotrope - + &Zoom - + &Zoom - + Co&ntrols - + Co&ntrôles - + &Core - + &Emulation - + &Help &Aide - + &Open... &Ouvrir... - + &Close &Fermer - + - - + - - + Quickload state - + Chargement rapide - + F4 - + F4 - + Quicksave state - + Sauvegarde rapide - + F2 - + F2 - + &Load State File... - + &Charger... - + &Save State File... - + &Sauvegarder... - + E&xit &Quitter - + &Run - + &Démarrer - + F7 - + F7 - + &Pause - + &Pause - + F8 - + F8 - + R&eset - + R&eset - + &Interpreter - + &Interpreteur - &Slightly Faster Interpreter - + Could delete the "un peu" which means slightly but takes a lot of space + &Interpreteur un peu plus rapide - + &Dynarec - + &DRC - + Load &Map File... - + &Save Map File... - + &Reset Symbol Table - + &Disassembly - + Ctrl+D - + Ctrl+D - + &Log Console - + &Journal d'événements - + Ctrl+L - + Ctrl+L - + Memory &View... - + Ctrl+M - + Ctrl+M - + &Keyboard - + &Clavier - + &Toggle fullscreen - + &Plein écran - + Show &debug statistics - + Afficher &les statistiques de débogage - + I&gnore illegal reads/writes - + I&gnorer les écritures/lectures illégales - + &Gamepad - + &Pad - + Run on loa&d - + Lancer au cha&rgement - + Show &FPS counter - + Afficher &les FPS - + S&tretch to display - + A&dapter à l'écran - + &Sound emulation - + &Son - + F12 - + F12 - + &Buffered Rendering - + &Rendu Tampon - + F5 - + F5 - + &Hardware Transform - + &Hardware Transform - + F6 - + F6 - + &Linear Filtering - + &Filtrage Linéaire - + &Wireframe (experimental) - + &Rendu en fil de fer (expérimental) - + &Display Raw Framebuffer - + Screen &1x - + &1x - + Ctrl+1 - + Ctrl+1 - + Screen &2x - + &2x - + Ctrl+2 - + Ctrl+2 - + Screen &3x - + &3x - + Ctrl+3 - + Ctrl+3 - + Screen &4x - + &4x - + Ctrl+4 - + Ctrl+4 - + &Fast Memory (dynarec, unstable) - + &Mémoire Rapide (DRC, instable) - + &Go to http://www.ppsspp.org/ - + &Aller à http://www.ppsspp.org/ - + &About PPSSPP... - + &A propos de PPSSPP... - + &Use VBO - + &Utiliser les VBO - - - + + + Debug - + Débogage - - - + + + Warning - + Avertissement - - - + + + Error - + Erreur - - - + + + Info - + Informations - + D&ump next frame to log - + &Vertex Cache - + &Cache du Vertex - + Memory View Texture... - + + DisplayList... + + + + Simple 2xAA - + 2x AA - + Off - + Off - + 2x - + 2x - + 4x - + 4x - + 8x - + 8x - + 16x + 16x + + + + Frameskip - - No translations + + Gamepad + + + You need to compile with SDL to have Gamepad support. + + + + + No translations + Pas de traductions + gamepadMapping Cross - + Croix Circle - + Rond Square - + Carré Triangle - + Triangle Left Trigger - + Boutton L Right Trigger - + Boutton R Start - + Start Select - + Select Up - + Haut Down - + Bas Left - + Gauche Right - + Droite Home - + Accueil Stick left - + Stick : Gauche Stick right - + Stick : Droite Stick up - + Stick : Haut Stick bottom - + Stick : Bas diff --git a/Qt/languages/ppsspp_gr.ts b/Qt/languages/ppsspp_gr.ts new file mode 100644 index 0000000000..73bd2cf92b --- /dev/null +++ b/Qt/languages/ppsspp_gr.ts @@ -0,0 +1,1330 @@ + + + + + Controls + + + Controls + Controls window title + Τίτλος παραθύρου χειρισμών + + + + CtrlDisAsmView + + + Copy &address + Αντιγραφή &address + + + + Copy instruction (&hex) + Αντιγραφή οδηγίας (&hex) + + + + Copy instruction (&disasm) + Αντιγραφή οδηγίας (&disasm) + + + + &Run to here + &Τρέξιμο ως εδώ + + + + &Set Next Statement + &Ορισμός Επόμενη Κατάστασης + + + + &Toggle breakpoint + + + + + &Follow branch + &Ακολούθηση κλάδου + + + + Go to in &Memory View + Μετάβαση σε &Προβολέα Μνήμης + + + + &Rename function... + &Μετονομασία λειτουργίας... + + + + New function name + Νέο όνομα λειτουργίας + + + + New function name: + Νέο όνομα λειτουργίας: + + + + Warning + Προειδοποίηση + + + + No symbol selected + + + + + CtrlMemView + + + Go to in &disasm + Μετάβαση σε &disasm + + + + &Copy value + &Αντιγραφή τιμής + + + + C&hange value + + + + + Dump... + Αποτύπωση... + + + + Set new value + Ορισμός νέας τιμής + + + + Set new value: + Ορισμός νέας τιμής: + + + + CtrlRegisterList + + + Go to in &memory view + Μετάβαση σε &προβολής μνήμης + + + + Go to in &disasm + Μετάβαση σε &disasm + + + + &Copy value + &Αντιγραφή τιμής + + + + C&hange... + Α&λλαγή... + + + + Set new value + Ορισμός νέας τιμής + + + + Set new value: + Ορισμός νέας τιμής: + + + + Debugger_Disasm + + + Disassembler + Window title + Τίτλος παραθύρου + + + + Ctr: + + + + + &Go to + &Μετάβαση σε + + + + &PC + + + + + &LR + + + + + Show VFPU + Εμφάνιση VFPU + + + + Regs + + + + + Funcs + + + + + &Go + &Ξεκίνημα + + + + Stop + Σταμάτημα + + + + Step &Into + Μεταπήδηση &σε + + + + Step &Over + Μεταπήδηση &Πάνω από + + + + S&kip + Α&γνόηση + + + + Next &HLE + Επόμενο &ΕΥΕ (HLE) + + + + Breakpoints + + + + + Address + Διεύθυνση + + + + Clear All + Εκκαθάριση Όλων + + + + Callstack + + + + + Display Lists + Λίστες Απεικόνισης + + + + + Id + + + + + + Status + Κατάσταση + + + + Start Address + Αρχική Διεύθυνση + + + + Current Address + Τρέχουσα Διεύθυνση + + + Run + Εκκίνηση + + + Step + Βήμα + + + + Threads + Νήματα + + + + Name + Όνομα + + + + Current PC + Τρέχον PC + + + + Entry point + Σημείο έναρξης + + + + Remove breakpoint + Αφαίρεση σημείου διακοπής + + + + Go to entry point + Μετάβαση στο σημείο εισόδου + + + + Change status + + + + + Running + Σε λειτουργία + + + + Wait + Αναμονή + + + + Suspend + Αναστολή + + + Show code + Εμφάνιση κώδικα + + + + Debugger_DisplayList + + + Dialog + Διάλογος + + + + DisplayList + + + + + Id + + + + + Status + Κατάσταση + + + + Start Address + Αρχική Διεύθυνση + + + + Current Address + Τρέχουσα Διεύθυνση + + + + Run + Εκκίνηση + + + + Stop + Σταμάτημα + + + + Next DL + + + + + Commands + + + + + Step + Βήμα + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + Διεύθυνση + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + + + + + Debugger_Memory + + + Dialog + Διάλογος + + + + Goto: + Μετάβαση σε: + + + + Mode + Λειτουργία + + + + Normal + Κανονικό + + + + Symbols + Σύμβολα + + + + Memory Viewer - %1 + Προβολέας Μνήμης - %1 + + + + Debugger_MemoryTex + + + Dialog + Διάλογος + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + + + Debugger_VFPU + + + VFPU + + + + + Float + + + + + HalfFloat + + + + + Hex + Δεκαεξαδικό + + + + Bytes + + + + + Shorts + + + + + Ints + + + + + GamePadDialog + + + Gamepad Configuration + Διαμόρφωση Χειριστηρίου + + + + GamePad List + Λίστα Χειριστηρίων + + + + Refresh + Ανανέωση + + + + Select + Επιλογή + + + + Gamepad Values : + Τιμές Χειριστηρίου : + + + + TextLabel + + + + + Assign Gamepad input + Εκχώρηση εισόδου χειριστηρίου + + + + to PSP button/axis + στο κουμί/άξονα PSP + + + + Assign + Εκχώρηση + + + + Press buttons on your gamePad to verify mapping : + Πατήστε τα κουμπιά στο χειριστήριο σας για να επιβεβαιώσετε την αντιστοίχιση: + + + + + <b>No gamepad</b> + <b>Κανένα χειριστήριο</b> + + + + <b>Unknown gamepad</b> + <b>’γνωστο χειριστήριο</b> + + + + Buttons + Πλήκτρα + + + + + Button %1 + Πλήκτρο %1 + + + + Axes + ’ξονες + + + + %1 Neg + %1 Αρν. + + + + Axes %1 Neg + ’ξονες %1 Αρν. + + + + %1 Pos + %1 Θετ. + + + + Axes %1 Pos + ’ξονες %1 Θετ. + + + + Hats + Μοχλοί + + + + <b>Current gamepad: %1</b> + <b>Τρέχον χειριστήριο: %1</b> + + + + MainWindow + + + PPSSPP + + + + + &File + &Αρχείο + + + + &Emulation + &Εξομοίωση + + + + Debu&g + Αποσφαλμάτωσ&η + + + + &Options + &Επιλογές + + + + G3D + + + + + HLE + ΕΥΕ(HLE) + + + + Default + Προεπιλογή + + + + Lo&g Levels + Επ&ίπεδα Καταγραφικού + + + + &Language + &Γλώσσα + + + + &Video + &Βίντεο + + + + &Anisotropic filtering + &Ανισοτροπικό φιτράρισμα + + + + &Zoom + &Μεγένθυση + + + + Co&ntrols + Χε&ιριστήρια + + + + &Core + &Πυρήνας + + + + &Help + &Βοήθεια + + + + &Open... + &’νοιγμα... + + + + &Close + &Κλείσιμο + + + + - + + + + + Quickload state + Γρήγορη Φόρτωση + + + + F4 + + + + + Quicksave state + Γρήγορη Αποθήκευση + + + + F2 + + + + + &Load State File... + &Φόρτωση Σημείου Αποθήκευσης... + + + + &Save State File... + &Αποθήκευση Σημείου Αποθήκευσης... + + + + E&xit + Έ&ξοδος + + + + &Run + &Εκκίνηση + + + + F7 + + + + + &Pause + &Παύση + + + + F8 + + + + + R&eset + Ε&πανεκκίνηση + + + + &Interpreter + + + + &Slightly Faster Interpreter + &Ελαφρώς Γρηγορότερος Interpreter + + + + &Dynarec + + + + + Load &Map File... + Φόρτωση &Αρχείου Χάρτη... + + + + &Save Map File... + &Αποθήκευση Αρχείου Χάρτη... + + + + &Reset Symbol Table + &Επαναφορά Πίνακα Συμβόλων + + + + &Disassembly + &Αποσυναρμολόγηση + + + + Ctrl+D + + + + + &Log Console + &Κονσόλα Καταγραφέα + + + + Ctrl+L + + + + + Memory &View... + Εμφάνιση &Μνήμης... + + + + Ctrl+M + + + + + &Keyboard + &Πληκτρολόγιο + + + + &Toggle fullscreen + &Μετάβαση σε πλήρη οθόνη + + + + Show &debug statistics + Εμφάνιση &στατιστικών αποσφαλμάτωσης + + + + I&gnore illegal reads/writes + Α&γνόηση αθέμιτων αναγνώσεων + + + + &Gamepad + &Χειριστήριο + + + + Run on loa&d + Εκκίνηση στην έναρξ&η + + + + Show &FPS counter + Εμφάνιση μετρητή &FPS + + + + S&tretch to display + Ε&πέκταση στην οθόνη + + + + &Sound emulation + &Εξομοίωση ήχου + + + + F12 + + + + + &Buffered Rendering + &Buffered Απεικόνιση + + + + F5 + + + + + &Hardware Transform + Hardware Μετασχηματισμός + + + + F6 + + + + + &Linear Filtering + Γραμμικό φιλτράρισμα + + + + &Wireframe (experimental) + Γράφημα Πλέγματος + + + + &Display Raw Framebuffer + &Εμφάνιση Ακατέργαστου Framebuffer + + + + Screen &1x + Οθόνη &1x + + + + Ctrl+1 + + + + + Screen &2x + Οθόνη &2x + + + + Ctrl+2 + + + + + Screen &3x + Οθόνη &3x + + + + Ctrl+3 + + + + + Screen &4x + Οθόνη &4x + + + + Ctrl+4 + + + + + &Fast Memory (dynarec, unstable) + &Γρήγορη Μνήμη (dynarec, ασταθής) + + + + &Go to http://www.ppsspp.org/ + &Μετάβαση σε http://www.ppsspp.org/ + + + + &About PPSSPP... + &Περί του PPSSPP... + + + + &Use VBO + &Χρήση VBO + + + + + + Debug + Αποσφαλμάτωση + + + + + + Warning + Προειδοποίηση + + + + + + Error + Σφάλμα + + + + + + Info + Πληροφορίες + + + + D&ump next frame to log + Ε&ξαγωγή επόμενου καρέ στον καταγραφέα + + + + &Vertex Cache + &Προσορηνή Μνήμη Κορυφών + + + + Memory View Texture... + Προβολή Μνήμης Υφών... + + + + DisplayList... + + + + + Simple 2xAA + Απλό 2xAA + + + + Off + + + + + 2x + + + + + 4x + + + + + 8x + + + + + 16x + + + + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + + No translations + Καμία Μετάφραση + + + + gamepadMapping + + + Cross + Χί + + + + Circle + Κύκλος + + + + Square + Τετράγωνο + + + + Triangle + Τρίγωνο + + + + Left Trigger + Αριστερή σκανδάλη + + + + Right Trigger + Δεξιά σκανδάλη + + + + Start + + + + + Select + Επιλογή + + + + Up + Πάνω + + + + Down + Κάτω + + + + Left + Αριστερά + + + + Right + Δεξιά + + + + Home + + + + + Stick left + Αναλογικό αριστερά + + + + Stick right + Αναλογικό δεξιά + + + + Stick up + Αναλογικό πάνω + + + + Stick bottom + Αναλογικό κάτω + + + diff --git a/Qt/languages/ppsspp_hu.ts b/Qt/languages/ppsspp_hu.ts new file mode 100644 index 0000000000..244f02f54c --- /dev/null +++ b/Qt/languages/ppsspp_hu.ts @@ -0,0 +1,1314 @@ + + + + + Controls + + + Controls + Controls window title + Írányítás + + + + CtrlDisAsmView + + + Copy &address + Cím másolása + + + + Copy instruction (&hex) + + + + + Copy instruction (&disasm) + + + + + &Run to here + + + + + &Set Next Statement + + + + + &Toggle breakpoint + + + + + &Follow branch + + + + + Go to in &Memory View + + + + + &Rename function... + + + + + New function name + + + + + New function name: + + + + + Warning + + + + + No symbol selected + + + + + CtrlMemView + + + Go to in &disasm + + + + + &Copy value + + + + + C&hange value + + + + + Dump... + + + + + Set new value + + + + + Set new value: + + + + + CtrlRegisterList + + + Go to in &memory view + + + + + Go to in &disasm + + + + + &Copy value + + + + + C&hange... + + + + + Set new value + + + + + Set new value: + + + + + Debugger_Disasm + + + Disassembler + Window title + + + + + Ctr: + + + + + &Go to + + + + + &PC + + + + + &LR + + + + + Show VFPU + + + + + Regs + + + + + Funcs + + + + + &Go + + + + + Stop + + + + + Step &Into + + + + + Step &Over + + + + + S&kip + + + + + Next &HLE + + + + + Breakpoints + + + + + Address + + + + + Clear All + + + + + Callstack + + + + + Display Lists + + + + + + Id + + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Threads + + + + + Name + + + + + Current PC + + + + + Entry point + + + + + Remove breakpoint + + + + + Go to entry point + + + + + Change status + + + + + Running + + + + + Wait + + + + + Suspend + + + + + Debugger_DisplayList + + + Dialog + + + + + DisplayList + + + + + Id + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Run + + + + + Stop + + + + + Next DL + + + + + Commands + + + + + Step + + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + + + + + Debugger_Memory + + + Dialog + + + + + Goto: + + + + + Mode + + + + + Normal + + + + + Symbols + + + + + Memory Viewer - %1 + + + + + Debugger_MemoryTex + + + Dialog + + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + + + Debugger_VFPU + + + VFPU + + + + + Float + + + + + HalfFloat + + + + + Hex + + + + + Bytes + + + + + Shorts + + + + + Ints + + + + + GamePadDialog + + + Gamepad Configuration + Játékvezérlő Beállítás + + + + GamePad List + Játékvezérlők listája + + + + Refresh + Frissítés + + + + Select + Kiválasztás + + + + Gamepad Values : + Játékvezérlő Értékei : + + + + TextLabel + + + + + Assign Gamepad input + Játékvezérlő Gomb hozzárendelése + + + + to PSP button/axis + PSP gomb/tengelyhez + + + + Assign + Hozzárendelés + + + + Press buttons on your gamePad to verify mapping : + Nyomj meg gombokat a játékvezérlődön a gombok ellenőrzéséhez : + + + + + <b>No gamepad</b> + <b>Nincs Játékvezérlő</b> + + + + <b>Unknown gamepad</b> + <b>Ismeretlen Játékvezérlő</b> + + + + Buttons + Gombok + + + + + Button %1 + Gomb %1 + + + + Axes + Tengelyek + + + + %1 Neg + %1 Neg + + + + Axes %1 Neg + Tengely %1 Neg + + + + %1 Pos + %1 Poz + + + + Axes %1 Pos + Tengely %1 Poz + + + + Hats + + + + + <b>Current gamepad: %1</b> + <b>Jelenlegi Játékvezérlő: %1</b> + + + + MainWindow + + + PPSSPP + PPSSPP + + + + &File + Fájl + + + + &Emulation + Emuláció + + + + Debu&g + + + + + &Options + Beállítások + + + + G3D + + + + + HLE + + + + + Default + Alapértelmezett + + + + Lo&g Levels + Log szint + + + + &Language + Nyelv + + + + &Video + Videó + + + + &Anisotropic filtering + Anizotróp szűrés + + + + &Zoom + Nagyítás + + + + Co&ntrols + Irányítás + + + + &Core + Központi + + + + &Help + Segítség + + + + &Open... + Megnyitás... + + + + &Close + Bezárás + + + + - + - + + + + Quickload state + Állás gyorsbetöltése + + + + F4 + F4 + + + + Quicksave state + Állás gyorsmentése + + + + F2 + F2 + + + + &Load State File... + Állás betöltése... + + + + &Save State File... + Állás mentése... + + + + E&xit + Kilépés + + + + &Run + Futtatás + + + + F7 + F7 + + + + &Pause + Szüneteltetés + + + + F8 + F8 + + + + R&eset + Újraindítás + + + + &Interpreter + Interpreter + + + + &Dynarec + Dynarec + + + + Load &Map File... + Map fájl betöltése... + + + + &Save Map File... + Map fájl mentése... + + + + &Reset Symbol Table + + + + + &Disassembly + + + + + Ctrl+D + Ctrl+D + + + + &Log Console + Log Konzol + + + + Ctrl+L + Ctrl+L + + + + Memory &View... + + + + + Ctrl+M + Ctrl+M + + + + &Keyboard + Billentyűzet + + + + &Toggle fullscreen + Teljesképernyőre váltás + + + + Show &debug statistics + + + + + I&gnore illegal reads/writes + Illegális olvasások/írások mellőzése + + + + &Gamepad + Játékvezérlő + + + + Run on loa&d + Futtatás betöltéskor + + + + Show &FPS counter + FPS számláló mutatása + + + + S&tretch to display + Kép nyújtása + + + + &Sound emulation + Hang emuláció + + + + F12 + F12 + + + + &Buffered Rendering + Pufferelt Renderelés + + + + F5 + F5 + + + + &Hardware Transform + Hardveres Átváltoztatás + + + + F6 + F6 + + + + &Linear Filtering + Lineáris Szűrés + + + + &Wireframe (experimental) + + + + + &Display Raw Framebuffer + + + + + Screen &1x + 1x-es méret + + + + Ctrl+1 + Ctrl+1 + + + + Screen &2x + 2x-es méret + + + + Ctrl+2 + Ctrl+2 + + + + Screen &3x + 3x-os méret + + + + Ctrl+3 + Ctrl+3 + + + + Screen &4x + 4x-es méret + + + + Ctrl+4 + Ctrl+4 + + + + &Fast Memory (dynarec, unstable) + Gyors Memória (dynarec, instabil) + + + + &Go to http://www.ppsspp.org/ + Ugrás a honlapra http//www.ppsspp.org/ + + + + &About PPSSPP... + PPSSPP Névjegye + + + + &Use VBO + VBO Használata + + + + + + Debug + + + + + + + Warning + Figyelmeztetés + + + + + + Error + Hiba + + + + + + Info + Infó + + + + D&ump next frame to log + + + + + &Vertex Cache + + + + + Memory View Texture... + + + + + DisplayList... + + + + + Simple 2xAA + Egyszerű 2x-es AA + + + + Off + Ki + + + + 2x + 2x + + + + 4x + 4x + + + + 8x + 8x + + + + 16x + 16x + + + + Frameskip + Frameskip + + + + Gamepad + Játékvezérlő + + + + You need to compile with SDL to have Gamepad support. + SDL-t kell használnod fordításnál Játékvezérlő támogatásért. + + + + No translations + Nincs Fordítás + + + + gamepadMapping + + + Cross + Kereszt + + + + Circle + Kör + + + + Square + Négyzet + + + + Triangle + Háromszög + + + + Left Trigger + Bal Trigger + + + + Right Trigger + Jobb Trigger + + + + Start + Start + + + + Select + Select + + + + Up + Fel + + + + Down + Le + + + + Left + Bal + + + + Right + Jobb + + + + Home + Home + + + + Stick left + Stick balra + + + + Stick right + Stick jobbra + + + + Stick up + Stick fel + + + + Stick bottom + Stick le + + + diff --git a/Qt/languages/ppsspp_id.ts b/Qt/languages/ppsspp_id.ts new file mode 100644 index 0000000000..0b4c424130 --- /dev/null +++ b/Qt/languages/ppsspp_id.ts @@ -0,0 +1,1314 @@ + + + + + Controls + + + Controls + Controls window title + + + + + CtrlDisAsmView + + + Copy &address + + + + + Copy instruction (&hex) + + + + + Copy instruction (&disasm) + + + + + &Run to here + + + + + &Set Next Statement + + + + + &Toggle breakpoint + + + + + &Follow branch + + + + + Go to in &Memory View + + + + + &Rename function... + + + + + New function name + + + + + New function name: + + + + + Warning + Peringatan + + + + No symbol selected + + + + + CtrlMemView + + + Go to in &disasm + + + + + &Copy value + + + + + C&hange value + + + + + Dump... + + + + + Set new value + + + + + Set new value: + + + + + CtrlRegisterList + + + Go to in &memory view + + + + + Go to in &disasm + + + + + &Copy value + + + + + C&hange... + + + + + Set new value + + + + + Set new value: + + + + + Debugger_Disasm + + + Disassembler + Window title + + + + + Ctr: + + + + + &Go to + + + + + &PC + + + + + &LR + + + + + Show VFPU + + + + + Regs + + + + + Funcs + + + + + &Go + + + + + Stop + + + + + Step &Into + + + + + Step &Over + + + + + S&kip + + + + + Next &HLE + + + + + Breakpoints + + + + + Address + + + + + Clear All + + + + + Callstack + + + + + Display Lists + + + + + + Id + + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Threads + + + + + Name + + + + + Current PC + + + + + Entry point + + + + + Remove breakpoint + + + + + Go to entry point + + + + + Change status + + + + + Running + + + + + Wait + + + + + Suspend + + + + + Debugger_DisplayList + + + Dialog + + + + + DisplayList + + + + + Id + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Run + + + + + Stop + + + + + Next DL + + + + + Commands + + + + + Step + + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + + + + + Debugger_Memory + + + Dialog + + + + + Goto: + + + + + Mode + + + + + Normal + + + + + Symbols + + + + + Memory Viewer - %1 + + + + + Debugger_MemoryTex + + + Dialog + + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + + + Debugger_VFPU + + + VFPU + + + + + Float + + + + + HalfFloat + + + + + Hex + + + + + Bytes + + + + + Shorts + + + + + Ints + + + + + GamePadDialog + + + Gamepad Configuration + + + + + GamePad List + + + + + Refresh + + + + + Select + Select + + + + Gamepad Values : + + + + + TextLabel + + + + + Assign Gamepad input + + + + + to PSP button/axis + + + + + Assign + + + + + Press buttons on your gamePad to verify mapping : + + + + + + <b>No gamepad</b> + + + + + <b>Unknown gamepad</b> + + + + + Buttons + Tombol + + + + + Button %1 + + + + + Axes + + + + + %1 Neg + + + + + Axes %1 Neg + + + + + %1 Pos + + + + + Axes %1 Pos + + + + + Hats + + + + + <b>Current gamepad: %1</b> + + + + + MainWindow + + + PPSSPP + + + + + &File + + + + + &Emulation + + + + + Debu&g + + + + + &Options + + + + + G3D + + + + + HLE + + + + + Default + + + + + Lo&g Levels + + + + + &Language + + + + + &Video + + + + + &Anisotropic filtering + + + + + &Zoom + + + + + Co&ntrols + + + + + &Core + + + + + &Help + + + + + &Open... + + + + + &Close + + + + + - + + + + + Quickload state + + + + + F4 + + + + + Quicksave state + + + + + F2 + + + + + &Load State File... + + + + + &Save State File... + + + + + E&xit + + + + + &Run + + + + + F7 + + + + + &Pause + + + + + F8 + + + + + R&eset + + + + + &Interpreter + + + + + &Dynarec + + + + + Load &Map File... + + + + + &Save Map File... + + + + + &Reset Symbol Table + + + + + &Disassembly + + + + + Ctrl+D + + + + + &Log Console + + + + + Ctrl+L + + + + + Memory &View... + + + + + Ctrl+M + + + + + &Keyboard + + + + + &Toggle fullscreen + + + + + Show &debug statistics + + + + + I&gnore illegal reads/writes + + + + + &Gamepad + + + + + Run on loa&d + + + + + Show &FPS counter + + + + + S&tretch to display + + + + + &Sound emulation + + + + + F12 + + + + + &Buffered Rendering + + + + + F5 + + + + + &Hardware Transform + + + + + F6 + + + + + &Linear Filtering + + + + + &Wireframe (experimental) + + + + + &Display Raw Framebuffer + + + + + Screen &1x + + + + + Ctrl+1 + + + + + Screen &2x + + + + + Ctrl+2 + + + + + Screen &3x + + + + + Ctrl+3 + + + + + Screen &4x + + + + + Ctrl+4 + + + + + &Fast Memory (dynarec, unstable) + + + + + &Go to http://www.ppsspp.org/ + + + + + &About PPSSPP... + + + + + &Use VBO + + + + + + + Debug + + + + + + + Warning + Peringatan + + + + + + Error + Galat + + + + + + Info + Informasi + + + + D&ump next frame to log + + + + + &Vertex Cache + + + + + Memory View Texture... + + + + + DisplayList... + + + + + Simple 2xAA + + + + + Off + Mati + + + + 2x + + + + + 4x + + + + + 8x + + + + + 16x + + + + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + + No translations + Tak ada terjemahan + + + + gamepadMapping + + + Cross + Silang + + + + Circle + Bundar + + + + Square + Kotak + + + + Triangle + Segitiga + + + + Left Trigger + Trigger Kiri + + + + Right Trigger + Trigger Kanan + + + + Start + Start + + + + Select + Select + + + + Up + Atas + + + + Down + Bawah + + + + Left + Kiri + + + + Right + Kanan + + + + Home + Beranda + + + + Stick left + Stick kiri + + + + Stick right + Stick kanan + + + + Stick up + Stick atas + + + + Stick bottom + Stick bawah + + + diff --git a/Qt/languages/ppsspp_pl.ts b/Qt/languages/ppsspp_pl.ts index 930d85663c..17779b5b13 100644 --- a/Qt/languages/ppsspp_pl.ts +++ b/Qt/languages/ppsspp_pl.ts @@ -13,108 +13,133 @@ CtrlDisAsmView - + Copy &address Kopiuj &adres - + Copy instruction (&hex) Kopiuj instrukcję (&hex) - + Copy instruction (&disasm) Kopiuj instrukcję (&deasm) - + &Run to here &Uruchom do tego miejsca - + &Set Next Statement U&staw następny rozkaz - + &Toggle breakpoint Ustaw &breakpoint - + &Follow branch - + Go to in &Memory View Przejdź do widoku &pamięci - + &Rename function... &Zmień nazwę funkcji... - + New function name Nowa nazwa funkcji - + New function name: Nowa nazwa funkcji: + + + Warning + Ostrzeżenia + + + + No symbol selected + + CtrlMemView - + Go to in &disasm &Przejdź do deasemblera - + &Copy value &Kopiuj wartość - + + C&hange value + + + + Dump... Zrzut... + + + Set new value + Ustaw nową wartość + + + + Set new value: + Ustaw nową wartość: + CtrlRegisterList - + Go to in &memory view Przejdź do widoku &pamięci - + Go to in &disasm Przejdź do &deasemblera - + &Copy value &Kopiuj wartość - + C&hange... &Zmień... - + Set new value Ustaw nową wartość - + Set new value: Ustaw nową wartość: @@ -219,13 +244,13 @@ - + Id Id - + Status Status @@ -240,32 +265,30 @@ Obecny adres - Run - Uruchom + Uruchom - Step - Krok + Krok - + Threads Wątki - + Name Nazwa - + Current PC Obecny PC - + Entry point Punkt wejścia @@ -275,29 +298,246 @@ Usuń breakpoint - + Go to entry point Przejdź do punktu wejścia - + + Change status + + + + Running Działający - + Wait Czekający - + Suspend Uśpiony - Show code - Pokaż kod + Pokaż kod + + + + Debugger_DisplayList + + + Dialog + Widok pamięci + + + + DisplayList + + + + + Id + Id + + + + Status + Status + + + + Start Address + Początkowy adres + + + + Current Address + Obecny adres + + + + Run + Uruchom + + + + Stop + Stop + + + + Next DL + + + + + Commands + + + + + Step + Krok + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + Adres + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + @@ -333,6 +573,64 @@ Widok pamięci - %1 + + Debugger_MemoryTex + + + Dialog + Widok pamięci + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + Debugger_VFPU @@ -424,59 +722,59 @@ Naciśnij przyciski na kontrolerze: - - + + <b>No gamepad</b> <b>Nie wykryto pada</b> - + <b>Unknown gamepad</b> <b>Nieznany pad</b> - + Buttons Przyciski - - + + Button %1 Przycisk %1 - + Axes Osie - + %1 Neg %1 zanegowany - + Axes %1 Neg Oś %1 zanegowana - + %1 Pos %1 pozycja - + Axes %1 Pos Pozycja osi %1 - + Hats Haty - + <b>Current gamepad: %1</b> <b>Wybrany pad: %1</b> @@ -504,420 +802,439 @@ &Debugger - + &Options &Opcje - + G3D G3D - + HLE HLE - + Default Domyślne - + Lo&g Levels &Poziomy logowania - + &Language &Język - + &Video &Wideo - + &Anisotropic filtering &Filtrowanie anizotropowe - + &Zoom &Powiększenie - + Co&ntrols S&terowanie - + &Core Jądr&o - + &Help Pomo&c - + &Open... &Otwórz... - + &Close &Zamknij - + - - + Quickload state Wczytaj stan - + F4 F4 - + Quicksave state Zapisz stan - + F2 F2 - + &Load State File... &Wczytaj plik stanu... - + &Save State File... &Zapisz plik stanu... - + E&xit Wyj&dź - + &Run &Uruchom - + F7 F7 - + &Pause &Pauza - + F8 F8 - + R&eset &Reset - + &Interpreter &Interpreter - &Slightly Faster Interpreter - &Szybszy interpreter + &Szybszy interpreter - + &Dynarec R&ekompilacja (Dynarec) - + Load &Map File... &Wczytaj plik mapy... - + &Save Map File... &Zapisz plik mapy... - + &Reset Symbol Table Zresetuj &tablicę symboli - + &Disassembly &Deasembler - + Ctrl+D Ctrl+D - + &Log Console &Konsola logowania - + Ctrl+L Ctrl+L - + Memory &View... Widok &pamięci... - + Ctrl+M Ctrl+M - + &Keyboard &Klawiatura - + &Toggle fullscreen Pełny &ekran - + Show &debug statistics Pokaż &statystyki - + I&gnore illegal reads/writes I&gnoruj błędne odczyty/zapisy - + &Gamepad &Pad - + Run on loa&d Uruchom po &załadowaniu - + Show &FPS counter Pokaż licznik &FPS - + S&tretch to display &Rozciągnij obraz - + &Sound emulation &Emulacja dźwięku - + F12 F12 - + &Buffered Rendering &Buforowane renderowanie - + F5 F5 - + &Hardware Transform Sprzętowa &transformacja - + F6 F6 - + &Linear Filtering Filtrowanie &liniowe - + &Wireframe (experimental) &Widok siatki (eksperymentalny) - + &Display Raw Framebuffer Wyświetl &surowy framebuffer - + Screen &1x &1x - + Ctrl+1 Ctrl+1 - + Screen &2x &2x - + Ctrl+2 Ctrl+2 - + Screen &3x &3x - + Ctrl+3 Ctrl+3 - + Screen &4x &4x - + Ctrl+4 Ctrl+4 - + &Fast Memory (dynarec, unstable) S&zybka pamięć (wymagany Dynarec, niestabilne) - + &Go to http://www.ppsspp.org/ &Idź do http://www.ppsspp.org - + &About PPSSPP... &O PPSSPP... - + &Use VBO Użyj &VBO - - - + + + Debug Debug - - - + + + Warning Ostrzeżenia - - - + + + Error Błędy - - - + + + Info Info - + D&ump next frame to log Z&rzuć następną ramkę do logu - + &Vertex Cache &Cache wierzchołków - + Memory View Texture... - + + DisplayList... + + + + Simple 2xAA Prosty antyaliasing 2x - + Off Wyłączone - + 2x 2x - + 4x 4x - + 8x 8x - + 16x 16x - + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + No translations Brak tłumaczeń diff --git a/Qt/languages/ppsspp_pt-br.ts b/Qt/languages/ppsspp_pt-br.ts new file mode 100644 index 0000000000..f9971b8803 --- /dev/null +++ b/Qt/languages/ppsspp_pt-br.ts @@ -0,0 +1,1330 @@ + + + + + Controls + + + Controls + Controls window title + Controles + + + + CtrlDisAsmView + + + Copy &address + Copiar &endereço + + + + Copy instruction (&hex) + Copiar instrução (&hex) + + + + Copy instruction (&disasm) + Copiar instrução (&disam) + + + + &Run to here + &Rodar aqui + + + + &Set Next Statement + + + + + &Toggle breakpoint + &Ativar breakpoint + + + + &Follow branch + &Seguir caminho + + + + Go to in &Memory View + Vá para o Visualizador de &Memória + + + + &Rename function... + &Renomear função... + + + + New function name + Novo nome de função + + + + New function name: + Novo nome de função: + + + + Warning + Atenção + + + + No symbol selected + + + + + CtrlMemView + + + Go to in &disasm + Vá para &disasm + + + + &Copy value + &Copiar valor + + + + C&hange value + + + + + Dump... + Despejar... + + + + Set new value + Setar novo valor + + + + Set new value: + Setar novo valor: + + + + CtrlRegisterList + + + Go to in &memory view + Vá para o visualizador de &memória + + + + Go to in &disasm + Vá para o &disasm + + + + &Copy value + &Copiar valor + + + + C&hange... + &Trocar... + + + + Set new value + Setar novo valor + + + + Set new value: + Setar novo valor: + + + + Debugger_Disasm + + + Disassembler + Window title + + + + + Ctr: + + + + + &Go to + &Vá para + + + + &PC + + + + + &LR + + + + + Show VFPU + Mostrar VFPU + + + + Regs + + + + + Funcs + + + + + &Go + &Ir + + + + Stop + Parar + + + + Step &Into + + + + + Step &Over + + + + + S&kip + P&ular + + + + Next &HLE + Próximo &HLE + + + + Breakpoints + + + + + Address + Endereços + + + + Clear All + Limpar Tudo + + + + Callstack + + + + + Display Lists + Mostrar Listas + + + + + Id + + + + + + Status + Estado + + + + Start Address + Endereço inicial + + + + Current Address + Endereço atual + + + Run + Rodar + + + Step + Passo + + + + Threads + + + + + Name + Nome + + + + Current PC + PC corrente + + + + Entry point + Ponto de entrada + + + + Remove breakpoint + Remover breakpoint + + + + Go to entry point + Ir para ponto de entrada + + + + Change status + + + + + Running + Rodando + + + + Wait + Esperando + + + + Suspend + Suspenso + + + Show code + Mostrar código + + + + Debugger_DisplayList + + + Dialog + Diálogo + + + + DisplayList + + + + + Id + + + + + Status + Estado + + + + Start Address + Endereço inicial + + + + Current Address + Endereço atual + + + + Run + Rodar + + + + Stop + Parar + + + + Next DL + + + + + Commands + + + + + Step + Passo + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + Endereços + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + + + + + Debugger_Memory + + + Dialog + Diálogo + + + + Goto: + Vá para: + + + + Mode + Modo + + + + Normal + + + + + Symbols + Símbolos + + + + Memory Viewer - %1 + Visualizador de Memória - %1 + + + + Debugger_MemoryTex + + + Dialog + Diálogo + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + + + Debugger_VFPU + + + VFPU + + + + + Float + + + + + HalfFloat + + + + + Hex + + + + + Bytes + + + + + Shorts + + + + + Ints + + + + + GamePadDialog + + + Gamepad Configuration + Configuração do Gamepad + + + + GamePad List + Lista de Gamepads + + + + Refresh + Atualizar + + + + Select + Selecionar + + + + Gamepad Values : + Valores de Gamepad : + + + + TextLabel + + + + + Assign Gamepad input + Atribuir entrada do Gamepad + + + + to PSP button/axis + para o botão/eixo do PSP + + + + Assign + Atribuir + + + + Press buttons on your gamePad to verify mapping : + Pressione botões no seu Gamepad para verificar o mapeamento : + + + + + <b>No gamepad</b> + Sem Gamepad + + + + <b>Unknown gamepad</b> + Gamepad desconhecido + + + + Buttons + Botões + + + + + Button %1 + Botões %1 + + + + Axes + Eixos + + + + %1 Neg + + + + + Axes %1 Neg + Eixos %1 Neg + + + + %1 Pos + + + + + Axes %1 Pos + Eixos %1 Pos + + + + Hats + + + + + <b>Current gamepad: %1</b> + <b>Gamepad atual: %1</b> + + + + MainWindow + + + PPSSPP + + + + + &File + &Arquivo + + + + &Emulation + &Emulação + + + + Debu&g + + + + + &Options + &Opções + + + + G3D + + + + + HLE + + + + + Default + Padrão + + + + Lo&g Levels + Nível de Lo&g + + + + &Language + &Linguagem + + + + &Video + &Vídeo + + + + &Anisotropic filtering + Filtragem &Anisotrópica + + + + &Zoom + + + + + Co&ntrols + Co&ntroles + + + + &Core + &Núcleo + + + + &Help + Aj&uda + + + + &Open... + &Abrir... + + + + &Close + &Fechar + + + + - + + + + + Quickload state + Carregar estado rápido + + + + F4 + + + + + Quicksave state + Salvar estado rápido + + + + F2 + + + + + &Load State File... + &Carregar estado do arquivo... + + + + &Save State File... + &Salvar estado no arquivo... + + + + E&xit + Sai&r + + + + &Run + &Rodar + + + + F7 + + + + + &Pause + &Pausar + + + + F8 + + + + + R&eset + R&esetar + + + + &Interpreter + &Interpretador + + + &Slightly Faster Interpreter + Interpretador um &pouco mais rápido + + + + &Dynarec + Recompilador &dinâmico + + + + Load &Map File... + Carregar &mapa do arquivo... + + + + &Save Map File... + &Salvar mapa no arquivo... + + + + &Reset Symbol Table + &Reiniciar tabela de símbolos + + + + &Disassembly + + + + + Ctrl+D + L + + + + &Log Console + Console de &Logs + + + + Ctrl+L + L + + + + Memory &View... + &Visualizador de Memória... + + + + Ctrl+M + + + + + &Keyboard + &Teclado + + + + &Toggle fullscreen + Tela &cheia + + + + Show &debug statistics + Mostrar estatísticas de &debug + + + + I&gnore illegal reads/writes + I&gnorar leituras/escritas ilegais + + + + &Gamepad + + + + + Run on loa&d + Rodar ao &abrir + + + + Show &FPS counter + Mostrar contador de &FPS + + + + S&tretch to display + Es&ticar tela + + + + &Sound emulation + Emular &som + + + + F12 + + + + + &Buffered Rendering + Renderização com &buffer + + + + F5 + + + + + &Hardware Transform + Transformação em &Hardware + + + + F6 + + + + + &Linear Filtering + Filtragem &Linear + + + + &Wireframe (experimental) + &Wireframe (experimental) + + + + &Display Raw Framebuffer + Mostrar framebuffer &bruto + + + + Screen &1x + &1x Tela + + + + Ctrl+1 + + + + + Screen &2x + &2x Tela + + + + Ctrl+2 + + + + + Screen &3x + &3x Tela + + + + Ctrl+3 + + + + + Screen &4x + &4x Tela + + + + Ctrl+4 + + + + + &Fast Memory (dynarec, unstable) + Memória &rápida (recompilador dinâmico, instável) + + + + &Go to http://www.ppsspp.org/ + &Ir para http://www.ppsspp.org/ + + + + &About PPSSPP... + &Sobre o PPSSPP... + + + + &Use VBO + &Usar VBO + + + + + + Debug + + + + + + + Warning + Atenção + + + + + + Error + Erro + + + + + + Info + Informação + + + + D&ump next frame to log + D&espejar o próximo frame no log + + + + &Vertex Cache + Cache de &Vértices + + + + Memory View Texture... + Ver texturas na memória... + + + + DisplayList... + + + + + Simple 2xAA + Simples 2xAA + + + + Off + Desligar + + + + 2x + + + + + 4x + + + + + 8x + + + + + 16x + + + + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + + No translations + Sem tradução + + + + gamepadMapping + + + Cross + X + + + + Circle + Círculo + + + + Square + Quadrado + + + + Triangle + Triângulo + + + + Left Trigger + Gatilho Esquerdo + + + + Right Trigger + Gatilho Direito + + + + Start + + + + + Select + + + + + Up + Cima + + + + Down + Baixo + + + + Left + Esquerda + + + + Right + Direita + + + + Home + + + + + Stick left + Analógico Esquerda + + + + Stick right + Analógico Direita + + + + Stick up + Analógico Cima + + + + Stick bottom + Analógico Baixo + + + diff --git a/Qt/languages/ppsspp_ru.ts b/Qt/languages/ppsspp_ru.ts new file mode 100644 index 0000000000..f50a92782a --- /dev/null +++ b/Qt/languages/ppsspp_ru.ts @@ -0,0 +1,1318 @@ + + + + + Controls + + + Controls + Controls window title + Управление + + + + CtrlDisAsmView + + + Copy &address + + + + + Copy instruction (&hex) + + + + + Copy instruction (&disasm) + + + + + &Run to here + + + + + &Set Next Statement + + + + + &Toggle breakpoint + + + + + &Follow branch + + + + + Go to in &Memory View + + + + + &Rename function... + + + + + New function name + + + + + New function name: + + + + + Warning + + + + + No symbol selected + + + + + CtrlMemView + + + Go to in &disasm + + + + + &Copy value + + + + + C&hange value + + + + + Dump... + + + + + Set new value + + + + + Set new value: + + + + + CtrlRegisterList + + + Go to in &memory view + + + + + Go to in &disasm + + + + + &Copy value + + + + + C&hange... + + + + + Set new value + + + + + Set new value: + + + + + Debugger_Disasm + + + Disassembler + Window title + + + + + Ctr: + + + + + &Go to + + + + + &PC + + + + + &LR + + + + + Show VFPU + + + + + Regs + + + + + Funcs + + + + + &Go + + + + + Stop + + + + + Step &Into + + + + + Step &Over + + + + + S&kip + + + + + Next &HLE + + + + + Breakpoints + + + + + Address + + + + + Clear All + + + + + Callstack + + + + + Display Lists + + + + + + Id + + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Threads + + + + + Name + + + + + Current PC + + + + + Entry point + + + + + Remove breakpoint + + + + + Go to entry point + + + + + Change status + + + + + Running + + + + + Wait + + + + + Suspend + + + + + Debugger_DisplayList + + + Dialog + + + + + DisplayList + + + + + Id + + + + + Status + + + + + Start Address + + + + + Current Address + + + + + Run + + + + + Stop + + + + + Next DL + + + + + Commands + + + + + Step + + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + + + + + Debugger_Memory + + + Dialog + + + + + Goto: + + + + + Mode + + + + + Normal + + + + + Symbols + + + + + Memory Viewer - %1 + + + + + Debugger_MemoryTex + + + Dialog + + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + + + Debugger_VFPU + + + VFPU + + + + + Float + + + + + HalfFloat + + + + + Hex + + + + + Bytes + + + + + Shorts + + + + + Ints + + + + + GamePadDialog + + + Gamepad Configuration + Настройка геймпада + + + + GamePad List + Список геймпадов + + + + Refresh + Обновить + + + + Select + Выбрать + + + + Gamepad Values : + Значения геймпадов : + + + + TextLabel + + + + + Assign Gamepad input + Выбрать ввод геймпада + + + + to PSP button/axis + для кнопок PSP + + + + Assign + Выбрать + + + + Press buttons on your gamePad to verify mapping : + Нажмите кнопки для проверки геймпада : + + + + + <b>No gamepad</b> + <b>Геймпад не найден</b> + + + + <b>Unknown gamepad</b> + <b>Неизвестный геймпад</b> + + + + Buttons + Кнопки + + + + + Button %1 + Кнопка %1 + + + + Axes + Оси + + + + %1 Neg + %1 отрицательно + + + + Axes %1 Neg + Ось %1 отрицательна + + + + %1 Pos + %1 положительно + + + + Axes %1 Pos + Ось %1 положительна + + + + Hats + + + + + <b>Current gamepad: %1</b> + <b>Текущий геймпад: %1</b> + + + + MainWindow + + + PPSSPP + PPSSPP + + + + &File + &Файл + + + + &Emulation + &Эмуляция + + + + Debu&g + &Отладка + + + + &Options + &Настройки + + + + G3D + G3D + + + + HLE + HLE + + + + Default + По умолчанию + + + + Lo&g Levels + Уровень ло&гирования + + + + &Language + &Язык + + + + &Video + &Видео + + + + &Anisotropic filtering + &Анизотропная фильтрация + + + + &Zoom + &Экран + + + + Co&ntrols + У&правление + + + + &Core + &Ядро + + + + &Help + &Помощь + + + + &Open... + &Открыть... + + + + &Close + &Закрыть + + + + - + - + + + + Quickload state + Быстро загрузить состояние + + + + F4 + F4 + + + + Quicksave state + Быстро сохранить состояние + + + + F2 + F2 + + + + &Load State File... + &Открыть файл состояния... + + + + &Save State File... + &Сохранить файл состояния... + + + + E&xit + В&ыход + + + + &Run + &Запустить + + + + F7 + F7 + + + + &Pause + &Пауза + + + + F8 + F8 + + + + R&eset + Пере&загрузить + + + + &Interpreter + &Интерпретатор + + + &Slightly Faster Interpreter + &etwas scnellerer Interpreter + + + + &Dynarec + &Dynarec + + + + Load &Map File... + Загрузить файл &карты... + + + + &Save Map File... + &Сохранить файл карты... + + + + &Reset Symbol Table + &Сбросить таблицу символов + + + + &Disassembly + &Деасэмблинг + + + + Ctrl+D + Ctrl+D + + + + &Log Console + &Консоль логов + + + + Ctrl+L + Ctrl+L + + + + Memory &View... + &Отображение памяти... + + + + Ctrl+M + Ctrl+M + + + + &Keyboard + &Клавиатура + + + + &Toggle fullscreen + &Полный экран + + + + Show &debug statistics + Показывать &отладочную информацию + + + + I&gnore illegal reads/writes + &Игнорировать неправильные чтения/запись + + + + &Gamepad + &Геймпад + + + + Run on loa&d + Запускать при &загрузке + + + + Show &FPS counter + Показывать &FPS + + + + S&tretch to display + За&стягивать под экран + + + + &Sound emulation + Эмуляция &звука + + + + F12 + F12 + + + + &Buffered Rendering + &Буферированный рендеринг + + + + F5 + F5 + + + + &Hardware Transform + &Аппаратное преобразование + + + + F6 + F6 + + + + &Linear Filtering + &Линейная фильтрация + + + + &Wireframe (experimental) + &Отображать каркас (экспериментально) + + + + &Display Raw Framebuffer + &Отображать буфер кадров + + + + Screen &1x + Увеличить &1x + + + + Ctrl+1 + Ctrl+1 + + + + Screen &2x + Увеличить &2x + + + + Ctrl+2 + Ctrl+2 + + + + Screen &3x + Увеличить &3x + + + + Ctrl+3 + Ctrl+3 + + + + Screen &4x + Увеличить &4x + + + + Ctrl+4 + Ctrl+4 + + + + &Fast Memory (dynarec, unstable) + &Быстрая память (dynarec, нестабильно) + + + + &Go to http://www.ppsspp.org/ + &Веб сайт http://www.ppsspp.org + + + + &About PPSSPP... + &О PPSSPP... + + + + &Use VBO + &Использовать VBO + + + + + + Debug + Отладка + + + + + + Warning + Предупреждение + + + + + + Error + Ошибка + + + + + + Info + Информация + + + + D&ump next frame to log + С&бросить следующий кадр в лог + + + + &Vertex Cache + &Vertex кэш + + + + Memory View Texture... + Память отображаемых текстур... + + + + DisplayList... + Список экранов... + + + + Simple 2xAA + Простое 2x сглаживание + + + + Off + Выключено + + + + 2x + 2x + + + + 4x + 4x + + + + 8x + 8x + + + + 16x + 16x + + + + Frameskip + Пропуск кадров + + + + Gamepad + Геймпад + + + + You need to compile with SDL to have Gamepad support. + Вам нужно скомпилировать с SDL чтобы иметь поддержку геймпада. + + + + No translations + Нет перевода + + + + gamepadMapping + + + Cross + Крест + + + + Circle + Круг + + + + Square + Квадрат + + + + Triangle + Треугольник + + + + Left Trigger + Левый курок + + + + Right Trigger + Правый курок + + + + Start + Старт + + + + Select + Выбор + + + + Up + Вверх + + + + Down + Вниз + + + + Left + Влево + + + + Right + Вправо + + + + Home + Домой + + + + Stick left + Стик влево + + + + Stick right + Стик вправо + + + + Stick up + Стик вверх + + + + Stick bottom + Стик вниз + + + diff --git a/Qt/languages/ppsspp_tc.ts b/Qt/languages/ppsspp_tc.ts index 8b4520c1a0..3cedf5b27d 100644 --- a/Qt/languages/ppsspp_tc.ts +++ b/Qt/languages/ppsspp_tc.ts @@ -1,1014 +1,1331 @@ - - - - - Controls - - - Controls - Controls window title - 控制器 - - - - CtrlDisAsmView - - - Copy &address - (&A)複製地址 - - - - Copy instruction (&hex) - (&H)複製指令(十六進制型) - - - - Copy instruction (&disasm) - (&D)複製指令(彙編型) - - - - &Run to here - (&R)執行到此處 - - - - &Set Next Statement - (&S)設置下一語句 - - - - &Toggle breakpoint - (&T)鎖定斷點 - - - - &Follow branch - (&F)跟隨分支 - - - - Go to in &Memory View - (&M)轉到內存視圖 - - - - &Rename function... - (&R)重命名函數... - - - - New function name - 新函數名稱 - - - - New function name: - 新函數名稱: - - - - CtrlMemView - - - Go to in &disasm - (&D)轉到彙編視圖 - - - - &Copy value - (&C)複製值 - - - - Dump... - 轉儲... - - - - CtrlRegisterList - - - Go to in &memory view - (&M)轉到內存視圖 - - - - Go to in &disasm - (&D)轉到彙編視圖 - - - - &Copy value - (&C)複製值 - - - - C&hange... - (&H)更改... - - - - Set new value - 設置新值 - - - - Set new value: - 設置新值: - - - - Debugger_Disasm - - - Disassembler - Window title - 反彙編器 - - - - Ctr: - 計數器: - - - - &Go to - (&G)轉到 - - - - &PC - (&P)PC寄存器 - - - - &LR - (&L)連接寄存器 - - - - Show VFPU - 顯示VFPU - - - - Regs - 寄存器 - - - - Funcs - 函數 - - - - &Go - (&G)轉到 - - - - Stop - 停止 - - - - Step &Into - (&I)單步跟進 - - - - Step &Over - (&O)單步步過 - - - - S&kip - (&K)跳過 - - - - Next &HLE - (&H)下一HLE - - - - Breakpoints - 斷點 - - - - Address - 地址 - - - - Clear All - 清空所有 - - - - Callstack - 調用棧 - - - - Display Lists - 顯示列表 - - - - - Id - Id - - - - - Status - 狀態 - - - - Start Address - 起始地址 - - - - Current Address - 當前地址 - - - - Run - 執行 - - - - Step - 單步執行 - - - - Threads - 線程 - - - - Name - 名稱 - - - - Current PC - 當前PC寄存器 - - - - Entry point - 入口點 - - - - Remove breakpoint - 移除斷點 - - - - Go to entry point - 轉到入口點 - - - - Running - 執行中 - - - - Wait - 等待 - - - - Suspend - 掛起 - - - - Show code - 顯示代碼 - - - - Debugger_Memory - - - Dialog - 對話框 - - - - Goto: - 轉到: - - - - Mode - 模式 - - - - Normal - 普通模式 - - - - Symbols - 特徵符模式 - - - - Memory Viewer - %1 - 內存查看器 - %1 - - - - Debugger_VFPU - - - VFPU - VFPU - - - - Float - 浮點型 - - - - HalfFloat - 半浮點型 - - - - Hex - 十六進制型 - - - - Bytes - 字節型 - - - - Shorts - 短整型 - - - - Ints - 整型 - - - - GamePadDialog - - - Gamepad Configuration - 手柄設置 - - - - GamePad List - 手柄列表 - - - - Refresh - 刷新 - - - - Select - 選中 - - - - Gamepad Values : - 手柄值: - - - - TextLabel - TextLabel - TextLabel - - - - Assign Gamepad input - 指定該手柄 - - - - to PSP button/axis - 作為PSP按鍵/搖桿輸入 - - - - Assign - 指定 - - - - Press buttons on your gamePad to verify mapping : - 按下手柄按鍵來確認鍵位映射: - - - - - <b>No gamepad</b> - <b>未發現手柄</b> - - - - <b>Unknown gamepad</b> - <b>未識別的手柄</b> - - - - Buttons - 按鈕 - - - - - Button %1 - 按鈕 %1 - - - - Axes - 搖桿 - - - - %1 Neg - %1 Neg - - - - Axes %1 Neg - Axes %1 Neg - - - - %1 Pos - %1 Pos - - - - Axes %1 Pos - Axes %1 Pos - - - - Hats - Hats - - - - <b>Current gamepad: %1</b> - <b>當前手柄: %1</b> - - - - MainWindow - - - PPSSPP - PPSSPP - - - - &File - (&F)文件 - - - - &Emulation - (&E)模擬 - - - - Debu&g - (&G)調試 - - - - &Options - (&O)選項 - - - - G3D - - - - - HLE - - - - - Default - 默認 - - - - Lo&g Levels - (&G)日誌級別 - - - - &Language - (&L)語言選擇 - - - - &Video - (&V)視頻 - - - - &Anisotropic filtering - (&A)各向異性過濾 - - - - &Zoom - (&Z)縮放 - - - - Co&ntrols - (&N)控制 - - - - &Core - (&C)核心 - - - - &Help - (&H)幫助 - - - - &Open... - (&O)打開... - - - - &Close - (&C)關閉 - - - - - - - - - - - Quickload state - 快速讀檔 - - - - F4 - F4 - - - - Quicksave state - 快速存檔 - - - - F2 - F2 - - - - &Load State File... - (&L)讀取存檔... - - - - &Save State File... - (&S)保存存檔... - - - - E&xit - (&X)退出 - - - - &Run - (&R)運行 - - - - F7 - F7 - - - - &Pause - (&P)暫停 - - - - F8 - F8 - - - - R&eset - (&E)重置 - - - - &Interpreter - (&I)解釋器 - - - - &Slightly Faster Interpreter - (&S)較快的解釋器 - - - - &Dynarec - (&D)動態重編譯 - - - - Load &Map File... - (&M)讀取Map文件... - - - - &Save Map File... - (&S)保存Map文件... - - - - &Reset Symbol Table - (&R)重置符號表 - - - - &Disassembly - (&D)彙編視圖 - - - - Ctrl+D - Ctrl+D - - - - &Log Console - (&L)查看控制台日誌 - - - - Ctrl+L - Ctrl+L - - - - Memory &View... - (&V)內存視圖... - - - - Ctrl+M - Ctrl+M - - - - &Keyboard - (&K)鍵盤 - - - - &Toggle fullscreen - (&T)全屏 - - - - Show &debug statistics - (&D)顯示調試信息 - - - - I&gnore illegal reads/writes - (&G)忽略非法讀寫 - - - - &Gamepad - (&G)手柄 - - - - Run on loa&d - (&D)載入時運行 - - - - Show &FPS counter - (&F)顯示幀率計數器 - - - - S&tretch to display - (&T)拉伸顯示 - - - - &Sound emulation - (&S)模擬聲音 - - - - F12 - F12 - - - - &Buffered Rendering - (&B)渲染緩衝 - - - - F5 - F5 - - - - &Hardware Transform - (&H)硬件加速 - - - - F6 - F6 - - - - &Linear Filtering - (&L)線性過濾 - - - - &Wireframe (experimental) - (&W)使用線框 (實驗性選項) - - - - &Display Raw Framebuffer - (&D)顯示 Raw 原始緩衝 - - - - Screen &1x - &1倍窗口 - - - - Ctrl+1 - Ctrl+1 - - - - Screen &2x - &2倍窗口 - - - - Ctrl+2 - Ctrl+2 - - - - Screen &3x - &3倍窗口 - - - - Ctrl+3 - Ctrl+3 - - - - Screen &4x - &4倍窗口 - - - - Ctrl+4 - Ctrl+4 - - - - &Fast Memory (dynarec, unstable) - (&F)高速閃存 (動態重編譯,不穩定) - - - - &Go to http://www.ppsspp.org/ - (&G)轉到 http://www.ppsspp.org/ - - - - &About PPSSPP... - (&A)關於 PPSSPP... - - - - &Use VBO - (&U)使用 VBO - - - - - - Debug - 調試 - - - - - - Warning - 警告 - - - - - - Error - 錯誤 - - - - - - Info - 信息 - - - - D&ump next frame to log - (&U)將下一幀轉儲至日誌 - - - - &Vertex Cache - (&V)頂點緩存 - - - - Memory View Texture... - 內存紋理視圖... - - - - Simple 2xAA - - - - - Off - 關閉 - - - - 2x - 2x - - - - 4x - 4x - - - - 8x - 8x - - - - 16x - 16x - - - - No translations - 未翻譯 - - - - gamepadMapping - - - Cross - × - - - - Circle - ○ - - - - Square - □ - - - - Triangle - △ - - - - Left Trigger - L - - - - Right Trigger - R - - - - Start - 開始 - - - - Select - 選擇 - - - - Up - ↑ - - - - Down - ↓ - - - - Left - ← - - - - Right - → - - - - Home - Home - - - - Stick left - 搖桿左 - - - - Stick right - 搖桿右 - - - - Stick up - 搖桿上 - - - - Stick bottom - 搖桿下 - - - + + + + + Controls + + + Controls + Controls window title + 控制器 + + + + CtrlDisAsmView + + + Copy &address + (&A)複製地址 + + + + Copy instruction (&hex) + (&H)複製指令(十六進制型) + + + + Copy instruction (&disasm) + (&D)複製指令(彙編型) + + + + &Run to here + (&R)執行到此處 + + + + &Set Next Statement + (&S)設置下一語句 + + + + &Toggle breakpoint + (&T)鎖定斷點 + + + + &Follow branch + (&F)跟隨分支 + + + + Go to in &Memory View + (&M)轉到內存視圖 + + + + &Rename function... + (&R)重命名函數... + + + + New function name + 新函數名稱 + + + + New function name: + 新函數名稱: + + + + Warning + 警告 + + + + No symbol selected + + + + + CtrlMemView + + + Go to in &disasm + (&D)轉到彙編視圖 + + + + &Copy value + (&C)複製值 + + + + C&hange value + + + + + Dump... + 轉儲... + + + + Set new value + 設置新值 + + + + Set new value: + 設置新值: + + + + CtrlRegisterList + + + Go to in &memory view + (&M)轉到內存視圖 + + + + Go to in &disasm + (&D)轉到彙編視圖 + + + + &Copy value + (&C)複製值 + + + + C&hange... + (&H)更改... + + + + Set new value + 設置新值 + + + + Set new value: + 設置新值: + + + + Debugger_Disasm + + + Disassembler + Window title + 反彙編器 + + + + Ctr: + 計數器: + + + + &Go to + (&G)轉到 + + + + &PC + (&P)PC寄存器 + + + + &LR + (&L)連接寄存器 + + + + Show VFPU + 顯示VFPU + + + + Regs + 寄存器 + + + + Funcs + 函數 + + + + &Go + (&G)轉到 + + + + Stop + 停止 + + + + Step &Into + (&I)單步跟進 + + + + Step &Over + (&O)單步步過 + + + + S&kip + (&K)跳過 + + + + Next &HLE + (&H)下一HLE + + + + Breakpoints + 斷點 + + + + Address + 地址 + + + + Clear All + 清空所有 + + + + Callstack + 調用棧 + + + + Display Lists + 顯示列表 + + + + + Id + Id + + + + + Status + 狀態 + + + + Start Address + 起始地址 + + + + Current Address + 當前地址 + + + Run + 執行 + + + Step + 單步執行 + + + + Threads + 線程 + + + + Name + 名稱 + + + + Current PC + 當前PC寄存器 + + + + Entry point + 入口點 + + + + Remove breakpoint + 移除斷點 + + + + Go to entry point + 轉到入口點 + + + + Change status + + + + + Running + 執行中 + + + + Wait + 等待 + + + + Suspend + 掛起 + + + Show code + 顯示代碼 + + + + Debugger_DisplayList + + + Dialog + 對話框 + + + + DisplayList + + + + + Id + Id + + + + Status + 狀態 + + + + Start Address + 起始地址 + + + + Current Address + 當前地址 + + + + Run + 執行 + + + + Stop + 停止 + + + + Next DL + + + + + Commands + + + + + Step + 單步執行 + + + + Next Draw + + + + + Goto PC + + + + + Textures + + + + + + Address + 地址 + + + + + Width + + + + + + Height + + + + + + Format + + + + + Vertex Buffer + + + + + Coord Type + + + + + Number Morph + + + + + Number Weights + + + + + Has Weight + + + + + Has Position + + + + + Has Normal + + + + + Has Color + + + + + Has UV + + + + + Values + + + + + + Next 20 + + + + + Index Buffer + + + + + Idx + + + + + Value + + + + + Framebuffer + + + + + VAddress + + + + + Display : + + + + + Color + + + + + Depth + + + + + Zoom- + + + + + Zoom+ + + + + + Run to here + + + + + Run to draw using this texture + + + + + Debugger_Memory + + + Dialog + 對話框 + + + + Goto: + 轉到: + + + + Mode + 模式 + + + + Normal + 普通模式 + + + + Symbols + 特徵符模式 + + + + Memory Viewer - %1 + 內存查看器 - %1 + + + + Debugger_MemoryTex + + + Dialog + 對話框 + + + + TexAddr + + + + + TexBufWidth0 + + + + + TexFormat + + + + + TexSize + + + + + ClutFormat + + + + + ClutAddr + + + + + ClutAddrUpper + + + + + LoadClut + + + + + TexMode + + + + + Read + + + + + Debugger_VFPU + + + VFPU + VFPU + + + + Float + 浮點型 + + + + HalfFloat + 半浮點型 + + + + Hex + 十六進制型 + + + + Bytes + 字節型 + + + + Shorts + 短整型 + + + + Ints + 整型 + + + + GamePadDialog + + + Gamepad Configuration + 手柄設置 + + + + GamePad List + 手柄列表 + + + + Refresh + 刷新 + + + + Select + 選中 + + + + Gamepad Values : + 手柄值: + + + + TextLabel + TextLabel + TextLabel + + + + Assign Gamepad input + 指定該手柄 + + + + to PSP button/axis + 作為PSP按鍵/搖桿輸入 + + + + Assign + 指定 + + + + Press buttons on your gamePad to verify mapping : + 按下手柄按鍵來確認鍵位映射: + + + + + <b>No gamepad</b> + <b>未發現手柄</b> + + + + <b>Unknown gamepad</b> + <b>未識別的手柄</b> + + + + Buttons + 按鈕 + + + + + Button %1 + 按鈕 %1 + + + + Axes + 搖桿 + + + + %1 Neg + %1 Neg + + + + Axes %1 Neg + Axes %1 Neg + + + + %1 Pos + %1 Pos + + + + Axes %1 Pos + Axes %1 Pos + + + + Hats + Hats + + + + <b>Current gamepad: %1</b> + <b>當前手柄: %1</b> + + + + MainWindow + + + PPSSPP + PPSSPP + + + + &File + (&F)文件 + + + + &Emulation + (&E)模擬 + + + + Debu&g + (&G)調試 + + + + &Options + (&O)選項 + + + + G3D + + + + + HLE + + + + + Default + 默認 + + + + Lo&g Levels + (&G)日誌級別 + + + + &Language + (&L)語言選擇 + + + + &Video + (&V)視頻 + + + + &Anisotropic filtering + (&A)各向異性過濾 + + + + &Zoom + (&Z)縮放 + + + + Co&ntrols + (&N)控制 + + + + &Core + (&C)核心 + + + + &Help + (&H)幫助 + + + + &Open... + (&O)打開... + + + + &Close + (&C)關閉 + + + + - + - + + + + Quickload state + 快速讀檔 + + + + F4 + F4 + + + + Quicksave state + 快速存檔 + + + + F2 + F2 + + + + &Load State File... + (&L)讀取存檔... + + + + &Save State File... + (&S)保存存檔... + + + + E&xit + (&X)退出 + + + + &Run + (&R)運行 + + + + F7 + F7 + + + + &Pause + (&P)暫停 + + + + F8 + F8 + + + + R&eset + (&E)重置 + + + + &Interpreter + (&I)解釋器 + + + &Slightly Faster Interpreter + (&S)較快的解釋器 + + + + &Dynarec + (&D)動態重編譯 + + + + Load &Map File... + (&M)讀取Map文件... + + + + &Save Map File... + (&S)保存Map文件... + + + + &Reset Symbol Table + (&R)重置符號表 + + + + &Disassembly + (&D)彙編視圖 + + + + Ctrl+D + Ctrl+D + + + + &Log Console + (&L)查看控制台日誌 + + + + Ctrl+L + Ctrl+L + + + + Memory &View... + (&V)內存視圖... + + + + Ctrl+M + Ctrl+M + + + + &Keyboard + (&K)鍵盤 + + + + &Toggle fullscreen + (&T)全屏 + + + + Show &debug statistics + (&D)顯示調試信息 + + + + I&gnore illegal reads/writes + (&G)忽略非法讀寫 + + + + &Gamepad + (&G)手柄 + + + + Run on loa&d + (&D)載入時運行 + + + + Show &FPS counter + (&F)顯示幀率計數器 + + + + S&tretch to display + (&T)拉伸顯示 + + + + &Sound emulation + (&S)模擬聲音 + + + + F12 + F12 + + + + &Buffered Rendering + (&B)渲染緩衝 + + + + F5 + F5 + + + + &Hardware Transform + (&H)硬件加速 + + + + F6 + F6 + + + + &Linear Filtering + (&L)線性過濾 + + + + &Wireframe (experimental) + (&W)使用線框 (實驗性選項) + + + + &Display Raw Framebuffer + (&D)顯示 Raw 原始緩衝 + + + + Screen &1x + &1倍窗口 + + + + Ctrl+1 + Ctrl+1 + + + + Screen &2x + &2倍窗口 + + + + Ctrl+2 + Ctrl+2 + + + + Screen &3x + &3倍窗口 + + + + Ctrl+3 + Ctrl+3 + + + + Screen &4x + &4倍窗口 + + + + Ctrl+4 + Ctrl+4 + + + + &Fast Memory (dynarec, unstable) + (&F)高速閃存 (動態重編譯,不穩定) + + + + &Go to http://www.ppsspp.org/ + (&G)轉到 http://www.ppsspp.org/ + + + + &About PPSSPP... + (&A)關於 PPSSPP... + + + + &Use VBO + (&U)使用 VBO + + + + + + Debug + 調試 + + + + + + Warning + 警告 + + + + + + Error + 錯誤 + + + + + + Info + 信息 + + + + D&ump next frame to log + (&U)將下一幀轉儲至日誌 + + + + &Vertex Cache + (&V)頂點緩存 + + + + Memory View Texture... + 內存紋理視圖... + + + + DisplayList... + + + + + Simple 2xAA + + + + + Off + 關閉 + + + + 2x + 2x + + + + 4x + 4x + + + + 8x + 8x + + + + 16x + 16x + + + + Frameskip + + + + + Gamepad + + + + + You need to compile with SDL to have Gamepad support. + + + + + No translations + 未翻譯 + + + + gamepadMapping + + + Cross + × + + + + Circle + ○ + + + + Square + □ + + + + Triangle + △ + + + + Left Trigger + L + + + + Right Trigger + R + + + + Start + 開始 + + + + Select + 選擇 + + + + Up + ↑ + + + + Down + ↓ + + + + Left + ← + + + + Right + → + + + + Home + Home + + + + Stick left + 搖桿左 + + + + Stick right + 搖桿右 + + + + Stick up + 搖桿上 + + + + Stick bottom + 搖桿下 + + + diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index a7e08e35f9..f4a2bfa713 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -204,6 +204,7 @@ void MainWindow::UpdateMenus() ui->action_FileQuickSaveState->setEnabled(!enable); ui->action_CPUDynarec->setEnabled(enable); ui->action_CPUInterpreter->setEnabled(enable); + ui->actionUse_MediaEngine->setEnabled(enable); ui->action_DebugDumpFrame->setEnabled(!enable); ui->action_DebugDisassembly->setEnabled(!enable); ui->action_DebugMemoryView->setEnabled(!enable); @@ -222,6 +223,7 @@ void MainWindow::UpdateMenus() ui->action_CPUDynarec->setChecked(g_Config.bJit); ui->action_OptionsFastMemory->setChecked(g_Config.bFastMemory); ui->action_OptionsIgnoreIllegalReadsWrites->setChecked(g_Config.bIgnoreBadMemAccess); + ui->actionUse_MediaEngine->setChecked(g_Config.bUseMediaEngine); ui->action_AFOff->setChecked(g_Config.iAnisotropyLevel == 0); ui->action_AF2x->setChecked(g_Config.iAnisotropyLevel == 2); @@ -244,7 +246,7 @@ void MainWindow::UpdateMenus() ui->action_OptionsVertexCache->setChecked(g_Config.bVertexCache); ui->action_OptionsWireframe->setChecked(g_Config.bDrawWireframe); ui->action_OptionsDisplayRawFramebuffer->setChecked(g_Config.bDisplayFramebuffer); -// ui->actionFrameskip->setChecked(g_Config.iFrameSkip != 0); + ui->actionFrameskip->setChecked(g_Config.iFrameSkip != 0); ui->action_Sound->setChecked(g_Config.bEnableSound); @@ -558,6 +560,12 @@ void MainWindow::on_action_OptionsIgnoreIllegalReadsWrites_triggered() UpdateMenus(); } +void MainWindow::on_actionUse_MediaEngine_triggered() +{ + g_Config.bUseMediaEngine = !g_Config.bUseMediaEngine; + UpdateMenus(); +} + void MainWindow::on_action_OptionsControls_triggered() { controls->show(); @@ -684,7 +692,7 @@ void MainWindow::on_action_OptionsDisplayRawFramebuffer_triggered() void MainWindow::on_actionFrameskip_triggered() { -// g_Config.iFrameSkip = !g_Config.iFrameSkip; + g_Config.iFrameSkip = !g_Config.iFrameSkip; UpdateMenus(); } @@ -884,7 +892,7 @@ void MainWindow::SetZoom(float zoom) { void MainWindow::SetGameTitle(QString text) { - QString title = "PPSSPP " + QString(PPSSPP_VERSION_STR); + QString title = "PPSSPP " + QString(PPSSPP_GIT_VERSION); if (text != "") title += QString(" - %1").arg(text); diff --git a/Qt/mainwindow.h b/Qt/mainwindow.h index cb0af14bb0..059758f978 100644 --- a/Qt/mainwindow.h +++ b/Qt/mainwindow.h @@ -79,6 +79,7 @@ private slots: void on_action_CPUInterpreter_triggered(); void on_action_OptionsFastMemory_triggered(); void on_action_OptionsIgnoreIllegalReadsWrites_triggered(); + void on_actionUse_MediaEngine_triggered(); // Controls void on_action_OptionsControls_triggered(); diff --git a/Qt/mainwindow.ui b/Qt/mainwindow.ui index 6cabbd9838..5fd6cdf61c 100644 --- a/Qt/mainwindow.ui +++ b/Qt/mainwindow.ui @@ -30,7 +30,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -187,6 +196,8 @@ + + @@ -704,6 +715,14 @@ Frameskip + + + true + + + Use MediaEngine + + diff --git a/Qt/resources.qrc b/Qt/resources.qrc index 1eee7d4c45..0385010eed 100644 --- a/Qt/resources.qrc +++ b/Qt/resources.qrc @@ -24,5 +24,8 @@ languages/ppsspp_pl.qm languages/ppsspp_de.qm languages/ppsspp_tc.qm + languages/ppsspp_pt-br.qm + languages/ppsspp_id.qm + languages/ppsspp_ru.qm diff --git a/Windows/Debugger/Debugger_Disasm.cpp b/Windows/Debugger/Debugger_Disasm.cpp index 7f0d044c5d..c27d2f09b2 100644 --- a/Windows/Debugger/Debugger_Disasm.cpp +++ b/Windows/Debugger/Debugger_Disasm.cpp @@ -2,6 +2,7 @@ #include "../../Core/MemMap.h" #include "../Resource.h" +#include "../InputBox.h" #include "../../Core/Debugger/Breakpoints.h" #include "../../Core/Debugger/SymbolMap.h" @@ -234,6 +235,37 @@ BOOL CDisasm::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) } break; + case IDC_MEMCHECK: + { + bool isRunning = !Core_IsInactive(); + if (isRunning) + { + SetDebugMode(true); + Core_EnableStepping(true); + Core_WaitInactive(200); + } + + MemCheck check; + if (InputBox_GetHex(GetModuleHandle(NULL), m_hDlg, "JIT (and not HLE) only for now, no delete", 0, check.iStartAddress)) + { + check.bBreak = true; + check.bLog = true; + check.bOnRead = true; + check.bOnWrite = true; + check.bRange = false; + CBreakPoints::MemChecks.push_back(check); + CBreakPoints::InvalidateJit(); + } + + if (isRunning) + { + SetDebugMode(false); + Core_EnableStepping(false); + MainWindow::UpdateMenus(); + } + } + break; + case IDC_ADDRESS: { if (HIWORD(wParam) == EN_CHANGE ) diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index ac7e4fc153..88c0eb20a4 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -2,6 +2,7 @@ #include "base/threadutil.h" #include "Log.h" +#include "StringUtil.h" #include "../Globals.h" #include "EmuThread.h" #include "../Core/MemMap.h" @@ -53,18 +54,25 @@ char *GetCurrentFilename() return fileToStart; } -DWORD TheThread(LPVOID x) -{ +DWORD TheThread(LPVOID x) { setCurrentThreadName("EmuThread"); g_State.bEmuThreadStarted = true; + CoreParameter coreParameter; + host->UpdateUI(); - host->InitGL(); + + std::string error_string; + if (!host->InitGL(&error_string)) { + std::string full_error = StringFromFormat( "Failed initializing OpenGL. Try upgrading your graphics drivers.\n\nError message:\n\n%s", error_string.c_str()); + MessageBoxA(0, full_error.c_str(), "OpenGL Error", MB_OK | MB_ICONERROR); + ERROR_LOG(BOOT, full_error.c_str()); + goto shutdown; + } INFO_LOG(BOOT, "Starting up hardware."); - CoreParameter coreParameter; coreParameter.fileToStart = fileToStart; coreParameter.enableSound = true; coreParameter.gpuCore = GPU_GLES; @@ -79,10 +87,9 @@ DWORD TheThread(LPVOID x) coreParameter.pixelWidth = 480 * g_Config.iWindowZoom; coreParameter.pixelHeight = 272 * g_Config.iWindowZoom; coreParameter.startPaused = !g_Config.bAutoRun; - coreParameter.disableG3Dlog = g_Config.bDisableG3DLog; coreParameter.useMediaEngine = false; - std::string error_string; + error_string = ""; if (!PSP_Init(coreParameter, &error_string)) { ERROR_LOG(BOOT, "Error loading: %s", error_string.c_str()); diff --git a/Windows/Log.bat b/Windows/Log.bat new file mode 100644 index 0000000000..ff714ca190 --- /dev/null +++ b/Windows/Log.bat @@ -0,0 +1,5 @@ +@echo off +IF Not exist .\User md .\User +IF Not exist .\User\Logs md .\User\Logs +If exist .\User\Logs\ppsspp.log Del .\User\Logs\ppsspp.log +PPSSPPWindows.exe \ No newline at end of file diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index 92d4af4c14..a1e5fdf62b 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -30,37 +30,32 @@ void setVSync(int interval=1) wglSwapIntervalEXT(interval); } -void GL_Resized() // Resize And Initialize The GL Window -{ +// Resize And Initialize The GL Window +void GL_Resized() { if (!hWnd) return; RECT rc; GetWindowRect(hWnd,&rc); - xres=rc.right-rc.left; //account for border :P - yres=rc.bottom-rc.top; + xres = rc.right - rc.left; //account for border :P + yres = rc.bottom - rc.top; //swidth=width; // Set Scissor Width To Window Width //sheight=height; // Set Scissor Height To Window Height - if (yres==0) // Prevent A Divide By Zero By - { - yres=1; // Making Height Equal One - } + if (yres == 0) + yres = 1; glstate.viewport.set(0, 0, xres, yres); glstate.viewport.restore(); } -void GL_SwapBuffers() -{ +void GL_SwapBuffers() { SwapBuffers(hDC); } void FormatDebugOutputARB(char outStr[], size_t outStrSize, GLenum source, GLenum type, - GLuint id, GLenum severity, const char *msg) -{ + GLuint id, GLenum severity, const char *msg) { char sourceStr[32]; const char *sourceFmt = "UNDEFINED(0x%04X)"; - switch(source) - { + switch(source) { case GL_DEBUG_SOURCE_API_ARB: sourceFmt = "API"; break; case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: sourceFmt = "WINDOW_SYSTEM"; break; case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: sourceFmt = "SHADER_COMPILER"; break; @@ -72,8 +67,7 @@ void FormatDebugOutputARB(char outStr[], size_t outStrSize, GLenum source, GLenu char typeStr[32]; const char *typeFmt = "UNDEFINED(0x%04X)"; - switch(type) - { + switch(type) { case GL_DEBUG_TYPE_ERROR_ARB: typeFmt = "ERROR"; break; case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: typeFmt = "DEPRECATED_BEHAVIOR"; break; case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: typeFmt = "UNDEFINED_BEHAVIOR"; break; @@ -98,8 +92,7 @@ void FormatDebugOutputARB(char outStr[], size_t outStrSize, GLenum source, GLenu } void DebugCallbackARB(GLenum source, GLenum type, GLuint id, GLenum severity, - GLsizei length, const GLchar *message, GLvoid *userParam) -{ + GLsizei length, const GLchar *message, GLvoid *userParam) { (void)length; FILE *outFile = (FILE*)userParam; char finalMessage[256]; @@ -107,15 +100,13 @@ void DebugCallbackARB(GLenum source, GLenum type, GLuint id, GLenum severity, ERROR_LOG(HLE, "GL: %s", finalMessage); } -bool GL_Init(HWND window) -{ +bool GL_Init(HWND window, std::string *error_message) { + *error_message = "ok"; hWnd = window; - GLuint PixelFormat; // Holds The Results After Searching For A Match + GLuint PixelFormat; - hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window - - static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be - { + hInstance = GetModuleHandle(NULL); + static const PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window @@ -127,65 +118,68 @@ bool GL_Init(HWND window) 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer - 0, 0, 0, 0, // Accumulation Bits Ignored + 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer - PFD_MAIN_PLANE, // Main Drawing Layer + PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved - 0, 0, 0 // Layer Masks Ignored + 0, 0, 0 // Layer Masks Ignored }; - if (!(hDC = GetDC(hWnd))) // Did We Get A Device Context? - { - MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); + hDC = GetDC(hWnd); + + if (!hDC) { + *error_message = "Failed to get a device context."; return false; // Return FALSE } - if (!(PixelFormat = ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format? + // Did Windows Find A Matching Pixel Format? + if (!(PixelFormat = ChoosePixelFormat(hDC,&pfd))) { - MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); + *error_message = "Can't Find A Suitable PixelFormat."; return false; } - if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format? - { - MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); + // Are We Able To Set The Pixel Format? + if (!SetPixelFormat(hDC,PixelFormat,&pfd)) { + *error_message = "Can't Set The PixelFormat."; return false; } - if (!(hRC = wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? - { - MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); + // Are We Able To Get A Rendering Context? + if (!(hRC = wglCreateContext(hDC))) { + *error_message = "Can't Create A GL Rendering Context."; return false; } - if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context - { - MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); + // Try To Activate The Rendering Context + if (!wglMakeCurrent(hDC,hRC)) { + *error_message = "Can't activate the GL Rendering Context."; + return false; + } + + if (GLEW_OK != glewInit()) { + *error_message = "Failed to initialize GLEW."; return false; } - glewInit(); // Alright, now for the modernity. - int attribs[] = - { + static const int attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 1, WGL_CONTEXT_FLAGS_ARB, enableGLDebug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0, 0 }; - HGLRC m_hrc; - if(wglewIsSupported("WGL_ARB_create_context") == 1) - { + HGLRC m_hrc; + if(wglewIsSupported("WGL_ARB_create_context") == 1) { m_hrc = wglCreateContextAttribsARB(hDC,0, attribs); wglMakeCurrent(NULL,NULL); wglDeleteContext(hRC); wglMakeCurrent(hDC, m_hrc); - } - else - { //It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before) + } else { + // We can't make a GL 3.x context. Use an old style context (GL 2.1 and before) m_hrc = hRC; } @@ -197,43 +191,41 @@ bool GL_Init(HWND window) glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0]); glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1]); - if (!m_hrc) return false; + if (!m_hrc) { + *error_message = "No m_hrc"; + return false; + } hRC = m_hrc; glstate.Initialize(); setVSync(0); - if (enableGLDebug && glewIsSupported("GL_ARB_debug_output")) - { + if (enableGLDebug && glewIsSupported("GL_ARB_debug_output")) { glDebugMessageCallbackARB((GLDEBUGPROCARB)&DebugCallbackARB, 0); // print debug output to stderr glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); } GL_Resized(); // Set Up Our Perspective GL Screen - return true; // Success } -void GL_Shutdown() -{ - if (hRC) // Do We Have A Rendering Context? - { - if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts? - { +void GL_Shutdown() { + if (hRC) { + // Are We Able To Release The DC And RC Contexts? + if (!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } - if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC? - { + // Are We Able To Delete The RC? + if (!wglDeleteContext(hRC)) { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } - hRC=NULL; // Set RC To NULL + hRC = NULL; } - if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC - { + if (hDC && !ReleaseDC(hWnd,hDC)) { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); - hDC=NULL; // Set DC To NULL + hDC = NULL; } hWnd = NULL; } diff --git a/Windows/OpenGLBase.h b/Windows/OpenGLBase.h index b26ed0ebfd..bf19199b49 100644 --- a/Windows/OpenGLBase.h +++ b/Windows/OpenGLBase.h @@ -5,7 +5,7 @@ #define WIN32_LEAN_AND_MEAN #include -bool GL_Init(HWND window); +bool GL_Init(HWND window, std::string *error_message); void GL_Shutdown(); void GL_Resized(); void GL_SwapBuffers(); diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index cd964dba60..c765986f39 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -249,6 +249,12 @@ true true + + true + true + true + true + true true @@ -307,6 +313,7 @@ + @@ -339,6 +346,7 @@ + diff --git a/Windows/PPSSPP.vcxproj.filters b/Windows/PPSSPP.vcxproj.filters index 6c0a8b3408..82eccdf3f8 100644 --- a/Windows/PPSSPP.vcxproj.filters +++ b/Windows/PPSSPP.vcxproj.filters @@ -107,6 +107,9 @@ Android + + Android + @@ -188,6 +191,9 @@ Android + + Android + @@ -215,6 +221,7 @@ Windows + diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index cef4e558e6..efa2b82c34 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -1,3 +1,20 @@ +// 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 "Core/Core.h" #include "Core/Config.h" #include "EmuThread.h" @@ -26,9 +43,9 @@ int MyMix(short *buffer, int numSamples, int bits, int rate, int channels) } } -void WindowsHost::InitGL() +bool WindowsHost::InitGL(std::string *error_message) { - GL_Init(MainWindow::GetDisplayHWND()); + return GL_Init(MainWindow::GetDisplayHWND(), error_message); } void WindowsHost::ShutdownGL() @@ -38,16 +55,15 @@ void WindowsHost::ShutdownGL() void WindowsHost::SetWindowTitle(const char *message) { - // Really need a better way to deal with versions. - std::string title = "PPSSPP " PPSSPP_VERSION_STR " - "; - title += message; + std::string title = std::string("PPSSPP ") + PPSSPP_GIT_VERSION + " - " + message; - int size = MultiByteToWideChar(CP_UTF8, 0, message, (int) title.size(), NULL, 0); + int size = MultiByteToWideChar(CP_UTF8, 0, title.c_str(), (int) title.size(), NULL, 0); if (size > 0) { - wchar_t *utf16_title = new wchar_t[size + 1]; + // VC++6.0 any more? + wchar_t *utf16_title = new(std::nothrow) wchar_t[size + 1]; if (utf16_title) - size = MultiByteToWideChar(CP_UTF8, 0, message, (int) title.size(), utf16_title, size); + size = MultiByteToWideChar(CP_UTF8, 0, title.c_str(), (int) title.size(), utf16_title, size); else size = 0; @@ -143,7 +159,8 @@ bool WindowsHost::AttemptLoadSymbolMap() void WindowsHost::PrepareShutdown() { - symbolMap.SaveSymbolMap(SymbolMapFilename(GetCurrentFilename()).c_str()); + // Autosaving symbolmap is no longer very useful. + // symbolMap.SaveSymbolMap(SymbolMapFilename(GetCurrentFilename()).c_str()); } void WindowsHost::AddSymbol(std::string name, u32 addr, u32 size, int type=0) diff --git a/Windows/WindowsHost.h b/Windows/WindowsHost.h index 923acf10b8..06ac8b9fdf 100644 --- a/Windows/WindowsHost.h +++ b/Windows/WindowsHost.h @@ -1,3 +1,20 @@ +// 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 "../Core/Host.h" #include "InputDevice.h" #include @@ -19,7 +36,7 @@ public: void AddSymbol(std::string name, u32 addr, u32 size, int type); - void InitGL(); + bool InitGL(std::string *error_message); void BeginFrame(); void ShutdownGL(); diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 2a233ff034..26d110d813 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -2,34 +2,34 @@ #include #include -#include "../globals.h" +#include "Globals.h" #include "shellapi.h" #include "commctrl.h" -#include "../Core/Debugger/SymbolMap.h" -#include "OpenGLBase.h" -#include "Debugger/Debugger_Disasm.h" -#include "Debugger/Debugger_MemoryDlg.h" +#include "Core/Debugger/SymbolMap.h" +#include "Windows/OpenGLBase.h" +#include "Windows/Debugger/Debugger_Disasm.h" +#include "Windows/Debugger/Debugger_MemoryDlg.h" #include "main.h" -#include "../Core/Core.h" -#include "../Core/MemMap.h" -#include "../Core/SaveState.h" -#include "../Core/System.h" -#include "EmuThread.h" +#include "Core/Core.h" +#include "Core/MemMap.h" +#include "Core/SaveState.h" +#include "Core/System.h" +#include "Core/Config.h" +#include "Windows/EmuThread.h" #include "resource.h" -#include "WndMainWindow.h" -#include "LogManager.h" -#include "ConsoleListener.h" -#include "W32Util/DialogManager.h" -#include "W32Util/ShellUtil.h" -#include "W32Util/Misc.h" -#include "../Core/Config.h" -#include "../GPU/GPUInterface.h" -#include "../GPU/GPUState.h" +#include "Windows/WndMainWindow.h" +#include "Common/LogManager.h" +#include "Common/ConsoleListener.h" +#include "Windows/W32Util/DialogManager.h" +#include "Windows/W32Util/ShellUtil.h" +#include "Windows/W32Util/Misc.h" +#include "GPU/GPUInterface.h" +#include "GPU/GPUState.h" #ifdef THEMES #include "XPTheme.h" @@ -401,6 +401,8 @@ namespace MainWindow case ID_OPTIONS_BUFFEREDRENDERING: g_Config.bBufferedRendering = !g_Config.bBufferedRendering; UpdateMenus(); + if (gpu) + gpu->Resized(); // easy way to force a clear... break; case ID_OPTIONS_SHOWDEBUGSTATISTICS: @@ -416,7 +418,8 @@ namespace MainWindow case ID_OPTIONS_STRETCHDISPLAY: g_Config.bStretchToDisplay = !g_Config.bStretchToDisplay; UpdateMenus(); - gpu->Resized(); // easy way to force a clear... + if (gpu) + gpu->Resized(); // easy way to force a clear... break; case ID_OPTIONS_FRAMESKIP: @@ -424,6 +427,11 @@ namespace MainWindow UpdateMenus(); break; + case ID_OPTIONS_USEMEDIAENGINE: + g_Config.bUseMediaEngine = !g_Config.bUseMediaEngine; + UpdateMenus(); + break; + case ID_FILE_EXIT: DestroyWindow(hWnd); break; @@ -443,12 +451,12 @@ namespace MainWindow break; case ID_DEBUG_DUMPNEXTFRAME: - gpu->DumpNextFrame(); + if (gpu) + gpu->DumpNextFrame(); break; case ID_DEBUG_LOADMAPFILE: - if (W32Util::BrowseForFileName(true, hWnd, "Load .MAP",0,"Maps\0*.map\0All files\0*.*\0\0","map",fn)) - { + if (W32Util::BrowseForFileName(true, hWnd, "Load .MAP",0,"Maps\0*.map\0All files\0*.*\0\0","map",fn)) { symbolMap.LoadSymbolMap(fn.c_str()); // HLE_PatchFunctions(); for (int i=0; iSetEnable(LogTypes::G3D, true); - else - LogManager::GetInstance()->SetEnable(LogTypes::G3D, false); - UpdateMenus(); - break; case ID_OPTIONS_CONTROLS: DialogManager::EnableAll(FALSE); DialogBox(hInst, (LPCTSTR)IDD_CONTROLS, hWnd, (DLGPROC)Controls); @@ -687,10 +687,10 @@ namespace MainWindow CHECKITEM(ID_OPTIONS_STRETCHDISPLAY, g_Config.bStretchToDisplay); CHECKITEM(ID_EMULATION_RUNONLOAD, g_Config.bAutoRun); CHECKITEM(ID_OPTIONS_USEVBO, g_Config.bUseVBO); - CHECKITEM(ID_OPTIONS_DISABLEG3DLOG, g_Config.bDisableG3DLog); CHECKITEM(ID_OPTIONS_VERTEXCACHE, g_Config.bVertexCache); CHECKITEM(ID_OPTIONS_SHOWFPS, g_Config.bShowFPSCounter); CHECKITEM(ID_OPTIONS_FRAMESKIP, g_Config.iFrameSkip != 0); + CHECKITEM(ID_OPTIONS_USEMEDIAENGINE, g_Config.bUseMediaEngine); UINT enable = !Core_IsStepping() ? MF_GRAYED : MF_ENABLED; EnableMenuItem(menu,ID_EMULATION_RUN, g_State.bEmuThreadStarted ? enable : MF_GRAYED); @@ -705,11 +705,8 @@ namespace MainWindow EnableMenuItem(menu,ID_FILE_QUICKLOADSTATE,!enable); EnableMenuItem(menu,ID_CPU_DYNAREC,enable); EnableMenuItem(menu,ID_CPU_INTERPRETER,enable); - EnableMenuItem(menu,ID_DVD_INSERTISO,enable); - EnableMenuItem(menu,ID_FILE_BOOTBIOS,enable); EnableMenuItem(menu,ID_EMULATION_STOP,!enable); - EnableMenuItem(menu,ID_OPTIONS_SETTINGS,enable); - EnableMenuItem(menu,ID_PLUGINS_CHOOSEPLUGINS,enable); + EnableMenuItem(menu,ID_OPTIONS_USEMEDIAENGINE,enable); const int zoomitems[4] = { ID_OPTIONS_SCREEN1X, @@ -730,6 +727,12 @@ namespace MainWindow { case WM_INITDIALOG: W32Util::CenterWindow(hDlg); + { + HWND versionBox = GetDlgItem(hDlg, IDC_VERSION); + char temp[256]; + sprintf(temp, "PPSSPP %s", PPSSPP_GIT_VERSION); + SetWindowText(versionBox, temp); + } return TRUE; case WM_COMMAND: @@ -853,14 +856,13 @@ namespace MainWindow void SetPlaying(const char *text) { + char temp[256]; if (text == 0) - SetWindowText(hwndMain, "PPSSPP " PPSSPP_VERSION_STR); + snprintf(temp, 256, "PPSSPP %s", PPSSPP_GIT_VERSION); else - { - char temp[256]; - sprintf(temp, "%s - %s", text, "PPSSPP " PPSSPP_VERSION_STR); - SetWindowText(hwndMain,temp); - } + snprintf(temp, 256, "%s - PPSSPP %s", text, PPSSPP_GIT_VERSION); + temp[255] = '\0'; + SetWindowText(hwndMain, temp); } void SaveStateActionFinished(bool result, void *userdata) diff --git a/Windows/git-version-gen.cmd b/Windows/git-version-gen.cmd new file mode 100644 index 0000000000..eaa42ba57d --- /dev/null +++ b/Windows/git-version-gen.cmd @@ -0,0 +1,71 @@ +@echo off +rem // Copyright (c) 2012- PPSSPP Project. + +rem // This program is free software: you can redistribute it and/or modify +rem // it under the terms of the GNU General Public License as published by +rem // the Free Software Foundation, version 2.0 or later versions. + +rem // This program is distributed in the hope that it will be useful, +rem // but WITHOUT ANY WARRANTY; without even the implied warranty of +rem // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +rem // GNU General Public License 2.0 for more details. + +rem // A copy of the GPL 2.0 should have been included with the program. +rem // If not, see http://www.gnu.org/licenses/ + +rem // Official git repository and contact information can be found at +rem // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +setlocal ENABLEDELAYEDEXPANSION + +set GIT_VERSION_FILE=%~p0..\git-version.cpp +if not defined GIT ( + set GIT="git" +) +call %GIT% describe > NUL 2> NUL +if errorlevel 1 ( + echo Git not on path, trying default Msysgit paths + set GIT="%ProgramFiles(x86)%\Git\bin\git.exe" + call !GIT! describe > NUL 2> NUL + if errorlevel 1 ( + set GIT="%ProgramFiles%\Git\bin\git.exe" + ) +) + +if exist "%GIT_VERSION_FILE%" ( + rem // Skip updating the file if PPSSPP_GIT_VERSION_NO_UPDATE is 1. + findstr /B /C:"#define PPSSPP_GIT_VERSION_NO_UPDATE 1" "%GIT_VERSION_FILE%" > NUL + if not errorlevel 1 ( + goto done + ) +) + +call %GIT% describe --always > NUL 2> NUL +if errorlevel 1 ( + echo Unable to update git-version.cpp, git not found. + echo If you don't want to add it to your path, set the GIT environment variable. + + echo // This is a generated file. > "%GIT_VERSION_FILE%" + echo. >> "%GIT_VERSION_FILE%" + echo const char *PPSSPP_GIT_VERSION = "unknown"; >> "%GIT_VERSION_FILE%" + goto done +) + +for /F %%I IN ('call %GIT% describe --always') do set GIT_VERSION=%%I + +rem // Don't modify the file if it already has the current version. +if exist "%GIT_VERSION_FILE%" ( + findstr /C:"%GIT_VERSION%" "%GIT_VERSION_FILE%" > NUL + if not errorlevel 1 ( + goto done + ) +) + +echo // This is a generated file. > "%GIT_VERSION_FILE%" +echo. >> "%GIT_VERSION_FILE%" +echo const char *PPSSPP_GIT_VERSION = "%GIT_VERSION%"; >> "%GIT_VERSION_FILE%" +echo. >> "%GIT_VERSION_FILE%" +echo // If you don't want this file to update/recompile, change to 1. >> "%GIT_VERSION_FILE%" +echo #define PPSSPP_GIT_VERSION_NO_UPDATE 0 >> "%GIT_VERSION_FILE%" + +:done diff --git a/Windows/ppsspp.rc b/Windows/ppsspp.rc index 8d0a8e1004..10b98bef97 100644 Binary files a/Windows/ppsspp.rc and b/Windows/ppsspp.rc differ diff --git a/Windows/resource.h b/Windows/resource.h index f883f17e5b..01f93a0a46 100644 --- a/Windows/resource.h +++ b/Windows/resource.h @@ -118,6 +118,7 @@ #define IDC_REGISTERS 1007 #define IDC_BREAKPOINTS 1008 #define IDC_STEP 1009 +#define IDC_VERSION 1010 #define IDC_UP 1014 #define IDC_DIRTREE 1014 #define IDC_DOWN 1015 @@ -261,6 +262,8 @@ #define ID_OPTIONS_SHOWFPS 40137 #define ID_OPTIONS_STRETCHDISPLAY 40138 #define ID_OPTIONS_FRAMESKIP 40139 +#define IDC_MEMCHECK 40140 +#define ID_OPTIONS_USEMEDIAENGINE 40141 #define IDC_STATIC -1 // Next default values for new objects @@ -268,7 +271,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 233 -#define _APS_NEXT_COMMAND_VALUE 40140 +#define _APS_NEXT_COMMAND_VALUE 40141 #define _APS_NEXT_CONTROL_VALUE 1163 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 30812f98fa..58de156616 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,8 +1,8 @@ diff --git a/android/ab.cmd b/android/ab.cmd index a3ca5c5b51..36eecad802 100644 --- a/android/ab.cmd +++ b/android/ab.cmd @@ -1,3 +1,4 @@ +xcopy ..\flash0 assets\flash0 /s /y SET NDK=C:\AndroidNDK SET NDK_MODULE_PATH=..;..\native\ext REM Need to force target-platform to android-9 to get access to OpenSL headers. diff --git a/android/ab.sh b/android/ab.sh index 6190b3e541..cf79aab3bc 100755 --- a/android/ab.sh +++ b/android/ab.sh @@ -1 +1,2 @@ +cp -r ../flash0 assets NDK_MODULE_PATH=..:../native/ext $NDK/ndk-build -j3 TARGET_PLATFORM=android-9 $* diff --git a/android/git-version-gen.sh b/android/git-version-gen.sh new file mode 100755 index 0000000000..d441c38379 --- /dev/null +++ b/android/git-version-gen.sh @@ -0,0 +1,52 @@ +#!/bin/bash +## 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/. + +GIT_VERSION_FILE=$(dirname $0)/../git-version.cpp + +if [ -e "$GIT_VERSION_FILE" ]; then + # Skip updating the file if PPSSPP_GIT_VERSION_NO_UPDATE is 1. + results=$(grep '^#define PPSSPP_GIT_VERSION_NO_UPDATE 1' "$GIT_VERSION_FILE") + if [ "$results" != "" ]; then + exit 0 + fi +fi + +GIT_VERSION=$(git describe --always) +if [ "$GIT_VERSION" == "" ]; then + echo "Unable to update git-version.cpp, git not on path." 1>&2 + + echo "// This is a generated file." > "$GIT_VERSION_FILE" + echo >> "$GIT_VERSION_FILE" + echo 'const char *PPSSPP_GIT_VERSION = "unknown";' >> "$GIT_VERSION_FILE" + exit 0 +fi + +# Don't modify the file if it already has the current version. +if [ -e "$GIT_VERSION_FILE" ]; then + results=$(grep "$GIT_VERSION" "$GIT_VERSION_FILE") + if [ "$results" != "" ]; then + exit 0 + fi +fi + +echo "// This is a generated file." > "$GIT_VERSION_FILE" +echo >> "$GIT_VERSION_FILE" +echo 'const char *PPSSPP_GIT_VERSION = "'"$GIT_VERSION"'";' >> "$GIT_VERSION_FILE" +echo >> "$GIT_VERSION_FILE" +echo "// If you don't want this file to update/recompile, change to 1." >> "$GIT_VERSION_FILE" +echo "#define PPSSPP_GIT_VERSION_NO_UPDATE 0" >> "$GIT_VERSION_FILE" diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 5f6640f5a0..e0a8710636 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -50,6 +50,7 @@ LOCAL_SRC_FILES := \ UIShader.cpp \ GamepadEmu.cpp \ ArmEmitterTest.cpp \ + TestRunner.cpp \ ui_atlas.cpp \ $(SRC)/native/android/app-android.cpp \ $(SRC)/ext/disarm.cpp \ @@ -105,6 +106,7 @@ LOCAL_SRC_FILES := \ $(SRC)/Core/PSPLoaders.cpp \ $(SRC)/Core/MemMap.cpp \ $(SRC)/Core/MemMapFunctions.cpp \ + $(SRC)/Core/Reporting.cpp \ $(SRC)/Core/SaveState.cpp \ $(SRC)/Core/System.cpp \ $(SRC)/Core/PSPMixer.cpp \ @@ -116,6 +118,7 @@ LOCAL_SRC_FILES := \ $(SRC)/Core/Dialog/PSPPlaceholderDialog.cpp \ $(SRC)/Core/Dialog/PSPSaveDialog.cpp \ $(SRC)/Core/Dialog/SavedataParam.cpp \ + $(SRC)/Core/Font/PGF.cpp \ $(SRC)/Core/HLE/HLETables.cpp \ $(SRC)/Core/HLE/HLE.cpp \ $(SRC)/Core/HLE/sceAtrac.cpp \ @@ -147,6 +150,7 @@ LOCAL_SRC_FILES := \ $(SRC)/Core/HLE/sceMpeg.cpp \ $(SRC)/Core/HLE/sceNet.cpp \ $(SRC)/Core/HLE/sceOpenPSID.cpp \ + $(SRC)/Core/HLE/sceP3da.cpp \ $(SRC)/Core/HLE/sceParseHttp.cpp \ $(SRC)/Core/HLE/sceParseUri.cpp \ $(SRC)/Core/HLE/scePower.cpp \ @@ -186,10 +190,17 @@ LOCAL_SRC_FILES := \ $(SRC)/Core/MIPS/ARM/ArmRegCacheFPU.cpp \ $(SRC)/Core/Util/BlockAllocator.cpp \ $(SRC)/Core/Util/ppge_atlas.cpp \ - $(SRC)/Core/Util/PPGeDraw.cpp + $(SRC)/Core/Util/PPGeDraw.cpp \ + $(SRC)/git-version.cpp include $(BUILD_SHARED_LIBRARY) $(call import-module,libzip) $(call import-module,native) + +jni/$(SRC)/git-version.cpp: + -./git-version-gen.sh + -..\Windows\git-version-gen.cmd + +.PHONY: jni/$(SRC)/git-version.cpp diff --git a/android/jni/ArmEmitterTest.cpp b/android/jni/ArmEmitterTest.cpp index b52a68e38a..66a74ba671 100644 --- a/android/jni/ArmEmitterTest.cpp +++ b/android/jni/ArmEmitterTest.cpp @@ -20,61 +20,54 @@ TestCode::TestCode() AllocCodeSpace(0x10000); } - -u32 TestLeaf(u32 a, u32 b, u32 c) -{ - ILOG("TestLeaf: %08x %08x %08x\n", a, b, c); - return 0xFF; -} - -void TestLeaf2(u32 a) -{ - ILOG("TestLeaf2 %08x\n"); -} - +static float abc[256] = {1.0f, 2.0f, 0.0f}; void TestCode::Generate() { testCodePtr = this->GetCodePtr(); // Sonic1 commented that R11 is the frame pointer in debug mode, whatever "debug mode" means. PUSH(2, R11, _LR); - MOVI2R(R0, 0x13371338); - AND(R1, R0, Operand2(0xFC, 4)); - BIC(R0, R0, Operand2(0xFC, 4)); - CMP(R1, Operand2(0x10, 4)); - SetCC(CC_EQ); - MOV(R2, Operand2(0x99, 0)); - SetCC(CC_NEQ); - MOV(R2, Operand2(0xFF, 0)); - SetCC(); - QuickCallFunction(R3, (void*)&TestLeaf); + MOVI2R(R11, (u32)&abc[0]); + MOVI2R(R1, 0x3f800000); + STR(R11, R1, 4 * (32 + 31)); + VLDR(S0, R11, 0); + VLDR(S1, R11, 4); + VADD(S12, S0, S1); + VSTR(S0, R11, 4 * (32 + 31)); + VSTR(S12, R11, 4 * (32 + 31)); + //VSTR(S2, R0, 8); + POP(2, R11, _PC); // Yup, this is how you return. + + //VLDR(S1, R0, 4); + //VADD(S2, S0, S1); + //VSTR(S2, R0, 8); + //QuickCallFunction(R3, (void*)&TestLeaf); //ARMABI_CallFunctionCCC((void*)&TestLeaf, 0x1, 0x100, 0x1337); //ARMABI_CallFunctionCCC((void*)&TestLeaf, 0x2, 0x100, 0x31337); //ARMABI_CallFunctionCCC((void*)&TestLeaf, 0x3, 0x100, 0x1337); - POP(2, R11, _PC); // Yup, this is how you return. - - testCodePtr2 = this->GetCodePtr(); - PUSH(2, R11, _LR); - QuickCallFunction(R3, (void*)&TestLeaf2); - POP(2, R11, _PC); } -void CallPtr(const void *ptr) +u32 CallPtr(const void *ptr) { - ((void(*)())ptr)(); + return ((u32(*)())ptr)(); } +extern void DisassembleArm(const u8 *data, int size); void ArmEmitterTest() { + // Disabled for now. + return; ILOG("Running ARM emitter test!"); TestCode gen; - gen.ReserveCodeSpace(0x4000); + gen.ReserveCodeSpace(0x1000); + const u8 *codeStart = gen.GetCodePtr(); gen.Generate(); + DisassembleArm(codeStart, gen.GetCodePtr()-codeStart); - CallPtr(gen.testCodePtr); - ILOG("ARM emitter test 1 passed!"); + u32 retval = CallPtr(gen.testCodePtr); + ILOG("ARM emitter test 1 passed if %f == 3.0! retval = %08x", abc[32 + 31], retval); } diff --git a/android/jni/EmuScreen.cpp b/android/jni/EmuScreen.cpp index 8a0d13f84e..19ac140f37 100644 --- a/android/jni/EmuScreen.cpp +++ b/android/jni/EmuScreen.cpp @@ -15,6 +15,8 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include "base/logging.h" + #include "gfx_es2/glsl_program.h" #include "gfx_es2/gl_state.h" #include "gfx_es2/fbo.h" @@ -95,6 +97,24 @@ void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) { } } +inline float curve1(float x) { + const float deadzone = 0.15f; + const float factor = 1.0f / (1.0f - deadzone); + if (x > deadzone) { + return (x - deadzone) * (x - deadzone) * factor; + } else if (x < -0.1f) { + return -(x + deadzone) * (x + deadzone) * factor; + } else { + return 0.0f; + } +} + +inline float clamp1(float x) { + if (x > 1.0f) return 1.0f; + if (x < -1.0f) return -1.0f; + return x; +} + void EmuScreen::update(InputState &input) { if (errorMessage_.size()) { @@ -108,12 +128,11 @@ void EmuScreen::update(InputState &input) if (invalid_) return; - // First translate touches into pad input. + // First translate touches into native pad input. UpdateGamepad(input); UpdateInputState(&input); - // Then translate pad input into PSP pad input. - + // Then translate pad input into PSP pad input. Also, add in tilt. static const int mapping[12][2] = { {PAD_BUTTON_A, CTRL_CROSS}, {PAD_BUTTON_B, CTRL_CIRCLE}, @@ -137,7 +156,17 @@ void EmuScreen::update(InputState &input) __CtrlButtonUp(mapping[i][1]); } } - __CtrlSetAnalog(input.pad_lstick_x, input.pad_lstick_y); + + float stick_x = input.pad_lstick_x; + float stick_y = input.pad_lstick_y; + // Apply tilt + if (g_Config.bAccelerometerToAnalogHoriz) { + // TODO: Deadzone, etc. + stick_x += clamp1(curve1(input.acc.y) * 2.0f); + stick_x = clamp1(stick_x); + } + + __CtrlSetAnalog(stick_x, stick_y); if (input.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK)) { if (g_Config.bBufferedRendering) @@ -167,8 +196,14 @@ void EmuScreen::render() if (coreState == CORE_NEXTFRAME) { // set back to running for the next frame coreState = CORE_RUNNING; + } else if (coreState == CORE_POWERDOWN) { + ILOG("SELF-POWERDOWN!"); + screenManager()->switchScreen(new MenuScreen()); } + if (invalid_) + return; + if (g_Config.bBufferedRendering) fbo_unbind(); @@ -202,5 +237,6 @@ void EmuScreen::render() void EmuScreen::deviceLost() { + ILOG("EmuScreen::deviceLost()"); gpu->DeviceLost(); } diff --git a/android/jni/GamepadEmu.cpp b/android/jni/GamepadEmu.cpp index 826c1900b1..6db54fcad4 100644 --- a/android/jni/GamepadEmu.cpp +++ b/android/jni/GamepadEmu.cpp @@ -40,7 +40,7 @@ TouchStick leftStick(&ui_atlas, I_STICKBG, I_STICK, 0); void LayoutGamepad(int w, int h) { - float controlScale = g_Config.bLargeControls ? 1.7 : 1.0; + float controlScale = g_Config.bLargeControls ? 1.6 : 1.15; const int button_spacing = 50 * controlScale; const int arrow_spacing = 40 * controlScale; diff --git a/android/jni/MenuScreens.cpp b/android/jni/MenuScreens.cpp index a858667588..db27b96057 100644 --- a/android/jni/MenuScreens.cpp +++ b/android/jni/MenuScreens.cpp @@ -42,6 +42,7 @@ #include "MenuScreens.h" #include "EmuScreen.h" +#include "TestRunner.h" #ifdef USING_QT_UI #include @@ -166,11 +167,11 @@ void MenuScreen::render() { int w = LARGE_BUTTON_WIDTH + 40; - ui_draw2d.DrawTextShadow(UBUNTU48, "PPSSPP", dp_xres + xoff - w/2, 80, 0xFFFFFFFF, ALIGN_HCENTER | ALIGN_BOTTOM); + ui_draw2d.DrawTextShadow(UBUNTU48, "PPSSPP", dp_xres + xoff - w/2, 75, 0xFFFFFFFF, ALIGN_HCENTER | ALIGN_BOTTOM); ui_draw2d.SetFontScale(0.7f, 0.7f); - ui_draw2d.DrawTextShadow(UBUNTU24, PPSSPP_VERSION_STR, dp_xres + xoff, 80, 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_BOTTOM); + ui_draw2d.DrawTextShadow(UBUNTU24, PPSSPP_GIT_VERSION, dp_xres + xoff, 85, 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_BOTTOM); ui_draw2d.SetFontScale(1.0f, 1.0f); - VLinear vlinear(dp_xres + xoff, 95, 20); + VLinear vlinear(dp_xres + xoff, 100, 20); if (UIButton(GEN_ID, vlinear, w, "Load...", ALIGN_RIGHT)) { #if defined(USING_QT_UI) @@ -196,7 +197,7 @@ void MenuScreen::render() { } if (UIButton(GEN_ID, vlinear, w, "Settings", ALIGN_RIGHT)) { - screenManager()->switchScreen(new SettingsScreen()); + screenManager()->push(new SettingsScreen(), 0); UIReset(); } @@ -237,7 +238,8 @@ void InGameMenuScreen::render() { DrawBackground(1.0f); const char *title; - if (UTF8StringHasNonASCII(game_title.c_str())) { + // Try to ignore (tm) etc. + if (UTF8StringNonASCIICount(game_title.c_str()) > 2) { title = "(can't display japanese title)"; } else { title = game_title.c_str(); @@ -247,15 +249,21 @@ void InGameMenuScreen::render() { int x = 30; int y = 50; - UICheckBox(GEN_ID, x, y += 50, "Show Debug Statistics", ALIGN_TOPLEFT, &g_Config.bShowDebugStats); - UICheckBox(GEN_ID, x, y += 50, "Show FPS", ALIGN_TOPLEFT, &g_Config.bShowFPSCounter); + int stride = 40; + int columnw = 420; + UICheckBox(GEN_ID, x, y += stride, "Show Debug Statistics", ALIGN_TOPLEFT, &g_Config.bShowDebugStats); + UICheckBox(GEN_ID, x + columnw, y, "Show FPS", ALIGN_TOPLEFT, &g_Config.bShowFPSCounter); // TODO: Maybe shouldn't show this if the screen ratios are very close... - UICheckBox(GEN_ID, x, y += 50, "Stretch to display", ALIGN_TOPLEFT, &g_Config.bStretchToDisplay); + UICheckBox(GEN_ID, x, y += stride, "Stretch to display", ALIGN_TOPLEFT, &g_Config.bStretchToDisplay); - UICheckBox(GEN_ID, x, y += 50, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform); + UICheckBox(GEN_ID, x, y += stride, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform); + if (UICheckBox(GEN_ID, x, y += stride, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) { + if (gpu) + gpu->Resized(); + } bool fs = g_Config.iFrameSkip == 1; - UICheckBox(GEN_ID, x, y += 50, "Frameskip", ALIGN_TOPLEFT, &fs); + UICheckBox(GEN_ID, x, y += stride, "Frameskip (beta)", ALIGN_TOPLEFT, &fs); g_Config.iFrameSkip = fs ? 1 : 0; // TODO: Add UI for more than one slot. @@ -273,13 +281,18 @@ void InGameMenuScreen::render() { if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, "Continue", ALIGN_RIGHT)) { screenManager()->finishDialog(this, DR_CANCEL); } + if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, "Settings", ALIGN_RIGHT)) { + screenManager()->push(new SettingsScreen(), 0); + } if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, "Return to Menu", ALIGN_RIGHT)) { screenManager()->finishDialog(this, DR_OK); } - + + /* if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH*2, "Debug: Dump Next Frame", ALIGN_BOTTOMRIGHT)) { gpu->DumpNextFrame(); } + */ DrawWatermark(); UIEnd(); @@ -291,7 +304,7 @@ void InGameMenuScreen::render() { void SettingsScreen::update(InputState &input) { if (input.pad_buttons_down & PAD_BUTTON_BACK) { g_Config.Save(); - screenManager()->switchScreen(new MenuScreen()); + screenManager()->finishDialog(this, DR_OK); } } @@ -308,30 +321,86 @@ void SettingsScreen::render() { int x = 30; int y = 30; int stride = 40; + int columnw = 420; UICheckBox(GEN_ID, x, y += stride, "Sound Emulation", ALIGN_TOPLEFT, &g_Config.bEnableSound); - UICheckBox(GEN_ID, x, y += stride, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering); + UICheckBox(GEN_ID, x + columnw, y, "Linear Filtering", ALIGN_TOPLEFT, &g_Config.bLinearFiltering); + if (UICheckBox(GEN_ID, x, y += stride, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) { + if (gpu) + gpu->Resized(); + } if (g_Config.bBufferedRendering) { bool doubleRes = g_Config.iWindowZoom == 2; - UICheckBox(GEN_ID, x + 50, y += stride, "2x Render Resolution", ALIGN_TOPLEFT, &doubleRes); + if (UICheckBox(GEN_ID, x + columnw, y, "2x Render Resolution", ALIGN_TOPLEFT, &doubleRes)) { + if (gpu) + gpu->Resized(); + } g_Config.iWindowZoom = doubleRes ? 2 : 1; } +#ifndef __SYMBIAN32__ UICheckBox(GEN_ID, x, y += stride, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform); - UICheckBox(GEN_ID, x, y += stride, "Draw using Stream VBO", ALIGN_TOPLEFT, &g_Config.bUseVBO); + UICheckBox(GEN_ID, x + columnw, y, "Draw using Stream VBO", ALIGN_TOPLEFT, &g_Config.bUseVBO); +#endif UICheckBox(GEN_ID, x, y += stride, "Vertex Cache", ALIGN_TOPLEFT, &g_Config.bVertexCache); + UICheckBox(GEN_ID, x + columnw, y, "Use Media Engine", ALIGN_TOPLEFT, &g_Config.bUseMediaEngine); UICheckBox(GEN_ID, x, y += stride, "JIT (Dynarec)", ALIGN_TOPLEFT, &g_Config.bJit); if (g_Config.bJit) - UICheckBox(GEN_ID, x + 450, y, "Fastmem (may be unstable)", ALIGN_TOPLEFT, &g_Config.bFastMemory); - // ui_draw2d.DrawText(UBUNTU48, "much faster JIT coming later", x, y+=50, 0xcFFFFFFF, ALIGN_LEFT); + UICheckBox(GEN_ID, x + columnw, y, "Fastmem (may be unstable)", ALIGN_TOPLEFT, &g_Config.bFastMemory); + UICheckBox(GEN_ID, x, y += stride, "On-screen Touch Controls", ALIGN_TOPLEFT, &g_Config.bShowTouchControls); if (g_Config.bShowTouchControls) { - UICheckBox(GEN_ID, x + 450, y, "Large Controls", ALIGN_TOPLEFT, &g_Config.bLargeControls); - UICheckBox(GEN_ID, x + 50, y += stride, "Show Analog Stick", ALIGN_TOPLEFT, &g_Config.bShowAnalogStick); + UICheckBox(GEN_ID, x + columnw, y, "Large Controls", ALIGN_TOPLEFT, &g_Config.bLargeControls); + UICheckBox(GEN_ID, x + columnw, y += stride, "Show Analog Stick", ALIGN_TOPLEFT, &g_Config.bShowAnalogStick); + } else { + y += stride; } + UICheckBox(GEN_ID, x, y, "Tilt to Analog (horizontal)", ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz); + + + ui_draw2d.DrawText(UBUNTU24, "Some settings may require a restart to apply.", dp_xres/2, y += stride + 20, 0xFFFFFFFF, ALIGN_HCENTER); + // UICheckBox(GEN_ID, x, y += stride, "Draw raw framebuffer (for some homebrew)", ALIGN_TOPLEFT, &g_Config.bDisplayFramebuffer); if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { - screenManager()->switchScreen(new MenuScreen()); + screenManager()->finishDialog(this, DR_OK); + } + if (UIButton(GEN_ID, Pos(10, dp_yres-10), LARGE_BUTTON_WIDTH, "Developer Menu", ALIGN_BOTTOMLEFT)) { + screenManager()->push(new DeveloperScreen()); + } + + UIEnd(); + + glsl_bind(UIShader_Get()); + ui_draw2d.Flush(UIShader_Get()); +} + +void DeveloperScreen::update(InputState &input) { + if (input.pad_buttons_down & PAD_BUTTON_BACK) { + g_Config.Save(); + screenManager()->finishDialog(this, DR_OK); + } +} + +void DeveloperScreen::render() { + UIShader_Prepare(); + UIBegin(); + DrawBackground(1.0f); + + ui_draw2d.DrawText(UBUNTU48, "Developer Tools", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + screenManager()->finishDialog(this, DR_OK); + } + + if (UIButton(GEN_ID, Pos(dp_xres / 2, 100), LARGE_BUTTON_WIDTH, "Run CPU tests", ALIGN_CENTER | ALIGN_TOP)) { + // TODO: Run tests + RunTests(); + // screenManager()->push(new EmuScreen()) + } + + + if (UIButton(GEN_ID, Pos(10, dp_yres-10), LARGE_BUTTON_WIDTH, "Dump frame to log", ALIGN_BOTTOMLEFT)) { + gpu->DumpNextFrame(); } UIEnd(); @@ -439,13 +508,11 @@ void CreditsScreen::update(InputState &input_state) { frames_++; } -static const char *credits[] = -{ - "PPSSPP " PPSSPP_VERSION_STR, +static const char * credits[] = { + "PPSSPP", "", "", "A fast and portable PSP emulator", - "(well, an early prototype of that)", "", "Created by Henrik Rydgard", "", @@ -501,6 +568,11 @@ static const char *credits[] = }; void CreditsScreen::render() { + // TODO: This is kinda ugly, done on every frame... + char temp[256]; + snprintf(temp, 256, "PPSSPP %s", PPSSPP_GIT_VERSION); + credits[0] = (const char *)temp; + UIShader_Prepare(); UIBegin(); DrawBackground(1.0f); diff --git a/android/jni/MenuScreens.h b/android/jni/MenuScreens.h index d5858f4892..9652a79bf5 100644 --- a/android/jni/MenuScreens.h +++ b/android/jni/MenuScreens.h @@ -67,6 +67,14 @@ public: }; +class DeveloperScreen : public Screen +{ +public: + void update(InputState &input); + void render(); +}; + + struct FileSelectScreenOptions { const char* filter; // Enforced extension filter. Case insensitive, extensions separated by ":". bool allowChooseDirectory; diff --git a/android/jni/NativeApp.cpp b/android/jni/NativeApp.cpp index 77d9e97100..69234a7e17 100644 --- a/android/jni/NativeApp.cpp +++ b/android/jni/NativeApp.cpp @@ -65,6 +65,7 @@ public: { switch (level) { + case LogTypes::LVERBOSE: case LogTypes::LDEBUG: case LogTypes::LINFO: ILOG("%s", msg); @@ -99,12 +100,12 @@ public: virtual void SetDebugMode(bool mode) { } - virtual void InitGL() {} + virtual bool InitGL(std::string *error_message) { return true; } virtual void BeginFrame() {} virtual void ShutdownGL() {} virtual void InitSound(PMixer *mixer); - virtual void UpdateSound() {}; + virtual void UpdateSound() {} virtual void ShutdownSound(); // this is sent from EMU thread! Make sure that Host handles it properly! @@ -154,7 +155,9 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo *app_dir_name = "ppsspp"; *landscape = true; - // ArmEmitterTest(); +#if defined(ANDROID) + ArmEmitterTest(); +#endif } void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID) @@ -250,7 +253,13 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co g_Config.flashDirectory = std::string(external_directory)+"/flash/"; #elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(IOS) g_Config.memCardDirectory = user_data_path; +#ifdef BLACKBERRY + g_Config.flashDirectory = "app/native/assets/flash/"; +#elif IOS + g_Config.flashDirectory = std::string(external_directory) + "flash0/"; +#else g_Config.flashDirectory = user_data_path+"/flash/"; +#endif #else g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/"; g_Config.flashDirectory = g_Config.memCardDirectory+"/flash/"; @@ -265,6 +274,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co logman->AddListener(type, logger); #endif } +#ifdef __SYMBIAN32__ + g_Config.bHardwareTransform = true; + g_Config.bUseVBO = false; +#endif // Special hack for G3D as it's very spammy. Need to make a flag for this. if (!gfxLog) logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR); @@ -347,6 +360,7 @@ void NativeDeviceLost() { screenManager->deviceLost(); gl_lost(); + glstate.Restore(); // Should dirty EVERYTHING } diff --git a/android/jni/TestRunner.cpp b/android/jni/TestRunner.cpp new file mode 100644 index 0000000000..3783081a1f --- /dev/null +++ b/android/jni/TestRunner.cpp @@ -0,0 +1,145 @@ +// 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/. + + +// TO USE: +// Simply copy pspautotests to the root of the USB memory / SD card of your android device. +// Then go to Settings / Developer Menu / Run CPU tests. +// It currently just runs one test but that can be easily changed. + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/display.h" +#include "base/logging.h" +#include "gfx_es2/gl_state.h" + +#include "Core/Core.h" +#include "Core/System.h" +#include "Core/Config.h" +#include "Core/CoreTiming.h" +#include "Core/MIPS/MIPS.h" +#include "TestRunner.h" + + +const char *testsToRun[] = { + "cpu/cpu_alu/cpu_alu", + "cpu/fpu/fpu", + "cpu/icache/icache", + "cpu/lsu/lsu", + "cpu/vfpu/base/vfpu", + "cpu/vfpu/colors/vfpu_colors", + "cpu/vfpu/convert/vfpu_convert", + "cpu/vfpu/prefixes/vfpu_prefixes", +}; + +void RunTests() +{ + std::string output; + + CoreParameter coreParam; + coreParam.cpuCore = g_Config.bJit ? CPU_JIT : CPU_INTERPRETER; + coreParam.gpuCore = GPU_GLES; + coreParam.enableSound = g_Config.bEnableSound; + coreParam.mountIso = ""; + coreParam.startPaused = false; + coreParam.enableDebugging = false; + coreParam.printfEmuLog = false; + coreParam.headLess = false; + coreParam.renderWidth = 480; + coreParam.renderHeight = 272; + coreParam.outputWidth = 480; + coreParam.outputHeight = 272; + coreParam.pixelWidth = 480; + coreParam.pixelHeight = 272; + coreParam.useMediaEngine = false; + coreParam.collectEmuLog = &output; + + // Never report from tests. + std::string savedReportHost = g_Config.sReportHost; + g_Config.sReportHost = ""; + + for (int i = 0; i < ARRAY_SIZE(testsToRun); i++) { + const char *testName = testsToRun[i]; + coreParam.fileToStart = g_Config.memCardDirectory + "pspautotests/tests/" + testName + ".prx"; + std::string expectedFile = g_Config.memCardDirectory + "pspautotests/tests/" + testName + ".expected"; + + ILOG("Preparing to execute %s", testName) + std::string error_string; + output = ""; + if (!PSP_Init(coreParam, &error_string)) { + ELOG("Failed to init unittest %s : %s", testsToRun[i], error_string.c_str()); + return; + } + + // Run the emu until the test exits + while (true) { + int blockTicks = usToCycles(1000000 / 10); + while (coreState == CORE_RUNNING) { + u64 nowTicks = CoreTiming::GetTicks(); + mipsr4k.RunLoopUntil(nowTicks + blockTicks); + } + // Hopefully coreState is now CORE_NEXTFRAME + if (coreState == CORE_NEXTFRAME) { + // set back to running for the next frame + coreState = CORE_RUNNING; + } else if (coreState == CORE_POWERDOWN) { + ILOG("Finished running test %s", testName); + break; + } + } + + std::ifstream expected(expectedFile.c_str(), std::ios_base::in); + if (!expected) { + ELOG("Error opening expectedFile %s", expectedFile.c_str()); + return; + } + + std::istringstream logoutput(output); + + int line = 0; + while (true) { + ++line; + std::string e, o; + std::getline(expected, e); + std::getline(logoutput, o); + // Remove stray returns + while (e[e.size()-1] == 10 || e[e.size()-1] == 13) + e = e.substr(0, e.size() - 1); // For some reason we get some extra character + while (o[o.size()-1] == 10 || o[o.size()-1] == 13) + o = o.substr(0, o.size() - 1); // For some reason we get some extra character + if (e != o) { + ELOG("DIFF on line %i!", line); + ILOG("O: %s", o.c_str()); + ILOG("E: %s", e.c_str()); + } + if (expected.eof()) { + break; + } + if (logoutput.eof()) { + break; + } + } + PSP_Shutdown(); + } + glstate.Restore(); + glstate.viewport.set(0,0,pixel_xres,pixel_yres); + + g_Config.sReportHost = savedReportHost; +} \ No newline at end of file diff --git a/android/jni/TestRunner.h b/android/jni/TestRunner.h new file mode 100644 index 0000000000..50f4546a6f --- /dev/null +++ b/android/jni/TestRunner.h @@ -0,0 +1,20 @@ +// 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 + +void RunTests(); diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index c752713aaa..a710d02017 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -15,4 +15,4 @@ public class PpssppActivity extends NativeActivity { { return false; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/ext/disarm.cpp b/ext/disarm.cpp index ffd3d756b5..a700847367 100644 --- a/ext/disarm.cpp +++ b/ext/disarm.cpp @@ -308,8 +308,8 @@ instr_disassemble(word instr, address addr, pDisOptions opts) { fpn = ((instr>>15)&1) + ((instr>>21)&2); - result.undefined = - result.badbits = + result.undefined = 0; + result.badbits = 0; result.oddbits = 0; result.is_SWI = 0; result.target_type = target_None; diff --git a/ext/libkirk/AES.c b/ext/libkirk/AES.c index c75748510b..c7a84621f2 100644 --- a/ext/libkirk/AES.c +++ b/ext/libkirk/AES.c @@ -37,11 +37,11 @@ //CMAC GLOBS #define AES_128 0 -const unsigned char const_Rb[16] = { +static const unsigned char const_Rb[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87 }; -const unsigned char const_Zero[16] = { +static const unsigned char const_Zero[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/flash0/font/jpn0.pgf b/flash0/font/jpn0.pgf new file mode 100644 index 0000000000..913bd73b11 Binary files /dev/null and b/flash0/font/jpn0.pgf differ diff --git a/flash0/font/kr0.pgf b/flash0/font/kr0.pgf new file mode 100644 index 0000000000..5d4f615b9c Binary files /dev/null and b/flash0/font/kr0.pgf differ diff --git a/flash0/font/ltn0.pgf b/flash0/font/ltn0.pgf new file mode 100644 index 0000000000..bf710feef0 Binary files /dev/null and b/flash0/font/ltn0.pgf differ diff --git a/flash0/font/ltn1.pgf b/flash0/font/ltn1.pgf new file mode 100644 index 0000000000..7b9dede484 Binary files /dev/null and b/flash0/font/ltn1.pgf differ diff --git a/flash0/font/ltn10.pgf b/flash0/font/ltn10.pgf new file mode 100644 index 0000000000..a12d1814ca Binary files /dev/null and b/flash0/font/ltn10.pgf differ diff --git a/flash0/font/ltn11.pgf b/flash0/font/ltn11.pgf new file mode 100644 index 0000000000..402bf6084c Binary files /dev/null and b/flash0/font/ltn11.pgf differ diff --git a/flash0/font/ltn12.pgf b/flash0/font/ltn12.pgf new file mode 100644 index 0000000000..092d5ef041 Binary files /dev/null and b/flash0/font/ltn12.pgf differ diff --git a/flash0/font/ltn13.pgf b/flash0/font/ltn13.pgf new file mode 100644 index 0000000000..89b28d366a Binary files /dev/null and b/flash0/font/ltn13.pgf differ diff --git a/flash0/font/ltn14.pgf b/flash0/font/ltn14.pgf new file mode 100644 index 0000000000..873afb3d05 Binary files /dev/null and b/flash0/font/ltn14.pgf differ diff --git a/flash0/font/ltn15.pgf b/flash0/font/ltn15.pgf new file mode 100644 index 0000000000..c517fe05cd Binary files /dev/null and b/flash0/font/ltn15.pgf differ diff --git a/flash0/font/ltn2.pgf b/flash0/font/ltn2.pgf new file mode 100644 index 0000000000..9ee2763f85 Binary files /dev/null and b/flash0/font/ltn2.pgf differ diff --git a/flash0/font/ltn3.pgf b/flash0/font/ltn3.pgf new file mode 100644 index 0000000000..805c286330 Binary files /dev/null and b/flash0/font/ltn3.pgf differ diff --git a/flash0/font/ltn4.pgf b/flash0/font/ltn4.pgf new file mode 100644 index 0000000000..12b075101d Binary files /dev/null and b/flash0/font/ltn4.pgf differ diff --git a/flash0/font/ltn5.pgf b/flash0/font/ltn5.pgf new file mode 100644 index 0000000000..d12e9eccc3 Binary files /dev/null and b/flash0/font/ltn5.pgf differ diff --git a/flash0/font/ltn6.pgf b/flash0/font/ltn6.pgf new file mode 100644 index 0000000000..0f626ddff2 Binary files /dev/null and b/flash0/font/ltn6.pgf differ diff --git a/flash0/font/ltn7.pgf b/flash0/font/ltn7.pgf new file mode 100644 index 0000000000..ba9afda58c Binary files /dev/null and b/flash0/font/ltn7.pgf differ diff --git a/flash0/font/ltn8.pgf b/flash0/font/ltn8.pgf new file mode 100644 index 0000000000..a07a1f718e Binary files /dev/null and b/flash0/font/ltn8.pgf differ diff --git a/flash0/font/ltn9.pgf b/flash0/font/ltn9.pgf new file mode 100644 index 0000000000..11132d1a32 Binary files /dev/null and b/flash0/font/ltn9.pgf differ diff --git a/git-version.cmake b/git-version.cmake new file mode 100644 index 0000000000..f26cf95542 --- /dev/null +++ b/git-version.cmake @@ -0,0 +1,43 @@ +set(GIT_VERSION_FILE "${SOURCE_DIR}/git-version.cpp") +set(GIT_VERSION "unknown") +set(GIT_VERSION_UPDATE "1") + +find_package(Git) +if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} describe --always + WORKING_DIRECTORY ${SOURCE_DIR} + RESULT_VARIABLE exit_code + OUTPUT_VARIABLE GIT_VERSION) + if(NOT ${exit_code} EQUAL 0) + message(WARNING "git describe failed, unable to include version.") + endif() + string(STRIP ${GIT_VERSION} GIT_VERSION) +else() + message(WARNING "git not found, unable to include version.") +endif() + +if(EXISTS ${GIT_VERSION_FILE}) + # Don't update if marked not to update. + file(STRINGS ${GIT_VERSION_FILE} match + REGEX "PPSSPP_GIT_VERSION_NO_UPDATE = 1") + if(NOT $[match} EQUAL "") + set(GIT_VERSION_UPDATE "0") + endif() + + # Don't update if it's already the same. + file(STRINGS ${GIT_VERSION_FILE} match + REGEX "${GIT_VERSION}") + if(NOT $[match} EQUAL "") + set(GIT_VERSION_UPDATE "0") + endif() +endif() + +set(code_string "// This is a generated file.\n\n" + "const char *PPSSPP_GIT_VERSION = \"${GIT_VERSION}\"\;\n\n" + "// If you don't want this file to update/recompile, change to 1.\n" + "#define PPSSPP_GIT_VERSION_NO_UPDATE 0\n") + +message(WARNING "UPDATE: ${GIT_VERSION_FILE}") +if ("${GIT_VERSION_UPDATE}" EQUAL "1") + file(WRITE ${GIT_VERSION_FILE} ${code_string}) +endif() \ No newline at end of file diff --git a/headless/Headless.cpp b/headless/Headless.cpp index f8db1ff0fb..8f1a4eca5c 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -27,6 +27,9 @@ public: { switch (level) { + case LogTypes::LVERBOSE: + fprintf(stderr, "V %s", msg); + break; case LogTypes::LDEBUG: fprintf(stderr, "D %s", msg); break; @@ -137,7 +140,9 @@ int main(int argc, const char* argv[]) HeadlessHost *headlessHost = useGraphics ? new HEADLESSHOST_CLASS() : new HeadlessHost(); host = headlessHost; - host->InitGL(); + + std::string error_string; + host->InitGL(&error_string); LogManager::Init(); LogManager *logman = LogManager::GetInstance(); @@ -166,6 +171,8 @@ int main(int argc, const char* argv[]) g_Config.bEnableSound = false; g_Config.bFirstRun = false; g_Config.bIgnoreBadMemAccess = true; + // Never report from tests. + g_Config.sReportHost = ""; #if defined(ANDROID) #elif defined(BLACKBERRY) || defined(__SYMBIAN32__) @@ -174,7 +181,6 @@ int main(int argc, const char* argv[]) g_Config.flashDirectory = g_Config.memCardDirectory+"/flash/"; #endif - std::string error_string; if (!PSP_Init(coreParameter, &error_string)) { fprintf(stderr, "Failed to start %s. Error: %s\n", coreParameter.fileToStart.c_str(), error_string.c_str()); diff --git a/headless/StubHost.h b/headless/StubHost.h index 19e71c3b68..fd85de2ca1 100644 --- a/headless/StubHost.h +++ b/headless/StubHost.h @@ -33,7 +33,7 @@ public: virtual void SetDebugMode(bool mode) { } - virtual void InitGL() {} + virtual bool InitGL(std::string *error_message) {return true;} virtual void BeginFrame() {} virtual void ShutdownGL() {} diff --git a/ios/ViewController.mm b/ios/ViewController.mm index da3699e194..95fa5b4fc2 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -55,7 +55,7 @@ ViewController* sharedViewController; self.touches = [[[NSMutableArray alloc] init] autorelease]; self.documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; - self.bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets"]; + self.bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets/"]; memset(&input_state, 0, sizeof(input_state)); @@ -80,6 +80,7 @@ ViewController* sharedViewController; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; [EAGLContext setCurrentContext:self.context]; + self.preferredFramesPerSecond = 60; float scale = [UIScreen mainScreen].scale; CGSize size = [[UIApplication sharedApplication].delegate window].frame.size; diff --git a/native b/native index 17c8eb1ae7..21a7ee80fb 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 17c8eb1ae7ca285a4228bac56059ca441b53ba6f +Subproject commit 21a7ee80fb2f31bfff1a739bce80ac8e5047952b diff --git a/pspautotests b/pspautotests index a013aed6f1..a9c949b87d 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit a013aed6f1ca37f9a665a0010e8971090a73116c +Subproject commit a9c949b87dc69d4d6cde854b73455a170a2aaff4 diff --git a/test.py b/test.py index f2f4abbe2b..625b1d5c93 100755 --- a/test.py +++ b/test.py @@ -53,6 +53,7 @@ tests_good = [ "ctrl/sampling/sampling", "ctrl/sampling2/sampling2", "display/display", + "display/vblankmulti", "dmac/dmactest", "loader/bss/bss", "intr/intr", @@ -134,7 +135,6 @@ tests_next = [ "audio/atrac/atractest", "audio/mp3/mp3test", "audio/sascore/sascore", - "display/vblankmulti", "malloc/malloc", "threads/fpl/fpl", "threads/k0/k0", @@ -162,6 +162,7 @@ tests_next = [ "io/iodrv/iodrv", "modules/loadexec/loader", "rtc/rtc", + "sysmem/partition", "sysmem/sysmem", "umd/io/umd_io", "umd/raw_access/raw_access",