cdvdgigaherz: Change signs

Avoid some unnecessary casting.
This commit is contained in:
Jonathan Li 2016-11-11 17:51:19 +00:00 committed by Gregory Hainaut
parent 008fea5d89
commit 23f48e07ed
5 changed files with 43 additions and 54 deletions

View File

@ -113,7 +113,6 @@ bool weAreInNewDiskCB = false;
std::unique_ptr<IOCtlSrc> src;
char throwaway[2352];
extern s32 prefetch_last_lba;
extern s32 prefetch_last_mode;
@ -122,6 +121,8 @@ extern s32 prefetch_last_mode;
void keepAliveThread()
{
u8 throwaway[2352];
printf(" * CDVD: KeepAlive thread started...\n");
std::unique_lock<std::mutex> guard(s_keepalive_lock);
@ -236,11 +237,11 @@ EXPORT s32 CALLBACK CDVDgetDualInfo(s32 *dualType, u32 *_layer1start)
}
int lastReadInNewDiskCB = 0;
char directReadSectorBuffer[2448];
u8 directReadSectorBuffer[2448];
EXPORT s32 CALLBACK CDVDreadSector(u8 *buffer, u32 lsn, int mode)
{
return cdvdDirectReadSector(lsn, mode, (char *)buffer);
return cdvdDirectReadSector(lsn, mode, buffer);
}
EXPORT s32 CALLBACK CDVDreadTrack(u32 lsn, int mode)
@ -263,12 +264,10 @@ EXPORT u8 *CALLBACK CDVDgetBuffer()
{
if (lastReadInNewDiskCB) {
lastReadInNewDiskCB = 0;
return (u8 *)directReadSectorBuffer;
return directReadSectorBuffer;
}
u8 *s = (u8 *)cdvdGetSector(csector, cmode);
return s;
return cdvdGetSector(csector, cmode);
}
// return can be NULL (for async modes)

View File

@ -24,6 +24,7 @@
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <memory>
#include <mutex>
#include <string>
@ -83,8 +84,8 @@ public:
u32 GetSectorCount() const;
const std::vector<toc_entry> &ReadTOC() const;
bool ReadSectors2048(u32 sector, u32 count, char *buffer) const;
bool ReadSectors2352(u32 sector, u32 count, char *buffer) const;
bool ReadSectors2048(u32 sector, u32 count, u8 *buffer) const;
bool ReadSectors2352(u32 sector, u32 count, u8 *buffer) const;
u32 GetLayerBreakAddress() const;
s32 GetMediaType() const;
void SetSpindleSpeed(bool restore_defaults) const;
@ -114,8 +115,8 @@ bool cdvdStartThread();
void cdvdStopThread();
s32 cdvdRequestSector(u32 sector, s32 mode);
s32 cdvdRequestComplete();
char *cdvdGetSector(s32 sector, s32 mode);
s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer);
u8 *cdvdGetSector(u32 sector, s32 mode);
s32 cdvdDirectReadSector(u32 first, s32 mode, u8 *buffer);
s32 cdvdGetMediaType();
s32 cdvdRefreshData();
void cdvdParseTOC();

View File

