1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
////////////////////////////////////////////////////////////////////////////////////////
//
// Nestopia - NES/Famicom emulator written in C++
//
// Copyright (C) 2003-2008 Martin Freij
//
// This file is part of Nestopia.
//
// Nestopia 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; either version 2 of the License, or
// (at your option) any later version.
//
// Nestopia 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.
//
// You should have received a copy of the GNU General Public License
// along with Nestopia; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
////////////////////////////////////////////////////////////////////////////////////////
#ifndef NST_IO_ACCESSOR_H
#define NST_IO_ACCESSOR_H
#ifdef NST_PRAGMA_ONCE
#pragma once
#endif
namespace Nes
{
namespace Core
{
namespace Io
{
#ifdef NST_FASTDELEGATE
class Accessor
{
public:
template<typename T> struct Type
{
typedef Data (NST_FASTCALL T::*Function)(Address);
};
private:
class Component {};
typedef Type<Component>::Function Function;
Component* component;
Function function;
public:
Accessor() {}
template<typename T>
Accessor(T* c,typename Type<T>::Function f)
:
component ( reinterpret_cast<Component*>(c) ),
function ( reinterpret_cast<Function>(f) )
{
NST_COMPILE_ASSERT( sizeof(function) == sizeof(f) );
}
template<typename T>
void Set(T* c,typename Type<T>::Function f)
{
NST_COMPILE_ASSERT( sizeof(function) == sizeof(f) );
component = reinterpret_cast<Component*>(c);
function = reinterpret_cast<Function>(f);
}
Data Fetch(Address address) const
{
return (*component.*function)( address );
}
};
#define NES_DECL_ACCESSOR(a_) Data NST_FASTCALL Access_##a_(Address)
#define NES_ACCESSOR(o_,a_) Data NST_FASTCALL o_::Access_##a_(Address address)
#else
class Accessor
{
typedef void* Component;
typedef Data (NST_REGCALL *Function)(Component,Address);
Component component;
Function function;
public:
Accessor() {}
Accessor(Component c,Function t)
:
component ( c ),
function ( t )
{}
void Set(Component c,Function t)
{
component = c;
function = t;
}
Data Fetch(Address address) const
{
return function( component, address );
}
template<typename T> struct Type
{
typedef Data (NST_REGCALL *Function)(Component,Address);
};
};
#define NES_DECL_ACCESSOR(a_) \
\
NST_SINGLE_CALL Data NST_FASTCALL Access_M_##a_(Address); \
static NST_NO_INLINE Data NST_REGCALL Access_##a_(void*,Address)
#define NES_ACCESSOR(o_,a_) \
\
NST_NO_INLINE Data NST_REGCALL o_::Access_##a_(void* p_,Address i_) \
{ \
return static_cast<o_*>(p_)->Access_M_##a_(i_); \
} \
\
NST_SINGLE_CALL Data NST_FASTCALL o_::Access_M_##a_(Address address)
#endif
}
}
}
#endif
|