~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/emu/sound/disc_dev.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#define DEFAULT_555_BLEED_R     RES_M(10)
28
28
 
29
 
struct dsd_555_astbl_context
30
 
{
31
 
        int             use_ctrlv;
32
 
        int             output_type;
33
 
        int             output_is_ac;
34
 
        double  ac_shift;                       /* DC shift needed to make waveform ac */
35
 
        int             flip_flop;                      /* 555 flip/flop output state */
36
 
        double  cap_voltage;            /* voltage on cap */
37
 
        double  threshold;
38
 
        double  trigger;
39
 
        double  v_out_high;                     /* Logic 1 voltage level */
40
 
        double  v_charge;
41
 
        double *v_charge_node;          /* point to output of node */
42
 
        int             has_rc_nodes;
43
 
        double  exp_bleed;
44
 
        double  exp_charge;
45
 
        double  exp_discharge;
46
 
        double  t_rc_bleed;
47
 
        double  t_rc_charge;
48
 
        double  t_rc_discharge;
49
 
        double  last_r1;
50
 
        double  last_r2;
51
 
        double  last_c;
52
 
};
53
 
 
54
 
struct dsd_555_mstbl_context
55
 
{
56
 
        int             trig_is_logic;
57
 
        int             trig_discharges_cap;
58
 
        int             output_type;
59
 
        double  ac_shift;                               /* DC shift needed to make waveform ac */
60
 
        int             flip_flop;                              /* 555 flip/flop output state */
61
 
        int             has_rc_nodes;
62
 
        double  exp_charge;
63
 
        double  cap_voltage;                    /* voltage on cap */
64
 
        double  threshold;
65
 
        double  trigger;
66
 
        double  v_out_high;                             /* Logic 1 voltage level */
67
 
        double  v_charge;
68
 
};
69
 
 
70
 
struct dsd_555_cc_context
71
 
{
72
 
        unsigned int    type;                   /* type of 555cc circuit */
73
 
        int                             output_type;
74
 
        int                             output_is_ac;
75
 
        double                  ac_shift;               /* DC shift needed to make waveform ac */
76
 
        int                             flip_flop;              /* 555 flip/flop output state */
77
 
        double                  cap_voltage;    /* voltage on cap */
78
 
        double                  threshold;
79
 
        double                  trigger;
80
 
        double                  v_out_high;             /* Logic 1 voltage level */
81
 
        double                  v_cc_source;
82
 
        int                             has_rc_nodes;
83
 
        double                  exp_bleed;
84
 
        double                  exp_charge;
85
 
        double                  exp_discharge;
86
 
        double                  exp_discharge_01;
87
 
        double                  exp_discharge_no_i;
88
 
        double                  t_rc_charge;
89
 
        double                  t_rc_discharge;
90
 
        double                  t_rc_discharge_01;
91
 
        double                  t_rc_discharge_no_i;
92
 
};
93
 
 
94
 
struct dsd_555_vco1_context
95
 
{
96
 
        int             ctrlv_is_node;
97
 
        int             output_type;
98
 
        int             output_is_ac;
99
 
        double  ac_shift;                       /* DC shift needed to make waveform ac */
100
 
        int             flip_flop;                      /* flip/flop output state */
101
 
        double  v_out_high;                     /* 555 high voltage */
102
 
        double  threshold;                      /* falling threshold */
103
 
        double  trigger;                        /* rising threshold */
104
 
        double  i_charge;                       /* charge current */
105
 
        double  i_discharge;            /* discharge current */
106
 
        double  cap_voltage;            /* current capacitor voltage */
107
 
};
108
 
 
109
 
struct dsd_566_context
110
 
{
111
 
        unsigned int state[2];                  /* keeps track of excess flip_flop changes during the current step */
112
 
        int                     flip_flop;                      /* 566 flip/flop output state */
113
 
        double          cap_voltage;            /* voltage on cap */
114
 
        double          v_sqr_low;                      /* voltage for a squarewave at low */
115
 
        double          v_sqr_high;                     /* voltage for a squarewave at high */
116
 
        double          v_sqr_diff;
117
 
        double          threshold_low;          /* falling threshold */
118
 
        double          threshold_high;         /* rising threshold */
119
 
        double          ac_shift;                       /* used to fake AC */
120
 
        double          v_osc_stable;
121
 
        double          v_osc_stop;
122
 
        int                     fake_ac;
123
 
        int                     out_type;
124
 
};
125
 
 
126
 
struct dsd_ls624_context
127
 
{
128
 
        double  exponent;
129
 
        double  t_used;
130
 
        double  v_cap_freq_in;
131
 
        double  v_freq_scale;
132
 
        double  v_rng_scale;
133
 
        int             flip_flop;
134
 
        int             has_freq_in_cap;
135
 
        int             out_type;
136
 
};
137
 
 
138
 
 
139
29
/************************************************************************
140
30
 *
141
31
 * DSD_555_ASTBL -  - 555 Astable simulation
167
57
 
168
58
DISCRETE_STEP(dsd_555_astbl)
169
59
{
170
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_astbl)
171
60
        DISCRETE_DECLARE_INFO(discrete_555_desc)
172
61
 
173
62
        int             count_f = 0;
174
63
        int             count_r = 0;
175
64
        double  dt;                                                             /* change in time */
176
65
        double  x_time  = 0;                                    /* time since change happened */
177
 
        double  v_cap   = context->cap_voltage; /* Current voltage on capacitor, before dt */
 
66
        double  v_cap   = m_cap_voltage;        /* Current voltage on capacitor, before dt */
178
67
        double  v_cap_next = 0;                                 /* Voltage on capacitor, after dt */
179
68
        double  v_charge, exponent = 0;
180
 
        UINT8   flip_flop = context->flip_flop;
 
69
        UINT8   flip_flop = m_flip_flop;
181
70
        UINT8   update_exponent = 0;
 
71
        double  v_out = 0.0;
182
72
 
183
73
        /* put commonly used stuff in local variables for speed */
184
 
        double  threshold = context->threshold;
185
 
        double  trigger   = context->trigger;
 
74
        double  threshold = m_threshold;
 
75
        double  trigger   = m_trigger;
186
76
 
187
77
        if(DSD_555_ASTBL__RESET)
188
78
        {
189
79
                /* We are in RESET */
190
 
                node->output[0]      = 0;
191
 
                context->flip_flop   = 1;
192
 
                context->cap_voltage = 0;
 
80
                set_output(0, 0);
 
81
                m_flip_flop   = 1;
 
82
                m_cap_voltage = 0;
193
83
                return;
194
84
        }
195
85
 
196
86
        /* Check: if the Control Voltage node is connected. */
197
 
        if (context->use_ctrlv)
 
87
        if (m_use_ctrlv)
198
88
        {
199
89
                /* If CV is less then .25V, the circuit will oscillate way out of range.
200
90
         * So we will just ignore it when it happens. */
217
107
        }
218
108
 
219
109
        /* get the v_charge and update each step if it is a node */
220
 
        if (context->v_charge_node != NULL)
 
110
        if (m_v_charge_node != NULL)
221
111
        {
222
 
                v_charge = *context->v_charge_node;
 
112
                v_charge = *m_v_charge_node;
223
113
                if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) v_charge -= 0.5;
224
114
        }
225
115
        else
226
 
                v_charge = context->v_charge;
 
116
                v_charge = m_v_charge;
227
117
 
228
118
 
229
119
        /* Calculate future capacitor voltage.
244
134
     * dt = R*C(log(1/(1-(Vc/Vr))))
245
135
     */
246
136
 
247
 
        dt = node->info->sample_time;
 
137
        dt = this->sample_time();
248
138
 
249
139
        /* Sometimes a switching network is used to setup the capacitance.
250
140
     * These may select no capacitor, causing oscillation to stop.
255
145
                /* The voltage goes high because the cap circuit is open. */
256
146
                v_cap_next = v_charge;
257
147
                v_cap      = v_charge;
258
 
                context->cap_voltage = 0;
 
148
                m_cap_voltage = 0;
259
149
        }
260
150
        else
261
151
        {
262
152
                /* Update charge contstants and exponents if nodes changed */
263
 
                if (context->has_rc_nodes && (DSD_555_ASTBL__R1 != context->last_r1 || DSD_555_ASTBL__C != context->last_c || DSD_555_ASTBL__R2 != context->last_r2))
 
153
                if (m_has_rc_nodes && (DSD_555_ASTBL__R1 != m_last_r1 || DSD_555_ASTBL__C != m_last_c || DSD_555_ASTBL__R2 != m_last_r2))
264
154
                {
265
 
                        context->t_rc_bleed  = DSD_555_ASTBL_T_RC_BLEED;
266
 
                        context->t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE;
267
 
                        context->t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE;
268
 
                        context->exp_bleed  = RC_CHARGE_EXP(context->t_rc_bleed);
269
 
                        context->exp_charge = RC_CHARGE_EXP(context->t_rc_charge);
270
 
                        context->exp_discharge = RC_CHARGE_EXP(context->t_rc_discharge);
271
 
                        context->last_r1 = DSD_555_ASTBL__R1;
272
 
                        context->last_r2 = DSD_555_ASTBL__R2;
273
 
                        context->last_c  = DSD_555_ASTBL__C;
 
155
                        m_t_rc_bleed  = DSD_555_ASTBL_T_RC_BLEED;
 
156
                        m_t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE;
 
157
                        m_t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE;
 
158
                        m_exp_bleed  = RC_CHARGE_EXP(m_t_rc_bleed);
 
159
                        m_exp_charge = RC_CHARGE_EXP(m_t_rc_charge);
 
160
                        m_exp_discharge = RC_CHARGE_EXP(m_t_rc_discharge);
 
161
                        m_last_r1 = DSD_555_ASTBL__R1;
 
162
                        m_last_r2 = DSD_555_ASTBL__R2;
 
163
                        m_last_c  = DSD_555_ASTBL__C;
274
164
                }
275
165
                /* Keep looping until all toggling in time sample is used up. */
276
166
                do
282
172
                                        /* Oscillation disabled because there is no longer any charge resistor. */
283
173
                                        /* Bleed the cap due to circuit losses. */
284
174
                                        if (update_exponent)
285
 
                                                exponent = RC_CHARGE_EXP_DT(context->t_rc_bleed, dt);
 
175
                                                exponent = RC_CHARGE_EXP_DT(m_t_rc_bleed, dt);
286
176
                                        else
287
 
                                                exponent = context->exp_bleed;
 
177
                                                exponent = m_exp_bleed;
288
178
                                        v_cap_next = v_cap - (v_cap * exponent);
289
179
                                        dt = 0;
290
180
                                }