@ -16,8 +16,16 @@
#include "CDVD.h"
#include <atomic>
#include <condition_variable>
#include <limits>
#include <thread>
struct SectorInfo
{
u32 lsn;
s32 mode;
u8 data[2352 * 16]; // we will read in blocks of 16 sectors
};
const s32 prefetch_max_blocks = 16;
s32 prefetch_mode = 0;
s32 prefetch_last_lba = 0;
@ -34,28 +42,21 @@ static std::mutex s_cache_lock;
static std::atomic<bool> cdvd_is_open;
typedef struct
{
int lsn;
int mode;
char data[2352 * 16]; //we will read in blocks of 16 sectors
} SectorInfo;
//bits: 12 would use 1<<12 entries, or 4096*16 sectors ~ 128MB
#define CACHE_SIZE 12
const s32 CacheSize = (1 << CACHE_SIZE);
const u32 CacheSize = 1U << CACHE_SIZE;
SectorInfo Cache[CacheSize];
bool threadRequestPending;
SectorInfo threadRequestInfo;
u32 cdvdSectorHash(int lsn, int mode)
u32 cdvdSectorHash(u32 lsn, s32 mode)
{
u32 t = 0;
int i = 32;
int m = CacheSize - 1;
u32 m = CacheSize - 1;
while (i >= 0) {
t ^= lsn & m;
@ -66,7 +67,7 @@ u32 cdvdSectorHash(int lsn, int mode)
return (t ^ mode) & m;
}
void cdvdCacheUpdate(int lsn, int mode, char *data)
void cdvdCacheUpdate(u32 lsn, s32 mode, u8 *data)
{
std::lock_guard<std::mutex> guard(s_cache_lock);
u32 entry = cdvdSectorHash(lsn, mode);
@ -76,7 +77,7 @@ void cdvdCacheUpdate(int lsn, int mode, char *data)
Cache[entry].mode = mode;
}
bool cdvdCacheFetch(int lsn, int mode, char *data)
bool cdvdCacheFetch(u32 lsn, s32 mode, u8 *data)
{
std::lock_guard<std::mutex> guard(s_cache_lock);
u32 entry = cdvdSectorHash(lsn, mode);
@ -93,8 +94,8 @@ bool cdvdCacheFetch(int lsn, int mode, char *data)
void cdvdCacheReset()
{
std::lock_guard<std::mutex> guard(s_cache_lock);
for (int i = 0; i < CacheSize; i++) {
Cache[i].lsn = -1;
for (u32 i = 0; i < CacheSize; i++) {
Cache[i].lsn = std::numeric_limits<u32>::max();
Cache[i].mode = -1;
}
}
@ -161,11 +162,7 @@ void cdvdThread()
}
if (threadRequestPending || prefetch_left) {
s32 count = 16;
s32 left = src->GetSectorCount() - info.lsn;
if (left < count)
count = left;
u32 count = std::min(16U, src->GetSectorCount() - info.lsn);
for (int tries = 0; tries < 4; ++tries) {
if (info.mode == CDVD_MODE_2048) {
@ -246,7 +243,7 @@ s32 cdvdRequestComplete()
return !threadRequestPending;
}
s8 *cdvdGetSector(s32 sector, s32 mode)
u8 *cdvdGetSector(u32 sector, s32 mode)
{
{
std::unique_lock<std::mutex> guard(s_request_lock);
@ -254,15 +251,13 @@ s8 *cdvdGetSector(s32 sector, s32 mode)
s_request_cv.wait_for(guard, std::chrono::milliseconds(10));
}
s32 offset;
if (mode == CDVD_MODE_2048) {
offset = 2048 * (sector - threadRequestInfo.lsn);
u32 offset = 2048 * (sector - threadRequestInfo.lsn);
return threadRequestInfo.data + offset;
}
offset = 2352 * (sector - threadRequestInfo.lsn);
s8 *data = threadRequestInfo.data + offset;
u32 offset = 2352 * (sector - threadRequestInfo.lsn);
u8 *data = threadRequestInfo.data + offset;
switch (mode) {
case CDVD_MODE_2328:
@ -273,21 +268,17 @@ s8 *cdvdGetSector(s32 sector, s32 mode)
return data;
}
s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer)
s32 cdvdDirectReadSector(u32 first, s32 mode, u8 *buffer)
{
static char data[16 * 2352];
static u8 data[16 * 2352];
if ((u32)first >= src->GetSectorCount())
if (first >= src->GetSectorCount())
return -1;
s32 sector = first & (~15); //align to 16-sector block
u32 sector = first & (~15); //align to 16-sector block
if (!cdvdCacheFetch(sector, mode, data)) {
s32 count = 16;
s32 left = src->GetSectorCount() - sector;
if (left < count)
count = left;
u32 count = std::min(16U, src->GetSectorCount() - sector);
for (int tries = 0; tries < 4; ++tries) {
if (mode == CDVD_MODE_2048) {
@ -302,16 +293,14 @@ s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer)
cdvdCacheUpdate(sector, mode, data);
}
s32 offset;
if (mode == CDVD_MODE_2048) {
offset = 2048 * (first - sector);
u32 offset = 2048 * (first - sector);
memcpy(buffer, data + offset, 2048);
return 0;
}
offset = 2352 * (first - sector);
s8 *bfr = data + offset;
u32 offset = 2352 * (first - sector);
u8 *bfr = data + offset;
switch (mode) {
case CDVD_MODE_2328:

View File

@ -84,7 +84,7 @@ const std::vector<toc_entry> &IOCtlSrc::ReadTOC() const
return m_toc;
}
bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer) const
bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, u8 *buffer) const
{
std::lock_guard<std::mutex> guard(m_lock);
@ -108,7 +108,7 @@ bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer) const
return false;
}
bool IOCtlSrc::ReadSectors2352(u32 sector, u32 count, char *buffer) const
bool IOCtlSrc::ReadSectors2352(u32 sector, u32 count, u8 *buffer) const
{
union
{

View File

@ -111,7 +111,7 @@ const std::vector<toc_entry> &IOCtlSrc::ReadTOC() const
return m_toc;
}
bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer) const
bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, u8 *buffer) const
{
std::lock_guard<std::mutex> guard(m_lock);
LARGE_INTEGER offset;
@ -138,7 +138,7 @@ bool IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer) const
return false;
}
bool IOCtlSrc::ReadSectors2352(u32 sector, u32 count, char *buffer) const
bool IOCtlSrc::ReadSectors2352(u32 sector, u32 count, u8 *buffer) const
{
struct sptdinfo
{