summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/tanbus/tanhrg.cpp
blob: b857e84ac69f581e6658403bc31d4d91bc79519e (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    Tangerine High Resolution Graphics Card (MT0055 Iss2)

    http://www.microtan.ukpc.net/pageProducts.html#VIDEO

    TODO:
    - option to merge MT65 chunky and HRG screens

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


#include "emu.h"
#include "tanhrg.h"


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

DEFINE_DEVICE_TYPE(TANBUS_TANHRG, tanbus_tanhrg_device, "tanbus_tanhrg", "Tangerine High Resolution Graphics Card (monochrome)")
DEFINE_DEVICE_TYPE(TANBUS_TANHRGC, tanbus_tanhrgc_device, "tanbus_tanhrgc", "Tangerine High Resolution Graphics Card (colour)")

//-------------------------------------------------
//  INPUT_PORTS( tanhrg )
//-------------------------------------------------

INPUT_PORTS_START(tanhrg)
	PORT_START("DSW")
	PORT_DIPNAME(0x07, 0x04, "Address Space") PORT_DIPLOCATION("DSW:1,2,3")
	PORT_DIPSETTING(0x00, "&0000-&1FFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x01, "&2000-&3FFF")
	PORT_DIPSETTING(0x02, "&4000-&5FFF")
	PORT_DIPSETTING(0x03, "&6000-&7FFF")
	PORT_DIPSETTING(0x04, "&8000-&9FFF")
	PORT_DIPSETTING(0x05, "&A000-&BFFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x06, "&C000-&DFFF")
	PORT_DIPSETTING(0x07, "&E000-&FFFF")
	PORT_DIPNAME(0x08, 0x00, "Video") PORT_DIPLOCATION("DSW:4")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x08, DEF_STR(On))
	PORT_DIPNAME(0x10, 0x10, "Inhibit RAM (INHRAM)") PORT_DIPLOCATION("DSW:5")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x10, DEF_STR(On))
	PORT_DIPNAME(0x20, 0x20, "Block Enable (BE)") PORT_DIPLOCATION("DSW:6")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x20, DEF_STR(On))
INPUT_PORTS_END


INPUT_PORTS_START(tanhrgc)
	PORT_START("DSW_1")
	PORT_DIPNAME(0x07, 0x02, "Address Space - Red") PORT_DIPLOCATION("DSW_R:1,2,3")
	PORT_DIPSETTING(0x00, "&0000-&1FFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x01, "&2000-&3FFF")
	PORT_DIPSETTING(0x02, "&4000-&5FFF")
	PORT_DIPSETTING(0x03, "&6000-&7FFF")
	PORT_DIPSETTING(0x04, "&8000-&9FFF")
	PORT_DIPSETTING(0x05, "&A000-&BFFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x06, "&C000-&DFFF")
	PORT_DIPSETTING(0x07, "&E000-&FFFF")
	PORT_DIPNAME(0x08, 0x00, "Video") PORT_DIPLOCATION("DSW_R:4")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x08, DEF_STR(On))
	PORT_DIPNAME(0x10, 0x10, "Inhibit RAM (INHRAM)") PORT_DIPLOCATION("DSW_R:5")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x10, DEF_STR(On))
	PORT_DIPNAME(0x20, 0x20, "Block Enable (BE)") PORT_DIPLOCATION("DSW_R:6")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x20, DEF_STR(On))

	PORT_START("DSW_2")
	PORT_DIPNAME(0x07, 0x04, "Address Space - Green") PORT_DIPLOCATION("DSW_G:1,2,3")
	PORT_DIPSETTING(0x00, "&0000-&1FFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x01, "&2000-&3FFF")
	PORT_DIPSETTING(0x02, "&4000-&5FFF")
	PORT_DIPSETTING(0x03, "&6000-&7FFF")
	PORT_DIPSETTING(0x04, "&8000-&9FFF")
	PORT_DIPSETTING(0x05, "&A000-&BFFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x06, "&C000-&DFFF")
	PORT_DIPSETTING(0x07, "&E000-&FFFF")
	PORT_DIPNAME(0x08, 0x00, "Video") PORT_DIPLOCATION("DSW_G:4")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x08, DEF_STR(On))
	PORT_DIPNAME(0x10, 0x10, "Inhibit RAM (INHRAM)") PORT_DIPLOCATION("DSW_G:5")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x10, DEF_STR(On))
	PORT_DIPNAME(0x20, 0x20, "Block Enable (BE)") PORT_DIPLOCATION("DSW_G:6")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x20, DEF_STR(On))

	PORT_START("DSW_3")
	PORT_DIPNAME(0x07, 0x03, "Address Space - Blue") PORT_DIPLOCATION("DSW_B:1,2,3")
	PORT_DIPSETTING(0x00, "&0000-&1FFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x01, "&2000-&3FFF")
	PORT_DIPSETTING(0x02, "&4000-&5FFF")
	PORT_DIPSETTING(0x03, "&6000-&7FFF")
	PORT_DIPSETTING(0x04, "&8000-&9FFF")
	PORT_DIPSETTING(0x05, "&A000-&BFFF (Invalid - Do Not Use)")
	PORT_DIPSETTING(0x06, "&C000-&DFFF")
	PORT_DIPSETTING(0x07, "&E000-&FFFF")
	PORT_DIPNAME(0x08, 0x00, "Video") PORT_DIPLOCATION("DSW_B:4")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x08, DEF_STR(On))
	PORT_DIPNAME(0x10, 0x10, "Inhibit RAM (INHRAM)") PORT_DIPLOCATION("DSW_B:5")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x10, DEF_STR(On))
	PORT_DIPNAME(0x20, 0x20, "Block Enable (BE)") PORT_DIPLOCATION("DSW_B:6")
	PORT_DIPSETTING(0x00, DEF_STR(Off))
	PORT_DIPSETTING(0x20, DEF_STR(On))
