diff options
| author | iCatButler <i.am.catbutler@gmail.com> | 2018-03-19 07:39:08 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-19 07:39:08 +0000 |
| commit | 6f76041029393c6823973a29426b28c8c2d0b064 (patch) | |
| tree | 13c1bb5215c2510a7c430b59bc22df666cd2fbf3 /libpcsxcore | |
| parent | 768332417644451d38ce1a737465656c7cc75de3 (diff) | |
| parent | 128d6afb179756513860187cf5e31d84d6d8cac4 (diff) | |
Merge pull request #7 from loathingKernel/sync-with-codeplex
Sync with codeplex
Diffstat (limited to 'libpcsxcore')
| -rw-r--r-- | libpcsxcore/CMakeLists.txt | 114 | ||||
| -rw-r--r-- | libpcsxcore/Makefile.am | 102 | ||||
| -rwxr-xr-x | libpcsxcore/cdrom.c | 4 | ||||
| -rwxr-xr-x | libpcsxcore/debug.c | 61 | ||||
| -rwxr-xr-x | libpcsxcore/gpu.c | 3 | ||||
| -rwxr-xr-x | libpcsxcore/gte.c | 18 | ||||
| -rwxr-xr-x | libpcsxcore/ix86/iR3000A.c | 152 | ||||
| -rwxr-xr-x | libpcsxcore/ix86_64/iR3000A-64.c | 6 | ||||
| -rwxr-xr-x | libpcsxcore/ix86_64/ix86_cpudetect.c | 2 | ||||
| -rwxr-xr-x | libpcsxcore/misc.c | 151 | ||||
| -rwxr-xr-x | libpcsxcore/misc.h | 1 | ||||
| -rwxr-xr-x | libpcsxcore/plugins.c | 40 | ||||
| -rwxr-xr-x | libpcsxcore/plugins.h | 6 | ||||
| -rwxr-xr-x | libpcsxcore/psxbios.c | 14 | ||||
| -rwxr-xr-x | libpcsxcore/psxcommon.c | 3 | ||||
| -rwxr-xr-x | libpcsxcore/psxcommon.h | 2 | ||||
| -rwxr-xr-x | libpcsxcore/psxcounters.c | 4 | ||||
| -rwxr-xr-x | libpcsxcore/psxdma.c | 2 | ||||
| -rwxr-xr-x | libpcsxcore/psxhw.c | 10 | ||||
| -rwxr-xr-x | libpcsxcore/psxinterpreter.c | 17 | ||||
| -rwxr-xr-x | libpcsxcore/psxmem.c | 30 | ||||
| -rwxr-xr-x | libpcsxcore/psxmem.h | 4 | ||||
| -rwxr-xr-x | libpcsxcore/r3000a.c | 1 | ||||
| -rwxr-xr-x | libpcsxcore/sio.c | 53 | ||||
| -rwxr-xr-x | libpcsxcore/sio.h | 2 |
25 files changed, 458 insertions, 344 deletions
diff --git a/libpcsxcore/CMakeLists.txt b/libpcsxcore/CMakeLists.txt new file mode 100644 index 00000000..a3a0fd34 --- /dev/null +++ b/libpcsxcore/CMakeLists.txt @@ -0,0 +1,114 @@ +message(STATUS "* Configuring core") + +set(DYNAREC "auto" CACHE STRING "Build dynarec for arch.") +set_property(CACHE DYNAREC PROPERTY STRINGS auto x86_64 x86 ppc no) + +option(ENABLE_CCDDA "Enables compressed CDDA support." OFF) +option(USE_LIBARCHIVE "Enables compressed data-tracks support." OFF) + +if (ENABLE_CCDDA) + find_package(FFMPEG REQUIRED) + include_directories(${FFMPEG_INCLUDE_DIRS}) + add_definitions(-DENABLE_CCDDA) +endif() + +if (USE_LIBARCHIVE) + find_package(LibArchive REQUIRED) + include_directories(${LibArchive_INCLUDE_DIRS}) + add_definitions(-DHAVE_LIBARCHIVE) +endif() + +# Architecture detection and arch specific settings +message(STATUS "Building PCSXr on arch " ${CMAKE_SYSTEM_PROCESSOR}) +include(TargetArch) +target_architecture(PCSXR_TARGET_ARCH) +message(STATUS "Targeting arch " ${PCSXR_TARGET_ARCH}) +if (${PCSXR_TARGET_ARCH} MATCHES "ppc") + set(_ARCH_PPC 1) +elseif(${PCSXR_TARGET_ARCH} MATCHES "i386") + set(_ARCH_32 1) +elseif(${PCSXR_TARGET_ARCH} MATCHES "x86_64") + set(_ARCH_64 1) +else() + message(STATUS "Unsupported arch. Will not build dynarec") + add_definitions(-DNOPSXREC) +endif() +set(CMAKE_POSITION_INDEPENDENT_CODE OFF) #for x86 + +if (${DYNAREC} STREQUAL "auto") + if (_ARCH_PPC) + set(DYNAREC_PPC 1) + message(STATUS "Autodetected PPC dynarec.") + elseif(_ARCH_64) + set(DYNAREC_64 1) + message(STATUS "Autodetected x86_64 dynarec.") + elseif(_ARCH_32) + set(DYNAREC_32 1) + message(STATUS "Autodetected x86 dynarec.") + endif() +elseif (${DYNAREC} STREQUAL "ppc") +#if anyone ever fixes ppc dynarec +# set(DYNAREC_PPC 1) +# message(STATUS "User selected PPC dynarec") + message(STATUS "User selected PPC dynarec is broken, sorry.") + add_definitions(-DNOPSXREC) +elseif (${DYNAREC} STREQUAL "x86_64") + set(DYNAREC_64 1) + message(STATUS "User selected x86_64 dynarec.") +elseif (${DYNAREC} STREQUAL "x86") + set(DYNAREC_32 1) + message(STATUS "User selected x86 dynarec.") +elseif (${DYNAREC} STREQUAL "no") + message(STATUS "User selected to not build dynarec.") + add_definitions(-DNOPSXREC) +endif() + + +set(SRCS psxbios.c + cdrom.c + psxcounters.c + psxdma.c + disr3000a.c + gpu.c + spu.c + sio.c + psxhw.c + mdec.c + psxmem.c + misc.c + plugins.c + decode_xa.c + r3000a.c + psxinterpreter.c + gte.c + psxhle.c + debug.c + psxcommon.c + cdriso.c + cheat.c + socket.c + ppf.c + pgxp_cpu.c + pgxp_debug.c + pgxp_gte.c + pgxp_mem.c + pgxp_value.c +) + +set(LIBS "-lm") + +if(DYNAREC_64) + file(GLOB_RECURSE DYNAREC_SRC ix86_64/*.c) +elseif(DYNAREC_32) + file(GLOB_RECURSE DYNAREC_SRC ix86/*.c) +elseif(DYNAREC_PPC) + enable_language(ASM-ATT) + SET(CMAKE_ASM-ATT_SOURCE_FILE_EXTENSIONS nasm;nas;asm;s) + file(GLOB_RECURSE DYNAREC_SRC ppc/*.c) + set(DYNAREC_SRC ${DYNAREC_SRC} ppc/pasm.s) +endif() + +set(SRCS ${SRCS} ${DYNAREC_SRC}) + +add_library(pcsxcore STATIC ${SRCS}) +target_link_libraries(pcsxcore ${FFMPEG_LIBRARIES} ${LibArchive_LIBRARIES} ${LIBS}) diff --git a/libpcsxcore/Makefile.am b/libpcsxcore/Makefile.am deleted file mode 100644 index ee585ab7..00000000 --- a/libpcsxcore/Makefile.am +++ /dev/null @@ -1,102 +0,0 @@ -AM_CPPFLAGS = -DLOCALE_DIR=\"${datadir}/locale/\" \ - -I$(top_srcdir)/include - -noinst_LIBRARIES = libpcsxcore.a - -libpcsxcore_a_SOURCES = \ - psxbios.c \ - cdrom.c \ - psxcounters.c \ - psxdma.c \ - disr3000a.c \ - gpu.c \ - gpu.h \ - spu.c \ - sio.c \ - psxhw.c \ - mdec.c \ - psxmem.c \ - misc.c \ - plugins.c \ - decode_xa.c \ - r3000a.c \ - psxinterpreter.c \ - gte.c \ - psxhle.c \ - cdrom.h \ - coff.h \ - debug.c \ - debug.h \ - decode_xa.h \ - ecm.h \ - gte.h \ - mdec.h \ - misc.h \ - plugins.h \ - psemu_plugin_defs.h \ - psxbios.h \ - psxcommon.c \ - psxcommon.h \ - psxcounters.h \ - psxdma.h \ - psxhle.h \ - psxhw.h \ - psxmem.h \ - r3000a.h \ - sio.h \ - sjisfont.h \ - spu.h \ - system.h \ - cdriso.c \ - cdriso.h \ - cheat.c \ - cheat.h \ - socket.c \ - socket.h \ - ppf.c \ - ppf.h \ - pgxp_cpu.c \ - pgxp_cpu.h \ - pgxp_debug.c \ - pgxp_debug.h \ - pgxp_gte.c \ - pgxp_gte.h \ - pgxp_mem.c \ - pgxp_mem.h \ - pgxp_value.c \ - pgxp_value.h - -if ARCH_X86_64 -libpcsxcore_a_SOURCES += \ - ix86_64/iGte.h \ - ix86_64/iR3000A-64.c \ - ix86_64/ix86-64.c \ - ix86_64/ix86-64.h \ - ix86_64/ix86_cpudetect.c \ - ix86_64/ix86_fpu.c \ - ix86_64/ix86_3dnow.c \ - ix86_64/ix86_mmx.c \ - ix86_64/ix86_sse.c \ - ix86_64/iPGXP.h -else -if ARCH_X86 -libpcsxcore_a_SOURCES += \ - ix86/iGte.h \ - ix86/iR3000A.c \ - ix86/ix86.c \ - ix86/ix86.h \ - ix86/iPGXP.h -endif -endif - -if ARCH_PPC -libpcsxcore_a_SOURCES += \ - ppc/pGte.h \ - ppc/pR3000A.c \ - ppc/ppc.c \ - ppc/ppc.h \ - ppc/ppc_mnemonics.h \ - ppc/reguse.c \ - ppc/reguse.h -libpcsxcore_a_CCASFLAGS = -x assembler-with-cpp -mregnames -D__POWERPC__ -endif diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index f92cdd22..b0d462c6 100755 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -1516,9 +1516,9 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) { cdr.transferIndex++; adjustTransferIndex(); } - +#ifdef PSXREC psxCpu->Clear(madr, cdsize / 4); - +#endif // burst vs normal if( chcr == 0x11400100 ) { CDRDMA_INT( (cdsize/4) / 4 ); diff --git a/libpcsxcore/debug.c b/libpcsxcore/debug.c index b5497d11..a4e9ab35 100755 --- a/libpcsxcore/debug.c +++ b/libpcsxcore/debug.c @@ -230,6 +230,10 @@ Error messages (5xx): */ static int debugger_active = 0, paused = 0, trace = 0, printpc = 0, reset = 0, resetting = 0; +static int run_to = 0; +static u32 run_to_addr = 0; +static int step_over = 0; +static u32 step_over_addr = 0; static int mapping_e = 0, mapping_r8 = 0, mapping_r16 = 0, mapping_r32 = 0, mapping_w8 = 0, mapping_w16 = 0, mapping_w32 = 0; static int breakmp_e = 0, breakmp_r8 = 0, breakmp_r16 = 0, breakmp_r32 = 0, breakmp_w8 = 0, breakmp_w16 = 0, breakmp_w32 = 0; @@ -393,13 +397,34 @@ void ProcessDebug() { } } if (!paused) { - if(trace && printpc) - { + if(trace && printpc) { char reply[256]; sprintf(reply, "219 %s\r\n", disR3000AF(psxMemRead32(psxRegs.pc), psxRegs.pc)); WriteSocket(reply, strlen(reply)); } + if(step_over) { + if(psxRegs.pc == step_over_addr) { + char reply[256]; + step_over = 0; + step_over_addr = 0; + sprintf(reply, "050 @%08X\r\n", psxRegs.pc); + WriteSocket(reply, strlen(reply)); + paused = 1; + } + } + + if(run_to) { + if(psxRegs.pc == run_to_addr) { + char reply[256]; + run_to = 0; + run_to_addr = 0; + sprintf(reply, "040 @%08X\r\n", psxRegs.pc); + WriteSocket(reply, strlen(reply)); + paused = 1; + } + } + DebugCheckBP(psxRegs.pc, BE); } if (mapping_e) { @@ -1078,6 +1103,37 @@ static void ProcessCommands() { reset = 1; sprintf(reply, "499 Resetting\r\n"); break; + case 0x3A0: + // run to + p = arguments; + if (arguments) { + run_to = 1; + run_to_addr = strtol(arguments, &p, 16); + paused = 0; + } + if (p == arguments) { + sprintf(reply, "500 Malformed 3A0 command '%s'\r\n", arguments); + break; + } + sprintf(reply, "4A0 run to addr %08X\r\n", run_to_addr); + break; + case 0x3A1: + // step over (jal) + if(paused) { + u32 opcode = psxMemRead32(psxRegs.pc); + if((opcode >> 26) == 3) { + step_over = 1; + step_over_addr = psxRegs.pc + 8; + paused = 0; + + sprintf(reply, "4A1 step over addr %08X\r\n", psxRegs.pc); + } + else { + trace = 1; + paused = 0; + } + } + break; default: sprintf(reply, "500 Unknown command '%s'\r\n", cmd); break; @@ -1100,6 +1156,7 @@ void DebugCheckBP(u32 address, enum breakpoint_types type) { if (!debugger_active || reset) return; + for (bp = first; bp; bp = next_breakpoint(bp)) { if ((bp->type == type) && (bp->address == address)) { sprintf(reply, "030 %X@%08X\r\n", bp->number, psxRegs.pc); diff --git a/libpcsxcore/gpu.c b/libpcsxcore/gpu.c index 37367363..d34093ea 100755 --- a/libpcsxcore/gpu.c +++ b/libpcsxcore/gpu.c @@ -118,8 +118,9 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU // BA blocks * BS words (word = 32-bits) size = (bcr >> 16) * (bcr & 0xffff); GPU_readDataMem(ptr, size); +#ifdef PSXREC psxCpu->Clear(madr, size); - +#endif #if 1 // already 32-bit word size ((size * 4) / 4) GPUDMA_INT(size); diff --git a/libpcsxcore/gte.c b/libpcsxcore/gte.c index 7965a0e9..bd9c30c6 100755 --- a/libpcsxcore/gte.c +++ b/libpcsxcore/gte.c @@ -250,40 +250,34 @@ static void CTC2(u32 value, int reg) { psxRegs.CP2C.p[reg].d = value; } -void gteMFC2() -{ +void gteMFC2() { // CPU[Rt] = GTE_D[Rd] if (!_Rt_) return; psxRegs.GPR.r[_Rt_] = MFC2(_Rd_); } -void gteCFC2() -{ +void gteCFC2() { // CPU[Rt] = GTE_C[Rd] if (!_Rt_) return; psxRegs.GPR.r[_Rt_] = psxRegs.CP2C.p[_Rd_].d; } -void gteMTC2() -{ +void gteMTC2() { MTC2(psxRegs.GPR.r[_Rt_], _Rd_); } -void gteCTC2() -{ +void gteCTC2() { CTC2(psxRegs.GPR.r[_Rt_], _Rd_); } #define _oB_ (psxRegs.GPR.r[_Rs_] + _Imm_) void gteLWC2() { - u32 val = psxMemRead32(_oB_); - MTC2(val, _Rt_); + MTC2(psxMemRead32(_oB_), _Rt_); } void gteSWC2() { - u32 val = MFC2(_Rt_); - psxMemWrite32(_oB_, val); + psxMemWrite32(_oB_, MFC2(_Rt_)); } static inline s64 gte_shift(s64 a, int sf) { diff --git a/libpcsxcore/ix86/iR3000A.c b/libpcsxcore/ix86/iR3000A.c index 66fac432..ff806172 100755 --- a/libpcsxcore/ix86/iR3000A.c +++ b/libpcsxcore/ix86/iR3000A.c @@ -25,9 +25,9 @@ #include "ix86.h" #include <sys/mman.h> -#include "pgxp_cpu.h" -#include "pgxp_gte.h" -#include "pgxp_debug.h" +#include "../pgxp_cpu.h" +#include "../pgxp_gte.h" +#include "../pgxp_debug.h" #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON @@ -156,12 +156,10 @@ static void iFlushRegs() { } } -static void iPushReg(int reg) -{ +static void iPushReg(int reg) { if (IsConst(reg)) { PUSH32I(iRegs[reg].k); - } - else { + } else { PUSH32M((u32)&psxRegs.GPR.r[reg]); } } @@ -619,9 +617,6 @@ static void recADDIU() { // iFlushRegs(); - - - if (_Rs_ == _Rt_) { if (IsConst(_Rt_)) { iRegs[_Rt_].k+= _Imm_; @@ -651,7 +646,6 @@ static void recADDIU() { MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } } - } static void recADDI() { @@ -660,46 +654,35 @@ static void recADDI() { // iFlushRegs(); - - - if (_Rs_ == _Rt_) { if (IsConst(_Rt_)) { iRegs[_Rt_].k += _Imm_; - } - else { + } else { if (_Imm_ == 1) { INC32M((u32)&psxRegs.GPR.r[_Rt_]); - } - else if (_Imm_ == -1) { + } else if (_Imm_ == -1) { DEC32M((u32)&psxRegs.GPR.r[_Rt_]); - } - else if (_Imm_) { + } else if (_Imm_) { ADD32ItoM((u32)&psxRegs.GPR.r[_Rt_], _Imm_); } } - } - else { + } else { if (IsConst(_Rs_)) { MapConst(_Rt_, iRegs[_Rs_].k + _Imm_); - } - else { + } else { iRegs[_Rt_].state = ST_UNK; MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); if (_Imm_ == 1) { INC32R(EAX); - } - else if (_Imm_ == -1) { + } else if (_Imm_ == -1) { DEC32R(EAX); - } - else if (_Imm_) { + } else if (_Imm_) { ADD32ItoR(EAX, _Imm_); } MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } } - } static void recSLTI() { @@ -708,7 +691,6 @@ static void recSLTI() { // iFlushRegs(); - if (IsConst(_Rs_)) { MapConst(_Rt_, (s32)iRegs[_Rs_].k < _Imm_); } else { @@ -720,8 +702,6 @@ static void recSLTI() { AND32ItoR(EAX, 0xff); MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } - - } static void recSLTIU() { @@ -730,7 +710,6 @@ static void recSLTIU() { // iFlushRegs(); - if (IsConst(_Rs_)) { MapConst(_Rt_, iRegs[_Rs_].k < _ImmU_); } else { @@ -742,8 +721,6 @@ static void recSLTIU() { AND32ItoR(EAX, 0xff); MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } - - } static void recANDI() { @@ -752,7 +729,6 @@ static void recANDI() { // iFlushRegs(); - if (_Rs_ == _Rt_) { if (IsConst(_Rt_)) { iRegs[_Rt_].k&= _ImmU_; @@ -770,14 +746,13 @@ static void recANDI() { MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } } - - } static void recORI() { // Rt = Rs Or Im if (!_Rt_) return; +// iFlushRegs(); if (_Rs_ == _Rt_) { if (IsConst(_Rt_)) { @@ -796,14 +771,13 @@ static void recORI() { MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } } - - } static void recXORI() { // Rt = Rs Xor Im if (!_Rt_) return; +// iFlushRegs(); if (_Rs_ == _Rt_) { if (IsConst(_Rt_)) { @@ -822,8 +796,6 @@ static void recXORI() { MOV32RtoM((u32)&psxRegs.GPR.r[_Rt_], EAX); } } - - } //#endif //end of * Arithmetic with immediate operand @@ -839,8 +811,6 @@ static void recLUI() { if (!_Rt_) return; MapConst(_Rt_, psxRegs.code << 16); - - } //#endif //End of Load Higher ..... @@ -869,9 +839,6 @@ static void recADDU() { // iFlushRegs(); - - - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rs_].k + iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -933,8 +900,6 @@ static void recADDU() { MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } } - - } static void recADD() { @@ -948,8 +913,6 @@ static void recSUBU() { // iFlushRegs(); - - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rs_].k - iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -971,8 +934,6 @@ static void recSUBU() { SUB32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSUB() { @@ -986,7 +947,6 @@ static void recAND() { // iFlushRegs(); - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rs_].k & iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -1024,8 +984,6 @@ static void recAND() { MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } } - - } static void recOR() { @@ -1034,8 +992,6 @@ static void recOR() { // iFlushRegs(); - - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rs_].k | iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -1057,8 +1013,6 @@ static void recOR() { OR32MtoR (EAX, (u32)&psxRegs.GPR.r[_Rt_]); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recXOR() { @@ -1067,8 +1021,6 @@ static void recXOR() { // iFlushRegs(); - - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rs_].k ^ iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -1090,8 +1042,6 @@ static void recXOR() { XOR32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recNOR() { @@ -1100,7 +1050,6 @@ static void recNOR() { // iFlushRegs(); - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, ~(iRegs[_Rs_].k | iRegs[_Rt_].k)); } else if (IsConst(_Rs_)) { @@ -1125,8 +1074,6 @@ static void recNOR() { NOT32R (EAX); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSLT() { @@ -1135,8 +1082,6 @@ static void recSLT() { // iFlushRegs(); - - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, (s32)iRegs[_Rs_].k < (s32)iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -1164,8 +1109,6 @@ static void recSLT() { AND32ItoR(EAX, 0xff); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSLTU() { @@ -1174,8 +1117,6 @@ static void recSLTU() { // iFlushRegs(); - - if (IsConst(_Rs_) && IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rs_].k < iRegs[_Rt_].k); } else if (IsConst(_Rs_)) { @@ -1203,8 +1144,6 @@ static void recSLTU() { NEG32R (EAX); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } //#endif //End of * Register arithmetic @@ -1224,14 +1163,11 @@ static void recMULT() { // iFlushRegs(); - if ((IsConst(_Rs_) && iRegs[_Rs_].k == 0) || (IsConst(_Rt_) && iRegs[_Rt_].k == 0)) { XOR32RtoR(EAX, EAX); MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); - - return; } @@ -1248,8 +1184,6 @@ static void recMULT() { } MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); - - } static void recMULTU() { @@ -1257,15 +1191,11 @@ static void recMULTU() { // iFlushRegs(); - - if ((IsConst(_Rs_) && iRegs[_Rs_].k == 0) || (IsConst(_Rt_) && iRegs[_Rt_].k == 0)) { XOR32RtoR(EAX, EAX); MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); - - return; } @@ -1282,8 +1212,6 @@ static void recMULTU() { } MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EDX); - - } static void recDIV() { @@ -1291,8 +1219,6 @@ static void recDIV() { // iFlushRegs(); - - if (IsConst(_Rt_)) { if (iRegs[_Rt_].k == 0) { MOV32ItoM((u32)&psxRegs.GPR.n.lo, 0xffffffff); @@ -1302,8 +1228,6 @@ static void recDIV() { MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); } - - return; } MOV32ItoR(ECX, iRegs[_Rt_].k);// printf("divrtk %x\n", iRegs[_Rt_].k); @@ -1337,8 +1261,6 @@ static void recDIV() { x86SetJ8(j8Ptr[1]); } - - } static void recDIVU() { @@ -1346,8 +1268,6 @@ static void recDIVU() { // iFlushRegs(); - - if (IsConst(_Rt_)) { if (iRegs[_Rt_].k == 0) { MOV32ItoM((u32)&psxRegs.GPR.n.lo, 0xffffffff); @@ -1357,8 +1277,6 @@ static void recDIVU() { MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); } - - return; } MOV32ItoR(ECX, iRegs[_Rt_].k);// printf("divurtk %x\n", iRegs[_Rt_].k); @@ -1392,8 +1310,6 @@ static void recDIVU() { x86SetJ8(j8Ptr[1]); } - - } //#endif //End of * Register mult/div & Register trap logic @@ -1474,7 +1390,6 @@ static void recLB() { resp+= 4; } - static void recLBU() { // Rt = mem[Rs + Im] (unsigned) @@ -1520,7 +1435,6 @@ static void recLBU() { resp+= 4; } - static void recLH() { // Rt = mem[Rs + Im] (signed) @@ -1566,7 +1480,6 @@ static void recLH() { resp+= 4; } - static void recLHU() { // Rt = mem[Rs + Im] (unsigned) @@ -1661,7 +1574,6 @@ static void recLHU() { resp+= 4; } - static void recLW() { // Rt = mem[Rs + Im] (unsigned) @@ -1974,7 +1886,6 @@ void recLWR() { } } - static void recSB() { // mem[Rs + Im] = Rt @@ -2053,7 +1964,6 @@ static void recSH() { MOV16MtoR(EAX, (u32)&psxRegs.GPR.r[_Rt_]); MOV16RtoM((u32)&psxH[addr & 0xfff], EAX); } - return; } if (t == 0x1f80) { @@ -2261,7 +2171,6 @@ void iSWLk(u32 shift) { OR32RtoR (EAX, ECX); } - void recSWL() { // mem[Rs + Im] = Rt Merge mem[Rs + Im] @@ -2281,7 +2190,6 @@ void recSWL() { MOV32MtoR(EAX, (u32)&psxH[addr & 0xffc]); iSWLk(addr & 3); MOV32RtoM((u32)&psxH[addr & 0xffc], EAX); - return; } } @@ -2424,8 +2332,6 @@ static void recSLL() { // iFlushRegs(); - - if (IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rt_].k << _Sa_); } else { @@ -2435,8 +2341,6 @@ static void recSLL() { if (_Sa_) SHL32ItoR(EAX, _Sa_); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSRL() { @@ -2446,7 +2350,6 @@ static void recSRL() { // iFlushRegs(); - if (IsConst(_Rt_)) { MapConst(_Rd_, iRegs[_Rt_].k >> _Sa_); } else { @@ -2456,8 +2359,6 @@ static void recSRL() { if (_Sa_) SHR32ItoR(EAX, _Sa_); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSRA() { @@ -2467,7 +2368,6 @@ static void recSRA() { // iFlushRegs(); - if (IsConst(_Rt_)) { MapConst(_Rd_, (s32)iRegs[_Rt_].k >> _Sa_); } else { @@ -2477,8 +2377,6 @@ static void recSRA() { if (_Sa_) SAR32ItoR(EAX, _Sa_); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } //#endif @@ -2493,7 +2391,6 @@ static void recSLLV() { // iFlushRegs(); - if (IsConst(_Rt_) && IsConst(_Rs_)) { MapConst(_Rd_, iRegs[_Rt_].k << iRegs[_Rs_].k); } else if (IsConst(_Rs_)) { @@ -2518,8 +2415,6 @@ static void recSLLV() { SHL32CLtoR(EAX); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSRLV() { @@ -2528,7 +2423,6 @@ static void recSRLV() { // iFlushRegs(); - if (IsConst(_Rt_) && IsConst(_Rs_)) { MapConst(_Rd_, iRegs[_Rt_].k >> iRegs[_Rs_].k); } else if (IsConst(_Rs_)) { @@ -2553,8 +2447,6 @@ static void recSRLV() { SHR32CLtoR(EAX); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } static void recSRAV() { @@ -2564,7 +2456,6 @@ static void recSRAV() { // iFlushRegs(); - if (IsConst(_Rt_) && IsConst(_Rs_)) { MapConst(_Rd_, (s32)iRegs[_Rt_].k >> iRegs[_Rs_].k); } else if (IsConst(_Rs_)) { @@ -2589,8 +2480,6 @@ static void recSRAV() { SAR32CLtoR(EAX); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); } - - } //#endif @@ -2628,26 +2517,20 @@ static void recMFHI() { if (!_Rd_) return; - iRegs[_Rd_].state = ST_UNK; MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.hi); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - - } static void recMTHI() { // Hi = Rs - if (IsConst(_Rs_)) { MOV32ItoM((u32)&psxRegs.GPR.n.hi, iRegs[_Rs_].k); } else { MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); MOV32RtoM((u32)&psxRegs.GPR.n.hi, EAX); } - - } static void recMFLO() { @@ -2655,25 +2538,20 @@ static void recMFLO() { if (!_Rd_) return; - iRegs[_Rd_].state = ST_UNK; MOV32MtoR(EAX, (u32)&psxRegs.GPR.n.lo); MOV32RtoM((u32)&psxRegs.GPR.r[_Rd_], EAX); - } static void recMTLO() { // Lo = Rs - if (IsConst(_Rs_)) { MOV32ItoM((u32)&psxRegs.GPR.n.lo, iRegs[_Rs_].k); } else { MOV32MtoR(EAX, (u32)&psxRegs.GPR.r[_Rs_]); MOV32RtoM((u32)&psxRegs.GPR.n.lo, EAX); } - - } //#endif @@ -3089,7 +2967,6 @@ static void recHLE() { } // - #include "iPGXP.h" static void (*recBSC[64])() = { @@ -3146,7 +3023,6 @@ static void (*recCP2BSC[32])() = { recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL, recNULL }; - // Trace all functions using PGXP static void(*pgxpRecBSC[64])() = { recSPECIAL, recREGIMM, recJ , recJAL , recBEQ , recBNE , recBLEZ, recBGTZ, diff --git a/libpcsxcore/ix86_64/iR3000A-64.c b/libpcsxcore/ix86_64/iR3000A-64.c index 64d9c1d5..15554338 100755 --- a/libpcsxcore/ix86_64/iR3000A-64.c +++ b/libpcsxcore/ix86_64/iR3000A-64.c @@ -27,9 +27,9 @@ #include "../r3000a.h" #include "../psxhle.h" -#include "pgxp_cpu.h" -#include "pgxp_gte.h" -#include "pgxp_debug.h" +#include "../pgxp_cpu.h" +#include "../pgxp_gte.h" +#include "../pgxp_debug.h" #include <sys/mman.h> diff --git a/libpcsxcore/ix86_64/ix86_cpudetect.c b/libpcsxcore/ix86_64/ix86_cpudetect.c index c59186bf..9bbb67d5 100755 --- a/libpcsxcore/ix86_64/ix86_cpudetect.c +++ b/libpcsxcore/ix86_64/ix86_cpudetect.c @@ -145,7 +145,7 @@ u64 GetCPUTick( void ) #endif } -#if defined(__LINUX__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) #include <sys/time.h> #include <errno.h> diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index f54abeb6..3c3eb318 100755 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -52,6 +52,10 @@ struct iso_directory_record { char name [1]; }; +//local extern +void trim_key(char *str, char key ); +void split( char* str, char key, char* pout ); + void mmssdd( char *b, char *p ) { int m, s, d; @@ -261,7 +265,9 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) { addr = head->t_addr; // Cache clear/invalidate dynarec/int. Fixes startup of Casper/X-Files and possibly others. +#ifdef PSXREC psxCpu->Clear(addr, size / 4); +#endif psxRegs.ICache_valid = FALSE; while (size) { @@ -356,13 +362,9 @@ int CheckCdrom() { else Config.PsxType = PSX_TYPE_NTSC; // ntsc } - - if (Config.OverClock == 0) - { + if (Config.OverClock == 0) { PsxClockSpeed = 33868800; // 33.8688 MHz (stock) - } - else - { + } else { PsxClockSpeed = 33868800 * Config.PsxClock; } @@ -376,9 +378,22 @@ int CheckCdrom() { memset(Config.PsxExeName, 0, sizeof(Config.PsxExeName)); strncpy(Config.PsxExeName, exename, 11); - if(Config.PerGameMcd) - LoadMcds(Config.Mcd1, Config.Mcd2); - + if(Config.PerGameMcd) { + char mcd1path[MAXPATHLEN] = { '\0' }; + char mcd2path[MAXPATHLEN] = { '\0' }; +#ifdef _WINDOWS + sprintf(mcd1path, "memcards\\games\\%s-%02d.mcd", Config.PsxExeName, 1); + sprintf(mcd2path, "memcards\\games\\%s-%02d.mcd", Config.PsxExeName, 2); +#else + //lk: dot paths should not be hardcoded here, this is for testing only + sprintf(mcd1path, "%s/.pcsxr/memcards/games/%s-%02d.mcd", getenv("HOME"), Config.PsxExeName, 1); + sprintf(mcd2path, "%s/.pcsxr/memcards/games/%s-%02d.mcd", getenv("HOME"), Config.PsxExeName, 2); +#endif + strcpy(Config.Mcd1, mcd1path); + strcpy(Config.Mcd2, mcd2path); + LoadMcds(Config.Mcd1, Config.Mcd2); + } + BuildPPFCache(); LoadSBI(NULL); @@ -531,6 +546,95 @@ int Load(const char *ExePath) { return retval; } +static int LoadBin( unsigned long addr, char* filename ) { + int result = -1; + + FILE *f; + long len; + unsigned long mem = addr & 0x001fffff; + + // Load binery files + f = fopen(filename, "rb"); + if (f != NULL) { + fseek(f,0,SEEK_END); + len = ftell(f); + fseek(f,0,SEEK_SET); + if( len + mem < 0x00200000 ) { + if( psxM ) { + int readsize = fread(psxM + mem, len, 1, f); + if( readsize == len ) + result = 0; + } + } + fclose(f); + } + + if( result == 0 ) + SysPrintf(_("ng Load Bin file: [0x%08x] : %s\n"), addr, filename ); + else + SysPrintf(_("ok Load Bin file: [0x%08x] : %s\n"), addr, filename ); + + return result; +} + +int LoadLdrFile(const char *LdrPath ) { + FILE * tmpFile; + int retval = 0; //-1 is error, 0 is success + + tmpFile = fopen(LdrPath, "rt"); + if (tmpFile == NULL) { + SysPrintf(_("Error opening file: %s.\n"), LdrPath); + retval = -1; + } else { + int index = 0; + char sztext[16][256]; + + memset( sztext, 0x00, sizeof(sztext) ); + + while(index <= 15 && fgets( &sztext[index][0], 254, tmpFile )) { + + char szaddr[256]; + char szpath[256]; + char* psrc = &sztext[index][0]; + char* paddr; + char* ppath; + int len; + unsigned long addr = 0L; + + memset( szaddr, 0x00, sizeof(szaddr)); + memset( szpath, 0x00, sizeof(szpath)); + + len = strlen( psrc ); + if( len > 0 ) { + trim( psrc ); + trim_key( psrc, '\t' ); + split( psrc, '\t', szaddr ); + + paddr = szaddr; + ppath = psrc + strlen(paddr); + + //getting address + trim( paddr ); + trim_key( paddr, '\t' ); + addr = strtoul(szaddr, NULL, 16); + if( addr != 0 ) { + //getting bin filepath in ldrfile + trim( ppath ); + trim_key( ppath, '\t' ); + memmove( szpath, ppath, sizeof(szpath)); + + //Load binary to main memory + LoadBin( addr, szpath ); + } + } + + index++; + } + } + + return retval; +} + // STATES #define PCSXR_HEADER_SZ (10) #define SZ_GPUPIC (128 * 96 * 3) @@ -612,7 +716,7 @@ int SaveStateMem(const u32 id) { char name[32]; int ret = -1; - snprintf(name, 32, SHM_SS_NAME_TEMPLATE, id); + snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, id); int fd = shm_open(name, O_CREAT | O_RDWR | O_TRUNC, 0666); if (fd >= 0) { @@ -635,7 +739,7 @@ int LoadStateMem(const u32 id) { char name[32]; int ret = -1; - snprintf(name, 32, SHM_SS_NAME_TEMPLATE, id); + snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, id); int fd = shm_open(name, O_RDONLY, 0444); if (fd >= 0) { @@ -861,11 +965,15 @@ int RecvPcsxInfo() { // remove the leading and trailing spaces in a string void trim(char *str) { + trim_key( str, ' ' ); +} + +void trim_key(char *str, char key ) { int pos = 0; char *dest = str; // skip leading blanks - while (str[pos] <= ' ' && str[pos] > 0) + while (str[pos] <= key && str[pos] > 0) pos++; while (str[pos]) { @@ -876,10 +984,27 @@ void trim(char *str) { *(dest--) = '\0'; // store the null // remove trailing blanks - while (dest >= str && *dest <= ' ' && *dest > 0) + while (dest >= str && *dest <= key && *dest > 0) *(dest--) = '\0'; } +// split by the keys codes in strings +void split( char* str, char key, char* pout ) +{ + char* psrc = str; + char* pdst = pout; + int len = strlen(str); + int i; + for( i = 0; i < len; i++ ) { + if( psrc[i] == '\0' || psrc[i] == key ) { + *pdst = '\0'; + break; + } else { + *pdst++ = psrc[i]; + } + } +} + // lookup table for crc calculation static unsigned short crctab[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, diff --git a/libpcsxcore/misc.h b/libpcsxcore/misc.h index 860c1d29..2e44364f 100755 --- a/libpcsxcore/misc.h +++ b/libpcsxcore/misc.h @@ -60,6 +60,7 @@ int LoadCdrom(); int LoadCdromFile(const char *filename, EXE_HEADER *head); int CheckCdrom(); int Load(const char *ExePath); +int LoadLdrFile(const char *LdrPath); int SaveState(const char *file); int SaveStateMem(const u32 id); diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index 567630c8..a1175e48 100755 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -25,6 +25,9 @@ #include "cdriso.h" static char IsoFile[MAXPATHLEN] = ""; +static char ExeFile[MAXPATHLEN] = ""; +static char AppPath[MAXPATHLEN] = ""; //Application path(== pcsxr.exe directory) +static char LdrFile[MAXPATHLEN] = ""; //bin-load file static s64 cdOpenCaseTime = 0; GPUupdateLace GPU_updateLace; @@ -845,10 +848,47 @@ void SetIsoFile(const char *filename) { strncpy(IsoFile, filename, MAXPATHLEN); } +void SetExeFile(const char *filename) { + if (filename == NULL) { + ExeFile[0] = '\0'; + return; + } + strncpy(ExeFile, filename, MAXPATHLEN); +} + +// Set pcsxr.exe directory. This is not contain filename(and ext)). +void SetAppPath(const char *apppath ) { + if (apppath == NULL) { + AppPath[0] = '\0'; + return; + } + strncpy(AppPath, apppath, MAXPATHLEN); +} + +void SetLdrFile(const char *ldrfile ) { + if (ldrfile == NULL) { + LdrFile[0] = '\0'; + return; + } + strncpy(LdrFile, ldrfile, MAXPATHLEN); +} + const char *GetIsoFile(void) { return IsoFile; } +const char *GetExeFile(void) { + return ExeFile; +} + +const char *GetAppPath(void) { + return AppPath; +} + +const char *GetLdrFile(void) { + return LdrFile; +} + boolean UsingIso(void) { return (IsoFile[0] != '\0' || Config.Cdr[0] == '\0'); } diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index b7ba4cd3..a9756b7e 100755 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -422,7 +422,13 @@ extern SIO1registerCallback SIO1_registerCallback; void CALLBACK clearDynarec(void); void SetIsoFile(const char *filename); +void SetExeFile(const char *filename); +void SetAppPath(const char *filename); +void SetLdrFile(const char *ldrfile ); const char *GetIsoFile(void); +const char *GetExeFile(void); +const char *GetAppPath(void); +const char *GetLdrFile(void); boolean UsingIso(void); void SetCdOpenCaseTime(s64 time); diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 1249f596..61f9a463 100755 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -1744,7 +1744,7 @@ static void buopen(int mcd, u8 *ptr, u8 *cfg) SysPrintf("openC %s %d\n", ptr, nblk); v0 = 1 + mcd; /* just go ahead and resave them all */ - SaveMcd(mcd, cfg, ptr, 128, 128 * 15); + SaveMcd(cfg, ptr, 128, 128 * 15); break; } /* shouldn't this return ENOSPC if i == 16? */ @@ -1839,7 +1839,7 @@ void psxBios_read() { // 0x34 ptr = Mcd##mcd##Data + offset; \ memcpy(ptr, Ra1, a2); \ FDesc[1 + mcd].offset += a2; \ - SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \ + SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \ if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \ else v0 = a2; \ DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \ @@ -1936,7 +1936,7 @@ int nfile; ptr+= 0xa; \ if (pfile[0] == 0) { \ strncpy(dir->name, ptr, sizeof(dir->name)); \ - dir->name[sizeof(dir->name)] = '\0'; \ + dir->name[sizeof(dir->name) - 1] = '\0'; \ } else for (i=0; i<20; i++) { \ if (pfile[i] == ptr[i]) { \ dir->name[i] = ptr[i]; continue; } \ @@ -2023,7 +2023,7 @@ void psxBios_nextfile() { // 43 memset(ptr+0xa+namelen, 0, 0x75-namelen); \ for (j=0; j<127; j++) xor^= ptr[j]; \ ptr[127] = xor; \ - SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, 128 * i + 0xa, 0x76); \ + SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i + 0xa, 0x76); \ v0 = 1; \ break; \ } \ @@ -2061,7 +2061,7 @@ void psxBios_rename() { // 44 if ((*ptr & 0xF0) != 0x50) continue; \ if (strcmp(Ra0+5, ptr+0xa)) continue; \ *ptr = (*ptr & 0xf) | 0xA0; \ - SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, 128 * i, 1); \ + SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i, 1); \ SysPrintf("delete %s\n", ptr+0xa); \ v0 = 1; \ break; \ @@ -2135,10 +2135,10 @@ void psxBios__card_write() { // 0x4e if (port == 0) { memcpy(Mcd1Data + (sect * MCD_SECT_SIZE), Ra2, MCD_SECT_SIZE); - SaveMcd(1, Config.Mcd1, Mcd1Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); + SaveMcd(Config.Mcd1, Mcd1Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); } else { memcpy(Mcd2Data + (sect * MCD_SECT_SIZE), Ra2, MCD_SECT_SIZE); - SaveMcd(2, Config.Mcd2, Mcd2Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); + SaveMcd(Config.Mcd2, Mcd2Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); } DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 diff --git a/libpcsxcore/psxcommon.c b/libpcsxcore/psxcommon.c index ff846a11..b77d17a6 100755 --- a/libpcsxcore/psxcommon.c +++ b/libpcsxcore/psxcommon.c @@ -80,8 +80,7 @@ void EmuUpdate() { } } -void EmuSetPGXPMode(u32 pgxpMode) -{ +void EmuSetPGXPMode(u32 pgxpMode) { psxSetPGXPMode(pgxpMode); } diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h index f89044a2..f2fba819 100755 --- a/libpcsxcore/psxcommon.h +++ b/libpcsxcore/psxcommon.h @@ -71,7 +71,7 @@ typedef uint8_t boolean; #include "system.h" #include "debug.h" -#if defined (__LINUX__) || defined (__MACOSX__) +#if defined (__linux__) || defined (__MACOSX__) #define strnicmp strncasecmp #endif #define __inline inline diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c index 01fc7c2b..a6d7e10e 100755 --- a/libpcsxcore/psxcounters.c +++ b/libpcsxcore/psxcounters.c @@ -68,11 +68,13 @@ static const u32 FrameRate[] = { 60, 50 }; static const u32 VBlankStart[] = { 243, 256 }; static const u32 SpuUpdInterval[] = { 23, 22 }; -#if defined(PSXHW_LOG) && defined(PSXMEM_LOG) && defined(PSXDMA_LOG) // automatic guess if we want trace level logging +#if defined(PSXHW_LOG) +#if defined(PSXMEM_LOG) && defined(PSXDMA_LOG) // automatic guess if we want trace level logging static const s32 VerboseLevel = 4; #else static const s32 VerboseLevel = 0; #endif +#endif static const u16 JITTER_FLAGS = (Rc2OneEighthClock|RcIrqRegenerate|RcCountToTarget); /******************************************************************************/ diff --git a/libpcsxcore/psxdma.c b/libpcsxcore/psxdma.c index 4f5290bd..7443577a 100755 --- a/libpcsxcore/psxdma.c +++ b/libpcsxcore/psxdma.c @@ -68,7 +68,9 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU } size = (bcr >> 16) * (bcr & 0xffff) * 2; SPU_readDMAMem(ptr, size); +#ifdef PSXREC psxCpu->Clear(madr, size); +#endif #if 1 SPUDMA_INT((bcr >> 16) * (bcr & 0xffff) / 2); diff --git a/libpcsxcore/psxhw.c b/libpcsxcore/psxhw.c index 91aa4b32..58a2ba65 100755 --- a/libpcsxcore/psxhw.c +++ b/libpcsxcore/psxhw.c @@ -650,11 +650,11 @@ void psxHwWrite32(u32 add, u32 value) { PSXHW_LOG("DMA2 CHCR 32bit write %x\n", value); #endif /* A hack that makes Vampire Hunter D title screen visible, - /* but makes Tomb Raider II water effect to stay opaque - /* Root cause for this problem is that when DMA2 is issued - /* it is incompletele and still beign built by the game. - /* Maybe it is ready when some signal comes in or within given delay? - */ + * but makes Tomb Raider II water effect to stay opaque + * Root cause for this problem is that when DMA2 is issued + * it is incompletele and still beign built by the game. + * Maybe it is ready when some signal comes in or within given delay? + */ if (dmaGpuListHackEn && value == 0x00000401 && HW_DMA2_BCR == 0x0) { psxDma2(SWAPu32(HW_DMA2_MADR), SWAPu32(HW_DMA2_BCR), SWAPu32(value)); return; diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c index 6aa5ac15..a4f38e6d 100755 --- a/libpcsxcore/psxinterpreter.c +++ b/libpcsxcore/psxinterpreter.c @@ -559,14 +559,20 @@ void psxSLTU() { if (!_Rd_) return; _rRd_ = _u32(_rRs_) < _u32(_rRt_); } // Rd * Format: OP rs, rt * *********************************************************/ void psxDIV() { - if (_i32(_rRt_) != 0) { + if (!_i32(_rRt_)) { + if (_i32(_rRs_) & 0x80000000) { + _i32(_rLo_) = 1; + } else { + _i32(_rLo_) = 0xFFFFFFFF; + _i32(_rHi_) = _i32(_rRs_); + } + } else if (_i32(_rRs_) == 0x80000000 && _i32(_rRt_) == 0xFFFFFFFF) { + _i32(_rLo_) = 0x80000000; + _i32(_rHi_) = 0; + } else { _i32(_rLo_) = _i32(_rRs_) / _i32(_rRt_); _i32(_rHi_) = _i32(_rRs_) % _i32(_rRt_); } - else { - _i32(_rLo_) = 0xffffffff; - _i32(_rHi_) = _i32(_rRs_); - } } void psxDIVU() { @@ -1115,7 +1121,6 @@ void (*psxCP2BSC[32])() = { }; #include "psxinterpreter_pgxp.h" - // Trace all functions using PGXP static void(*pgxpPsxBSC[64])() = { psxSPECIAL, psxREGIMM, psxJ , psxJAL , psxBEQ , psxBNE , psxBLEZ, psxBGTZ, diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index bc2a0ca0..f8013886 100755 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -107,16 +107,21 @@ int psxMemInit() { void psxMemReset() { FILE *f = NULL; - char bios[1024]; + char bios[1024] = { '\0' }; memset(psxM, 0, 0x00200000); memset(psxP, 0, 0x00010000); // Load BIOS if (strcmp(Config.Bios, "HLE") != 0) { - sprintf(bios, "%s/%s", Config.BiosDir, Config.Bios); - f = fopen(bios, "rb"); + //AppPath's priority is high. + const char* apppath = GetAppPath(); + if( strlen(apppath) > 0 ) + strcat( strcat( strcat( bios, GetAppPath() ), "bios\\"), Config.Bios ); + else + sprintf(bios, "%s/%s", Config.BiosDir, Config.Bios); + f = fopen(bios, "rb"); if (f == NULL) { SysMessage(_("Could not open BIOS:\"%s\". Enabling HLE Bios!\n"), bios); memset(psxR, 0, 0x80000); @@ -125,6 +130,7 @@ void psxMemReset() { fread(psxR, 1, 0x80000, f); fclose(f); Config.HLE = FALSE; + SysPrintf(_("Loaded BIOS: %s\n"), bios ); } } else Config.HLE = TRUE; } @@ -143,8 +149,7 @@ u8 psxMemRead8(u32 mem) { char *p; u32 t; - if (!Config.MemHack) - { + if (!Config.MemHack) { psxRegs.cycle += 0; } @@ -173,8 +178,7 @@ u16 psxMemRead16(u32 mem) { char *p; u32 t; - if (!Config.MemHack) - { + if (!Config.MemHack) { psxRegs.cycle += 1; } @@ -203,8 +207,7 @@ u32 psxMemRead32(u32 mem) { char *p; u32 t; - if (!Config.MemHack) - { + if (!Config.MemHack) { psxRegs.cycle += 1; } @@ -233,8 +236,7 @@ void psxMemWrite8(u32 mem, u8 value) { char *p; u32 t; - if (!Config.MemHack) - { + if (!Config.MemHack) { psxRegs.cycle += 1; } @@ -265,8 +267,7 @@ void psxMemWrite16(u32 mem, u16 value) { char *p; u32 t; - if (!Config.MemHack) - { + if (!Config.MemHack) { psxRegs.cycle += 1; } @@ -297,8 +298,7 @@ void psxMemWrite32(u32 mem, u32 value) { char *p; u32 t; - if (!Config.MemHack) - { + if (!Config.MemHack) { psxRegs.cycle += 1; } diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index 08d16197..a1e32b4f 100755 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -31,8 +31,8 @@ extern "C" { #define _SWAP16(b) ((((unsigned char *)&(b))[0] & 0xff) | (((unsigned char *)&(b))[1] & 0xff) << 8) #define _SWAP32(b) ((((unsigned char *)&(b))[0] & 0xff) | ((((unsigned char *)&(b))[1] & 0xff) << 8) | ((((unsigned char *)&(b))[2] & 0xff) << 16) | (((unsigned char *)&(b))[3] << 24)) -#define SWAP16(v) ((((v) & 0xff00) >> 8) +(((v) & 0xff) << 8)) -#define SWAP32(v) ((((v) & 0xff000000ul) >> 24) + (((v) & 0xff0000ul) >> 8) + (((v) & 0xff00ul)<<8) +(((v) & 0xfful) << 24)) +#define SWAP16(v) ((((v) & 0xff00) >> 8) | (((v) & 0xff) << 8)) +#define SWAP32(v) ((((v) & 0xff000000ul) >> 24) | (((v) & 0xff0000ul) >> 8) | (((v) & 0xff00ul)<<8) | (((v) & 0xfful) << 24)) #define SWAPu32(v) SWAP32((u32)(v)) #define SWAPs32(v) SWAP32((s32)(v)) diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index 61adc5c0..fd0a2414 100755 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -46,6 +46,7 @@ int psxInit() { if (psxMemInit() == -1) return -1; PGXP_Init(); + PauseDebugger(); return psxCpu->Init(); } diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index dfa79bb1..76742352 100755 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -801,11 +801,11 @@ unsigned char sioRead8() { switch (CtrlReg & 0x2002) { case 0x0002: memcpy(Mcd1Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); - SaveMcd(1, Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128); + SaveMcd(Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128); break; case 0x2002: memcpy(Mcd2Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); - SaveMcd(2, Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128); + SaveMcd(Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128); break; } } @@ -884,29 +884,30 @@ void sioInterrupt() { void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; - char Mcd[MAXPATHLEN]; + char filepath[MAXPATHLEN] = { '\0' }; + const char *apppath = GetAppPath(); if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; - if (Config.PerGameMcd && mcd && strlen(Config.PsxExeName)) - sprintf(Mcd, "memcards\\games\\%s-%02d.mcr", Config.PsxExeName, mcd-1); - else - strcpy(Mcd, str); - - if (*Mcd == 0) { + if (*str == 0) { SysPrintf(_("No memory card value was specified - card %i is not plugged.\n"), mcd); return; } - f = fopen(Mcd, "rb"); + + //Getting full application path. + memmove(filepath, apppath, strlen(apppath)); + strcat(filepath, str); + + f = fopen(filepath, "rb"); if (f == NULL) { - SysPrintf(_("The memory card %s doesn't exist - creating it\n"), Mcd); - CreateMcd(Mcd); - f = fopen(Mcd, "rb"); + SysPrintf(_("The memory card %s doesn't exist - creating it\n"), filepath); + CreateMcd(filepath); + f = fopen(filepath, "rb"); if (f != NULL) { struct stat buf; - if (stat(Mcd, &buf) != -1) { + if (stat(filepath, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) @@ -916,12 +917,12 @@ void LoadMcd(int mcd, char *str) { fclose(f); } else - SysMessage(_("Memory card %s failed to load!\n"), Mcd); + SysMessage(_("Memory card %s failed to load!\n"), filepath); } else { struct stat buf; - SysPrintf(_("Loading memory card %s\n"), Mcd); - if (stat(Mcd, &buf) != -1) { + SysPrintf(_("Loading memory card %s\n"), filepath); + if (stat(filepath, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) @@ -940,20 +941,14 @@ void LoadMcds(char *mcd1, char *mcd2) { LoadMcd(2, mcd2); } -void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size) { +void SaveMcd(char *mcd, char *data, uint32_t adr, int size) { FILE *f; - char Mcd[MAXPATHLEN]; - if (Config.PerGameMcd && mcd && strlen(Config.PsxExeName)) - sprintf(Mcd, "memcards\\games\\%s-%02d.mcr", Config.PsxExeName, mcd-1); - else - strcpy(Mcd, str); - - f = fopen(Mcd, "r+b"); + f = fopen(mcd, "r+b"); if (f != NULL) { struct stat buf; - if (stat(Mcd, &buf) != -1) { + if (stat(mcd, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, adr + 64, SEEK_SET); else if (buf.st_size == MCD_SIZE + 3904) @@ -965,9 +960,7 @@ void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size) { fwrite(data + adr, 1, size, f); fclose(f); - - SysPrintf(_("Saving memory card %s\n"), Mcd); - + SysPrintf(_("Saving memory card %s\n"), mcd); return; } @@ -980,7 +973,7 @@ void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size) { } #endif - ConvertMcd(str, data); + ConvertMcd(mcd, data); } void CreateMcd(char *mcd) { diff --git a/libpcsxcore/sio.h b/libpcsxcore/sio.h index b3897552..64993992 100755 --- a/libpcsxcore/sio.h +++ b/libpcsxcore/sio.h @@ -55,7 +55,7 @@ int sioFreeze(gzFile f, int Mode); void LoadMcd(int mcd, char *str); void LoadMcds(char *mcd1, char *mcd2); -void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size); +void SaveMcd(char *mcd, char *data, uint32_t adr, int size); void CreateMcd(char *mcd); void ConvertMcd(char *mcd, char *data); |
