Let's Emulate Space Invaders

From MAMEDEV Wiki
Revision as of 00:08, 15 July 2016 by Ajr (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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