summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/video/bt45x.cpp
blob: f1176ee5f7730a4a9d267da8b35268355942d670 (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
// license:BSD-3-Clause
// copyright-holders:Patrick Mackinlay

/*
 * An implementation of the Brooktree Bt45x family (except the Bt459) of RAMDAC
 * devices. The 453, 454 and 455 are simpler, and have no command or control
 * registers, whereas the others in the family use these to support additional
 * options such as multiplexing, blinking etc. Otherwise the devices are quite
 * similar, and vary only in terms of maximum clock speed, number of color or
 * overlay bits, and quantity and number bits of resolution of DAC output.
 *
 *           Max.       Input          Output
 *   Part    Clock  Color  Overlay  Num.  Levels  Other
 *   Bt451  165MHz  8 bit   2 bit    3     4 bit  blinking, multiplexing
 *   Bt453   66MHz  8 bit   2 bit    3     8 bit
 *   Bt454  170MHz  4 bit   1 bit    3     4 bit
 *   Bt455  170MHz  4 bit   1 bit    1     4 bit
 *   Bt457  165Mhz  8 bit   2 bit    1     8 bit  blinking, multiplexing
 *   Bt458  165MHz  8 bit   2 bit    3     8 bit  blinking, multiplexing
 *
 * Reference: http://www.bitsavers.org/components/brooktree/_dataBooks/1991_Brooktree_Product_Databook.pdf
 *
 * The bt45x_mono_device_base uses the standard red/green/blue read/write
 * cycles defined in the databook, with color data active on the green cycle.
 *
 * TODO
 *   - refactor to separate devices with registers
 *   - implement blinking and overlay
 *   - unsure about address masking when accessing overlay colors
 */

#include "emu.h"
#include "bt45x.h"

#define LOG_GENERAL (1U << 0)
#define LOG_READS   (1U << 1)

#define VERBOSE (0)

#include "logmacro.h"

DEFINE_DEVICE_TYPE(BT451, bt451_device, "bt451", "Brooktree Bt451 256 Color RAMDAC")
DEFINE_DEVICE_TYPE(BT453, bt453_device, "bt453", "Brooktree Bt453 256 Color RAMDAC")
DEFINE_DEVICE_TYPE(BT454, bt454_device, "bt454", "Brooktree Bt454 16 Color RAMDAC")
DEFINE_DEVICE_TYPE(BT455, bt455_device, "bt455", "Brooktree Bt455 16 Color RAMDAC")
DEFINE_DEVICE_TYPE(BT457, bt457_device, "bt457", "Brooktree Bt457 256 Color RAMDAC")
DEFINE_DEVICE_TYPE(BT458, bt458_device, "bt458", "Brooktree Bt458 256 Color RAMDAC")

void bt45x_device_base::map(address_map &map)
{
	map(0x00, 0x00).rw(FUNC(bt45x_device_base::address_r), FUNC(bt45x_device_base::address_w));
	map(0x01, 0x01).rw(FUNC(bt45x_device_base::palette_r), FUNC(bt45x_device_base::palette_w));
	map(0x02, 0x02).rw(FUNC(bt45x_device_base::register_r), FUNC(bt45x_device_base::register_w));
	map(0x03, 0x03).rw(FUNC(bt45x_device_base::overlay_r), FUNC(bt45x_device_base::overlay_w));
}

void bt453_device::map(address_map &map)
{
	map(0x00, 0x00).rw(FUNC(bt453_device::address_r), FUNC(bt453_device::address_w));
	map(0x01, 0x01).rw(FUNC(bt453_device::palette_r), FUNC(bt453_device::palette_w));
	map(0x02, 0x02).rw(FUNC(bt453_device::address_r), FUNC(bt453_device::address_w));
	map(0x03, 0x03).rw(FUNC(bt453_device::overlay_r), FUNC(bt453_device::overlay_w));
}

void bt454_device::map(address_map &map)
{
	map(0x00, 0x00).rw(FUNC(bt454_device::address_r), FUNC(bt454_device::address_w));
	map(0x01, 0x01).rw(FUNC(bt454_device::palette_r), FUNC(bt454_device::palette_w));
	// FIXME: not clear what happens here
	//map(0x02, 0x02).rw(FUNC(bt454_device::address_r), FUNC(bt454_device::address_w));
	map(0x03, 0x03).rw(FUNC(bt454_device::overlay_r), FUNC(bt454_device::overlay_w));
}

void bt455_device::map(address_map &map)
{
	map(0x00, 0x00).rw(FUNC(bt455_device::address_r), FUNC(bt455_device::address_w));
	map(0x01, 0x01).rw(FUNC(bt455_device::palette_r), FUNC(bt455_device::palette_w));
	// FIXME: not clear what happens here
	//map(0x02, 0x02).rw(FUNC(bt455_device::address_r), FUNC(bt455_device::address_w));
	map(0x03, 0x03).rw(FUNC(bt455_device::overlay_r), FUNC(bt455_device::overlay_w));
}

bt45x_device_base::bt45x_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, const u32 palette_colors, const u32 overlay_colors)
	: device_t(mconfig, type, tag, owner, clock)
	, m_palette_colors(palette_colors)
	, m_overlay_colors(overlay_colors)
{
}

