summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/bus/nubus/nubus_specpdq.c
blob: 71afcfa463a56d8eae79029b8aa7e7daed11699e (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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/***************************************************************************

  SuperMac Spectrum PDQ video card

  Accelerated only in 256 color mode.  Accleration is not yet emulated
  properly (pattern fill works but has glitches).  Use in B&W or 16 colors
  for full functionality right now.

  blitter info:

  ctrl 1 = ?
  ctrl 2 = low 3 bits of Y position in bits 3-5, low 3 bits of X position in bits 0-2
  ctrl 3 = width
  ctrl 4 = height
  ctrl 5 = ?
  ctrl 6 = VRAM offset * 4
  ctrl 7 = command/execute (00000002 for pattern fill, 00000100 for copy)

  Busy flag at Fs800000 (bit 8)

  There is 256 bytes of pattern RAM arranged as 32 pixels horizontally by 8
  vertically.

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

#include "emu.h"
#include "nubus_specpdq.h"

#define SPECPDQ_SCREEN_NAME "specpdq_screen"
#define SPECPDQ_ROM_REGION  "specpdq_rom"

#define VRAM_SIZE   (0x400000)

MACHINE_CONFIG_FRAGMENT( specpdq )
	MCFG_SCREEN_ADD( SPECPDQ_SCREEN_NAME, RASTER)
	MCFG_SCREEN_UPDATE_DEVICE(DEVICE_SELF, nubus_specpdq_device, screen_update)
	MCFG_SCREEN_RAW_PARAMS(25175000, 800, 0, 640, 525, 0, 480)
	MCFG_SCREEN_SIZE(1280,1024)
	MCFG_SCREEN_VISIBLE_AREA(0, 1152-1, 0, 844-1)
MACHINE_CONFIG_END

ROM_START( specpdq )
	ROM_REGION(0x10000, SPECPDQ_ROM_REGION, 0)
	ROM_LOAD( "specpdq.bin",  0x000000, 0x010000, CRC(82a35f78) SHA1(9511c2df47140f4279196d3b8836b53429879dd9) )
ROM_END

//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

const device_type NUBUS_SPECPDQ = &device_creator<nubus_specpdq_device>;


//-------------------------------------------------
//  machine_config_additions - device-specific
//  machine configurations
//-------------------------------------------------

machine_config_constructor nubus_specpdq_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( specpdq );
}

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

const rom_entry *nubus_specpdq_device::device_rom_region() const
{
	return ROM_NAME( specpdq );
}

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

//-------------------------------------------------
//  nubus_specpdq_device - constructor
//-------------------------------------------------

nubus_specpdq_device::nubus_specpdq_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
		device_t(mconfig, NUBUS_SPECPDQ, "SuperMac Spectrum PDQ video card", tag, owner, clock, "nb_spdq", __FILE__),
		device_video_interface(mconfig, *this),
		device_nubus_card_interface(mconfig, *this),
		m_assembled_tag(tag, ":", SPECPDQ_SCREEN_NAME)
{
	m_screen_tag = m_assembled_tag;
}

nubus_specpdq_device::nubus_specpdq_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) :
		device_t(mconfig, type, name, tag, owner, clock, shortname, source),
		device_video_interface(mconfig, *this),
		device_nubus_card_interface(mconfig, *this),
		m_assembled_tag(tag, ":", SPECPDQ_SCREEN_NAME)
{
	m_screen_tag = m_assembled_tag;
}

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

void nubus_specpdq_device::device_start()
{
	UINT32 slotspace;

	// set_nubus_device makes m_slot valid
	set_nubus_device();
	install_declaration_rom(this, SPECPDQ_ROM_REGION);

	slotspace = get_slotspace();

//  printf("[specpdq %p] slotspace = %x\n", this, slotspace);

	m_vram.resize(VRAM_SIZE);
	m_vram32 = (UINT32 *)&m_vram[0];
	m_nubus->install_device(slotspace, slotspace+VRAM_SIZE-1, read32_delegate(FUNC(nubus_specpdq_device::vram_r), this), write32_delegate(FUNC(nubus_specpdq_device::vram_w), this));
	m_nubus->install_device(slotspace+0x400000, slotspace+0xfbffff, read32_delegate(FUNC(nubus_specpdq_device::specpdq_r), this), write32_delegate(FUNC(nubus_specpdq_device::specpdq_w), this));

	m_timer = timer_alloc(0, NULL);
	m_timer->adjust(m_screen->time_until_pos(843, 0), 0);
}

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

void nubus_specpdq_device::device_reset()
{
	m_count = 0;
	m_clutoffs = 0;
	m_vbl_disable = 1;
	m_mode = 0;
	memset(m_vram, 0, VRAM_SIZE);
	memset(m_palette, 0, sizeof(m_palette));

	m_palette[0] = rgb_t(255, 255, 255);
	m_palette[0x80] = rgb_t(0, 0, 0);
}


void nubus_specpdq_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr)
{
	if (!m_vbl_disable)
	{
		raise_slot_irq();
	}

	m_timer->adjust(m_screen->time_until_pos(843, 0), 0);
}

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

  Spectrum 24 PDQ section

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

UINT32 nubus_specpdq_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	UINT32 *scanline;
	int x, y;
	UINT8 pixels, *vram;

	// first time?  kick off the VBL timer
	vram = m_vram + 0x9000;

	switch (m_mode)
	{
		case 0: // 1 bpp
			for (y = 0; y < 844; y++)
			{
				scanline = &bitmap.pix32(y);
				for (x = 0; x < 1152/8; x++)
				{
					pixels = vram[(y * 512) + (BYTE4_XOR_BE(x))];

					*scanline++ = m_palette[(pixels&0x80)];
					*scanline++ = m_palette[((pixels<<1)&0x80)];
					*scanline++ = m_palette[((pixels<<2)&0x80)];
					*scanline++ = m_palette[((pixels<<3)&0x80)];
					*scanline++ = m_palette[((pixels<<4)&0x80)];
					*scanline++ = m_palette[((pixels<<5)&0x80)];
					*scanline++ = m_palette[((pixels<<6)&0x80)];
					*scanline++ = m_palette[((pixels<<7)&0x80)];
				}
			}
			break;

		case 1: // 2 bpp
			for (y = 0; y < 844; y++)
			{
				scanline = &bitmap.pix32(y);
				for (x = 0; x < 1152/4; x++)
				{
					pixels = vram[(y * 512) + (BYTE4_XOR_BE(x))];

					*scanline++ = m_palette[(pixels&0xc0)];
					*scanline++ = m_palette[((pixels<<2)&0xc0)];
					*scanline++ = m_palette[((pixels<<4)&0xc0)];
					*scanline++ = m_palette[((pixels<<6)&0xc0)];
				}
			}
			break;

		case 2: // 4 bpp
			for (y = 0; y < 844; y++)
			{
				scanline = &bitmap.pix32(y);

				for (x = 0; x < 1152/2; x++)
				{
					pixels = vram[(y * 1024) + (BYTE4_XOR_BE(x))];

					*scanline++ = m_palette[(pixels&0xf0)];
					*scanline++ = m_palette[((pixels<<4)&0xf0)];
				}
			}
			break;

		case 3: // 8 bpp
			for (y = 0; y < 844; y++)
			{
				scanline = &bitmap.pix32(y);

				for (x = 0; x < 1152; x++)
				{
					pixels = vram[(y * 1152) + (BYTE4_XOR_BE(x))];
					*scanline++ = m_palette[pixels];
				}
			}
			break;

		default:
			fatalerror("specpdq: unknown video mode %d\n", m_mode);
			break;
	}
	return 0;
}

WRITE32_MEMBER( nubus_specpdq_device::specpdq_w )
{
	if (offset >= 0xc0000 && offset < 0x100000)
	{
		COMBINE_DATA(&m_7xxxxx_regs[offset-0xc0000]);
	}

	switch (offset)
	{
		case 0xc0054:   // mode 1
//          printf("%x to mode1\n", data);
			break;

		case 0xc005c:   // interrupt control
			if (!(data & 0x8000))
			{
				m_vbl_disable = 1;
			}
			else
			{
				m_vbl_disable = 0;
				lower_slot_irq();
			}
			break;

		case 0xc005e:   // not sure, interrupt related?
			break;

		case 0xc007a:
//          printf("%x to mode2\n", data);

			switch (data)
			{
				case 0xff7fffff:
					m_mode = 0;
					break;

				case 0xfeffffff:
					m_mode = 2;
					break;

				case 0xfedfffff:
					m_mode = 3;
					break;
			}

//          printf("m_mode = %d\n", m_mode);
			break;

		case 0x120000:  // DAC address
//          printf("%08x to DAC control (PC=%x)\n", data, space.device().safe_pc());
			m_clutoffs = ((data>>8)&0xff)^0xff;
			break;

		case 0x120001:  // DAC data
			m_colors[m_count++] = ((data>>8)&0xff)^0xff;

			if (m_count == 3)
			{
//              printf("RAMDAC: color %d = %02x %02x %02x (PC=%x)\n", m_clutoffs, m_colors[0], m_colors[1], m_colors[2], space.device().safe_pc() );
				palette_set_color(space.machine(), m_clutoffs, rgb_t(m_colors[0], m_colors[1], m_colors[2]));
				m_palette[m_clutoffs] = rgb_t(m_colors[0], m_colors[1], m_colors[2]);
				m_clutoffs++;
				if (m_clutoffs > 255)
				{
					m_clutoffs = 0;
				}
				m_count = 0;
			}
			break;

		// blitter texture? pattern?  256 pixels worth at 8bpp
		case 0x181000:
		case 0x181001:
		case 0x181002:
		case 0x181003:
		case 0x181004:
		case 0x181005:
		case 0x181006:
		case 0x181007:
		case 0x181008:
		case 0x181009:
		case 0x18100a:
		case 0x18100b:
		case 0x18100c:
		case 0x18100d:
		case 0x18100e:
		case 0x18100f:
		case 0x181010:
		case 0x181011:
		case 0x181012:
		case 0x181013:
		case 0x181014:
		case 0x181015:
		case 0x181016:
		case 0x181017:
		case 0x181018:
		case 0x181019:
		case 0x18101a:
		case 0x18101b:
		case 0x18101c:
		case 0x18101d:
		case 0x18101e:
		case 0x18101f:
		case 0x181020:
		case 0x181021:
		case 0x181022:
		case 0x181023:
		case 0x181024:
		case 0x181025:
		case 0x181026:
		case 0x181027:
		case 0x181028:
		case 0x181029:
		case 0x18102a:
		case 0x18102b:
		case 0x18102c:
		case 0x18102d:
		case 0x18102e:
		case 0x18102f:
		case 0x181030:
		case 0x181031:
		case 0x181032:
		case 0x181033:
		case 0x181034:
		case 0x181035:
		case 0x181036:
		case 0x181037:
		case 0x181038:
		case 0x181039:
		case 0x18103a:
		case 0x18103b:
		case 0x18103c:
		case 0x18103d:
		case 0x18103e:
		case 0x18103f:
//          printf("Pattern %08x @ %x\n", data ^ 0xffffffff, offset);
			m_fillbytes[((offset&0x3f)*4)] = ((data>>24) & 0xff) ^ 0xff;
			m_fillbytes[((offset&0x3f)*4)+1] = ((data>>16) & 0xff) ^ 0xff;
			m_fillbytes[((offset&0x3f)*4)+2] = ((data>>8) & 0xff) ^ 0xff;
			m_fillbytes[((offset&0x3f)*4)+3] = (data& 0xff) ^ 0xff;
			break;

		// blitter control
		case 0x182006:
//          printf("%08x (%d) to blitter ctrl 1 (PC=%x)\n", data^0xffffffff, data^0xffffffff, space.device().safe_pc());
			break;

		case 0x182008:
//          printf("%08x (%d) to blitter ctrl 2 (PC=%x)\n", data^0xffffffff, data^0xffffffff, space.device().safe_pc());
			m_patofsx = (data ^ 0xffffffff) & 7;
			m_patofsy = ((data ^ 0xffffffff)>>3) & 7;
			break;

		case 0x18200e:
//          printf("%08x (%d) to blitter ctrl 3 (PC=%x)\n", data^0xffffffff, data^0xffffffff, space.device().safe_pc());
			m_width = data ^ 0xffffffff;
			break;

		case 0x18200b:
//          printf("%08x (%d) to blitter ctrl 4 (PC=%x)\n", data^0xffffffff, data^0xffffffff, space.device().safe_pc());
			m_height = (data ^ 0xffffffff) & 0xffff;
			break;

		case 0x18200a:
			data ^= 0xffffffff;
//          printf("%08x to blitter ctrl 5 (PC=%x)\n", data, space.device().safe_pc());
			m_vram_src = data>>2;
			break;

		case 0x182009:
			data ^= 0xffffffff;
//          printf("%08x to blitter ctrl 6 (PC=%x)\n", data, space.device().safe_pc());
			m_vram_addr = data>>2;
			break;

		case 0x182007:
			data ^= 0xffffffff;
//          printf("%08x to blitter ctrl 7 (PC=%x)\n", data, space.device().safe_pc());

			// fill rectangle
			if (data == 2)
			{
				int x, y;
				UINT8 *vram = m_vram + m_vram_addr + m_patofsx; // m_vram_addr is missing the low 2 bits, we add them back here

//              printf("Fill rectangle with %02x %02x %02x %02x, width %d height %d\n", m_fillbytes[0], m_fillbytes[1], m_fillbytes[2], m_fillbytes[3], m_width, m_height);

				for (y = 0; y < m_height; y++)
				{
					for (x = 0; x < m_width; x++)
					{
						vram[(y * 1152)+x] = m_fillbytes[((m_patofsx + x) & 0x1f)+(((m_patofsy + y) & 0x7)*32)];
					}
				}
			}
			else if ((data == 0x101) || (data == 0x100))
			{
				int x, y;
				UINT8 *vram = m_vram + m_vram_addr;
				UINT8 *vramsrc = m_vram + m_vram_src;

//              printf("Copy rectangle, width %d height %d  src %x dst %x\n", m_width, m_height, m_vram_addr, m_vram_src);

				for (y = 0; y < m_height; y++)
				{
					for (x = 0; x < m_width; x++)
					{
						vram[(y * 1152)+x] = vramsrc[(y * 1152)+x];
					}
				}
			}
			else
			{
				printf("Unknown blitter command %08x\n", data);
			}
			break;

		default:
//          printf("specpdq_w: %08x @ %x (mask %08x  PC=%x)\n", data^0xffffffff, offset, mem_mask, space.device().safe_pc());
			break;
	}
}

READ32_MEMBER( nubus_specpdq_device::specpdq_r )
{
//  if (offset != 0xc005c && offset != 0xc005e) printf("specpdq_r: @ %x (mask %08x  PC=%x)\n", offset, mem_mask, space.device().safe_pc());

	if (offset >= 0xc0000 && offset < 0x100000)
	{
		return m_7xxxxx_regs[offset-0xc0000];
	}

	return 0;
}

WRITE32_MEMBER( nubus_specpdq_device::vram_w )
{
	data ^= 0xffffffff;
	COMBINE_DATA(&m_vram32[offset]);
}

READ32_MEMBER( nubus_specpdq_device::vram_r )
{
	return m_vram32[offset] ^ 0xffffffff;
}