292
182
                                {
293
183
                                        /* Charging */
294
184
                                        if (update_exponent)
295
 
                                                exponent = RC_CHARGE_EXP_DT(context->t_rc_charge, dt);
 
185
                                                exponent = RC_CHARGE_EXP_DT(m_t_rc_charge, dt);
296
186
                                        else
297
 
                                                exponent = context->exp_charge;
 
187
                                                exponent = m_exp_charge;
298
188
                                        v_cap_next = v_cap + ((v_charge - v_cap) * exponent);
299
189
                                        dt = 0;
300
190
 
302
192
                                        if (v_cap_next >= threshold)
303
193
                                        {
304
194
                                                /* calculate the overshoot time */
305
 
                                                dt     = context->t_rc_charge  * log(1.0 / (1.0 - ((v_cap_next - threshold) / (v_charge - v_cap))));
 
195
                                                dt     = m_t_rc_charge  * log(1.0 / (1.0 - ((v_cap_next - threshold) / (v_charge - v_cap))));
306
196
                                                x_time = dt;
307
197
                                                v_cap_next  = threshold;
308
198
                                                flip_flop = 0;
317
207
                                if(DSD_555_ASTBL__R2 != 0)
318
208
                                {
319
209
                                        if (update_exponent)
320
 
                                                exponent = RC_CHARGE_EXP_DT(context->t_rc_discharge, dt);
 
210
                                                exponent = RC_CHARGE_EXP_DT(m_t_rc_discharge, dt);
321
211
                                        else
322
 
                                                exponent = context->exp_discharge;
 
212
                                                exponent = m_exp_discharge;
323
213
                                        v_cap_next = v_cap - (v_cap * exponent);
324
214
                                        dt = 0;
325
215
                                }
334
224
                                {
335
225
                                        /* calculate the overshoot time */
336
226
                                        if (v_cap_next < trigger)
337
 
                                                dt = context->t_rc_discharge  * log(1.0 / (1.0 - ((trigger - v_cap_next) / v_cap)));
 
227
                                                dt = m_t_rc_discharge  * log(1.0 / (1.0 - ((trigger - v_cap_next) / v_cap)));
338
228
                                        x_time = dt;
339
229
                                        v_cap_next  = trigger;
340
230
                                        flip_flop = 1;
345
235
                        v_cap = v_cap_next;
346
236
                } while(dt);
347
237
 
348
 
                context->cap_voltage = v_cap;
 
238
                m_cap_voltage = v_cap;
349
239
        }
350
240
 
351
241
        /* Convert last switch time to a ratio */
352
 
        x_time = x_time / node->info->sample_time;
 
242
        x_time = x_time / this->sample_time();
353
243
 
354
 
        switch (context->output_type)
 
244
        switch (m_output_type)
355
245
        {
356
246
                case DISC_555_OUT_SQW:
357
247
                        if (count_f + count_r >= 2)
358
248
                                /* force at least 1 toggle */
359
 
                                node->output[0] = context->flip_flop ? 0 : context->v_out_high;
 
249
                                v_out =  m_flip_flop ? 0 : m_v_out_high;
360
250
                        else
361
 
                                node->output[0] = flip_flop * context->v_out_high;
362
 
                        node->output[0] += context->ac_shift;
 
251
                                v_out =  flip_flop * m_v_out_high;
 
252
                        v_out += m_ac_shift;
363
253
                        break;
364
254
                case DISC_555_OUT_CAP:
365
 
                        node->output[0] = v_cap;
 
255
                        v_out =  v_cap;
366
256
                        /* Fake it to AC if needed */
367
 
                        if (context->output_is_ac)
368
 
                                node->output[0] -= threshold * 3.0 /4.0;
 
257
                        if (m_output_is_ac)
 
258
                                v_out -= threshold * 3.0 /4.0;
369
259
                        break;
370
260
                case DISC_555_OUT_ENERGY:
371
261
                        if (x_time == 0) x_time = 1.0;
372
 
                        node->output[0]  = context->v_out_high * (flip_flop ? x_time : (1.0 - x_time));
373
 
                        node->output[0] += context->ac_shift;
 
262
                        v_out = m_v_out_high * (flip_flop ? x_time : (1.0 - x_time));
 
263
                        v_out += m_ac_shift;
374
264
                        break;
375
265
                case DISC_555_OUT_LOGIC_X:
376
 
                        node->output[0] = flip_flop + x_time;
 
266
                        v_out =  flip_flop + x_time;
377
267
                        break;
378
268
                case DISC_555_OUT_COUNT_F_X:
379
 
                        node->output[0] = count_f ? count_f + x_time : count_f;
 
269
                        v_out = count_f ? count_f + x_time : count_f;
380
270
                        break;
381
271
                case DISC_555_OUT_COUNT_R_X:
382
 
                        node->output[0] =  count_r ? count_r + x_time : count_r;
 
272
                        v_out =  count_r ? count_r + x_time : count_r;
383
273
                        break;
384
274
                case DISC_555_OUT_COUNT_F:
385
 
                        node->output[0] = count_f;
 
275
                        v_out =  count_f;
386
276
                        break;
387
277
                case DISC_555_OUT_COUNT_R:
388
 
                        node->output[0] = count_r;
 
278
                        v_out =  count_r;
389
279
                        break;
390
280
        }
391
 
        context->flip_flop = flip_flop;
 
281
        set_output(0, v_out);
 
282
        m_flip_flop = flip_flop;
392
283
}
393
284
 
394
285
DISCRETE_RESET(dsd_555_astbl)
395
286
{
396
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_astbl)
397
287
        DISCRETE_DECLARE_INFO(discrete_555_desc)
398
288
 
399
 
        node_description *v_charge_node;
400
 
 
401
 
        context->use_ctrlv   = (node->input_is_node >> 4) & 1;
402
 
        context->output_type = info->options & DISC_555_OUT_MASK;
 
289
        m_use_ctrlv   = (this->input_is_node() >> 4) & 1;
 
290
        m_output_type = info->options & DISC_555_OUT_MASK;
403
291
 
404
292
        /* Use the defaults or supplied values. */
405
 
        context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
 
293
        m_v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
406
294
 
407
295
        /* setup v_charge or node */
408
 
        v_charge_node = discrete_find_node(node->info, info->v_charge);
409
 
        if (v_charge_node)
410
 
                context->v_charge_node = &(v_charge_node->output[NODE_CHILD_NODE_NUM(info->v_charge)]);
411
 
        else
 
296
        m_v_charge_node = m_device->node_output_ptr(info->v_charge);
 
297
        if (m_v_charge_node == NULL)
412
298
        {
413
 
                context->v_charge   = (info->v_charge == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge;
414
 
                context->v_charge_node = NULL;
 
299
                m_v_charge   = (info->v_charge == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge;
415
300
 
416
 
                if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) context->v_charge -= 0.5;
 
301
                if (info->options & DISC_555_ASTABLE_HAS_FAST_CHARGE_DIODE) m_v_charge -= 0.5;
417
302
        }
418
303
 
419
 
        if ((DSD_555_ASTBL__CTRLV != -1) && !context->use_ctrlv)
 
304
        if ((DSD_555_ASTBL__CTRLV != -1) && !m_use_ctrlv)
420
305
        {
421
306
                /* Setup based on supplied Control Voltage static value */
422
 
                context->threshold = DSD_555_ASTBL__CTRLV;
423
 
                context->trigger   = DSD_555_ASTBL__CTRLV / 2.0;
 
307
                m_threshold = DSD_555_ASTBL__CTRLV;
 
308
                m_trigger   = DSD_555_ASTBL__CTRLV / 2.0;
424
309
        }
425
310
        else
426
311
        {
427
312
                /* Setup based on v_pos power source */
428
 
                context->threshold = info->v_pos * 2.0 / 3.0;
429
 
                context->trigger   = info->v_pos / 3.0;
 
313
                m_threshold = info->v_pos * 2.0 / 3.0;
 
314
                m_trigger   = info->v_pos / 3.0;
430
315
        }
431
316
 
432
317
        /* optimization if none of the values are nodes */
433
 
        context->has_rc_nodes = 0;
434
 
        if (node->input_is_node & DSD_555_ASTBL_RC_MASK)
435
 
                context->has_rc_nodes = 1;
 
318
        m_has_rc_nodes = 0;
 
319
        if (this->input_is_node() & DSD_555_ASTBL_RC_MASK)
 
320
                m_has_rc_nodes = 1;
436
321
        else
437
322
        {
438
 
                context->t_rc_bleed  = DSD_555_ASTBL_T_RC_BLEED;
439
 
                context->exp_bleed   = RC_CHARGE_EXP(context->t_rc_bleed);
440
 
                context->t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE;
441
 
                context->exp_charge  = RC_CHARGE_EXP(context->t_rc_charge);
442
 
                context->t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE;
443
 
                context->exp_discharge  = RC_CHARGE_EXP(context->t_rc_discharge);
 
323
                m_t_rc_bleed  = DSD_555_ASTBL_T_RC_BLEED;
 
324
                m_exp_bleed   = RC_CHARGE_EXP(m_t_rc_bleed);
 
325
                m_t_rc_charge = DSD_555_ASTBL_T_RC_CHARGE;
 
326
                m_exp_charge  = RC_CHARGE_EXP(m_t_rc_charge);
 
327
                m_t_rc_discharge = DSD_555_ASTBL_T_RC_DISCHARGE;
 
328
                m_exp_discharge  = RC_CHARGE_EXP(m_t_rc_discharge);
444
329
        }
445
330
 
446
 
        context->output_is_ac = info->options & DISC_555_OUT_AC;
 
331
        m_output_is_ac = info->options & DISC_555_OUT_AC;
447
332
        /* Calculate DC shift needed to make squarewave waveform AC */
448
 
        context->ac_shift = context->output_is_ac ? -context->v_out_high / 2.0 : 0;
 
333
        m_ac_shift = m_output_is_ac ? -m_v_out_high / 2.0 : 0;
449
334
 
450
 
        context->flip_flop = 1;
451
 
        context->cap_voltage = 0;
 
335
        m_flip_flop = 1;
 
336
        m_cap_voltage = 0;
452
337
 
453
338
        /* Step to set the output */
454
 
        DISCRETE_STEP_CALL(dsd_555_astbl);
 
339
        this->step();
455
340
}
456
341
 
