From 4b2d2d255e2dac287c2fe44455f05b6c548727b6 Mon Sep 17 00:00:00 2001 From: Couriersud Date: Wed, 16 Oct 2013 20:59:29 +0000 Subject: [PATCH] Pong now uses the new analog monitor device. - Cleanup code (at least a bit :-)) - Minor improvements --- src/emu/machine/net_lib.c | 16 ++--- src/emu/machine/netlist.c | 50 ++++++++++++++- src/emu/machine/netlist.h | 99 +++++++++++++--------------- src/mame/drivers/pong.c | 131 +++++++++----------------------------- src/mame/mame.mak | 1 + 5 files changed, 130 insertions(+), 167 deletions(-) diff --git a/src/emu/machine/net_lib.c b/src/emu/machine/net_lib.c index 5849925d6df..4815a066d9d 100644 --- a/src/emu/machine/net_lib.c +++ b/src/emu/machine/net_lib.c @@ -670,11 +670,11 @@ NETLIB_UPDATE(nic7493) m_QC.setTo(0, NLTIME_FROM_NS(40)); m_QD.setTo(0, NLTIME_FROM_NS(40)); } - //m_CLK.inactivate(); + m_CLK.inactivate(); } //else if (old_clk & !m_lastclk) else { - //m_CLK.activate_hl(); + m_CLK.activate_hl(); if (INPVAL_LAST(m_CLK) & !INPVAL(m_CLK)) { m_cnt++; @@ -694,9 +694,9 @@ NETLIB_FUNC_VOID(nic7493, update_outputs, (void)) switch (m_cnt) { case 0x00: - m_QB.setToNoCheck(0, NLTIME_FROM_NS(34)); - m_QC.setToNoCheck(0, NLTIME_FROM_NS(48)); m_QD.setToNoCheck(0, NLTIME_FROM_NS(70)); + m_QC.setToNoCheck(0, NLTIME_FROM_NS(48)); + m_QB.setToNoCheck(0, NLTIME_FROM_NS(34)); break; case 0x02: case 0x06: @@ -706,13 +706,13 @@ NETLIB_FUNC_VOID(nic7493, update_outputs, (void)) break; case 0x04: case 0x0C: - m_QB.setToNoCheck(0, NLTIME_FROM_NS(34)); m_QC.setToNoCheck(1, NLTIME_FROM_NS(48)); + m_QB.setToNoCheck(0, NLTIME_FROM_NS(34)); break; case 0x08: - m_QB.setToNoCheck(0, NLTIME_FROM_NS(34)); - m_QC.setToNoCheck(0, NLTIME_FROM_NS(48)); m_QD.setToNoCheck(1, NLTIME_FROM_NS(70)); + m_QC.setToNoCheck(0, NLTIME_FROM_NS(48)); + m_QB.setToNoCheck(0, NLTIME_FROM_NS(34)); break; } } @@ -898,7 +898,7 @@ NETLIB_FUNC_VOID(nic9316_sub, update_outputs_all, (void)) NETLIB_FUNC_VOID(nic9316_sub, update_outputs, (void)) { const netlist_time out_delay = NLTIME_FROM_NS(20); -#if 1 +#if 0 m_QA.setTo((m_cnt >> 0) & 1, out_delay); m_QB.setTo((m_cnt >> 1) & 1, out_delay); m_QC.setTo((m_cnt >> 2) & 1, out_delay); diff --git a/src/emu/machine/netlist.c b/src/emu/machine/netlist.c index ac6e0e7e86a..cf66762f49b 100644 --- a/src/emu/machine/netlist.c +++ b/src/emu/machine/netlist.c @@ -79,6 +79,42 @@ #endif +// ---------------------------------------------------------------------------------------- +// netlist_timed_queue +// ---------------------------------------------------------------------------------------- + +ATTR_HOT ATTR_ALIGN void netlist_timed_queue::push(const netlist_timed_queue::entry_t &e) +{ + const netlist_time &t = e.time(); + + if (is_empty() || (t <= item(m_end - 1).time())) + { + set_item(m_end, e); + m_end++; + inc_stat(m_prof_end); + } + else if (t >= item(m_start).time()) + { + m_start--; + set_item(m_start, e); + inc_stat(m_prof_start); + } + else + { + register UINT32 i = m_end; + m_end++; + while ((t > item(i-1).time())) + { + set_item(i, item(i-1)); + inc_stat(m_prof_sortmove); + i--; + } + set_item(i, e); + inc_stat(m_prof_sort); + } +} + + const netlist_time netlist_time::zero = netlist_time::from_raw(0); // ---------------------------------------------------------------------------------------- @@ -304,7 +340,7 @@ public: netdev_a_to_d_proxy(netlist_setup_t &setup, const char *name, net_input_t &in_proxied) : net_device_t(setup, name) { - assert_always(in_proxied.object_type(SIGNAL_MASK) == SIGNAL_DIGITAL, "Digital signal expected"); + assert(in_proxied.object_type(SIGNAL_MASK) == SIGNAL_DIGITAL); m_I.m_high_thresh_V = in_proxied.m_high_thresh_V; m_I.m_low_thresh_V = in_proxied.m_low_thresh_V; } @@ -395,7 +431,7 @@ ATTR_HOT ATTR_ALIGN inline void netlist_base_t::update_time(const netlist_time t const netlist_time delta = t - m_time_ps; m_time_ps = t; - atime -= (delta.as_raw() >> NETLIST_DIV_BITS); + atime -= delta.as_raw(); } else { const netlist_time delta = t - m_time_ps + netlist_time::from_raw(m_rem); m_time_ps = t; @@ -746,8 +782,13 @@ void netlist_setup_t::print_stats() { for (netlist_setup_t::tagmap_devices_t::entry_t *entry = m_devices.first(); entry != NULL; entry = m_devices.next(entry)) { + //entry->object()->s printf("Device %20s : %12d %15ld\n", entry->object()->name(), entry->object()->stat_count, (long int) entry->object()->total_time / (entry->object()->stat_count + 1)); } + printf("Queue Start %15d\n", m_netlist.m_queue.m_prof_start); + printf("Queue End %15d\n", m_netlist.m_queue.m_prof_end); + printf("Queue Sort %15d\n", m_netlist.m_queue.m_prof_sort); + printf("Queue Move %15d\n", m_netlist.m_queue.m_prof_sortmove); } } @@ -866,7 +907,7 @@ ATTR_COLD void net_output_t::set_netdev(net_core_device_t *dev) ATTR_HOT inline void net_output_t::update_dev(const net_input_t &inp, const UINT8 mask) { - if ((inp.state() & mask) != 0) + if (((inp.state() & mask) != 0)) { begin_timing(inp.netdev()->total_time); inc_stat(inp.netdev()->stat_count); @@ -881,11 +922,14 @@ ATTR_HOT inline void net_output_t::update_dev(const net_input_t &inp, const UINT ATTR_HOT inline void net_output_t::update_devs() { + assert(m_num_cons != 0); const UINT8 masks[4] = { 1, 5, 3, 1 }; m_Q = m_new_Q; m_Q_analog = m_new_Q_analog; + //if (m_last_Q == m_Q) + //printf("%s\n", m_netdev->name()); //UINT32 mask = 1 | ((m_last_Q & (m_Q ^ 1)) << 1) | (((m_last_Q ^ 1) & m_Q) << 2); const UINT8 mask = masks[ (m_last_Q << 1) | m_Q ]; diff --git a/src/emu/machine/netlist.h b/src/emu/machine/netlist.h index c30f3beb214..eff033a6da4 100644 --- a/src/emu/machine/netlist.h +++ b/src/emu/machine/netlist.h @@ -64,15 +64,15 @@ //#define NETLIST_INTERNAL_RES (U64(1000000000)) //#define NETLIST_DIV_BITS (0) #define NETLIST_INTERNAL_RES (U64(1000000000000)) -#define NETLIST_DIV_BITS (12) +#define NETLIST_DIV_BITS (10) #define NETLIST_DIV (U64(1) << NETLIST_DIV_BITS) #define NETLIST_MASK (NETLIST_DIV-1) #define NETLIST_CLOCK (NETLIST_INTERNAL_RES / NETLIST_DIV) -#define NLTIME_FROM_NS(_t) netlist_time::from_ns(_t) -#define NLTIME_FROM_US(_t) netlist_time::from_us(_t) -#define NLTIME_FROM_MS(_t) netlist_time::from_ms(_t) -#define NLTIME_IMMEDIATE netlist_time::from_ns(0) +#define NLTIME_FROM_NS(_t) netlist_time::from_nsec(_t) +#define NLTIME_FROM_US(_t) netlist_time::from_usec(_t) +#define NLTIME_FROM_MS(_t) netlist_time::from_msec(_t) +#define NLTIME_IMMEDIATE netlist_time::from_nsec(0) #define NETLIST_HIGHIMP_V (1.23456e20) /* some voltage we should never see */ @@ -223,9 +223,9 @@ public: ATTR_HOT inline const INTERNALTYPE as_raw() const { return m_time; } - ATTR_HOT static inline const netlist_time from_ns(const int ns) { return netlist_time((UINT64) ns * (RESOLUTION / U64(1000000000))); } - ATTR_HOT static inline const netlist_time from_us(const int us) { return netlist_time((UINT64) us * (RESOLUTION / U64(1000000))); } - ATTR_HOT static inline const netlist_time from_ms(const int ms) { return netlist_time((UINT64) ms * (RESOLUTION / U64(1000))); } + ATTR_HOT static inline const netlist_time from_nsec(const int ns) { return netlist_time((UINT64) ns * (RESOLUTION / U64(1000000000))); } + ATTR_HOT static inline const netlist_time from_usec(const int us) { return netlist_time((UINT64) us * (RESOLUTION / U64(1000000))); } + ATTR_HOT static inline const netlist_time from_msec(const int ms) { return netlist_time((UINT64) ms * (RESOLUTION / U64(1000))); } ATTR_HOT static inline const netlist_time from_hz(const UINT64 hz) { return netlist_time(RESOLUTION / hz); } ATTR_HOT static inline const netlist_time from_raw(const INTERNALTYPE raw) { return netlist_time(raw); } @@ -305,25 +305,38 @@ private: _ListClass *m_list; }; +// ---------------------------------------------------------------------------------------- +// forward definitions +// ---------------------------------------------------------------------------------------- + +class net_output_t; +class net_core_device_t; +class net_param_t; +class netlist_setup_t; +class netlist_base_t; + +// ---------------------------------------------------------------------------------------- +// timed queue +// ---------------------------------------------------------------------------------------- + //#define SIZE ((1 << _Size) - 1) -template class netlist_timed_queue { public: - static const int SIZE = ((1 << _Size) - 1); + static const int SIZE = ((1 << 11) - 1); struct entry_t { public: inline entry_t() {} - inline entry_t(netlist_time atime, _QC elem) : m_time(atime), m_object(elem) {} + inline entry_t(netlist_time atime, net_output_t *elem) : m_time(atime), m_object(elem) {} ATTR_HOT inline const netlist_time &time() const { return m_time; } - ATTR_HOT inline _QC object() const { return m_object; } + ATTR_HOT inline net_output_t * object() const { return m_object; } private: netlist_time m_time; - _QC m_object; + net_output_t *m_object; }; netlist_timed_queue() @@ -331,35 +344,15 @@ public: clear(); } +#if 1 + ATTR_HOT bool is_empty() { return ((m_start ^ m_end) & SIZE) == 0; } + ATTR_HOT bool is_not_empty() { return ((m_start ^ m_end) & SIZE) != 0; } +#else ATTR_HOT bool is_empty() { return ((m_start & SIZE) == (m_end & SIZE)); } ATTR_HOT bool is_not_empty() { return ((m_start & SIZE) != (m_end & SIZE)); } +#endif - ATTR_HOT void push(const entry_t &e) - { - const netlist_time &t = e.time(); - - if (is_empty() || (t <= item(m_end - 1).time())) - { - set_item(m_end, e); - m_end++; - } - else if (t >= item(m_start).time()) - { - m_start--; - set_item(m_start, e); - } - else - { - register UINT32 i = m_end; - m_end++; - while ((t > item(i-1).time())) - { - set_item(i, item(i-1)); - i--; - } - set_item(i, e); - } - } + ATTR_HOT ATTR_ALIGN void push(const entry_t &e); ATTR_HOT entry_t &pop() { @@ -374,8 +367,14 @@ public: ATTR_COLD void clear() { - m_end = m_start = (1 << _Size) >> 1; + m_end = m_start = (SIZE + 1) >> 1; } + // profiling + + INT32 m_prof_start; + INT32 m_prof_end; + INT32 m_prof_sortmove; + INT32 m_prof_sort; private: ATTR_HOT inline entry_t &item(const UINT32 x) { return m_list[x & SIZE]; } ATTR_HOT inline void set_item(const UINT32 x, const entry_t &aitem) { m_list[x & SIZE] = aitem; } @@ -383,19 +382,9 @@ private: UINT32 m_start; UINT32 m_end; entry_t m_list[SIZE + 1]; + }; - -// ---------------------------------------------------------------------------------------- -// forward definitions -// ---------------------------------------------------------------------------------------- - -class net_output_t; -class net_core_device_t; -class net_param_t; -class netlist_setup_t; -class netlist_base_t; - // ---------------------------------------------------------------------------------------- // net_object_t // ---------------------------------------------------------------------------------------- @@ -967,6 +956,7 @@ public: else m_i[0].inactivate(); } else { + m_i[1].activate(); if (INPVAL(m_i[1]) ^ _check) m_i[1].inactivate(); } @@ -1107,7 +1097,7 @@ class netlist_base_t { public: - typedef netlist_timed_queue queue_t; + typedef netlist_timed_queue queue_t; netlist_base_t(); virtual ~netlist_base_t(); @@ -1125,6 +1115,9 @@ public: ATTR_COLD void set_mainclock_dev(netdev_mainclock *dev) { m_mainclock = dev; } + // FIXME: should'nt be public + queue_t m_queue; + protected: // performance int m_perf_out_processed; @@ -1137,7 +1130,6 @@ private: UINT32 m_rem; UINT32 m_div; - queue_t m_queue; ATTR_HOT void update_time(const netlist_time t, INT32 &atime); @@ -1522,5 +1514,4 @@ public: // device type definition extern const device_type NETLIST; - #endif diff --git a/src/mame/drivers/pong.c b/src/mame/drivers/pong.c index 177922bec50..3b491c8d7c1 100644 --- a/src/mame/drivers/pong.c +++ b/src/mame/drivers/pong.c @@ -20,6 +20,7 @@ TODO: #include "machine/netlist.h" #include "machine/net_lib.h" #include "sound/dac.h" +#include "video/fixfreq.h" #include "astring.h" /* @@ -47,7 +48,7 @@ TODO: */ #define MASTER_CLOCK 7159000 -#define V_TOTAL (0x105+1) +#define V_TOTAL (0x105+1) // 262 #define H_TOTAL (0x1C6+1) // 454 #define HBSTART (H_TOTAL) @@ -55,7 +56,23 @@ TODO: #define VBSTART (V_TOTAL) #define VBEND (16) -#define HRES_MULT (2) +#define HRES_MULT (1) + +fixedfreq_interface fixedfreq_mode_pong = { + MASTER_CLOCK, + H_TOTAL-67,H_TOTAL-40,H_TOTAL-8,H_TOTAL, + V_TOTAL-22,V_TOTAL-19,V_TOTAL-16,V_TOTAL, + 1, /* interlaced */ + 0.3 +}; + +fixedfreq_interface fixedfreq_mode_pongX2 = { + MASTER_CLOCK * 2, + (H_TOTAL-67) * 2, (H_TOTAL-40) * 2, (H_TOTAL-8) * 2, (H_TOTAL) * 2, + V_TOTAL-22,V_TOTAL-19,V_TOTAL-16,V_TOTAL, + 1, /* interlaced */ + 0.3 +}; enum input_changed_enum { @@ -479,6 +496,8 @@ public: pong_state(const machine_config &mconfig, device_type type, const char *tag) : driver_device(mconfig, type, tag), m_maincpu(*this, "maincpu"), + m_video(*this, "fixfreq"), + m_dac(*this, "dac"), /* just to have a sound device */ m_srst(*this, "maincpu", "SRST"), m_p_V0(*this, "maincpu", "P1"), @@ -492,6 +511,7 @@ public: // devices required_device m_maincpu; + required_device m_video; required_device m_dac; /* just to have a sound device */ // sub devices @@ -516,12 +536,7 @@ public: void video_cb(double newval) { - //printf("%f\n", newval); - if (newval != m_vid) - { - update_vid(); - m_vid = newval; - } + m_video->update_vid(newval, m_maincpu->local_time()); } protected: @@ -534,91 +549,10 @@ protected: private: - void update_vid() - { - const netlist_time clock_period = netlist_time::from_hz(NETLIST_CLOCK); - const netlist_time hsync_min_time = netlist_time::from_us(4); - const netlist_time vsync_min_time = netlist_time::from_us(50); /* usec */ - const int vsync_min_pulses = 4; - - bitmap_rgb32 *bm = m_bitmap[m_cur_bm]; - - UINT64 clocks = m_maincpu->total_cycles(); // m_maincpu->attotime_to_cycles(m_maincpu->local_time()); - int pw = NETLIST_CLOCK / ((UINT64)MASTER_CLOCK) / HRES_MULT; - netlist_time time = clock_period * (clocks - m_last_clock); - - //UINT64 clocks = m_maincpu->netlist().time().as_raw() >> 10; // m_maincpu->attotime_to_cycles(m_maincpu->local_time()); - //int pw = (NETLIST_INTERNAL_CLOCK / ((UINT64)MASTER_CLOCK) / HRES_MULT) >> 8; - - if (m_last_y < bm->height()) - { - int colv = (int) (m_vid / 3.5 * 255.0); - rgb_t col = MAKE_RGB(colv, colv, colv); - int pixels = (clocks - m_line_clock) / pw; - - while (pixels >= bm->width()) - { - bm->plot_box(m_last_x, m_last_y, bm->width() - 1 - m_last_x, 1, col); - pixels -= bm->width(); - m_last_x = 0; - } - bm->plot_box(m_last_x, m_last_y, pixels - m_last_x, 1, col); - m_last_x = pixels; - } - if (m_vid <= 0.34) - { - if (time >= vsync_min_time) - { - m_vsync_cnt++; - if (m_vsync_cnt >= vsync_min_pulses) - { - m_vsync_cnt = 0; - m_last_y = 0; - // toggle bitmap - m_cur_bm ^= 1; - attoseconds_t new_refresh = DOUBLE_TO_ATTOSECONDS((double) (clocks - m_vsync_clock) / (double) NETLIST_CLOCK); - if (new_refresh != m_refresh) - { - m_refresh = new_refresh; - rectangle visarea(0, H_TOTAL * HRES_MULT - 1, 0, V_TOTAL-1); - this->mconfig().first_screen()->configure(H_TOTAL * HRES_MULT, V_TOTAL, visarea, m_refresh); - m_vsync_clock = clocks; - } - } - m_last_y++; - m_last_x = 0; - } - else if (time >= hsync_min_time) - { - //printf("%d\n", m_last_x); - m_last_x = 0; // hsync - m_last_y++; - m_line_clock = clocks; - } - } - m_last_clock = clocks; - } - - double m_vid; - int m_last_x; - int m_last_y; - UINT64 m_last_clock; - UINT64 m_line_clock; - UINT64 m_vsync_clock; - attoseconds_t m_refresh; - int m_vsync_cnt; - bitmap_rgb32 *m_bitmap[2]; - int m_cur_bm; }; void pong_state::machine_start() { - m_bitmap[0] = auto_bitmap_rgb32_alloc(machine(),H_TOTAL * HRES_MULT,V_TOTAL); - m_bitmap[1] = auto_bitmap_rgb32_alloc(machine(),H_TOTAL * HRES_MULT,V_TOTAL); - m_cur_bm = 0; - - m_maincpu->setup().register_callback("sound_cb", net_output_delegate(&pong_state::sound_cb, "pong_state::sound_cb", this)); - m_maincpu->setup().register_callback("video_cb", net_output_delegate(&pong_state::video_cb, "pong_state::video_cb", this)); } void pong_state::machine_reset() @@ -628,15 +562,8 @@ void pong_state::machine_reset() void pong_state::video_start() { - //FIXME: createtemporary bitmap -} - - -UINT32 pong_state::screen_update( screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect ) -{ - copybitmap(bitmap, *m_bitmap[!m_cur_bm], 0, 0, 0, 0, cliprect); - //m_bitmap->fill(MAKE_RGB(0,0,0)); - return 0; + m_maincpu->setup().register_callback("sound_cb", net_output_delegate(&pong_state::sound_cb, "pong_state::sound_cb", this)); + m_maincpu->setup().register_callback("video_cb", net_output_delegate(&pong_state::video_cb, "pong_state::video_cb", this)); } @@ -722,9 +649,10 @@ static MACHINE_CONFIG_START( pong, pong_state ) MCFG_NETLIST_ADD("maincpu", pong) /* video hardware */ - MCFG_SCREEN_ADD("screen", RASTER) - MCFG_SCREEN_RAW_PARAMS(MASTER_CLOCK * HRES_MULT, H_TOTAL * HRES_MULT, HBEND * HRES_MULT, HBSTART * HRES_MULT, V_TOTAL, VBEND, VBSTART) - MCFG_SCREEN_UPDATE_DRIVER(pong_state, screen_update) + + //MCFG_FIXFREQ_ADD("fixfreq", "screen", fixedfreq_mode_ntsc720) + //MCFG_FIXFREQ_ADD("fixfreq", "screen", fixedfreq_mode_pongX2) + MCFG_FIXFREQ_ADD("fixfreq", "screen", fixedfreq_mode_pong) /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") @@ -736,7 +664,6 @@ MACHINE_CONFIG_END static MACHINE_CONFIG_DERIVED( pongf, pong ) /* basic machine hardware */ - //MCFG_NETLIST_REPLACE("maincpu", MASTER_CLOCK, pong_fast, 100) MCFG_NETLIST_REPLACE("maincpu", pong_fast) MACHINE_CONFIG_END diff --git a/src/mame/mame.mak b/src/mame/mame.mak index 915da9a67bb..baf5a388c34 100644 --- a/src/mame/mame.mak +++ b/src/mame/mame.mak @@ -280,6 +280,7 @@ VIDEOS += BUFSPRITE #VIDEOS += DL1416 VIDEOS += DM9368 #VIDEOS += EF9340_1 +VIDEOS += FIXFREQ VIDEOS += H63484 #VIDEOS += HD44102 #VIDEOS += HD44352