From 67c88d7b3346258c5dee39241f304df81ae3b1c2 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Thu, 13 Dec 2012 22:06:45 +0100 Subject: [PATCH 01/11] * Load and display save image in save/load menu * Add help math function * Add draw function in PPGe without texture and with alternative texture. * Change hardcoded atlas texture size in PPGe --- Common/MathUtil.cpp | 25 +++++++ Common/MathUtil.h | 3 +- Core/Dialog/PSPSaveDialog.cpp | 42 ++++++++++-- Core/Dialog/SavedataParam.cpp | 54 +++++++++++++++- Core/Dialog/SavedataParam.h | 6 ++ Core/Util/PPGeDraw.cpp | 118 +++++++++++++++++++++++----------- Core/Util/PPGeDraw.h | 5 ++ 7 files changed, 206 insertions(+), 47 deletions(-) diff --git a/Common/MathUtil.cpp b/Common/MathUtil.cpp index f088c7fbc0..bc06cdac07 100644 --- a/Common/MathUtil.cpp +++ b/Common/MathUtil.cpp @@ -247,3 +247,28 @@ void Matrix44::Multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &result) MatrixMul(4, a.data, b.data, result.data); } +int Pow2roundup(int x) +{ + if (x < 0) + return 0; + --x; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return x+1; +} + +int GetPow2(int x) +{ + int ret = 0; + int val = 1; + while(x > val) + { + ret++; + val *= 2; + } + return ret; +} + diff --git a/Common/MathUtil.h b/Common/MathUtil.h index a9e9f0c0a2..4c5675bbc7 100644 --- a/Common/MathUtil.h +++ b/Common/MathUtil.h @@ -146,6 +146,8 @@ struct Rectangle inline float pow2f(float x) {return x * x;} inline double pow2(double x) {return x * x;} +int Pow2roundup(int x); +int GetPow2(int x); /* @@ -163,7 +165,6 @@ float MathFloatVectorSum(const std::vector&); #define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) #define ROUND_DOWN(x, a) ((x) & ~((a) - 1)) - // Tiny matrix/vector library. // Used for things like Free-Look in the gfx backend. diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 567d2541b6..da54deb30e 100644 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -129,7 +129,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) int displayCount = 0; for(int i = 0; i < param.GetFilenameCount(); i++) { - int textureColor = 0xFF000000; // Hack for differencing save existing and not while real texture not displayed + int textureColor = 0xFFFFFFFF; if(param.GetFileInfo(i).size == 0) { @@ -154,8 +154,23 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) y += 90 + 50 * (displayCount - currentSelectedSave - 1); } - PPGeDraw4Patch(I_BUTTON, x, y, w, h, textureColor); // TODO : Display save texture image, or default if no save - + int tw = 256; + int th = 256; + if(param.GetFileInfo(i).textureData != 0) + { + tw = param.GetFileInfo(i).textureWidth; + th = param.GetFileInfo(i).textureHeight; + PPGeSetTexture(param.GetFileInfo(i).textureData, param.GetFileInfo(i).textureWidth, param.GetFileInfo(i).textureHeight); + } + else + { + PPGeDisableTexture(); + } + PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor); + if(param.GetFileInfo(i).textureData != 0) + { + PPGeSetDefaultTexture(); + } displayCount++; } @@ -174,7 +189,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) void PSPSaveDialog::DisplaySaveIcon() { - int textureColor = 0xFF000000; // Hack for differencing save existing and not while real texture not displayed + int textureColor = 0xFFFFFFFF; if(param.GetFileInfo(currentSelectedSave).size == 0) { @@ -187,8 +202,23 @@ void PSPSaveDialog::DisplaySaveIcon() int x = 20; int y = 80; - PPGeDraw4Patch(I_BUTTON, x, y, w, h, textureColor); // TODO : Display save texture image, or default if no save - + int tw = 256; + int th = 256; + if(param.GetFileInfo(currentSelectedSave).textureData != 0) + { + tw = param.GetFileInfo(currentSelectedSave).textureWidth; + th = param.GetFileInfo(currentSelectedSave).textureHeight; + PPGeSetTexture(param.GetFileInfo(currentSelectedSave).textureData, param.GetFileInfo(currentSelectedSave).textureWidth, param.GetFileInfo(currentSelectedSave).textureHeight); + } + else + { + PPGeDisableTexture(); + } + PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor); + if(param.GetFileInfo(currentSelectedSave).textureData != 0) + { + PPGeSetDefaultTexture(); + } } void PSPSaveDialog::DisplaySaveDataInfo1() diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 4f56b56e2b..8a5e464e32 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -17,6 +17,8 @@ #include "SavedataParam.h" #include "../System.h" +#include "image/png_load.h" +#include "../HLE/sceKernelMemory.h" std::string icon0Name = "ICON0.PNG"; std::string icon1Name = "ICON1.PNG"; @@ -259,10 +261,30 @@ bool SavedataParam::GetList(SceUtilitySavedataParam* param) return true; } +void SavedataParam::Clear() +{ + if(saveDataList) + { + for(int i = 0; i < saveNameListDataCount; i++) + { + if(saveDataList[i].textureData != 0) + kernelMemory.Free(saveDataList[i].textureData); + saveDataList[i].textureData = 0; + } + + delete[] saveDataList; + saveDataList = 0; + } +} + void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) { pspParam = param; - if(!pspParam) return; + if(!pspParam) + { + Clear(); + return; + } bool listEmptyFile = true; if(param->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTLOAD || @@ -282,8 +304,7 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) count++; } while(saveNameListData[count][0] != 0); - if(saveDataList) - delete[] saveDataList; + Clear(); saveDataList = new SaveFileInfo[count]; // get and stock file info for each file @@ -300,6 +321,32 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) saveDataList[realCount].size = info.size; saveDataList[realCount].saveName = saveNameListData[i]; saveDataList[realCount].idx = i; + + // Search save image icon0 + std::string fileDataPath2 = savePath+GetGameName(param)+saveNameListData[i]+"/"+icon0Name; + PSPFileInfo info2 = pspFileSystem.GetFileInfo(fileDataPath2); + if(info2.exists) + { + u8* textureDataPNG = new u8[info2.size]; + int handle = pspFileSystem.OpenFile(fileDataPath2,FILEACCESS_READ); + pspFileSystem.ReadFile(handle,textureDataPNG,info2.size); + unsigned char* textureData; + int w,h; + pngLoadPtr(textureDataPNG, info2.size, &w, &h, &textureData, false); + delete[] textureDataPNG; + u32 texSize = w*h*4; + u32 atlasPtr = kernelMemory.Alloc(texSize, true, "SaveData Icon"); + saveDataList[realCount].textureData = atlasPtr; + Memory::Memcpy(atlasPtr, textureData, texSize); + free(textureData); + saveDataList[realCount].textureWidth = w; + saveDataList[realCount].textureHeight = h; + } + else + { + saveDataList[realCount].textureData = 0; + } + DEBUG_LOG(HLE,"%s Exist",fileDataPath.c_str()); realCount++; } @@ -310,6 +357,7 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) saveDataList[realCount].size = 0; saveDataList[realCount].saveName = saveNameListData[i]; saveDataList[realCount].idx = i; + saveDataList[realCount].textureData = 0; DEBUG_LOG(HLE,"Don't Exist"); realCount++; } diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 4507b3c148..90af709700 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -123,6 +123,10 @@ struct SaveFileInfo int size; char* saveName; int idx; + + u32 textureData; + int textureWidth; + int textureHeight; }; class SavedataParam @@ -153,6 +157,8 @@ public: void SetSelectedSave(int idx); private: + void Clear(); + SceUtilitySavedataParam* pspParam; int selectedSave; char (*saveNameListData)[20]; diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 904b36fcff..57e79195e6 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -27,8 +27,11 @@ #include "gfx/texture_atlas.h" #include "gfx/gl_common.h" #include "../System.h" +#include "MathUtil.h" static u32 atlasPtr; +static int atlasWidth; +static int atlasHeight; struct PPGeVertex { u16 u, v; @@ -78,11 +81,11 @@ static void BeginVertexData() { vertexStart = dataWritePtr; } -static void Vertex(float x, float y, float u, float v, u32 color = 0xFFFFFFFF) +static void Vertex(float x, float y, float u, float v, int tw, int th, u32 color = 0xFFFFFFFF) { PPGeVertex vtx; vtx.x = x - 0.5f; vtx.y = y - 0.5f; vtx.z = 0; - vtx.u = u * 256 - 0.5f; vtx.v = v * 256 - 0.5f; + vtx.u = u * tw - 0.5f; vtx.v = v * th - 0.5f; vtx.color = color; Memory::WriteStruct(dataWritePtr, &vtx); vertexCount++; @@ -112,6 +115,8 @@ void __PPGeInit() } u32 atlasSize = height * width * 2; // it's a 4444 texture + atlasWidth = width; + atlasHeight = height; dlPtr = kernelMemory.Alloc(dlSize, false, "PPGe Display List"); dataPtr = kernelMemory.Alloc(dataSize, false, "PPGe Vertex Data"); atlasPtr = kernelMemory.Alloc(atlasSize, false, "PPGe Atlas Texture"); @@ -173,17 +178,7 @@ void PPGeBegin() WriteCmd(GE_CMD_CULLFACEENABLE, 0); WriteCmd(GE_CMD_CLEARMODE, 0); // Normal mode - WriteCmd(GE_CMD_TEXTUREMAPENABLE, 1); - WriteCmd(GE_CMD_TEXSIZE0, 8 | (8 << 8)); // 1 << (7+1) = 256 - WriteCmd(GE_CMD_TEXMAPMODE, 0 | (1 << 8)); - WriteCmd(GE_CMD_TEXMODE, 0); - WriteCmd(GE_CMD_TEXFORMAT, 2); // 4444 - WriteCmd(GE_CMD_TEXFILTER, (1 << 8) | 1); // mag = LINEAR min = LINEAR - WriteCmd(GE_CMD_TEXWRAP, (1 << 8) | 1); // clamp texture wrapping - WriteCmd(GE_CMD_TEXFUNC, (0 << 16) | (1 << 8) | 0); // RGBA texture reads, modulate, no color doubling - WriteCmd(GE_CMD_TEXADDR0, atlasPtr & 0xFFFFF0); - WriteCmd(GE_CMD_TEXBUFWIDTH0, 256 | ((atlasPtr & 0xFF000000) >> 8)); - WriteCmd(GE_CMD_TEXFLUSH, 0); + PPGeSetDefaultTexture(); WriteCmd(GE_CMD_SCISSOR1, (0 << 10) | 0); WriteCmd(GE_CMD_SCISSOR2, (1023 << 10) | 1023); @@ -271,8 +266,8 @@ void PPGeDrawText(const char *text, float x, float y, int align, float scale, u3 float cy1 = y + c.oy * scale; float cx2 = x + (c.ox + c.pw) * scale; float cy2 = y + (c.oy + c.ph) * scale; - Vertex(cx1, cy1, c.sx, c.sy, color); - Vertex(cx2, cy2, c.ex, c.ey, color); + Vertex(cx1, cy1, c.sx, c.sy, 256, 256, color); + Vertex(cx2, cy2, c.ex, c.ey, 256, 256, color); x += c.wx * scale; } EndVertexDataAndDraw(GE_PRIM_RECTANGLES); @@ -296,26 +291,26 @@ void PPGeDraw4Patch(int atlasImage, float x, float y, float w, float h, u32 colo float y2 = y + h; BeginVertexData(); // Top row - Vertex(x, y, u1, v1, color); - Vertex(xmid1, ymid1, uhalf, vhalf, color); - Vertex(xmid1, y, uhalf, v1, color); - Vertex(xmid2, ymid1, uhalf, vhalf, color); - Vertex(xmid2, y, uhalf, v1, color); - Vertex(x2, ymid1, u2, vhalf, color); + Vertex(x, y, u1, v1, atlasWidth, atlasHeight, color); + Vertex(xmid1, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid1, y, uhalf, v1, atlasWidth, atlasHeight, color); + Vertex(xmid2, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid2, y, uhalf, v1, atlasWidth, atlasHeight, color); + Vertex(x2, ymid1, u2, vhalf, atlasWidth, atlasHeight, color); // Middle row - Vertex(x, ymid1, u1, vhalf, color); - Vertex(xmid1, ymid2, uhalf, vhalf, color); - Vertex(xmid1, ymid1, uhalf, vhalf, color); - Vertex(xmid2, ymid2, uhalf, vhalf, color); - Vertex(xmid2, ymid1, uhalf, vhalf, color); - Vertex(x2, ymid2, u2, v2, color); + Vertex(x, ymid1, u1, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid1, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid1, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid2, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid2, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(x2, ymid2, u2, v2, atlasWidth, atlasHeight, color); // Bottom row - Vertex(x, ymid2, u1, vhalf, color); - Vertex(xmid1, y2, uhalf, v2, color); - Vertex(xmid1, ymid2, uhalf, vhalf, color); - Vertex(xmid2, y2, uhalf, v2, color); - Vertex(xmid2, ymid2, uhalf, vhalf, color); - Vertex(x2, y2, u2, v2, color); + Vertex(x, ymid2, u1, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid1, y2, uhalf, v2, atlasWidth, atlasHeight, color); + Vertex(xmid1, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(xmid2, y2, uhalf, v2, atlasWidth, atlasHeight, color); + Vertex(xmid2, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color); + Vertex(x2, y2, u2, v2, atlasWidth, atlasHeight, color); EndVertexDataAndDraw(GE_PRIM_RECTANGLES); } @@ -329,8 +324,8 @@ void PPGeDrawImage(int atlasImage, float x, float y, int align, u32 color) float w = img.w; float h = img.h; BeginVertexData(); - Vertex(x, y, img.u1, img.v1, color); - Vertex(x + w, y + h, img.u2, img.v2, color); + Vertex(x, y, img.u1, img.v1, atlasWidth, atlasHeight, color); + Vertex(x + w, y + h, img.u2, img.v2, atlasWidth, atlasHeight, color); EndVertexDataAndDraw(GE_PRIM_RECTANGLES); } @@ -341,8 +336,57 @@ void PPGeDrawImage(int atlasImage, float x, float y, float w, float h, int align const AtlasImage &img = ppge_atlas.images[atlasImage]; BeginVertexData(); - Vertex(x, y, img.u1, img.v1, color); - Vertex(x + w, y + h, img.u2, img.v2, color); + Vertex(x, y, img.u1, img.v1, atlasWidth, atlasHeight, color); + Vertex(x + w, y + h, img.u2, img.v2, atlasWidth, atlasHeight, color); EndVertexDataAndDraw(GE_PRIM_RECTANGLES); } +void PPGeDrawImage(float x, float y, float w, float h, float u1, float v1, float u2, float v2, int tw, int th, u32 color) +{ + if (!dlPtr) + return; + BeginVertexData(); + Vertex(x, y, u1, v1, tw, th, color); + Vertex(x + w, y + h, u2, v2, tw, th, color); + EndVertexDataAndDraw(GE_PRIM_RECTANGLES); +} + +void PPGeSetDefaultTexture() +{ + WriteCmd(GE_CMD_TEXTUREMAPENABLE, 1); + int wp2 = GetPow2(atlasWidth); + int hp2 = GetPow2(atlasHeight); + WriteCmd(GE_CMD_TEXSIZE0, wp2 | (hp2 << 8)); // 1 << (7+1) = 256 + WriteCmd(GE_CMD_TEXMAPMODE, 0 | (1 << 8)); + WriteCmd(GE_CMD_TEXMODE, 0); + WriteCmd(GE_CMD_TEXFORMAT, 2); // 4444 + WriteCmd(GE_CMD_TEXFILTER, (1 << 8) | 1); // mag = LINEAR min = LINEAR + WriteCmd(GE_CMD_TEXWRAP, (1 << 8) | 1); // clamp texture wrapping + WriteCmd(GE_CMD_TEXFUNC, (0 << 16) | (1 << 8) | 0); // RGBA texture reads, modulate, no color doubling + WriteCmd(GE_CMD_TEXADDR0, atlasPtr & 0xFFFFF0); + WriteCmd(GE_CMD_TEXBUFWIDTH0, atlasWidth | ((atlasPtr & 0xFF000000) >> 8)); + WriteCmd(GE_CMD_TEXFLUSH, 0); +} + +void PPGeSetTexture(u32 dataAddr, int width, int height) +{ + WriteCmd(GE_CMD_TEXTUREMAPENABLE, 1); + int wp2 = GetPow2(width); + int hp2 = GetPow2(height); + WriteCmd(GE_CMD_TEXSIZE0, wp2 | (hp2 << 8)); // 1 << (7+1) = 256 + WriteCmd(GE_CMD_TEXMAPMODE, 0 | (1 << 8)); + WriteCmd(GE_CMD_TEXMODE, 0); + WriteCmd(GE_CMD_TEXFORMAT, GE_TFMT_8888); // 4444 + WriteCmd(GE_CMD_TEXFILTER, (1 << 8) | 1); // mag = LINEAR min = LINEAR + WriteCmd(GE_CMD_TEXWRAP, (1 << 8) | 1); // clamp texture wrapping + WriteCmd(GE_CMD_TEXFUNC, (0 << 16) | (1 << 8) | 0); // RGBA texture reads, modulate, no color doubling + WriteCmd(GE_CMD_TEXADDR0, dataAddr & 0xFFFFF0); + WriteCmd(GE_CMD_TEXBUFWIDTH0, width | ((dataAddr & 0xFF000000) >> 8)); + WriteCmd(GE_CMD_TEXFLUSH, 0); +} + +void PPGeDisableTexture() +{ + WriteCmd(GE_CMD_TEXTUREMAPENABLE, 0); +} + diff --git a/Core/Util/PPGeDraw.h b/Core/Util/PPGeDraw.h index 00765bc60d..e77a53cd89 100644 --- a/Core/Util/PPGeDraw.h +++ b/Core/Util/PPGeDraw.h @@ -68,4 +68,9 @@ void PPGeDraw4Patch(int atlasImage, float x, float y, float w, float h, u32 colo // Just blits an image to the screen, multiplied with the color. void PPGeDrawImage(int atlasImage, float x, float y, int align, u32 color = 0xFFFFFFFF); void PPGeDrawImage(int atlasImage, float x, float y, float w, float h, int align, u32 color = 0xFFFFFFFF); +void PPGeDrawImage(float x, float y, float w, float h, float u1, float v1, float u2, float v2, int tw, int th, u32 color); + +void PPGeSetDefaultTexture(); +void PPGeSetTexture(u32 dataAddr, int width, int height); +void PPGeDisableTexture(); From fc3ff5853c18173592ce98118cb74c655eb27673 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Thu, 13 Dec 2012 22:45:13 +0100 Subject: [PATCH 02/11] Update for android build --- Common/MathUtil.cpp | 10 ++++++++-- Common/MathUtil.h | 7 +++++++ android/jni/Android.mk | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Common/MathUtil.cpp b/Common/MathUtil.cpp index bc06cdac07..6225afa6be 100644 --- a/Common/MathUtil.cpp +++ b/Common/MathUtil.cpp @@ -22,10 +22,10 @@ #include namespace { - +#ifdef USE_SSE static u32 saved_sse_state = _mm_getcsr(); static const u32 default_sse_state = _mm_getcsr(); - +#endif } namespace MathUtil @@ -116,19 +116,25 @@ namespace MathUtil void LoadDefaultSSEState() { +#ifdef USE_SSE _mm_setcsr(default_sse_state); +#endif } void LoadSSEState() { +#ifdef USE_SSE _mm_setcsr(saved_sse_state); +#endif } void SaveSSEState() { +#ifdef USE_SSE saved_sse_state = _mm_getcsr(); +#endif } inline void MatrixMul(int n, const float *a, const float *b, float *result) diff --git a/Common/MathUtil.h b/Common/MathUtil.h index 4c5675bbc7..77aa57e8ec 100644 --- a/Common/MathUtil.h +++ b/Common/MathUtil.h @@ -20,7 +20,14 @@ #include "Common.h" +#ifndef ANDROID +#define USE_SSE +#endif + +#ifdef USE_SSE #include +#endif + #include namespace MathUtil diff --git a/android/jni/Android.mk b/android/jni/Android.mk index b691f6b076..1839645a4d 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -66,6 +66,7 @@ LOCAL_SRC_FILES := \ $(SRC)/Common/Timer.cpp \ $(SRC)/Common/ThunkARM.cpp \ $(SRC)/Common/Misc.cpp \ + $(SRC)/Common/MathUtil.cpp \ $(SRC)/GPU/Math3D.cpp \ $(SRC)/GPU/GPUState.cpp \ $(SRC)/GPU/GLES/Framebuffer.cpp \ From 1ea6fe7e4d3ad190da04ec977314c1b2c6369588 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Fri, 14 Dec 2012 01:04:45 +0100 Subject: [PATCH 03/11] Correct texture display in save dialog on Android. --- Core/Dialog/PSPSaveDialog.cpp | 5 +---- GPU/GLES/DisplayListInterpreter.cpp | 1 + GPU/GLES/TransformPipeline.cpp | 5 +++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index da54deb30e..8b9a02fbb4 100644 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -167,10 +167,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove) PPGeDisableTexture(); } PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor); - if(param.GetFileInfo(i).textureData != 0) - { - PPGeSetDefaultTexture(); - } + PPGeSetDefaultTexture(); displayCount++; } diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index 1f84c5ed1f..630e966797 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -561,6 +561,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) break; case GE_CMD_TEXTUREMAPENABLE: + gstate_c.textureChanged = true; DEBUG_LOG(G3D, "DL Texture map enable: %i", data); break; diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 31071a23b6..6bf47ce136 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -215,9 +215,14 @@ void GLES_GPU::TransformAndDrawPrim(void *verts, void *inds, int prim, int verte { if ((gstate.textureMapEnable & 1) && !gstate.isModeClear()) { + glEnable(GL_TEXTURE_2D); PSPSetTexture(); useTexCoord = true; } + else + { + glDisable(GL_TEXTURE_2D); + } } gpuStats.numDrawCalls++; gpuStats.numVertsTransformed += vertexCount; From ab71c3d1d023fac489f4195ce0849505a82b4880 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Fri, 14 Dec 2012 20:55:57 +0100 Subject: [PATCH 04/11] Save unencrypted PARAM.SFO --- Core/Dialog/SavedataParam.cpp | 39 ++++++++-- Core/Dialog/SavedataParam.h | 1 + Core/ELF/ParamSFO.cpp | 142 ++++++++++++++++++++++++++++++---- Core/ELF/ParamSFO.h | 32 +++++++- Core/PSPLoaders.cpp | 4 +- 5 files changed, 193 insertions(+), 25 deletions(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 8a5e464e32..5eed0de3be 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -19,6 +19,7 @@ #include "../System.h" #include "image/png_load.h" #include "../HLE/sceKernelMemory.h" +#include "../ELF/ParamSFO.h" std::string icon0Name = "ICON0.PNG"; std::string icon1Name = "ICON1.PNG"; @@ -45,8 +46,7 @@ void SavedataParam::Init() } } - -std::string SavedataParam::GetSaveFilePath(SceUtilitySavedataParam* param, int saveId) +std::string SavedataParam::GetSaveDir(SceUtilitySavedataParam* param, int saveId) { if (!param) { return ""; @@ -56,7 +56,16 @@ std::string SavedataParam::GetSaveFilePath(SceUtilitySavedataParam* param, int s if(saveId >= 0 && saveNameListDataCount > 0) // if user selection, use it dirPath = std::string(GetGameName(param))+GetFilename(saveId); - return savePath + dirPath; + return dirPath; +} + +std::string SavedataParam::GetSaveFilePath(SceUtilitySavedataParam* param, int saveId) +{ + if (!param) { + return ""; + } + + return savePath + GetSaveDir(param,saveId); } std::string SavedataParam::GetGameName(SceUtilitySavedataParam* param) @@ -134,9 +143,27 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, int saveId) { pspFileSystem.CloseFile(handle); - // TODO SAVE PARAM.SFO - /*data_ = (u8*)Memory::GetPointer(*((unsigned int*)¶m->dataBuf)); - writeDataToFile(false, );*/ + // SAVE PARAM.SFO + ParamSFOData sfoFile; + sfoFile.SetValue("TITLE",param->sfoParam.title,128); + sfoFile.SetValue("SAVEDATA_TITLE",param->sfoParam.savedataTitle,128); + sfoFile.SetValue("SAVEDATA_DETAIL",param->sfoParam.savedataTitle,1024); + sfoFile.SetValue("PARENTAL_LEVEL",param->sfoParam.parentalLevel,4); + sfoFile.SetValue("CATEGORY","MS",4); + sfoFile.SetValue("SAVEDATA_DIRECTORY",GetSaveDir(param,saveId),64); + sfoFile.SetValue("SAVEDATA_FILE_LIST","",3168); + sfoFile.SetValue("SAVEDATA_PARAMS","",128); + u8* sfoData; + size_t sfoSize; + sfoFile.WriteSFO(&sfoData,&sfoSize); + std::string sfopath = dirPath+"/"+sfoName; + handle = pspFileSystem.OpenFile(sfopath,(FileAccess)(FILEACCESS_WRITE | FILEACCESS_CREATE)); + if(handle) + { + pspFileSystem.WriteFile(handle, sfoData, sfoSize); + pspFileSystem.CloseFile(handle); + } + delete[] sfoData; // SAVE ICON0 if(param->icon0FileData.buf) diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 90af709700..6330e7d0f2 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -134,6 +134,7 @@ class SavedataParam public: static void Init(); std::string GetSaveFilePath(SceUtilitySavedataParam* param, int saveId = -1); + std::string GetSaveDir(SceUtilitySavedataParam* param, int saveId = -1); bool Delete(SceUtilitySavedataParam* param, int saveId = -1); bool Save(SceUtilitySavedataParam* param, int saveId = -1); bool Load(SceUtilitySavedataParam* param, int saveId = -1); diff --git a/Core/ELF/ParamSFO.cpp b/Core/ELF/ParamSFO.cpp index a86e6c77b8..e2b423b29e 100644 --- a/Core/ELF/ParamSFO.cpp +++ b/Core/ELF/ParamSFO.cpp @@ -38,22 +38,48 @@ struct IndexTable u32 data_table_offset; /* Offset of the param_data from start of data_table */ }; -void ParseDataString(const char *key, const char *utfdata, ParamSFOData *sfodata, int maxlen = 0) +void ParamSFOData::SetValue(std::string key, unsigned int value, int max_size) { - std::string data; - if (maxlen) - data = std::string(utfdata, maxlen); - else - data = std::string(utfdata); - if (!strcmp(key, "DISC_ID")) { - sfodata->discID = data; - } else if (!strcmp(key, "TITLE")) { - sfodata->title = data; + values[key].type = VT_INT; + values[key].i_value = value; + values[key].max_size = max_size; +} +void ParamSFOData::SetValue(std::string key, std::string value, int max_size) +{ + if(key == "ACCOUNT_ID" || + key == "PADDING" || + key == "PARAMS" || + key == "PARAMS2" || + key == "SAVEDATA_FILE_LIST" || + key == "SAVEDATA_PARAMS") + { + values[key].type = VT_UTF8_SPE; } + else + { + values[key].type = VT_UTF8; + } + values[key].s_value = value; + values[key].max_size = max_size; +} + +int ParamSFOData::GetValueInt(std::string key) +{ + std::map::iterator it = values.find(key); + if(it == values.end() || it->second.type != VT_INT) + return 0; + return it->second.i_value; +} +std::string ParamSFOData::GetValueString(std::string key) +{ + std::map::iterator it = values.find(key); + if(it == values.end() || (it->second.type != VT_UTF8 && it->second.type != VT_UTF8_SPE)) + return ""; + return it->second.s_value; } // I'm so sorry Ced but this is highly endian unsafe :( -bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data) +bool ParamSFOData::ReadSFO(const u8 *paramsfo, size_t size) { const Header *header = (const Header *)paramsfo; if (header->magic != 0x46535000) @@ -75,6 +101,7 @@ bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data) { // Unsigned int const u32 *data = (const u32 *)(data_start + indexTables[i].data_table_offset); + SetValue(key,*data,indexTables[i].param_max_len); DEBUG_LOG(LOADER, "%s %08x", key, *data); } break; @@ -83,7 +110,7 @@ bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data) { const char *utfdata = (const char *)(data_start + indexTables[i].data_table_offset); DEBUG_LOG(LOADER, "%s %s", key, utfdata); - ParseDataString(key, utfdata, data, indexTables[i].param_len); + SetValue(key,std::string(utfdata,indexTables[i].param_len),indexTables[i].param_max_len); } break; case 0x0204: @@ -91,7 +118,7 @@ bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data) { const char *utfdata = (const char *)(data_start + indexTables[i].data_table_offset); DEBUG_LOG(LOADER, "%s %s", key, utfdata); - ParseDataString(key, utfdata, data, indexTables[i].param_len); + SetValue(key,std::string(utfdata,indexTables[i].param_len),indexTables[i].param_max_len); } break; } @@ -99,3 +126,92 @@ bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data) return true; } + +bool ParamSFOData::WriteSFO(u8 **paramsfo, size_t *size) +{ + size_t total_size = 0; + size_t key_size = 0; + size_t data_size = 0; + + Header header; + header.magic = 0x46535000; + header.version = 0x00000101; + header.index_table_entries = 0; + + total_size += sizeof(Header); + + // Get size info + for(std::map::iterator it = values.begin(); it != values.end(); it++) + { + key_size += it->first.size()+1; + data_size += it->second.max_size; + + header.index_table_entries++; + } + + // Padding + while((key_size%4)) key_size++; + + header.key_table_start = sizeof(Header) + header.index_table_entries * sizeof(IndexTable); + header.data_table_start = header.key_table_start + key_size; + + total_size += sizeof(IndexTable) * header.index_table_entries; + total_size += key_size; + total_size += data_size; + *size = total_size; + + u8* data = new u8[total_size]; + *paramsfo = data; + memset(data,0,total_size); + memcpy(data,&header,sizeof(Header)); + + // Now fill + IndexTable *index_ptr = (IndexTable*)(data + sizeof(Header)); + u8* key_ptr = data + header.key_table_start; + u8* data_ptr = data + header.data_table_start; + + for(std::map::iterator it = values.begin(); it != values.end(); it++) + { + u16 offset = (u16)(key_ptr - (data+header.key_table_start)); + index_ptr->key_table_offset = offset; + offset = (u16)(data_ptr - (data+header.data_table_start)); + index_ptr->data_table_offset = offset; + index_ptr->param_max_len = it->second.max_size; + if(it->second.type == VT_INT) + { + index_ptr->param_fmt = 0x0404; + index_ptr->param_len = 4; + + *(int*)data_ptr = it->second.i_value; + } + else if(it->second.type == VT_UTF8_SPE) + { + index_ptr->param_fmt = 0x0004; + index_ptr->param_len = it->second.s_value.size()+1; + + memcpy(data_ptr,it->second.s_value.c_str(),index_ptr->param_len); + data_ptr[index_ptr->param_len] = 0; + } + else if(it->second.type == VT_UTF8) + { + index_ptr->param_fmt = 0x0204; + index_ptr->param_len = it->second.s_value.size()+1; + + memcpy(data_ptr,it->second.s_value.c_str(),index_ptr->param_len); + data_ptr[index_ptr->param_len] = 0; + } + + memcpy(key_ptr,it->first.c_str(),it->first.size()); + key_ptr[it->first.size()] = 0; + + data_ptr += index_ptr->param_max_len; + key_ptr += it->first.size()+1; + index_ptr++; + + } + + return true; + + +} + diff --git a/Core/ELF/ParamSFO.h b/Core/ELF/ParamSFO.h index f92bef1a5a..3d3441c521 100644 --- a/Core/ELF/ParamSFO.h +++ b/Core/ELF/ParamSFO.h @@ -18,11 +18,35 @@ #pragma once +#include -struct ParamSFOData +class ParamSFOData { - std::string discID; - std::string title; // utf-8 +public: + void SetValue(std::string key, unsigned int value, int max_size); + void SetValue(std::string key, std::string value, int max_size); + + int GetValueInt(std::string key); + std::string GetValueString(std::string key); + + bool ReadSFO(const u8 *paramsfo, size_t size); + bool WriteSFO(u8 **paramsfo, size_t *size); +private: + + enum ValueType + { + VT_INT, + VT_UTF8, + VT_UTF8_SPE + }; + struct ValueData + { + ValueType type; + int max_size; + std::string s_value; + int i_value; + }; + + std::map values; }; -bool ParseParamSFO(const u8 *paramsfo, size_t size, ParamSFOData *data); \ No newline at end of file diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index ae628e760a..afc8cad456 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -78,10 +78,10 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string) pspFileSystem.ReadFile(fd, paramsfo, fileInfo.size); pspFileSystem.CloseFile(fd); ParamSFOData data; - if (ParseParamSFO(paramsfo, (size_t)fileInfo.size, &data)) + if (data.ReadSFO(paramsfo, (size_t)fileInfo.size)) { char title[1024]; - sprintf(title, "%s : %s", data.discID.c_str(), data.title.c_str()); + sprintf(title, "%s : %s", data.GetValueString("DISC_ID").c_str(), data.GetValueString("TITLE").c_str()); INFO_LOG(LOADER, "%s", title); host->SetWindowTitle(title); } From 1697e1dd93a728b02f81b4a8c74dcf78bc8bf38c Mon Sep 17 00:00:00 2001 From: Xele02 Date: Fri, 14 Dec 2012 21:36:54 +0100 Subject: [PATCH 05/11] Save save snd file --- Core/Dialog/SavedataParam.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 5eed0de3be..e1bae3d370 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -22,8 +22,9 @@ #include "../ELF/ParamSFO.h" std::string icon0Name = "ICON0.PNG"; -std::string icon1Name = "ICON1.PNG"; +std::string icon1Name = "ICON1.PMF"; std::string pic1Name = "PIC1.PNG"; +std::string snd0Name = "SND0.AT3"; std::string sfoName = "PARAM.SFO"; std::string savePath = "ms0:/PSP/SAVEDATA/"; @@ -151,8 +152,8 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, int saveId) sfoFile.SetValue("PARENTAL_LEVEL",param->sfoParam.parentalLevel,4); sfoFile.SetValue("CATEGORY","MS",4); sfoFile.SetValue("SAVEDATA_DIRECTORY",GetSaveDir(param,saveId),64); - sfoFile.SetValue("SAVEDATA_FILE_LIST","",3168); - sfoFile.SetValue("SAVEDATA_PARAMS","",128); + sfoFile.SetValue("SAVEDATA_FILE_LIST","",3168); // This need to be filed with the save filename and a hash + sfoFile.SetValue("SAVEDATA_PARAMS","",128); // This need to be filled with a hash of the save file encrypted. u8* sfoData; size_t sfoSize; sfoFile.WriteSFO(&sfoData,&sfoSize); @@ -202,7 +203,18 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, int saveId) } } - // TODO Save SND + // Save SND + if(param->snd0FileData.buf) + { + data_ = (u8*)Memory::GetPointer(*((unsigned int*)¶m->snd0FileData.buf)); + std::string snd0path = dirPath+"/"+snd0Name; + handle = pspFileSystem.OpenFile(snd0path,(FileAccess)(FILEACCESS_WRITE | FILEACCESS_CREATE)); + if(handle) + { + pspFileSystem.WriteFile(handle, data_, param->snd0FileData.bufSize); + pspFileSystem.CloseFile(handle); + } + } } return true; } From e7856627477aba4755fd1aab714eba11e49c22b7 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Fri, 14 Dec 2012 23:08:56 +0100 Subject: [PATCH 06/11] Read PARAM.SFO for display save info Display save modification date and time --- Common/FileUtil.cpp | 28 ++++++++++++++++++++ Common/FileUtil.h | 3 +++ Core/Dialog/PSPSaveDialog.cpp | 22 ++++++++++++++-- Core/Dialog/SavedataParam.cpp | 33 ++++++++++++++++++++++-- Core/Dialog/SavedataParam.h | 6 +++++ Core/FileSystems/DirectoryFileSystem.cpp | 1 + Core/FileSystems/FileSystem.h | 2 ++ 7 files changed, 91 insertions(+), 4 deletions(-) diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index 19ae1983dd..885efe8615 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -346,6 +346,34 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) #endif } +tm GetModifTime(const std::string &filename) +{ + tm return_time; + if (!Exists(filename)) + { + WARN_LOG(COMMON, "GetCreateTime: failed %s: No such file", filename.c_str()); + return return_time; + } + + if (IsDirectory(filename)) + { + WARN_LOG(COMMON, "GetCreateTime: failed %s: is a directory", filename.c_str()); + return return_time; + } + struct stat64 buf; + if (stat64(filename.c_str(), &buf) == 0) + { + DEBUG_LOG(COMMON, "GetCreateTime: %s: %lld", + filename.c_str(), (long long)buf.st_mtime); + localtime_r(&buf.st_mtime,&return_time); + return return_time; + } + + ERROR_LOG(COMMON, "GetCreateTime: Stat failed %s: %s", + filename.c_str(), GetLastErrorMsg()); + return return_time; +} + // Returns the size of filename (64bit) u64 GetSize(const std::string &filename) { diff --git a/Common/FileUtil.h b/Common/FileUtil.h index 0c9e464fbb..4c9a86f5cf 100644 --- a/Common/FileUtil.h +++ b/Common/FileUtil.h @@ -56,6 +56,9 @@ bool Exists(const std::string &filename); // Returns true if filename is a directory bool IsDirectory(const std::string &filename); +// Returns struct with modification date of file +tm GetModifTime(const std::string &filename); + // Returns the size of filename (64bit) u64 GetSize(const std::string &filename); diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 8b9a02fbb4..ff4aafef2c 100644 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -227,7 +227,17 @@ void PSPSaveDialog::DisplaySaveDataInfo1() else { char txt[1024]; - sprintf(txt,"%s\nSize : %d",param.GetFilename(currentSelectedSave).c_str(),param.GetFileInfo(currentSelectedSave).size); + sprintf(txt,"%s\n%d/%d/%d %d:%d %d KB\n%s\n%s" + , param.GetFileInfo(currentSelectedSave).title + , param.GetFileInfo(currentSelectedSave).modif_time.tm_mday + , param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1 + , param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900 + , param.GetFileInfo(currentSelectedSave).modif_time.tm_hour + , param.GetFileInfo(currentSelectedSave).modif_time.tm_min + , param.GetFileInfo(currentSelectedSave).size / 1024 + , param.GetFileInfo(currentSelectedSave).saveTitle + , param.GetFileInfo(currentSelectedSave).saveDetail + ); std::string saveinfoTxt = txt; PPGeDrawText(saveinfoTxt.c_str(), 200, 100, PPGE_ALIGN_LEFT, 0.5f, 0xFFFFFFFF); } @@ -241,7 +251,15 @@ void PSPSaveDialog::DisplaySaveDataInfo2() else { char txt[1024]; - sprintf(txt,"%s\nSize : %d",param.GetFilename(currentSelectedSave).c_str(),param.GetFileInfo(currentSelectedSave).size); + sprintf(txt,"%s\n%d/%d/%d %d:%d\n%d KB" + , param.GetFileInfo(currentSelectedSave).saveTitle + , param.GetFileInfo(currentSelectedSave).modif_time.tm_mday + , param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1 + , param.GetFileInfo(currentSelectedSave).modif_time.tm_year + 1900 + , param.GetFileInfo(currentSelectedSave).modif_time.tm_hour + , param.GetFileInfo(currentSelectedSave).modif_time.tm_min + , param.GetFileInfo(currentSelectedSave).size / 1024 + ); std::string saveinfoTxt = txt; PPGeDrawText(saveinfoTxt.c_str(), 10, 180, PPGE_ALIGN_LEFT, 0.5f, 0xFFFFFFFF); } diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index e1bae3d370..e2897c69ef 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -148,7 +148,7 @@ bool SavedataParam::Save(SceUtilitySavedataParam* param, int saveId) ParamSFOData sfoFile; sfoFile.SetValue("TITLE",param->sfoParam.title,128); sfoFile.SetValue("SAVEDATA_TITLE",param->sfoParam.savedataTitle,128); - sfoFile.SetValue("SAVEDATA_DETAIL",param->sfoParam.savedataTitle,1024); + sfoFile.SetValue("SAVEDATA_DETAIL",param->sfoParam.detail,1024); sfoFile.SetValue("PARENTAL_LEVEL",param->sfoParam.parentalLevel,4); sfoFile.SetValue("CATEGORY","MS",4); sfoFile.SetValue("SAVEDATA_DIRECTORY",GetSaveDir(param,saveId),64); @@ -356,12 +356,13 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) PSPFileInfo info = pspFileSystem.GetFileInfo(fileDataPath); if(info.exists) { - // TODO : Load PARAM.SFO when saved and save title and save info saveDataList[realCount].size = info.size; saveDataList[realCount].saveName = saveNameListData[i]; saveDataList[realCount].idx = i; + saveDataList[realCount].modif_time = info.mtime; // Search save image icon0 + // TODO : If icon0 don't exist, need to use icon1 which is a moving icon. Also play sound std::string fileDataPath2 = savePath+GetGameName(param)+saveNameListData[i]+"/"+icon0Name; PSPFileInfo info2 = pspFileSystem.GetFileInfo(fileDataPath2); if(info2.exists) @@ -369,6 +370,7 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) u8* textureDataPNG = new u8[info2.size]; int handle = pspFileSystem.OpenFile(fileDataPath2,FILEACCESS_READ); pspFileSystem.ReadFile(handle,textureDataPNG,info2.size); + pspFileSystem.CloseFile(handle); unsigned char* textureData; int w,h; pngLoadPtr(textureDataPNG, info2.size, &w, &h, &textureData, false); @@ -386,6 +388,33 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) saveDataList[realCount].textureData = 0; } + // Load info in PARAM.SFO + fileDataPath2 = savePath+GetGameName(param)+saveNameListData[i]+"/"+sfoName; + info2 = pspFileSystem.GetFileInfo(fileDataPath2); + if(info2.exists) + { + u8* sfoParam = new u8[info2.size]; + int handle = pspFileSystem.OpenFile(fileDataPath2,FILEACCESS_READ); + pspFileSystem.ReadFile(handle,sfoParam,info2.size); + pspFileSystem.CloseFile(handle); + ParamSFOData sfoFile; + if(sfoFile.ReadSFO(sfoParam,info2.size)) + { + std::string title = sfoFile.GetValueString("TITLE"); + memcpy(saveDataList[realCount].title,title.c_str(),title.size()); + saveDataList[realCount].title[title.size()] = 0; + + std::string savetitle = sfoFile.GetValueString("SAVEDATA_TITLE"); + memcpy(saveDataList[realCount].saveTitle,savetitle.c_str(),savetitle.size()); + saveDataList[realCount].saveTitle[savetitle.size()] = 0; + + std::string savedetail = sfoFile.GetValueString("SAVEDATA_DETAIL"); + memcpy(saveDataList[realCount].saveDetail,savedetail.c_str(),savedetail.size()); + saveDataList[realCount].saveDetail[savedetail.size()] = 0; + } + delete sfoParam; + } + DEBUG_LOG(HLE,"%s Exist",fileDataPath.c_str()); realCount++; } diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index 6330e7d0f2..fdbae353f7 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -124,6 +124,12 @@ struct SaveFileInfo char* saveName; int idx; + char title[128]; + char saveTitle[128]; + char saveDetail[1024]; + + tm modif_time; + u32 textureData; int textureWidth; int textureHeight; diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 3678b659c8..64089cf6d3 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -277,6 +277,7 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) x.size = File::GetSize(fullName); //TODO #endif + x.mtime = File::GetModifTime(fullName); return x; } diff --git a/Core/FileSystems/FileSystem.h b/Core/FileSystems/FileSystem.h index 069296d7de..ab1c1e48d2 100644 --- a/Core/FileSystems/FileSystem.h +++ b/Core/FileSystems/FileSystem.h @@ -62,6 +62,8 @@ struct PSPFileInfo bool exists; FileType type; + tm mtime; + bool isOnSectorSystem; u32 startSector; u32 numSectors; From 825e058c94986ded9597673f29e4acadc7890ac5 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Fri, 14 Dec 2012 23:40:02 +0100 Subject: [PATCH 07/11] Correct date display with padding --- Core/Dialog/PSPSaveDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index ff4aafef2c..f8193be97d 100644 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -227,7 +227,7 @@ void PSPSaveDialog::DisplaySaveDataInfo1() else { char txt[1024]; - sprintf(txt,"%s\n%d/%d/%d %d:%d %d KB\n%s\n%s" + sprintf(txt,"%s\n%02d/%02d/%d %02d:%02d %d KB\n%s\n%s" , param.GetFileInfo(currentSelectedSave).title , param.GetFileInfo(currentSelectedSave).modif_time.tm_mday , param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1 @@ -251,7 +251,7 @@ void PSPSaveDialog::DisplaySaveDataInfo2() else { char txt[1024]; - sprintf(txt,"%s\n%d/%d/%d %d:%d\n%d KB" + sprintf(txt,"%s\n%02d/%02d/%d %02d:%02d\n%d KB" , param.GetFileInfo(currentSelectedSave).saveTitle , param.GetFileInfo(currentSelectedSave).modif_time.tm_mday , param.GetFileInfo(currentSelectedSave).modif_time.tm_mon + 1 From 6eef9a1d1edafb64da52d10d8f5d827567644410 Mon Sep 17 00:00:00 2001 From: Xele02 Date: Sat, 15 Dec 2012 12:59:31 +0100 Subject: [PATCH 08/11] Add localtime_r function which is not existing in Windows --- Common/FileUtil.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index 885efe8615..8027e56261 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -70,6 +70,16 @@ static inline int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **res } #endif +// No thread safe +#ifdef _WIN32 +inline struct tm* localtime_r (const time_t *clock, struct tm *result) { + if (!clock || !result) return NULL; + memcpy(result,localtime(clock),sizeof(*result)); + return result; +} +#endif + + // This namespace has various generic functions related to files and paths. // The code still needs a ton of cleanup. // REMEMBER: strdup considered harmful! From 8a07e54ca888c624ebf2a995aeeb85e1722fbc3a Mon Sep 17 00:00:00 2001 From: Xele02 Date: Sat, 15 Dec 2012 14:00:41 +0100 Subject: [PATCH 09/11] Sync native --- native | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native b/native index 417a7ae2f3..0de5e114f3 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 417a7ae2f36e9186d07248b2f3d1ec4645524a9b +Subproject commit 0de5e114f337859a03d0763c30beaf6e03af03c4 From bd1a9c2b1a9d36da4d7623dd5b6436da5b266cfb Mon Sep 17 00:00:00 2001 From: Xele02 Date: Sun, 16 Dec 2012 12:51:02 +0100 Subject: [PATCH 10/11] Make Save/Load List work when there is no multiple save files in the request. --- Core/Dialog/SavedataParam.cpp | 94 +++++++++++++++++++++++++++++++++-- Core/Dialog/SavedataParam.h | 2 +- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index e2897c69ef..189b04f11b 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -433,6 +433,95 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param) } saveNameListDataCount = realCount; } + else // Load info on only save + { + saveNameListData == 0; + + Clear(); + saveDataList = new SaveFileInfo[1]; + + // get and stock file info for each file + DEBUG_LOG(HLE,"Name : %s",GetSaveName(param).c_str()); + + std::string fileDataPath = savePath+GetGameName(param)+GetSaveName(param)+"/"+param->fileName; + PSPFileInfo info = pspFileSystem.GetFileInfo(fileDataPath); + if(info.exists) + { + saveDataList[0].size = info.size; + saveDataList[0].saveName = GetSaveName(param); + saveDataList[0].idx = 0; + saveDataList[0].modif_time = info.mtime; + + // Search save image icon0 + // TODO : If icon0 don't exist, need to use icon1 which is a moving icon. Also play sound + std::string fileDataPath2 = savePath+GetGameName(param)+GetSaveName(param)+"/"+icon0Name; + PSPFileInfo info2 = pspFileSystem.GetFileInfo(fileDataPath2); + if(info2.exists) + { + u8* textureDataPNG = new u8[info2.size]; + int handle = pspFileSystem.OpenFile(fileDataPath2,FILEACCESS_READ); + pspFileSystem.ReadFile(handle,textureDataPNG,info2.size); + pspFileSystem.CloseFile(handle); + unsigned char* textureData; + int w,h; + pngLoadPtr(textureDataPNG, info2.size, &w, &h, &textureData, false); + delete[] textureDataPNG; + u32 texSize = w*h*4; + u32 atlasPtr = kernelMemory.Alloc(texSize, true, "SaveData Icon"); + saveDataList[0].textureData = atlasPtr; + Memory::Memcpy(atlasPtr, textureData, texSize); + free(textureData); + saveDataList[0].textureWidth = w; + saveDataList[0].textureHeight = h; + } + else + { + saveDataList[0].textureData = 0; + } + + // Load info in PARAM.SFO + fileDataPath2 = savePath+GetGameName(param)+GetSaveName(param)+"/"+sfoName; + info2 = pspFileSystem.GetFileInfo(fileDataPath2); + if(info2.exists) + { + u8* sfoParam = new u8[info2.size]; + int handle = pspFileSystem.OpenFile(fileDataPath2,FILEACCESS_READ); + pspFileSystem.ReadFile(handle,sfoParam,info2.size); + pspFileSystem.CloseFile(handle); + ParamSFOData sfoFile; + if(sfoFile.ReadSFO(sfoParam,info2.size)) + { + std::string title = sfoFile.GetValueString("TITLE"); + memcpy(saveDataList[0].title,title.c_str(),title.size()); + saveDataList[0].title[title.size()] = 0; + + std::string savetitle = sfoFile.GetValueString("SAVEDATA_TITLE"); + memcpy(saveDataList[0].saveTitle,savetitle.c_str(),savetitle.size()); + saveDataList[0].saveTitle[savetitle.size()] = 0; + + std::string savedetail = sfoFile.GetValueString("SAVEDATA_DETAIL"); + memcpy(saveDataList[0].saveDetail,savedetail.c_str(),savedetail.size()); + saveDataList[0].saveDetail[savedetail.size()] = 0; + } + delete sfoParam; + } + + DEBUG_LOG(HLE,"%s Exist",fileDataPath.c_str()); + saveNameListDataCount = 1; + } + else + { + if(listEmptyFile) + { + saveDataList[0].size = 0; + saveDataList[0].saveName = GetSaveName(param); + saveDataList[0].idx = 0; + saveDataList[0].textureData = 0; + DEBUG_LOG(HLE,"Don't Exist"); + } + saveNameListDataCount = 0; + } + } } SceUtilitySavedataParam* SavedataParam::GetPspParam() @@ -451,10 +540,7 @@ const SaveFileInfo& SavedataParam::GetFileInfo(int idx) } std::string SavedataParam::GetFilename(int idx) { - char fileName[21]; - memcpy(fileName,saveDataList[idx].saveName,20); - fileName[20] = 0; - return fileName; + return saveDataList[idx].saveName; } int SavedataParam::GetSelectedSave() diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index fdbae353f7..23c77e28ad 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -121,7 +121,7 @@ struct SceUtilitySavedataParam struct SaveFileInfo { int size; - char* saveName; + std::string saveName; int idx; char title[128]; From 71839414ca06ee77cab9960f284d000e602ce29d Mon Sep 17 00:00:00 2001 From: Xele02 Date: Sun, 16 Dec 2012 13:07:11 +0100 Subject: [PATCH 11/11] Fix Android build cast error Remove gl command for texture 2d --- Common/FileUtil.cpp | 2 +- GPU/GLES/TransformPipeline.cpp | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index 8027e56261..ee1d71dd26 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -375,7 +375,7 @@ tm GetModifTime(const std::string &filename) { DEBUG_LOG(COMMON, "GetCreateTime: %s: %lld", filename.c_str(), (long long)buf.st_mtime); - localtime_r(&buf.st_mtime,&return_time); + localtime_r((time_t*)&buf.st_mtime,&return_time); return return_time; } diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 6bf47ce136..31071a23b6 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -215,14 +215,9 @@ void GLES_GPU::TransformAndDrawPrim(void *verts, void *inds, int prim, int verte { if ((gstate.textureMapEnable & 1) && !gstate.isModeClear()) { - glEnable(GL_TEXTURE_2D); PSPSetTexture(); useTexCoord = true; } - else - { - glDisable(GL_TEXTURE_2D); - } } gpuStats.numDrawCalls++; gpuStats.numVertsTransformed += vertexCount;