From b3e306b985c98019687f46fb08cd4f999ec751f7 Mon Sep 17 00:00:00 2001 From: AJR Date: Tue, 21 Aug 2018 09:04:09 -0400 Subject: [PATCH] divideo: Fetch screen to be potentially configured during device_config_complete (nw) - Allow device finder to be used as an argument for set_screen (nw) screen: Calculate physical aspect ratio whenever required, not in device_config_complete, since the renderer caches the result anyway (nw) cdp1861, cdp1864: Eliminate the "magic reference" constructors, doing their work in device_config_complete instead (nw) --- src/devices/sound/cdp1864.cpp | 22 +++++++++++++++++----- src/devices/sound/cdp1864.h | 4 +--- src/devices/video/cdp1861.cpp | 23 ++++++++++++++++++----- src/devices/video/cdp1861.h | 4 +--- src/emu/divideo.cpp | 16 ++++++++++++++++ src/emu/divideo.h | 7 +++++++ src/emu/screen.cpp | 30 ++++++++++++++++++++++-------- src/emu/screen.h | 2 +- src/mame/drivers/cosmicos.cpp | 5 ++++- src/mame/drivers/elf.cpp | 5 +++-- src/mame/drivers/eti660.cpp | 8 ++++++-- src/mame/drivers/studio2.cpp | 13 +++++++++---- src/mame/drivers/tmc2000e.cpp | 8 ++++++-- src/mame/drivers/vip.cpp | 6 ++++-- src/mame/video/tmc1800.cpp | 10 +++++++--- 15 files changed, 122 insertions(+), 41 deletions(-) diff --git a/src/devices/sound/cdp1864.cpp b/src/devices/sound/cdp1864.cpp index 6e69a2a1853..c8d13cda92c 100644 --- a/src/devices/sound/cdp1864.cpp +++ b/src/devices/sound/cdp1864.cpp @@ -23,6 +23,7 @@ #include "emu.h" #include "cdp1864.h" +#include "screen.h" @@ -78,12 +79,23 @@ cdp1864_device::cdp1864_device(const machine_config &mconfig, const char *tag, d { } -cdp1864_device::cdp1864_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, screen_device &screen) - : cdp1864_device(mconfig, tag, owner, clock) + +//------------------------------------------------- +// device_config_complete - perform any +// operations now that the configuration is +// complete +//------------------------------------------------- + +void cdp1864_device::device_config_complete() { - set_screen(screen, DEVICE_SELF); - screen.set_screen_update(screen_update_rgb32_delegate(FUNC(cdp1864_device::screen_update), this)); - screen.set_raw(clock, SCREEN_WIDTH, HBLANK_END, HBLANK_START, TOTAL_SCANLINES, SCANLINE_VBLANK_END, SCANLINE_VBLANK_START); + if (!has_screen()) + return; + + if (!screen().refresh_attoseconds()) + screen().set_raw(clock(), SCREEN_WIDTH, HBLANK_END, HBLANK_START, TOTAL_SCANLINES, SCANLINE_VBLANK_END, SCANLINE_VBLANK_START); + + if (!screen().have_screen_update()) + screen().set_screen_update(screen_update_rgb32_delegate(FUNC(cdp1864_device::screen_update), this)); } diff --git a/src/devices/sound/cdp1864.h b/src/devices/sound/cdp1864.h index ef8caba13e8..ff66122dfbd 100644 --- a/src/devices/sound/cdp1864.h +++ b/src/devices/sound/cdp1864.h @@ -40,8 +40,6 @@ #include "machine/rescap.h" #include "video/resnet.h" -#include "screen.h" - //************************************************************************** @@ -83,7 +81,6 @@ public: // construction/destruction cdp1864_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - cdp1864_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, screen_device &screen); auto inlace_cb() { return m_read_inlace.bind(); } auto int_cb() { return m_write_int.bind(); } @@ -112,6 +109,7 @@ public: protected: // device-level overrides + virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; diff --git a/src/devices/video/cdp1861.cpp b/src/devices/video/cdp1861.cpp index 09a6810c426..9748d5e03c1 100644 --- a/src/devices/video/cdp1861.cpp +++ b/src/devices/video/cdp1861.cpp @@ -9,6 +9,8 @@ #include "emu.h" #include "cdp1861.h" +#include "screen.h" + //************************************************************************** @@ -51,12 +53,23 @@ cdp1861_device::cdp1861_device(const machine_config &mconfig, const char *tag, d { } -cdp1861_device::cdp1861_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, screen_device &screen) - : cdp1861_device(mconfig, tag, owner, clock) + +//------------------------------------------------- +// device_config_complete - perform any +// operations now that the configuration is +// complete +//------------------------------------------------- + +void cdp1861_device::device_config_complete() { - set_screen(screen, DEVICE_SELF); - screen.set_screen_update(screen_update_rgb32_delegate(FUNC(cdp1861_device::screen_update), this)); - screen.set_raw(clock, SCREEN_WIDTH, HBLANK_END, HBLANK_START, TOTAL_SCANLINES, SCANLINE_VBLANK_END, SCANLINE_VBLANK_START); + if (!has_screen()) + return; + + if (!screen().refresh_attoseconds()) + screen().set_raw(clock(), SCREEN_WIDTH, HBLANK_END, HBLANK_START, TOTAL_SCANLINES, SCANLINE_VBLANK_END, SCANLINE_VBLANK_START); + + if (!screen().have_screen_update()) + screen().set_screen_update(screen_update_rgb32_delegate(FUNC(cdp1861_device::screen_update), this)); } diff --git a/src/devices/video/cdp1861.h b/src/devices/video/cdp1861.h index 9b523402410..77f350d5afe 100644 --- a/src/devices/video/cdp1861.h +++ b/src/devices/video/cdp1861.h @@ -26,8 +26,6 @@ #pragma once -#include "screen.h" - //************************************************************************** // TYPE DEFINITIONS @@ -65,7 +63,6 @@ public: // construction/destruction cdp1861_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - cdp1861_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, screen_device &screen); auto int_cb() { return m_write_int.bind(); } auto dma_out_cb() { return m_write_dma_out.bind(); } @@ -81,6 +78,7 @@ public: protected: // device-level overrides + virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; diff --git a/src/emu/divideo.cpp b/src/emu/divideo.cpp index 437cd20a31b..61287e0e35d 100644 --- a/src/emu/divideo.cpp +++ b/src/emu/divideo.cpp @@ -50,6 +50,22 @@ void device_video_interface::set_screen(const char *tag) } +//------------------------------------------------- +// interface_config_complete - perform any +// operations now that the configuration is +// complete +//------------------------------------------------- + +void device_video_interface::interface_config_complete() +{ + // find the screen if explicitly configured + if (m_screen_tag && strcmp(m_screen_tag, s_unconfigured_screen_tag) != 0) + m_screen = m_screen_base->subdevice(m_screen_tag); + + // device_config_complete may now do whatever it needs to with the screen +} + + //------------------------------------------------- // interface_validity_check - validation for a // device after the configuration has been diff --git a/src/emu/divideo.h b/src/emu/divideo.h index 87425f09a9a..1b6f48104bd 100644 --- a/src/emu/divideo.h +++ b/src/emu/divideo.h @@ -49,6 +49,12 @@ public: m_screen_base = &base; m_screen_tag = tag; } + template + void set_screen(device_finder &finder) + { + m_screen_base = &finder.finder_target().first; + m_screen_tag = finder.finder_target().second; + } // getters screen_device &screen() const { return *m_screen; } @@ -56,6 +62,7 @@ public: protected: // optional operation overrides + virtual void interface_config_complete() override; virtual void interface_validity_check(validity_checker &valid) const override; virtual void interface_pre_start() override; diff --git a/src/emu/screen.cpp b/src/emu/screen.cpp index 2ec5b660876..edfc92e62a9 100644 --- a/src/emu/screen.cpp +++ b/src/emu/screen.cpp @@ -656,19 +656,32 @@ void screen_device::device_config_complete() { // combine orientation with machine orientation m_orientation = orientation_add(m_orientation, mconfig().gamedrv().flags & machine_flags::MASK_ORIENTATION); +} + + +//------------------------------------------------- +// physical_aspect - determine the physical +// aspect ratio to be used for rendering +//------------------------------------------------- + +std::pair screen_device::physical_aspect() const +{ + assert(configured()); + + std::pair phys_aspect = m_phys_aspect; // physical aspect ratio unconfigured - if (!m_phys_aspect.first || !m_phys_aspect.second) + if (!phys_aspect.first || !phys_aspect.second) { switch (m_type) { case SCREEN_TYPE_RASTER: case SCREEN_TYPE_VECTOR: - m_phys_aspect = std::make_pair(4, 3); // assume standard CRT + phys_aspect = std::make_pair(4, 3); // assume standard CRT break; case SCREEN_TYPE_LCD: case SCREEN_TYPE_SVG: - m_phys_aspect = std::make_pair(~0U, ~0U); // assume square pixels + phys_aspect = std::make_pair(~0U, ~0U); // assume square pixels break; case SCREEN_TYPE_INVALID: default: @@ -677,16 +690,17 @@ void screen_device::device_config_complete() } // square pixels? - if ((~0U == m_phys_aspect.first) && (~0U == m_phys_aspect.second)) + if ((~0U == phys_aspect.first) && (~0U == phys_aspect.second)) { - m_phys_aspect.first = visible_area().width(); - m_phys_aspect.second = visible_area().height(); + phys_aspect.first = visible_area().width(); + phys_aspect.second = visible_area().height(); } // always keep this in reduced form - util::reduce_fraction(m_phys_aspect.first, m_phys_aspect.second); -} + util::reduce_fraction(phys_aspect.first, phys_aspect.second); + return phys_aspect; +} //------------------------------------------------- diff --git a/src/emu/screen.h b/src/emu/screen.h index 45374fef1e7..2b72a2691ac 100644 --- a/src/emu/screen.h +++ b/src/emu/screen.h @@ -182,7 +182,7 @@ public: // configuration readers screen_type_enum screen_type() const { return m_type; } int orientation() const { assert(configured()); return m_orientation; } - std::pair physical_aspect() const { assert(configured()); return m_phys_aspect; } + std::pair physical_aspect() const; int width() const { return m_width; } int height() const { return m_height; } const rectangle &visible_area() const { return m_visarea; } diff --git a/src/mame/drivers/cosmicos.cpp b/src/mame/drivers/cosmicos.cpp index 553997796ee..f3aa02eba41 100644 --- a/src/mame/drivers/cosmicos.cpp +++ b/src/mame/drivers/cosmicos.cpp @@ -36,6 +36,7 @@ #include "emu.h" #include "includes/cosmicos.h" +#include "screen.h" #include "speaker.h" #include "cosmicos.lh" @@ -527,13 +528,15 @@ MACHINE_CONFIG_START(cosmicos_state::cosmicos) MCFG_TIMER_DRIVER_ADD_PERIODIC("digit", cosmicos_state, digit_tick, attotime::from_hz(100)) MCFG_TIMER_DRIVER_ADD_PERIODIC("interrupt", cosmicos_state, int_tick, attotime::from_hz(1000)) + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); + /* sound hardware */ SPEAKER(config, "mono").front_center(); MCFG_DEVICE_ADD("speaker", SPEAKER_SOUND) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) - CDP1864(config, m_cti, 1.75_MHz_XTAL, SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1864(config, m_cti, 1.75_MHz_XTAL).set_screen(SCREEN_TAG); m_cti->inlace_cb().set_constant(0); m_cti->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_cti->dma_out_cb().set(FUNC(cosmicos_state::dmaout_w)); diff --git a/src/mame/drivers/elf.cpp b/src/mame/drivers/elf.cpp index 2a3de82e26a..f9ce8358370 100644 --- a/src/mame/drivers/elf.cpp +++ b/src/mame/drivers/elf.cpp @@ -17,6 +17,7 @@ #include "emu.h" #include "includes/elf.h" #include "elf2.lh" +#include "screen.h" #define RUN \ BIT(m_special->read(), 0) @@ -251,11 +252,11 @@ MACHINE_CONFIG_START(elf2_state::elf2) /* video hardware */ config.set_default_layout(layout_elf2); - - CDP1861(config, m_vdc, XTAL(3'579'545)/2, SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1861(config, m_vdc, XTAL(3'579'545)/2).set_screen(SCREEN_TAG); m_vdc->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_vdc->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); m_vdc->efx_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_EF1); + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); /* devices */ MCFG_DEVICE_ADD(MM74C923_TAG, MM74C923, 0) diff --git a/src/mame/drivers/eti660.cpp b/src/mame/drivers/eti660.cpp index dbd4eef6fcd..9ca22647fc5 100644 --- a/src/mame/drivers/eti660.cpp +++ b/src/mame/drivers/eti660.cpp @@ -38,6 +38,7 @@ #include "emu.h" #include "includes/eti660.h" +#include "screen.h" #include "speaker.h" @@ -318,9 +319,12 @@ MACHINE_CONFIG_START(eti660_state::eti660) m_maincpu->q_cb().set(FUNC(eti660_state::q_w)); m_maincpu->dma_wr_cb().set(FUNC(eti660_state::dma_w)); - /* video/sound hardware */ + /* video hardware */ + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); + + /* sound hardware */ SPEAKER(config, "mono").front_center(); - CDP1864(config, m_cti, XTAL(8'867'238)/5, SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1864(config, m_cti, XTAL(8'867'238)/5).set_screen(SCREEN_TAG); m_cti->inlace_cb().set_constant(0); m_cti->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_cti->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); diff --git a/src/mame/drivers/studio2.cpp b/src/mame/drivers/studio2.cpp index a98a74c3f69..40282dc6999 100644 --- a/src/mame/drivers/studio2.cpp +++ b/src/mame/drivers/studio2.cpp @@ -194,6 +194,7 @@ Notes: #include "bus/generic/slot.h" #include "bus/generic/carts.h" +#include "screen.h" #include "softlist.h" #include "speaker.h" @@ -660,7 +661,8 @@ MACHINE_CONFIG_START(studio2_state::studio2) m_maincpu->dma_wr_cb().set(m_vdc, FUNC(cdp1861_device::dma_w)); /* video hardware */ - CDP1861(config, m_vdc, 1760000, SCREEN(config, m_screen, SCREEN_TYPE_RASTER)); + SCREEN(config, m_screen, SCREEN_TYPE_RASTER); + CDP1861(config, m_vdc, 1760000).set_screen(m_screen); m_vdc->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_vdc->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); m_vdc->efx_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_EF1); @@ -685,11 +687,13 @@ MACHINE_CONFIG_START(visicom_state::visicom) m_maincpu->dma_wr_cb().set(FUNC(visicom_state::dma_w)); /* video hardware */ - CDP1861(config, m_vdc, XTAL(3'579'545)/2, SCREEN(config, m_screen, SCREEN_TYPE_RASTER)); + SCREEN(config, m_screen, SCREEN_TYPE_RASTER); + m_screen->set_screen_update(FUNC(visicom_state::screen_update)); + + CDP1861(config, m_vdc, XTAL(3'579'545)/2).set_screen(m_screen); m_vdc->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_vdc->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); m_vdc->efx_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_EF1); - m_screen->set_screen_update(FUNC(visicom_state::screen_update)); /* sound hardware */ SPEAKER(config, "mono").front_center(); @@ -718,7 +722,8 @@ MACHINE_CONFIG_START(mpt02_state::mpt02) SPEAKER(config, "mono").front_center(); BEEP(config, m_beeper, 300).add_route(ALL_OUTPUTS, "mono", 1.00); - CDP1864(config, m_cti, 1.75_MHz_XTAL, SCREEN(config, m_screen, SCREEN_TYPE_RASTER)); + SCREEN(config, m_screen, SCREEN_TYPE_RASTER); + CDP1864(config, m_cti, 1.75_MHz_XTAL).set_screen(m_screen); m_cti->inlace_cb().set_constant(0); m_cti->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_cti->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); diff --git a/src/mame/drivers/tmc2000e.cpp b/src/mame/drivers/tmc2000e.cpp index 1d6d43cfee3..315f398479d 100644 --- a/src/mame/drivers/tmc2000e.cpp +++ b/src/mame/drivers/tmc2000e.cpp @@ -34,6 +34,7 @@ #include "emu.h" #include "includes/tmc2000e.h" +#include "screen.h" #include "speaker.h" @@ -293,9 +294,12 @@ void tmc2000e_state::tmc2000e(machine_config &config) m_maincpu->q_cb().set(FUNC(tmc2000e_state::q_w)); m_maincpu->dma_wr_cb().set(FUNC(tmc2000e_state::dma_w)); - // video/sound hardware + // video hardware + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); + + // sound hardware SPEAKER(config, "mono").front_center(); - CDP1864(config, m_cti, 1.75_MHz_XTAL, SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1864(config, m_cti, 1.75_MHz_XTAL).set_screen(SCREEN_TAG); m_cti->inlace_cb().set_constant(0); m_cti->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_cti->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); diff --git a/src/mame/drivers/vip.cpp b/src/mame/drivers/vip.cpp index 88d9a6d5af9..54ceade7ab1 100644 --- a/src/mame/drivers/vip.cpp +++ b/src/mame/drivers/vip.cpp @@ -222,6 +222,7 @@ Notes: #include "emu.h" #include "includes/vip.h" +#include "screen.h" #include "softlist.h" #include "speaker.h" @@ -716,11 +717,12 @@ MACHINE_CONFIG_START(vip_state::vip) m_maincpu->tpb_cb().set(m_exp, FUNC(vip_expansion_slot_device::tpb_w)); // video hardware - screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); - CDP1861(config, m_vdc, 3.52128_MHz_XTAL / 2, screen); + CDP1861(config, m_vdc, 3.52128_MHz_XTAL / 2).set_screen(SCREEN_TAG); m_vdc->int_cb().set(FUNC(vip_state::vdc_int_w)); m_vdc->dma_out_cb().set(FUNC(vip_state::vdc_dma_out_w)); m_vdc->efx_cb().set(FUNC(vip_state::vdc_ef1_w)); + + screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); screen.set_screen_update(FUNC(vip_state::screen_update)); // sound hardware diff --git a/src/mame/video/tmc1800.cpp b/src/mame/video/tmc1800.cpp index 83d2471ca4e..71110e5aa51 100644 --- a/src/mame/video/tmc1800.cpp +++ b/src/mame/video/tmc1800.cpp @@ -7,6 +7,7 @@ #include "machine/rescap.h" #include "sound/cdp1864.h" #include "video/cdp1861.h" +#include "screen.h" #include "speaker.h" @@ -38,10 +39,11 @@ uint32_t osc1000b_state::screen_update(screen_device &screen, bitmap_rgb32 &bitm void tmc1800_state::tmc1800_video(machine_config &config) { - CDP1861(config, m_vdc, XTAL(1'750'000), SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1861(config, m_vdc, XTAL(1'750'000)).set_screen(SCREEN_TAG); m_vdc->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_vdc->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); m_vdc->efx_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_EF1); + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); } MACHINE_CONFIG_START(osc1000b_state::osc1000b_video) @@ -54,8 +56,9 @@ MACHINE_CONFIG_END void tmc2000_state::tmc2000_video(machine_config &config) { + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); SPEAKER(config, "mono").front_center(); - CDP1864(config, m_cti, XTAL(1'750'000), SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1864(config, m_cti, XTAL(1'750'000)).set_screen(SCREEN_TAG); m_cti->inlace_cb().set_constant(0); m_cti->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_cti->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT); @@ -69,8 +72,9 @@ void tmc2000_state::tmc2000_video(machine_config &config) void nano_state::nano_video(machine_config &config) { + SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER); SPEAKER(config, "mono").front_center(); - CDP1864(config, m_cti, XTAL(1'750'000), SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER)); + CDP1864(config, m_cti, XTAL(1'750'000)).set_screen(SCREEN_TAG); m_cti->inlace_cb().set_constant(0); m_cti->int_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_INT); m_cti->dma_out_cb().set_inputline(m_maincpu, COSMAC_INPUT_LINE_DMAOUT);