summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/system1.cpp
blob: d6c3e0a3bdca38dbe4386bb84661181a0dd37dc3 (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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
// license:BSD-3-Clause
// copyright-holders:Jarek Parchanski, Nicola Salmoria, Mirko Buffoni
/*************************************************************************

    System1 / System 2
    original driver by Jarek Parchanski & Mirko Buffoni

    Many thanks to Roberto Ventura, for precious information about
    System 1 hardware.

**************************************************************************

    The System 1/System 2 video hardware is composed of two tilemap
    layers and a sprite layer.

    The tilemap layers are built up out of "pages" of 32x32 tilemaps.
    Each tile is described by two bytes, meaning each page is 2k bytes
    in size. One of the tilemaps is fixed in position, while the other
    has registers for scrolling that vary between board variants.

    The original System 1 hardware simply had two fixed pages. Page 0
    was the scrolling tilemap, and page 1 was the fixed tilemap.

    With later boards and the introduction of System 2, this was
    expanded to support up to 8 pages. The fixed tilemap was hard-
    coded to page 0, but the scrolling tilemap was extended. Instead
    of a single page, the scrolling tilemap consisted of 4 pages glued
    together to form an effective large 64x64 tilemap. Further, each
    of the 4 pages that made up the scrolling tilemap could be
    independently selected from one of the 8 available pages. This
    unique paged tilemap system would continue on to form the basis of
    Sega's tilemap systems for their 16-bit era.

    Up to 32 sprites can be displayed. They are rendered one scanline
    ahead of the beam into 12-bit line buffers which store the sprite
    pixel data and sprite index. During rendering, collisions are
    checked between sprites and if one is found a bit is set in a
    special 32x32x1 collision RAM indiciating which pair of sprites
    collided. Note that the sprite color is derived directly from the
    sprite index, giving each sprite its own set of 16 colors.

    The 11-bit output from the two tilemaps (3 bits of pixel data,
    6 bits of color, 2 bits of priority), plus the 9-bit output from
    the sprite line buffer (4 bits of pixel data, 5 bits of color)
    are combined in a final step to produce the final pixel value. To
    do this, a lookup PROM is used which accepts as input the priority
    bits from the two tilemaps and the whether each of the incoming
    pixel values is transparent (color 0).

    The output of the lookup PROM is a 4-bit value. The lower 2 bits
    select sprite data (0), fixed tilemap (1) or scrolling tilemap (2).
    9 bits of data from the appropriate source are used as a lookup
    into a palette RAM, and the lookup PROM's low 2 bits are used as
    the upper 2 bits of the palette RAM address, providing 512
    independent colors for each source.

    The upper 2 bits of the lookup PROM are used for an additional
    mixer collision detection. Bit 2 indicates that a collision
    should be recorded, and bit 3 indicates which of two banks of
    collision flags should be set. Each bank is 32 entries long, and
    the sprite index is used to select which bit within the bank to
    set.

    On the original System 1 hardware, the palette RAM value was used
    directly as RGB, with 3 bits each of red and green, and 2 bits of
    blue. Later hardware added an extra indirection layer, where the
    8-bit palette RAM value passed into 3 256x4 palette PROMs, one for
    each color.

    Collision data is accessed via a 4k window that is broken into
    4 equal-sized sections. The first section returns data from the
    2x32x1 mixer collision; the data for the collision is returned in
    D0, and a summary bit indicating that some sort of collision has
    occurred is returned in D7. The specific collision bit is cleared
    by writing to the equivalent address in the same region. The
    collision summary bit is cleared by writing to the second region.

    The third and fourth collision regions operate similarly, but
    return data for the 32x32x1 sprite collisions.

**************************************************************************

    TODO:
    - Sprite vs background alignment is off sometimes, best visible when
      scrolling, eg. in regulus, brain. Yet it is correct in other games,
      such as wboy.
    - not sure if sprite priorities are completely accurate

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

#include "emu.h"
#include "includes/system1.h"


/*************************************
 *
 *  Tile callback
 *
 *************************************/

TILE_GET_INFO_MEMBER(system1_state::tile_get_info)
{
	const uint8_t *rambase = (const uint8_t *)tilemap.user_data();
	uint32_t tiledata = rambase[tile_index*2+0] | (rambase[tile_index*2+1] << 8);
	uint32_t code = ((tiledata >> 4) & 0x800) | (tiledata & 0x7ff);
	uint32_t color = (tiledata >> 5) & 0xff;

	SET_TILE_INFO_MEMBER(0, code, color, 0);
}



/*************************************
 *
 *  Video startup
 *
 *************************************/

void system1_state::video_start_common(int pagecount)
{
	int pagenum;

	/* allocate memory for the collision arrays */
	m_mix_collide = make_unique_clear<uint8_t[]>(64);
	m_sprite_collide = make_unique_clear<uint8_t[]>(1024);

	/* allocate memory for videoram */
	m_tilemap_pages = pagecount;
	m_videoram = make_unique_clear<uint8_t[]>(0x800 * pagecount);

	/* create the tilemap pages */
	for (pagenum = 0; pagenum < pagecount; pagenum++)
	{
		m_tilemap_page[pagenum] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(system1_state::tile_get_info),this), TILEMAP_SCAN_ROWS, 8,8, 32,32);
		m_tilemap_page[pagenum]->set_transparent_pen(0);
		m_tilemap_page[pagenum]->set_user_data(m_videoram.get() + 0x800 * pagenum);
	}

	/* allocate a temporary bitmap for sprite rendering */
	m_screen->register_screen_bitmap(m_sprite_bitmap);

	/* register for save stats */
	save_item(NAME(m_video_mode));
	save_item(NAME(m_mix_collide_summary));
	save_item(NAME(m_sprite_collide_summary));
	save_item(NAME(m_videoram_bank));
	save_pointer(NAME(m_videoram), 0x800 * pagecount);
	save_pointer(NAME(m_mix_collide), 64);
	save_pointer(NAME(m_sprite_collide), 1024);
}


