1
/*********************************************************************
5
Buffered Sprite RAM device.
7
****************************************************************************
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are
16
* Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
18
* Redistributions in binary form must reproduce the above copyright
19
notice, this list of conditions and the following disclaimer in
20
the documentation and/or other materials provided with the
22
* Neither the name 'MAME' nor the names of its contributors may be
23
used to endorse or promote products derived from this software
24
without specific prior written permission.
26
THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
POSSIBILITY OF SUCH DAMAGE.
38
*********************************************************************/
42
#ifndef __BUFSPRITE_H__
43
#define __BUFSPRITE_H__
47
//**************************************************************************
49
//**************************************************************************
51
// device type definition
52
extern const device_type BUFFERED_SPRITERAM8;
53
extern const device_type BUFFERED_SPRITERAM16;
54
extern const device_type BUFFERED_SPRITERAM32;
55
extern const device_type BUFFERED_SPRITERAM64;
59
//**************************************************************************
60
// DEVICE CONFIGURATION MACROS
61
//**************************************************************************
63
#define MCFG_BUFFERED_SPRITERAM8_ADD(_tag) \
64
MCFG_DEVICE_ADD(_tag, BUFFERED_SPRITERAM8, 0) \
66
#define MCFG_BUFFERED_SPRITERAM16_ADD(_tag) \
67
MCFG_DEVICE_ADD(_tag, BUFFERED_SPRITERAM16, 0) \
69
#define MCFG_BUFFERED_SPRITERAM32_ADD(_tag) \
70
MCFG_DEVICE_ADD(_tag, BUFFERED_SPRITERAM32, 0) \
72
#define MCFG_BUFFERED_SPRITERAM64_ADD(_tag) \
73
MCFG_DEVICE_ADD(_tag, BUFFERED_SPRITERAM64, 0) \
77
//**************************************************************************
79
//**************************************************************************
81
// ======================> buffered_spriteram_device
83
// base class to manage buffered spriteram
84
template<typename _Type>
85
class buffered_spriteram_device : public device_t
89
buffered_spriteram_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock)
90
: device_t(mconfig, type, "Buffered Sprite RAM", tag, owner, clock),
91
m_spriteram(*owner, tag) { }
94
_Type *live() const { return m_spriteram; }
95
_Type *buffer() { return m_buffered; }
96
UINT32 bytes() const { return m_spriteram.bytes(); }
99
_Type *copy(UINT32 srcoffset = 0, UINT32 srclength = 0x7fffffff)
101
assert(m_spriteram != NULL);
102
if (m_spriteram != NULL)
103
memcpy(m_buffered, m_spriteram + srcoffset, MIN(srclength, m_spriteram.bytes() / sizeof(_Type) - srcoffset) * sizeof(_Type));
107
// read/write handlers
108
void write(address_space &space, offs_t offset, _Type data, _Type mem_mask = ~_Type(0)) { copy(); }
111
void vblank_copy_rising(screen_device &screen, bool state) { if (state) copy(); }
112
void vblank_copy_falling(screen_device &screen, bool state) { if (!state) copy(); }
116
virtual void device_start()
118
if (m_spriteram != NULL)
120
m_buffered.resize(m_spriteram.bytes() / sizeof(_Type));
121
save_item(NAME(m_buffered));
127
required_shared_ptr<_Type> m_spriteram;
128
dynamic_array<_Type> m_buffered;
132
// ======================> buffered_spriteram8_device
134
class buffered_spriteram8_device : public buffered_spriteram_device<UINT8>
138
buffered_spriteram8_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
139
: buffered_spriteram_device<UINT8>(mconfig, BUFFERED_SPRITERAM8, tag, owner, clock) { }
143
// ======================> buffered_spriteram16_device
145
class buffered_spriteram16_device : public buffered_spriteram_device<UINT16>
149
buffered_spriteram16_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
150
: buffered_spriteram_device<UINT16>(mconfig, BUFFERED_SPRITERAM16, tag, owner, clock) { }
154
// ======================> buffered_spriteram32_device
156
class buffered_spriteram32_device : public buffered_spriteram_device<UINT32>
160
buffered_spriteram32_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
161
: buffered_spriteram_device<UINT32>(mconfig, BUFFERED_SPRITERAM32, tag, owner, clock) { }
165
// ======================> buffered_spriteram64_device
167
class buffered_spriteram64_device : public buffered_spriteram_device<UINT64>
171
buffered_spriteram64_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
172
: buffered_spriteram_device<UINT64>(mconfig, BUFFERED_SPRITERAM64, tag, owner, clock) { }
176
#endif /* __BUFSPRITE_H__ */