457
342
 
478
363
 
479
364
DISCRETE_STEP(dsd_555_mstbl)
480
365
{
481
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_mstbl)
482
366
        DISCRETE_DECLARE_INFO(discrete_555_desc)
483
367
 
484
368
        double v_cap;                   /* Current voltage on capacitor, before dt */
487
371
        double out = 0;
488
372
        int trigger = 0;
489
373
        int trigger_type;
490
 
        int update_exponent = context->has_rc_nodes;
 
374
        int update_exponent = m_has_rc_nodes;
491
375
        int flip_flop;
492
376
 
493
377
        if(UNEXPECTED(DSD_555_MSTBL__RESET))
494
378
        {
495
379
                /* We are in RESET */
496
 
                node->output[0]     = 0;
497
 
                context->flip_flop  = 0;
498
 
                context->cap_voltage = 0;
 
380
                set_output(0, 0);
 
381
                m_flip_flop  = 0;
 
382
                m_cap_voltage = 0;
499
383
                return;
500
384
        }
501
385
 
502
 
        dt = node->info->sample_time;
503
 
        flip_flop = context->flip_flop;
 
386
        dt = this->sample_time();
 
387
        flip_flop = m_flip_flop;
504
388
        trigger_type = info->options;
505
 
        v_cap = context->cap_voltage;
 
389
        v_cap = m_cap_voltage;
506
390
 
507
391
        switch (trigger_type & DSD_555_TRIGGER_TYPE_MASK)
508
392
        {
512
396
                                x_time = 1.0 - DSD_555_MSTBL__TRIGGER;
513
397
                        break;
514
398
                case DISC_555_TRIGGER_IS_VOLTAGE:
515
 
                        trigger = (int)(DSD_555_MSTBL__TRIGGER < context->trigger);
 
399
                        trigger = (int)(DSD_555_MSTBL__TRIGGER < m_trigger);
516
400
                        break;
517
401
                case DISC_555_TRIGGER_IS_COUNT:
518
402
                        trigger = (int)DSD_555_MSTBL__TRIGGER;
530
414
        x_time = 0;
531
415
 
532
416
        if ((trigger_type & DISC_555_TRIGGER_DISCHARGES_CAP) && trigger)
533
 
                context->cap_voltage = 0;
 
417
                m_cap_voltage = 0;
534
418
 
535
419
        /* Wait for trigger */
536
420
        if (UNEXPECTED(!flip_flop && trigger))
537
421
        {
538
422
                flip_flop = 1;
539
 
                context->flip_flop = 1;
 
423
                m_flip_flop = 1;
540
424
        }
541
425
 
542
426
        if (flip_flop)
549
433
                        /* The trigger voltage goes high because the cap circuit is open.
550
434
             * and the cap discharges */
551
435
                        v_cap = info->v_pos;    /* needed for cap output type */
552
 
                        context->cap_voltage = 0;
 
436
                        m_cap_voltage = 0;
553
437
 
554
438
                        if (!trigger)
555
439
                        {
556
440
                                flip_flop = 0;
557
 
                                context->flip_flop = 0;
 
441
                                m_flip_flop = 0;
558
442
                        }
559
443
                }
560
444
                else
561
445
                {
562
446
                        /* Charging */
563
 
                        double v_diff = context->v_charge - v_cap;
 
447
                        double v_diff = m_v_charge - v_cap;
564
448
 
565
449
                        if (UNEXPECTED(update_exponent))
566
450
                                exponent = RC_CHARGE_EXP_DT(DSD_555_MSTBL__R * DSD_555_MSTBL__C, dt);
567
451
                        else
568
 
                                exponent = context->exp_charge;
 
452
                                exponent = m_exp_charge;
569
453
                        v_cap += v_diff * exponent;
570
454
 
571
455
                        /* Has it charged past upper limit? */
572
456
                        /* If trigger is still enabled, then we keep charging,
573
457
             * regardless of threshold. */
574
 
                        if (UNEXPECTED((v_cap >= context->threshold) && !trigger))
 
458
                        if (UNEXPECTED((v_cap >= m_threshold) && !trigger))
575
459
                        {
576
 
                                dt = DSD_555_MSTBL__R * DSD_555_MSTBL__C  * log(1.0 / (1.0 - ((v_cap - context->threshold) / v_diff)));
577
 
                                x_time = 1.0 - dt / node->info->sample_time;
 
460
                                dt = DSD_555_MSTBL__R * DSD_555_MSTBL__C  * log(1.0 / (1.0 - ((v_cap - m_threshold) / v_diff)));
 
461
                                x_time = 1.0 - dt / this->sample_time();
578
462
                                v_cap  = 0;
579
463
                                flip_flop = 0;
580
 
                                context->flip_flop = 0;
 
464
                                m_flip_flop = 0;
581
465
                        }
582
 
                        context->cap_voltage = v_cap;
 
466
                        m_cap_voltage = v_cap;
583
467
                }
584
468
        }
585
469
 
586
 
        switch (context->output_type)
 
470
        switch (m_output_type)
587
471
        {
588
472
                case DISC_555_OUT_SQW:
589
 
                        out = flip_flop * context->v_out_high - context->ac_shift;
 
473
                        out = flip_flop * m_v_out_high - m_ac_shift;
590
474
                        break;
591
475
                case DISC_555_OUT_CAP:
592
476
                        if (x_time > 0)
594
478
                        else
595
479
                                out = v_cap;
596
480
 
597
 
                        out -= context->ac_shift;
 
481
                        out -= m_ac_shift;
598
482
                        break;
599
483
                case DISC_555_OUT_ENERGY:
600
484
                        if (x_time > 0)
601
 
                                out = context->v_out_high * x_time;
 
485
                                out = m_v_out_high * x_time;
602
486
                        else if (flip_flop)
603
 
                                out = context->v_out_high;
 
487
                                out = m_v_out_high;
604
488
                        else
605
489
                                out = 0;
606
490
 
607
 
                        out -= context->ac_shift;
 
491
                        out -= m_ac_shift;
608
492
                        break;
609
493
        }
610
 
        node->output[0] = out;
 
494
        set_output(0,  out);
611
495
}
612
496
 
613
497
DISCRETE_RESET(dsd_555_mstbl)
614
498
{
615
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_mstbl)
616
499
        DISCRETE_DECLARE_INFO(discrete_555_desc)
617
500
 
618
 
        context->output_type = info->options & DISC_555_OUT_MASK;
619
 
        if ((context->output_type == DISC_555_OUT_COUNT_F) || (context->output_type == DISC_555_OUT_COUNT_R))
 
501
        m_output_type = info->options & DISC_555_OUT_MASK;
 
502
        if ((m_output_type == DISC_555_OUT_COUNT_F) || (m_output_type == DISC_555_OUT_COUNT_R))
620
503
        {
621
 
                discrete_log(node->info, "Invalid Output type in NODE_%d.\n", NODE_BLOCKINDEX(node));
622
 
                context->output_type = DISC_555_OUT_SQW;
 
504
                m_device->discrete_log("Invalid Output type in NODE_%d.\n", this->index());
 
505
                m_output_type = DISC_555_OUT_SQW;
623
506
        }
624
507
 
625
508
        /* Use the defaults or supplied values. */
626
 
        context->v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
627
 
        context->v_charge   = (info->v_charge   == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge;
 
509
        m_v_out_high = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
 
510
        m_v_charge   = (info->v_charge   == DEFAULT_555_CHARGE) ? info->v_pos : info->v_charge;
628
511
 
629
512
        /* Setup based on v_pos power source */
630
 
        context->threshold = info->v_pos * 2.0 / 3.0;
631
 
        context->trigger   = info->v_pos / 3.0;
 
513
        m_threshold = info->v_pos * 2.0 / 3.0;
 
514
        m_trigger   = info->v_pos / 3.0;
632
515
 
633
516
        /* Calculate DC shift needed to make waveform AC */
634
517
        if (info->options & DISC_555_OUT_AC)
635
518
        {
636
 
                if (context->output_type == DISC_555_OUT_CAP)
637
 
                        context->ac_shift = context->threshold * 3.0 /4.0;
 
519
                if (m_output_type == DISC_555_OUT_CAP)
 
520
                        m_ac_shift = m_threshold * 3.0 /4.0;
638
521
                else
639
 
                        context->ac_shift = context->v_out_high / 2.0;
 
522
                        m_ac_shift = m_v_out_high / 2.0;
640
523
        }
641
524
        else
642
 
                context->ac_shift = 0;
643
 
 
644
 
        context->trig_is_logic       = (info->options & DISC_555_TRIGGER_IS_VOLTAGE) ? 0: 1;
645
 
        context->trig_discharges_cap = (info->options & DISC_555_TRIGGER_DISCHARGES_CAP) ? 1: 0;
646
 
 
647
 
        context->flip_flop   = 0;
648
 
        context->cap_voltage = 0;
 
525
                m_ac_shift = 0;
 
526
 
 
527
        m_trig_is_logic       = (info->options & DISC_555_TRIGGER_IS_VOLTAGE) ? 0: 1;
 
528
        m_trig_discharges_cap = (info->options & DISC_555_TRIGGER_DISCHARGES_CAP) ? 1: 0;
 
529
 
 
530
        m_flip_flop   = 0;
 
531
        m_cap_voltage = 0;
649
532
 
650
533
        /* optimization if none of the values are nodes */
651
 
        context->has_rc_nodes = 0;
652
 
        if (node->input_is_node & DSD_555_MSTBL_RC_MASK)
653
 
                context->has_rc_nodes = 1;
 
534
        m_has_rc_nodes = 0;
 
535
        if (this->input_is_node() & DSD_555_MSTBL_RC_MASK)
 
536
                m_has_rc_nodes = 1;
654
537
        else
655
 
                context->exp_charge = RC_CHARGE_EXP(DSD_555_MSTBL__R * DSD_555_MSTBL__C);
 
538
                m_exp_charge = RC_CHARGE_EXP(DSD_555_MSTBL__R * DSD_555_MSTBL__C);
656
539
 
657
 
        node->output[0] = 0;
 
540
        set_output(0,  0);
658
541
}
659
542
 
