trunk/src/emu/machine/netlist.c
r27452 | r27453 | |
66 | 66 | |
67 | 67 | netlist_mame_analog_input_t::netlist_mame_analog_input_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
68 | 68 | : device_t(mconfig, NETLIST_ANALOG_INPUT, "netlist analog input", tag, owner, clock, "netlist_analog_input", __FILE__), |
69 | | netlist_mame_sub_interface(*this), |
| 69 | netlist_mame_sub_interface(*owner), |
70 | 70 | m_param(0), |
71 | 71 | m_offset(0.0), |
72 | 72 | m_mult(1.0), |
r27452 | r27453 | |
93 | 93 | void netlist_mame_analog_input_t::device_start() |
94 | 94 | { |
95 | 95 | LOG_DEV_CALLS(("start %s\n", tag())); |
96 | | netlist_param_t *p = downcast<netlist_mame_device_t *>(this->owner())->setup().find_param(m_param_name); |
| 96 | netlist_param_t *p = this->nl_owner().setup().find_param(m_param_name); |
97 | 97 | m_param = dynamic_cast<netlist_param_double_t *>(p); |
98 | 98 | if (m_param == NULL) |
99 | 99 | { |
r27452 | r27453 | |
103 | 103 | |
104 | 104 | netlist_mame_logic_input_t::netlist_mame_logic_input_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
105 | 105 | : device_t(mconfig, NETLIST_ANALOG_INPUT, "netlist analog input", tag, owner, clock, "netlist_analog_input", __FILE__), |
106 | | netlist_mame_sub_interface(*this), |
| 106 | netlist_mame_sub_interface(*owner), |
107 | 107 | m_param(0), |
108 | 108 | m_mask(0xffffffff), |
109 | 109 | m_shift(0), |
trunk/src/emu/machine/netlist.h
r27452 | r27453 | |
281 | 281 | |
282 | 282 | static void static_set_constructor(device_t &device, void (*setup_func)(netlist_setup_t &)); |
283 | 283 | |
| 284 | inline sound_stream *get_stream() { return m_stream; } |
| 285 | |
| 286 | |
284 | 287 | // device_sound_interface overrides |
285 | 288 | |
286 | 289 | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
r27452 | r27453 | |
318 | 321 | { |
319 | 322 | public: |
320 | 323 | // construction/destruction |
321 | | netlist_mame_sub_interface(netlist_mame_device_t &obj) : m_object(obj) {} |
| 324 | netlist_mame_sub_interface(device_t &aowner) |
| 325 | { |
| 326 | m_owner = dynamic_cast<netlist_mame_device_t *>(&aowner); |
| 327 | m_sound = dynamic_cast<netlist_mame_sound_device_t *>(&aowner); |
| 328 | } |
322 | 329 | virtual ~netlist_mame_sub_interface() { } |
323 | 330 | |
324 | 331 | virtual void custom_netlist_additions(netlist_base_t &netlist) { } |
325 | 332 | |
326 | | inline netlist_mame_device_t &object() { return m_object; } |
| 333 | inline netlist_mame_device_t &nl_owner() const { return *m_owner; } |
| 334 | |
| 335 | inline bool is_sound_device() const { return (m_sound != NULL); } |
| 336 | |
| 337 | inline void update_to_current_time() |
| 338 | { |
| 339 | printf("%p\n", m_sound); |
| 340 | printf("%p\n", m_sound->get_stream()); |
| 341 | m_sound->get_stream()->update(); |
| 342 | } |
| 343 | |
327 | 344 | private: |
328 | | netlist_mame_device_t &m_object; |
| 345 | netlist_mame_device_t *m_owner; |
| 346 | netlist_mame_sound_device_t *m_sound; |
329 | 347 | }; |
330 | 348 | |
331 | 349 | // ---------------------------------------------------------------------------------------- |
r27452 | r27453 | |
344 | 362 | static void static_set_name(device_t &device, const char *param_name); |
345 | 363 | static void static_set_mult_offset(device_t &device, const double mult, const double offset); |
346 | 364 | |
347 | | inline void write(const double val) { m_param->setTo(val * m_mult + m_offset); } |
| 365 | inline void write(const double val) |
| 366 | { |
| 367 | if (is_sound_device()) |
| 368 | { |
| 369 | update_to_current_time(); |
| 370 | m_param->setTo(val * m_mult + m_offset); |
| 371 | } |
| 372 | else |
| 373 | { |
| 374 | // FIXME: use device timer .... |
| 375 | m_param->setTo(val * m_mult + m_offset); |
| 376 | } |
| 377 | } |
348 | 378 | |
349 | 379 | inline DECLARE_INPUT_CHANGED_MEMBER(input_changed) |
350 | 380 | { |
r27452 | r27453 | |
386 | 416 | |
387 | 417 | static void static_set_params(device_t &device, const char *param_name, const UINT32 mask, const UINT32 shift); |
388 | 418 | |
389 | | inline void write(const UINT32 val) { m_param->setTo((val >> m_shift) & m_mask); } |
| 419 | inline void write(const UINT32 val) |
| 420 | { |
| 421 | if (is_sound_device()) |
| 422 | { |
| 423 | update_to_current_time(); |
| 424 | m_param->setTo((val >> m_shift) & m_mask); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | // FIXME: use device timer .... |
| 429 | m_param->setTo((val >> m_shift) & m_mask); |
| 430 | } |
| 431 | } |
390 | 432 | |
391 | 433 | inline DECLARE_INPUT_CHANGED_MEMBER(input_changed) { write(newval); } |
392 | 434 | DECLARE_WRITE_LINE_MEMBER(write_line) { write(state); } |
r27452 | r27453 | |
510 | 552 | NETLIB_NAME(sound_in)() |
511 | 553 | : netlist_device_t() { } |
512 | 554 | |
513 | | static const int BUFSIZE = 2048; |
| 555 | static const int MAX_INPUT_CHANNELS = 10; |
514 | 556 | |
515 | 557 | ATTR_COLD void start() |
516 | 558 | { |
r27452 | r27453 | |
522 | 564 | m_inc = netlist_time::from_nsec(1); |
523 | 565 | |
524 | 566 | |
525 | | for (int i=0; i<10; i++) |
| 567 | for (int i = 0; i < MAX_INPUT_CHANNELS; i++) |
526 | 568 | register_param(pstring::sprintf("CHAN%d", i), m_param_name[i], ""); |
527 | 569 | m_num_channel = 0; |
528 | 570 | } |
r27452 | r27453 | |
530 | 572 | ATTR_COLD void reset() |
531 | 573 | { |
532 | 574 | m_pos = 0; |
533 | | for (int i=0; i<10; i++) |
| 575 | for (int i = 0; i < MAX_INPUT_CHANNELS; i++) |
534 | 576 | m_buffer[i] = NULL; |
535 | 577 | } |
536 | 578 | |
537 | 579 | ATTR_COLD int resolve() |
538 | 580 | { |
539 | 581 | m_pos = 0; |
540 | | for (int i=0; i<10; i++) |
| 582 | for (int i = 0; i < MAX_INPUT_CHANNELS; i++) |
541 | 583 | { |
542 | 584 | if (m_param_name[i].Value() != "") |
543 | 585 | { |
r27452 | r27453 | |
568 | 610 | m_pos = 0; |
569 | 611 | } |
570 | 612 | |
571 | | netlist_param_str_t m_param_name[10]; |
572 | | netlist_param_double_t *m_param[10]; |
573 | | stream_sample_t *m_buffer[10]; |
| 613 | netlist_param_str_t m_param_name[MAX_INPUT_CHANNELS]; |
| 614 | netlist_param_double_t *m_param[MAX_INPUT_CHANNELS]; |
| 615 | stream_sample_t *m_buffer[MAX_INPUT_CHANNELS]; |
574 | 616 | netlist_time m_inc; |
575 | 617 | |
576 | 618 | private: |
trunk/src/emu/netlist/devices/nld_7474.c
r27452 | r27453 | |
5 | 5 | |
6 | 6 | #include "nld_7474.h" |
7 | 7 | |
8 | | ATTR_HOT inline void NETLIB_NAME(7474sub)::newstate(const UINT8 state) |
| 8 | ATTR_HOT inline void NETLIB_NAME(7474sub)::newstate(const UINT8 stateQ, const UINT8 stateQQ) |
9 | 9 | { |
10 | 10 | static const netlist_time delay[2] = { NLTIME_FROM_NS(25), NLTIME_FROM_NS(40) }; |
11 | | OUTLOGIC(m_Q, state, delay[state]); |
12 | | OUTLOGIC(m_QQ, !state, delay[!state]); |
| 11 | OUTLOGIC(m_Q, stateQ, delay[stateQ]); |
| 12 | OUTLOGIC(m_QQ, stateQQ, delay[stateQQ]); |
13 | 13 | } |
14 | 14 | |
15 | 15 | NETLIB_UPDATE(7474sub) |
16 | 16 | { |
17 | | //if (!INP_LAST(m_clk) & INP(m_clk)) |
| 17 | //if (INP_LH(m_CLK)) |
18 | 18 | { |
19 | | newstate(m_nextD); |
| 19 | newstate(m_nextD, !m_nextD); |
20 | 20 | m_CLK.inactivate(); |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | NETLIB_UPDATE(7474) |
25 | 25 | { |
| 26 | if (!INPLOGIC(m_PREQ) && !INPLOGIC(m_CLRQ)) |
| 27 | { |
| 28 | sub.newstate(1, 1); |
| 29 | sub.m_CLK.inactivate(); |
| 30 | } |
26 | 31 | if (!INPLOGIC(m_PREQ)) |
27 | 32 | { |
28 | | sub.newstate(1); |
| 33 | sub.newstate(1, 0); |
29 | 34 | sub.m_CLK.inactivate(); |
30 | 35 | m_D.inactivate(); |
31 | 36 | } |
32 | 37 | else if (!INPLOGIC(m_CLRQ)) |
33 | 38 | { |
34 | | sub.newstate(0); |
| 39 | sub.newstate(0, 1); |
35 | 40 | sub.m_CLK.inactivate(); |
36 | 41 | m_D.inactivate(); |
37 | 42 | } |
r27452 | r27453 | |
77 | 82 | m_CLK.set_state(netlist_input_t::STATE_INP_LH); |
78 | 83 | |
79 | 84 | m_nextD = 0; |
| 85 | /* FIXME: required by pong doubles - need a mechanism to set this from netlist */ |
| 86 | m_Q.initial(1); |
| 87 | m_QQ.initial(0); |
80 | 88 | } |
81 | 89 | |
82 | 90 | NETLIB_START(7474_dip) |
r27452 | r27453 | |
109 | 117 | |
110 | 118 | NETLIB_UPDATE(7474_dip) |
111 | 119 | { |
| 120 | m_1.update_dev(); |
| 121 | m_2.update_dev(); |
112 | 122 | } |