summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/video/sed1200.cpp
blob: 885033548732db074ef249cd0b09ab2a7adc789b (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
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
/***************************************************************************

    SED1200

    A LCD controller similar to HD44780/SED1278 that drives a 20-character
    display. Data input is 4 bits at a time. (SED1210 has a 40-character
    display and 8-bit data input.)

    The D/F variants have a packaging difference (QFP80 vs. bare chip).

    The A/B variants have an internal CGROM difference (jis
    vs. european characters)

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

#include "emu.h"
#include "sed1200.h"

DEFINE_DEVICE_TYPE(SED1200D0A, sed1200d0a_device, "sed1200da", "Epson SED1200D-0A LCD Controller")
DEFINE_DEVICE_TYPE(SED1200F0A, sed1200f0a_device, "sed1200fa", "Epson SED1200F-0A LCD Controller")
DEFINE_DEVICE_TYPE(SED1200D0B, sed1200d0b_device, "sed1200db", "Epson SED1200D-0B LCD Controller")
DEFINE_DEVICE_TYPE(SED1200F0B, sed1200f0b_device, "sed1200fb", "Epson SED1200F-0B LCD Controller")

ROM_START( sed1200x0a )
	ROM_REGION( 0x800, "cgrom", 0 )
	ROM_LOAD( "sed1200-a.bin", 0x000, 0x800, CRC(e8c28054) SHA1(086406eb74e9ed97b309d2a4bdedc567626e9a98))
ROM_END

ROM_START( sed1200x0b )
	ROM_REGION( 0x800, "cgrom", 0 )
	ROM_LOAD( "sed1200-b.bin", 0x000, 0x800, CRC(d0741f51) SHA1(c8c856f1357286a2c8c806af81724a828345357e))
ROM_END

sed1200_device::sed1200_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, cursor_direction(false)
	, cursor_blinking(false)
	, cursor_full(false)
	, cursor_on(false)
	, display_on(false)
	, two_lines(false)
	, cursor_address(0)
	, cgram_address(0)
	, cgrom(nullptr)
	, chip_select(false)
	, first_input(false)
	, first_data(0)
{
}

sed1200d0a_device::sed1200d0a_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed1200_device(mconfig, SED1200D0A, tag, owner, clock)
{
}

sed1200f0a_device::sed1200f0a_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed1200_device(mconfig, SED1200F0A, tag, owner, clock)
{
}

sed1200d0b_device::sed1200d0b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed1200_device(mconfig, SED1200D0B, tag, owner, clock)
{
}

sed1200f0b_device::sed1200f0b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: sed1200_device(mconfig, SED1200F0B, tag, owner, clock)
{
}

const tiny_rom_entry *sed1200d0a_device::device_rom_region() const
{
	return ROM_NAME(sed1200x0a);
}

const tiny_rom_entry *sed1200f0a_device::device_rom_region() const
{
	return ROM_NAME(sed1200x0a);
}

const tiny_rom_entry *sed1200d0b_device::device_rom_region() const
{
	return ROM_NAME(sed1200x0b);
}

const tiny_rom_entry *sed1200f0b_device::device_rom_region() const
{
	return ROM_NAME(sed1200x0b);
}

void sed1200_device::device_start()
{
	memset(cgram, 0, sizeof(cgram));
	memset(ddram, 0, sizeof(ddram));
	if(memregion("cgrom"))
		cgrom = memregion("cgrom")->base();
	else
		cgrom = nullptr;

	chip_select = false;

	save_item(NAME(cgram));
	save_item(NAME(ddram));
	save_item(NAME(cursor_direction));
	save_item(NAME(cursor_blinking));
	save_item(NAME(cursor_full));
	save_item(NAME(cursor_on));
	save_item(NAME(display_on));
	save_item(NAME(two_lines));
	save_item(NAME(cursor_address));
	save_item(NAME(cgram_address));
	save_item(NAME(chip_select));
	save_item(NAME(first_input));
	save_item(NAME(first_data));

	soft_reset();
}

void sed1200_device::cs_w(int state)
{
	if (chip_select != !state) {
		chip_select = !state;
		first_input = true;
	}
}

void sed1200_device::soft_reset()
{
	cursor_direction = false;
	cursor_blinking = false;
	cursor_full = false;
	cursor_on = false;
	display_on = false;
	two_lines = false;
	cursor_address = 0x00;
	cgram_address = 0x00;
}

void sed1200_device::control_w(uint8_t data)
{
	if(chip_select) {
		if(first_input)
			first_data = data & 0x0f;
		else
			control_write(first_data << 4 | (data & 0x0f));
		first_input = !first_input;
	}
}

void sed1200_device::control_write(uint8_t data)
{
	switch(data) {
	case 0x04: case 0x05:
		cursor_direction = data & 0x01;
		break;
	case 0x06: case 0x07:
		cursor_step();
		break;
	case 0x08: case 0x09:
		cursor_full = data & 0x01;
		break;
	case 0x0a: case 0x0b:
		cursor_blinking = data & 0x01;
		break;
	case 0x0c: case 0x0d:
		display_on = data & 0x01;
		break;
	case 0x0e: case 0x0f:
		cursor_on = data & 0x01;
		break;
	case 0x10:
		soft_reset();
		break;
	case 0x12: case 0x13:
		two_lines = data & 0x01;
		break;
	default:
		if((data & 0xf0) == 0x20)
			cgram_address = (data & 3)*8;
		else if((data & 0xe0) == 0x40) {
			cgram[cgram_address++] = data;
			if(cgram_address == 4*8)
				cgram_address = 0;
		} else if(data & 0x80) {
			if (two_lines) {
				cursor_address = data & 0x40 ? 10 : 0;
				cursor_address += (data & 0x3f) >= 10 ? 9 : data & 0x3f;
			} else
				cursor_address = (data & 0x3f) >= 20 ? 19 : data & 0x3f;
		}
		break;
	}
}

uint8_t sed1200_device::busy_r()
{
	// TODO: bit 3 = busy flag
	return 0x00;
}

void sed1200_device::data_w(uint8_t data)
{
	if(chip_select) {
		if(first_input)
			first_data = data & 0x0f;
		else
			data_write(first_data << 4 | (data & 0x0f));
		first_input = !first_input;
	}
}

void sed1200_device::data_write(uint8_t data)
{
	ddram[cursor_address] = data;
	cursor_step();
}

void sed1200_device::cursor_step()
{
	if(cursor_direction) {
		if(cursor_address != 0 && (!two_lines || cursor_address != 10))
			cursor_address --;
	} else {
		if((!two_lines || cursor_address != 9) && cursor_address != 19)
			cursor_address ++;
	}
}

const uint8_t *sed1200_device::render()
{
	memset(render_buf, 0, 20*8);
	if(!display_on)
		return render_buf;

	for(int i=0; i<20; i++) {
		uint8_t c = ddram[i];
		if(c < 4)
			memcpy(render_buf + 8*i, cgram + 8*c, 8);
		else if(cgrom)
			memcpy(render_buf + 8*i, cgrom + 8*c, 8);
	}

	if(cursor_on && (!cursor_blinking || (machine().time().as_ticks(2) & 1))) {
		if(cursor_full)
			for(int i=0; i<8; i++)
				render_buf[cursor_address*8+i] ^= 0x1f;
		else
			render_buf[cursor_address*8+7] ^= 0x1f;
	}

	return render_buf;
}