summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/ram.h
blob: 7579c730a6e856cf7e8ffae4f28371aa9bd6032d (plain) (blame)
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
/*************************************************************************

    RAM device

    license: MAME, GPL-2.0+
    copyright-holders: Dirk Best

    Provides a configurable amount of RAM to drivers

**************************************************************************/

#ifndef __RAM_H__
#define __RAM_H__


/***************************************************************************
    CONSTANTS
***************************************************************************/

#define RAM_TAG             "ram"


/***************************************************************************
    DEVICE CONFIGURATION MACROS
***************************************************************************/

#define MCFG_RAM_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, RAM, 0)

#define MCFG_RAM_REMOVE(_tag) \
	MCFG_DEVICE_REMOVE(_tag)

#define MCFG_RAM_MODIFY(_tag) \
	MCFG_DEVICE_MODIFY(_tag)    \
	ram_device::static_set_extra_options(*device, NULL);

#define MCFG_RAM_DEFAULT_SIZE(_default_size) \
	ram_device::static_set_default_size(*device, _default_size);

#define MCFG_RAM_EXTRA_OPTIONS(_extra_options) \
	ram_device::static_set_extra_options(*device, _extra_options);

#define MCFG_RAM_DEFAULT_VALUE(_default_value) \
	ram_device::static_set_default_value(*device, _default_value);


/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

class ram_device :  public device_t
{
public:
	// construction/destruction
	ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// accessors
	UINT32 size(void) const { return m_size; }
	UINT32 mask(void) const { return m_size - 1; }
	UINT8 *pointer(void) const { return m_pointer; }
	static UINT32 parse_string(const char *s);
	UINT32 default_size(void) const;
	const char *extra_options(void) const { return m_extra_options; }

	// read/write
	UINT8 read(offs_t offset)               { return m_pointer[offset % m_size]; }
	void write(offs_t offset, UINT8 data)   { m_pointer[offset % m_size] = data; }

	// inline configuration helpers
	static void static_set_default_size(device_t &device, const char *default_size)     { downcast<ram_device &>(device).m_default_size = default_size; }
	static void static_set_extra_options(device_t &device, const char *extra_options)   { downcast<ram_device &>(device).m_extra_options = extra_options; }
	static void static_set_default_value(device_t &device, UINT8 default_value)         { downcast<ram_device &>(device).m_default_value = default_value; }

protected:
	virtual void device_start(void);
	virtual void device_validity_check(validity_checker &valid) const;

private:
	// device state
	UINT32 m_size;
	UINT8 *m_pointer;

	// device config
	const char *m_default_size;
	const char *m_extra_options;
	UINT8 m_default_value;
};


// device type definition
extern const device_type RAM;

// device iterator
typedef device_type_iterator<&device_creator<ram_device>, ram_device> ram_device_iterator;

#endif /* __RAM_H__ */