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

    Legionnaire / Heated Barrel video hardware (derived from D-Con)

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

#include "driver.h"

UINT16 *legionna_back_data,*legionna_fore_data,*legionna_mid_data,*legionna_scrollram16,*legionna_textram;

static tilemap *background_layer,*foreground_layer,*midground_layer,*text_layer;
UINT16 legionna_layer_disable;

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

static UINT16 back_gfx_bank = 0,fore_gfx_bank = 0,mid_gfx_bank = 0;
UINT8 sdgndmrb_pri_n;

void heatbrl_setgfxbank(UINT16 data)
{
	back_gfx_bank = (data &0x4000) >> 2;
}

/*xxx- --- ---- ---- banking*/
void denjinmk_setgfxbank(UINT16 data)
{
	fore_gfx_bank = (data &0x2000) >> 1;//???
	back_gfx_bank = (data &0x4000) >> 2;
	mid_gfx_bank  = (data &0x8000) >> 3;//???

	tilemap_mark_all_tiles_dirty (background_layer);
	tilemap_mark_all_tiles_dirty (foreground_layer);
	tilemap_mark_all_tiles_dirty (midground_layer);
	tilemap_mark_all_tiles_dirty (text_layer);
}

#ifdef UNUSED_FUNCTION
WRITE16_HANDLER( legionna_control_w )
{
	if (ACCESSING_BITS_0_7)
	{
		legionna_enable=data;
		if ((legionna_enable&4)==4)
			tilemap_set_enable(foreground_layer,0);
		else
			tilemap_set_enable(foreground_layer,1);

		if ((legionna_enable&2)==2)
			tilemap_set_enable(midground_layer,0);
		else
			tilemap_set_enable(midground_layer,1);

		if ((legionna_enable&1)==1)
			tilemap_set_enable(background_layer,0);
		else
			tilemap_set_enable(background_layer,1);
	}
}
#endif

WRITE16_HANDLER( legionna_background_w )
{
	COMBINE_DATA(&legionna_back_data[offset]);
	tilemap_mark_tile_dirty(background_layer,offset);
}

WRITE16_HANDLER( legionna_midground_w )
{
	COMBINE_DATA(&legionna_mid_data[offset]);
	tilemap_mark_tile_dirty(midground_layer,offset);
}

WRITE16_HANDLER( legionna_foreground_w )
{
	COMBINE_DATA(&legionna_fore_data[offset]);
	tilemap_mark_tile_dirty(foreground_layer,offset);
}

WRITE16_HANDLER( legionna_text_w )
{
	COMBINE_DATA(&legionna_textram[offset]);
	tilemap_mark_tile_dirty(text_layer,offset);
}

static TILE_GET_INFO( get_back_tile_info )
{
	int tile=legionna_back_data[tile_index];
	int color=(tile>>12)&0xf;

	tile &= 0xfff;
	tile |= back_gfx_bank;		/* Heatbrl uses banking */

	SET_TILE_INFO(1,tile,color,0);
}

static TILE_GET_INFO( get_mid_tile_info )
{
	int tile=legionna_mid_data[tile_index];
	int color=(tile>>12)&0xf;

	tile &= 0xfff;

	SET_TILE_INFO(5,tile,color,0);
}

static TILE_GET_INFO( get_mid_tile_info_denji )
{
	int tile=legionna_mid_data[tile_index];
	int color=(tile>>12)&0xf;

	tile &= 0xfff;
	tile |= mid_gfx_bank;

	SET_TILE_INFO(5,tile,color,0);
}

static TILE_GET_INFO( get_mid_tile_info_cupsoc )
{
	int tile=legionna_mid_data[tile_index];
	int color=(tile>>12)&0xf;

	tile &= 0xfff;

	tile |= 0x1000;

	SET_TILE_INFO(1,tile,color,0);
}

static TILE_GET_INFO( get_fore_tile_info )	/* this is giving bad tiles... */
{
	int tile=legionna_fore_data[tile_index];
	int color=(tile>>12)&0xf;

	// legionnaire tile numbers / gfx set wrong, see screen after coin insertion
	tile &= 0xfff;

	SET_TILE_INFO(4,tile,color,0);
}

