Skip to content

Commit

Permalink
Created new device_video_interface. Right now its sole purpose is to
Browse files Browse the repository at this point in the history
house a screen tag and to find the screen at startup, providing an m_screen
object that can be used. One nice feature is that if there is only one
screen and no screen has been specified, it will auto configure to that
screen. This removes the need to explicitly specify a screen in the
configuration for a large chunk of drivers (though doing so never hurts).
A new macro MCFG_VIDEO_SET_SCREEN is provided, though devices are 
encouraged to define their own that maps there so it is obvious which
device is being targeted. The device_video_interface's validation
function will error if an invalid screen is specified or if no screen
is provided but there are multiple screens present.

Updated all devices that currently had an m_screen in them to use the
device_video_interface instead. This also has the nice benefit of flagging
video-related devices for categorization purposes. It also means all
these devices inherit the same screen-finding behaviors. For devices
that had interfaces that specified a screen tag, those have been removed
and all existing structs updated.

Added an optional_device<screen_device> m_screen to the base driver_device.
If you name your screen "screen" (as most drivers do), you will have free
access to your screen this way.

Future updates include:
* Updating all devices referencing machine.primary_screen to use the
device_video_interface instead
* Updating all drivers referencing machine.primary_screen to use the
m_screen instead
* Removing machine.primary_screen entirely
  • Loading branch information
