summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/pushman.c
blob: 0037e39613675f56661ef62d18a4154f86806cbb (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
#include "driver.h"

static tilemap *bg_tilemap,*tx_tilemap;
static UINT16 control[2];


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

  Callbacks for the TileMap code

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

static TILEMAP_MAPPER( background_scan_rows )
{
	/* logical (col,row) -> memory offset */
	return ((col & 0x7)) + ((7-(row & 0x7)) << 3) + ((col & 0x78) <<3) + ((0x38-(row&0x38))<<7);
}

static TILE_GET_INFO( get_back_tile_info )
{
	UINT8 *bgMap = memory_region(REGION_GFX4);
	int tile;

	tile=bgMap[tile_index<<1]+(bgMap[(tile_index<<1)+1]<<8);
	SET_TILE_INFO(
			2,
			(tile&0xff)|((tile&0x4000)>>6),
			(tile>>8)&0xf,
			(tile&0x2000)?TILE_FLIPX:0);
}

static TILE_GET_INFO( get_text_tile_info )
{
	int tile = videoram16[tile_index];
	SET_TILE_INFO(
			0,
			(tile&0xff)|((tile&0xc000)>>6)|((tile&0x2000)>>3),
			(tile>>8)&0xf,
			(tile&0x1000)?TILE_FLIPY:0);	/* not used? from Tiger Road */
}



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

  Start the video hardware emulation.

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

VIDEO_START( pushman )
{
	bg_tilemap = tilemap_create(get_back_tile_info,background_scan_rows,TILEMAP_TYPE_PEN,     32,32,128,64);
	tx_tilemap = tilemap_create(get_text_tile_info,tilemap_scan_rows,   TILEMAP_TYPE_PEN, 8, 8, 32,32);

	tilemap_set_transparent_pen(tx_tilemap,3);
}



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

  Memory handlers

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

WRITE16_HANDLER( pushman_scroll_w )
{
	COMBINE_DATA(&control[offset]);
}

WRITE16_HANDLER( pushman_videoram_w )
{
	COMBINE_DATA(&videoram16[offset]);
	tilemap_mark_tile_dirty(tx_tilemap,offset);
}



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

  Display refresh

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

static void draw_sprites(running_machine *machine, mame_bitmap *bitmap,const rectangle *cliprect)
{
	int offs,x,y,color,sprite,flipx,flipy;

	for (offs = 0x0800-4;offs >=0;offs -= 4)
	{
		/* Don't draw empty sprite table entries */
		x = spriteram16[offs+3]&0x1ff;
		if (x==0x180) continue;
		if (x>0xff) x=0-(0x200-x);
		y = 240-spriteram16[offs+2];
		color = ((spriteram16[offs+1]>>2)&0xf);
		sprite = spriteram16[offs]&0x7ff;
		/* ElSemi - Sprite flip info */
		flipx=spriteram16[offs+1]&2;
		flipy=spriteram16[offs+1]&1;	/* flip y untested */

		drawgfx(bitmap,machine->gfx[1],
				sprite,
                color,flipx,flipy,x,y,
				cliprect,TRANSPARENCY_PEN,15);
	}
}

VIDEO_UPDATE( pushman )
{
	/* Setup the tilemaps */
	tilemap_set_scrollx( bg_tilemap,0, control[0] );
	tilemap_set_scrolly( bg_tilemap,0, 0xf00-control[1] );

	tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
	draw_sprites(machine,bitmap,cliprect);
	tilemap_draw(bitmap,cliprect,tx_tilemap,0,0);
	return 0;
}