1 // license:BSD-3-Clause
2 // copyright-holders:hap
3 /*
4 
5 Epson SED1500 series LCD Driver
6 128 bytes internal RAM.
7 
8 SED1500: 8 commons, 42 segments
9 SED1501: 10 commons, 40 segments
10 SED1502: 16 commons, 34 segments
11 SED1503: 8 commons, 42 segments, needs multiple of 2 chips to function
12 
13 The default input OSC frequency is 32768Hz, the frame output frequency is
14 divided by 64 and by number of commons, eg. 64Hz on a SED1500.
15 
16 TODO:
17 - bus mode (only mode 3 now)
18 - EI pin (master/slave mode)
19 - SYNC pin, used for frame synchronizing if multiple chips are used
20 - SED1503 only has 8 COM pins, the extra 8 outputs are from the slave chip
21 
22 */
23 
24 #include "emu.h"
25 #include "video/sed1500.h"
26 
27 
28 DEFINE_DEVICE_TYPE(SED1500, sed1500_device, "sed1500", "Epson SED1500 LCD Driver")
29 DEFINE_DEVICE_TYPE(SED1501, sed1501_device, "sed1501", "Epson SED1501 LCD Driver")
30 DEFINE_DEVICE_TYPE(SED1502, sed1502_device, "sed1502", "Epson SED1502 LCD Driver")
31 DEFINE_DEVICE_TYPE(SED1503, sed1503_device, "sed1503", "Epson SED1503 LCD Driver")
32 
33 //-------------------------------------------------
34 //  constructor
35 //-------------------------------------------------
36 
sed1500_device(const machine_config & mconfig,device_type type,const char * tag,device_t * owner,u32 clock,u8 cmax,u8 smax)37 sed1500_device::sed1500_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u8 cmax, u8 smax) :
38 	device_t(mconfig, type, tag, owner, clock),
39 	m_cmax(cmax), m_smax(smax),
40 	m_write_segs(*this)
41 { }
42 
sed1500_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)43 sed1500_device::sed1500_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
44 	sed1500_device(mconfig, SED1500, tag, owner, clock, 8, 42)
45 { }
46 
sed1501_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)47 sed1501_device::sed1501_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
48 	sed1500_device(mconfig, SED1501, tag, owner, clock, 10, 40)
49 { }
50 
sed1502_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)51 sed1502_device::sed1502_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
52 	sed1500_device(mconfig, SED1502, tag, owner, clock, 16, 34)
53 { }
54 
sed1503_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)55 sed1503_device::sed1503_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
56 	sed1500_device(mconfig, SED1503, tag, owner, clock, 8+8, 42)
57 { }
58 
59 
60 //-------------------------------------------------
61 //  device_start - device-specific startup
62 //-------------------------------------------------
63 
device_start()64 void sed1500_device::device_start()
65 {
66 	memset(m_ram, 0, sizeof(m_ram));
67 
68 	// resolve callbacks
69 	m_write_segs.resolve_safe();
70 
71 	// timer
72 	m_lcd_timer = timer_alloc();
73 	attotime period = attotime::from_hz(clock() / 64);
74 	m_lcd_timer->adjust(period, 0, period);
75 
76 	// register for savestates
77 	save_item(NAME(m_mode));
78 	save_item(NAME(m_cout));
79 	save_item(NAME(m_ram));
80 }
81 
82 
83 //-------------------------------------------------
84 //  handlers
85 //-------------------------------------------------
86 
device_timer(emu_timer & timer,device_timer_id id,int param,void * ptr)87 void sed1500_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
88 {
89 	u64 data = 0;
90 
91 	for (int i = m_smax-1; i >= 0; i--)
92 		data = data << 1 | BIT(m_ram[i | 0x40] << 8 | m_ram[i], m_cout);
93 
94 	// transfer segments to output
95 	m_write_segs(m_cout, data);
96 	m_cout = (m_cout + 1) % m_cmax;
97 }
98 
write(offs_t offset,u8 data)99 void sed1500_device::write(offs_t offset, u8 data)
100 {
101 	offset &= 0x7f;
102 	m_ram[offset] = data;
103 
104 	// bus mode command:
105 	// 0 = 4-bit addr, 4-bit data, combined
106 	// 1 = 7-bit addr, 4-bit data, separate
107 	// 2 = 7-bit addr, 8-bit data, combined
108 	// 3 = 7-bit addr, 8-bit data, separate
109 	if ((offset & 0x3f) == 0x3f && ~data & 1)
110 		m_mode = data >> 1 & 3;
111 }
112 
read(offs_t offset)113 u8 sed1500_device::read(offs_t offset)
114 {
115 	return m_ram[offset & 0x7f];
116 }
117