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

First version of the Dynax blitter.

Can handle up to 8 256x256 bitmaps; in the games supported, every pair of
bitmaps is interleaved horizontally to form 4 higher res 512x256 layer.

The blitter reads compressed data from ROM and copies it to the bitmap RAM.

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

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

static void common_vh_start( running_machine &machine, int num_pixmaps )
{
	hnayayoi_state *state = machine.driver_data<hnayayoi_state>();
	int i;

	state->m_total_pixmaps = num_pixmaps;

	for (i = 0; i < 8; i++)
	{
		if (i < state->m_total_pixmaps)
		{
			state->m_pixmap[i] = auto_alloc_array(machine, UINT8, 256 * 256);
		}
		else
			state->m_pixmap[i] = NULL;
	}
}

VIDEO_START( hnayayoi )
{
	hnayayoi_state *state = machine.driver_data<hnayayoi_state>();
	common_vh_start(machine, 4);	/* 4 bitmaps -> 2 layers */

	state->save_pointer(NAME(state->m_pixmap[0]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[1]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[2]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[3]), 256 * 256);
}

VIDEO_START( untoucha )
{
	hnayayoi_state *state = machine.driver_data<hnayayoi_state>();
	common_vh_start(machine, 8);	/* 8 bitmaps -> 4 layers */

	state->save_pointer(NAME(state->m_pixmap[0]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[1]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[2]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[3]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[4]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[5]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[6]), 256 * 256);
	state->save_pointer(NAME(state->m_pixmap[7]), 256 * 256);
}



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

Blitter support

three parameters:
blit_layer: mask of the bitmaps to write to (can write to multiple bitmaps
            at the same time)
blit_dest:  position in the destination bitmap where to start blitting
blit_src:   address of source data in the gfx ROM

additional parameters specify the palette base, but this is handled while rendering
the screen, not during blitting (games change the palette base without redrawing
the screen).

It is not known whether the palette base control registers are part of the blitter
hardware or latched somewhere else. Since they are mapped in memory immediately
before the bitter parameters, they probably are part of the blitter, but I'm
handling them separately anyway.


The format of the blitter data stored in ROM is very simple:

7654 ----   Pen to draw with
---- 3210   Command

Commands:

0       Stop
1-b     Draw 1-b pixels along X.
c       Followed by 1 byte (N): draw N pixels along X.
d       Followed by 2 bytes (X,N): move on the line to pixel (start+X), draw N pixels
        along X.
e       Followed by 1 byte (N): set blit_layer = N. Used to draw interleaved graphics
        with a single blitter run.
f       Move to next line.

At the end of the blit, blit_src is left pointing to the next data in the gfx ROM.
This is used to draw interleaved graphics with two blitter runs without having to set
up blit_src for the second call.

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

WRITE8_HANDLER( dynax_blitter_rev1_param_w )
{
	hnayayoi_state *state = space->machine().driver_data<hnayayoi_state>();
	switch (offset)
	{
		case 0: state->m_blit_dest = (state->m_blit_dest & 0xff00) | (data << 0); break;
		case 1: state->m_blit_dest = (state->m_blit_dest & 0x00ff) | (data << 8); break;
		case 2: state->m_blit_layer = data; break;
		case 3: state->m_blit_src = (state->m_blit_src & 0xffff00) | (data << 0); break;
		case 4: state->m_blit_src = (state->m_blit_src & 0xff00ff) | (data << 8); break;
		case 5: state->m_blit_src = (state->m_blit_src & 0x00ffff) | (data <<16); break;
	}
}

static void copy_pixel( running_machine &machine, int x, int y, int pen )
{
	hnayayoi_state *state = machine.driver_data<hnayayoi_state>();
	if (x >= 0 && x <= 255 && y >= 0 && y <= 255)
	{
		int i;

		for (i = 0; i < 8; i++)
		{
			if ((~state->m_blit_layer & (1 << i)) && (state->m_pixmap[i]))
				state->m_pixmap[i][256 * y + x] = pen;
		}
	}
}

WRITE8_HANDLER( dynax_blitter_rev1_start_w )
{
	hnayayoi_state *state = space->machine().driver_data<hnayayoi_state>();
	UINT8 *rom = space->machine().region("gfx1")->base();
	int romlen = space->machine().region("gfx1")->bytes();
	int sx = state->m_blit_dest & 0xff;
	int sy = state->m_blit_dest >> 8;
	int x, y;

	x = sx;
	y = sy;
	while (state->m_blit_src < romlen)
	{
		int cmd = rom[state->m_blit_src] & 0x0f;
		int pen = rom[state->m_blit_src] >> 4;

		state->m_blit_src++;

		switch (cmd)
		{
			case 0xf:
				y++;
				x = sx;
				break;

			case 0xe:
				if (state->m_blit_src >= romlen)
				{
					popmessage("GFXROM OVER %06x", state->m_blit_src);
					return;
				}
				x = sx;
				state->m_blit_layer = rom[state->m_blit_src++];
				break;

			case 0xd:
				if (state->m_blit_src >= romlen)
				{
					popmessage("GFXROM OVER %06x", state->m_blit_src);
					return;
				}
				x = sx + rom[state->m_blit_src++];
				/* fall through into next case */

			case 0xc:
				if (state->m_blit_src >= romlen)
				{
					popmessage("GFXROM OVER %06x", state->m_blit_src);
					return;
				}
				cmd = rom[state->m_blit_src++];
				/* fall through into next case */

			case 0xb:
			case 0xa:
			case 0x9:
			case 0x8:
			case 0x7:
			case 0x6:
			case 0x5:
			case 0x4:
			case 0x3:
			case 0x2:
			case 0x1:
				while (cmd--)
					copy_pixel(space->machine(), x++, y, pen);
				break;

			case 0x0:
				return;
		}
	}

	popmessage("GFXROM OVER %06x", state->m_blit_src);
}

WRITE8_HANDLER( dynax_blitter_rev1_clear_w )
{
	hnayayoi_state *state = space->machine().driver_data<hnayayoi_state>();
	int pen = data >> 4;
	int i;

	for (i = 0; i < 8; i++)
	{
		if ((~state->m_blit_layer & (1 << i)) && (state->m_pixmap[i]))
			memset(state->m_pixmap[i] + state->m_blit_dest, pen, 0x10000 - state->m_blit_dest);
	}
}


WRITE8_HANDLER( hnayayoi_palbank_w )
{
	hnayayoi_state *state = space->machine().driver_data<hnayayoi_state>();
	offset *= 8;
	state->m_palbank = (state->m_palbank & (0xff00 >> offset)) | (data << offset);
}


static void draw_layer_interleaved( running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect, int left_pixmap, int right_pixmap, int palbase, int transp )
{
	hnayayoi_state *state = machine.driver_data<hnayayoi_state>();
	int county, countx, pen;
	UINT8 *src1 = state->m_pixmap[left_pixmap];
	UINT8 *src2 = state->m_pixmap[right_pixmap];
	UINT16 *dstbase = (UINT16 *)bitmap->base;

	palbase *= 16;

	for (county = 255; county >= 0; county--, dstbase += bitmap->rowpixels)
	{
		UINT16 *dst = dstbase;

		if (transp)
		{
			for (countx = 255; countx >= 0; countx--, dst += 2)
			{
				pen = *(src1++);
				if (pen) *dst = palbase + pen;
				pen = *(src2++);
				if (pen) *(dst + 1) = palbase + pen;
			}
		}
		else
		{
			for (countx = 255; countx >= 0; countx--, dst += 2)
			{
				*dst = palbase + *(src1++);
				*(dst + 1) = palbase + *(src2++);
			}
		}
	}
}


SCREEN_UPDATE( hnayayoi )
{
	hnayayoi_state *state = screen->machine().driver_data<hnayayoi_state>();
	int col0 = (state->m_palbank >>  0) & 0x0f;
	int col1 = (state->m_palbank >>  4) & 0x0f;
	int col2 = (state->m_palbank >>  8) & 0x0f;
	int col3 = (state->m_palbank >> 12) & 0x0f;

	if (state->m_total_pixmaps == 4)
	{
		draw_layer_interleaved(screen->machine(), bitmap, cliprect, 3, 2, col1, 0);
		draw_layer_interleaved(screen->machine(), bitmap, cliprect, 1, 0, col0, 1);
	}
	else	/* total_pixmaps == 8 */
	{
		draw_layer_interleaved(screen->machine(), bitmap, cliprect, 7, 6, col3, 0);
		draw_layer_interleaved(screen->machine(), bitmap, cliprect, 5, 4, col2, 1);
		draw_layer_interleaved(screen->machine(), bitmap, cliprect, 3, 2, col1, 1);
		draw_layer_interleaved(screen->machine(), bitmap, cliprect, 1, 0, col0, 1);
	}
	return 0;
}