1 /*****************************************************************************
2 
3   74153 Dual 4-line to 1-line data selectors/multiplexers
4 
5 
6   Pin layout and functions to access pins:
7 
8   enable_w(0)        [1] /1G   VCC [16]
9   b_w                [2] B     /2G [15]  enable_w(1)
10   input_line_w(0,3)  [3] 1C3	 A [14]  a_w
11   input_line_w(0,2)  [4] 1C2   2C3 [13]  input_line_w(1,3)
12   input_line_w(0,1)  [5] 1C1   2C2 [12]  input_line_w(1,2)
13   input_line_w(0,0)  [6] 1C0   2C1 [11]  input_line_w(1,1)
14   output_r(0)        [7] 1Y	   2C0 [10]  input_line_w(1,0)
15 	                 [8] GND    2Y [9]   output_r(1)
16 
17 
18   Truth table (all logic levels indicate the actual voltage on the line):
19 
20   	        INPUTS         | OUTPUT
21                            |
22 	G | B  A | C0 C1 C2 C3 | Y
23 	--+------+-------------+---
24 1	H |	X  X | X  X  X  X  | L
25 2 	L | L  L | X  X  X  X  | C0
26 3 	L | L  H | X  X  X  X  | C1
27 4 	L | H  L | X  X  X  X  | C2
28 5 	L | H  H | X  X  X  X  | C3
29 	--+------+-------------+---
30 	L	= lo (0)
31 	H	= hi (1)
32 	X	= any state
33 
34 *****************************************************************************/
35 
36 #include "driver.h"
37 #include "machine/74153.h"
38 
39 
40 #define MAX_TTL74153 4
41 
42 struct TTL74153
43 {
44 	/* callback */
45 	void (*output_cb)(void);
46 
47 	/* inputs */
48 	int a;					/* pin 14 */
49 	int b;					/* pin 2 */
50 	int input_lines[2][4];	/* pins 3-6,10-13 */
51 	int enable[2];			/* pins 1,9 */
52 
53 	/* output */
54 	int output[2];			/* pins 7,9 */
55 
56 	/* internals */
57 	int last_output[2];
58 };
59 
60 static struct TTL74153 chips[MAX_TTL74153];
61 
62 
TTL74153_update(int which)63 void TTL74153_update(int which)
64 {
65 	int sel;
66 	int section;
67 
68 
69 	sel = (chips[which].b << 1) | chips[which].a;
70 
71 
72 	/* process both sections */
73 	for (section = 0; section < 2; section++)
74 	{
75 		if (chips[which].enable[section])
76 			chips[which].output[section] = 0;	// row 1 in truth table
77 		else
78 			chips[which].output[section] = chips[which].input_lines[section][sel];
79 	}
80 
81 
82 	/* call callback if either of the outputs changed */
83 	if (  chips[which].output_cb &&
84 		((chips[which].output[0] != chips[which].last_output[0]) ||
85 		 (chips[which].output[1] != chips[which].last_output[1])))
86 	{
87 		chips[which].last_output[0] = chips[which].output[0];
88 		chips[which].last_output[1] = chips[which].output[1];
89 
90 		chips[which].output_cb();
91 	}
92 }
93 
94 
TTL74153_a_w(int which,int data)95 void TTL74153_a_w(int which, int data)
96 {
97 	chips[which].a = data ? 1 : 0;
98 }
99 
100 
TTL74153_b_w(int which,int data)101 void TTL74153_b_w(int which, int data)
102 {
103 	chips[which].b = data ? 1 : 0;
104 }
105 
106 
TTL74153_input_line_w(int which,int section,int input_line,int data)107 void TTL74153_input_line_w(int which, int section, int input_line, int data)
108 {
109 	chips[which].input_lines[section][input_line] = data ? 1 : 0;
110 }
111 
112 
TTL74153_enable_w(int which,int section,int data)113 void TTL74153_enable_w(int which, int section, int data)
114 {
115 	chips[which].enable[section] = data ? 1 : 0;
116 }
117 
118 
TTL74153_output_r(int which,int section)119 int TTL74153_output_r(int which, int section)
120 {
121 	return chips[which].output[section];
122 }
123 
124 
125 
TTL74153_config(int which,const struct TTL74153_interface * intf)126 void TTL74153_config(int which, const struct TTL74153_interface *intf)
127 {
128 	if (which >= MAX_TTL74153)
129 	{
130 		logerror("Only %d 74153's are supported at this time.\n", MAX_TTL74153);
131 		return;
132 	}
133 
134 
135 	chips[which].output_cb = (intf ? intf->output_cb : 0);
136 	chips[which].a = 1;
137 	chips[which].b = 1;
138 	chips[which].enable[0] = 1;
139 	chips[which].enable[1] = 1;
140 	chips[which].input_lines[0][0] = 1;
141 	chips[which].input_lines[0][1] = 1;
142 	chips[which].input_lines[0][2] = 1;
143 	chips[which].input_lines[0][3] = 1;
144 	chips[which].input_lines[1][0] = 1;
145 	chips[which].input_lines[1][1] = 1;
146 	chips[which].input_lines[1][2] = 1;
147 	chips[which].input_lines[1][3] = 1;
148 
149 	chips[which].last_output[0] = -1;
150 	chips[which].last_output[1] = -1;
151 }
152