2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 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 for more details.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
|
|
|
|
2009-05-02 10:48:41 +00:00
|
|
|
#pragma once
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-06 12:37:37 +00:00
|
|
|
#include "MemoryTypes.h"
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
extern uptr *psxMemWLUT;
|
|
|
|
extern const uptr *psxMemRLUT;
|
|
|
|
|
2009-02-27 18:12:59 +00:00
|
|
|
|
2009-03-01 21:49:17 +00:00
|
|
|
// Obtains a writable pointer into the IOP's memory, with TLB address translation.
|
|
|
|
// If the address maps to read-only memory, NULL is returned.
|
|
|
|
// Hacky! This should really never be used, ever, since it bypasses the iop's Hardware
|
|
|
|
// Register handler and SPU/DEV/USB maps.
|
2010-05-28 10:33:15 +00:00
|
|
|
template<typename T>
|
2010-08-09 04:10:38 +00:00
|
|
|
static __fi T* iopVirtMemW( u32 mem )
|
2009-02-27 18:12:59 +00:00
|
|
|
{
|
2009-03-01 21:49:17 +00:00
|
|
|
return (psxMemWLUT[(mem) >> 16] == 0) ? NULL : (T*)(psxMemWLUT[(mem) >> 16] + ((mem) & 0xffff));
|
2010-05-28 10:33:15 +00:00
|
|
|
}
|
2009-03-01 21:49:17 +00:00
|
|
|
|
|
|
|
// Obtains a read-safe pointer into the IOP's physical memory, with TLB address translation.
|
|
|
|
// Returns NULL if the address maps to an invalid/unmapped physical address.
|
|
|
|
//
|
|
|
|
// Hacky! This should really never be used, since anything reading through the
|
|
|
|
// TLB should be using iopMemRead/Write instead for each individual access. That ensures
|
|
|
|
// correct handling of page boundary crossings.
|
2009-02-27 18:12:59 +00:00
|
|
|
template<typename T>
|
2010-08-09 04:10:38 +00:00
|
|
|
static __fi const T* iopVirtMemR( u32 mem )
|
2009-02-27 18:12:59 +00:00
|
|
|
{
|
2009-03-19 03:59:25 +00:00
|
|
|
mem &= 0x1fffffff;
|
|
|
|
return (psxMemRLUT[mem >> 16] == 0) ? NULL : (const T*)(psxMemRLUT[mem >> 16] + (mem & 0xffff));
|
2009-02-27 18:12:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains a pointer to the IOP's physical mapping (bypasses the TLB)
|
2010-08-09 04:10:38 +00:00
|
|
|
static __fi u8* iopPhysMem( u32 addr )
|
2009-02-27 18:12:59 +00:00
|
|
|
{
|
2010-09-23 19:44:55 +00:00
|
|
|
return &iopMem->Main[addr & 0x1fffff];
|
2009-02-27 18:12:59 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-09-23 19:44:55 +00:00
|
|
|
#define psxSs8(mem) iopMem->Sif[(mem) & 0x00ff]
|
|
|
|
#define psxSs16(mem) (*(s16*)&iopMem->Sif[(mem) & 0x00ff])
|
|
|
|
#define psxSs32(mem) (*(s32*)&iopMem->Sif[(mem) & 0x00ff])
|
|
|
|
#define psxSu8(mem) (*(u8*) &iopMem->Sif[(mem) & 0x00ff])
|
|
|
|
#define psxSu16(mem) (*(u16*)&iopMem->Sif[(mem) & 0x00ff])
|
|
|
|
#define psxSu32(mem) (*(u32*)&iopMem->Sif[(mem) & 0x00ff])
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-09-23 19:44:55 +00:00
|
|
|
#define psxPs8(mem) iopMem->P[(mem) & 0xffff]
|
|
|
|
#define psxPs16(mem) (*(s16*)&iopMem->P[(mem) & 0xffff])
|
|
|
|
#define psxPs32(mem) (*(s32*)&iopMem->P[(mem) & 0xffff])
|
|
|
|
#define psxPu8(mem) (*(u8*) &iopMem->P[(mem) & 0xffff])
|
|
|
|
#define psxPu16(mem) (*(u16*)&iopMem->P[(mem) & 0xffff])
|
|
|
|
#define psxPu32(mem) (*(u32*)&iopMem->P[(mem) & 0xffff])
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-09-23 19:44:55 +00:00
|
|
|
#define psxHs8(mem) iopHw[(mem) & 0xffff]
|
|
|
|
#define psxHs16(mem) (*(s16*)&iopHw[(mem) & 0xffff])
|
|
|
|
#define psxHs32(mem) (*(s32*)&iopHw[(mem) & 0xffff])
|
|
|
|
#define psxHu8(mem) (*(u8*) &iopHw[(mem) & 0xffff])
|
|
|
|
#define psxHu16(mem) (*(u16*)&iopHw[(mem) & 0xffff])
|
|
|
|
#define psxHu32(mem) (*(u32*)&iopHw[(mem) & 0xffff])
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-11-15 14:05:02 +00:00
|
|
|
extern void psxMemReserve();
|
2009-10-20 20:02:07 +00:00
|
|
|
extern void psxMemAlloc();
|
|
|
|
extern void psxMemReset();
|
|
|
|
extern void psxMemShutdown();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-20 20:02:07 +00:00
|
|
|
extern u8 __fastcall iopMemRead8 (u32 mem);
|
|
|
|
extern u16 __fastcall iopMemRead16(u32 mem);
|
|
|
|
extern u32 __fastcall iopMemRead32(u32 mem);
|
|
|
|
extern void __fastcall iopMemWrite8 (u32 mem, u8 value);
|
|
|
|
extern void __fastcall iopMemWrite16(u32 mem, u16 value);
|
|
|
|
extern void __fastcall iopMemWrite32(u32 mem, u32 value);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-11-08 10:12:38 +00:00
|
|
|
std::string iopMemReadString(u32 mem, int maxlen = 65536);
|
|
|
|
|
2009-05-02 10:48:41 +00:00
|
|
|
namespace IopMemory
|
|
|
|
{
|
|
|
|
// Sif functions not made yet (will for future Iop improvements):
|
2009-05-06 02:15:43 +00:00
|
|
|
extern mem8_t __fastcall SifRead8( u32 iopaddr );
|
|
|
|
extern mem16_t __fastcall SifRead16( u32 iopaddr );
|
|
|
|
extern mem32_t __fastcall SifRead32( u32 iopaddr );
|
|
|
|
|
|
|
|
extern void __fastcall SifWrite8( u32 iopaddr, mem8_t data );
|
|
|
|
extern void __fastcall SifWrite16( u32 iopaddr, mem16_t data );
|
|
|
|
extern void __fastcall SifWrite32( u32 iopaddr, mem32_t data );
|
|
|
|
|
|
|
|
extern mem8_t __fastcall iopHwRead8_generic( u32 addr );
|
|
|
|
extern mem16_t __fastcall iopHwRead16_generic( u32 addr );
|
|
|
|
extern mem32_t __fastcall iopHwRead32_generic( u32 addr );
|
|
|
|
extern void __fastcall iopHwWrite8_generic( u32 addr, mem8_t val );
|
|
|
|
extern void __fastcall iopHwWrite16_generic( u32 addr, mem16_t val );
|
|
|
|
extern void __fastcall iopHwWrite32_generic( u32 addr, mem32_t val );
|
|
|
|
|
|
|
|
|
|
|
|
extern mem8_t __fastcall iopHwRead8_Page1( u32 iopaddr );
|
|
|
|
extern mem8_t __fastcall iopHwRead8_Page3( u32 iopaddr );
|
|
|
|
extern mem8_t __fastcall iopHwRead8_Page8( u32 iopaddr );
|
|
|
|
extern mem16_t __fastcall iopHwRead16_Page1( u32 iopaddr );
|
|
|
|
extern mem16_t __fastcall iopHwRead16_Page3( u32 iopaddr );
|
|
|
|
extern mem16_t __fastcall iopHwRead16_Page8( u32 iopaddr );
|
|
|
|
extern mem32_t __fastcall iopHwRead32_Page1( u32 iopaddr );
|
|
|
|
extern mem32_t __fastcall iopHwRead32_Page3( u32 iopaddr );
|
|
|
|
extern mem32_t __fastcall iopHwRead32_Page8( u32 iopaddr );
|
|
|
|
|
|
|
|
extern void __fastcall iopHwWrite8_Page1( u32 iopaddr, mem8_t data );
|
|
|
|
extern void __fastcall iopHwWrite8_Page3( u32 iopaddr, mem8_t data );
|
|
|
|
extern void __fastcall iopHwWrite8_Page8( u32 iopaddr, mem8_t data );
|
|
|
|
extern void __fastcall iopHwWrite16_Page1( u32 iopaddr, mem16_t data );
|
|
|
|
extern void __fastcall iopHwWrite16_Page3( u32 iopaddr, mem16_t data );
|
|
|
|
extern void __fastcall iopHwWrite16_Page8( u32 iopaddr, mem16_t data );
|
|
|
|
extern void __fastcall iopHwWrite32_Page1( u32 iopaddr, mem32_t data );
|
|
|
|
extern void __fastcall iopHwWrite32_Page3( u32 iopaddr, mem32_t data );
|
|
|
|
extern void __fastcall iopHwWrite32_Page8( u32 iopaddr, mem32_t data );
|
2009-11-16 13:49:56 +00:00
|
|
|
}
|