diff options
author | Aaron Giles <aaron@aarongiles.com> | 2012-04-06 20:24:04 +0000 |
---|---|---|
committer | Aaron Giles <aaron@aarongiles.com> | 2012-04-06 20:24:04 +0000 |
commit | 332448313045dddcf778d9c19c7a3c1080215d41 (patch) | |
tree | a63b5c77ecb7cd1e814c3085bdbc323271e74303 | |
parent | 3e575ad6b94974bf2a782c7ebf2d5a8b79d09ae5 (diff) |
Extracted driver_device base class from machine.* and into its
own file driver.*
-rw-r--r-- | .gitattributes | 2 | ||||
-rw-r--r-- | src/emu/driver.c | 284 | ||||
-rw-r--r-- | src/emu/driver.h | 242 | ||||
-rw-r--r-- | src/emu/emu.h | 1 | ||||
-rw-r--r-- | src/emu/emu.mak | 1 | ||||
-rw-r--r-- | src/emu/machine.c | 244 | ||||
-rw-r--r-- | src/emu/machine.h | 188 |
7 files changed, 530 insertions, 432 deletions
diff --git a/.gitattributes b/.gitattributes index 0f1728c36e4..76d67d0c634 100644 --- a/.gitattributes +++ b/.gitattributes @@ -701,6 +701,8 @@ src/emu/drawgfx.h svneol=native#text/plain src/emu/drawgfxm.h svneol=native#text/plain src/emu/drivenum.c svneol=native#text/plain src/emu/drivenum.h svneol=native#text/plain +src/emu/driver.c svneol=native#text/plain +src/emu/driver.h svneol=native#text/plain src/emu/drivers/empty.c svneol=native#text/plain src/emu/drivers/emudummy.c svneol=native#text/plain src/emu/drivers/testcpu.c svneol=native#text/plain diff --git a/src/emu/driver.c b/src/emu/driver.c new file mode 100644 index 00000000000..9b108b57ed7 --- /dev/null +++ b/src/emu/driver.c @@ -0,0 +1,284 @@ +/*************************************************************************** + + driver.c + + Core driver device base class. + +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +***************************************************************************/ + +#include "emu.h" +#include "drivenum.h" + + +//************************************************************************** +// DRIVER DEVICE +//************************************************************************** + +//------------------------------------------------- +// driver_device - constructor +//------------------------------------------------- + +driver_device::driver_device(const machine_config &mconfig, device_type type, const char *tag) + : device_t(mconfig, type, "Driver Device", tag, NULL, 0), + m_system(NULL), + m_palette_init(NULL), + m_generic_paletteram_8(*this, "paletteram"), + m_generic_paletteram2_8(*this, "paletteram2"), + m_generic_paletteram_16(*this, "paletteram"), + m_generic_paletteram2_16(*this, "paletteram2"), + m_generic_paletteram_32(*this, "paletteram"), + m_generic_paletteram2_32(*this, "paletteram2") +{ + memset(m_callbacks, 0, sizeof(m_callbacks)); +} + + +//------------------------------------------------- +// driver_device - destructor +//------------------------------------------------- + +driver_device::~driver_device() +{ +} + + +//------------------------------------------------- +// static_set_game - set the game in the device +// configuration +//------------------------------------------------- + +void driver_device::static_set_game(device_t &device, const game_driver &game) +{ + driver_device &driver = downcast<driver_device &>(device); + + // set the system + driver.m_system = &game; + + // set the short name to the game's name + driver.m_shortname = game.name; + + // set the full name to the game's description + driver.m_name = game.description; + + // and set the search path to include all parents + driver.m_searchpath = game.name; + for (int parent = driver_list::clone(game); parent != -1; parent = driver_list::clone(parent)) + driver.m_searchpath.cat(";").cat(driver_list::driver(parent).name); +} + + +//------------------------------------------------- +// static_set_machine_start - set the legacy +// machine start callback in the device +// configuration +//------------------------------------------------- + +void driver_device::static_set_callback(device_t &device, callback_type type, legacy_callback_func callback) +{ + downcast<driver_device &>(device).m_callbacks[type] = callback; +} + + +//------------------------------------------------- +// static_set_palette_init - set the legacy +// palette init callback in the device +// configuration +//------------------------------------------------- + +void driver_device::static_set_palette_init(device_t &device, palette_init_func callback) +{ + downcast<driver_device &>(device).m_palette_init = callback; +} + + +//------------------------------------------------- +// driver_start - default implementation which +// does nothing +//------------------------------------------------- + +void driver_device::driver_start() +{ +} + + +//------------------------------------------------- +// machine_start - default implementation which +// calls to the legacy machine_start function +//------------------------------------------------- + +void driver_device::machine_start() +{ + if (m_callbacks[CB_MACHINE_START] != NULL) + (*m_callbacks[CB_MACHINE_START])(machine()); +} + + +//------------------------------------------------- +// sound_start - default implementation which +// calls to the legacy sound_start function +//------------------------------------------------- + +void driver_device::sound_start() +{ + if (m_callbacks[CB_SOUND_START] != NULL) + (*m_callbacks[CB_SOUND_START])(machine()); +} + + +//------------------------------------------------- +// video_start - default implementation which +// calls to the legacy video_start function +//------------------------------------------------- + +void driver_device::video_start() +{ + if (m_callbacks[CB_VIDEO_START] != NULL) + (*m_callbacks[CB_VIDEO_START])(machine()); +} + + +//------------------------------------------------- +// driver_reset - default implementation which +// does nothing +//------------------------------------------------- + +void driver_device::driver_reset() +{ +} + + +//------------------------------------------------- +// machine_reset - default implementation which +// calls to the legacy machine_reset function +//------------------------------------------------- + +void driver_device::machine_reset() +{ + if (m_callbacks[CB_MACHINE_RESET] != NULL) + (*m_callbacks[CB_MACHINE_RESET])(machine()); +} + + +//------------------------------------------------- +// sound_reset - default implementation which +// calls to the legacy sound_reset function +//------------------------------------------------- + +void driver_device::sound_reset() +{ + if (m_callbacks[CB_SOUND_RESET] != NULL) + (*m_callbacks[CB_SOUND_RESET])(machine()); +} + + +//------------------------------------------------- +// video_reset - default implementation which +// calls to the legacy video_reset function +//------------------------------------------------- + +void driver_device::video_reset() +{ + if (m_callbacks[CB_VIDEO_RESET] != NULL) + (*m_callbacks[CB_VIDEO_RESET])(machine()); +} + + +//------------------------------------------------- +// device_rom_region - return a pointer to the +// game's ROMs +//------------------------------------------------- + +const rom_entry *driver_device::device_rom_region() const +{ + return m_system->rom; +} + + +//------------------------------------------------- +// device_input_ports - return a pointer to the +// game's input ports +//------------------------------------------------- + +ioport_constructor driver_device::device_input_ports() const +{ + return m_system->ipt; +} + + +//------------------------------------------------- +// device_start - device override which calls +// the various helpers +//------------------------------------------------- + +void driver_device::device_start() +{ + // reschedule ourselves to be last + device_iterator iter(*this); + for (device_t *test = iter.first(); test != NULL; test = iter.next()) + if (test != this && !test->started()) + throw device_missing_dependencies(); + + // call the game-specific init + if (m_system->driver_init != NULL) + (*m_system->driver_init)(machine()); + + // finish image devices init process + image_postdevice_init(machine()); + + // call palette_init if present + if (m_palette_init != NULL) + (*m_palette_init)(machine(), machine().region("proms")->base()); + + // start the various pieces + driver_start(); + machine_start(); + sound_start(); + video_start(); +} + + +//------------------------------------------------- +// device_reset_after_children - device override +// which calls the various helpers; must happen +// after all child devices are reset +//------------------------------------------------- + +void driver_device::device_reset_after_children() +{ + // reset each piece + driver_reset(); + machine_reset(); + sound_reset(); + video_reset(); +} diff --git a/src/emu/driver.h b/src/emu/driver.h new file mode 100644 index 00000000000..98731198924 --- /dev/null +++ b/src/emu/driver.h @@ -0,0 +1,242 @@ +/*************************************************************************** + + driver.h + + Core driver device base class. + +**************************************************************************** + + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +***************************************************************************/ + +#pragma once + +#ifndef __EMU_H__ +#error Dont include this file directly; include emu.h instead. +#endif + +#ifndef __DRIVER_H__ +#define __DRIVER_H__ + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + + +// ======================> driver_device + +// base class for machine driver-specific devices +class driver_device : public device_t +{ +public: + // construction/destruction + driver_device(const machine_config &mconfig, device_type type, const char *tag); + virtual ~driver_device(); + + // indexes into our generic callbacks + enum callback_type + { + CB_MACHINE_START, + CB_MACHINE_RESET, + CB_SOUND_START, + CB_SOUND_RESET, + CB_VIDEO_START, + CB_VIDEO_RESET, + CB_COUNT + }; + + // inline configuration helpers + static void static_set_game(device_t &device, const game_driver &game); + static void static_set_callback(device_t &device, callback_type type, legacy_callback_func callback); + static void static_set_palette_init(device_t &device, palette_init_func callback); + + // generic helpers + + // watchdog read/write handlers + DECLARE_WRITE8_MEMBER( watchdog_reset_w ); + DECLARE_READ8_MEMBER( watchdog_reset_r ); + DECLARE_WRITE16_MEMBER( watchdog_reset16_w ); + DECLARE_READ16_MEMBER( watchdog_reset16_r ); + DECLARE_WRITE32_MEMBER( watchdog_reset32_w ); + DECLARE_READ32_MEMBER( watchdog_reset32_r ); + + // sound latch readers + DECLARE_READ8_MEMBER( soundlatch_r ); + DECLARE_READ8_MEMBER( soundlatch2_r ); + DECLARE_READ8_MEMBER( soundlatch3_r ); + DECLARE_READ8_MEMBER( soundlatch4_r ); + DECLARE_READ16_MEMBER( soundlatch_word_r ); + DECLARE_READ16_MEMBER( soundlatch2_word_r ); + DECLARE_READ16_MEMBER( soundlatch3_word_r ); + DECLARE_READ16_MEMBER( soundlatch4_word_r ); + + // sound latch writers + DECLARE_WRITE8_MEMBER( soundlatch_w ); + DECLARE_WRITE8_MEMBER( soundlatch2_w ); + DECLARE_WRITE8_MEMBER( soundlatch3_w ); + DECLARE_WRITE8_MEMBER( soundlatch4_w ); + DECLARE_WRITE16_MEMBER( soundlatch_word_w ); + DECLARE_WRITE16_MEMBER( soundlatch2_word_w ); + DECLARE_WRITE16_MEMBER( soundlatch3_word_w ); + DECLARE_WRITE16_MEMBER( soundlatch4_word_w ); + + // sound latch clearers + DECLARE_WRITE8_MEMBER( soundlatch_clear_w ); + DECLARE_WRITE8_MEMBER( soundlatch2_clear_w ); + DECLARE_WRITE8_MEMBER( soundlatch3_clear_w ); + DECLARE_WRITE8_MEMBER( soundlatch4_clear_w ); + + // general palette helpers + void set_color_332(pen_t color, int rshift, int gshift, int bshift, UINT32 data); + void set_color_444(pen_t color, int rshift, int gshift, int bshift, UINT32 data); + void set_color_555(pen_t color, int rshift, int gshift, int bshift, UINT32 data); + void set_color_565(pen_t color, int rshift, int gshift, int bshift, UINT32 data); + void set_color_888(pen_t color, int rshift, int gshift, int bshift, UINT32 data); + void set_color_4444(pen_t color, int ishift, int rshift, int gshift, int bshift, UINT16 data); + + // 3-3-2 RGB palette write handlers + DECLARE_WRITE8_MEMBER( paletteram_BBGGGRRR_w ); + DECLARE_WRITE8_MEMBER( paletteram_RRRGGGBB_w ); + DECLARE_WRITE8_MEMBER( paletteram_BBGGRRII_w ); + DECLARE_WRITE8_MEMBER( paletteram_IIBBGGRR_w ); + + // 4-4-4 RGB palette write handlers + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_le_w ); + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_be_w ); + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_split2_w ); // uses paletteram2 + DECLARE_WRITE16_MEMBER( paletteram16_xxxxBBBBGGGGRRRR_word_w ); + + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_le_w ); + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_be_w ); + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_split2_w ); // uses paletteram2 + DECLARE_WRITE16_MEMBER( paletteram16_xxxxBBBBRRRRGGGG_word_w ); + + DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRBBBBGGGG_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRBBBBGGGG_split2_w ); // uses paletteram2 + + DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_le_w ); + DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_be_w ); + DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_split2_w ); // uses paletteram2 + DECLARE_WRITE16_MEMBER( paletteram16_xxxxRRRRGGGGBBBB_word_w ); + + DECLARE_WRITE8_MEMBER( paletteram_RRRRGGGGBBBBxxxx_be_w ); + DECLARE_WRITE8_MEMBER( paletteram_RRRRGGGGBBBBxxxx_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_RRRRGGGGBBBBxxxx_split2_w ); // uses paletteram2 + DECLARE_WRITE16_MEMBER( paletteram16_RRRRGGGGBBBBxxxx_word_w ); + + // 4-4-4-4 IRGB palette write handlers + DECLARE_WRITE16_MEMBER( paletteram16_IIIIRRRRGGGGBBBB_word_w ); + DECLARE_WRITE16_MEMBER( paletteram16_RRRRGGGGBBBBIIII_word_w ); + + // 5-5-5 RGB palette write handlers + DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_le_w ); + DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_be_w ); + DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_split2_w ); // uses paletteram2 + DECLARE_WRITE16_MEMBER( paletteram16_xBBBBBGGGGGRRRRR_word_w ); + + DECLARE_WRITE8_MEMBER( paletteram_xBBBBBRRRRRGGGGG_split1_w ); // uses paletteram + DECLARE_WRITE8_MEMBER( paletteram_xBBBBBRRRRRGGGGG_split2_w ); // uses paletteram2 + + DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_le_w ); + DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_be_w ); + DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_split1_w ); + DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_split2_w ); + DECLARE_WRITE16_MEMBER( paletteram16_xRRRRRGGGGGBBBBB_word_w ); + + DECLARE_WRITE16_MEMBER( paletteram16_xGGGGGRRRRRBBBBB_word_w ); + DECLARE_WRITE16_MEMBER( paletteram16_xGGGGGBBBBBRRRRR_word_w ); + + DECLARE_WRITE16_MEMBER( paletteram16_RRRRRGGGGGBBBBBx_word_w ); + DECLARE_WRITE16_MEMBER( paletteram16_GGGGGRRRRRBBBBBx_word_w ); + DECLARE_WRITE16_MEMBER( paletteram16_RRRRGGGGBBBBRGBx_word_w ); + + // 8-8-8 RGB palette write handlers + DECLARE_WRITE16_MEMBER( paletteram16_xrgb_word_be_w ); + DECLARE_WRITE16_MEMBER( paletteram16_xbgr_word_be_w ); + +protected: + // helpers called at startup + virtual void driver_start(); + virtual void machine_start(); + virtual void sound_start(); + virtual void video_start(); + + // helpers called at reset + virtual void driver_reset(); + virtual void machine_reset(); + virtual void sound_reset(); + virtual void video_reset(); + + // device-level overrides + virtual const rom_entry *device_rom_region() const; + virtual ioport_constructor device_input_ports() const; + virtual void device_start(); + virtual void device_reset_after_children(); + + // internal helpers + inline UINT16 paletteram16_le(offs_t offset) const { return m_generic_paletteram_8[offset & ~1] | (m_generic_paletteram_8[offset | 1] << 8); } + inline UINT16 paletteram16_be(offs_t offset) const { return m_generic_paletteram_8[offset | 1] | (m_generic_paletteram_8[offset & ~1] << 8); } + inline UINT16 paletteram16_split(offs_t offset) const { return m_generic_paletteram_8[offset] | (m_generic_paletteram2_8[offset] << 8); } + inline UINT32 paletteram32_be(offs_t offset) const { return m_generic_paletteram_16[offset | 1] | (m_generic_paletteram_16[offset & ~1] << 16); } + + // internal state + const game_driver * m_system; // pointer to the game driver + + legacy_callback_func m_callbacks[CB_COUNT]; // generic legacy callbacks + palette_init_func m_palette_init; // one-time palette init callback + +public: + // generic pointers + optional_shared_ptr<UINT8> m_generic_paletteram_8; + optional_shared_ptr<UINT8> m_generic_paletteram2_8; + optional_shared_ptr<UINT16> m_generic_paletteram_16; + optional_shared_ptr<UINT16> m_generic_paletteram2_16; + optional_shared_ptr<UINT32> m_generic_paletteram_32; + optional_shared_ptr<UINT32> m_generic_paletteram2_32; +}; + + +// this template function creates a stub which constructs a device +template<class _DriverClass> +device_t *driver_device_creator(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) +{ + assert(owner == NULL); + assert(clock == 0); + return global_alloc_clear(_DriverClass(mconfig, &driver_device_creator<_DriverClass>, tag)); +} + + +#endif /* __DRIVER_H__ */ diff --git a/src/emu/emu.h b/src/emu/emu.h index 005efc2244e..2e242cdd5f0 100644 --- a/src/emu/emu.h +++ b/src/emu/emu.h @@ -123,6 +123,7 @@ typedef device_t * (*machine_config_constructor)(machine_config &config, device_ // the running machine #include "machine.h" +#include "driver.h" #include "mame.h" // video-related diff --git a/src/emu/emu.mak b/src/emu/emu.mak index 2ad743db39e..ba96ab2c2a2 100644 --- a/src/emu/emu.mak +++ b/src/emu/emu.mak @@ -70,6 +70,7 @@ EMUOBJS = \ $(EMUOBJ)/disound.o \ $(EMUOBJ)/distate.o \ $(EMUOBJ)/drawgfx.o \ + $(EMUOBJ)/driver.o \ $(EMUOBJ)/drivenum.o \ $(EMUOBJ)/emualloc.o \ $(EMUOBJ)/emucore.o \ diff --git a/src/emu/machine.c b/src/emu/machine.c index 2d131978b66..55cd4406a63 100644 --- a/src/emu/machine.c +++ b/src/emu/machine.c @@ -1038,250 +1038,6 @@ running_machine::logerror_callback_item::logerror_callback_item(logerror_callbac //************************************************************************** -// DRIVER DEVICE -//************************************************************************** - -//------------------------------------------------- -// driver_device - constructor -//------------------------------------------------- - -driver_device::driver_device(const machine_config &mconfig, device_type type, const char *tag) - : device_t(mconfig, type, "Driver Device", tag, NULL, 0), - m_system(NULL), - m_palette_init(NULL), - m_generic_paletteram_8(*this, "paletteram"), - m_generic_paletteram2_8(*this, "paletteram2"), - m_generic_paletteram_16(*this, "paletteram"), - m_generic_paletteram2_16(*this, "paletteram2"), - m_generic_paletteram_32(*this, "paletteram"), - m_generic_paletteram2_32(*this, "paletteram2") -{ - memset(m_callbacks, 0, sizeof(m_callbacks)); -} - - -//------------------------------------------------- -// driver_device - destructor -//------------------------------------------------- - -driver_device::~driver_device() -{ -} - - -//------------------------------------------------- -// static_set_game - set the game in the device -// configuration -//------------------------------------------------- - -void driver_device::static_set_game(device_t &device, const game_driver &game) -{ - driver_device &driver = downcast<driver_device &>(device); - - // set the system - driver.m_system = &game; - - // set the short name to the game's name - driver.m_shortname = game.name; - - // set the full name to the game's description - driver.m_name = game.description; - - // and set the search path to include all parents - driver.m_searchpath = game.name; - for (int parent = driver_list::clone(game); parent != -1; parent = driver_list::clone(parent)) - driver.m_searchpath.cat(";").cat(driver_list::driver(parent).name); -} - - -//------------------------------------------------- -// static_set_machine_start - set the legacy -// machine start callback in the device -// configuration -//------------------------------------------------- - -void driver_device::static_set_callback(device_t &device, callback_type type, legacy_callback_func callback) -{ - downcast<driver_device &>(device).m_callbacks[type] = callback; -} - - -//------------------------------------------------- -// static_set_palette_init - set the legacy -// palette init callback in the device -// configuration -//------------------------------------------------- - -void driver_device::static_set_palette_init(device_t &device, palette_init_func callback) -{ - downcast<driver_device &>(device).m_palette_init = callback; -} - - -//------------------------------------------------- -// driver_start - default implementation which -// does nothing -//------------------------------------------------- - -void driver_device::driver_start() -{ -} - - -//------------------------------------------------- -// machine_start - default implementation which -// calls to the legacy machine_start function -//------------------------------------------------- - -void driver_device::machine_start() -{ - if (m_callbacks[CB_MACHINE_START] != NULL) - (*m_callbacks[CB_MACHINE_START])(machine()); -} - - -//------------------------------------------------- -// sound_start - default implementation which -// calls to the legacy sound_start function -//------------------------------------------------- - -void driver_device::sound_start() -{ - if (m_callbacks[CB_SOUND_START] != NULL) - (*m_callbacks[CB_SOUND_START])(machine()); -} - - -//------------------------------------------------- -// video_start - default implementation which -// calls to the legacy video_start function -//------------------------------------------------- - -void driver_device::video_start() -{ - if (m_callbacks[CB_VIDEO_START] != NULL) - (*m_callbacks[CB_VIDEO_START])(machine()); -} - - -//------------------------------------------------- -// driver_reset - default implementation which -// does nothing -//------------------------------------------------- - -void driver_device::driver_reset() -{ -} - - -//------------------------------------------------- -// machine_reset - default implementation which -// calls to the legacy machine_reset function -//------------------------------------------------- - -void driver_device::machine_reset() -{ - if (m_callbacks[CB_MACHINE_RESET] != NULL) - (*m_callbacks[CB_MACHINE_RESET])(machine()); -} - - -//------------------------------------------------- -// sound_reset - default implementation which -// calls to the legacy sound_reset function -//------------------------------------------------- - -void driver_device::sound_reset() -{ - if (m_callbacks[CB_SOUND_RESET] != NULL) - (*m_callbacks[CB_SOUND_RESET])(machine()); -} - - -//------------------------------------------------- -// video_reset - default implementation which -// calls to the legacy video_reset function -//------------------------------------------------- - -void driver_device::video_reset() -{ - if (m_callbacks[CB_VIDEO_RESET] != NULL) - (*m_callbacks[CB_VIDEO_RESET])(machine()); -} - - -//------------------------------------------------- -// device_rom_region - return a pointer to the -// game's ROMs -//------------------------------------------------- - -const rom_entry *driver_device::device_rom_region() const -{ - return m_system->rom; -} - - -//------------------------------------------------- -// device_input_ports - return a pointer to the -// game's input ports -//------------------------------------------------- - -ioport_constructor driver_device::device_input_ports() const -{ - return m_system->ipt; -} - - -//------------------------------------------------- -// device_start - device override which calls -// the various helpers -//------------------------------------------------- - -void driver_device::device_start() -{ - // reschedule ourselves to be last - device_iterator iter(*this); - for (device_t *test = iter.first(); test != NULL; test = iter.next()) - if (test != this && !test->started()) - throw device_missing_dependencies(); - - // call the game-specific init - if (m_system->driver_init != NULL) - (*m_system->driver_init)(machine()); - - // finish image devices init process - image_postdevice_init(machine()); - - // call palette_init if present - if (m_palette_init != NULL) - (*m_palette_init)(machine(), machine().region("proms")->base()); - - // start the various pieces - driver_start(); - machine_start(); - sound_start(); - video_start(); -} - - -//------------------------------------------------- -// device_reset_after_children - device override -// which calls the various helpers; must happen -// after all child devices are reset -//------------------------------------------------- - -void driver_device::device_reset_after_children() -{ - // reset each piece - driver_reset(); - machine_reset(); - sound_reset(); - video_reset(); -} - - - -//************************************************************************** // SYSTEM TIME //************************************************************************** diff --git a/src/emu/machine.h b/src/emu/machine.h index cc6dddf1fe3..5dfeb80558b 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -518,194 +518,6 @@ private: -// ======================> driver_device - -// base class for machine driver-specific devices -class driver_device : public device_t -{ -public: - // construction/destruction - driver_device(const machine_config &mconfig, device_type type, const char *tag); - virtual ~driver_device(); - - // indexes into our generic callbacks - enum callback_type - { - CB_MACHINE_START, - CB_MACHINE_RESET, - CB_SOUND_START, - CB_SOUND_RESET, - CB_VIDEO_START, - CB_VIDEO_RESET, - CB_COUNT - }; - - // inline configuration helpers - static void static_set_game(device_t &device, const game_driver &game); - static void static_set_callback(device_t &device, callback_type type, legacy_callback_func callback); - static void static_set_palette_init(device_t &device, palette_init_func callback); - - // generic helpers - - // watchdog read/write handlers - DECLARE_WRITE8_MEMBER( watchdog_reset_w ); - DECLARE_READ8_MEMBER( watchdog_reset_r ); - DECLARE_WRITE16_MEMBER( watchdog_reset16_w ); - DECLARE_READ16_MEMBER( watchdog_reset16_r ); - DECLARE_WRITE32_MEMBER( watchdog_reset32_w ); - DECLARE_READ32_MEMBER( watchdog_reset32_r ); - - // sound latch readers - DECLARE_READ8_MEMBER( soundlatch_r ); - DECLARE_READ8_MEMBER( soundlatch2_r ); - DECLARE_READ8_MEMBER( soundlatch3_r ); - DECLARE_READ8_MEMBER( soundlatch4_r ); - DECLARE_READ16_MEMBER( soundlatch_word_r ); - DECLARE_READ16_MEMBER( soundlatch2_word_r ); - DECLARE_READ16_MEMBER( soundlatch3_word_r ); - DECLARE_READ16_MEMBER( soundlatch4_word_r ); - - // sound latch writers - DECLARE_WRITE8_MEMBER( soundlatch_w ); - DECLARE_WRITE8_MEMBER( soundlatch2_w ); - DECLARE_WRITE8_MEMBER( soundlatch3_w ); - DECLARE_WRITE8_MEMBER( soundlatch4_w ); - DECLARE_WRITE16_MEMBER( soundlatch_word_w ); - DECLARE_WRITE16_MEMBER( soundlatch2_word_w ); - DECLARE_WRITE16_MEMBER( soundlatch3_word_w ); - DECLARE_WRITE16_MEMBER( soundlatch4_word_w ); - - // sound latch clearers - DECLARE_WRITE8_MEMBER( soundlatch_clear_w ); - DECLARE_WRITE8_MEMBER( soundlatch2_clear_w ); - DECLARE_WRITE8_MEMBER( soundlatch3_clear_w ); - DECLARE_WRITE8_MEMBER( soundlatch4_clear_w ); - - // general palette helpers - void set_color_332(pen_t color, int rshift, int gshift, int bshift, UINT32 data); - void set_color_444(pen_t color, int rshift, int gshift, int bshift, UINT32 data); - void set_color_555(pen_t color, int rshift, int gshift, int bshift, UINT32 data); - void set_color_565(pen_t color, int rshift, int gshift, int bshift, UINT32 data); - void set_color_888(pen_t color, int rshift, int gshift, int bshift, UINT32 data); - void set_color_4444(pen_t color, int ishift, int rshift, int gshift, int bshift, UINT16 data); - - // 3-3-2 RGB palette write handlers - DECLARE_WRITE8_MEMBER( paletteram_BBGGGRRR_w ); - DECLARE_WRITE8_MEMBER( paletteram_RRRGGGBB_w ); - DECLARE_WRITE8_MEMBER( paletteram_BBGGRRII_w ); - DECLARE_WRITE8_MEMBER( paletteram_IIBBGGRR_w ); - - // 4-4-4 RGB palette write handlers - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_le_w ); - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_be_w ); - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBGGGGRRRR_split2_w ); // uses paletteram2 - DECLARE_WRITE16_MEMBER( paletteram16_xxxxBBBBGGGGRRRR_word_w ); - - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_le_w ); - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_be_w ); - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_xxxxBBBBRRRRGGGG_split2_w ); // uses paletteram2 - DECLARE_WRITE16_MEMBER( paletteram16_xxxxBBBBRRRRGGGG_word_w ); - - DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRBBBBGGGG_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRBBBBGGGG_split2_w ); // uses paletteram2 - - DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_le_w ); - DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_be_w ); - DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_xxxxRRRRGGGGBBBB_split2_w ); // uses paletteram2 - DECLARE_WRITE16_MEMBER( paletteram16_xxxxRRRRGGGGBBBB_word_w ); - - DECLARE_WRITE8_MEMBER( paletteram_RRRRGGGGBBBBxxxx_be_w ); - DECLARE_WRITE8_MEMBER( paletteram_RRRRGGGGBBBBxxxx_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_RRRRGGGGBBBBxxxx_split2_w ); // uses paletteram2 - DECLARE_WRITE16_MEMBER( paletteram16_RRRRGGGGBBBBxxxx_word_w ); - - // 4-4-4-4 IRGB palette write handlers - DECLARE_WRITE16_MEMBER( paletteram16_IIIIRRRRGGGGBBBB_word_w ); - DECLARE_WRITE16_MEMBER( paletteram16_RRRRGGGGBBBBIIII_word_w ); - - // 5-5-5 RGB palette write handlers - DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_le_w ); - DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_be_w ); - DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_xBBBBBGGGGGRRRRR_split2_w ); // uses paletteram2 - DECLARE_WRITE16_MEMBER( paletteram16_xBBBBBGGGGGRRRRR_word_w ); - - DECLARE_WRITE8_MEMBER( paletteram_xBBBBBRRRRRGGGGG_split1_w ); // uses paletteram - DECLARE_WRITE8_MEMBER( paletteram_xBBBBBRRRRRGGGGG_split2_w ); // uses paletteram2 - - DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_le_w ); - DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_be_w ); - DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_split1_w ); - DECLARE_WRITE8_MEMBER( paletteram_xRRRRRGGGGGBBBBB_split2_w ); - DECLARE_WRITE16_MEMBER( paletteram16_xRRRRRGGGGGBBBBB_word_w ); - - DECLARE_WRITE16_MEMBER( paletteram16_xGGGGGRRRRRBBBBB_word_w ); - DECLARE_WRITE16_MEMBER( paletteram16_xGGGGGBBBBBRRRRR_word_w ); - - DECLARE_WRITE16_MEMBER( paletteram16_RRRRRGGGGGBBBBBx_word_w ); - DECLARE_WRITE16_MEMBER( paletteram16_GGGGGRRRRRBBBBBx_word_w ); - DECLARE_WRITE16_MEMBER( paletteram16_RRRRGGGGBBBBRGBx_word_w ); - - // 8-8-8 RGB palette write handlers - DECLARE_WRITE16_MEMBER( paletteram16_xrgb_word_be_w ); - DECLARE_WRITE16_MEMBER( paletteram16_xbgr_word_be_w ); - -protected: - // helpers called at startup - virtual void driver_start(); - virtual void machine_start(); - virtual void sound_start(); - virtual void video_start(); - - // helpers called at reset - virtual void driver_reset(); - virtual void machine_reset(); - virtual void sound_reset(); - virtual void video_reset(); - - // device-level overrides - virtual const rom_entry *device_rom_region() const; - virtual ioport_constructor device_input_ports() const; - virtual void device_start(); - virtual void device_reset_after_children(); - - // internal helpers - inline UINT16 paletteram16_le(offs_t offset) const { return m_generic_paletteram_8[offset & ~1] | (m_generic_paletteram_8[offset | 1] << 8); } - inline UINT16 paletteram16_be(offs_t offset) const { return m_generic_paletteram_8[offset | 1] | (m_generic_paletteram_8[offset & ~1] << 8); } - inline UINT16 paletteram16_split(offs_t offset) const { return m_generic_paletteram_8[offset] | (m_generic_paletteram2_8[offset] << 8); } - inline UINT32 paletteram32_be(offs_t offset) const { return m_generic_paletteram_16[offset | 1] | (m_generic_paletteram_16[offset & ~1] << 16); } - - // internal state - const game_driver * m_system; // pointer to the game driver - - legacy_callback_func m_callbacks[CB_COUNT]; // generic legacy callbacks - palette_init_func m_palette_init; // one-time palette init callback - -public: - // generic pointers - optional_shared_ptr<UINT8> m_generic_paletteram_8; - optional_shared_ptr<UINT8> m_generic_paletteram2_8; - optional_shared_ptr<UINT16> m_generic_paletteram_16; - optional_shared_ptr<UINT16> m_generic_paletteram2_16; - optional_shared_ptr<UINT32> m_generic_paletteram_32; - optional_shared_ptr<UINT32> m_generic_paletteram2_32; -}; - - -// this template function creates a stub which constructs a device -template<class _DriverClass> -device_t *driver_device_creator(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) -{ - assert(owner == NULL); - assert(clock == 0); - return global_alloc_clear(_DriverClass(mconfig, &driver_device_creator<_DriverClass>, tag)); -} - - - //************************************************************************** // INLINE FUNCTIONS //************************************************************************** |