trunk/src/emu/netlist/nl_base.h
| r31069 | r31070 | |
| 20 | 20 | * | rail net | |
| 21 | 21 | * +-------------------------------------------+ |
| 22 | 22 | * |
| 23 | | * A rail net is a net which is driven by exactly one output with an (idealized) internal resistance |
| 24 | | * of zero. Ideally, it can deliver infinite current. |
| 23 | * A rail net is a net which is driven by exactly one output with an |
| 24 | * (idealized) internal resistance of zero. |
| 25 | * Ideally, it can deliver infinite current. |
| 25 | 26 | * |
| 26 | 27 | * A infinite resistance input does not source or sink current. |
| 27 | 28 | * |
| 28 | 29 | * Terminals source or sink finite (but never zero) current. |
| 29 | 30 | * |
| 30 | | * The system differentiates between analog and logic input and outputs and analog terminals. |
| 31 | | * Analog and logic devices can not be connected to the same net. Instead, proxy devices |
| 32 | | * are inserted automatically: |
| 31 | * The system differentiates between analog and logic input and outputs and |
| 32 | * analog terminals. Analog and logic devices can not be connected to the |
| 33 | * same net. Instead, proxy devices are inserted automatically: |
| 33 | 34 | * |
| 34 | 35 | * +---+ +---+ |
| 35 | 36 | * | | | | |
| r31069 | r31070 | |
| 57 | 58 | * This works both analog to logic as well as logic to analog. |
| 58 | 59 | * |
| 59 | 60 | * The above is an advanced implementation of the existing discrete |
| 60 | | * subsystem in MAME. Instead of relying on a fixed time-step, analog devices could |
| 61 | | * either connect to fixed time-step clock or use an internal clock to update them. |
| 62 | | * This would however introduce macro devices for RC, diodes and transistors again. |
| 61 | * subsystem in MAME. Instead of relying on a fixed time-step, analog devices |
| 62 | * could either connect to fixed time-step clock or use an internal clock |
| 63 | * to update them. This would however introduce macro devices for RC, diodes |
| 64 | * and transistors again. |
| 63 | 65 | * |
| 64 | | * ==================================================================================== |
| 66 | * ============================================================================ |
| 65 | 67 | * |
| 66 | | * Instead, the following approach in case of a pure terminal/input network is taken: |
| 68 | * Instead, the following approach in case of a pure terminal/input network |
| 69 | * is taken: |
| 67 | 70 | * |
| 68 | 71 | * +---+ +---+ +---+ +---+ +---+ |
| 69 | 72 | * | | | | | | | | | | |
| r31069 | r31070 | |
| 96 | 99 | * +-----T-----+ |
| 97 | 100 | * (l) |
| 98 | 101 | * |
| 99 | | * This is a resistance in series to a voltage source and paralleled by a current source. |
| 100 | | * This is suitable to model voltage sources, current sources, resistors, capacitors, |
| 101 | | * inductances and diodes. |
| 102 | * This is a resistance in series to a voltage source and paralleled by a |
| 103 | * current source. This is suitable to model voltage sources, current sources, |
| 104 | * resistors, capacitors, inductances and diodes. |
| 102 | 105 | * |
| 103 | 106 | * I(n,l) = - I(n,k) = ( V(k) - V - V(l) ) * (1/R(n)) + I(n) |
| 104 | 107 | * |
| r31069 | r31070 | |
| 120 | 123 | * |
| 121 | 124 | * (G - D) * V = I |
| 122 | 125 | * |
| 123 | | * with G being the conductance matrix, D a diagonal matrix with the total conductance |
| 124 | | * on the diagonal elements, V the net voltage vector and I the current vector. |
| 126 | * with G being the conductance matrix, D a diagonal matrix with the total |
| 127 | * conductance on the diagonal elements, V the net voltage vector and I the |
| 128 | * current vector. |
| 125 | 129 | * |
| 126 | 130 | * By using solely two terminal devices, we can simplify the whole calculation |
| 127 | 131 | * significantly. A BJT now is a four terminal device with two terminals being |
| r31069 | r31070 | |
| 141 | 145 | * b) Voltage source |
| 142 | 146 | * c) Current source/sink |
| 143 | 147 | * |
| 144 | | * Going forward, the approach can be extended e.g. to use a linear equation solver |
| 148 | * Going forward, the approach can be extended e.g. to use a linear |
| 149 | * equation solver. |
| 145 | 150 | * |
| 146 | 151 | * The formal representation of the circuit will stay the same, thus scales. |
| 147 | 152 | * |
| r31069 | r31070 | |
| 191 | 196 | #define NETLIB_UPDATE_TERMINALS() ATTR_HOT ATTR_ALIGN inline void update_terminals(void) |
| 192 | 197 | #define NETLIB_UPDATEI() ATTR_HOT ATTR_ALIGN inline void update(void) |
| 193 | 198 | |
| 194 | | #define NETLIB_DEVICE_BASE(_name, _pclass, _extra, _priv) \ |
| 195 | | class _name : public _pclass \ |
| 196 | | { \ |
| 197 | | public: \ |
| 198 | | _name() \ |
| 199 | | : _pclass() { } \ |
| 200 | | protected: \ |
| 201 | | _extra \ |
| 202 | | ATTR_HOT void update(); \ |
| 203 | | ATTR_HOT void start(); \ |
| 204 | | ATTR_HOT void reset(); \ |
| 205 | | _priv \ |
| 199 | #define NETLIB_DEVICE_BASE(_name, _pclass, _extra, _priv) \ |
| 200 | class _name : public _pclass \ |
| 201 | { \ |
| 202 | public: \ |
| 203 | _name() \ |
| 204 | : _pclass() { } \ |
| 205 | protected: \ |
| 206 | _extra \ |
| 207 | ATTR_HOT void update(); \ |
| 208 | ATTR_HOT void start(); \ |
| 209 | ATTR_HOT void reset(); \ |
| 210 | _priv \ |
| 206 | 211 | } |
| 207 | 212 | |
| 208 | | #define NETLIB_DEVICE_DERIVED(_name, _pclass, _priv) \ |
| 213 | #define NETLIB_DEVICE_DERIVED(_name, _pclass, _priv) \ |
| 209 | 214 | NETLIB_DEVICE_BASE(NETLIB_NAME(_name), NETLIB_NAME(_pclass), , _priv) |
| 210 | 215 | |
| 211 | | #define NETLIB_DEVICE(_name, _priv) \ |
| 216 | #define NETLIB_DEVICE(_name, _priv) \ |
| 212 | 217 | NETLIB_DEVICE_BASE(NETLIB_NAME(_name), netlist_device_t, , _priv) |
| 213 | 218 | |
| 214 | | #define NETLIB_SUBDEVICE(_name, _priv) \ |
| 215 | | class NETLIB_NAME(_name) : public netlist_device_t \ |
| 216 | | { \ |
| 217 | | public: \ |
| 218 | | NETLIB_NAME(_name) () \ |
| 219 | | : netlist_device_t() \ |
| 220 | | { } \ |
| 221 | | /*protected:*/ \ |
| 222 | | ATTR_HOT void update(); \ |
| 223 | | ATTR_HOT void start(); \ |
| 224 | | ATTR_HOT void reset(); \ |
| 225 | | public: \ |
| 226 | | _priv \ |
| 219 | #define NETLIB_SUBDEVICE(_name, _priv) \ |
| 220 | class NETLIB_NAME(_name) : public netlist_device_t \ |
| 221 | { \ |
| 222 | public: \ |
| 223 | NETLIB_NAME(_name) () \ |
| 224 | : netlist_device_t() \ |
| 225 | { } \ |
| 226 | /*protected:*/ \ |
| 227 | ATTR_HOT void update(); \ |
| 228 | ATTR_HOT void start(); \ |
| 229 | ATTR_HOT void reset(); \ |
| 230 | public: \ |
| 231 | _priv \ |
| 227 | 232 | } |
| 228 | 233 | |
| 229 | | #define NETLIB_DEVICE_WITH_PARAMS(_name, _priv) \ |
| 230 | | NETLIB_DEVICE_BASE(NETLIB_NAME(_name), netlist_device_t, \ |
| 231 | | ATTR_HOT void update_param(); \ |
| 234 | #define NETLIB_DEVICE_WITH_PARAMS(_name, _priv) \ |
| 235 | NETLIB_DEVICE_BASE(NETLIB_NAME(_name), netlist_device_t, \ |
| 236 | ATTR_HOT void update_param(); \ |
| 232 | 237 | , _priv) |
| 233 | 238 | |
| 234 | | #define NETLIB_DEVICE_WITH_PARAMS_DERIVED(_name, _pclass, _priv) \ |
| 235 | | NETLIB_DEVICE_BASE(NETLIB_NAME(_name), NETLIB_NAME(_pclass), \ |
| 236 | | ATTR_HOT void update_param(); \ |
| 239 | #define NETLIB_DEVICE_WITH_PARAMS_DERIVED(_name, _pclass, _priv) \ |
| 240 | NETLIB_DEVICE_BASE(NETLIB_NAME(_name), NETLIB_NAME(_pclass), \ |
| 241 | ATTR_HOT void update_param(); \ |
| 237 | 242 | , _priv) |
| 238 | 243 | |
| 239 | | // ---------------------------------------------------------------------------------------- |
| 244 | #define NETLIB_LOGIC_FAMILY(_fam) \ |
| 245 | ATTR_COLD virtual const netlist_logic_family_desc_t *logic_family() \ |
| 246 | { \ |
| 247 | return &netlist_family_ ## _fam; \ |
| 248 | } |
| 249 | |
| 250 | |
| 251 | |
| 252 | // ----------------------------------------------------------------------------- |
| 240 | 253 | // forward definitions |
| 241 | | // ---------------------------------------------------------------------------------------- |
| 254 | // ----------------------------------------------------------------------------- |
| 242 | 255 | |
| 243 | 256 | class netlist_net_t; |
| 244 | 257 | class netlist_analog_net_t; |
| r31069 | r31070 | |
| 253 | 266 | class NETLIB_NAME(mainclock); |
| 254 | 267 | class NETLIB_NAME(base_d_to_a_proxy); |
| 255 | 268 | |
| 256 | | // ---------------------------------------------------------------------------------------- |
| 269 | // ----------------------------------------------------------------------------- |
| 257 | 270 | // netlist_output_family_t |
| 258 | | // ---------------------------------------------------------------------------------------- |
| 271 | // ----------------------------------------------------------------------------- |
| 259 | 272 | |
| 260 | 273 | struct netlist_logic_family_desc_t |
| 261 | 274 | { |
| r31069 | r31070 | |
| 274 | 287 | * Only devices of type GENERIC should have a family description entry |
| 275 | 288 | */ |
| 276 | 289 | |
| 277 | | extern netlist_logic_family_desc_t netlist_family_ttl; |
| 290 | extern netlist_logic_family_desc_t netlist_family_TTL; |
| 291 | extern netlist_logic_family_desc_t netlist_family_CD4000; |
| 278 | 292 | |
| 279 | 293 | |
| 280 | | // ---------------------------------------------------------------------------------------- |
| 294 | // ----------------------------------------------------------------------------- |
| 281 | 295 | // netlist_state_t |
| 282 | | // ---------------------------------------------------------------------------------------- |
| 296 | // ----------------------------------------------------------------------------- |
| 283 | 297 | |
| 284 | 298 | template< typename X> |
| 285 | 299 | class netlist_state_t { |
| r31069 | r31070 | |
| 294 | 308 | X m_x; |
| 295 | 309 | }; |
| 296 | 310 | |
| 297 | | // ---------------------------------------------------------------------------------------- |
| 311 | // ----------------------------------------------------------------------------- |
| 298 | 312 | // netlist_object_t |
| 299 | | // ---------------------------------------------------------------------------------------- |
| 313 | // ----------------------------------------------------------------------------- |
| 300 | 314 | |
| 301 | 315 | class netlist_object_t |
| 302 | 316 | { |
| r31069 | r31070 | |
| 339 | 353 | ATTR_COLD const pstring &name() const; |
| 340 | 354 | |
| 341 | 355 | PSTATE_INTERFACE_DECL() |
| 342 | | template<typename C> ATTR_COLD void save(netlist_state_t<C> &state, const pstring &stname) |
| 356 | template<typename C> ATTR_COLD void save(netlist_state_t<C> &state, |
| 357 | const pstring &stname) |
| 343 | 358 | { |
| 344 | 359 | save(state.ref(), stname); |
| 345 | 360 | } |
| r31069 | r31070 | |
| 371 | 386 | netlist_base_t * RESTRICT m_netlist; |
| 372 | 387 | }; |
| 373 | 388 | |
| 374 | | // ---------------------------------------------------------------------------------------- |
| 389 | // ----------------------------------------------------------------------------- |
| 375 | 390 | // netlist_owned_object_t |
| 376 | | // ---------------------------------------------------------------------------------------- |
| 391 | // ----------------------------------------------------------------------------- |
| 377 | 392 | |
| 378 | 393 | class netlist_owned_object_t : public netlist_object_t |
| 379 | 394 | { |
| r31069 | r31070 | |
| 388 | 403 | netlist_core_device_t * RESTRICT m_netdev; |
| 389 | 404 | }; |
| 390 | 405 | |
| 391 | | // ---------------------------------------------------------------------------------------- |
| 406 | // ----------------------------------------------------------------------------- |
| 392 | 407 | // netlist_core_terminal_t |
| 393 | | // ---------------------------------------------------------------------------------------- |
| 408 | // ----------------------------------------------------------------------------- |
| 394 | 409 | |
| 395 | 410 | class netlist_core_terminal_t : public netlist_owned_object_t, public plinkedlist_element_t<netlist_core_terminal_t> |
| 396 | 411 | { |
| r31069 | r31070 | |
| 430 | 445 | m_state = astate; |
| 431 | 446 | } |
| 432 | 447 | |
| 433 | | const netlist_logic_family_desc_t *m_family_desc; |
| 448 | const netlist_logic_family_desc_t *m_logic_family; |
| 434 | 449 | |
| 435 | 450 | protected: |
| 436 | 451 | ATTR_COLD virtual void save_register() |
| r31069 | r31070 | |
| 499 | 514 | }; |
| 500 | 515 | |
| 501 | 516 | |
| 502 | | // ---------------------------------------------------------------------------------------- |
| 517 | // ----------------------------------------------------------------------------- |
| 503 | 518 | // netlist_input_t |
| 504 | | // ---------------------------------------------------------------------------------------- |
| 519 | // ----------------------------------------------------------------------------- |
| 505 | 520 | |
| 506 | 521 | class netlist_input_t : public netlist_core_terminal_t |
| 507 | 522 | { |
| r31069 | r31070 | |
| 527 | 542 | private: |
| 528 | 543 | }; |
| 529 | 544 | |
| 530 | | // ---------------------------------------------------------------------------------------- |
| 545 | // ----------------------------------------------------------------------------- |
| 531 | 546 | // netlist_logic_input_t |
| 532 | | // ---------------------------------------------------------------------------------------- |
| 547 | // ----------------------------------------------------------------------------- |
| 533 | 548 | |
| 534 | 549 | class netlist_logic_input_t : public netlist_input_t |
| 535 | 550 | { |
| r31069 | r31070 | |
| 547 | 562 | |
| 548 | 563 | }; |
| 549 | 564 | |
| 550 | | // ---------------------------------------------------------------------------------------- |
| 565 | // ----------------------------------------------------------------------------- |
| 551 | 566 | // netlist_ttl_input_t |
| 552 | | // ---------------------------------------------------------------------------------------- |
| 567 | // ----------------------------------------------------------------------------- |
| 553 | 568 | |
| 554 | 569 | class netlist_ttl_input_t : public netlist_logic_input_t |
| 555 | 570 | { |
| r31069 | r31070 | |
| 558 | 573 | : netlist_logic_input_t() { } |
| 559 | 574 | }; |
| 560 | 575 | |
| 561 | | // ---------------------------------------------------------------------------------------- |
| 576 | // ----------------------------------------------------------------------------- |
| 562 | 577 | // netlist_analog_input_t |
| 563 | | // ---------------------------------------------------------------------------------------- |
| 578 | // ----------------------------------------------------------------------------- |
| 564 | 579 | |
| 565 | 580 | class netlist_analog_input_t : public netlist_input_t |
| 566 | 581 | { |
| r31069 | r31070 | |
| 573 | 588 | |
| 574 | 589 | //#define INPVAL(_x) (_x).Q() |
| 575 | 590 | |
| 576 | | // ---------------------------------------------------------------------------------------- |
| 591 | // ----------------------------------------------------------------------------- |
| 577 | 592 | // net_net_t |
| 578 | | // ---------------------------------------------------------------------------------------- |
| 593 | // ----------------------------------------------------------------------------- |
| 579 | 594 | |
| 580 | 595 | class netlist_net_t : public netlist_object_t |
| 581 | 596 | { |
| r31069 | r31070 | |
| 753 | 768 | netlist_matrix_solver_t *m_solver; |
| 754 | 769 | }; |
| 755 | 770 | |
| 756 | | // ---------------------------------------------------------------------------------------- |
| 771 | // ----------------------------------------------------------------------------- |
| 757 | 772 | // net_output_t |
| 758 | | // ---------------------------------------------------------------------------------------- |
| 773 | // ----------------------------------------------------------------------------- |
| 759 | 774 | |
| 760 | 775 | class netlist_output_t : public netlist_core_terminal_t |
| 761 | 776 | { |
| r31069 | r31070 | |
| 823 | 838 | netlist_analog_net_t m_my_net; |
| 824 | 839 | }; |
| 825 | 840 | |
| 826 | | // ---------------------------------------------------------------------------------------- |
| 841 | // ----------------------------------------------------------------------------- |
| 827 | 842 | // net_param_t |
| 828 | | // ---------------------------------------------------------------------------------------- |
| 843 | // ----------------------------------------------------------------------------- |
| 829 | 844 | |
| 830 | 845 | class netlist_param_t : public netlist_owned_object_t |
| 831 | 846 | { |
| r31069 | r31070 | |
| 935 | 950 | pstring m_param; |
| 936 | 951 | }; |
| 937 | 952 | |
| 938 | | // ---------------------------------------------------------------------------------------- |
| 953 | // ----------------------------------------------------------------------------- |
| 939 | 954 | // net_device_t |
| 940 | | // ---------------------------------------------------------------------------------------- |
| 955 | // ----------------------------------------------------------------------------- |
| 941 | 956 | |
| 942 | 957 | class netlist_core_device_t : public netlist_object_t |
| 943 | 958 | { |
| r31069 | r31070 | |
| 946 | 961 | |
| 947 | 962 | typedef plinearlist_t<netlist_core_device_t *> list_t; |
| 948 | 963 | |
| 949 | | ATTR_COLD netlist_core_device_t(const family_t afamily, const netlist_logic_family_desc_t *family_desc); |
| 964 | ATTR_COLD netlist_core_device_t(const family_t afamily); |
| 950 | 965 | |
| 951 | 966 | ATTR_COLD virtual ~netlist_core_device_t(); |
| 952 | 967 | |
| r31069 | r31070 | |
| 1007 | 1022 | net_update_delegate static_update; |
| 1008 | 1023 | #endif |
| 1009 | 1024 | |
| 1010 | | const netlist_logic_family_desc_t *m_family_desc; |
| 1011 | | |
| 1012 | 1025 | protected: |
| 1013 | 1026 | |
| 1014 | 1027 | ATTR_HOT virtual void update() { } |
| 1015 | 1028 | ATTR_COLD virtual void start() { } |
| 1029 | ATTR_COLD virtual const netlist_logic_family_desc_t *logic_family() |
| 1030 | { |
| 1031 | return &netlist_family_TTL; |
| 1032 | } |
| 1016 | 1033 | |
| 1017 | 1034 | private: |
| 1018 | 1035 | }; |
| r31069 | r31070 | |
| 1055 | 1072 | }; |
| 1056 | 1073 | |
| 1057 | 1074 | |
| 1058 | | // ---------------------------------------------------------------------------------------- |
| 1075 | // ----------------------------------------------------------------------------- |
| 1059 | 1076 | // netlist_queue_t |
| 1060 | | // ---------------------------------------------------------------------------------------- |
| 1077 | // ----------------------------------------------------------------------------- |
| 1061 | 1078 | |
| 1062 | 1079 | class netlist_queue_t : public netlist_timed_queue<netlist_net_t *, netlist_time, 512>, |
| 1063 | 1080 | public netlist_object_t, |
| r31069 | r31070 | |
| 1080 | 1097 | char m_name[512][64]; |
| 1081 | 1098 | }; |
| 1082 | 1099 | |
| 1083 | | // ---------------------------------------------------------------------------------------- |
| 1100 | // ----------------------------------------------------------------------------- |
| 1084 | 1101 | // netlist_base_t |
| 1085 | | // ---------------------------------------------------------------------------------------- |
| 1102 | // ----------------------------------------------------------------------------- |
| 1086 | 1103 | |
| 1087 | 1104 | |
| 1088 | 1105 | class netlist_base_t : public netlist_object_t, public pstate_manager_t |
| r31069 | r31070 | |
| 1210 | 1227 | netlist_setup_t *m_setup; |
| 1211 | 1228 | }; |
| 1212 | 1229 | |
| 1213 | | // ---------------------------------------------------------------------------------------- |
| 1230 | // ----------------------------------------------------------------------------- |
| 1214 | 1231 | // Inline implementations |
| 1215 | | // ---------------------------------------------------------------------------------------- |
| 1232 | // ----------------------------------------------------------------------------- |
| 1216 | 1233 | |
| 1217 | 1234 | PSTATE_INTERFACE(netlist_object_t, m_netlist, name()) |
| 1218 | 1235 | |
| r31069 | r31070 | |
| 1351 | 1368 | } |
| 1352 | 1369 | |
| 1353 | 1370 | |
| 1354 | | // ---------------------------------------------------------------------------------------- |
| 1371 | // ----------------------------------------------------------------------------- |
| 1355 | 1372 | // net_dev class factory |
| 1356 | | // ---------------------------------------------------------------------------------------- |
| 1373 | // ----------------------------------------------------------------------------- |
| 1357 | 1374 | |
| 1358 | 1375 | class net_device_t_base_factory |
| 1359 | 1376 | { |