bt45x_rgb_device_base::bt45x_rgb_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, const u32 palette_colors, const u32 overlay_colors)
	: bt45x_device_base(mconfig, type, tag, owner, clock, palette_colors, overlay_colors)
	, device_palette_interface(mconfig, *this)
{
}

bt45x_mono_device_base::bt45x_mono_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, const u32 palette_colors, const u32 overlay_colors)
	: bt45x_device_base(mconfig, type, tag, owner, clock, palette_colors, overlay_colors)
{
}

bt451_device::bt451_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: bt45x_rgb_device_base(mconfig, BT451, tag, owner, clock, 256, 3)
{
}

bt453_device::bt453_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: bt45x_rgb_device_base(mconfig, BT453, tag, owner, clock, 256, 3)
{
}

bt454_device::bt454_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: bt45x_rgb_device_base(mconfig, BT454, tag, owner, clock, 16, 1)
{
}

bt455_device::bt455_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: bt45x_mono_device_base(mconfig, BT455, tag, owner, clock, 16, 1)
{
}
bt457_device::bt457_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: bt45x_mono_device_base(mconfig, BT457, tag, owner, clock, 256, 3)
{
}

bt458_device::bt458_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: bt45x_rgb_device_base(mconfig, BT458, tag, owner, clock, 256, 3)
{
}

void bt45x_device_base::device_start()
{
	save_item(NAME(m_address));
	save_item(NAME(m_address_rgb));

	save_item(NAME(m_read_mask));
	save_item(NAME(m_blink_mask));
	save_item(NAME(m_command));
	save_item(NAME(m_control));

	save_item(NAME(m_blink_start));
}

void bt45x_rgb_device_base::device_start()
{
	bt45x_device_base::device_start();

	m_color_ram = std::make_unique<std::array<u8, 3>[]>(m_palette_colors + m_overlay_colors);

	//save_pointer(NAME(m_color_ram), m_palette_colors + m_overlay_colors);
}

void bt45x_mono_device_base::device_start()
{
	bt45x_device_base::device_start();

	m_color_ram = std::make_unique<u8[]>(m_palette_colors + m_overlay_colors);

	save_pointer(NAME(m_color_ram), m_palette_colors + m_overlay_colors);
}

void bt45x_device_base::device_reset()
{
	m_blink_start = -1;
}

READ8_MEMBER(bt45x_device_base::address_r)
{
	LOGMASKED(LOG_READS, "address_r 0x%02x\n", m_address & (m_palette_colors - 1));

	if (!machine().side_effects_disabled())
		m_address_rgb = 0;

	return m_address & (m_palette_colors - 1);
}

