summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/video/mb88303.cpp
blob: 5b291553dddfa5066292e1829fa3f2ea08203860 (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
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/***********************************************************************

    Fujitsu MB88303 NMOS Television Display Controller (TVDC) emulation

    TOOD:
    - Character-size registers.
    - Proper hsync/vsync emulation.
    - Blinking.

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

#include "emu.h"
#include "mb88303.h"



//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

// device type definition
DEFINE_DEVICE_TYPE(MB88303, mb88303_device, "mb88303", "Fujitsu MB88303")



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

/*static*/ const uint8_t mb88303_device::s_character_data[0x40][7] = {
	{ 0x0e, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11 }, // 0x00
	{ 0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e },
	{ 0x0e, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0e },
	{ 0x1e, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1e },
	{ 0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x1f },
	{ 0x1f, 0x10, 0x10, 0x1e, 0x10, 0x10, 0x10 },
	{ 0x0f, 0x10, 0x10, 0x13, 0x11, 0x11, 0x0f },
	{ 0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11 },
	{ 0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e },
	{ 0x01, 0x01, 0x01, 0x01, 0x11, 0x11, 0x0e },
	{ 0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11 },
	{ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f },
	{ 0x11, 0x1b, 0x15, 0x15, 0x11, 0x11, 0x11 },
	{ 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 },
	{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x1f },
	{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 },
	{ 0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11 }, // 0x10
	{ 0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e },
	{ 0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10 },
	{ 0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d },
	{ 0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11 },
	{ 0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e },
	{ 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 },
	{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e },
	{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04 },
	{ 0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11 },
	{ 0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11 },
	{ 0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04 },
	{ 0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f },
	{ 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00 },
	{ 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f },
	{ 0x02, 0x04, 0x04, 0x04, 0x04, 0x04, 0x02 },
	{ 0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e }, // 0x20
	{ 0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04 },
	{ 0x0e, 0x11, 0x01, 0x0e, 0x10, 0x10, 0x1f },
	{ 0x0e, 0x11, 0x01, 0x06, 0x01, 0x11, 0x0e },
	{ 0x06, 0x0a, 0x12, 0x12, 0x1f, 0x02, 0x02 },
	{ 0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e },
	{ 0x0e, 0x11, 0x10, 0x1e, 0x11, 0x11, 0x0e },
	{ 0x1f, 0x11, 0x01, 0x02, 0x04, 0x04, 0x04 },
	{ 0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e },
	{ 0x0e, 0x11, 0x11, 0x0f, 0x01, 0x11, 0x0e },
	{ 0x0e, 0x11, 0x01, 0x06, 0x04, 0x00, 0x04 },
	{ 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04 },
	{ 0x06, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00 },
	{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c },
	{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
	{ 0x08, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08 },
	{ 0x00, 0x04, 0x0a, 0x15, 0x04, 0x04, 0x00 }, // 0x30
	{ 0x00, 0x04, 0x04, 0x15, 0x0a, 0x04, 0x00 },
	{ 0x00, 0x04, 0x08, 0x17, 0x08, 0x04, 0x00 },
	{ 0x00, 0x04, 0x02, 0x1d, 0x02, 0x04, 0x00 },
	{ 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04, 0x00 },
	{ 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00 },
	{ 0x00, 0x04, 0x15, 0x0e, 0x15, 0x04, 0x00 },
	{ 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00 },
	{ 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00 },
	{ 0x0c, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0d },
	{ 0x10, 0x1f, 0x02, 0x0f, 0x0a, 0x1f, 0x02 },
	{ 0x1f, 0x11, 0x1f, 0x11, 0x1f, 0x11, 0x11 },
	{ 0x1f, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x1f },
	{ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x04, 0x08 },
	{ 0x00, 0x00, 0x00, 0x08, 0x15, 0x02, 0x00 },
	{ 0x0e, 0x11, 0x04, 0x1f, 0x1b, 0x1f, 0x11 }
};


//-------------------------------------------------
//  mb88303_device - constructor
//-------------------------------------------------

mb88303_device::mb88303_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, MB88303, tag, owner, clock)
	, m_write_vow(*this)
	, m_write_vobn(*this)
	, m_write_do(*this)
	, m_horiz_display_pos(0)
	, m_vert_display_pos(0)
	, m_display_ctrl(0)
	, m_general_out(7)
	, m_address(0)
	, m_addr_inc_mode(false)
{
}


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

void mb88303_device::device_start()
{
	// resolve callbacks
	m_write_vow.resolve_safe();
	m_write_vobn.resolve_safe();
	m_write_do.resolve_safe();

	// register for state saving
	save_item(NAME(m_display_mem));
	save_item(NAME(m_horiz_display_pos));
	save_item(NAME(m_vert_display_pos));
	save_item(NAME(m_display_ctrl));
	save_item(NAME(m_general_out));
	save_item(NAME(m_address));
	save_item(NAME(m_addr_inc_mode));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void mb88303_device::device_reset()
{
	m_horiz_display_pos = 0;
	m_vert_display_pos = 0;
	m_display_ctrl = 0;
	m_general_out = 0x07;
	m_address = 0;
	m_addr_inc_mode = false;

	memset(m_display_mem, 0, sizeof(uint8_t) * 180);

	m_da = 0;
	m_adm = 0;
	m_reset_n = 1;
	m_ldi = 0;
	m_hsync_n = 1;
	m_vsync_n = 1;

	m_write_vow(CLEAR_LINE);
	m_write_vobn(ASSERT_LINE);
	m_write_do(m_general_out);
}


WRITE8_MEMBER( mb88303_device::da_w )
{
	//logerror("%s: mb88303_device::da_w: %02x\n", machine().describe_context(), data);
	m_da = data;
}

WRITE_LINE_MEMBER( mb88303_device::adm_w )
{
	//logerror("%s: mb88303_device::adm_w: %02x\n", machine().describe_context(), state);
	m_adm = state;
}

WRITE_LINE_MEMBER( mb88303_device::reset_n_w )
{
	logerror("%s: mb88303_device::reset_n_w: %02x\n", machine().describe_context(), state);
	uint8_t old = m_reset_n;
	m_reset_n = state;

	if (old != m_reset_n && m_reset_n)
	{
		m_horiz_display_pos = 0;
		m_vert_display_pos = 0;
		m_display_ctrl = 0;
		m_general_out = 0x07;
		m_addr_inc_mode = false;

		m_write_vow(CLEAR_LINE);
		m_write_vobn(ASSERT_LINE);
		m_write_do(m_general_out);
	}
}

WRITE_LINE_MEMBER( mb88303_device::ldi_w )
{
	//logerror("%s: mb88303_device::ldi_w: %02x\n", machine().describe_context(), state);
	uint8_t old = m_ldi;
	m_ldi = state;

	if (m_ldi != old)
	{
		if (!m_ldi)
		{
			// Direct Address Mode: At the trailing edge of LDI, a 7-bit
			// data on DA6-DA0 is written into an internal control register
			// or an internal display memory location that is designated by
			// the address latched at the leading edge.

			// Address Increment Mode: At the trailing edge of LDI, a 7-bit
			// data on DA6-DA0 is written into an internal control register
			// or a display memory location that is indicated by the
			// address register.
			process_data();
		}
		else if (!m_adm)
		{
			// Direct Address Mode: At the leading edge of LDI, an 8-bit
			// address on DA7-DA0 is automatically latched into the
			// internal address register.
			//logerror("%s: mb88303_device::ldi_w: new address = %02x\n", machine().describe_context(), m_da);
			m_address = m_da;
		}
		else
		{
			// Address Increment Mode: At the leading edge of LDI, the
			// address register is automatically incremented.
			m_address++;
			//logerror("%s: mb88303_device::ldi_w: new address = %02x\n", machine().describe_context(), m_address);
		}
	}
}

void mb88303_device::process_data()
{
	switch (m_address)
	{
		case 180:
			hdpr_w(m_da);
			break;
		case 181:
			vdpr_w(m_da);
			break;
		case 182:
			dcr_w(m_da);
			break;
		case 183:
			gor_w(m_da);
			break;
		default:
			assert(m_address < 180);
			m_display_mem[m_address] = m_da;
			break;
	}
}

WRITE_LINE_MEMBER( mb88303_device::hsync_n_w )
{
	m_hsync_n = state;
}

WRITE_LINE_MEMBER( mb88303_device::vsync_n_w )
{
	m_vsync_n = state;
}

void mb88303_device::hdpr_w(uint8_t data)
{
	logerror("%s: mb88303_device::hdpr_w: %02x\n", machine().describe_context(), data);
	m_horiz_display_pos = data & 0x3f;
}

void mb88303_device::vdpr_w(uint8_t data)
{
	logerror("%s: mb88303_device::vdpr_w: %02x\n", machine().describe_context(), data);
	m_vert_display_pos = data & 0x3f;
}

void mb88303_device::dcr_w(uint8_t data)
{
	logerror("%s: mb88303_device::dcr_w: %02x\n", machine().describe_context(), data);
	m_display_ctrl = data & 0x7f;
}

void mb88303_device::gor_w(uint8_t data)
{
	//logerror("%s: mb88303_device::gor_w: %02x\n", machine().describe_context(), data);
	uint8_t old = m_general_out;
	m_general_out = data & 0x07;
	if (m_general_out != old)
	{
		m_write_do(m_general_out);
	}
}


bool mb88303_device::blank_display()
{
	return !BIT(m_display_ctrl, BLK_BIT);
}

bool mb88303_device::show_background()
{
	return BIT(m_display_ctrl, BLKB_BIT);
}

bool mb88303_device::enable_blinking()
{
	return BIT(m_display_ctrl, BLINK_BIT);
}

void mb88303_device::update_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	if (blank_display())
	{
		bitmap.fill(0, cliprect);
		return;
	}

	for (unsigned x = 0; x < VISIBLE_COLUMNS; x++)
	{
		for (unsigned y = 0; y < VISIBLE_LINES; y++)
		{
			uint16_t bitmap_y = y * 9;
			uint16_t bitmap_x = x * 6;
			const uint8_t *gfx = s_character_data[m_display_mem[y * VISIBLE_COLUMNS + x] & 0x3f];
			for (unsigned row = 0; row < 7; row++)
			{
				for (unsigned bit = 0; bit < 6; bit++)
				{
					if (gfx[row] & 0x80)
						continue;
					const uint32_t color = BIT(gfx[row], bit) ? 0xffffffff : 0;
					if (!show_background() && !color)
						continue;
					bitmap.pix32(bitmap_y + row + m_vert_display_pos, bitmap_x + (6 - bit) + m_horiz_display_pos) = color;
				}
			}
		}
	}
}