INPUT_PORTS_END


//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor tanbus_tanhrg_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(tanhrg);
}


ioport_constructor tanbus_tanhrgc_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(tanhrgc);
}


//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void tanbus_tanhrg_device::device_add_mconfig(machine_config &config)
{
	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
	m_screen->set_raw(6_MHz_XTAL, 384, 0, 256, 312, 0, 256);
	m_screen->set_screen_update(FUNC(tanbus_tanhrg_device::screen_update));

	PALETTE(config, m_palette, palette_device::MONOCHROME);
}


void tanbus_tanhrgc_device::device_add_mconfig(machine_config &config)
{
	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
	m_screen->set_raw(6_MHz_XTAL, 384, 0, 256, 312, 0, 256);
	m_screen->set_screen_update(FUNC(tanbus_tanhrgc_device::screen_update));

	PALETTE(config, m_palette, palette_device::RGB_3BIT);
}


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

//-------------------------------------------------
//  tanbus_tanhrg_device - constructor
//-------------------------------------------------

tanbus_tanhrg_device::tanbus_tanhrg_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, TANBUS_TANHRG, tag, owner, clock)
	, device_tanbus_interface(mconfig, *this)
	, m_dsw(*this, "DSW")
	, m_screen(*this, "screen")
	, m_palette(*this, "palette")
{
}


tanbus_tanhrgc_device::tanbus_tanhrgc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, TANBUS_TANHRGC, tag, owner, clock)
	, device_tanbus_interface(mconfig, *this)
	, m_dsw(*this, "DSW_%u", 1)
	, m_screen(*this, "screen")
	, m_palette(*this, "palette")
{
}


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

void tanbus_tanhrg_device::device_start()
{
	m_videoram = std::make_unique<uint8_t[]>(0x2000);

	/* randomize video memory contents */
	for (uint16_t addr = 0; addr < 0x2000; addr++)
		m_videoram[addr] = machine().rand() & 0xff;

	save_pointer(NAME(m_videoram), 0x2000);
}


void tanbus_tanhrgc_device::device_start()
{
	m_videoram = std::make_unique<uint8_t[]>(0x6000);

	/* randomize video memory contents */
	for (uint16_t addr = 0; addr < 0x6000; addr++)
		m_videoram[addr] = machine().rand() & 0xff;

	save_pointer(NAME(m_videoram), 0x6000);
}


//-------------------------------------------------
//  read - card read
//-------------------------------------------------

uint8_t tanbus_tanhrg_device::read(offs_t offset, int inhrom, int inhram, int be)
{
	uint8_t data = 0xff;

	offs_t addr = (m_dsw->read() & 7) << 13;

	if ((!BIT(m_dsw->read(), 5) || be) && (offset & 0xe000) == addr)
	{
		data = m_videoram[offset & 0x1fff];
	}

	return data;
}