WRITE8_MEMBER(bt45x_device_base::address_w)
{
	LOG("address_w 0x%02x\n", data);
	m_address_rgb = 0;

	m_address = data & (m_palette_colors - 1);
}

void bt45x_device_base::increment_address(const bool side_effects)
{
	if (!machine().side_effects_disabled() || side_effects)
	{
		// increment component index and address register
		m_address_rgb = (m_address_rgb + 1) % 3;
		if (m_address_rgb == 0)
			m_address = (m_address + 1) & (m_palette_colors - 1);
	}
}

void bt457_device::increment_address(const bool side_effects)
{
	if (!machine().side_effects_disabled() || side_effects)
	{
		// check for rgb mode
		if (m_control & RGB)
		{
			// increment component index and address register
			m_address_rgb = (m_address_rgb + 1) % 3;
			if (m_address_rgb == 0)
				m_address++;
		}
		else
			m_address++;
	}
}

READ8_MEMBER(bt45x_rgb_device_base::palette_r)
{
	const u8 data = m_color_ram[m_address][m_address_rgb];

	increment_address();

	LOGMASKED(LOG_READS, "palette_r 0x%02x\n", data & get_mask());

	return data & get_mask();
}

READ8_MEMBER(bt45x_mono_device_base::palette_r)
{
	u8 data = space.unmap();

	if (m_address_rgb == 1)
		data = m_color_ram[m_address];

	increment_address();

	LOGMASKED(LOG_READS, "palette_r 0x%02x\n", data & get_mask());

	return data & get_mask();
}

READ8_MEMBER(bt457_device::palette_r)
{
	u8 data = space.unmap();

	// normal mode or rgb mode and selected
	if (!(m_control & RGB) || (m_control & RGB) == (1 << m_address_rgb))
		data = m_color_ram[m_address];

	increment_address();

	LOGMASKED(LOG_READS, "palette_r 0x%02x\n", data);

	return data;
}

WRITE8_MEMBER(bt45x_rgb_device_base::palette_w)
{
	LOG("palette_w 0x%02x\n", data);

	m_color_ram[m_address][m_address_rgb] = data & get_mask();

	// update the mame palette to match the device
	if (m_address_rgb == 2)
		set_pen_color(m_address, rgb_t(m_color_ram[m_address][0], m_color_ram[m_address][1], m_color_ram[m_address][2]));

	increment_address(true);
}

WRITE8_MEMBER(bt45x_mono_device_base::palette_w)
{
	LOG("palette_w 0x%02x\n", data);

	if (m_address_rgb == 1)
		m_color_ram[m_address] = data & get_mask();

	increment_address(true);
}

WRITE8_MEMBER(bt457_device::palette_w)
{
	LOG("palette_w 0x%02x\n", data);

	// device in normal mode, or rgb mode and selected
	if (!(m_control & RGB) || (m_control & RGB) == (1 << m_address_rgb))
		m_color_ram[m_address] = data;

	increment_address(true);
}

READ8_MEMBER(bt45x_device_base::register_r)
{
	LOGMASKED(LOG_READS, "register_r 0x%02x\n", m_address);

	switch (m_address)
	{
	case REG_READ_MASK:  return m_read_mask;
	case REG_BLINK_MASK: return m_blink_mask;
	case REG_COMMAND:    return m_command;
	case REG_CONTROL:    return m_control;
	}

	return space.unmap();
}