660
543
 
695
578
 
696
579
DISCRETE_STEP(dsd_555_cc)
697
580
{
698
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_cc)
699
581
        DISCRETE_DECLARE_INFO(discrete_555_cc_desc)
700
582
 
701
583
        int             count_f  = 0;
715
597
        double  r_temp;                         /* play thing */
716
598
        double  exponent;
717
599
        UINT8   update_exponent, update_t_rc;
718
 
        UINT8   flip_flop = context->flip_flop;
 
600
        UINT8   flip_flop = m_flip_flop;
 
601
 
 
602
        double v_out = 0;
719
603
 
720
604
 
721
605
        if (UNEXPECTED(DSD_555_CC__RESET))
722
606
        {
723
607
                /* We are in RESET */
724
 
                node->output[0]      = 0;
725
 
                context->flip_flop   = 1;
726
 
                context->cap_voltage = 0;
 
608
                set_output(0, 0);
 
609
                m_flip_flop   = 1;
 
610
                m_cap_voltage = 0;
727
611
                return;
728
612
        }
729
613
 
730
 
        dt    = node->info->sample_time;        /* Change in time */
731
 
        v_cap = context->cap_voltage;   /* Set to voltage before change */
 
614
        dt    = this->sample_time();    /* Change in time */
 
615
        v_cap = m_cap_voltage;  /* Set to voltage before change */
732
616
        v_vcharge_limit = DSD_555_CC__VIN + info->v_cc_junction;        /* the max v_cap can be and still be charged by i */
733
617
        /* Calculate charging current */
734
 
        i = (context->v_cc_source - v_vcharge_limit) / DSD_555_CC__R;
 
618
        i = (m_v_cc_source - v_vcharge_limit) / DSD_555_CC__R;
735
619
        if ( i < 0) i = 0;
736
620
 
737
621
        if (info->options & DISCRETE_555_CC_TO_CAP)
740
624
        }
741
625
        else
