summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/antic.c
blob: 516c8b2a011b229c440aee42987c00d7cd488d4d (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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/******************************************************************************
    Atari 400/800

    ANTIC video controller

    Juergen Buchmueller, June 1998
******************************************************************************/

#include "driver.h"
#include "cpu/m6502/m6502.h"
#include "includes/atari.h"

#ifdef MAME_DEBUG
#define VERBOSE 1
#else
#define VERBOSE 0
#endif

#if VERBOSE
#define LOG(x)	logerror x
#else
#define LOG(x)	/* x */
#endif

ANTIC antic;

/**************************************************************
 *
 * Reset ANTIC
 *
 **************************************************************/

void antic_reset(void)
{
	/* reset the ANTIC read / write registers */
	memset(&antic.r, 0, sizeof(antic.r));
	memset(&antic.w, 0, sizeof(antic.w));
	antic.r.antic00 = 0xff;
	antic.r.antic01 = 0xff;
	antic.r.antic02 = 0xff;
	antic.r.antic03 = 0xff;
	antic.r.antic04 = 0xff;
	antic.r.antic05 = 0xff;
	antic.r.antic06 = 0xff;
	antic.r.antic07 = 0xff;
	antic.r.antic08 = 0xff;
	antic.r.antic09 = 0xff;
	antic.r.antic0a = 0xff;
	antic.r.penh	= 0x00;
	antic.r.penv	= 0x00;
	antic.r.antic0e = 0xff;
	antic.r.nmist	= 0x1f;
}

/**************************************************************
 *
 * Read ANTIC hardware registers
 *
 **************************************************************/
READ8_HANDLER ( atari_antic_r )
{
	UINT8 data = 0xff;

	switch (offset & 15)
	{
	case  0: /* nothing */
		data = antic.r.antic00;
		break;
	case  1: /* nothing */
		data = antic.r.antic01;
		break;
	case  2: /* nothing */
		data = antic.r.antic02;
		break;
	case  3: /* nothing */
		data = antic.r.antic03;
		break;
	case  4: /* nothing */
		data = antic.r.antic04;
		break;
	case  5: /* nothing */
		data = antic.r.antic05;
		break;
	case  6: /* nothing */
		data = antic.r.antic06;
		break;
	case  7: /* nothing */
		data = antic.r.antic07;
		break;
	case  8: /* nothing */
		data = antic.r.antic08;
		break;
	case  9: /* nothing */
		data = antic.r.antic09;
		break;
	case 10: /* WSYNC read */
		cpunum_spinuntil_trigger(0, TRIGGER_HSYNC);
		antic.w.wsync = 1;
		data = antic.r.antic0a;
		break;
	case 11: /* vert counter (scanline / 2) */
		data = antic.r.vcount = antic.scanline >> 1;
		break;
	case 12: /* light pen horz pos */
		data = antic.r.penh;
		break;
	case 13: /* light pen vert pos */
		data = antic.r.penv;
		break;
	case 14: /* NMI enable */
		data = antic.r.antic0e;
		break;
	case 15: /* NMI status */
		data = antic.r.nmist;
		break;
	}
	return data;
}

/**************************************************************
 *
 * Write ANTIC hardware registers
 *
 **************************************************************/

WRITE8_HANDLER ( atari_antic_w )
{
	int temp;

	switch (offset & 15)
	{
	case  0:
		if( data == antic.w.dmactl )
			break;
		LOG(("ANTIC 00 write DMACTL $%02X\n", data));
		antic.w.dmactl = data;
		switch (data & 3)
		{
			case 0: antic.pfwidth =  0; break;
			case 1: antic.pfwidth = 32; break;
			case 2: antic.pfwidth = 40; break;
			case 3: antic.pfwidth = 48; break;
		}
		break;
	case  1:
		if( data == antic.w.chactl )
			break;
		LOG(("ANTIC 01 write CHACTL $%02X\n", data));
		antic.w.chactl = data;
		antic.chand = (data & 1) ? 0x00 : 0xff;
		antic.chxor = (data & 2) ? 0xff : 0x00;
		break;
	case  2:
		LOG(("ANTIC 02 write DLISTL $%02X\n", data));
		antic.w.dlistl = data;
		temp = (antic.w.dlisth << 8) + antic.w.dlistl;
		antic.dpage = temp & DPAGE;
		antic.doffs = temp & DOFFS;
		break;
	case  3:
		LOG(("ANTIC 03 write DLISTH $%02X\n", data));
		antic.w.dlisth = data;
		temp = (antic.w.dlisth << 8) + antic.w.dlistl;
		antic.dpage = temp & DPAGE;
		antic.doffs = temp & DOFFS;
		break;
	case  4:
		if( data == antic.w.hscrol )
			break;
		LOG(("ANTIC 04 write HSCROL $%02X\n", data));
		antic.w.hscrol = data & 15;
		break;
	case  5:
		if( data == antic.w.vscrol )
			break;
		LOG(("ANTIC 05 write VSCROL $%02X\n", data));
		antic.w.vscrol = data & 15;
		break;
	case  6:
		if( data == antic.w.pmbasl )
			break;
		LOG(("ANTIC 06 write PMBASL $%02X\n", data));
		/* antic.w.pmbasl = data; */
		break;
	case  7:
		if( data == antic.w.pmbash )
			break;
		LOG(("ANTIC 07 write PMBASH $%02X\n", data));
		antic.w.pmbash = data;
		antic.pmbase_s = (data & 0xfc) << 8;
		antic.pmbase_d = (data & 0xf8) << 8;
		break;
	case  8:
		if( data == antic.w.chbasl )
			break;
		LOG(("ANTIC 08 write CHBASL $%02X\n", data));
		/* antic.w.chbasl = data; */
		break;
	case  9:
		if( data == antic.w.chbash )
			break;
		LOG(("ANTIC 09 write CHBASH $%02X\n", data));
		antic.w.chbash = data;
		break;
	case 10: /* WSYNC write */
		LOG(("ANTIC 0A write WSYNC  $%02X\n", data));
		cpunum_spinuntil_trigger(0, TRIGGER_HSYNC);
		antic.w.wsync = 1;
		break;
	case 11:
		if( data == antic.w.antic0b )
			break;
		LOG(("ANTIC 0B write ?????? $%02X\n", data));
		antic.w.antic0b = data;
		break;
	case 12:
		if( data == antic.w.antic0c )
			break;
		LOG(("ANTIC 0C write ?????? $%02X\n", data));
		antic.w.antic0c = data;
		break;
	case 13:
		if( data == antic.w.antic0d )
			break;
		LOG(("ANTIC 0D write ?????? $%02X\n", data));
		antic.w.antic0d = data;
		break;
	case 14:
		if( data == antic.w.nmien )
			break;
		LOG(("ANTIC 0E write NMIEN  $%02X\n", data));
		antic.w.nmien  = data;
		break;
	case 15:
		LOG(("ANTIC 0F write NMIRES $%02X\n", data));
		antic.r.nmist = 0x1f;
		antic.w.nmires = data;
		break;
	}
}

/*************  ANTIC mode 00: *********************************
 * generate 1-8 empty scanlines
 ***************************************************************/
void antic_mode_0_xx(VIDEO *video)
{
	PREPARE();
	memset(dst, PBK, HWIDTH*4);
	POST();
}

/*************  ANTIC mode 01: *********************************
 * display list jump, eventually wait for vsync
 ***************************************************************/


/*************  ANTIC mode 02: *********************************
 * character mode 8x8:2 (32/40/48 byte per line)
 ***************************************************************/
#define MODE2(s) COPY4(dst, antic.pf_21[video->data[s]])

void antic_mode_2_32(VIDEO *video)
{
	PREPARE_TXT2(32);
	REP32(MODE2);
	POST_TXT(32);
}
void antic_mode_2_40(VIDEO *video)
{
	PREPARE_TXT2(40);
	REP40(MODE2);
	POST_TXT(40);
}
void antic_mode_2_48(VIDEO *video)
{
	PREPARE_TXT2(48);
	REP48(MODE2);
	POST_TXT(48);
}

/*************  ANTIC mode 03: *********************************
 * character mode 8x10:2 (32/40/48 byte per line)
 ***************************************************************/
#define MODE3(s) COPY4(dst, antic.pf_21[video->data[s]])

void antic_mode_3_32(VIDEO *video)
{
	PREPARE_TXT3(32);
	REP32(MODE3);
	POST_TXT(32);
}
void antic_mode_3_40(VIDEO *video)
{
	PREPARE_TXT3(40);
	REP40(MODE3);
	POST_TXT(40);
}
void antic_mode_3_48(VIDEO *video)
{
	PREPARE_TXT3(48);
	REP48(MODE3);
	POST_TXT(48);
}

/*************  ANTIC mode 04: *********************************
 * character mode 8x8:4 multi color (32/40/48 byte per line)
 ***************************************************************/
#define MODE4(s) COPY4(dst, antic.pf_x10b[video->data[s]])

void antic_mode_4_32(VIDEO *video)
{
	PREPARE_TXT45(32,0);
	REP32(MODE4);
	POST_TXT(32);
}
void antic_mode_4_40(VIDEO *video)
{
	PREPARE_TXT45(40,0);
	REP40(MODE4);
	POST_TXT(40);
}
void antic_mode_4_48(VIDEO *video)
{
	PREPARE_TXT45(48,0);
	REP48(MODE4);
	POST_TXT(48);
}

/*************  ANTIC mode 05: *********************************
 * character mode 8x16:4 multi color (32/40/48 byte per line)
 ***************************************************************/
#define MODE5(s) COPY4(dst, antic.pf_x10b[video->data[s]])

void antic_mode_5_32(VIDEO *video)
{
	PREPARE_TXT45(32,1);
	REP32(MODE5);
	POST_TXT(32);
}
void antic_mode_5_40(VIDEO *video)
{
	PREPARE_TXT45(40,1);
	REP40(MODE5);
	POST_TXT(40);
}
void antic_mode_5_48(VIDEO *video)
{
	PREPARE_TXT45(48,1);
	REP48(MODE5);
	POST_TXT(48);
}

/*************  ANTIC mode 06: *********************************
 * character mode 16x8:5 single color (16/20/24 byte per line)
 ***************************************************************/
#define MODE6(s) COPY8(dst, antic.pf_3210b2[video->data[s]], antic.pf_3210b2[video->data[s]+1])

void antic_mode_6_32(VIDEO *video)
{
	PREPARE_TXT67(16,0);
	REP16(MODE6);
	POST_TXT(16);
}
void antic_mode_6_40(VIDEO *video)
{
	PREPARE_TXT67(20,0);
	REP20(MODE6);
	POST_TXT(20);
}
void antic_mode_6_48(VIDEO *video)
{
	PREPARE_TXT67(24,0);
	REP24(MODE6);
	POST_TXT(24);
}

/*************  ANTIC mode 07: *********************************
 * character mode 16x16:5 single color (16/20/24 byte per line)
 ***************************************************************/
#define MODE7(s) COPY8(dst, antic.pf_3210b2[video->data[s]], antic.pf_3210b2[video->data[s]+1])

void antic_mode_7_32(VIDEO *video)
{
	PREPARE_TXT67(16,1);
	REP16(MODE7);
	POST_TXT(16);
}
void antic_mode_7_40(VIDEO *video)
{
	PREPARE_TXT67(20,1);
	REP20(MODE7);
	POST_TXT(20);
}
void antic_mode_7_48(VIDEO *video)
{
	PREPARE_TXT67(24,1);
	REP24(MODE7);
	POST_TXT(24);
}

/*************  ANTIC mode 08: *********************************
 * graphics mode 8x8:4 (8/10/12 byte per line)
 ***************************************************************/
#define MODE8(s) COPY16(dst, antic.pf_210b4[video->data[s]],antic.pf_210b4[video->data[s]+1],antic.pf_210b4[video->data[s]+2],antic.pf_210b4[video->data[s]+3])

void antic_mode_8_32(VIDEO *video)
{
	PREPARE_GFX8(8);
	REP08(MODE8);
	POST_GFX(8);
}
void antic_mode_8_40(VIDEO *video)
{
	PREPARE_GFX8(10);
	REP10(MODE8);
	POST_GFX(10);
}
void antic_mode_8_48(VIDEO *video)
{
	PREPARE_GFX8(12);
	REP12(MODE8);
	POST_GFX(12);
}

/*************  ANTIC mode 09: *********************************
 * graphics mode 4x4:2 (8/10/12 byte per line)
 ***************************************************************/
#define MODE9(s) COPY8(dst, antic.pf_3210b2[video->data[s]], antic.pf_3210b2[video->data[s]+1])

void antic_mode_9_32(VIDEO *video)
{
	PREPARE_GFX9BC(16);
	REP16(MODE9);
	POST_GFX(16);
}
void antic_mode_9_40(VIDEO *video)
{
	PREPARE_GFX9BC(20);
	REP20(MODE9);
	POST_GFX(20);
}
void antic_mode_9_48(VIDEO *video)
{
	PREPARE_GFX9BC(24);
	REP24(MODE9);
	POST_GFX(24);
}

/*************  ANTIC mode 0A: *********************************
 * graphics mode 4x4:4 (16/20/24 byte per line)
 ***************************************************************/
#define MODEA(s) COPY8(dst, antic.pf_210b2[video->data[s]], antic.pf_210b2[video->data[s]+1])

void antic_mode_a_32(VIDEO *video)
{
	PREPARE_GFXA(16);
	REP16(MODEA);
	POST_GFX(16);
}
void antic_mode_a_40(VIDEO *video)
{
	PREPARE_GFXA(20);
	REP20(MODEA);
	POST_GFX(20);
}
void antic_mode_a_48(VIDEO *video)
{
	PREPARE_GFXA(24);
	REP24(MODEA);
	POST_GFX(24);
}

/*************  ANTIC mode 0B: *********************************
 * graphics mode 2x2:2 (16/20/24 byte per line)
 ***************************************************************/
#define MODEB(s) COPY8(dst, antic.pf_3210b2[video->data[s]], antic.pf_3210b2[video->data[s]+1])

void antic_mode_b_32(VIDEO *video)
{
	PREPARE_GFX9BC(16);
	REP16(MODEB);
	POST_GFX(16);
}
void antic_mode_b_40(VIDEO *video)
{
	PREPARE_GFX9BC(20);
	REP20(MODEB);
	POST_GFX(20);
}
void antic_mode_b_48(VIDEO *video)
{
	PREPARE_GFX9BC(24);
	REP24(MODEB);
	POST_GFX(24);
}

/*************  ANTIC mode 0C: *********************************
 * graphics mode 2x1:2 (16/20/24 byte per line)
 ***************************************************************/
#define MODEC(s) COPY8(dst, antic.pf_3210b2[video->data[s]], antic.pf_3210b2[video->data[s]+1])

void antic_mode_c_32(VIDEO *video)
{
	PREPARE_GFX9BC(16);
	REP16(MODEC);
	POST_GFX(16);
}
void antic_mode_c_40(VIDEO *video)
{
	PREPARE_GFX9BC(20);
	REP20(MODEC);
	POST_GFX(20);
}
void antic_mode_c_48(VIDEO *video)
{
	PREPARE_GFX9BC(24);
	REP24(MODEC);
	POST_GFX(24);
}

/*************  ANTIC mode 0D: *********************************
 * graphics mode 2x2:4 (32/40/48 byte per line)
 ***************************************************************/
#define MODED(s) COPY4(dst, antic.pf_x10b[video->data[s]])

void antic_mode_d_32(VIDEO *video)
{
	PREPARE_GFXDE(32);
	REP32(MODED);
	POST_GFX(32);
}
void antic_mode_d_40(VIDEO *video)
{
	PREPARE_GFXDE(40);
	REP40(MODED);
	POST_GFX(40);
}
void antic_mode_d_48(VIDEO *video)
{
	PREPARE_GFXDE(48);
	REP48(MODED);
	POST_GFX(48);
}

/*************  ANTIC mode 0E: *********************************
 * graphics mode 2x1:4 (32/40/48 byte per line)
 ***************************************************************/
#define MODEE(s) COPY4(dst, antic.pf_x10b[video->data[s]])

void antic_mode_e_32(VIDEO *video)
{
	PREPARE_GFXDE(32);
	REP32(MODEE);
	POST_GFX(32);
}
void antic_mode_e_40(VIDEO *video)
{
	PREPARE_GFXDE(40);
	REP40(MODEE);
	POST_GFX(40);
}
void antic_mode_e_48(VIDEO *video)
{
	PREPARE_GFXDE(48);
	REP48(MODEE);
	POST_GFX(48);
}

/*************  ANTIC mode 0F: *********************************
 * graphics mode 1x1:2 (32/40/48 byte per line)
 ***************************************************************/
#define MODEF(s) COPY4(dst, antic.pf_1b[video->data[s]])

void antic_mode_f_32(VIDEO *video)
{
	PREPARE_GFXF(32);
	REP32(MODEF);
	POST_GFX(32);
}
void antic_mode_f_40(VIDEO *video)
{
	PREPARE_GFXF(40);
	REP40(MODEF);
	POST_GFX(40);
}
void antic_mode_f_48(VIDEO *video)
{
	PREPARE_GFXF(48);
	REP48(MODEF);
	POST_GFX(48);
}