void system1_state::video_start()
{
	video_start_common(2);
}


VIDEO_START_MEMBER(system1_state,system2)
{
	video_start_common(8);
}



/*************************************
 *
 *  Video control
 *
 *************************************/

WRITE8_MEMBER(system1_state::system1_videomode_w)
{
	if (data & 0x6e) logerror("videomode = %02x\n",data);

	/* bit 4 is screen blank */
	m_video_mode = data;

	/* bit 7 is flip screen */
	flip_screen_set(data & 0x80);
}



/*************************************
 *
 *  Mixer collision I/O
 *
 *************************************/

READ8_MEMBER(system1_state::system1_mixer_collision_r)
{
//  m_screen->update_now();
	m_screen->update_partial(m_screen->vpos());
	return m_mix_collide[offset & 0x3f] | 0x7e | (m_mix_collide_summary << 7);
}

WRITE8_MEMBER(system1_state::system1_mixer_collision_w)
{
//  m_screen->update_now();
	m_screen->update_partial(m_screen->vpos());
	m_mix_collide[offset & 0x3f] = 0;
}

WRITE8_MEMBER(system1_state::system1_mixer_collision_reset_w)
{
//  m_screen->update_now();
	m_screen->update_partial(m_screen->vpos());
	m_mix_collide_summary = 0;
}



/*************************************
 *
 *  Sprite collision I/O
 *
 *************************************/

READ8_MEMBER(system1_state::system1_sprite_collision_r)
{
//  m_screen->update_now();
	m_screen->update_partial(m_screen->vpos());
	return m_sprite_collide[offset & 0x3ff] | 0x7e | (m_sprite_collide_summary << 7);
}

WRITE8_MEMBER(system1_state::system1_sprite_collision_w)
{
//  m_screen->update_now();
	m_screen->update_partial(m_screen->vpos());
	m_sprite_collide[offset & 0x3ff] = 0;
}

