1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Wang PC Text/Image/Graphics controller emulation
6 
7 **********************************************************************/
8 
9 /*
10 
11     TODO:
12 
13     - all
14 
15 */
16 
17 #include "emu.h"
18 #include "tig.h"
19 
20 #include "screen.h"
21 
22 
23 
24 //**************************************************************************
25 //  MACROS/CONSTANTS
26 //**************************************************************************
27 
28 #define LOG 1
29 
30 #define OPTION_ID_0         0x13
31 #define OPTION_ID_1         0x17
32 
33 #define UPD7720_0_TAG       "upd7220_0"
34 #define UPD7720_1_TAG       "upd7220_1"
35 #define SCREEN_TAG          "screen"
36 
37 #define DMA_GRAPHICS        BIT(m_option, 0)
38 #define DMA_DREQ1           BIT(m_option, 1)
39 #define DMA_DREQ2           BIT(m_option, 2)
40 #define DMA_DREQ3           BIT(m_option, 3)
41 #define DMA_ID              BIT(m_option, 4)
42 
43 #define ATTR_ALT_FONT       BIT(data, 8)
44 #define ATTR_UNDERSCORE     BIT(data, 9)
45 #define ATTR_BLINK          BIT(data, 10)
46 #define ATTR_REVERSE        BIT(data, 11)
47 #define ATTR_BLANK          BIT(data, 12)
48 #define ATTR_BOLD           BIT(data, 13)
49 #define ATTR_SUBSCRIPT      BIT(data, 14)
50 #define ATTR_SUPERSCRIPT    BIT(data, 15)
51 
52 
53 
54 //**************************************************************************
55 //  DEVICE DEFINITIONS
56 //**************************************************************************
57 
58 DEFINE_DEVICE_TYPE(WANGPC_TIG, wangpc_tig_device, "wangpc_tig", "Want PC Text/Image/Graphics Controller")
59 
60 
61 //-------------------------------------------------
62 //  ROM( wangpc_tig )
63 //-------------------------------------------------
64 
ROM_START(wangpc_tig)65 ROM_START( wangpc_tig )
66 	ROM_REGION( 0x100, "plds", 0 )
67 	ROM_LOAD( "377-3072.l26", 0x000, 0x100, NO_DUMP ) // PAL10L8
68 	ROM_LOAD( "377-3073.l16", 0x000, 0x100, NO_DUMP ) // PAL10L8
69 ROM_END
70 
71 
72 //-------------------------------------------------
73 //  rom_region - device-specific ROM region
74 //-------------------------------------------------
75 
76 const tiny_rom_entry *wangpc_tig_device::device_rom_region() const
77 {
78 	return ROM_NAME( wangpc_tig );
79 }
80 
81 
82 //-------------------------------------------------
83 //  UPD7220_INTERFACE( hgdc0_intf )
84 //-------------------------------------------------
85 
upd7220_0_map(address_map & map)86 void wangpc_tig_device::upd7220_0_map(address_map &map)
87 {
88 	map.global_mask(0x7fff);
89 	map(0x0000, 0x0fff).mirror(0x1000).ram(); // frame buffer
90 	map(0x4000, 0x7fff).ram(); // font memory
91 }
92 
UPD7220_DRAW_TEXT_LINE_MEMBER(wangpc_tig_device::hgdc_draw_text)93 UPD7220_DRAW_TEXT_LINE_MEMBER( wangpc_tig_device::hgdc_draw_text )
94 {
95 }
96 
97 
98 //-------------------------------------------------
99 //  UPD7220_INTERFACE( hgdc1_intf )
100 //-------------------------------------------------
101 
upd7220_1_map(address_map & map)102 void wangpc_tig_device::upd7220_1_map(address_map &map)
103 {
104 	map.global_mask(0xffff);
105 	map(0x0000, 0xffff).ram(); // graphics memory
106 }
107 
UPD7220_DISPLAY_PIXELS_MEMBER(wangpc_tig_device::hgdc_display_pixels)108 UPD7220_DISPLAY_PIXELS_MEMBER( wangpc_tig_device::hgdc_display_pixels )
109 {
110 }
111 
112 
113 //-------------------------------------------------
114 //  machine_config( wangpc_tig )
115 //-------------------------------------------------
116 
device_add_mconfig(machine_config & config)117 void wangpc_tig_device::device_add_mconfig(machine_config &config)
118 {
119 	screen_device &screen(SCREEN(config, SCREEN_TAG, SCREEN_TYPE_RASTER, rgb_t::green()));
120 	screen.set_screen_update(FUNC(wangpc_tig_device::screen_update));
121 	screen.set_size(80*10, 25*12);
122 	screen.set_visarea(0, 80*10-1, 0, 25*12-1);
123 	screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500));
124 	screen.set_refresh_hz(60);
125 
126 	PALETTE(config, m_palette, palette_device::MONOCHROME_HIGHLIGHT);
127 
128 	UPD7220(config, m_hgdc0, XTAL(52'832'000)/28);
129 	m_hgdc0->set_addrmap(0, &wangpc_tig_device::upd7220_0_map);
130 	m_hgdc0->set_draw_text(FUNC(wangpc_tig_device::hgdc_draw_text));
131 	m_hgdc0->set_screen(SCREEN_TAG);
132 
133 	UPD7220(config, m_hgdc1, XTAL(52'832'000)/28);
134 	m_hgdc1->set_addrmap(0, &wangpc_tig_device::upd7220_1_map);
135 	m_hgdc1->set_display_pixels(FUNC(wangpc_tig_device::hgdc_display_pixels));
136 	m_hgdc1->set_screen(SCREEN_TAG);
137 }
138 
139 
140 //**************************************************************************
141 //  LIVE DEVICE
142 //**************************************************************************
143 
144 //-------------------------------------------------
145 //  wangpc_tig_device - constructor
146 //-------------------------------------------------
147 
wangpc_tig_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)148 wangpc_tig_device::wangpc_tig_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
149 	device_t(mconfig, WANGPC_TIG, tag, owner, clock),
150 	device_wangpcbus_card_interface(mconfig, *this),
151 	m_hgdc0(*this, UPD7720_0_TAG),
152 	m_hgdc1(*this, UPD7720_1_TAG),
153 	m_option(0), m_underline(0),
154 	m_palette(*this, "palette")
155 {
156 }
157 
158 
159 //-------------------------------------------------
160 //  device_start - device-specific startup
161 //-------------------------------------------------
162 
device_start()163 void wangpc_tig_device::device_start()
164 {
165 	// state saving
166 	save_item(NAME(m_option));
167 	save_item(NAME(m_attr));
168 	save_item(NAME(m_underline));
169 }
170 
171 
172 //-------------------------------------------------
173 //  device_reset - device-specific reset
174 //-------------------------------------------------
175 
device_reset()176 void wangpc_tig_device::device_reset()
177 {
178 	m_option = 0;
179 }
180 
181 
182 //-------------------------------------------------
183 //  screen_update -
184 //-------------------------------------------------
185 
screen_update(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)186 uint32_t wangpc_tig_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
187 {
188 	m_hgdc0->screen_update(screen, bitmap, cliprect);
189 	m_hgdc1->screen_update(screen, bitmap, cliprect);
190 
191 	return 0;
192 }
193 
194 
195 //-------------------------------------------------
196 //  wangpcbus_iorc_r - I/O read
197 //-------------------------------------------------
198 
wangpcbus_iorc_r(offs_t offset,uint16_t mem_mask)199 uint16_t wangpc_tig_device::wangpcbus_iorc_r(offs_t offset, uint16_t mem_mask)
200 {
201 	uint16_t data = 0xffff;
202 
203 	if (sad(offset))
204 	{
205 		switch (offset & 0x7f)
206 		{
207 		case 0x20/2:
208 		case 0x22/2:
209 			data = m_hgdc0->read(offset);
210 			break;
211 
212 		case 0x24/2:
213 		case 0x26/2:
214 			data = m_hgdc1->read(offset);
215 			break;
216 
217 		case 0xfe/2:
218 			data = 0xff00 | (DMA_ID ? OPTION_ID_1 : OPTION_ID_0);
219 			break;
220 		}
221 	}
222 
223 	return data;
224 }
225 
226 
227 //-------------------------------------------------
228 //  wangpcbus_aiowc_w - I/O write
229 //-------------------------------------------------
230 
wangpcbus_aiowc_w(offs_t offset,uint16_t mem_mask,uint16_t data)231 void wangpc_tig_device::wangpcbus_aiowc_w(offs_t offset, uint16_t mem_mask, uint16_t data)
232 {
233 	if (sad(offset) && ACCESSING_BITS_0_7)
234 	{
235 		switch (offset & 0x7f)
236 		{
237 		case 0x00/2: case 0x02/2: case 0x04/2: case 0x06/2: case 0x08/2: case 0x0a/2: case 0x0c/2: case 0x0e/2:
238 		case 0x10/2: case 0x12/2: case 0x14/2: case 0x16/2: case 0x18/2: case 0x1a/2: case 0x1c/2: case 0x1e/2:
239 			if (LOG) logerror("TIG attribute %u: %02x\n", offset, data & 0xff);
240 
241 			m_attr[offset] = data & 0xff;
242 			break;
243 
244 		case 0x20/2:
245 		case 0x22/2:
246 			m_hgdc0->write(offset, data);
247 			break;
248 
249 		case 0x24/2:
250 		case 0x26/2:
251 			m_hgdc1->write(offset, data);
252 			break;
253 
254 		case 0x28/2:
255 			if (LOG) logerror("TIG underline %02x\n", data & 0xff);
256 
257 			m_underline = data & 0xff;
258 			break;
259 
260 		case 0x2a/2:
261 			if (LOG) logerror("TIG option %02x\n", data & 0xff);
262 
263 			m_option = data & 0xff;
264 			break;
265 
266 		case 0xfc/2:
267 			device_reset();
268 			break;
269 		}
270 	}
271 }
272 
273 
274 //-------------------------------------------------
275 //  wangpcbus_dack_r - DMA read
276 //-------------------------------------------------
277 
wangpcbus_dack_r(int line)278 uint8_t wangpc_tig_device::wangpcbus_dack_r(int line)
279 {
280 	uint8_t data;
281 
282 	if (DMA_GRAPHICS)
283 	{
284 		data = m_hgdc1->dack_r();
285 	}
286 	else
287 	{
288 		data = m_hgdc0->dack_r();
289 	}
290 
291 	return data;
292 }
293 
294 
295 //-------------------------------------------------
296 //  wangpcbus_dack_w - DMA write
297 //-------------------------------------------------
298 
wangpcbus_dack_w(int line,uint8_t data)299 void wangpc_tig_device::wangpcbus_dack_w(int line, uint8_t data)
300 {
301 	if (DMA_GRAPHICS)
302 	{
303 		m_hgdc1->dack_w(data);
304 	}
305 	else
306 	{
307 		m_hgdc0->dack_w(data);
308 	}
309 }
310 
311 
312 //-------------------------------------------------
313 //  wangpcbus_have_dack - DMA acknowledge
314 //-------------------------------------------------
315 
wangpcbus_have_dack(int line)316 bool wangpc_tig_device::wangpcbus_have_dack(int line)
317 {
318 	return (line == 1 && DMA_DREQ1) || (line == 2 && DMA_DREQ2) || (line == 3 && DMA_DREQ3);
319 }
320