The MESS Driver Lifecycle


When does my code get called?

This page is outdated and needs to be updated for the current MAME and MESS version.

Imagine we want to create, update, or understand a MESS driver. We have all these wonderful ADDRESS_MAP, MACHINE_RESET, VIDEO_START, DEVICE_INIT, etc. structures and functions we can use. The key to implementing the things properly is understanding the MESS driver lifecycle; knowing when what is created and/or available when a driver is started or reset (soft or hard reset).

This information can be found in the MAME and MESS source code. Most of which is available in the mame.c file. Additional information can be found on the mamedev wiki.

The section where information is used or code is called that we have defined in our own driver or cpu core code have been marked in bold.

  1. create_machine() to create the machine structure
  2. reset_machine() to initialize the machine strucutre
  3. mame_validitycheck() to perform validity checks on all compiled drivers
  4. game start/hard reset
    1. reset_machine() to initialize the machine strucutre
    2. init_resource_tracking()
    3. begin_resource_tracking()
    4. init_machine()
      1. cpuintrf_init() to determine which CPUs are available
      2. sndintrf_init() to determine which sound chips are available
      3. fileio_init() to initialize file I/O info
      4. config_init() to initialize the configuration system
      5. output_init() to initialize the output system
      6. state_init() to initialize the save state system
      7. state_save_allow_registration() to allow save state registrations
      8. drawgfx_init() to initialize rendering globals
      9. palette_init() to initialize palette system
      10. render_init() to initialize the rendering system
      11. ui_init() to initialize the user interface
      12. generic_machine_init() to initialize generic machine structures
      13. generic_video_init() to initialize generic video structures
      14. timer_init() and register soft_reset_timer handler to reset the timer system
      15. osd_init() to do platform specific initialization
      16. code_init() to initialize the input system
      17. input_port_init() to set up the input ports from the driver's INPUT_PORTs
      18. rom_init() to load the system's ROMs
      19. memory_init() to process the system's memory maps from the driver's ADDRESS_MAPs
      20. cpuexec_init() to initialize the CPUs
      21. cpuint_init() to initialize the CPU interrupts
      22. devices_init (MESS specific)
        1. inputx_init() to initialize natural keyboard support
        2. devices_allocate() to create the device information structures
        3. ram_init() to initialize the RAM settings
        4. image_init() to initialize all devices
          1. for each device type
            1. DEVICE_INIT(image)
        5. for each device type in the driver's SYSTEM_CONFIG
          1. for each device of type
            1. image_from_device_and_index() to identify the image
            2. image_load() to load the image
              1. image verify
              2. DEVICE_CREATE(image,format,args) or DEVICE_LOAD(image)
      23. mame_debug_init() to set up the debugger
      24. DRIVER_INIT()
      25. video_init() to start the video system
      26. sound_init() to start the audio system
      27. MACHINE_START()
      28. SOUND_START()
      29. VIDEO_START()
      30. free disposable memory regions
      31. saveload_init() to set up for save/load
      32. cheat_init() to initialize the cheat system
    5. config_load_settings() to load the configuration file
    6. nvram_load() to load the system's NVRAM by calling NVRAM_HANDLER() if available
    7. ui_display_startup_screens() to display the startup screens
    8. begin_resource_tracking()
    9. soft_reset() (can also be initiated while the machine is running)
      1. end_resource_tracking()
      2. begin_resource_tracking()
      3. state_save_allow_registrations() to allow save state registrations
      4. cpuint_reset
      5. MACHINE_RESET()
      6. SOUND_RESET()
      7. VIDEO_RESET()
      8. call everything on the reset callback lit
      9. state_save_allow_registrations() to disallow save state registrations
    10. while running
      1. execute cpu slices and video_frame_update
    11. end_resource_tracking() to free all auto_mallocs and timers
    12. nvram_save() to save the system's NVRAM by calling NVRAM_HANDLER() if available
    13. config_save_settings() to save the system's configuration
    14. call exit routines
    15. exit_resource_tracking()
    16. empty exit, reset, and pause callback lists
  5. destroy_machine