static TILE_GET_INFO( get_fore_tile_info_denji )
{
	int tile=legionna_fore_data[tile_index];
	int color=(tile>>12)&0xf;

	tile &= 0xfff;
	tile |= fore_gfx_bank;

	SET_TILE_INFO(4,tile,color,0);
}

static TILE_GET_INFO( get_text_tile_info )
{
	int tile = legionna_textram[tile_index];
	int color=(tile>>12)&0xf;

	tile &= 0xfff;

	SET_TILE_INFO(0,tile,color,0);
}

VIDEO_START( legionna )
{
	background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,16,16,32,32);
	foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,16,16,32,32);
	midground_layer =  tilemap_create(get_mid_tile_info, tilemap_scan_rows,16,16,32,32);
	text_layer =       tilemap_create(get_text_tile_info,tilemap_scan_rows,  8,8,64,32);
	legionna_layer_disable = 0x0000;

	legionna_scrollram16 = auto_malloc(0x60);

	tilemap_set_transparent_pen(background_layer,15);
	tilemap_set_transparent_pen(midground_layer,15);
	tilemap_set_transparent_pen(foreground_layer,15);
	tilemap_set_transparent_pen(text_layer,15);
}

VIDEO_START( denjinmk )
{
	background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,16,16,32,32);
	foreground_layer = tilemap_create(get_fore_tile_info_denji,tilemap_scan_rows,16,16,32,32);
	midground_layer =  tilemap_create(get_mid_tile_info_denji, tilemap_scan_rows,16,16,32,32);
	text_layer =       tilemap_create(get_text_tile_info,tilemap_scan_rows,  8,8,64,32);
	legionna_layer_disable = 0x0000;

	legionna_scrollram16 = auto_malloc(0x60);

	tilemap_set_transparent_pen(background_layer,15);
	tilemap_set_transparent_pen(midground_layer,15);
	tilemap_set_transparent_pen(foreground_layer,15);
	tilemap_set_transparent_pen(text_layer,7);//?
}

VIDEO_START( cupsoc )
{
	background_layer = tilemap_create(get_back_tile_info,tilemap_scan_rows,16,16,32,32);
	foreground_layer = tilemap_create(get_fore_tile_info,tilemap_scan_rows,16,16,32,32);
	midground_layer =  tilemap_create(get_mid_tile_info_cupsoc, tilemap_scan_rows,16,16,32,32);
	text_layer =       tilemap_create(get_text_tile_info,tilemap_scan_rows,  8,8,64,32);
	legionna_layer_disable = 0x0000;

	legionna_scrollram16 = auto_malloc(0x60);

	tilemap_set_transparent_pen(background_layer,15);
	tilemap_set_transparent_pen(midground_layer,15);
	tilemap_set_transparent_pen(foreground_layer,15);
	tilemap_set_transparent_pen(text_layer,15);
}


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

    Legionnaire Spriteram (similar to Dcon)
    ---------------------

    It has "big sprites" created by setting width or height >0. Tile
    numbers are read consecutively.

    +0   x....... ........  Sprite enable
    +0   .x...... ........  Flip x
    +0   ..x..... ........  Flip y ???
    +0   ...xxx.. ........  Width: do this many tiles horizontally
    +0   ......xx x.......  Height: do this many tiles vertically
    +0   ........ .x......  Tile bank,used in Denjin Makai
    +0   ........ ..xxxxxx  Color bank

    +1   xx...... ........  Priority? (1=high?)
    +1   ..xxxxxx xxxxxxxx  Tile number
	
    +2   ----xxxx xxxxxxxx  X coordinate (signed)
	
	+3   b------- --------  more tile banking used by Denjin Makai
    +3   ----xxxx xxxxxxxx  Y coordinate (signed)

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