WRITE8_MEMBER(system1_state::system1_sprite_collision_reset_w)
{
//  m_screen->update_now();
	m_screen->update_partial(m_screen->vpos());
	m_sprite_collide_summary = 0;
}



/*************************************
 *
 *  Video RAM access
 *
 *************************************/

inline void system1_state::videoram_wait_states(cpu_device *cpu)
{
	/* The main Z80's CPU clock is halted whenever an access to VRAM happens,
	   and is only restarted by the FIXST signal, which occurs once every
	   'n' pixel clocks. 'n' is determined by the horizontal control PAL. */

	/* this assumes 4 5MHz pixel clocks per FIXST, or 8*4 20MHz CPU clocks,
	   and is based on a dump of 315-5137 */
	const uint32_t cpu_cycles_per_fixst = 4 * 4;
	const uint32_t fixst_offset = 2 * 4;
	uint32_t cycles_until_next_fixst = cpu_cycles_per_fixst - ((cpu->total_cycles() - fixst_offset) % cpu_cycles_per_fixst);

	cpu->adjust_icount(-cycles_until_next_fixst);
}

READ8_MEMBER(system1_state::system1_videoram_r)
{
	uint8_t *videoram = m_videoram.get();
	videoram_wait_states(m_maincpu);
	offset |= 0x1000 * ((m_videoram_bank >> 1) % (m_tilemap_pages / 2));
	return videoram[offset];
}

WRITE8_MEMBER(system1_state::system1_videoram_w)
{
	uint8_t *videoram = m_videoram.get();
	videoram_wait_states(m_maincpu);
	offset |= 0x1000 * ((m_videoram_bank >> 1) % (m_tilemap_pages / 2));
	videoram[offset] = data;

	m_tilemap_page[offset / 0x800]->mark_tile_dirty((offset % 0x800) / 2);

	/* force a partial update if the page is changing */
	if (m_tilemap_pages > 2 && offset >= 0x740 && offset < 0x748 && offset % 2 == 0)
	{
		//m_screen->update_now();
		m_screen->update_partial(m_screen->vpos());
	}
}

WRITE8_MEMBER(system1_state::system1_videoram_bank_w)
{
	m_videoram_bank = data;
}



/*************************************
 *
 *  Palette RAM access
 *
 *************************************/

WRITE8_MEMBER(system1_state::system1_paletteram_w)
{
	/*
	  There are two kind of color handling: in the System 1 games, values in the
	  palette RAM are directly mapped to colors with the usual BBGGGRRR format;
	  in the System 2 ones (Choplifter, WBML, etc.), the value in the palette RAM
	  is a lookup offset for three palette PROMs in RRRRGGGGBBBB format.

	  It's hard to tell for sure because they use resistor packs, but here's
	  what I think the values are from measurment with a volt meter:

	  Blue: .250K ohms
	  Blue: .495K ohms
	  Green:.250K ohms
	  Green:.495K ohms
	  Green:.995K ohms
	  Red:  .495K ohms
	  Red:  .250K ohms
	  Red:  .995K ohms

	  accurate to +/- .003K ohms.
	*/

	if (m_color_prom != nullptr)
	{
		m_paletteram[offset] = data;
		uint8_t val;

		val = m_color_prom[data + 0 * 256];
		uint8_t r = 0x0e * BIT(val, 0) + 0x1f * BIT(val, 1) + 0x43 * BIT(val, 2) + 0x8f * BIT(val, 3);

		val = m_color_prom[data + 1 * 256];
		uint8_t g = 0x0e * BIT(val, 0) + 0x1f * BIT(val, 1) + 0x43 * BIT(val, 2) + 0x8f * BIT(val, 3);

		val = m_color_prom[data + 2 * 256];
		uint8_t b = 0x0e * BIT(val, 0) + 0x1f * BIT(val, 1) + 0x43 * BIT(val, 2) + 0x8f * BIT(val, 3);

		m_palette->set_pen_color(offset, rgb_t(r, g, b));
	}
	else
	{
		m_palette->write8(space, offset, data);
	}
}



