Let's Emulate Space Invaders: Difference between revisions

From MAMEDEV Wiki
(Initial version of this page.)
 
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== The Intro ==
== Introduction ==
Emulating any system can be a daunting task, even to experienced software engineers.  MAME can provide a good starting point, but can itself be quite daunting to get into.  This series of articles should provide some insight into the way MAME works, and accelerate any attempts to emulate something in a stand-alone emulator.


== The Topics ==
=== Foreword ===
* [[Part 1]]: Writing the disassembler
Emulating any system can be a daunting task, even to experienced software engineers.  MAME can provide a good starting point, but can itself be quite daunting to get into.  This series of articles should provide some insight into the way MAME works on a driver level and provide a good starting point for anyone who wants to contribute to pre-existing drivers in MAME.
* [[Part 2]]: Writing the CPU core
 
* [[Part 3]]: Writing the driver
=== What It Is ===
 
* An explanation of the most common structures found in drivers.
* A step-by-step guide on how to emulate a single game in MAME.
* A good starting point for a larger guide on the MAME source base.
 
=== What It Isn't ===
 
* A guide on how to write an emulator.
* A guide on how to work with MAME's core systems.
* A guide on how to port MAME to other systems.
* A pipe.
 
== Structures ==
 
=== Source Structure ===
 
There are two directories in the MAME codebase that are relevant for writing a driver; the rest should be ignored unless one is porting MAME to a different platform - in which case, good luck.  The two directories are:
 
* /src/mame - All MAME-specific subsystems (drivers, sound boards, video boards, etc.) go here.
* /src/devices - All core subsystems (CPU cores, audio chips, etc.) go here.
 
Under each of these are several subdirectories.  Since there is some overlap, and since only some are relevant to writing a driver, only a subset of them will be described.  They are:
 
* ./audio - Audio board drivers go here.  in /src/mame only.
* ./cpu - CPU cores and disassemblers go here.  In /src/devices only.
* ./includes - Headers for entire systems go here.  In /src/mame only.
* ./layout - MAME artwork layouts go here.  Only necessary for games that have unusual screen layouts.
* ./machine - Non-CPU IC and subsystem drivers go here. In both directories.
* ./sound - Sound IC drivers go here.  In /src/devices only.
* ./video - Video board drivers go here in /src/mame, video IC drivers go here in /src/devices.
 
=== Driver Structure ===
 
Any driver in MAME typically consists of:
 
* A declaration of a class derived from driver_device. This holds the driver data and all associated methods. (When the driver has multiple source files, this is done in a header file placed in /src/mame/includes.)
* A memory map for each CPU.
* A list of input devices and DIP switches.
* A GFXDECODE_START structure, linked to one or more gfx_layout structures, to define a machine's graphics layout. (This is common but not required; it may be omitted from drivers for systems with framebuffer- or GPU-based video rendering.)
* A MACHINE_CONFIG structure to define a PCB's hardware configuration.
* A ROM_START/ROM_END structure to define the ROM configuration for a game.
* A GAME() or GAMEX() macro to define an accessor for the game itself.
* Some form of video emulation, whether via a generic method or custom VIDEO_START/VIDEO_UPDATE functions.
 
Some drivers may involve other subsystems, such as timers and devices, but they are not strictly necessary in the most basic form of a driver.
 
== The Driver File ==
 
=== Memory Maps ===
 
=== Input Devices ===
 
=== Machine Configuration ===
 
=== ROM Layouts ===
 
=== Game Definition ===

Latest revision as of 00:08, 15 July 2016

Introduction

Foreword

Emulating any system can be a daunting task, even to experienced software engineers. MAME can provide a good starting point, but can itself be quite daunting to get into. This series of articles should provide some insight into the way MAME works on a driver level and provide a good starting point for anyone who wants to contribute to pre-existing drivers in MAME.

What It Is

  • An explanation of the most common structures found in drivers.
  • A step-by-step guide on how to emulate a single game in MAME.
  • A good starting point for a larger guide on the MAME source base.

What It Isn't

  • A guide on how to write an emulator.
  • A guide on how to work with MAME's core systems.
  • A guide on how to port MAME to other systems.
  • A pipe.

Structures

Source Structure

There are two directories in the MAME codebase that are relevant for writing a driver; the rest should be ignored unless one is porting MAME to a different platform - in which case, good luck. The two directories are:

  • /src/mame - All MAME-specific subsystems (drivers, sound boards, video boards, etc.) go here.
  • /src/devices - All core subsystems (CPU cores, audio chips, etc.) go here.

Under each of these are several subdirectories. Since there is some overlap, and since only some are relevant to writing a driver, only a subset of them will be described. They are:

  • ./audio - Audio board drivers go here. in /src/mame only.
  • ./cpu - CPU cores and disassemblers go here. In /src/devices only.
  • ./includes - Headers for entire systems go here. In /src/mame only.
  • ./layout - MAME artwork layouts go here. Only necessary for games that have unusual screen layouts.
  • ./machine - Non-CPU IC and subsystem drivers go here. In both directories.
  • ./sound - Sound IC drivers go here. In /src/devices only.
  • ./video - Video board drivers go here in /src/mame, video IC drivers go here in /src/devices.

Driver Structure

Any driver in MAME typically consists of:

  • A declaration of a class derived from driver_device. This holds the driver data and all associated methods. (When the driver has multiple source files, this is done in a header file placed in /src/mame/includes.)
  • A memory map for each CPU.
  • A list of input devices and DIP switches.
  • A GFXDECODE_START structure, linked to one or more gfx_layout structures, to define a machine's graphics layout. (This is common but not required; it may be omitted from drivers for systems with framebuffer- or GPU-based video rendering.)
  • A MACHINE_CONFIG structure to define a PCB's hardware configuration.
  • A ROM_START/ROM_END structure to define the ROM configuration for a game.
  • A GAME() or GAMEX() macro to define an accessor for the game itself.
  • Some form of video emulation, whether via a generic method or custom VIDEO_START/VIDEO_UPDATE functions.

Some drivers may involve other subsystems, such as timers and devices, but they are not strictly necessary in the most basic form of a driver.

The Driver File

Memory Maps

Input Devices

Machine Configuration

ROM Layouts

Game Definition