742
626
        {
743
 
                switch (context->type)  /* see dsd_555_cc_reset for descriptions */
 
627
                switch (m_type) /* see dsd_555_cc_reset for descriptions */
744
628
                {
745
629
                        case 1:
746
630
                                r_discharge = DSD_555_CC__RDIS;
781
665
        }
782
666
 
783
667
        /* Keep looping until all toggling in time sample is used up. */
784
 
        update_t_rc = context->has_rc_nodes;
 
668
        update_t_rc = m_has_rc_nodes;
785
669
        update_exponent = update_t_rc;
786
670
        do
787
671
        {
788
 
                if (context->type <= 1)
 
672
                if (m_type <= 1)
789
673
                {
790
674
                        /* Standard constant current charge */
791
675
                        if (flip_flop)
801
685
                                                exponent = RC_CHARGE_EXP_DT(t_rc, dt);
802
686
                                        }
803
687
                                        else
804
 
                                                exponent = context->exp_bleed;
 
688
                                                exponent = m_exp_bleed;
805
689
                                        v_cap_next = v_cap - (v_cap * exponent);
806
690
                                        dt = 0;
807
691
                                }
819
703
                                        dt = 0;
820
704
 
821
705
                                        /* has it charged past upper limit? */
822
 
                                        if (v_cap_next >= context->threshold)
 
706
                                        if (v_cap_next >= m_threshold)
823
707
                                        {
824
708
                                                /* calculate the overshoot time */
825
 
                                                dt     = DSD_555_CC__C * (v_cap_next - context->threshold) / i;
 
709
                                                dt     = DSD_555_CC__C * (v_cap_next - m_threshold) / i;
826
710
                                                x_time = dt;
827
 
                                                v_cap_next = context->threshold;
 
711
                                                v_cap_next = m_threshold;
828
712
                                                flip_flop = 0;
829
713
                                                count_f++;
830
714
                                                update_exponent = 1;
837
721
                                if (update_t_rc)
838
722
                                        t_rc = DSD_555_CC_T_RC_DISCHARGE_01;
839
723
                                else
840
 
                                        t_rc = context->t_rc_discharge_01;
 
724
                                        t_rc = m_t_rc_discharge_01;
841
725
                                if (update_exponent)
842
726
                                        exponent = RC_CHARGE_EXP_DT(t_rc, dt);
843
727
                                else
844
 
                                        exponent = context->exp_discharge_01;
 
728
                                        exponent = m_exp_discharge_01;
845
729
 
846
730
                                if (info->options & DISCRETE_555_CC_TO_CAP)
847
731
                                {
859
743
 
860
744
                                dt = 0;
861
745
                                /* has it discharged past lower limit? */
862
 
                                if (v_cap_next <= context->trigger)
 
746
                                if (v_cap_next <= m_trigger)
863
747
                                {
864
 
                                        dt     = t_rc  * log(1.0 / (1.0 - ((context->trigger - v_cap_next) / v_cap)));
 
748
                                        dt     = t_rc  * log(1.0 / (1.0 - ((m_trigger - v_cap_next) / v_cap)));
865
749
                                        x_time = dt;
866
 
                                        v_cap_next  = context->trigger;
 
750
                                        v_cap_next  = m_trigger;
867
751
                                        flip_flop = 1;
868
752
                                        count_r++;
869
753
                                        update_exponent = 1;
872
756
                        else    /* Immediate discharge. No change in dt. */
873
757
                        {
874
758
                                x_time = dt;
875
 
                                v_cap_next = context->trigger;
 
759
                                v_cap_next = m_trigger;
876
760
                                flip_flop = 1;
877
761
                                count_r++;
878
762
                        }
890
774
                                        if (update_t_rc)
891
775
                                                t_rc = DSD_555_CC_T_RC_DISCHARGE_NO_I;
892
776
                                        else
893
 
                                                t_rc = context->t_rc_discharge_no_i;
 
777
                                                t_rc = m_t_rc_discharge_no_i;
894
778
                                        if (update_exponent)
895
779
                                                exponent = RC_CHARGE_EXP_DT(t_rc, dt);
896
780
                                        else
897
 
                                                exponent = context->exp_discharge_no_i;
 
781
                                                exponent = m_exp_discharge_no_i;
898
782
 
899
783
                                        v_cap_next = v_cap - (v_cap * exponent);
900
784
                                        dt = 0;
906
790
                     * then only the bias voltage will charge the cap. */
907
791
                                        v = v_bias;
908
792
                                        if (v_cap < v_vcharge_limit) v += vi;
909
 
                                        else if (context->type <= 3) v = v_vcharge_limit;
 
793
                                        else if (m_type <= 3) v = v_vcharge_limit;
910
794
 
911
795
                                        if (update_t_rc)
912
796
                                                t_rc = DSD_555_CC_T_RC_CHARGE;
913
797
                                        else
914
 
                                                t_rc = context->t_rc_charge;
 
798
                                                t_rc = m_t_rc_charge;
915
799
                                        if (update_exponent)
916
800
                                                exponent = RC_CHARGE_EXP_DT(t_rc, dt);
917
801
                                        else
918
 
                                                exponent = context->exp_charge;
 
802
                                                exponent = m_exp_charge;
919
803
 
920
804
                                        v_cap_next = v_cap + ((v - v_cap) * exponent);
921
805
                                        dt         = 0;
922
806
 
923
807
                                        /* has it charged past upper limit? */
924
 
                                        if (v_cap_next >= context->threshold)
 
808
                                        if (v_cap_next >= m_threshold)
925
809
                                        {
926
810
                                                /* calculate the overshoot time */
927
 
                                                dt     = t_rc  * log(1.0 / (1.0 - ((v_cap_next - context->threshold) / (v - v_cap))));
 
811
                                                dt     = t_rc  * log(1.0 / (1.0 - ((v_cap_next - m_threshold) / (v - v_cap))));
928
812
                                                x_time = dt;
929
 
                                                v_cap_next = context->threshold;
 
813
                                                v_cap_next = m_threshold;
930
814
                                                flip_flop = 0;
931
815
                                                count_f++;
932
816
                                                update_exponent = 1;
939
823
                                if (update_t_rc)
940
824
                                        t_rc = DSD_555_CC_T_RC_DISCHARGE;
941
825
                                else
942
 
                                        t_rc = context->t_rc_discharge;
 
826
                                        t_rc = m_t_rc_discharge;
943
827
                                if (update_exponent)
944
828
                                        exponent = RC_CHARGE_EXP_DT(t_rc, dt);
945
829
                                else
946
 
                                        exponent = context->exp_discharge;
 
830
                                        exponent = m_exp_discharge;
947
831
 
948
832
                                v_cap_next = v_cap - (v_cap * exponent);
949
833
                                dt = 0;
950
834
 
951
835
                                /* has it discharged past lower limit? */
952
 
                                if (v_cap_next <= context->trigger)
 
836
                                if (v_cap_next <= m_trigger)
953
837
                                {
954
838
                                        /* calculate the overshoot time */
955
 
                                        dt     = t_rc  * log(1.0 / (1.0 - ((context->trigger - v_cap_next) / v_cap)));
 
839
                                        dt     = t_rc  * log(1.0 / (1.0 - ((m_trigger - v_cap_next) / v_cap)));
956
840
                                        x_time = dt;
957
 
                                        v_cap_next = context->trigger;
 
841
                                        v_cap_next = m_trigger;
958
842
                                        flip_flop = 1;
959
843
                                        count_r++;
960
844
                                        update_exponent = 1;
963
847
                        else    /* Immediate discharge. No change in dt. */
964
848
                        {
965
849
                                x_time = dt;
966
 
                                v_cap_next = context->trigger;
 
850
                                v_cap_next = m_trigger;
967
851
                                flip_flop = 1;
968
852
                                count_r++;
969
853
                        }
971
855
                v_cap = v_cap_next;
972
856
        } while(dt);
973
857
 
974
 
        context->cap_voltage = v_cap;
 
858
        m_cap_voltage = v_cap;
975
859
 
976
860
        /* Convert last switch time to a ratio */
977
 
        x_time = x_time / node->info->sample_time;
 
861
        x_time = x_time / this->sample_time();
978
862
 
979
 
        switch (context->output_type)
 
863
        switch (m_output_type)
980
864
        {
981
865
                case DISC_555_OUT_SQW:
982
866
                        if (count_f + count_r >= 2)
983
867
                                /* force at least 1 toggle */
984
 
                                node->output[0] = context->flip_flop ? 0 : context->v_out_high;
 
868
                                v_out =  m_flip_flop ? 0 : m_v_out_high;
985
869
                        else
986
 
                                node->output[0] = flip_flop * context->v_out_high;
 
870
                                v_out = flip_flop * m_v_out_high;
987
871
                        /* Fake it to AC if needed */
988
 
                        node->output[0] += context->ac_shift;
 
872
                        v_out += m_ac_shift;
989
873
                        break;
990
874
                case DISC_555_OUT_CAP:
991
 
                        node->output[0] = v_cap + context->ac_shift;
 
875
                        v_out = v_cap + m_ac_shift;
992
876
                        break;
993
877
                case DISC_555_OUT_ENERGY:
994
878
                        if (x_time == 0) x_time = 1.0;
995
 
                        node->output[0]  = context->v_out_high * (flip_flop ? x_time : (1.0 - x_time));
996
 
                        node->output[0] += context->ac_shift;
 
879
                        v_out = m_v_out_high * (flip_flop ? x_time : (1.0 - x_time));
 
880
                        v_out += m_ac_shift;
997
881
                        break;
998
882
                case DISC_555_OUT_LOGIC_X:
999
 
                        node->output[0] = flip_flop + x_time;
 
883
                        v_out = flip_flop + x_time;
1000
884
                        break;
1001
885
                case DISC_555_OUT_COUNT_F_X:
1002
 
                        node->output[0] = count_f ? count_f + x_time : count_f;
 
886
                        v_out = count_f ? count_f + x_time : count_f;
1003
887
                        break;
1004
888
                case DISC_555_OUT_COUNT_R_X:
1005
 
                        node->output[0] =  count_r ? count_r + x_time : count_r;
 
889
                        v_out = count_r ? count_r + x_time : count_r;
1006
890
                        break;
1007
891
                case DISC_555_OUT_COUNT_F:
1008
 
                        node->output[0] = count_f;
 
892
                        v_out = count_f;
1009
893
                        break;
1010
894
                case DISC_555_OUT_COUNT_R:
1011
 
                        node->output[0] = count_r;
 
895
                        v_out = count_r;
1012
896
                        break;
1013
897
        }
1014
 
        context->flip_flop = flip_flop;
 
898
        set_output(0, v_out);
 
899
        m_flip_flop = flip_flop;
1015
900
}
1016
901
 
1017
902
DISCRETE_RESET(dsd_555_cc)
1018
903
{
1019
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_cc)
1020
904
        DISCRETE_DECLARE_INFO(discrete_555_cc_desc)
1021
905
 
1022
906
        double  r_temp, r_discharge = 0, r_charge = 0;
1023
907
 
1024
 
        context->flip_flop   = 1;
1025
 
        context->cap_voltage = 0;
 
908
        m_flip_flop   = 1;
 
909
        m_cap_voltage = 0;
1026
910
 
1027
 
        context->output_type = info->options & DISC_555_OUT_MASK;
 
911
        m_output_type = info->options & DISC_555_OUT_MASK;
1028
912
 
1029
913
        /* Use the defaults or supplied values. */
1030
 
        context->v_out_high  = (info->v_out_high  == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
1031
 
        context->v_cc_source = (info->v_cc_source == DEFAULT_555_CC_SOURCE) ? info->v_pos : info->v_cc_source;
 
914
        m_v_out_high  = (info->v_out_high  == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
 
915
        m_v_cc_source = (info->v_cc_source == DEFAULT_555_CC_SOURCE) ? info->v_pos : info->v_cc_source;
1032
916
 
1033
917
        /* Setup based on v_pos power source */
1034
 
        context->threshold = info->v_pos * 2.0 / 3.0;
1035
 
        context->trigger   = info->v_pos / 3.0;
 
918
        m_threshold = info->v_pos * 2.0 / 3.0;
 
919
        m_trigger   = info->v_pos / 3.0;
1036
920
 
1037
 
        context->output_is_ac = info->options & DISC_555_OUT_AC;
 
921
        m_output_is_ac = info->options & DISC_555_OUT_AC;
1038
922
        /* Calculate DC shift needed to make squarewave waveform AC */
1039
 
        context->ac_shift     = context->output_is_ac ? -context->v_out_high / 2.0 : 0;
 
923
        m_ac_shift     = m_output_is_ac ? -m_v_out_high / 2.0 : 0;
1040
924
 
1041
925
        /* There are 8 different types of basic oscillators
1042
926
     * depending on the resistors used.  We will determine
1043
927
     * the type of circuit at reset, because the ciruit type
1044
928
     * is constant.  See Below.
1045
929
     */
1046
 
        context->type = (DSD_555_CC__RDIS > 0) | ((DSD_555_CC__RGND  > 0) << 1) | ((DSD_555_CC__RBIAS  > 0) << 2);
 
930
        m_type = (DSD_555_CC__RDIS > 0) | ((DSD_555_CC__RGND  > 0) << 1) | ((DSD_555_CC__RBIAS  > 0) << 2);
1047
931
 
1048
932
        /* optimization if none of the values are nodes */
1049
 
        context->has_rc_nodes = 0;
1050
 
        if (node->input_is_node & DSD_555_CC_RC_MASK)
1051
 
                context->has_rc_nodes = 1;
 
933
        m_has_rc_nodes = 0;
 
934
        if (this->input_is_node() & DSD_555_CC_RC_MASK)
 
935
                m_has_rc_nodes = 1;
1052
936
        else
1053
937
        {
1054
 
                switch (context->type)  /* see dsd_555_cc_reset for descriptions */
 
938
                switch (m_type) /* see dsd_555_cc_reset for descriptions */
1055
939
                {
1056
940
                        case 1:
1057
941
                                r_discharge = DSD_555_CC__RDIS;
1079
963
                                break;
1080
964
                }
1081
965
 
1082
 
                context->exp_bleed  = RC_CHARGE_EXP(DSD_555_CC_T_RC_BLEED);
1083
 
                context->t_rc_discharge_01 = DSD_555_CC_T_RC_DISCHARGE_01;
1084
 
                context->exp_discharge_01  = RC_CHARGE_EXP(context->t_rc_discharge_01);
1085
 
                context->t_rc_discharge_no_i = DSD_555_CC_T_RC_DISCHARGE_NO_I;
1086
 
                context->exp_discharge_no_i  = RC_CHARGE_EXP(context->t_rc_discharge_no_i);
1087
 
                context->t_rc_charge = DSD_555_CC_T_RC_CHARGE;
1088
 
                context->exp_charge  = RC_CHARGE_EXP(context->t_rc_charge);
1089
 
                context->t_rc_discharge = DSD_555_CC_T_RC_DISCHARGE;
1090
 
                context->exp_discharge  = RC_CHARGE_EXP(context->t_rc_discharge);
 
966
                m_exp_bleed  = RC_CHARGE_EXP(DSD_555_CC_T_RC_BLEED);
 
967
                m_t_rc_discharge_01 = DSD_555_CC_T_RC_DISCHARGE_01;
 
968
                m_exp_discharge_01  = RC_CHARGE_EXP(m_t_rc_discharge_01);
 
969
                m_t_rc_discharge_no_i = DSD_555_CC_T_RC_DISCHARGE_NO_I;
 
970
                m_exp_discharge_no_i  = RC_CHARGE_EXP(m_t_rc_discharge_no_i);
 
971
                m_t_rc_charge = DSD_555_CC_T_RC_CHARGE;
 
972
                m_exp_charge  = RC_CHARGE_EXP(m_t_rc_charge);
 
973
                m_t_rc_discharge = DSD_555_CC_T_RC_DISCHARGE;
 
974
                m_exp_discharge  = RC_CHARGE_EXP(m_t_rc_discharge);
1091
975
        }
1092
976
 
1093
977
        /* Step to set the output */
1094
 
        DISCRETE_STEP_CALL(dsd_555_cc);
 
978
        this->step();
1095
979
 
1096
980
        /*
1097
981
     * TYPES:
1246
1130
 
1247
1131
DISCRETE_STEP(dsd_555_vco1)
1248
1132
{
1249
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_vco1)
1250
1133
        DISCRETE_DECLARE_INFO(discrete_555_vco1_desc)
1251
1134
 
1252
1135
        int             count_f = 0;
1256
1139
        double  v_cap;                  /* Current voltage on capacitor, before dt */
1257
1140
        double  v_cap_next = 0; /* Voltage on capacitor, after dt */
1258
1141
 
1259
 
        dt    = node->info->sample_time;        /* Change in time */
1260
 
        v_cap = context->cap_voltage;
 
1142
        double  v_out = 0;
 
1143
 
 
1144
        dt    = this->sample_time();    /* Change in time */
 
1145
        v_cap = m_cap_voltage;
1261
1146
 
1262
1147
        /* Check: if the Control Voltage node is connected. */
1263
 
        if (context->ctrlv_is_node && DSD_555_VCO1__RESET)      /* reset active low */
 
1148
        if (m_ctrlv_is_node && DSD_555_VCO1__RESET)     /* reset active low */
1264
1149
        {
1265
1150
                /* If CV is less then .25V, the circuit will oscillate way out of range.
1266
1151
         * So we will just ignore it when it happens. */
1267
1152
                if (DSD_555_VCO1__VIN2 < .25) return;
1268
1153
                /* If it is a node then calculate thresholds based on Control Voltage */
1269
 
                context->threshold = DSD_555_VCO1__VIN2;
1270
 
                context->trigger   = DSD_555_VCO1__VIN2 / 2.0;
 
1154
                m_threshold = DSD_555_VCO1__VIN2;
 
1155
                m_trigger   = DSD_555_VCO1__VIN2 / 2.0;
1271
1156
                /* Since the thresholds may have changed we need to update the FF */
1272
 
                if (v_cap >= context->threshold)
 
1157
                if (v_cap >= m_threshold)
1273
1158
                {
1274
1159
                        x_time = dt;
1275
 
                        context->flip_flop = 0;
 
1160
                        m_flip_flop = 0;
1276
1161
                        count_f++;
1277
1162
                }
1278
1163
                else
1279
 
                if (v_cap <= context->trigger)
 
1164
                if (v_cap <= m_trigger)
1280
1165
                {
1281
1166
                        x_time = dt;
1282
 
                        context->flip_flop = 1;
 
1167
                        m_flip_flop = 1;
1283
1168
                        count_r++;
1284
1169
                }
1285
1170
        }
1287
1172
        /* Keep looping until all toggling in time sample is used up. */
1288
1173
        do
1289
1174
        {
1290
 
                if (context->flip_flop)
 
1175
                if (m_flip_flop)
1291
1176
                {
1292
1177
                        /* if we are in reset then toggle f/f and discharge */
1293
1178
                        if (!DSD_555_VCO1__RESET)       /* reset active low */
1294
1179
                        {
1295
 
                                context->flip_flop = 0;
 
1180
                                m_flip_flop = 0;
1296
1181
                                count_f++;
1297
1182
                        }
1298
1183
                        else
1299
1184
                        {
1300
1185
                                /* Charging */
1301
1186
                                /* iC=C*dv/dt  works out to dv=iC*dt/C */
1302
 
                                v_cap_next = v_cap + (context->i_charge * dt / info->c);
 
1187
                                v_cap_next = v_cap + (m_i_charge * dt / info->c);
1303
1188
                                dt         = 0;
1304
1189
 
1305
1190
                                /* has it charged past upper limit? */
1306
 
                                if (v_cap_next >= context->threshold)
 
1191
                                if (v_cap_next >= m_threshold)
1307
1192
                                {
1308
1193
                                        /* calculate the overshoot time */
1309
 
                                        dt     = info->c * (v_cap_next - context->threshold) / context->i_charge;
1310
 
                                        v_cap  = context->threshold;
 
1194
                                        dt     = info->c * (v_cap_next - m_threshold) / m_i_charge;
 
1195
                                        v_cap  = m_threshold;
1311
1196
                                        x_time = dt;
1312
 
                                        context->flip_flop = 0;
 
1197
                                        m_flip_flop = 0;
1313
1198
                                        count_f++;
1314
1199
                                }
1315
1200
                        }
1318
1203
                {
1319
1204
                        /* Discharging */
1320
1205
                        /* iC=C*dv/dt  works out to dv=iC*dt/C */
1321
 
                        v_cap_next = v_cap - (context->i_discharge * dt / info->c);
 
1206
                        v_cap_next = v_cap - (m_i_discharge * dt / info->c);
1322
1207
 
1323
1208
                        /* if we are in reset, then the cap can discharge to 0 */
1324
1209
                        if (!DSD_555_VCO1__RESET)       /* reset active low */
1330
1215
                        {
1331
1216
                                /* if we are out of reset and the cap voltage is less then
1332
1217
                 * the lower threshold, toggle f/f and start charging */
1333
 
                                if (v_cap <= context->trigger)
 
1218
                                if (v_cap <= m_trigger)
1334
1219
                                {
1335
 
                                        if (context->flip_flop == 0)
 
1220
                                        if (m_flip_flop == 0)
1336
1221
                                        {
1337
1222
                                                /* don't need to track x_time here */
1338
 
                                                context->flip_flop = 1;
 
1223
                                                m_flip_flop = 1;
1339
1224
                                                count_r++;
1340
1225
                                        }
1341
1226
                                }
1343
1228
                                {
1344
1229
                                        dt = 0;
1345
1230
                                        /* has it discharged past lower limit? */
1346
 
                                        if (v_cap_next <= context->trigger)
 
1231
                                        if (v_cap_next <= m_trigger)
1347
1232
                                        {
1348
1233
                                                /* calculate the overshoot time */
1349
 
                                                dt     = info->c * (v_cap_next - context->trigger) / context->i_discharge;
1350
 
                                                v_cap  = context->trigger;
 
1234
                                                dt     = info->c * (v_cap_next - m_trigger) / m_i_discharge;
 
1235
                                                v_cap  = m_trigger;
1351
1236
                                                x_time = dt;
1352
 
                                                context->flip_flop = 1;
 
1237
                                                m_flip_flop = 1;
1353
1238
                                                count_r++;
1354
1239
                                        }
1355
1240
                                }
1357
1242
                }
1358
1243
        } while(dt);
1359
1244
 
1360
 
        context->cap_voltage = v_cap_next;
 
1245
        m_cap_voltage = v_cap_next;
1361
1246
 
1362
1247
        /* Convert last switch time to a ratio.  No x_time in reset. */
1363
 
        x_time = x_time / node->info->sample_time;
 
1248
        x_time = x_time / this->sample_time();
1364
1249
        if (!DSD_555_VCO1__RESET) x_time = 0;
1365
1250
 
1366
 
        switch (context->output_type)
 
1251
        switch (m_output_type)
1367
1252
        {
1368
1253
                case DISC_555_OUT_SQW:
1369
 
                        node->output[0] = context->flip_flop * context->v_out_high + context->ac_shift;
 
1254
                        v_out = m_flip_flop * m_v_out_high + m_ac_shift;
1370
1255
                        break;
1371
1256
                case DISC_555_OUT_CAP:
1372
 
                        node->output[0] = v_cap_next;
 
1257
                        v_out = v_cap_next;
1373
1258
                        /* Fake it to AC if needed */
1374
 
                        if (context->output_is_ac)
1375
 
                                node->output[0] -= context->threshold * 3.0 /4.0;
 
1259
                        if (m_output_is_ac)
 
1260
                                v_out -= m_threshold * 3.0 /4.0;
1376
1261
                        break;
1377
1262
                case DISC_555_OUT_ENERGY:
1378
1263
                        if (x_time == 0) x_time = 1.0;
1379
 
                        node->output[0]  = context->v_out_high * (context->flip_flop ? x_time : (1.0 - x_time));
1380
 
                        node->output[0] += context->ac_shift;
 
1264
                        v_out =  m_v_out_high * (m_flip_flop ? x_time : (1.0 - x_time));
 
1265
                        v_out += m_ac_shift;
1381
1266
                        break;
1382
1267
                case DISC_555_OUT_LOGIC_X:
1383
 
                        node->output[0] = context->flip_flop + x_time;
 
1268
                        v_out = m_flip_flop + x_time;
1384
1269
                        break;
1385
1270
                case DISC_555_OUT_COUNT_F_X:
1386
 
                        node->output[0] = count_f ? count_f + x_time : count_f;
 
1271
                        v_out = count_f ? count_f + x_time : count_f;
1387
1272
                        break;
1388
1273
                case DISC_555_OUT_COUNT_R_X:
1389
 
                        node->output[0] =  count_r ? count_r + x_time : count_r;
 
1274
                        v_out = count_r ? count_r + x_time : count_r;
1390
1275
                        break;
1391
1276
                case DISC_555_OUT_COUNT_F:
1392
 
                        node->output[0] = count_f;
 
1277
                        v_out = count_f;
1393
1278
                        break;
1394
1279
                case DISC_555_OUT_COUNT_R:
1395
 
                        node->output[0] = count_r;
 
1280
                        v_out = count_r;
1396
1281
                        break;
1397
1282
        }
 
1283
        set_output(0, v_out);
1398
1284
}
1399
1285
 
1400
1286
DISCRETE_RESET(dsd_555_vco1)
1401
1287
{
1402
 
        DISCRETE_DECLARE_CONTEXT(dsd_555_vco1)
1403
1288
        DISCRETE_DECLARE_INFO(discrete_555_vco1_desc)
1404
1289
 
1405
1290
        double v_ratio_r3, v_ratio_r4_1, r_in_1;
1406
1291
 
1407
 
        context->output_type  = info->options & DISC_555_OUT_MASK;
1408
 
        context->output_is_ac = info->options & DISC_555_OUT_AC;
 
1292
        m_output_type  = info->options & DISC_555_OUT_MASK;
 
1293
        m_output_is_ac = info->options & DISC_555_OUT_AC;
1409
1294
 
1410
1295
        /* Setup op-amp parameters */
1411
1296
 
1423
1308
 
1424
1309
        /* Now that we know the voltages entering the op amp and the resistance for the
1425
1310
     * FF states, we can predetermine the ratios for the charge/discharge currents. */
1426
 
        context->i_discharge = (1 - v_ratio_r3) / info->r1;
1427
 
        context->i_charge    = (v_ratio_r3 - v_ratio_r4_1) / r_in_1;
 
1311
        m_i_discharge = (1 - v_ratio_r3) / info->r1;
 
1312
        m_i_charge    = (v_ratio_r3 - v_ratio_r4_1) / r_in_1;
1428
1313
 
1429
1314
        /* the cap starts off discharged */
1430
 
        context->cap_voltage = 0;
 
1315
        m_cap_voltage = 0;
1431
1316
 
1432
1317
        /* Setup 555 parameters */
1433
1318
 
1434
1319
        /* There is no charge on the cap so the 555 goes high at init. */
1435
 
        context->flip_flop     = 1;
1436
 
        context->ctrlv_is_node = (node->input_is_node >> 2) & 1;
1437
 
        context->v_out_high    = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
 
1320
        m_flip_flop     = 1;
 
1321
        m_ctrlv_is_node = (this->input_is_node() >> 2) & 1;
 
1322
        m_v_out_high    = (info->v_out_high == DEFAULT_555_HIGH) ? info->v_pos - 1.2 : info->v_out_high;
1438
1323
 
1439
1324
        /* Calculate 555 thresholds.
1440
1325
     * If the Control Voltage is a node, then the thresholds will be calculated each step.
1441
1326
     * If the Control Voltage is a fixed voltage, then the thresholds will be calculated
1442
1327
     * from that.  Otherwise we will use thresholds based on v_pos. */
1443
 
        if (!context->ctrlv_is_node && (DSD_555_VCO1__VIN2 != -1))
 
1328
        if (!m_ctrlv_is_node && (DSD_555_VCO1__VIN2 != -1))
1444
1329
        {
1445
1330
                /* Setup based on supplied Control Voltage static value */
1446
 
                context->threshold = DSD_555_VCO1__VIN2;
1447
 
                context->trigger   = DSD_555_VCO1__VIN2 / 2.0;
 
1331
                m_threshold = DSD_555_VCO1__VIN2;
 
1332
                m_trigger   = DSD_555_VCO1__VIN2 / 2.0;
1448
1333
        }
1449
1334
        else
1450
1335
        {
1451
1336
                /* Setup based on v_pos power source */
1452
 
                context->threshold = info->v_pos * 2.0 / 3.0;
1453
 
                context->trigger   = info->v_pos / 3.0;
 
1337
                m_threshold = info->v_pos * 2.0 / 3.0;
 
1338
                m_trigger   = info->v_pos / 3.0;
1454
1339
        }
1455
1340
 
1456
1341
        /* Calculate DC shift needed to make squarewave waveform AC */
1457
 
        context->ac_shift = context->output_is_ac ? -context->v_out_high / 2.0 : 0;
 
1342
        m_ac_shift = m_output_is_ac ? -m_v_out_high / 2.0 : 0;
1458
1343
}
1459
1344
 
1460
1345
 
1537
1422
 
1538
1423
DISCRETE_STEP(dsd_566)
1539
1424
{
1540
 
        DISCRETE_DECLARE_CONTEXT(dsd_566)
1541
 
 
1542
1425
        double  i = 0;                  /* Charging current created by vIn */
1543
1426
        double  i_rise;                 /* non-linear rise charge current */
1544
1427
        double  dt;                             /* change in time */
1546
1429
        double  v_cap;                  /* Current voltage on capacitor, before dt */
1547
1430
        int             count_f = 0, count_r = 0;
1548
1431
 
1549
 
        dt    = node->info->sample_time;        /* Change in time */
1550
 
        v_cap = context->cap_voltage;   /* Set to voltage before change */
 
1432
        double  v_out = 0.0;
 
1433
 
 
1434
        dt    = this->sample_time();    /* Change in time */
 
1435
        v_cap = m_cap_voltage;  /* Set to voltage before change */
1551
1436
 
1552
1437
        /* Calculate charging current if it is in range */
1553
 
        if (EXPECTED(DSD_566__VMOD > context->v_osc_stop))
 
1438
        if (EXPECTED(DSD_566__VMOD > m_v_osc_stop))
1554
1439
        {
1555
1440
                double v_charge = DSD_566__VCHARGE - DSD_566__VMOD - 0.1;
1556
1441
                if (v_charge > 0)
1557
1442
                {
1558
1443
                        i = (v_charge * .95) / DSD_566__R;
1559
 
                        if (DSD_566__VMOD < context->v_osc_stable)
 
1444
                        if (DSD_566__VMOD < m_v_osc_stable)
1560
1445
                        {
1561
1446
                                /* no where near correct calculation of non linear range */
1562
 
                                i_rise = ((DSD_566__VCHARGE - context->v_osc_stable - 0.1) * .95) / DSD_566__R;
1563
 
                                i_rise *= 1.0 - (context->v_osc_stable - DSD_566__VMOD) / (context->v_osc_stable - context->v_osc_stop);
 
1447
                                i_rise = ((DSD_566__VCHARGE - m_v_osc_stable - 0.1) * .95) / DSD_566__R;
 
1448
                                i_rise *= 1.0 - (m_v_osc_stable - DSD_566__VMOD) / (m_v_osc_stable - m_v_osc_stop);
1564
1449
                        }
1565
1450
                        else
1566
1451
                                i_rise = i;
1573
1458
        /* Keep looping until all toggling in this time sample is used up. */
1574
1459
        do
1575
1460
        {
1576
 
                if (context->flip_flop)
 
1461
                if (m_flip_flop)
1577
1462
                {
1578
1463
                        /* Discharging */
1579
1464
                        v_cap -= i * dt / DSD_566__C;
1580
1465
                        dt     = 0;
1581
1466
 
1582
1467
                        /* has it discharged past lower limit? */
1583
 
                        if (UNEXPECTED(v_cap < context->threshold_low))
 
1468
                        if (UNEXPECTED(v_cap < m_threshold_low))
1584
1469
                        {
1585
1470
                                /* calculate the overshoot time */
1586
 
                                dt = DSD_566__C * (context->threshold_low - v_cap) / i;
1587
 
                                v_cap = context->threshold_low;
1588
 
                                context->flip_flop = 0;
 
1471
                                dt = DSD_566__C * (m_threshold_low - v_cap) / i;
 
1472
                                v_cap = m_threshold_low;
 
1473
                                m_flip_flop = 0;
1589
1474
                                count_f++;
1590
1475
                                x_time = dt;
1591
1476
                        }
1604
1489
                        if (UNEXPECTED(v_cap > DSD_566__VMOD)) v_cap = DSD_566__VMOD;
1605
1490
 
1606
1491
                        /* has it charged past upper limit? */
1607
 
                        if (UNEXPECTED(v_cap > context->threshold_high))
 
1492
                        if (UNEXPECTED(v_cap > m_threshold_high))
1608
1493
                        {
1609
1494
                                /* calculate the overshoot time */
1610
 
                                dt = DSD_566__C * (v_cap - context->threshold_high) / i;
1611
 
                                v_cap = context->threshold_high;
1612
 
                                context->flip_flop = 1;
 
1495
                                dt = DSD_566__C * (v_cap - m_threshold_high) / i;
 
1496
                                v_cap = m_threshold_high;
 
1497
                                m_flip_flop = 1;
1613
1498
                                count_r++;
1614
1499
                                x_time = dt;
1615
1500
                        }
1616
1501
                }
1617
1502
        } while(dt);
1618
1503
 
1619
 
        context->cap_voltage = v_cap;
 
1504
        m_cap_voltage = v_cap;
1620
1505
 
1621
1506
        /* Convert last switch time to a ratio */
1622
 
        x_time /= node->info->sample_time;
 
1507
        x_time /= this->sample_time();
1623
1508
 
1624
 
        switch (context->out_type)
 
1509
        switch (m_out_type)
1625
1510
        {
1626
1511
                case DISC_566_OUT_SQUARE:
1627
 
                        node->output[0] = context->flip_flop ? context->v_sqr_high : context->v_sqr_low;
1628
 
                        if (context->fake_ac)
1629
 
                                node->output[0] += context->ac_shift;
 
1512
                        v_out = m_flip_flop ? m_v_sqr_high : m_v_sqr_low;
 
1513
                        if (m_fake_ac)
 
1514
                                v_out += m_ac_shift;
1630
1515
                        break;
1631
1516
                case DISC_566_OUT_ENERGY:
1632
1517
                        if (x_time == 0) x_time = 1.0;
1633
 
                        node->output[0]  = context->v_sqr_low + context->v_sqr_diff * (context->flip_flop ? x_time : (1.0 - x_time));
1634
 
                        if (context->fake_ac)
1635
 
                                node->output[0] += context->ac_shift;
 
1518
                        v_out = m_v_sqr_low + m_v_sqr_diff * (m_flip_flop ? x_time : (1.0 - x_time));
 
1519
                        if (m_fake_ac)
 
1520
                                v_out += m_ac_shift;
1636
1521
                        break;
1637
1522
                case DISC_566_OUT_LOGIC:
1638
 
                                node->output[0] = context->flip_flop;
 
1523
                        v_out = m_flip_flop;
1639
1524
                        break;
1640
1525
                case DISC_566_OUT_TRIANGLE:
1641
 
                        node->output[0] = v_cap;
1642
 
                        if (context->fake_ac)
1643
 
                                node->output[0] += context->ac_shift;
 
1526
                        v_out = v_cap;
 
1527
                        if (m_fake_ac)
 
1528
                                v_out += m_ac_shift;
1644
1529
                        break;
1645
1530
                case DISC_566_OUT_COUNT_F_X:
1646
 
                        node->output[0] = count_f ? count_f + x_time : count_f;
 
1531
                        v_out = count_f ? count_f + x_time : count_f;
1647
1532
                        break;
1648
1533
                case DISC_566_OUT_COUNT_R_X:
1649
 
                        node->output[0] =  count_r ? count_r + x_time : count_r;
 
1534
                        v_out = count_r ? count_r + x_time : count_r;
1650
1535
                        break;
1651
1536
                case DISC_566_OUT_COUNT_F:
1652
 
                        node->output[0] = count_f;
 
1537
                        v_out = count_f;
1653
1538
                        break;
1654
1539
                case DISC_566_OUT_COUNT_R:
1655
 
                        node->output[0] = count_r;
 
1540
                        v_out = count_r;
1656
1541
                        break;
1657
1542
        }
 
1543
        set_output(0, v_out);
1658
1544
}
1659
1545
 
1660
1546
DISCRETE_RESET(dsd_566)
1661
1547
{
1662
 
        DISCRETE_DECLARE_CONTEXT(dsd_566)
1663
 
 
1664
1548
        int             v_int;
1665
1549
        double  v_float;
1666
1550
 
1667
 
        context->out_type = (int)DSD_566__OPTIONS & DISC_566_OUT_MASK;
1668
 
        context->fake_ac =  (int)DSD_566__OPTIONS & DISC_566_OUT_AC;
 
1551
        m_out_type = (int)DSD_566__OPTIONS & DISC_566_OUT_MASK;
 
1552
        m_fake_ac =  (int)DSD_566__OPTIONS & DISC_566_OUT_AC;
1669
1553
 
1670
1554
        if (DSD_566__VNEG >= DSD_566__VPOS)
1671
 
                fatalerror("[v_neg >= v_pos] in NODE_%d!\n", NODE_BLOCKINDEX(node));
 
1555
                fatalerror("[v_neg >= v_pos] in NODE_%d!\n", this->index());
1672
1556
 
1673
1557
        v_float = DSD_566__VPOS - DSD_566__VNEG;
1674
1558
        v_int = (int)v_float;
1675
1559
        if ( v_float < 10 || v_float > 15 )
1676
 
                fatalerror("v_neg and/or v_pos out of range in NODE_%d\n", NODE_BLOCKINDEX(node));
 
1560
                fatalerror("v_neg and/or v_pos out of range in NODE_%d\n", this->index());
1677
1561
        if ( v_float != v_int )
1678
1562
                /* fatal for now. */
1679
 
                fatalerror("Power should be integer in NODE_%d\n", NODE_BLOCKINDEX(node));
 
1563
                fatalerror("Power should be integer in NODE_%d\n", this->index());
1680
1564
 
1681
 
        context->flip_flop   = 0;
1682
 
        context->cap_voltage = 0;
 
1565
        m_flip_flop   = 0;
 
1566
        m_cap_voltage = 0;
1683
1567
 
1684
1568
        v_int -= 10;
1685
 
        context->threshold_high = ne566.c_high[v_int] + DSD_566__VNEG;
1686
 
        context->threshold_low  = ne566.c_low[v_int] + DSD_566__VNEG;
1687
 
        context->v_sqr_high     = DSD_566__VPOS - 1;
1688
 
        context->v_sqr_low      = ne566.sqr_low[v_int] + DSD_566__VNEG;
1689
 
        context->v_sqr_diff     = context->v_sqr_high - context->v_sqr_low;
1690
 
        context->v_osc_stable   = ne566.osc_stable[v_int] + DSD_566__VNEG;
1691
 
        context->v_osc_stop             = ne566.osc_stop[v_int] + DSD_566__VNEG;
 
1569
        m_threshold_high = ne566.c_high[v_int] + DSD_566__VNEG;
 
1570
        m_threshold_low  = ne566.c_low[v_int] + DSD_566__VNEG;
 
1571
        m_v_sqr_high     = DSD_566__VPOS - 1;
 
1572
        m_v_sqr_low      = ne566.sqr_low[v_int] + DSD_566__VNEG;
 
1573
        m_v_sqr_diff     = m_v_sqr_high - m_v_sqr_low;
 
1574
        m_v_osc_stable  = ne566.osc_stable[v_int] + DSD_566__VNEG;
 
1575
        m_v_osc_stop            = ne566.osc_stop[v_int] + DSD_566__VNEG;
1692
1576
 
1693
 
        context->ac_shift = 0;
1694
 
        if (context->fake_ac)
 
1577
        m_ac_shift = 0;
 
1578
        if (m_fake_ac)
1695
1579
        {
1696
 
                if (context->out_type == DISC_566_OUT_TRIANGLE)
1697
 
                        context->ac_shift = (context->threshold_high - context->threshold_low) / 2 - context->threshold_high;
 
1580
                if (m_out_type == DISC_566_OUT_TRIANGLE)
 
1581
                        m_ac_shift = (m_threshold_high - m_threshold_low) / 2 - m_threshold_high;
1698
1582
                else
1699
 
                        context->ac_shift = context->v_sqr_diff / 2 - context->v_sqr_high;
 
1583
                        m_ac_shift = m_v_sqr_diff / 2 - m_v_sqr_high;
1700
1584
        }
1701
1585
 
1702
1586
        /* Step the output */
1703
 
        DISCRETE_STEP_CALL(dsd_566);
 
1587
        this->step();
1704
1588
}
1705
1589
 
1706
1590
 
1760
1644
 
1761
1645
DISCRETE_STEP(dsd_ls624)
1762
1646
{
1763
 
        DISCRETE_DECLARE_CONTEXT(dsd_ls624)
1764
 
 
1765
1647
        double  x_time = 0;
1766
1648
        double  freq, t1;
1767
1649
        double  v_freq_2, v_freq_3, v_freq_4;
1768
 
        double  t_used = context->t_used;
1769
 
        double  dt = node->info->sample_time;;
 
1650
        double  t_used = m_t_used;
 
1651
        double  dt = this->sample_time();;
1770
1652
        double  v_freq = DSD_LS624__VMOD;
1771
1653
        double  v_rng = DSD_LS624__VRNG;
1772
1654
        int             count_f = 0, count_r = 0;
1787
1669
                return;
1788
1670
 
1789
1671
        /* scale due to input resistance */
1790
 
        v_freq *= context->v_freq_scale;
1791
 
        v_rng *= context->v_rng_scale;
 
1672
        v_freq *= m_v_freq_scale;
 
1673
        v_rng *= m_v_rng_scale;
1792
1674
 
1793
1675
        /* apply cap if needed */
1794
 
        if (context->has_freq_in_cap)
 
1676
        if (m_has_freq_in_cap)
1795
1677
        {
1796
 
                context->v_cap_freq_in += (v_freq - context->v_cap_freq_in) * context->exponent;
1797
 
                v_freq = context->v_cap_freq_in;
 
1678
                m_v_cap_freq_in += (v_freq - m_v_cap_freq_in) * m_exponent;
 
1679
                v_freq = m_v_cap_freq_in;
1798
1680
        }
1799
1681
 
1800
1682
        /* Polyfunctional3D_model created by zunzun.com using sum of squared absolute error */
1815
1697
        freq *= CAP_U(0.1) / DSD_LS624__C;
1816
1698
 
1817
1699
        t1 = 0.5 / freq ;
1818
 
        t_used += node->info->sample_time;
 
1700
        t_used += this->sample_time();
1819
1701
        do
1820
1702
        {
1821
1703
                dt = 0;
1823
1705
                {
1824
1706
                        /* calculate the overshoot time */
1825
1707
                        t_used -= t1;
1826
 
                        context->flip_flop ^= 1;
1827
 
                        if (context->flip_flop)
 
1708
                        m_flip_flop ^= 1;
 
1709
                        if (m_flip_flop)
1828
1710
                                count_r++;
1829
1711
                        else
1830
1712
                                count_f++;
1831
1713
                        /* fix up any frequency increase change errors */
1832
 
                        while(t_used > node->info->sample_time)
1833
 
                                t_used -= node->info->sample_time;
 
1714
                        while(t_used > this->sample_time())
 
1715
                                t_used -= this->sample_time();
1834
1716
                        x_time = t_used;
1835
1717
                        dt = t_used;
1836
1718
                }
1837
1719
        }while(dt);
1838
1720
 
1839
 
        context->t_used = t_used;
 
1721
        m_t_used = t_used;
1840
1722
 
1841
1723
        /* Convert last switch time to a ratio */
1842
 
        x_time = x_time / node->info->sample_time;
 
1724
        x_time = x_time / this->sample_time();
1843
1725
 
1844
 
        switch (context->out_type)
 
1726
        switch (m_out_type)
1845
1727
        {
1846
1728
                case DISC_LS624_OUT_LOGIC_X:
1847
 
                                node->output[0] = context->flip_flop  + x_time;
 
1729
                        set_output(0,  m_flip_flop  + x_time);
1848
1730
                        break;
1849
1731
                case DISC_LS624_OUT_COUNT_F_X:
1850
 
                        node->output[0] = count_f ? count_f + x_time : count_f;
 
1732
                        set_output(0,  count_f ? count_f + x_time : count_f);
1851
1733
                        break;
1852
1734
                case DISC_LS624_OUT_COUNT_R_X:
1853
 
                        node->output[0] =  count_r ? count_r + x_time : count_r;
 
1735
                        set_output(0,   count_r ? count_r + x_time : count_r);
1854
1736
                        break;
1855
1737
                case DISC_LS624_OUT_COUNT_F:
1856
 
                        node->output[0] = count_f;
 
1738
                        set_output(0,  count_f);
1857
1739
                        break;
1858
1740
                case DISC_LS624_OUT_COUNT_R:
1859
 
                        node->output[0] = count_r;
 
1741
                        set_output(0,  count_r);
1860
1742
                        break;
1861
1743
                case DISC_LS624_OUT_ENERGY:
1862
1744
                        if (x_time == 0) x_time = 1.0;
1863
 
                        node->output[0] = LS624_OUT_HIGH * (context->flip_flop ? x_time : (1.0 - x_time));
 
1745
                        set_output(0,  LS624_OUT_HIGH * (m_flip_flop ? x_time : (1.0 - x_time)));
1864
1746
                        break;
1865
1747
                case DISC_LS624_OUT_LOGIC:
1866
 
                                node->output[0] = context->flip_flop;
 
1748
                                set_output(0,  m_flip_flop);
1867
1749
                        break;
1868
1750
                case DISC_LS624_OUT_SQUARE:
1869
 
                        node->output[0] = context->flip_flop ? LS624_OUT_HIGH : 0;
 
1751
                        set_output(0,  m_flip_flop ? LS624_OUT_HIGH : 0);
1870
1752
                        break;
1871
1753
        }
1872
1754
}
1873
1755
 
1874
1756
DISCRETE_RESET(dsd_ls624)
1875
1757
{
1876
 
        struct dsd_ls624_context *context = (struct dsd_ls624_context *)node->context;
1877
 
 
1878
 
        context->out_type = (int)DSD_LS624__OUTTYPE;
1879
 
 
1880
 
        context->flip_flop = 0;
1881
 
        context->t_used = 0;
1882
 
        context->v_freq_scale = LS624_IN_R / (DSD_LS624__R_FREQ_IN + LS624_IN_R);
1883
 
        context->v_rng_scale = LS624_IN_R / (DSD_LS624__R_RNG_IN + LS624_IN_R);
 
1758
        m_out_type = (int)DSD_LS624__OUTTYPE;
 
1759
 
 
1760
        m_flip_flop = 0;
 
1761
        m_t_used = 0;
 
1762
        m_v_freq_scale = LS624_IN_R / (DSD_LS624__R_FREQ_IN + LS624_IN_R);
 
1763
        m_v_rng_scale = LS624_IN_R / (DSD_LS624__R_RNG_IN + LS624_IN_R);
1884
1764
        if (DSD_LS624__C_FREQ_IN > 0)
1885
1765
        {
1886
 
                context->has_freq_in_cap = 1;
1887
 
                context->exponent = RC_CHARGE_EXP(RES_2_PARALLEL(DSD_LS624__R_FREQ_IN, LS624_IN_R) * DSD_LS624__C_FREQ_IN);
1888
 
                context->v_cap_freq_in = 0;
 
1766
                m_has_freq_in_cap = 1;
 
1767
                m_exponent = RC_CHARGE_EXP(RES_2_PARALLEL(DSD_LS624__R_FREQ_IN, LS624_IN_R) * DSD_LS624__C_FREQ_IN);
 
1768
                m_v_cap_freq_in = 0;
1889
1769
        }
1890
1770
        else
1891
 
                context->has_freq_in_cap = 0;
 
1771
                m_has_freq_in_cap = 0;
1892
1772
 
1893
 
        node->output[0] = 0;
 
1773
        set_output(0,  0);
1894
1774
}