/*************************************
 *
 *  Sprite rendering
 *
 *************************************/

void system1_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, int xoffset)
{
	uint32_t gfxbanks = memregion("sprites")->bytes() / 0x8000;
	const uint8_t *gfxbase = memregion("sprites")->base();
	uint8_t *spriteram = m_spriteram;
	int flipscreen = flip_screen();
	int spritenum;

	/* up to 32 sprites total */
	for (spritenum = 0; spritenum < 32; spritenum++)
	{
		const uint8_t *spritedata = &spriteram[spritenum * 0x10];
		uint16_t srcaddr = spritedata[6] + (spritedata[7] << 8);
		uint16_t stride = spritedata[4] + (spritedata[5] << 8);
		uint8_t bank = ((spritedata[3] & 0x80) >> 7) | ((spritedata[3] & 0x40) >> 5) | ((spritedata[3] & 0x20) >> 3);
		int xstart = ((spritedata[2] | (spritedata[3] << 8)) & 0x1ff) + xoffset;
		int bottom = spritedata[1] + 1;
		int top = spritedata[0] + 1;
		uint16_t palettebase = spritenum * 0x10;
		const uint8_t *gfxbankbase;
		int x, y, i;

		/* writing an 0xff into the first byte of sprite RAM seems to disable all sprites;
		   not sure if this applies to each sprite or only to the first one; see pitfall2
		   and wmatch for examples where this is done */
		if (spritedata[0] == 0xff)
			return;

		/* clamp the bank to the size of the sprite ROMs */
		bank %= gfxbanks;
		gfxbankbase = gfxbase + bank * 0x8000;

		/* flip sprites vertically */
		if (flipscreen)
		{
			int temp = top;
			top = 256 - bottom;
			bottom = 256 - temp;
		}

		/* iterate over all rows of the sprite */
		for (y = top; y < bottom; y++)
		{
			uint16_t *destbase = &bitmap.pix16(y);
			uint16_t curaddr;
			int addrdelta;

			/* advance by the row counter */
			srcaddr += stride;

			/* skip if outside of our clipping area */
			if (y < cliprect.min_y || y > cliprect.max_y)
				continue;

			/* iterate over X */
			addrdelta = (srcaddr & 0x8000) ? -1 : 1;
			for (x = xstart, curaddr = srcaddr; ; x += 4, curaddr += addrdelta)
			{
				uint8_t color1, color2;
				uint8_t data;

				data = gfxbankbase[curaddr & 0x7fff];

				/* non-flipped case */
				if (!(curaddr & 0x8000))
				{
					color1 = data >> 4;
					color2 = data & 0x0f;
				}
				else
				{
					color1 = data & 0x0f;
					color2 = data >> 4;
				}

				/* stop when we see color 0x0f */
				if (color1 == 0x0f)
					break;

				/* draw if non-transparent */
				if (color1 != 0)
				{
					for (i = 0; i < 2; i++)
					{
						int effx = flipscreen ? 0x1fe - (x + i) : (x + i);
						if (effx >= cliprect.min_x && effx <= cliprect.max_x)
						{
							int prevpix = destbase[effx];

							if ((prevpix & 0x0f) != 0)
								m_sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = m_sprite_collide_summary = 1;
							destbase[effx] = color1 | palettebase;
						}
					}
				}

				/* stop when we see color 0x0f */
				if (color2 == 0x0f)
					break;

				/* draw if non-transparent */
				if (color2 != 0)
				{
					for (i = 0; i < 2; i++)
					{
						int effx = flipscreen ? 0x1fe - (x + 2 + i) : (x + 2 + i);
						if (effx >= cliprect.min_x && effx <= cliprect.max_x)
						{
							int prevpix = destbase[effx];

							if ((prevpix & 0x0f) != 0)
								m_sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = m_sprite_collide_summary = 1;
							destbase[effx] = color2 | palettebase;
						}
					}
				}
			}
		}
	}
}