WRITE8_MEMBER(bt45x_device_base::register_w)
{
	switch (m_address)
	{
	case REG_READ_MASK:
		LOG("read mask 0x%02x\n", data);
		m_read_mask = data;
		break;

	case REG_BLINK_MASK:
		LOG("blink mask 0x%02x\n", data);
		m_blink_mask = data;
		break;

	case REG_COMMAND:
		LOG("command 0x%02x, %d:1 multiplexing, use %s, %s, OL1 %s blinking, OL0 %s blinking, OL1 display %s, OL0 display %s\n",
			data,
			(data & CR7) ? 5 : 4,
			(data & CR6) ? "color palette RAM" : "overlay color 0",
			(data & CR54) == CR54_6464 ? "64 on 64 off (50/50)" :
				(data & CR54) == CR54_3232 ? "32 on 32 off (50/50)" :
				(data & CR54) == CR54_1616 ? "16 on 16 off (50/50)" :
				"16 on 48 off (25/75)",
			(data & CR3) ? "enable" : "disable",
			(data & CR2) ? "enable" : "disable",
			(data & CR1) ? "enable" : "disable",
			(data & CR0) ? "enable" : "disable");
		m_command = data;
		break;

	case REG_CONTROL:
		LOG("control 0x%02x, %s nibble%s%s%s\n",
			data,
			(data & D3) ? "low" : "high",
			(data & D2) ? ", blue channel enable" : "",
			(data & D1) ? ", green channel enable" : "",
			(data & D0) ? ", red channel enable" : "");
		m_control = data & 0xf;
		break;
	}
}

READ8_MEMBER(bt45x_rgb_device_base::overlay_r)
{
	// address is ignored for 1 bit overlay devices
	const u8 address = (m_overlay_colors == 1) ? 0 : m_address;

	u8 data = space.unmap();

	if (address < m_overlay_colors)
		data = m_color_ram[m_palette_colors + address][m_address_rgb];

	increment_address();

	LOGMASKED(LOG_READS, "overlay_r 0x%02x\n", data & get_mask());

	return data & get_mask();
}

READ8_MEMBER(bt45x_mono_device_base::overlay_r)
{
	// address is ignored for 1 bit overlay devices
	const u8 address = (m_overlay_colors == 1) ? 0 : m_address;

	u8 data = space.unmap();

	if (address < m_overlay_colors && m_address_rgb == 1)
		data = m_color_ram[m_palette_colors + address];

	increment_address();

	LOGMASKED(LOG_READS, "overlay_r 0x%02x\n", data & get_mask());

	return data & get_mask();
}

READ8_MEMBER(bt457_device::overlay_r)
{
	u8 data = space.unmap();

	if (m_address < m_overlay_colors)
	{
		// device in normal mode, or rgb mode and selected
		if (!(m_control & RGB) || (m_control & RGB) == (1 << m_address_rgb))
			data = m_color_ram[m_address + m_palette_colors];
	}

	increment_address();

	LOGMASKED(LOG_READS, "overlay_r 0x%02x\n", data);

	return data;
}

WRITE8_MEMBER(bt45x_rgb_device_base::overlay_w)
{
	LOG("overlay_w 0x%02x\n", data);

	// address is ignored for 1 bit overlay devices
	const u8 address = (m_overlay_colors == 1) ? 0 : m_address;

	if (address < m_overlay_colors)
	{
		m_color_ram[m_palette_colors + address][m_address_rgb] = data & get_mask();

		// update the mame palette to match the device
		if (m_address_rgb == 2)
			set_pen_color(m_palette_colors + address, rgb_t(
				m_color_ram[m_palette_colors + address][0],
				m_color_ram[m_palette_colors + address][1],
				m_color_ram[m_palette_colors + address][2]));
	}

	increment_address(true);
}

WRITE8_MEMBER(bt45x_mono_device_base::overlay_w)
{
	LOG("overlay_w 0x%02x\n", data);

	// address is ignored for 1 bit overlay devices
	const u8 address = (m_overlay_colors == 1) ? 0 : m_address;

	if (address < m_overlay_colors)
		m_color_ram[m_palette_colors + address] = data & get_mask();

	increment_address(true);
}

WRITE8_MEMBER(bt457_device::overlay_w)
{
	LOG("overlay_w 0x%02x\n", data);

	if (m_address < m_overlay_colors)
	{
		// device in normal mode, or rgb mode and selected
		if (!(m_control & RGB) || (m_control & RGB) == (1 << m_address_rgb))
			m_color_ram[m_palette_colors + m_address] = data;
	}

	increment_address(true);
}