summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine/74145.c
blob: 3cb15e899a36aa42be959910c29ab699ed59312e (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*****************************************************************************
 *
 *  TTL74145
 *
 *  license: MAME, GPL-2.0+
 *  copyright-holders: Dirk Best
 *
 *  BCD-to-Decimal decoder
 *
 *        __ __
 *     0-|  v  |-VCC
 *     1-|     |-A
 *     2-|     |-B
 *     3-|     |-C
 *     4-|     |-D
 *     5-|     |-9
 *     6-|     |-8
 *   GND-|_____|-7
 *
 *
 * Truth table
 *  _______________________________
 * | Inputs  | Outputs             |
 * | D C B A | 0 1 2 3 4 5 6 7 8 9 |
 * |-------------------------------|
 * | L L L L | L H H H H H H H H H |
 * | L L L H | H L H H H H H H H H |
 * | L L H L | H H L H H H H H H H |
 * | L L H H | H H H L H H H H H H |
 * | L H L L | H H H H L H H H H H |
 * |-------------------------------|
 * | L H L H | H H H H H L H H H H |
 * | L H H L | H H H H H H L H H H |
 * | L H H H | H H H H H H H L H H |
 * | H L L L | H H H H H H H H L H |
 * | H L L H | H H H H H H H H H L |
 * |-------------------------------|
 * | H L H L | H H H H H H H H H H |
 * | H L H H | H H H H H H H H H H |
 * | H H L L | H H H H H H H H H H |
 * | H H L H | H H H H H H H H H H |
 * | H H H L | H H H H H H H H H H |
 * | H H H H | H H H H H H H H H H |
 *  -------------------------------
 *
 ****************************************************************************/

#include "emu.h"
#include "74145.h"
#include "coreutil.h"

/*****************************************************************************
    GLOBAL VARIABLES
*****************************************************************************/

const ttl74145_interface default_ttl74145 =
{
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL
};


const device_type TTL74145 = &device_creator<ttl74145_device>;

/***************************************************************************
    DEVICE INTERFACE
***************************************************************************/
//-------------------------------------------------
//  ttl74145_device - constructor
//-------------------------------------------------

ttl74145_device::ttl74145_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, TTL74145, "TTL74145", tag, owner, clock, "ttl74145", __FILE__)
	, m_number(0)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void ttl74145_device::device_start()
{
	/* resolve callbacks */
	m_output_line_0_func.resolve(m_output_line_0_cb, *this);
	m_output_line_1_func.resolve(m_output_line_1_cb, *this);
	m_output_line_2_func.resolve(m_output_line_2_cb, *this);
	m_output_line_3_func.resolve(m_output_line_3_cb, *this);
	m_output_line_4_func.resolve(m_output_line_4_cb, *this);
	m_output_line_5_func.resolve(m_output_line_5_cb, *this);
	m_output_line_6_func.resolve(m_output_line_6_cb, *this);
	m_output_line_7_func.resolve(m_output_line_7_cb, *this);
	m_output_line_8_func.resolve(m_output_line_8_cb, *this);
	m_output_line_9_func.resolve(m_output_line_9_cb, *this);

	// register for state saving
	save_item(NAME(m_number));
}

//-------------------------------------------------
//  device_config_complete - perform any
//  operations now that the configuration is
//  complete
//-------------------------------------------------

void ttl74145_device::device_config_complete()
{
	// inherit a copy of the static data
	const ttl74145_interface *intf = reinterpret_cast<const ttl74145_interface *>(static_config());
	if (intf != NULL)
		*static_cast<ttl74145_interface *>(this) = *intf;

	// or initialize to defaults if none provided
	else
	{
		memset(&m_output_line_0_cb, 0, sizeof(m_output_line_0_cb));
		memset(&m_output_line_1_cb, 0, sizeof(m_output_line_1_cb));
		memset(&m_output_line_2_cb, 0, sizeof(m_output_line_2_cb));
		memset(&m_output_line_3_cb, 0, sizeof(m_output_line_3_cb));
		memset(&m_output_line_4_cb, 0, sizeof(m_output_line_4_cb));
		memset(&m_output_line_5_cb, 0, sizeof(m_output_line_5_cb));
		memset(&m_output_line_6_cb, 0, sizeof(m_output_line_6_cb));
		memset(&m_output_line_7_cb, 0, sizeof(m_output_line_7_cb));
		memset(&m_output_line_8_cb, 0, sizeof(m_output_line_8_cb));
		memset(&m_output_line_9_cb, 0, sizeof(m_output_line_9_cb));
	}
}

//-------------------------------------------------
//  device_start - device-specific reset
//-------------------------------------------------

void ttl74145_device::device_reset()
{
	m_number = 0;
}

/***************************************************************************
    IMPLEMENTATION
***************************************************************************/

void ttl74145_device::write(UINT8 data)
{
	/* decode number */
	UINT16 new_number = bcd_2_dec(data & 0x0f);

	/* call output callbacks if the number changed */
	if (new_number != m_number)
	{
		m_output_line_0_func(new_number == 0);
		m_output_line_1_func(new_number == 1);
		m_output_line_2_func(new_number == 2);
		m_output_line_3_func(new_number == 3);
		m_output_line_4_func(new_number == 4);
		m_output_line_5_func(new_number == 5);
		m_output_line_6_func(new_number == 6);
		m_output_line_7_func(new_number == 7);
		m_output_line_8_func(new_number == 8);
		m_output_line_9_func(new_number == 9);
	}

	/* update state */
	m_number = new_number;
}


UINT16 ttl74145_device::read()
{
	return (1 << m_number) & 0x3ff;
}