From 6c8616c1c710efbfaca766e3e27deeafd97fdcd5 Mon Sep 17 00:00:00 2001 From: Curt Coder Date: Tue, 14 Jan 2014 18:49:24 +0000 Subject: [PATCH] tms9927: Added VSYNC callback. [Curt Coder] --- src/emu/video/tms9927.c | 39 +++++++++++++++++++++++++++++++++++++-- src/emu/video/tms9927.h | 17 +++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/emu/video/tms9927.c b/src/emu/video/tms9927.c index 831c088b2dc..59d3b05b4d8 100644 --- a/src/emu/video/tms9927.c +++ b/src/emu/video/tms9927.c @@ -37,13 +37,15 @@ const device_type CRT5057 = &device_creator; tms9927_device::tms9927_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, TMS9927, "TMS9927", tag, owner, clock, "tms9927", __FILE__), - device_video_interface(mconfig, *this) + device_video_interface(mconfig, *this), + m_write_vsyn(*this) { } tms9927_device::tms9927_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) : device_t(mconfig, type, name, tag, owner, clock, shortname, source), - device_video_interface(mconfig, *this) + device_video_interface(mconfig, *this), + m_write_vsyn(*this) { } @@ -98,6 +100,12 @@ void tms9927_device::device_start() assert(m_selfload != NULL); } + // resolve callbacks + m_write_vsyn.resolve_safe(); + + // allocate timers + m_vsync_timer = timer_alloc(TIMER_VSYNC); + /* register for state saving */ machine().save().register_postload(save_prepost_delegate(FUNC(tms9927_device::state_postload), this)); @@ -130,6 +138,30 @@ void tms9927_device::device_stop() +//------------------------------------------------- +// device_timer - handle timer events +//------------------------------------------------- + +void tms9927_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +{ + switch (id) + { + case TIMER_VSYNC: + m_vsyn = !m_vsyn; + + m_write_vsyn(m_vsyn); + + if (m_vsyn) + { + m_vsync_timer->adjust(m_screen->time_until_pos(3)); + } + else + { + m_vsync_timer->adjust(m_screen->time_until_pos(0)); + } + break; + } +} void tms9927_device::state_postload() { @@ -297,4 +329,7 @@ void tms9927_device::recompute_parameters(int postload) refresh = HZ_TO_ATTOSECONDS(m_clock) * m_total_hpix * m_total_vpix; m_screen->configure(m_total_hpix, m_total_vpix, visarea, refresh); + + m_vsyn = 0; + m_vsync_timer->adjust(m_screen->time_until_pos(0, 0)); } diff --git a/src/emu/video/tms9927.h b/src/emu/video/tms9927.h index 2405fbd1274..8f0b7f2b0a7 100644 --- a/src/emu/video/tms9927.h +++ b/src/emu/video/tms9927.h @@ -10,6 +10,10 @@ #ifndef __TMS9927__ #define __TMS9927__ + +#define MCFG_TMS9927_VSYN_CALLBACK(_write) \ + devcb = &tms9927_device::set_vsyn_wr_callback(*device, DEVCB2_##_write); + /* interface */ struct tms9927_interface { @@ -27,6 +31,8 @@ public: tms9927_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); ~tms9927_device() {} + template static devcb2_base &set_vsyn_wr_callback(device_t &device, _Object object) { return downcast(device).m_write_vsyn.set_callback(object); } + DECLARE_WRITE8_MEMBER(write); DECLARE_READ8_MEMBER(read); @@ -40,13 +46,20 @@ protected: virtual void device_start(); virtual void device_stop(); virtual void device_reset(); + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); private: + enum + { + TIMER_VSYNC + }; void state_postload(); void recompute_parameters(int postload); void generic_access(address_space &space, offs_t offset); + devcb2_write_line m_write_vsyn; + // internal state const UINT8 *m_selfload; @@ -60,6 +73,10 @@ private: UINT8 m_valid_config; UINT16 m_total_hpix, m_total_vpix; UINT16 m_visible_hpix, m_visible_vpix; + + int m_vsyn; + + emu_timer *m_vsync_timer; }; extern const device_type TMS9927;