summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/tigeroad.c
blob: b626ea3bd3bf0476b1ec3ef75eda788f719cd228 (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
#include "emu.h"
#include "includes/tigeroad.h"


WRITE16_HANDLER( tigeroad_videoram_w )
{
	tigeroad_state *state = space->machine().driver_data<tigeroad_state>();
	UINT16 *videoram = state->m_videoram;
	COMBINE_DATA(&videoram[offset]);
	tilemap_mark_tile_dirty(state->m_fg_tilemap, offset);
}

WRITE16_HANDLER( tigeroad_videoctrl_w )
{
	tigeroad_state *state = space->machine().driver_data<tigeroad_state>();
	int bank;

	if (ACCESSING_BITS_8_15)
	{
		data = (data >> 8) & 0xff;

		/* bit 1 flips screen */

		if (flip_screen_get(space->machine()) != (data & 0x02))
		{
			flip_screen_set(space->machine(), data & 0x02);
			tilemap_mark_all_tiles_dirty_all(space->machine());
		}

		/* bit 2 selects bg char bank */

		bank = (data & 0x04) >> 2;

		if (state->m_bgcharbank != bank)
		{
			state->m_bgcharbank = bank;
			tilemap_mark_all_tiles_dirty(state->m_bg_tilemap);
		}

		/* bits 4-5 are coin lockouts */

		coin_lockout_w(space->machine(), 0, !(data & 0x10));
		coin_lockout_w(space->machine(), 1, !(data & 0x20));

		/* bits 6-7 are coin counters */

		coin_counter_w(space->machine(), 0, data & 0x40);
		coin_counter_w(space->machine(), 1, data & 0x80);
	}
}

WRITE16_HANDLER( tigeroad_scroll_w )
{
	tigeroad_state *state = space->machine().driver_data<tigeroad_state>();
	int scroll = 0;

	COMBINE_DATA(&scroll);

	switch (offset)
	{
	case 0:
		tilemap_set_scrollx(state->m_bg_tilemap, 0, scroll);
		break;
	case 1:
		tilemap_set_scrolly(state->m_bg_tilemap, 0, -scroll - 32 * 8);
		break;
	}
}

static void draw_sprites(running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect, int priority )
{
	UINT16 *source = &machine.generic.buffered_spriteram.u16[machine.generic.spriteram_size/2] - 4;
	UINT16 *finish = machine.generic.buffered_spriteram.u16;

	// TODO: The Track Map should probably be drawn on top of the background tilemap...
	//       Also convert the below into a for loop!

	while (source >= finish)
	{
		int tile_number = source[0];

		if (tile_number != 0xfff) {
			int attr = source[1];
			int sy = source[2] & 0x1ff;
			int sx = source[3] & 0x1ff;

			int flipx = attr & 0x02;
			int flipy = attr & 0x01;
			int color = (attr >> 2) & 0x0f;

			if (sx > 0x100) sx -= 0x200;
			if (sy > 0x100) sy -= 0x200;

			if (flip_screen_get(machine))
			{
				sx = 240 - sx;
				sy = 240 - sy;
				flipx = !flipx;
				flipy = !flipy;
			}

			drawgfx_transpen(bitmap, cliprect,
				machine.gfx[2],
				tile_number,
				color,
				flipx, flipy,
				sx, 240 - sy, 15);
		}

		source -= 4;
	}
}

static TILE_GET_INFO( get_bg_tile_info )
{
	tigeroad_state *state = machine.driver_data<tigeroad_state>();
	UINT8 *tilerom = machine.region("gfx4")->base();

	int data = tilerom[tile_index];
	int attr = tilerom[tile_index + 1];
	int code = data + ((attr & 0xc0) << 2) + (state->m_bgcharbank << 10);
	int color = attr & 0x0f;
	int flags = (attr & 0x20) ? TILE_FLIPX : 0;

	SET_TILE_INFO(1, code, color, flags);
	tileinfo->group = (attr & 0x10) ? 1 : 0;
}

static TILE_GET_INFO( get_fg_tile_info )
{
	tigeroad_state *state = machine.driver_data<tigeroad_state>();
	UINT16 *videoram = state->m_videoram;
	int data = videoram[tile_index];
	int attr = data >> 8;
	int code = (data & 0xff) + ((attr & 0xc0) << 2) + ((attr & 0x20) << 5);
	int color = attr & 0x0f;
	int flags = (attr & 0x10) ? TILE_FLIPY : 0;

	SET_TILE_INFO(0, code, color, flags);
}

static TILEMAP_MAPPER( tigeroad_tilemap_scan )
{
	/* logical (col,row) -> memory offset */
	return 2 * (col % 8) + 16 * ((127 - row) % 8) + 128 * (col / 8) + 2048 * ((127 - row) / 8);
}

VIDEO_START( tigeroad )
{
	tigeroad_state *state = machine.driver_data<tigeroad_state>();
	state->m_bg_tilemap = tilemap_create(machine, get_bg_tile_info, tigeroad_tilemap_scan,
		 32, 32, 128, 128);

	state->m_fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows,
		 8, 8, 32, 32);

	tilemap_set_transmask(state->m_bg_tilemap, 0, 0xffff, 0);
	tilemap_set_transmask(state->m_bg_tilemap, 1, 0x1ff, 0xfe00);

	tilemap_set_transparent_pen(state->m_fg_tilemap, 3);
}

SCREEN_UPDATE( tigeroad )
{
	tigeroad_state *state = screen->machine().driver_data<tigeroad_state>();
	tilemap_draw(bitmap, cliprect, state->m_bg_tilemap, TILEMAP_DRAW_LAYER1, 0);
	draw_sprites(screen->machine(), bitmap, cliprect, 0);
	tilemap_draw(bitmap, cliprect, state->m_bg_tilemap, TILEMAP_DRAW_LAYER0, 1);
	//draw_sprites(screen->machine(), bitmap, cliprect, 1); draw priority sprites?
	tilemap_draw(bitmap, cliprect, state->m_fg_tilemap, 0, 2);
	return 0;
}

SCREEN_EOF( tigeroad )
{
	address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);

	buffer_spriteram16_w(space, 0, 0, 0xffff);
}