/*************************************
 *
 *  Generic update code
 *
 *************************************/

void system1_state::video_update_common(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, bitmap_ind16 &fgpixmap, bitmap_ind16 **bgpixmaps, const int *bgrowscroll, int bgyscroll, int spritexoffs)
{
	const uint8_t *lookup = memregion("proms")->base();
	int x, y;

	/* first clear the sprite bitmap and draw sprites within this area */
	m_sprite_bitmap.fill(0, cliprect);
	draw_sprites(m_sprite_bitmap, cliprect, spritexoffs);

	/* iterate over rows */
	for (y = cliprect.min_y; y <= cliprect.max_y; y++)
	{
		uint16_t *fgbase = &fgpixmap.pix16(y & 0xff);
		uint16_t *sprbase = &m_sprite_bitmap.pix16(y & 0xff);
		uint16_t *dstbase = &bitmap.pix16(y);
		int bgy = (y + bgyscroll) & 0x1ff;
		int bgxscroll = bgrowscroll[y >> 3 & 0x1f];
		uint16_t *bgbase[2];

		/* get the base of the left and right pixmaps for the effective background Y */
		bgbase[0] = &bgpixmaps[(bgy >> 8) * 2 + 0]->pix16(bgy & 0xff);
		bgbase[1] = &bgpixmaps[(bgy >> 8) * 2 + 1]->pix16(bgy & 0xff);

		/* iterate over pixels */
		for (x = cliprect.min_x; x <= cliprect.max_x; x++)
		{
			int bgx = ((x - bgxscroll) / 2) & 0x1ff;
			uint16_t fgpix = fgbase[(x / 2) & 0xff];
			uint16_t bgpix = bgbase[bgx >> 8][bgx & 0xff];
			uint16_t sprpix = sprbase[x];
			uint8_t lookup_index;
			uint8_t lookup_value;

			/* using the sprite, background, and foreground pixels, look up the color behavior */
			lookup_index =  (((sprpix & 0xf) == 0) << 0) |
							(((fgpix & 7) == 0) << 1) |
							(((fgpix >> 9) & 3) << 2) |
							(((bgpix & 7) == 0) << 4) |
							(((bgpix >> 9) & 3) << 5);
			lookup_value = lookup[lookup_index];

			/* compute collisions based on two of the PROM bits */
			if (!(lookup_value & 4))
				m_mix_collide[((lookup_value & 8) << 2) | ((sprpix >> 4) & 0x1f)] = m_mix_collide_summary = 1;

			/* the lower 2 PROM bits select the palette and which pixels */
			lookup_value &= 3;
			if (m_video_mode & 0x10)
				dstbase[x] = 0;
			else if (lookup_value == 0)
				dstbase[x] = 0x000 | (sprpix & 0x1ff);
			else if (lookup_value == 1)
				dstbase[x] = 0x200 | (fgpix & 0x1ff);
			else
				dstbase[x] = 0x400 | (bgpix & 0x1ff);
		}
	}
}



/*************************************
 *
 *  Board-specific update front-ends
 *
 *************************************/

uint32_t system1_state::screen_update_system1(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	uint8_t *videoram = m_videoram.get();
	bitmap_ind16 *bgpixmaps[4];
	int bgrowscroll[32];
	int xscroll, yscroll;
	int y;

	/* all 4 background pages are the same, fixed to page 0 */
	bgpixmaps[0] = bgpixmaps[1] = bgpixmaps[2] = bgpixmaps[3] = &m_tilemap_page[0]->pixmap();

	/* foreground is fixed to page 1 */
	bitmap_ind16 &fgpixmap = m_tilemap_page[1]->pixmap();

	/* get fixed scroll offsets */
	xscroll = (int16_t)((videoram[0xffc] | (videoram[0xffd] << 8)) + 28);
	yscroll = videoram[0xfbd];

	/* adjust for flipping */
	if (flip_screen())
	{
		xscroll = 640 - (xscroll & 0x1ff);
		yscroll = 764 - (yscroll & 0x1ff);
	}

	/* fill in the row scroll table */
	for (y = 0; y < 32; y++)
		bgrowscroll[y] = xscroll;

	/* common update */
	video_update_common(screen, bitmap, cliprect, fgpixmap, bgpixmaps, bgrowscroll, yscroll, 0);
	return 0;
}


