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

    Block Out

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

#include "driver.h"
#include "blockout.h"


static void setcolor( running_machine *machine, int color, int rgb )
{
	int bit0, bit1, bit2, bit3;
	int r, g, b;


	/* red component */
	bit0 = (rgb >> 0) & 0x01;
	bit1 = (rgb >> 1) & 0x01;
	bit2 = (rgb >> 2) & 0x01;
	bit3 = (rgb >> 3) & 0x01;
	r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;

	/* green component */
	bit0 = (rgb >> 4) & 0x01;
	bit1 = (rgb >> 5) & 0x01;
	bit2 = (rgb >> 6) & 0x01;
	bit3 = (rgb >> 7) & 0x01;
	g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;

	/* blue component */
	bit0 = (rgb >> 8) & 0x01;
	bit1 = (rgb >> 9) & 0x01;
	bit2 = (rgb >> 10) & 0x01;
	bit3 = (rgb >> 11) & 0x01;
	b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;

	palette_set_color(machine, color, MAKE_RGB(r,g,b));
}

WRITE16_HANDLER( blockout_paletteram_w )
{
	blockout_state *state = (blockout_state *)space->machine->driver_data;

	COMBINE_DATA(&state->paletteram[offset]);
	setcolor(space->machine, offset, state->paletteram[offset]);
}

WRITE16_HANDLER( blockout_frontcolor_w )
{
	blockout_state *state = (blockout_state *)space->machine->driver_data;

	COMBINE_DATA(&state->color);
	setcolor(space->machine, 512, state->color);
}



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

  Start the video hardware emulation.

***************************************************************************/
VIDEO_START( blockout )
{
	blockout_state *state = (blockout_state *)machine->driver_data;

	/* Allocate temporary bitmaps */
	state->tmpbitmap = video_screen_auto_bitmap_alloc(machine->primary_screen);
	state_save_register_global_bitmap(machine, state->tmpbitmap);
}

static void update_pixels( running_machine *machine, int x, int y )
{
	blockout_state *state = (blockout_state *)machine->driver_data;
	UINT16 front, back;
	int color;
	const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen);

	if (x < visarea->min_x || x > visarea->max_x || y < visarea->min_y || y > visarea->max_y)
		return;

	front = state->videoram[y * 256 + x / 2];
	back = state->videoram[0x10000 + y * 256 + x / 2];

	if (front >> 8)
		color = front >> 8;
	else
		color = (back >> 8) + 256;

	*BITMAP_ADDR16(state->tmpbitmap, y, x) = color;

	if (front & 0xff)
		color = front & 0xff;
	else
		color = (back & 0xff) + 256;

	*BITMAP_ADDR16(state->tmpbitmap, y, x + 1) = color;
}



WRITE16_HANDLER( blockout_videoram_w )
{
	blockout_state *state = (blockout_state *)space->machine->driver_data;

	COMBINE_DATA(&state->videoram[offset]);
	update_pixels(space->machine, (offset % 256) * 2, (offset / 256) % 256);
}



VIDEO_UPDATE( blockout )
{
	blockout_state *state = (blockout_state *)screen->machine->driver_data;
	int x, y;
	pen_t color = 512;

	copybitmap(bitmap, state->tmpbitmap, 0, 0, 0, 0, cliprect);

	for (y = 0; y < 256; y++)
	{
		for (x = 0; x < 320; x += 8)
		{
			int d = state->frontvideoram[y * 64 + (x / 8)];

			if (d)
			{
				if (d & 0x80) *BITMAP_ADDR16(bitmap, y, x + 0) = color;
				if (d & 0x40) *BITMAP_ADDR16(bitmap, y, x + 1) = color;
				if (d & 0x20) *BITMAP_ADDR16(bitmap, y, x + 2) = color;
				if (d & 0x10) *BITMAP_ADDR16(bitmap, y, x + 3) = color;
				if (d & 0x08) *BITMAP_ADDR16(bitmap, y, x + 4) = color;
				if (d & 0x04) *BITMAP_ADDR16(bitmap, y, x + 5) = color;
				if (d & 0x02) *BITMAP_ADDR16(bitmap, y, x + 6) = color;
				if (d & 0x01) *BITMAP_ADDR16(bitmap, y, x + 7) = color;
			}
		}
	}

	return 0;
}