diff --git a/src/core/CdStream.h b/src/core/CdStream.h index d35c5a6d..7b665fda 100644 --- a/src/core/CdStream.h +++ b/src/core/CdStream.h @@ -1,23 +1,40 @@ #ifndef __GTA_CDSTREAM_H__ #define __GTA_CDSTREAM_H__ +// IMPORTANT: this file has to be includable from C, +// so no custom types like int32 &c. + #define CDSTREAM_SECTOR_SIZE 2048 #define _GET_INDEX(a) (a >> 24) #define _GET_OFFSET(a) (a & 0xFFFFFF) +#ifdef __cplusplus +extern "C" +{ +#endif + +// These have to match IOP and also some SCE defines enum { - STREAM_NONE = uint8( 0), - STREAM_SUCCESS = uint8( 1), - STREAM_READING = uint8(-1), // 0xFF, - STREAM_ERROR = uint8(-2), // 0xFE, - STREAM_ERROR_NOCD = uint8(-3), // 0xFD, - STREAM_ERROR_WRONGCD = uint8(-4), // 0xFC, - STREAM_ERROR_OPENCD = uint8(-5), // 0xFB, - STREAM_WAITING = uint8(-6) // 0xFA, + STREAM_NONE = 0, + STREAM_SUCCESS = 1, + STREAM_READING = 0xFF, + STREAM_ERROR = 0xFE, // SCECdErREADCFR + STREAM_ERROR_NOCD = 0xFD, // SCECdErREADCF + STREAM_ERROR_WRONGCD = 0xFC, + STREAM_ERROR_OPENCD = 0xFB, + STREAM_WAITING = 0xFA }; +void CdStreamInit(int numChannels); +int CdStreamRead(int channel, void *buffer, unsigned int offset, unsigned int size); +int CdStreamGetStatus(int channel); +int CdStreamGetLastPosn(void); +int CdStreamSync(int channel); + +#ifndef GTA_PS2 +typedef struct Queue Queue; struct Queue { int32 *items; @@ -28,24 +45,27 @@ struct Queue VALIDATE_SIZE(Queue, 0x10); -void CdStreamInitThread(void); -void CdStreamInit(int32 numChannels); -uint32 GetGTA3ImgSize(void); void CdStreamShutdown(void); -int32 CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size); -int32 CdStreamGetStatus(int32 channel); -int32 CdStreamGetLastPosn(void); -int32 CdStreamSync(int32 channel); -void AddToQueue(Queue *queue, int32 item); +// on IOP on PS2 +void CdStreamInitThread(void); +void AddToQueue(Queue *queue, int item); int32 GetFirstInQueue(Queue *queue); void RemoveFirstInQueue(Queue *queue); + +// not on PS2 at all +uint32 GetGTA3ImgSize(void); bool CdStreamAddImage(char const *path); -char *CdStreamGetImageName(int32 cd); +char *CdStreamGetImageName(int cd); void CdStreamRemoveImages(void); int32 CdStreamGetNumImages(void); +#endif #ifdef FLUSHABLE_STREAMING extern bool flushStream[MAX_CDCHANNELS]; #endif +#ifdef __cplusplus +} +#endif + #endif // __GTA_CDSTREAM_H__ diff --git a/src/core/CdStream_ee.c b/src/core/CdStream_ee.c new file mode 100644 index 00000000..24f587d4 --- /dev/null +++ b/src/core/CdStream_ee.c @@ -0,0 +1,65 @@ +#include "config.h" +#ifdef GTA_PS2 +#include +#include +#include +#include + +#include "CdStream.h" + +unsigned int gRpcOutArgBuffer[16] __attribute__ ((aligned(64))); +unsigned int gRpcInArgBuffer[16] __attribute__ ((aligned(64))); +sceSifClientData gCdStreamClientData; + +void +CdStreamInit(int n) +{ + int i; + + sceSifInitRpc(0); + while(1){ + if(sceSifBindRpc(&gCdStreamClientData, 0x65686577, 0) < 0) + printf("sceSifBindRpc to Cdvd Stream module failed"); + if(gCdStreamClientData.serve != 0) + break; + i = 10000; + while(i--); + } + gRpcInArgBuffer[0] = n; + sceSifCallRpc(&gCdStreamClientData, 0, 0, gRpcInArgBuffer, 16, NULL, 0, NULL, NULL); +} + +int +CdStreamRead(int chan, void *buf, unsigned int off, unsigned int size) +{ + gRpcInArgBuffer[0] = chan; + gRpcInArgBuffer[1] = (int)buf; + gRpcInArgBuffer[2] = off; + gRpcInArgBuffer[3] = size; + sceSifCallRpc(&gCdStreamClientData, 1, 0, gRpcInArgBuffer, 16, gRpcOutArgBuffer, 16, NULL, NULL); + return gRpcOutArgBuffer[0]; +} + +int +CdStreamGetStatus(int chan) +{ + gRpcInArgBuffer[0] = chan; + sceSifCallRpc(&gCdStreamClientData, 2, 0, gRpcInArgBuffer, 16, gRpcOutArgBuffer, 16, NULL, NULL); + return gRpcOutArgBuffer[0]; +} + +int +CdStreamGetLastPosn(void) +{ + sceSifCallRpc(&gCdStreamClientData, 4, 0, gRpcInArgBuffer, 0, gRpcOutArgBuffer, 16, NULL, NULL); + return gRpcOutArgBuffer[0]; +} + +int +CdStreamSync(int chan) +{ + gRpcInArgBuffer[0] = chan; + sceSifCallRpc(&gCdStreamClientData, 3, 0, gRpcInArgBuffer, 16, gRpcOutArgBuffer, 16, NULL, NULL); + return gRpcOutArgBuffer[0]; +} +#endif diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStream_posix.cpp similarity index 99% rename from src/core/CdStreamPosix.cpp rename to src/core/CdStream_posix.cpp index bc9129eb..d4fcf676 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStream_posix.cpp @@ -1,5 +1,6 @@ #ifndef _WIN32 #include "common.h" +#ifdef GTA_PC #include "crossplatform.h" #include #include @@ -20,7 +21,6 @@ #endif #include "CdStream.h" -#include "rwcore.h" #include "MemoryMgr.h" #define CDDEBUG(f, ...) debug ("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__) @@ -602,3 +602,4 @@ CdStreamGetNumImages(void) return gNumImages; } #endif +#endif diff --git a/src/core/CdStream.cpp b/src/core/CdStream_win.cpp similarity index 99% rename from src/core/CdStream.cpp rename to src/core/CdStream_win.cpp index 977f16c2..f86c683a 100644 --- a/src/core/CdStream.cpp +++ b/src/core/CdStream_win.cpp @@ -3,8 +3,6 @@ #include "common.h" #include "CdStream.h" -#include "rwcore.h" -#include "RwHelper.h" #include "MemoryMgr.h" struct CdReadInfo