All About Devices: Difference between revisions
(To be continued....) |
|||
Line 1: | Line 1: | ||
'''Devices''' in MAME are a mechanism for encapsulating a particular bit of functionality in a standard way. All devices have a set of common characteristics (how they start, reset, interact with the rest of the system) which makes it possible for the MAME core to treat them equally, and allows for a driver to plug any number of them together to create a working system. | '''Devices''' in MAME are a mechanism for encapsulating a particular bit of functionality in a standard way. All devices have a set of common characteristics (how they start, reset, interact with the rest of the system) which makes it possible for the MAME core to treat them equally, and allows for a driver to plug any number of them together to create a working system. | ||
Revision as of 21:00, 9 December 2008
Devices in MAME are a mechanism for encapsulating a particular bit of functionality in a standard way. All devices have a set of common characteristics (how they start, reset, interact with the rest of the system) which makes it possible for the MAME core to treat them equally, and allows for a driver to plug any number of them together to create a working system.
The first thing to be aware of when thinking about devices is that you shouldn't get too hung up on the term "device". A device in MAME doesn't have to correspond to a physical chip or device or anything that concrete (although they can and often do). Instead, just think of a device as a means of grouping a set of functions and behaviors together and calling it something. They are a preferred means of wrapping together functions that are used across multiple machines.
Devices in MAME might seem like a relatively recent concept, but in reality they are simply the culmination of previous efforts to define a consistent "plug-in" style interface for assembling a machine. CPU cores were the first device-like objects which exposed a consistent interface (see cpuintrf.h for definitions). Later on, the sound cores got their own similar interface (see sndintrf.h). It has only been recently that a more abstract device interface (see devintrf.h) has been introduced. Eventually, the CPU and sound interfaces will be retooled to be based fully on the abstract device interface, and then everything will be able to be treated equally as a generic device.
Devices have many nice features beyond their consistent interface that makes them useful in MAME:
- They demand dynamic allocation of state (instead of relying on static global variables)
- They demand support for an arbitrary number of instances (no more hard-coded limits)
- They are uniquely identifiable via their required tag
- The preferred way to locate devices is by tag, not by index, removing dependencies on ordering and the possibility of conflicts
- They are described directly in the machine configuration structure
- They can be configured entirely within the machine configuration structure (as opposed to requiring an external struct)
- They can be directly mapped in the address map, referenced by tag
- They can add to or modify the machine configuration they are part of
- They can reference their own device-specific ROMs
How this all works is explained in more detail below, in the section on writing a new device.
However, the first and most important thing to know is: as a user, how do you add, remove, configure, and interact with devices?
Using Devices
The first step to using a device is declaring its existence. This is done in the machine configuration, like so: