summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/fgoal.c
blob: dc0c1182c5a54f795348201cd3a152dd4a2a3799 (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
/***************************************************************************

    Taito Field Goal video emulation

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

#include "driver.h"
#include "includes/fgoal.h"

static bitmap_t *fgbitmap;
static bitmap_t *bgbitmap;

static UINT8 xpos;
static UINT8 ypos;

static int current_color;


WRITE8_HANDLER( fgoal_color_w )
{
	current_color = data & 3;
}


WRITE8_HANDLER( fgoal_ypos_w )
{
	ypos = data;
}


WRITE8_HANDLER( fgoal_xpos_w )
{
	xpos = data;
}


VIDEO_START( fgoal )
{
	fgbitmap = video_screen_auto_bitmap_alloc(machine->primary_screen);
	bgbitmap = video_screen_auto_bitmap_alloc(machine->primary_screen);
}


VIDEO_UPDATE( fgoal )
{
	const UINT8* VRAM = fgoal_video_ram;

	int x;
	int y;
	int n;

	/* draw color overlay foreground and background */

	if (fgoal_player == 1 && (input_port_read(screen->machine, "IN1") & 0x40))
	{
		drawgfxzoom_opaque(fgbitmap, cliprect, screen->machine->gfx[0],
			0, (fgoal_player << 2) | current_color,
			1, 1,
			0, 16,
			0x40000,
			0x40000);

		drawgfxzoom_opaque(bgbitmap, cliprect, screen->machine->gfx[1],
			0, 0,
			1, 1,
			0, 16,
			0x40000,
			0x40000);
	}
	else
	{
		drawgfxzoom_opaque(fgbitmap, cliprect, screen->machine->gfx[0],
			0, (fgoal_player << 2) | current_color,
			0, 0,
			0, 0,
			0x40000,
			0x40000);

		drawgfxzoom_opaque(bgbitmap, cliprect, screen->machine->gfx[1],
			0, 0,
			0, 0,
			0, 0,
			0x40000,
			0x40000);
	}

	/* the ball has a fixed color */

	for (y = ypos; y < ypos + 8; y++)
	{
		for (x = xpos; x < xpos + 8; x++)
		{
			if (y < 256 && x < 256)
			{
				*BITMAP_ADDR16(fgbitmap, y, x) = 128 + 16;
			}
		}
	}

	/* draw bitmap layer */

	for (y = 0; y < 256; y++)
	{
		UINT16* p = BITMAP_ADDR16(bitmap, y, 0);

		const UINT16* FG = BITMAP_ADDR16(fgbitmap, y, 0);
		const UINT16* BG = BITMAP_ADDR16(bgbitmap, y, 0);

		for (x = 0; x < 256; x += 8)
		{
			UINT8 v = *VRAM++;

			for (n = 0; n < 8; n++)
			{
				if (v & (1 << n))
				{
					p[x + n] = FG[x + n];
				}
				else
				{
					p[x + n] = BG[x + n];
				}
			}
		}
	}
	return 0;
}