static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri)
{
	int offs,fx,fy,x,y,color,sprite,cur_pri;
	int dx,dy,ax,ay;

	for (offs = 0x400-4;offs >= 0;offs -= 4)
	{
		UINT16 data = spriteram16[offs];
		if (!(data &0x8000)) continue;

		cur_pri = (spriteram16[offs+1] & 0xc000) >> 14;
		if (cur_pri!=pri) continue;

		sprite = spriteram16[offs+1];

		sprite &= 0x3fff;
		if(data & 0x0040) sprite |= 0x4000;//tile banking,used in Denjin Makai
		if(spriteram16[offs+3] & 0x8000) sprite |= 0x8000;//tile banking?,used in Denjin Makai
			
		y = spriteram16[offs+3];
		x = spriteram16[offs+2];

		/* heated barrel hardware seems to need 0x1ff with 0x100 sign bit for sprite warp,
		   this doesn't work on denjin makai as the visible area is larger */
		/*
		x&=0x1ff;
		y&=0xfff;
		
		if (x&0x100) x-=0x200;
		if (y&0x800) y-=0x1000;
		*/
		
		x&=0xfff;
		y&=0xfff;
		
		if (x&0x800) x-=0x1000;
		if (y&0x800) y-=0x1000;	

		color = (data &0x3f) + 0x40;
		fx =  (data &0x4000) >> 14;
		fy =  (data &0x2000) >> 13;
		dy = ((data &0x0380) >> 7)  + 1;
		dx = ((data &0x1c00) >> 10) + 1;

		if (!fx)
		{
			if(!fy)
			{
				for (ax=0; ax<dx; ax++)
					for (ay=0; ay<dy; ay++)
					{
						drawgfx(bitmap,machine->gfx[3],
						sprite++,
						color,fx,fy,x+ax*16,y+ay*16,
						cliprect,TRANSPARENCY_PEN,15);
					}
			}
			else
			{
				for (ax=0; ax<dx; ax++)
					for (ay=0; ay<dy; ay++)
					{
						drawgfx(bitmap,machine->gfx[3],
						sprite++,
						color,fx,fy,x+ax*16,y+(dy-ay-1)*16,
						cliprect,TRANSPARENCY_PEN,15);
					}
			}
		}
		else
		{
			if(!fy)
			{
				for (ax=0; ax<dx; ax++)
					for (ay=0; ay<dy; ay++)
					{
						drawgfx(bitmap,machine->gfx[3],
						sprite++,
						color,fx,fy,x+(dx-ax-1)*16,y+ay*16,
						cliprect,TRANSPARENCY_PEN,15);
					}
			}
			else
			{
				for (ax=0; ax<dx; ax++)
					for (ay=0; ay<dy; ay++)
					{
						drawgfx(bitmap,machine->gfx[3],
						sprite++,
						color,fx,fy,x+(dx-ax-1)*16,y+(dy-ay-1)*16,
						cliprect,TRANSPARENCY_PEN,15);
					}
			}
		}
	}
}

#define LAYER_DB 0

VIDEO_UPDATE( legionna )
{
	/* Setup the tilemaps */
	tilemap_set_scrollx( background_layer, 0, legionna_scrollram16[0] );
	tilemap_set_scrolly( background_layer, 0, legionna_scrollram16[1] );
	tilemap_set_scrollx( midground_layer,  0, legionna_scrollram16[2] );
	tilemap_set_scrolly( midground_layer,  0, legionna_scrollram16[3] );
	tilemap_set_scrollx( foreground_layer, 0, legionna_scrollram16[4] );
	tilemap_set_scrolly( foreground_layer, 0, legionna_scrollram16[5] );


	fillbitmap(bitmap,get_black_pen(screen->machine),cliprect);	/* wrong color? */

	/* legionna_layer_disable is a guess based on 'stage 1' screen in heatbrl  */

	if (!(legionna_layer_disable&0x0020)) tilemap_draw(bitmap,cliprect,foreground_layer,TILEMAP_DRAW_OPAQUE,0);

	if (!(legionna_layer_disable&0x0010)) tilemap_draw(bitmap,cliprect,midground_layer,0,0);

	draw_sprites(screen->machine, bitmap,cliprect,3);

	if (!(legionna_layer_disable&0x0002)) tilemap_draw(bitmap,cliprect,background_layer,0,0);

	draw_sprites(screen->machine,bitmap,cliprect,2);
	draw_sprites(screen->machine,bitmap,cliprect,1);
	draw_sprites(screen->machine,bitmap,cliprect,0);

	if (!(legionna_layer_disable&0x0001)) tilemap_draw(bitmap,cliprect,text_layer,0,0);

	return 0;
}

VIDEO_UPDATE( godzilla )
{
//  tilemap_set_scrollx( text_layer, 0, 0 );
//  tilemap_set_scrolly( text_layer, 0, 112 );
	/* Setup the tilemaps */
	tilemap_set_scrollx( background_layer, 0, legionna_scrollram16[0] );
	tilemap_set_scrolly( background_layer, 0, legionna_scrollram16[1] );
	tilemap_set_scrollx( midground_layer,  0, legionna_scrollram16[2] );
	tilemap_set_scrolly( midground_layer,  0, legionna_scrollram16[3] );
	tilemap_set_scrollx( foreground_layer, 0, legionna_scrollram16[4] );
	tilemap_set_scrolly( foreground_layer, 0, legionna_scrollram16[5] );

	fillbitmap(bitmap,0x0200,cliprect);
	
	if (!(legionna_layer_disable&0x0001))
	{
		tilemap_draw(bitmap,cliprect,background_layer,0,0);
	}	
	
	draw_sprites(screen->machine,bitmap,cliprect,2);
	
	if (!(legionna_layer_disable&0x0002))
	{
		tilemap_draw(bitmap,cliprect,midground_layer,0,0);
	}
	
	draw_sprites(screen->machine,bitmap,cliprect,1);
	
	if (!(legionna_layer_disable&0x0004))
	{
		tilemap_draw(bitmap,cliprect,foreground_layer,0,0);	
	}
		
	draw_sprites(screen->machine,bitmap,cliprect,0);
	draw_sprites(screen->machine,bitmap,cliprect,3);
	
	if (!(legionna_layer_disable&0x0008))
	{
		tilemap_draw(bitmap,cliprect,text_layer,0,0);
	}

	return 0;
}

VIDEO_UPDATE( sdgndmrb )
{
	/* Setup the tilemaps */
	tilemap_set_scrollx( background_layer, 0, legionna_scrollram16[0] );
	tilemap_set_scrolly( background_layer, 0, legionna_scrollram16[1] );
	tilemap_set_scrollx( midground_layer,  0, legionna_scrollram16[2] );
	tilemap_set_scrolly( midground_layer,  0, legionna_scrollram16[3] );
	tilemap_set_scrollx( foreground_layer, 0, legionna_scrollram16[4] );
	tilemap_set_scrolly( foreground_layer, 0, legionna_scrollram16[5] );
  	tilemap_set_scrollx( text_layer, 0,  legionna_scrollram16[6] );
  	tilemap_set_scrolly( text_layer, 0,  legionna_scrollram16[7] );

	fillbitmap(bitmap,get_black_pen(screen->machine),cliprect);

	if(!(sdgndmrb_pri_n & 1))
		tilemap_draw(bitmap,cliprect,background_layer,0,0);
	draw_sprites(screen->machine,bitmap,cliprect,2);

	if(!(sdgndmrb_pri_n & 2))
		tilemap_draw(bitmap,cliprect,midground_layer,0,0);

	draw_sprites(screen->machine,bitmap,cliprect,1);

	if(!(sdgndmrb_pri_n & 4))
		tilemap_draw(bitmap,cliprect,foreground_layer,0,0);

	draw_sprites(screen->machine,bitmap,cliprect,0);

	draw_sprites(screen->machine,bitmap,cliprect,3);

	if(!(sdgndmrb_pri_n & 8))
		tilemap_draw(bitmap,cliprect,text_layer,0,0);

	return 0;
}