summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/74123.h
blob: 075e56c8206e1547401af8387ffe062309345735 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// license:BSD-3-Clause
// copyright-holders:Couriersud
/*****************************************************************************

    74123 monoflop emulator

    There are 2 monoflops per chips.

    Pin out:

              +--------+
          B1  |1 | | 16|  Vcc
          A1 o|2  -  15|  RCext1
      Clear1 o|3     14|  Cext1
    *Output1 o|4     13|  Output1
     Output2  |5     12|o *Output2
       Cext2  |6     11|o Clear2
      RCext2  |7     10|  B2
         GND  |8      9|o A2
              +--------+

    All resistor values in Ohms.
    All capacitor values in Farads.


    Truth table:

    C   A   B | Q  /Q
    ----------|-------
    L   X   X | L   H
    X   H   X | L   H
    X   X   L | L   H
    H   L  _- |_-_ -_-
    H  -_   H |_-_ -_-
    _-  L   H |_-_ -_-
    ------------------
    C   = clear
    L   = LO (0)
    H   = HI (1)
    X   = any state
    _-  = raising edge
    -_  = falling edge
    _-_ = positive pulse
    -_- = negative pulse

*****************************************************************************/

#ifndef MAME_MACHINE_74123_H
#define MAME_MACHINE_74123_H

#pragma once




/***************************************************************************
    DEVICE CONFIGURATION MACROS
***************************************************************************/

#define MCFG_TTL74123_CONNECTION_TYPE(_ctype) \
	downcast<ttl74123_device &>(*device).set_connection_type(_ctype);

#define MCFG_TTL74123_RESISTOR_VALUE(_value) \
	downcast<ttl74123_device &>(*device).set_resistor_value(_value);

#define MCFG_TTL74123_CAPACITOR_VALUE(_value) \
	downcast<ttl74123_device &>(*device).set_capacitor_value(_value);

#define MCFG_TTL74123_A_PIN_VALUE(_value) \
	downcast<ttl74123_device &>(*device).set_a_pin_value(_value);

#define MCFG_TTL74123_B_PIN_VALUE(_value) \
	downcast<ttl74123_device &>(*device).set_b_pin_value(_value);

#define MCFG_TTL74123_CLEAR_PIN_VALUE(_value) \
	downcast<ttl74123_device &>(*device).set_clear_pin_value(_value);

#define MCFG_TTL74123_OUTPUT_CHANGED_CB(_devcb) \
	devcb = &downcast<ttl74123_device &>(*device).set_output_changed_callback(DEVCB_##_devcb);

/* constants for the different ways the cap/res can be connected.
   This determines the formula for calculating the pulse width */
#define TTL74123_NOT_GROUNDED_NO_DIODE      (1)
#define TTL74123_NOT_GROUNDED_DIODE         (2)
#define TTL74123_GROUNDED                   (3)


/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

// ======================> ttl74123_device

class ttl74123_device :  public device_t
{
public:
	// construction/destruction
	ttl74123_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	void set_connection_type(int type) { m_connection_type = type; }
	void set_resistor_value(double value) { m_res = value; }
	void set_capacitor_value(double value) { m_cap = value; }
	void set_a_pin_value(int value) { m_a = value; }
	void set_b_pin_value(int value) { m_b = value; }
	void set_clear_pin_value(int value) { m_clear = value; }
	template <class Object> devcb_base &set_output_changed_callback(Object &&cb) { return m_output_changed_cb.set_callback(std::forward<Object>(cb)); }

	DECLARE_WRITE_LINE_MEMBER(a_w);
	DECLARE_WRITE_LINE_MEMBER(b_w);
	DECLARE_WRITE_LINE_MEMBER(clear_w);
	DECLARE_WRITE_LINE_MEMBER(reset_w);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_post_load() override { }
	virtual void device_clock_changed() override { }

	TIMER_CALLBACK_MEMBER( output_callback );
	TIMER_CALLBACK_MEMBER( clear_callback );

private:
	int timer_running();
	void start_pulse();
	void set_output();
	attotime compute_duration();

	emu_timer *m_timer;
	int m_connection_type;  /* the hook up type - one of the constants above */
	double m_res;           /* resistor connected to RCext */
	double m_cap;           /* capacitor connected to Cext and RCext */
	int m_a;                /* initial/constant value of the A pin */
	int m_b;                /* initial/constant value of the B pin */
	int m_clear;            /* initial/constant value of the Clear pin */
	devcb_write_line  m_output_changed_cb;
};


// device type definition
DECLARE_DEVICE_TYPE(TTL74123, ttl74123_device)

#endif // MAME_MACHINE_74123_H