2008-07-12 17:40:22 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#ifndef _DATAREADER_H
|
|
|
|
#define _DATAREADER_H
|
|
|
|
|
2008-09-29 17:29:25 +00:00
|
|
|
#include "Fifo.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(DATAREADER_INLINE) || defined(DATAREADER_DEBUG)
|
2008-07-12 17:40:22 +00:00
|
|
|
// =================================================================================================
|
|
|
|
// IDataReader
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
class IDataReader
|
2008-09-22 23:25:29 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual ~IDataReader();
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void Skip(u32) = 0;
|
2008-08-31 13:36:52 +00:00
|
|
|
virtual u8 Read8 () = 0;
|
|
|
|
virtual u16 Read16() = 0;
|
|
|
|
virtual u32 Read32() = 0;
|
|
|
|
|
|
|
|
virtual int GetPosition() = 0; // return values can be anything, as long as relative distances are correct
|
2008-10-02 18:43:56 +00:00
|
|
|
virtual u8* GetRealCurrentPtr() = 0;
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
// CDataReader_Fifo
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
class CDataReader_Fifo : public IDataReader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
2008-08-31 13:36:52 +00:00
|
|
|
CDataReader_Fifo();
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
virtual void Skip(u32);
|
2008-08-31 13:36:52 +00:00
|
|
|
virtual u8 Read8();
|
|
|
|
virtual u16 Read16();
|
|
|
|
virtual u32 Read32();
|
|
|
|
virtual int GetPosition();
|
2008-10-02 18:43:56 +00:00
|
|
|
virtual u8* GetRealCurrentPtr();
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// =================================================================================================
|
|
|
|
// CDataReader_Memory
|
|
|
|
// =================================================================================================
|
|
|
|
|
|
|
|
class CDataReader_Memory : public IDataReader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
//u8* m_pMemory;
|
|
|
|
u32 m_uReadAddress;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CDataReader_Memory(u32 _uAddress);
|
|
|
|
|
2008-08-31 13:36:52 +00:00
|
|
|
u32 GetReadAddress();
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
virtual void Skip(u32);
|
2008-08-31 13:36:52 +00:00
|
|
|
virtual u8 Read8();
|
|
|
|
virtual u16 Read16();
|
|
|
|
virtual u32 Read32();
|
|
|
|
virtual int GetPosition();
|
2008-10-02 18:43:56 +00:00
|
|
|
virtual u8* GetRealCurrentPtr();
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern IDataReader* g_pDataReader;
|
2008-09-29 17:29:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DATAREADER_INLINE
|
2008-10-02 18:43:56 +00:00
|
|
|
extern u8* g_pVideoData;
|
2008-09-29 17:29:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DATAREADER_DEBUG
|
2008-10-02 18:43:56 +00:00
|
|
|
extern u8* g_pDataReaderRealPtr;
|
|
|
|
#define DATAREADER_DEBUG_CHECK_PTR g_pDataReaderRealPtr = g_pDataReader->GetRealCurrentPtr(); \
|
2008-09-29 17:29:25 +00:00
|
|
|
if (g_pDataReaderRealPtr!=g_pVideoData) _asm int 3
|
2008-10-02 18:43:56 +00:00
|
|
|
#define DATAREADER_DEBUG_CHECK_PTR_VAL g_pDataReaderRealPtr = g_pDataReader->GetRealCurrentPtr(); \
|
2008-09-29 17:29:25 +00:00
|
|
|
if ((g_pDataReaderRealPtr != g_pVideoData) || (tmp != tmpdb)) _asm int 3
|
|
|
|
//#define DATAREADER_DEBUG_CHECK_PTR_VAL DATAREADER_DEBUG_CHECK_PTR
|
|
|
|
#else
|
|
|
|
#define DATAREADER_DEBUG_CHECK_PTR
|
|
|
|
#define DATAREADER_DEBUG_CHECK_PTR_VAL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DATAREADER_INLINE
|
|
|
|
inline u8 DataPeek8(u32 _uOffset)
|
|
|
|
{
|
|
|
|
u8 tmp = *(u8*)(g_pVideoData + _uOffset);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
inline u16 DataPeek16(u32 _uOffset)
|
|
|
|
{
|
|
|
|
u16 tmp = Common::swap16(*(u16*)(g_pVideoData + _uOffset));
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
inline u32 DataPeek32(u32 _uOffset) {
|
|
|
|
u32 tmp = Common::swap32(*(u32*)(g_pVideoData + _uOffset));
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline u8 DataReadU8()
|
|
|
|
{
|
2008-10-02 18:43:56 +00:00
|
|
|
u8 tmp = *g_pVideoData;
|
2008-09-29 17:29:25 +00:00
|
|
|
g_pVideoData++;
|
|
|
|
#ifdef DATAREADER_DEBUG
|
|
|
|
u8 tmpdb = g_pDataReader->Read8();
|
|
|
|
DATAREADER_DEBUG_CHECK_PTR_VAL;
|
|
|
|
#endif
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline u16 DataReadU16()
|
|
|
|
{
|
|
|
|
u16 tmp = Common::swap16(*(u16*)g_pVideoData);
|
|
|
|
g_pVideoData+=2;
|
|
|
|
#ifdef DATAREADER_DEBUG
|
|
|
|
u16 tmpdb = g_pDataReader->Read16();
|
|
|
|
DATAREADER_DEBUG_CHECK_PTR_VAL;
|
|
|
|
#endif
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline u32 DataReadU32()
|
|
|
|
{
|
|
|
|
u32 tmp = Common::swap32(*(u32*)g_pVideoData);
|
|
|
|
g_pVideoData+=4;
|
|
|
|
#ifdef DATAREADER_DEBUG
|
|
|
|
u32 tmpdb = g_pDataReader->Read32();
|
|
|
|
DATAREADER_DEBUG_CHECK_PTR_VAL;
|
|
|
|
#endif
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float DataReadF32()
|
|
|
|
{
|
|
|
|
union {u32 i; float f;} temp;
|
|
|
|
temp.i = Common::swap32(*(u32*)g_pVideoData);
|
|
|
|
g_pVideoData+=4;
|
|
|
|
float tmp = temp.f;
|
|
|
|
#ifdef DATAREADER_DEBUG
|
|
|
|
//TODO clean up
|
|
|
|
u32 tmp3 = g_pDataReader->Read32();
|
|
|
|
float tmpdb = *(float*)(&tmp3);
|
|
|
|
DATAREADER_DEBUG_CHECK_PTR_VAL;
|
|
|
|
#endif
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-10-02 18:43:56 +00:00
|
|
|
inline u8* DataGetPosition()
|
2008-09-29 17:29:25 +00:00
|
|
|
{
|
|
|
|
#ifdef DATAREADER_DEBUG
|
|
|
|
DATAREADER_DEBUG_CHECK_PTR;
|
|
|
|
#endif
|
|
|
|
return g_pVideoData;
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-29 17:29:25 +00:00
|
|
|
inline void DataSkip(u32 skip)
|
|
|
|
{
|
|
|
|
g_pVideoData += skip;
|
|
|
|
#ifdef DATAREADER_DEBUG
|
|
|
|
g_pDataReader->Skip(skip);
|
|
|
|
DATAREADER_DEBUG_CHECK_PTR;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
inline u8 DataReadU8()
|
|
|
|
{
|
|
|
|
u8 tmp = g_pDataReader->Read8();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
inline u16 DataReadU16()
|
|
|
|
{
|
|
|
|
u16 tmp = g_pDataReader->Read16();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
inline u32 DataReadU32()
|
|
|
|
{
|
|
|
|
u32 tmp = g_pDataReader->Read32();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
inline float DataReadF32()
|
|
|
|
{
|
|
|
|
u32 tmp2 = g_pDataReader->Read32();
|
|
|
|
float tmp = *(float*)(&tmp2);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
inline void DataSkip(u32 skip)
|
|
|
|
{
|
|
|
|
g_pDataReader->Skip(skip);
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-12 17:40:22 +00:00
|
|
|
#endif
|