uint8_t tanbus_tanhrgc_device::read(offs_t offset, int inhrom, int inhram, int be)
{
	uint8_t data = 0xff;

	offs_t addr_r = (m_dsw[0]->read() & 7) << 13;
	offs_t addr_g = (m_dsw[1]->read() & 7) << 13;
	offs_t addr_b = (m_dsw[2]->read() & 7) << 13;

	if ((!BIT(m_dsw[0]->read(), 5) || be) && (offset & 0xe000) == addr_r)
	{
		data = m_videoram[0x0000 | (offset & 0x1fff)];
	}
	else if ((!BIT(m_dsw[1]->read(), 5) || be) && (offset & 0xe000) == addr_g)
	{
		data = m_videoram[0x2000 | (offset & 0x1fff)];
	}
	else if ((!BIT(m_dsw[2]->read(), 5) || be) && (offset & 0xe000) == addr_b)
	{
		data = m_videoram[0x4000 | (offset & 0x1fff)];
	}

	return data;
}


//-------------------------------------------------
//  write - card write
//-------------------------------------------------

void tanbus_tanhrg_device::write(offs_t offset, uint8_t data, int inhrom, int inhram, int be)
{
	offs_t addr = (m_dsw->read() & 7) << 13;

	if ((!BIT(m_dsw->read(), 5) || be) && (offset & 0xe000) == addr)
	{
		m_videoram[offset & 0x1fff] = data;
	}
}


void tanbus_tanhrgc_device::write(offs_t offset, uint8_t data, int inhrom, int inhram, int be)
{
	offs_t addr_r = (m_dsw[0]->read() & 7) << 13;
	offs_t addr_g = (m_dsw[1]->read() & 7) << 13;
	offs_t addr_b = (m_dsw[2]->read() & 7) << 13;

	if ((!BIT(m_dsw[0]->read(), 5) || be) && (offset & 0xe000) == addr_r)
	{
		m_videoram[0x0000 | (offset & 0x1fff)] = data;
	}
	else if ((!BIT(m_dsw[1]->read(), 5) || be) && (offset & 0xe000) == addr_g)
	{
		m_videoram[0x2000 | (offset & 0x1fff)] = data;
	}
	else if ((!BIT(m_dsw[2]->read(), 5) || be) && (offset & 0xe000) == addr_b)
	{
		m_videoram[0x4000 | (offset & 0x1fff)] = data;
	}
}


//-------------------------------------------------
//  set_inhibit_lines
//-------------------------------------------------

void tanbus_tanhrg_device::set_inhibit_lines(offs_t offset, int &inhram, int &inhrom)
{
	offs_t addr = (m_dsw->read() & 7) << 13;

	if (BIT(m_dsw->read(), 4) && (offset & 0xe000) == addr)
	{
		inhram = 1;
	}
};


void tanbus_tanhrgc_device::set_inhibit_lines(offs_t offset, int &inhram, int &inhrom)
{
	offs_t addr_r = (m_dsw[0]->read() & 7) << 13;
	offs_t addr_g = (m_dsw[1]->read() & 7) << 13;
	offs_t addr_b = (m_dsw[2]->read() & 7) << 13;

	if ((BIT(m_dsw[0]->read(), 4) && (offset & 0xe000) == addr_r) || (BIT(m_dsw[1]->read(), 4) && (offset & 0xe000) == addr_g) || (BIT(m_dsw[2]->read(), 4) && (offset & 0xe000) == addr_b))
	{
		inhram = 1;
	}
};


//-------------------------------------------------
//  screen_update
//-------------------------------------------------

uint32_t tanbus_tanhrg_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	for (int y = 0; y < 256; y++)
	{
		uint32_t *p = &bitmap.pix(y);

		for (int x = 0; x < 256; x++)
		{
			uint16_t const offset = (y * 32) + (x / 8);

			*p++ = m_palette->pen_color(BIT(m_videoram[offset], x & 7));
		}
	}

	return 0;
}


uint32_t tanbus_tanhrgc_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	for (int y = 0; y < 256; y++)
	{
		uint32_t *p = &bitmap.pix(y);

		for (int x = 0; x < 256; x++)
		{
			uint16_t const offset = (y * 32) + (x / 8);

			uint8_t const r = m_videoram[0x0000 | offset];
			uint8_t const b = m_videoram[0x2000 | offset];
			uint8_t const g = m_videoram[0x4000 | offset];

			*p++ = m_palette->pen_color(BIT(b, x & 7) << 2 | BIT(g, x & 7) << 1 | BIT(r, x & 7));
		}
	}

	return 0;
}