trunk/src/emu/netlist/nl_base.h
| r26431 | r26432 | |
| 592 | 592 | }; |
| 593 | 593 | |
| 594 | 594 | // ---------------------------------------------------------------------------------------- |
| 595 | // net_param_t |
| 596 | // ---------------------------------------------------------------------------------------- |
| 597 | |
| 598 | class netlist_param_t : public netlist_owned_object_t |
| 599 | { |
| 600 | public: |
| 601 | |
| 602 | enum param_type_t { |
| 603 | STRING, |
| 604 | DOUBLE, |
| 605 | INTEGER, |
| 606 | LOGIC |
| 607 | }; |
| 608 | |
| 609 | netlist_param_t(const param_type_t atype) |
| 610 | : netlist_owned_object_t(PARAM, ANALOG) |
| 611 | , m_param_type(atype) |
| 612 | { } |
| 613 | |
| 614 | |
| 615 | ATTR_HOT inline const param_type_t param_type() const { return m_param_type; } |
| 616 | |
| 617 | private: |
| 618 | const param_type_t m_param_type; |
| 619 | }; |
| 620 | |
| 621 | class netlist_param_double_t : public netlist_param_t |
| 622 | { |
| 623 | public: |
| 624 | netlist_param_double_t() |
| 625 | : netlist_param_t(DOUBLE) |
| 626 | , m_param(0.0) |
| 627 | { } |
| 628 | |
| 629 | ATTR_HOT inline void setTo(const double param); |
| 630 | ATTR_COLD inline void initial(const double val) { m_param = val; } |
| 631 | ATTR_HOT inline const double Value() const { return m_param; } |
| 632 | |
| 633 | private: |
| 634 | double m_param; |
| 635 | }; |
| 636 | |
| 637 | class netlist_param_int_t : public netlist_param_t |
| 638 | { |
| 639 | public: |
| 640 | netlist_param_int_t() |
| 641 | : netlist_param_t(INTEGER) |
| 642 | , m_param(0) |
| 643 | { } |
| 644 | |
| 645 | ATTR_HOT inline void setTo(const int param); |
| 646 | ATTR_COLD inline void initial(const int val) { m_param = val; } |
| 647 | |
| 648 | ATTR_HOT inline const int Value() const { return m_param; } |
| 649 | |
| 650 | private: |
| 651 | int m_param; |
| 652 | }; |
| 653 | |
| 654 | class netlist_param_logic_t : public netlist_param_int_t |
| 655 | { |
| 656 | public: |
| 657 | netlist_param_logic_t() |
| 658 | : netlist_param_int_t() |
| 659 | { } |
| 660 | }; |
| 661 | |
| 662 | class netlist_param_str_t : public netlist_param_t |
| 663 | { |
| 664 | public: |
| 665 | netlist_param_str_t() |
| 666 | : netlist_param_t(STRING) |
| 667 | , m_param("") |
| 668 | { } |
| 669 | |
| 670 | ATTR_HOT inline void setTo(const pstring ¶m); |
| 671 | ATTR_COLD inline void initial(const pstring &val) { m_param = val; } |
| 672 | |
| 673 | ATTR_HOT inline const pstring &Value() const { return m_param; } |
| 674 | |
| 675 | private: |
| 676 | pstring m_param; |
| 677 | }; |
| 678 | |
| 679 | class netlist_param_multi_t : public netlist_param_str_t |
| 680 | { |
| 681 | public: |
| 682 | netlist_param_multi_t() |
| 683 | : netlist_param_str_t() |
| 684 | { } |
| 685 | |
| 686 | /* these should be cached! */ |
| 687 | ATTR_COLD double dValue(const pstring &entity, const double defval = 0.0) const; |
| 688 | |
| 689 | private: |
| 690 | }; |
| 691 | |
| 692 | // ---------------------------------------------------------------------------------------- |
| 595 | 693 | // net_device_t |
| 596 | 694 | // ---------------------------------------------------------------------------------------- |
| 597 | 695 | |
| r26431 | r26432 | |
| 729 | 827 | private: |
| 730 | 828 | }; |
| 731 | 829 | |
| 732 | | class netlist_param_t : public netlist_object_t |
| 733 | | { |
| 734 | | public: |
| 735 | 830 | |
| 736 | | enum param_type_t { |
| 737 | | STRING, |
| 738 | | DOUBLE, |
| 739 | | INTEGER, |
| 740 | | LOGIC |
| 741 | | }; |
| 742 | | |
| 743 | | netlist_param_t(const param_type_t atype) |
| 744 | | : netlist_object_t(PARAM, ANALOG) |
| 745 | | , m_param_type(atype) |
| 746 | | , m_netdev(NULL) |
| 747 | | { } |
| 748 | | |
| 749 | | |
| 750 | | ATTR_HOT inline const param_type_t param_type() const { return m_param_type; } |
| 751 | | ATTR_HOT inline netlist_core_device_t &netdev() const { return *m_netdev; } |
| 752 | | ATTR_COLD void set_netdev(netlist_core_device_t &dev) { m_netdev = &dev; } |
| 753 | | |
| 754 | | private: |
| 755 | | const param_type_t m_param_type; |
| 756 | | netlist_core_device_t *m_netdev; |
| 757 | | }; |
| 758 | | |
| 759 | | class netlist_param_double_t : public netlist_param_t |
| 760 | | { |
| 761 | | public: |
| 762 | | netlist_param_double_t() |
| 763 | | : netlist_param_t(DOUBLE) |
| 764 | | , m_param(0.0) |
| 765 | | { } |
| 766 | | |
| 767 | | ATTR_HOT inline void setTo(const double param) { m_param = param; netdev().update_param(); } |
| 768 | | ATTR_COLD inline void initial(const double val) { m_param = val; } |
| 769 | | ATTR_HOT inline const double Value() const { return m_param; } |
| 770 | | |
| 771 | | private: |
| 772 | | double m_param; |
| 773 | | }; |
| 774 | | |
| 775 | | class netlist_param_int_t : public netlist_param_t |
| 776 | | { |
| 777 | | public: |
| 778 | | netlist_param_int_t() |
| 779 | | : netlist_param_t(INTEGER) |
| 780 | | , m_param(0) |
| 781 | | { } |
| 782 | | |
| 783 | | ATTR_HOT inline void setTo(const int param) { m_param = param; netdev().update_param(); } |
| 784 | | ATTR_COLD inline void initial(const int val) { m_param = val; } |
| 785 | | |
| 786 | | ATTR_HOT inline const int Value() const { return m_param; } |
| 787 | | |
| 788 | | private: |
| 789 | | int m_param; |
| 790 | | }; |
| 791 | | |
| 792 | | class netlist_param_logic_t : public netlist_param_int_t |
| 793 | | { |
| 794 | | public: |
| 795 | | netlist_param_logic_t() |
| 796 | | : netlist_param_int_t() |
| 797 | | { } |
| 798 | | }; |
| 799 | | |
| 800 | 831 | // ---------------------------------------------------------------------------------------- |
| 801 | 832 | // netlist_base_t |
| 802 | 833 | // ---------------------------------------------------------------------------------------- |
| r26431 | r26432 | |
| 936 | 967 | // Inline implementations |
| 937 | 968 | // ---------------------------------------------------------------------------------------- |
| 938 | 969 | |
| 970 | ATTR_HOT inline void netlist_param_str_t::setTo(const pstring ¶m) |
| 971 | { |
| 972 | m_param = param; |
| 973 | netdev().update_param(); |
| 974 | } |
| 975 | |
| 976 | ATTR_HOT inline void netlist_param_int_t::setTo(const int param) |
| 977 | { |
| 978 | m_param = param; |
| 979 | netdev().update_param(); |
| 980 | } |
| 981 | |
| 982 | ATTR_HOT inline void netlist_param_double_t::setTo(const double param) |
| 983 | { |
| 984 | m_param = param; |
| 985 | netdev().update_param(); |
| 986 | } |
| 987 | |
| 988 | |
| 939 | 989 | ATTR_HOT inline void netlist_input_t::inactivate() |
| 940 | 990 | { |
| 941 | 991 | if (!is_state(STATE_INP_PASSIVE)) |
trunk/src/emu/netlist/pstring.h
| r26431 | r26432 | |
| 27 | 27 | ~pstring(); |
| 28 | 28 | |
| 29 | 29 | // construction with copy |
| 30 | | pstring(const char *string) {init(); if (string != NULL) pcopy(string); } |
| 30 | pstring(const char *string) {init(); if (string != NULL && *string != 0) pcopy(string); } |
| 31 | 31 | pstring(const pstring &string) {init(); pcopy(string); } |
| 32 | 32 | |
| 33 | 33 | // assignment operators |
| r26431 | r26432 | |
| 62 | 62 | inline const int len() const { return m_ptr->len(); } |
| 63 | 63 | |
| 64 | 64 | inline bool equals(const pstring &string) { return (pcmp(string.cstr(), m_ptr->str()) == 0); } |
| 65 | inline bool iequals(const pstring &string) { return (pcmpi(string.cstr(), m_ptr->str()) == 0); } |
| 66 | |
| 65 | 67 | int cmp(pstring &string) { return pcmp(string.cstr()); } |
| 68 | int cmpi(pstring &string) { return pcmpi(cstr(), string.cstr()); } |
| 66 | 69 | |
| 67 | 70 | int find(const char *search, int start = 0) const |
| 68 | 71 | { |
| r26431 | r26432 | |
| 123 | 126 | return strncmp(left, right, count); |
| 124 | 127 | } |
| 125 | 128 | |
| 129 | int pcmpi(const char *lhs, const char *rhs, int count = -1) const; |
| 130 | |
| 126 | 131 | void pcopy(const char *from, int size); |
| 127 | 132 | |
| 128 | 133 | inline void pcopy(const char *from) |
trunk/src/emu/netlist/devices/nld_system.h
| r26431 | r26432 | |
| 46 | 46 | NETDEV_PARAMI(_name, C, _C) |
| 47 | 47 | |
| 48 | 48 | /* Generic Diode */ |
| 49 | | #define NETDEV_D(_name) \ |
| 50 | | NET_REGISTER_DEV(D, _name) |
| 49 | #define NETDEV_D(_name, _model) \ |
| 50 | NET_REGISTER_DEV(D, _name) \ |
| 51 | NETDEV_PARAMI(_name, model, _model) |
| 51 | 52 | |
| 53 | #define NETDEV_1N914(_name) NETDEV_D(_name, "Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon") |
| 54 | |
| 52 | 55 | // .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon) |
| 53 | 56 | |
| 54 | 57 | // ---------------------------------------------------------------------------------------- |
| r26431 | r26432 | |
| 266 | 269 | { |
| 267 | 270 | } |
| 268 | 271 | |
| 269 | | netlist_param_double_t m_Vt; |
| 270 | | netlist_param_double_t m_Is; |
| 271 | | netlist_param_double_t m_Rmin; |
| 272 | netlist_param_multi_t m_model; |
| 272 | 273 | |
| 274 | double m_Vt; |
| 275 | double m_Is; |
| 276 | double m_n; |
| 277 | |
| 273 | 278 | double m_VtInv; |
| 274 | 279 | double m_Vcrit; |
| 275 | 280 | double m_Vd; |
| r26431 | r26432 | |
| 279 | 284 | { |
| 280 | 285 | register_terminal("A", m_P); |
| 281 | 286 | register_terminal("K", m_N); |
| 287 | register_param("model", m_model, ""); |
| 282 | 288 | |
| 283 | | register_param("Vt", m_Vt, 0.0258); |
| 284 | | register_param("Is", m_Is, 1e-15); |
| 285 | | register_param("Rmin", m_Rmin, 1.4); |
| 286 | 289 | m_Vd = 0.7; |
| 287 | 290 | } |
| 288 | 291 | |
| 289 | 292 | virtual void update_param() |
| 290 | 293 | { |
| 291 | | m_Vcrit = m_Vt.Value() * log(m_Vt.Value() / m_Is.Value() / sqrt(2.0)); |
| 292 | | m_VtInv = 1.0 / m_Vt.Value(); |
| 294 | m_Is = m_model.dValue("Is", 1e-15); |
| 295 | m_n = m_model.dValue("N", 1); |
| 296 | |
| 297 | m_Vt = 0.0258 * m_n; |
| 298 | |
| 299 | m_Vcrit = m_Vt * log(m_Vt / m_Is / sqrt(2.0)); |
| 300 | m_VtInv = 1.0 / m_Vt; |
| 293 | 301 | NL_VERBOSE_OUT(("VCutoff: %f\n", m_Vcrit)); |
| 294 | 302 | } |
| 295 | 303 | |
| r26431 | r26432 | |
| 298 | 306 | const double nVd = m_P.net().Q_Analog()- m_N.net().Q_Analog(); |
| 299 | 307 | |
| 300 | 308 | //FIXME: Optimize cutoff case |
| 301 | | m_Vd = (nVd > m_Vcrit) ? m_Vd + log((nVd - m_Vd) * m_VtInv + 1.0) * m_Vt.Value() : nVd; |
| 309 | m_Vd = (nVd > m_Vcrit) ? m_Vd + log((nVd - m_Vd) * m_VtInv + 1.0) * m_Vt : nVd; |
| 302 | 310 | |
| 303 | 311 | const double eVDVt = exp(m_Vd * m_VtInv); |
| 304 | | const double Id = m_Is.Value() * (eVDVt - 1.0); |
| 312 | const double Id = m_Is * (eVDVt - 1.0); |
| 305 | 313 | |
| 306 | | m_g = m_Is.Value() * m_VtInv * eVDVt; |
| 314 | m_g = m_Is * m_VtInv * eVDVt; |
| 307 | 315 | |
| 308 | 316 | m_I = (Id - m_Vd * m_g); |
| 309 | 317 | //printf("Vd: %f %f %f %f\n", m_Vd, m_g, Id, m_I); |
trunk/src/emu/netlist/nl_base.c
| r26431 | r26432 | |
| 329 | 329 | template <class C, class T> |
| 330 | 330 | ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, C ¶m, const T initialVal) |
| 331 | 331 | { |
| 332 | | param.set_netdev(dev); |
| 332 | param.init_object(dev, sname); |
| 333 | 333 | param.initial(initialVal); |
| 334 | 334 | m_setup->register_object(*this, *this, sname, param, netlist_terminal_t::STATE_NONEX); |
| 335 | 335 | } |
| r26431 | r26432 | |
| 337 | 337 | template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_double_t ¶m, const double initialVal); |
| 338 | 338 | template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_int_t ¶m, const int initialVal); |
| 339 | 339 | template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_logic_t ¶m, const int initialVal); |
| 340 | template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_str_t ¶m, const char * initialVal); |
| 341 | template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_str_t ¶m, const pstring &initialVal); |
| 342 | template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_multi_t ¶m, const char * initialVal); |
| 340 | 343 | |
| 341 | 344 | |
| 342 | 345 | // ---------------------------------------------------------------------------------------- |
| r26431 | r26432 | |
| 532 | 535 | m_high_V = high; |
| 533 | 536 | } |
| 534 | 537 | |
| 538 | // ---------------------------------------------------------------------------------------- |
| 539 | // netlist_param_t & friends |
| 540 | // ---------------------------------------------------------------------------------------- |
| 535 | 541 | |
| 542 | ATTR_COLD double netlist_param_multi_t::dValue(const pstring &entity, const double defval) const |
| 543 | { |
| 544 | pstring tmp = this->Value(); |
| 545 | // .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon) |
| 546 | int p = tmp.find(entity); |
| 547 | if (p>=0) |
| 548 | { |
| 549 | int pblank = tmp.find(" ", p); |
| 550 | if (pblank < 0) pblank = tmp.len() + 1; |
| 551 | tmp = tmp.substr(p, pblank - p); |
| 552 | int pequal = tmp.find("=", 0); |
| 553 | if (pequal < 0) |
| 554 | fatalerror("parameter %s misformat in model %s temp %s\n", entity.cstr(), Value().cstr(), tmp.cstr()); |
| 555 | tmp = tmp.substr(pequal+1); |
| 556 | double factor = 1.0; |
| 557 | switch (*(tmp.right(1).cstr())) |
| 558 | { |
| 559 | case 'm': factor = 1e-3; break; |
| 560 | case 'u': factor = 1e-6; break; |
| 561 | case 'n': factor = 1e-9; break; |
| 562 | case 'p': factor = 1e-12; break; |
| 563 | case 'f': factor = 1e-15; break; |
| 564 | case 'a': factor = 1e-18; break; |
| 565 | |
| 566 | } |
| 567 | if (factor != 1.0) |
| 568 | tmp = tmp.left(tmp.len() - 1); |
| 569 | return atof(tmp.cstr()) * factor; |
| 570 | } |
| 571 | else |
| 572 | return defval; |
| 573 | } |
| 574 | |
| 575 | |
| 536 | 576 | // ---------------------------------------------------------------------------------------- |
| 537 | 577 | // mainclock |
| 538 | 578 | // ---------------------------------------------------------------------------------------- |
trunk/src/mame/drivers/pong.c
| r26431 | r26432 | |
| 465 | 465 | NETDEV_PARAM(videomix.R2, RES_K(1.2)) |
| 466 | 466 | NETDEV_PARAM(videomix.R3, RES_K(22)) |
| 467 | 467 | |
| 468 | | NETDEV_SOLVER(Solver) |
| 469 | | NETDEV_ANALOG_CONST(V5, 5) |
| 470 | | NETDEV_ANALOG_CONST(V1, 1) |
| 471 | | NETDEV_ANALOG_CONST(V0, 0) |
| 472 | 468 | |
| 473 | 469 | #if 0 |
| 474 | 470 | NETDEV_R(R1, 10) |
| r26431 | r26432 | |
| 507 | 503 | tt(28) |
| 508 | 504 | tt(29) |
| 509 | 505 | */ |
| 510 | | #if 0 |
| 506 | #if 1 |
| 507 | NETDEV_SOLVER(Solver) |
| 508 | NETDEV_ANALOG_CONST(V5, 5) |
| 509 | NETDEV_ANALOG_CONST(V1, 1) |
| 510 | NETDEV_ANALOG_CONST(V0, 0) |
| 511 | |
| 511 | 512 | NETDEV_R(R5, 1000) |
| 512 | | NETDEV_D(D1) |
| 513 | NETDEV_1N914(D1) |
| 513 | 514 | NET_C(V5, R5.1) |
| 514 | 515 | NET_C(R5.2, D1.A) |
| 515 | 516 | NET_C(D1.K, V0) |
| 516 | 517 | //NETDEV_LOG(log1, D1.A) |
| 517 | 518 | #endif |
| 518 | 519 | |
| 519 | | #if 1 |
| 520 | #if 0 |
| 521 | NETDEV_SOLVER(Solver) |
| 522 | NETDEV_ANALOG_CONST(V5, 5) |
| 523 | NETDEV_ANALOG_CONST(V1, 1) |
| 524 | NETDEV_ANALOG_CONST(V0, 0) |
| 520 | 525 | // astable NAND Multivibrator |
| 521 | 526 | NETDEV_R(R1, 1000) |
| 522 | 527 | NETDEV_C(C1, 1e-6) |