aaronsgiles committed Jul 24, 2013
1 parent 4719b97 commit 25a100d
Show file tree
Hide file tree
Showing 428 changed files with 820 additions and 1,361 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Expand Up @@ -1048,6 +1048,8 @@ src/emu/disound.c svneol=native#text/plain
src/emu/disound.h svneol=native#text/plain
src/emu/distate.c svneol=native#text/plain
src/emu/distate.h svneol=native#text/plain
src/emu/divideo.c svneol=native#text/plain
src/emu/divideo.h svneol=native#text/plain
src/emu/drawgfx.c svneol=native#text/plain
src/emu/drawgfx.h svneol=native#text/plain
src/emu/drawgfxm.h svneol=native#text/plain
Expand Down
144 changes: 144 additions & 0 deletions src/emu/divideo.c
@@ -0,0 +1,144 @@
/***************************************************************************
divideo.c
Device video interfaces.
****************************************************************************
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"



//**************************************************************************
// DEVICE VIDEO INTERFACE
//**************************************************************************

//-------------------------------------------------
// device_video_interface - constructor
//-------------------------------------------------

device_video_interface::device_video_interface(const machine_config &mconfig, device_t &device, bool screen_required)
: device_interface(device),
m_screen_required(screen_required),
m_screen_tag(NULL),
m_screen(NULL)
{
}


//-------------------------------------------------
// ~device_video_interface - destructor
//-------------------------------------------------

device_video_interface::~device_video_interface()
{
}


//-------------------------------------------------
// static_add_route - configuration helper to add
// a new route to the device
//-------------------------------------------------

void device_video_interface::static_set_screen(device_t &device, const char *tag)
{
// find our video interface
device_video_interface *video;
if (!device.interface(video))
throw emu_fatalerror("MCFG_VIDEO_SET_SCREEN called on device '%s' with no video interface", device.tag());
video->m_screen_tag = tag;
}


//-------------------------------------------------
// interface_validity_check - validation for a
// device after the configuration has been
// constructed
//-------------------------------------------------

void device_video_interface::interface_validity_check(validity_checker &valid) const
{
// find the screen device
screen_device *screen = NULL;
if (m_screen_tag != NULL)
{
screen = device().siblingdevice<screen_device>(m_screen_tag);
if (screen == NULL)
mame_printf_error("Screen '%s' not found, explicitly set for device '%s'", m_screen_tag, device().tag());
}

// if no device, look for a single match
if (screen == NULL)
{
screen_device_iterator iter(device().mconfig().root_device());
screen = iter.first();
if (screen == NULL && m_screen_required)
mame_printf_error("Device '%s' requires a screen", device().tag());
if (iter.next() != NULL)
mame_printf_error("No screen specified for device '%s', but multiple screens found", device().tag());
}
}


//-------------------------------------------------
// interface_pre_start - make sure all our input
// devices are started
//-------------------------------------------------

void device_video_interface::interface_pre_start()
{
// find the screen device
if (m_screen_tag != NULL)
{
m_screen = device().siblingdevice<screen_device>(m_screen_tag);
if (m_screen == NULL)
throw emu_fatalerror("Screen '%s' not found, explicitly set for device '%s'", m_screen_tag, device().tag());
}

// if no device, look for a single match
if (m_screen == NULL)
{
screen_device_iterator iter(device().machine().root_device());
m_screen = iter.first();
if (m_screen == NULL && m_screen_required)
throw emu_fatalerror("Device '%s' requires a screen", device().tag());
if (iter.next() != NULL)
throw emu_fatalerror("No screen specified for device '%s', but multiple screens found", device().tag());
}

// if we have a screen and it's not started, wait for it
if (m_screen != NULL && !m_screen->started())
throw device_missing_dependencies();
}
95 changes: 95 additions & 0 deletions src/emu/divideo.h
@@ -0,0 +1,95 @@
/***************************************************************************
divideo.h
Device video interfaces.
****************************************************************************
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 __DIVIDEO_H__
#define __DIVIDEO_H__


//**************************************************************************
// INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_VIDEO_SET_SCREEN(_tag) \
device_video_interface::static_set_screen(*device, _tag);



//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************

// ======================> device_video_interface

class device_video_interface : public device_interface
{
public:
// construction/destruction
device_video_interface(const machine_config &mconfig, device_t &device, bool screen_required = true);
virtual ~device_video_interface();

// static configuration
static void static_set_screen(device_t &device, const char *tag);

// getters
screen_device &screen() const { return *m_screen; }

protected:
// optional operation overrides
virtual void interface_validity_check(validity_checker &valid) const;
virtual void interface_pre_start();

// configuration state
bool m_screen_required; // is a screen required?
const char * m_screen_tag; // configured tag for the target screen

// internal state
screen_device * m_screen; // pointer to the screen device
};

// iterator
typedef device_interface_iterator<device_video_interface> video_interface_iterator;


#endif /* __DIVIDEO_H__ */
1 change: 1 addition & 0 deletions src/emu/driver.c
Expand Up @@ -63,6 +63,7 @@ ADDRESS_MAP_END
driver_device::driver_device(const machine_config &mconfig, device_type type, const char *tag)
: device_t(mconfig, type, "Driver Device", tag, NULL, 0, "", __FILE__),
device_memory_interface(mconfig, *this),
m_screen(*this, "screen"),
m_generic_paletteram_8(*this, "paletteram"),
m_generic_paletteram2_8(*this, "paletteram2"),
m_generic_paletteram_16(*this, "paletteram"),
Expand Down
3 changes: 3 additions & 0 deletions src/emu/driver.h
Expand Up @@ -422,6 +422,9 @@ class driver_device : public device_t,
inline UINT32 paletteram32_be(offs_t offset) const { return m_generic_paletteram_16[offset | 1] | (m_generic_paletteram_16[offset & ~1] << 16); }

public:
// generic devices
optional_device<screen_device> m_screen;

// generic pointers
optional_shared_ptr<UINT8> m_generic_paletteram_8;
optional_shared_ptr<UINT8> m_generic_paletteram2_8;
Expand Down
1 change: 1 addition & 0 deletions src/emu/emu.h
Expand Up @@ -101,6 +101,7 @@ typedef device_t * (*machine_config_constructor)(machine_config &config, device_
#include "diserial.h"
#include "dislot.h"
#include "disound.h"
#include "divideo.h"
#include "dinvram.h"
#include "dirtc.h"
#include "didisasm.h"
Expand Down
1 change: 1 addition & 0 deletions src/emu/emu.mak
Expand Up @@ -71,6 +71,7 @@ EMUOBJS = \
$(EMUOBJ)/dislot.o \
$(EMUOBJ)/disound.o \
$(EMUOBJ)/distate.o \
$(EMUOBJ)/divideo.o \
$(EMUOBJ)/drawgfx.o \
$(EMUOBJ)/driver.o \
$(EMUOBJ)/drivenum.o \
Expand Down
44 changes: 20 additions & 24 deletions src/emu/machine/k053252.c
Expand Up @@ -59,7 +59,8 @@ xexex: 01 FF 00 21 00 37 01 00 00 20 0C 0E 54 00 00 00 384x256 ~ 384x256 (*)
const device_type K053252 = &device_creator<k053252_device>;

k053252_device::k053252_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, K053252, "Konami 053252", tag, owner, clock, "k053252", __FILE__)
: device_t(mconfig, K053252, "Konami 053252", tag, owner, clock, "k053252", __FILE__),
device_video_interface(mconfig, *this)
{
}

