summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/devintrf.h
blob: 9b08ddced6e1bef28bacd67d829522b00a72eb62 (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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/***************************************************************************

    devintrf.h

    Device interface functions.

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

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

#pragma once

#ifndef __DEVINTRF_H__
#define __DEVINTRF_H__

#include "mamecore.h"


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

/* useful in device_list functions for scanning through all devices */
#define DEVICE_TYPE_WILDCARD			NULL


/* state constants passed to the device_get_info_func */
enum
{
	/* --- the following bits of info are returned as 64-bit signed integers --- */
	DEVINFO_INT_FIRST = 0x00000,

	DEVINFO_INT_INLINE_CONFIG_BYTES = DEVINFO_INT_FIRST,/* R/O: bytes of inline configuration */

	DEVINFO_INT_DEVICE_SPECIFIC = 0x08000,				/* R/W: device-specific values start here */

	DEVINFO_INT_LAST = 0x0ffff,

	/* --- the following bits of info are returned as pointers --- */
	DEVINFO_PTR_FIRST = 0x10000,

	DEVINFO_PTR_DEVICE_SPECIFIC = 0x18000,				/* R/W: device-specific values start here */

	DEVINFO_PTR_LAST = 0x1ffff,

	/* --- the following bits of info are returned as pointers to functions --- */
	DEVINFO_FCT_FIRST = 0x20000,

	DEVINFO_FCT_SET_INFO = DEVINFO_FCT_FIRST,			/* R/O: device_set_info_func */
	DEVINFO_FCT_START,									/* R/O: device_start_func */
	DEVINFO_FCT_STOP,									/* R/O: device_stop_func */
	DEVINFO_FCT_RESET,									/* R/O: device_reset_func */

	DEVINFO_FCT_DEVICE_SPECIFIC = 0x28000,				/* R/W: device-specific values start here */

	DEVINFO_FCT_LAST = 0x1ffff,

	/* --- the following bits of info are returned as NULL-terminated strings --- */
	DEVINFO_STR_FIRST = 0x30000,

	DEVINFO_STR_NAME = DEVINFO_STR_FIRST,				/* R/O: name of the device */
	DEVINFO_STR_FAMILY,									/* R/O: family of the device */
	DEVINFO_STR_VERSION,								/* R/O: version of the device */
	DEVINFO_STR_SOURCE_FILE,							/* R/O: file containing the device implementation */
	DEVINFO_STR_CREDITS,								/* R/O: credits for the device implementation */

	DEVINFO_STR_DEVICE_SPECIFIC = 0x38000,				/* R/W: device-specific values start here */

	DEVINFO_STR_LAST = 0x3ffff
};



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

/* forward-declare this type */
typedef union _deviceinfo deviceinfo;


/* device interface function types */
typedef void (*device_get_info_func)(running_machine *machine, void *token, UINT32 state, deviceinfo *info);
typedef void (*device_set_info_func)(running_machine *machine, void *token, UINT32 state, const deviceinfo *info);
typedef void *(*device_start_func)(running_machine *machine, const char *tag, const void *static_config, const void *inline_config);
typedef void (*device_stop_func)(running_machine *machine, void *token);
typedef void (*device_reset_func)(running_machine *machine, void *token);


/* a device_type is simply a pointer to its get_info function */
typedef device_get_info_func device_type;


/* the actual deviceinfo union */
union _deviceinfo
{
	INT64					i;						/* generic integers */
	void *					p;						/* generic pointers */
	genf *  				f;						/* generic function pointers */
	const char *			s;						/* generic strings */

	device_set_info_func 	set_info;				/* DEVINFO_FCT_SET_INFO */
	device_start_func		start;					/* DEVINFO_FCT_START */
	device_stop_func		stop;					/* DEVINFO_FCT_STOP */
	device_reset_func		reset;					/* DEVINFO_FCT_RESET */
};


/* the configuration for a general device */
typedef struct _device_config device_config;
struct _device_config
{
	device_config *			next;					/* next device */
	device_type				type;					/* device type */
	UINT32					flags;					/* device flags */
	UINT32					clock;					/* device clock */
	device_set_info_func 	set_info;				/* quick pointer to set_info callback */
	device_start_func		start;					/* quick pointer to start callback */
	device_stop_func		stop;					/* quick pointer to stop callback */
	device_reset_func		reset;					/* quick pointer to reset callback */
	const void *			static_config;			/* static device configuration */
	void *					inline_config;			/* inline device configuration */
	void *					token;					/* token if device is live */
	char					tag[1];					/* tag for this instance */
};



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/


/* ----- device configuration ----- */

/* add a new device to the end of a device list */
device_config *device_list_add(device_config **listheadptr, device_type type, const char *tag);

/* remove a device from a device list */
void device_list_remove(device_config **listheadptr, device_type type, const char *tag);

/* return the number of items of a given type; DEVICE_TYPE_WILDCARD is allowed */
int device_list_items(const device_config *listhead, device_type type);

/* return the first device in the list of a given type; DEVICE_TYPE_WILDCARD is allowed */
const device_config *device_list_first(const device_config *listhead, device_type type);

/* return the next device in the list of a given type; DEVICE_TYPE_WILDCARD is allowed */
const device_config *device_list_next(const device_config *prevdevice, device_type type);

/* retrieve a device configuration based on a type and tag; DEVICE_TYPE_WILDCARD is allowed */
const device_config *device_list_find_by_tag(const device_config *listhead, device_type type, const char *tag);



/* ----- index-based device access (avoid if possible) ----- */

/* return the index of a device based on its type and tag; DEVICE_TYPE_WILDCARD is allowed */
int device_list_index(const device_config *listhead, device_type type, const char *tag);

/* retrieve a device configuration based on a type and index; DEVICE_TYPE_WILDCARD is allowed */
const device_config *device_list_find_by_index(const device_config *listhead, device_type type, int index);



/* ----- live device management ----- */

/* start the configured list of devices for a machine */
void device_list_start(running_machine *machine);

/* reset a device based on an allocated device_config */
void device_reset(running_machine *machine, const device_config *config);
void devtag_reset(running_machine *machine, device_type type, const char *tag);



/* ----- device information getters ----- */

/* return the token associated with an allocated device */
void *devtag_get_token(running_machine *machine, device_type type, const char *tag);

/* return a pointer to the static configuration for a device based on type and tag */
const void *devtag_get_static_config(running_machine *machine, device_type type, const char *tag);

/* return a pointer to the inline configuration for a device based on type and tag */
const void *devtag_get_inline_config(running_machine *machine, device_type type, const char *tag);

/* return an integer state value from an allocated device */
INT64 device_get_info_int(running_machine *machine, const device_config *config, UINT32 state);
INT64 devtag_get_info_int(running_machine *machine, device_type type, const char *tag, UINT32 state);

/* return a pointer state value from an allocated device */
void *device_get_info_ptr(running_machine *machine, const device_config *config, UINT32 state);
void *devtag_get_info_ptr(running_machine *machine, device_type type, const char *tag, UINT32 state);

/* return a function pointer state value from an allocated device */
genf *device_get_info_fct(running_machine *machine, const device_config *config, UINT32 state);
genf *devtag_get_info_fct(running_machine *machine, device_type type, const char *tag, UINT32 state);

/* return a string value from an allocated device */
const char *device_get_info_string(running_machine *machine, const device_config *config, UINT32 state);
const char *devtag_get_info_string(running_machine *machine, device_type type, const char *tag, UINT32 state);

/* return a string value from a device type (does not need to be allocated) */
const char *devtype_get_info_string(device_type type, UINT32 state);



/* ----- device information setters ----- */

/* set an integer state value for an allocated device */
void device_set_info_int(running_machine *machine, const device_config *config, UINT32 state, INT64 data);
void devtag_set_info_int(running_machine *machine, device_type type, const char *tag, UINT32 state, INT64 data);

/* set a pointer state value for an allocated device */
void device_set_info_ptr(running_machine *machine, const device_config *config, UINT32 state, void *data);
void devtag_set_info_ptr(running_machine *machine, device_type type, const char *tag, UINT32 state, void *data);

/* set a function pointer state value for an allocated device */
void device_set_info_fct(running_machine *machine, const device_config *config, UINT32 state, genf *data);
void devtag_set_info_fct(running_machine *machine, device_type type, const char *tag, UINT32 state, genf *data);



/***************************************************************************
    INLINE FUNCTIONS
***************************************************************************/

/* return common strings based on device types */
INLINE const char *devtype_name(device_type devtype)		{ return devtype_get_info_string(devtype, DEVINFO_STR_NAME); }
INLINE const char *devtype_family(device_type devtype) 		{ return devtype_get_info_string(devtype, DEVINFO_STR_FAMILY); }
INLINE const char *devtype_version(device_type devtype) 	{ return devtype_get_info_string(devtype, DEVINFO_STR_VERSION); }
INLINE const char *devtype_source_file(device_type devtype) { return devtype_get_info_string(devtype, DEVINFO_STR_SOURCE_FILE); }
INLINE const char *devtype_credits(device_type devtype) 	{ return devtype_get_info_string(devtype, DEVINFO_STR_CREDITS); }


#endif	/* __DEVINTRF_H__ */