summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/tankbust.cpp
blob: e179c067f6a49b17d35d6802d5dce53eb5a72f71 (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
// license:GPL-2.0+
// copyright-holders:Jarek Burczynski
/*
*   Video Driver for Tank Busters
*/

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


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

  Callbacks for the TileMap code

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

/* background tilemap :

0xc000-0xc7ff:  xxxx xxxx tile code: 8 lsb bits

0xc800-0xcfff:  .... .xxx tile code: 3 msb bits
                .... x... tile priority ON TOP of sprites (roofs and part of the rails)
                .xxx .... tile color code
                x... .... ?? set on *all* roofs (a different bg/sprite priority ?)

note:
 - seems that the only way to get color test right is to swap bit 1 and bit 0 of color code

*/

TILE_GET_INFO_MEMBER(tankbust_state::get_bg_tile_info)
{
	int code = m_videoram[tile_index];
	int attr = m_colorram[tile_index];

	int color = ((attr>>4) & 0x07);

	code |= (attr&0x07) * 256;


#if 0
	if (attr&0x08)  //priority bg/sprites (1 = this bg tile on top of sprites)
	{
		color = ((int)machine().rand()) & 0x0f;
	}
	if (attr&0x80)  //all the roofs of all buildings have this bit set. What's this ???
	{
		color = ((int)machine().rand()) & 0x0f;
	}
#endif

	/* priority bg/sprites (1 = this bg tile on top of sprites) */
	tileinfo.category = (attr & 0x08) >> 3;

	SET_TILE_INFO_MEMBER(1,
			code,
			(color&4) | ((color&2)>>1) | ((color&1)<<1),
			0);
}

TILE_GET_INFO_MEMBER(tankbust_state::get_txt_tile_info)
{
	int code = m_txtram[tile_index];
	int color = ((code>>6) & 0x03);

	SET_TILE_INFO_MEMBER(2,
			code & 0x3f,
			((color&2)>>1) | ((color&1)<<1),
			0);
}


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

  Start the video hardware emulation.

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

void tankbust_state::video_start()
{
	/* not scrollable */
	m_txt_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(tankbust_state::get_txt_tile_info),this), TILEMAP_SCAN_ROWS,  8, 8, 64, 32);

	/* scrollable */
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(tankbust_state::get_bg_tile_info),this), TILEMAP_SCAN_ROWS,  8, 8, 64, 32);

	m_txt_tilemap->set_transparent_pen(0);

	save_item(NAME(m_xscroll));
	save_item(NAME(m_yscroll));
}


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

  Memory handlers

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

WRITE8_MEMBER(tankbust_state::background_videoram_w)
{
	m_videoram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(tankbust_state::background_colorram_w)
{
	m_colorram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(tankbust_state::txtram_w)
{
	m_txtram[offset] = data;
	m_txt_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(tankbust_state::xscroll_w)
{
	if( m_xscroll[offset] != data )
	{
		int x;

		m_xscroll[offset] = data;

		x = m_xscroll[0] + 256 * (m_xscroll[1]&1);
		if (x>=0x100) x-=0x200;
		m_bg_tilemap->set_scrollx(0, x );
	}
//popmessage("x=%02x %02x", m_xscroll[0], m_xscroll[1]);
}


WRITE8_MEMBER(tankbust_state::yscroll_w)
{
	if( m_yscroll[offset] != data )
	{
		int y;

		m_yscroll[offset] = data;
		y = m_yscroll[0];
		if (y>=0x80) y-=0x100;
		m_bg_tilemap->set_scrolly(0, y );
	}
//popmessage("y=%02x %02x", m_yscroll[0], m_yscroll[1]);
}

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

  Display refresh

***************************************************************************/
/*
spriteram format (4 bytes per sprite):

    offset  0   x.......    flip X
    offset  0   .x......    flip Y
    offset  0   ..xxxxxx    gfx code (6 bits)

    offset  1   xxxxxxxx    y position

    offset  2   ??????..    not used ?
    offset  2   ......?.    used but unknown ??? (color code ? or x ?)
    offset  2   .......x    x position (1 MSB bit)

    offset  3   xxxxxxxx    x position (8 LSB bits)
*/

void tankbust_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	for (int offs = 0; offs < m_spriteram.bytes(); offs += 4)
	{
		int code,color,sx,sy,flipx,flipy;

		code  = m_spriteram[offs+0] & 0x3f;
		flipy = m_spriteram[offs+0] & 0x40;
		flipx = m_spriteram[offs+0] & 0x80;

		sy = (240- m_spriteram[offs+1]) - 14;
		sx = (m_spriteram[offs+2] & 0x01) * 256 + m_spriteram[offs+3] - 7;

		color = 0;

		//0x02 - don't know (most of the time this bit is set in tank sprite and others but not all and not always)
		//0x04 - not used
		//0x08 - not used
		//0x10 - not used
		//0x20 - not used
		//0x40 - not used
		//0x80 - not used
#if 0
		if ((m_spriteram[offs+2] & 0x02))
		{
			code = ((int)machine().rand()) & 63;
		}
#endif

		if ((m_spriteram[offs+1]!=4)) //otherwise - ghost sprites
		{
			m_gfxdecode->gfx(0)->transpen(bitmap,cliprect,
				code, color,
				flipx,flipy,
				sx,sy,0);
		}
	}
}


uint32_t tankbust_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
#if 0
	for (int i=0; i<0x800; i++)
	{
		int tile_attrib = m_colorram[i];

		if ( (tile_attrib&8) || (tile_attrib&0x80) )
		{
			m_bg_tilemap->mark_tile_dirty(i);
		}
	}
#endif

	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	draw_sprites(bitmap, cliprect);
	m_bg_tilemap->draw(screen, bitmap, cliprect, 1, 0);

	m_txt_tilemap->draw(screen, bitmap, cliprect, 0,0);
	return 0;
}