summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/speedbal.cpp
blob: 2642fed1af8d108aee9bb69bf28d3f19270efd34 (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
// license:BSD-3-Clause
// copyright-holders:Joseba Epalza
/****************************************************************************
 *                                                                          *
 *  Speed Ball                                                              *
 *                                                                          *
 *  Functions to emulate the video hardware of the machine.                 *
 *                                                                          *
 ****************************************************************************/

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


TILE_GET_INFO_MEMBER(speedbal_state::get_tile_info_bg)
{
	int code = m_background_videoram[tile_index*2] + ((m_background_videoram[tile_index*2+1] & 0x30) << 4);
	int color = m_background_videoram[tile_index*2+1] & 0x0f;

	SET_TILE_INFO_MEMBER(1, code, color, 0);
	tileinfo.group = (color == 8);
}

TILE_GET_INFO_MEMBER(speedbal_state::get_tile_info_fg)
{
	int code = m_foreground_videoram[tile_index*2] + ((m_foreground_videoram[tile_index*2+1] & 0x30) << 4);
	int color = m_foreground_videoram[tile_index*2+1] & 0x0f;

	SET_TILE_INFO_MEMBER(0, code, color, 0);
	tileinfo.group = (color == 9);
}

/*************************************
 *                                   *
 *      Start-Stop                   *
 *                                   *
 *************************************/

void speedbal_state::video_start()
{
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(speedbal_state::get_tile_info_bg)), TILEMAP_SCAN_COLS_FLIP_X, 16, 16, 16, 16);
	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(speedbal_state::get_tile_info_fg)), TILEMAP_SCAN_COLS_FLIP_X,  8,  8, 32, 32);

	m_bg_tilemap->set_transmask(0,0xffff,0x0000); /* split type 0 is totally transparent in front half */
	m_bg_tilemap->set_transmask(1,0x00f7,0x0000); /* split type 1 has pen 0-2, 4-7 transparent in front half */

	m_fg_tilemap->set_transmask(0,0xffff,0x0001); /* split type 0 is totally transparent in front half and has pen 0 transparent in back half */
	m_fg_tilemap->set_transmask(1,0x0001,0x0001); /* split type 1 has pen 0 transparent in front and back half */
}



/*************************************
 *                                   *
 *  Foreground characters RAM        *
 *                                   *
 *************************************/

WRITE8_MEMBER(speedbal_state::foreground_videoram_w)
{
	m_foreground_videoram[offset] = data;
	m_fg_tilemap->mark_tile_dirty(offset>>1);
}

/*************************************
 *                                   *
 *  Background tiles RAM             *
 *                                   *
 *************************************/

WRITE8_MEMBER(speedbal_state::background_videoram_w)
{
	m_background_videoram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset>>1);
}


/*************************************
 *                                   *
 *   Sprite drawing                  *
 *                                   *
 *************************************/

void speedbal_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int x,y,code,color,offset,flipx,flipy;

	/* Drawing sprites: 64 in total */

	for (offset = 0;offset < m_spriteram.bytes();offset += 4)
	{
		if(!(m_spriteram[offset + 2] & 0x80))
			continue;

		x = 243 - m_spriteram[offset + 3];
		y = 239 - m_spriteram[offset + 0];

		code = (m_spriteram[offset + 1]) | ((m_spriteram[offset + 2] & 0x40) << 2);

		color = m_spriteram[offset + 2] & 0x0f;

		flipx = flipy = 0;

		if(flip_screen())
		{
			x = 246 - x;
			y = 238 - y;
			flipx = flipy = 1;
		}

		m_gfxdecode->gfx(2)->transpen(bitmap,cliprect,
				code,
				color,
				flipx,flipy,
				x,y,0);
	}
}

/*************************************
 *                                   *
 *   Refresh screen                  *
 *                                   *
 *************************************/

uint32_t speedbal_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	m_bg_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_LAYER1, 0);
	m_fg_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_LAYER1, 0);
	draw_sprites(bitmap, cliprect);
	m_bg_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_LAYER0, 0);
	m_fg_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_LAYER0, 0);
	return 0;
}