summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/video/sed1520.cpp
blob: 9dd8017155d68fa18faf6c2a3f4bc7180a03b3a6 (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
// license:BSD-3-Clause
// copyright-holders:Sandro Ronco
/***************************************************************************

    SED1520 LCD controller
    SED1560 LCD controller
    EPL43102 LCD controller

    TODO:
    - busy flag

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

#include "emu.h"
#include "video/sed1520.h"

#include "screen.h"


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

DEFINE_DEVICE_TYPE(SED1520, sed1520_device, "sed1520", "Epson SED1520 LCD Driver")
DEFINE_DEVICE_TYPE(SED1560, sed1560_device, "sed1560", "Epson SED1560 LCD Driver")
DEFINE_DEVICE_TYPE(EPL43102, epl43102_device, "epl43102", "Elan EPL43102 LCD Driver")


//**************************************************************************
//  live device
//**************************************************************************

//-------------------------------------------------
//  sed1520_device - constructor
//-------------------------------------------------

sed15xx_device_base::sed15xx_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, uint32_t ddr_size, uint32_t page_size)
	: device_t(mconfig, type, tag, owner, clock)
	, m_ddr_size(ddr_size)
	, m_page_size(page_size)
	, m_lcd_on(0)
	, m_busy(0)
	, m_page(0)
	, m_column(0)
	, m_old_column(0)
	, m_start_line(0)
	, m_adc(0)
	, m_modify_write(false)
	, m_data(0)
	, m_duty(0)
{
}

sed1520_device::sed1520_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed15xx_device_base(mconfig, SED1520, tag, owner, clock, 320, 80)     // 2560-bit display RAM
	, m_screen_update_cb(*this)
{
}

sed1560_device::sed1560_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, uint32_t ddr_size, uint32_t page_size)
	: sed15xx_device_base(mconfig, type, tag, owner, clock, ddr_size, page_size)
	, m_screen_update_cb(*this)
{
}

sed1560_device::sed1560_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed1560_device(mconfig, SED1560, tag, owner, clock, 1349, 166)   // 166 × 65-bit display RAM
{
}

epl43102_device::epl43102_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed1560_device(mconfig, EPL43102, tag, owner, clock, 455, 102)   // 102 × 43-bit display RAM (TODO: page map is not straightforward)
{
}


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

void sed15xx_device_base::device_start()
{
	m_ddr = std::make_unique<uint8_t[]>(m_ddr_size);

	// state saving
	save_item(NAME(m_lcd_on));
	save_item(NAME(m_busy));
	save_item(NAME(m_page));
	save_item(NAME(m_column));
	save_item(NAME(m_old_column));
	save_item(NAME(m_start_line));
	save_item(NAME(m_adc));
	save_item(NAME(m_modify_write));
	save_item(NAME(m_data));
	save_item(NAME(m_duty));
	save_pointer(NAME(m_ddr), m_ddr_size);
}

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

void sed15xx_device_base::device_reset()
{
	m_lcd_on = 0;
	m_busy = 0;
	m_page = 3;
	m_column = 0;
	m_old_column = 0;
	m_start_line = 0;
	m_adc = 1;
	m_modify_write = false;
	m_data = 0;
	m_duty = 0;
	std::fill_n(m_ddr.get(), m_ddr_size, 0x00);
}

void sed1520_device::device_resolve_objects()
{
	m_screen_update_cb.resolve();
}

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

void sed1520_device::device_start()
{
	sed15xx_device_base::device_start();

	// state saving
	save_item(NAME(m_static_drive));
}

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

void sed1520_device::device_reset()
{
	sed15xx_device_base::device_reset();

	m_page = 3;
	m_static_drive = false;
}


void sed1560_device::device_resolve_objects()
{
	m_screen_update_cb.resolve();
}

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

void sed1560_device::device_start()
{
	sed15xx_device_base::device_start();

	// state saving
	save_item(NAME(m_contrast));
	save_item(NAME(m_reverse));
	save_item(NAME(m_fill));
	save_item(NAME(m_line_inv));
	save_item(NAME(m_line_inv_num));
}

void epl43102_device::device_start()
{
	sed1560_device::device_start();

	// state saving
	save_item(NAME(m_last_command));
}

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

void sed1560_device::device_reset()
{
	sed15xx_device_base::device_reset();

	m_page = 0;
	m_adc = 0;
	m_contrast = 0;
	m_reverse = false;
	m_fill = false;
	m_line_inv_num = 16;
	m_line_inv = false;
}

void epl43102_device::device_reset()
{
	sed1560_device::device_reset();

	m_last_command = 0;
}

//**************************************************************************
//  device interface
//**************************************************************************

uint8_t sed15xx_device_base::read(offs_t offset)
{
	if (offset & 0x01)
		return data_read();
	else
		return status_read();
}

void sed15xx_device_base::write(offs_t offset, uint8_t data)
{
	if (offset & 0x01)
		data_write(data);
	else
		control_write(data);
}

uint8_t sed15xx_device_base::status_read()
{
	return (m_busy << 7) | (m_adc << 6) | (m_lcd_on << 5);
}

void sed15xx_device_base::data_write(uint8_t data)
{
	m_data = data;

	// no RAM write when column address is invalid
	if (m_column < m_page_size)
	{
		m_ddr[(m_page * m_page_size + m_column) % m_ddr_size] = data;
		m_column++;
	}
}

uint8_t sed15xx_device_base::data_read()
{
	uint8_t data = m_data;
	if (machine().side_effects_disabled())
		return data;

	if (m_column < m_page_size)
	{
		m_data = m_ddr[(m_page * m_page_size + m_column) % m_ddr_size];
		if (!m_modify_write)
			m_column++;
	}
	else
	{
		// invalid column, not sure what happens with data latch
		m_data = 0;
	}

	return data;
}


void sed1520_device::control_write(uint8_t data)
{
	if ((data & 0xfe) == 0xae)           // Display ON/OFF
		m_lcd_on = data & 0x01;
	else if ((data & 0xe0) == 0xc0)      // Set start line
		m_start_line = data & 0x1f;
	else if ((data & 0xfc) == 0xb8)      // Set page address
		m_page = data & 0x03;
	else if ((data & 0x80) == 0x00)      // Set column address
		m_column = data & 0x7f;
	else if ((data & 0xfe) == 0xa0)      // Select ADC
		m_adc = data & 0x01;
	else if ((data & 0xfe) == 0xa4)      // Static drive ON/OFF
		m_static_drive = data & 0x01;
	else if ((data & 0xfe) == 0xa8)      // Select duty
		m_duty = data & 0x01;
	else if (data == 0xe0)               // Read Modify Write ON
	{
		m_modify_write = true;
		m_old_column = m_column;
	}
	else if (data == 0xee)               // Read Modify Write OFF
	{
		m_modify_write = false;
		m_column = m_old_column;
	}
	else if (data == 0xe2)               // Reset
	{
		m_start_line = m_column = 0;
		m_page = 3;
	}
	else
		logerror("%s: invalid SED1520 command: %x\n", machine().describe_context(), data);
}


void sed1560_device::control_write(uint8_t data)
{
	if ((data & 0xfe) == 0xae)           // Display ON/OFF
		m_lcd_on = BIT(data, 0);
	else if ((data & 0xc0) == 0x40)      // Initial display line
		m_start_line = data & 0x3f;
	else if ((data & 0xf0) == 0xb0)      // Set page
		m_page = data & 0x0f;
	else if ((data & 0xf0) == 0x00)      // Column address low nibble
		m_column = (m_column & 0xf0) | (data & 0x0f);
	else if ((data & 0xf0) == 0x10)      // Column address high nibble
		m_column = (m_column & 0x0f) | ((data << 4) & 0xf0);
	else if ((data & 0xfe) == 0xa0)      // Select ADC
		m_adc = BIT(data, 0);
	else if ((data & 0xfe) == 0xa6)      // Normal/reverse display
		m_reverse = BIT(data, 0);
	else if ((data & 0xfe) == 0xa4)      // Display all points ON/OFF
		m_fill = BIT(data, 0);
	else if ((data & 0xfe) == 0xa8)      // Select duty
		m_duty = (m_duty & 0x02) | (data & 0x01);
	else if ((data & 0xfe) == 0xaa)      // Duty + 1
		m_duty = (m_duty & 0x01) | ((data & 0x01) << 1);
	else if ((data & 0xf0) == 0x30)      // Set n-line inversion
	{
		m_line_inv = true;
		m_line_inv_num = data & 0x0f;
	}
	else if (data == 0x20)               // Cancel n-line inversion
		m_line_inv = false;
	else if (data == 0xe2)               // Reset
	{
		m_start_line = 0;
		m_column = 0;
		m_page = 0;
		m_line_inv_num = 16;
	}
	else if (data == 0xe0)               // Read Modify Write
	{
		m_modify_write = true;
		m_old_column = m_column;
	}
	else if (data == 0xee)               // End Modify Write
	{
		m_modify_write = false;
		m_column = m_old_column;
	}
	else if (data == 0xed)               // Power-on completion
		logerror("%s: Power-on completion\n", machine().describe_context());
	else if ((data & 0xf0) == 0xc0)      // Output status set
		logerror("%s: Output status set %x\n", machine().describe_context(), data & 0x0f);
	else if ((data & 0xfe) == 0x24)      // LCD power supply ON/OFF
		logerror("%s: LCD power supply %d\n", machine().describe_context(), data & 0x01);
	else if ((data & 0xe0) == 0x80)      // Software contrast setting
		m_contrast = data;
	else
		logerror("%s: invalid SED1560 command: %x\n", machine().describe_context(), data);
}


void epl43102_device::control_write(uint8_t data)
{
	switch (m_last_command)
	{
	case 0x81:
		m_contrast = data & 0x3f;
		m_last_command = 0;
		break;

	case 0x82:
		logerror("%s: CL frequency = fOSC / %d\n", machine().describe_context(), BIT(data, 4) ? 32 : (data & 0x0f) + 1);
		m_last_command = 0;
		break;

	case 0x84:
		logerror("%s: Duty ratio = %d%s\n", machine().describe_context(), ((data & 0x07) + 1) * 8, BIT(data, 3) ? " + ICON" : "");
		m_duty = data & 0x07;
		m_last_command = 0;
		break;

	case 0x85:
		logerror("%s: LCD bias = %d%s\n", machine().describe_context(), ((data & 0x0e) >> 1) + 3, BIT(data, 0) ? ".5" : "");
		m_last_command = 0;
		break;

	case 0xad:
		if ((data & 0x03) == 0)
			logerror("%s: Status indicator off\n", machine().describe_context());
		else
			logerror("%s: Status indicator on (%s)\n", machine().describe_context(), (data & 0x03) == 0x01 ? "4-frame blinking" : (data & 0x03) == 0x02 ? "2-frame blinking" : "continuously");
		m_last_command = 0;
		break;

	default:
		if (data == 0x81 || data == 0x82 || data == 0x84 || data == 0x85 || data == 0xad)
		{
			// 2-byte instructions
			m_last_command = data;
		}
		else if ((data & 0xf0) == 0xc0)
			logerror("%s: COM output direction = %s\n", machine().describe_context(), BIT(data, 3) ? "reverse" : "normal");
		else if ((data & 0xf8) == 0x28)
			logerror("%s: Voltage converter %s, regulator %s, follower %s\n", machine().describe_context(), BIT(data, 2) ? "on" : "off", BIT(data, 1) ? "on" : "off", BIT(data, 0) ? "on" : "off");
		else if ((data & 0xf8) == 0x20)
			logerror("%s: Regulator resistor select = %d\n", machine().describe_context(), data & 0x07);
		else
			sed1560_device::control_write(data);
		break;
	}
}


uint32_t sed1520_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	if (m_static_drive)
		return UPDATE_HAS_NOT_CHANGED;

	return m_screen_update_cb(bitmap, cliprect, m_lcd_on, m_ddr.get(), m_start_line, m_adc, m_duty);
}

uint32_t sed1560_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	return m_screen_update_cb(bitmap, cliprect, m_lcd_on, m_ddr.get(), m_start_line, m_adc, m_duty, m_reverse, m_fill, m_contrast, m_line_inv, m_line_inv_num);
}