Expand All @@ -79,7 +80,6 @@ void k053252_device::device_config_complete()
// or initialize to defaults if none provided
else
{
m_screen_tag = "";
memset(&m_int1_en, 0, sizeof(m_int1_en));
memset(&m_int2_en, 0, sizeof(m_int2_en));
memset(&m_int1_ack, 0, sizeof(m_int1_ack));
Expand All @@ -95,7 +95,6 @@ void k053252_device::device_config_complete()
void k053252_device::device_start()
{
save_item(NAME(m_regs));
m_screen = machine().device<screen_device>(m_screen_tag);
m_int1_en_func.resolve(m_int1_en, *this);
m_int2_en_func.resolve(m_int2_en, *this);
m_int1_ack_func.resolve(m_int1_ack, *this);
Expand Down Expand Up @@ -141,28 +140,25 @@ READ8_MEMBER( k053252_device::read )

void k053252_device::res_change()
{
if(m_screen != NULL)
if(m_hc && m_vc &&
m_hbp && m_hfp &&
m_vbp && m_vfp &&
m_hsw && m_vsw) //safety checks
{
if(m_hc && m_vc &&
m_hbp && m_hfp &&
m_vbp && m_vfp &&
m_hsw && m_vsw) //safety checks
{
rectangle visarea;
//(HC+1) - HFP - HBP - 8*(HSW+1)
//VC - VFP - VBP - (VSW+1)
attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * (m_hc) * m_vc;

//printf("H %d %d %d %d\n",m_hc,m_hfp,m_hbp,m_hsw);
//printf("V %d %d %d %d\n",m_vc,m_vfp,m_vbp,m_vsw);

visarea.min_x = m_offsx;
visarea.min_y = m_offsy;
visarea.max_x = m_offsx + m_hc - m_hfp - m_hbp - 8*(m_hsw) - 1;
visarea.max_y = m_offsy + m_vc - m_vfp - m_vbp - (m_vsw) - 1;

m_screen->configure(m_hc, m_vc, visarea, refresh);
}
rectangle visarea;
//(HC+1) - HFP - HBP - 8*(HSW+1)
//VC - VFP - VBP - (VSW+1)
attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * (m_hc) * m_vc;

//printf("H %d %d %d %d\n",m_hc,m_hfp,m_hbp,m_hsw);
//printf("V %d %d %d %d\n",m_vc,m_vfp,m_vbp,m_vsw);

visarea.min_x = m_offsx;
visarea.min_y = m_offsy;
visarea.max_x = m_offsx + m_hc - m_hfp - m_hbp - 8*(m_hsw) - 1;
visarea.max_y = m_offsy + m_vc - m_vfp - m_vbp - (m_vsw) - 1;

m_screen->configure(m_hc, m_vc, visarea, refresh);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/emu/machine/k053252.h
Expand Up @@ -8,7 +8,6 @@

struct k053252_interface
{
const char *m_screen_tag;
devcb_write_line m_int1_en;
devcb_write_line m_int2_en;
devcb_write_line m_int1_ack;
Expand All @@ -19,6 +18,7 @@ struct k053252_interface
};

class k053252_device : public device_t,
public device_video_interface,
public k053252_interface
{
public:
Expand All @@ -43,7 +43,6 @@ class k053252_device : public device_t,
UINT16 m_vc,m_vfp,m_vbp;
UINT8 m_vsw,m_hsw;

screen_device *m_screen;
devcb_resolved_write_line m_int1_en_func;
devcb_resolved_write_line m_int2_en_func;
devcb_resolved_write_line m_int1_ack_func;
Expand Down

0 comments on commit 25a100d

Please sign in to comment.