uint32_t system1_state::screen_update_system2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	uint8_t *videoram = m_videoram.get();
	bitmap_ind16 *bgpixmaps[4];
	int rowscroll[32];
	int xscroll, yscroll;
	int sprxoffset;
	int y;

	/* 4 independent background pages */
	bgpixmaps[0] = &m_tilemap_page[videoram[0x740] & 7]->pixmap();
	bgpixmaps[1] = &m_tilemap_page[videoram[0x742] & 7]->pixmap();
	bgpixmaps[2] = &m_tilemap_page[videoram[0x744] & 7]->pixmap();
	bgpixmaps[3] = &m_tilemap_page[videoram[0x746] & 7]->pixmap();

	/* foreground is fixed to page 0 */
	bitmap_ind16 &fgpixmap = m_tilemap_page[0]->pixmap();

	/* get scroll offsets */
	if (!flip_screen())
	{
		xscroll = ((videoram[0x7c0] | (videoram[0x7c1] << 8)) & 0x1ff) - 512 + 10;
		yscroll = videoram[0x7ba];
		sprxoffset = 14;
	}
	else
	{
		xscroll = 512 + 512 + 10 - (((videoram[0x7f6] | (videoram[0x7f7] << 8)) & 0x1ff) - 512 + 10);
		yscroll = 512 + 512 - videoram[0x784];
		sprxoffset = -14;
	}

	/* fill in the row scroll table */
	for (y = 0; y < 32; y++)
		rowscroll[y] = xscroll;

	/* common update */
	video_update_common(screen, bitmap, cliprect, fgpixmap, bgpixmaps, rowscroll, yscroll, sprxoffset);
	return 0;
}


uint32_t system1_state::screen_update_system2_rowscroll(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	uint8_t *videoram = m_videoram.get();
	bitmap_ind16 *bgpixmaps[4];
	int rowscroll[32];
	int yscroll;
	int sprxoffset;
	int y;

	/* 4 independent background pages */
	bgpixmaps[0] = &m_tilemap_page[videoram[0x740] & 7]->pixmap();
	bgpixmaps[1] = &m_tilemap_page[videoram[0x742] & 7]->pixmap();
	bgpixmaps[2] = &m_tilemap_page[videoram[0x744] & 7]->pixmap();
	bgpixmaps[3] = &m_tilemap_page[videoram[0x746] & 7]->pixmap();

	/* foreground is fixed to page 0 */
	bitmap_ind16 &fgpixmap = m_tilemap_page[0]->pixmap();

	/* get scroll offsets */
	if (!flip_screen())
	{
		for (y = 0; y < 32; y++)
			rowscroll[y] = ((videoram[0x7c0 + y * 2] | (videoram[0x7c1 + y * 2] << 8)) & 0x1ff) - 512 + 10;

		yscroll = videoram[0x7ba];
		sprxoffset = 14;
	}
	else
	{
		for (y = 0; y < 32; y++)
			rowscroll[y] = 512 + 512 + 10 - (((videoram[0x7fe - y * 2] | (videoram[0x7ff - y * 2] << 8)) & 0x1ff) - 512 + 10);

		yscroll = 512 + 512 - videoram[0x784];
		sprxoffset = -14;
	}

	/* common update */
	video_update_common(screen, bitmap, cliprect, fgpixmap, bgpixmaps, rowscroll, yscroll, sprxoffset);
	return 0;
}