Device Interfaces: Difference between revisions
(New page: =Standard Interfaces= * Execute * Memory * State * NVRAM * Disassembly * Sound =Custom Interface=) |
No edit summary |
||
Line 1: | Line 1: | ||
Device interfaces are separate classes that enable devices to participate in more areas of the overall system. Each interface is a sort of contract between the device that inherits from it and related other parts of the system. For example, a device inherits from the execute interface if it wishes to be scheduled and called regularly to execute. Simiarly, a device inherits from the NVRAM interface if it wishes to participate in saving/loading data to the .nv files. | |||
To add an interface to a device, both the device class and device's configuration class must inherit from the interface's class and the interface's configuration class, respectively. Some interfaces are more about configuration than runtime, and others are more about runtime than configuration, but in all cases both interface classes are required. | |||
Since a device is already required to inherit from device_t, this means that you must leverage C++'s <i>multiple inheritance</i> support in order to add an interface. For example, our configuration class might look like this: | |||
class example1_device_config : public device_config, | |||
public device_config_memory_interface, | |||
public device_config_nvram_interface | |||
{ | |||
}; | |||
and our device class like this: | |||
class example1_device : public device_t, | |||
public device_memory_interface, | |||
public device_nvram_interface | |||
{ | |||
}; | |||
Notice first that the '''device_config''' and '''device_t''' classes remain the first classes listed. This is important as they are the real base classes of our device. The interface classes should always be listed afterwards. Also notice that our configuration class and our device class inherit from matching configuration and interface classes. | |||
Each interface has its own demands on the device. Some interfaces, like the sound interface, really don't require any significant changes. Others, like the NVRAM interface, are pure virtual classes, requiring implementation of one or more methods. | |||
Currently the MAME core defines six standard interfaces: | |||
* The execute interface connects the device to the internal scheduler, and requires implementation of a '''device_run'''() method. | |||
* The memory interface connects the device to the memory system, allowing it to specify one or more address spaces. | |||
* The state interface connects the device to the debugger, enabling display and editing of state during execution from within the register view. It also provides simple indexed accessors for reading/writing state in a standard fashion. | |||
* The NVRAM interface connects the device to the NVRAM read/write process. | |||
* The disassembly interface connects the device to the debugger, enabling disassembly views from within the disassembly window. | |||
* The sound interface connects the device to the sound network, enabling routing of sound from the device to/from other devices. | |||
Details on the interfaces and their requirements are given in the sections below. | |||
=Standard Interfaces= | =Standard Interfaces= | ||
Revision as of 19:27, 8 June 2010
Device interfaces are separate classes that enable devices to participate in more areas of the overall system. Each interface is a sort of contract between the device that inherits from it and related other parts of the system. For example, a device inherits from the execute interface if it wishes to be scheduled and called regularly to execute. Simiarly, a device inherits from the NVRAM interface if it wishes to participate in saving/loading data to the .nv files.
To add an interface to a device, both the device class and device's configuration class must inherit from the interface's class and the interface's configuration class, respectively. Some interfaces are more about configuration than runtime, and others are more about runtime than configuration, but in all cases both interface classes are required.
Since a device is already required to inherit from device_t, this means that you must leverage C++'s multiple inheritance support in order to add an interface. For example, our configuration class might look like this:
class example1_device_config : public device_config, public device_config_memory_interface, public device_config_nvram_interface { };
and our device class like this:
class example1_device : public device_t, public device_memory_interface, public device_nvram_interface { };
Notice first that the device_config and device_t classes remain the first classes listed. This is important as they are the real base classes of our device. The interface classes should always be listed afterwards. Also notice that our configuration class and our device class inherit from matching configuration and interface classes.
Each interface has its own demands on the device. Some interfaces, like the sound interface, really don't require any significant changes. Others, like the NVRAM interface, are pure virtual classes, requiring implementation of one or more methods.
Currently the MAME core defines six standard interfaces:
- The execute interface connects the device to the internal scheduler, and requires implementation of a device_run() method.
- The memory interface connects the device to the memory system, allowing it to specify one or more address spaces.
- The state interface connects the device to the debugger, enabling display and editing of state during execution from within the register view. It also provides simple indexed accessors for reading/writing state in a standard fashion.
- The NVRAM interface connects the device to the NVRAM read/write process.
- The disassembly interface connects the device to the debugger, enabling disassembly views from within the disassembly window.
- The sound interface connects the device to the sound network, enabling routing of sound from the device to/from other devices.
Details on the interfaces and their requirements are given in the sections below.
Standard Interfaces
- Execute
- Memory
- State
- NVRAM
- Disassembly
- Sound