summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/bagman.cpp
blob: ede20bbb5136c91fe81f874adf0504e712419343 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
/***************************************************************************

  bagman.c

  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  I/O ports)

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

#include "emu.h"
#include "includes/bagman.h"


/*Creation date: 98-02-18 */
/*  A few words of comment:
**
**   What's inside of this file is a PAL16R6 emulator. Maybe someday we will
**need to use it for some other game too. We will need to make it more exact
**then (some of the functionality of this chip IS NOT implemented). However I
**have bought a book about PALs and I'm able to improve it. Just LMK.
**  Jarek Burczynski
**  bujar at mame dot net
*/


/*      64 rows x 32 columns
**  1 - fuse blown: disconnected from input (equal to 1)
**  0 - fuse not blown: connected to input (ie. x, not x, q, not q accordingly)
*/
static const UINT8 fusemap[64*32]=
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,1,1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, column, val;

/*calculate all rows ANDs*/
	for (row = 0; row < 64; row++)
	{
		rowoffs = row*32;
		val = 1; /*prepare for AND */
		for (column = 0; column < 32; column++)
		{
			if ( fusemap[ rowoffs + column ] == 0 )
				val &= m_columnvalue[column];
		}
		m_andmap[row] = val;
	}

/* I/O pin #19 */
	val = 0; /*prepare for OR*/
	for (row = 1; row < 8; row++)
		val |= m_andmap[row];
	if (m_andmap[0] == 1)
	{
		m_columnvalue[2] = 1-val;
		m_columnvalue[3] = val;
		m_outvalue[0]    = 1-val;
	}
	else
	{
		/*pin is in INPUT configuration so it doesn't create output...*/
		m_columnvalue[2] = 0;
		m_columnvalue[3] = 1;
	}

/* O pin #18 (D1) */
	val = 0; /*prepare for OR*/
	for (row = 8; row < 16; row++)
		val |= m_andmap[row];
	m_columnvalue[6] = 1-val;
	m_columnvalue[7] = val;
	m_outvalue[1]    = 1-val;

/* O pin #17 (D2) */
	val = 0; /*prepare for OR*/
	for (row = 16; row < 24; row++)
		val |= m_andmap[row];
	m_columnvalue[10] = 1-val;
	m_columnvalue[11] = val;
	m_outvalue[2]     = 1-val;

/* O pin #16 (D3) */
	val = 0; /*prepare for OR*/
	for (row = 24; row < 32; row++)
		val |= m_andmap[row];
	m_columnvalue[14] = 1-val;
	m_columnvalue[15] = val;
	m_outvalue[3]     = 1-val;

/* O pin #15 (D4) */
	val = 0; /*prepare for OR*/
	for (row = 32; row < 40; row++)
		val |= m_andmap[row];
	m_columnvalue[18] = 1-val;
	m_columnvalue[19] = val;
	m_outvalue[4]     = 1-val;

/* O pin #14 (D5) */
	val = 0; /*prepare for OR*/
	for (row = 40; row < 48; row++)
		val |= m_andmap[row];
	m_columnvalue[22] = 1-val;
	m_columnvalue[23] = val;
	m_outvalue[5]     = 1-val;

/* O pin #13 (D6) */
	val = 0; /*prepare for OR*/
	for (row = 48; row < 56; row++)
		val |= m_andmap[row];
	m_columnvalue[26] = 1-val;
	m_columnvalue[27] = val;
	m_outvalue[6]     = 1-val;

/* I/O pin #12 */
	val = 0; /*prepare for OR*/
	for (row = 57; row < 64; row++)
		val |= m_andmap[row];
	if (m_andmap[56] == 1)
	{
		m_columnvalue[30] = 1-val;
		m_columnvalue[31] = val;
		m_outvalue[7]     = 1-val;
	}
	else
	{
		/*pin is in INPUT configuration so it doesn't create output...*/
		m_columnvalue[30] = 0;
		m_columnvalue[31] = 1;
	}

}


WRITE8_MEMBER(bagman_state::pal16r6_w)
{
UINT8 line;

	line = offset * 4;
	m_columnvalue[line    ] = data & 1;
	m_columnvalue[line + 1] = 1 - (data & 1);
}

void bagman_state::machine_reset()
{
	address_space &space = m_maincpu->space(AS_PROGRAM);
	pal16r6_w(space, 0, 1);  /*pin 2*/
	pal16r6_w(space, 1, 1);  /*pin 3*/
	pal16r6_w(space, 2, 1);  /*pin 4*/
	pal16r6_w(space, 3, 1);  /*pin 5*/
	pal16r6_w(space, 4, 1);  /*pin 6*/
	pal16r6_w(space, 5, 1);  /*pin 7*/
	pal16r6_w(space, 6, 1);  /*pin 8*/
	pal16r6_w(space, 7, 1);  /*pin 9*/
	update_pal();
}

READ8_MEMBER(bagman_state::pal16r6_r)
{
	update_pal();
	return  (m_outvalue[6]) + (m_outvalue[5] << 1) + (m_outvalue[4] << 2) +
		(m_outvalue[3] << 3) + (m_outvalue[2] << 4) + (m_outvalue[1] << 5);

/* Bagman schematics show that this is right mapping order of PAL outputs to bits.
** This is the PAL 16R6 shown almost in the middle of the schematics.
** The /RD4 line goes low (active) whenever CPU reads from memory address a000.
*/
}