summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/esd16.cpp
blob: 77db92df0eb84433a326206f0baccfeb06a441ef (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
// license:BSD-3-Clause
// copyright-holders:Luca Elia, David Haywood
/***************************************************************************

                          -= ESD 16 Bit Games =-

                    driver by   Luca Elia (l.elia@tin.it)


Note:   if MAME_DEBUG is defined, pressing Z with:

        Q / W           Shows Layer 0 / 1
        A               Shows Sprites

        Keys can be used together!


    [ 2 Scrolling Layers ]

        Tile Size:              8 x 8 x 8
        Color Codes:            1 per Layer (banked for Layer 0)
        Layer Size (tiles) :    128 x 64
        Layer Size (pixels):    1024 x 512

    [ 256 Sprites ]

        Sprites are made of 16 x 16 x 5 tiles. Size can vary from 1 to
        8 tiles vertically, while their width is always 1 tile.

    [ Priorities ]

        The game only uses this scheme:

        Back -> Front:  Layer 0, Layer 1, Sprites

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

#include "emu.h"
#include "includes/esd16.h"
#include "screen.h"


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

                                    Tilemaps

    Offset:     Bits:                   Value:

        0.w                             Code

    Color code:  layer 0 (backmost) can bank at every 256 colors,
                 layer 1 uses the first 256.

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

template<unsigned Layer>
TILE_GET_INFO_MEMBER(esd16_state::get_tile_info)
{
	const u16 code = m_vram[Layer][tile_index];
	tileinfo.set(1,
			code,
			m_tilemap_color[Layer],
			0);
}

template<unsigned Layer>
TILE_GET_INFO_MEMBER(esd16_state::get_tile_info_16x16)
{
	const u16 code = m_vram[Layer][tile_index];
	tileinfo.set(2,
			code,
			m_tilemap_color[Layer],
			0);
}


void esd16_state::tilemap0_color_w(u16 data)
{
	m_tilemap_color[0] = data & 0x03;
	m_tilemap[0]->mark_all_dirty();
	m_tilemap_16x16[0]->mark_all_dirty();

	bool flip = BIT(data, 7);
	flip_screen_set(flip);
	m_sprgen->set_flip_screen(flip);
}

void esd16_state::tilemap0_color_jumppop_w(u16 data)
{
	// todo
	m_tilemap_color[0] = 2;
	m_tilemap_color[1] = 1;

	bool flip = BIT(data, 7);
	flip_screen_set(flip);
	m_sprgen->set_flip_screen(flip);
}


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


                            Video Hardware Init


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


void esd16_state::video_start()
{
	m_tilemap[0] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(esd16_state::get_tile_info<0>)), TILEMAP_SCAN_ROWS, 8, 8, 0x80, 0x40);
	m_tilemap[1] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(esd16_state::get_tile_info<1>)), TILEMAP_SCAN_ROWS, 8, 8, 0x80, 0x40);

	/* swatpolc changes tilemap 0 to 16x16 at various times */
	m_tilemap_16x16[0] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(esd16_state::get_tile_info_16x16<0>)), TILEMAP_SCAN_ROWS, 16,16, 0x40, 0x40);

	/* hedpanic changes tilemap 1 to 16x16 at various times */
	m_tilemap_16x16[1] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(esd16_state::get_tile_info_16x16<1>)), TILEMAP_SCAN_ROWS, 16,16, 0x40, 0x40);

	m_tilemap[0]->set_scrolldx(-0x60 + 2, -0x60);
	m_tilemap[1]->set_scrolldx(-0x60, -0x60 + 2);
	m_tilemap_16x16[0]->set_scrolldx(-0x60 + 2, -0x60);
	m_tilemap_16x16[1]->set_scrolldx(-0x60, -0x60 + 2);

	m_tilemap[1]->set_transparent_pen(0x00);
	m_tilemap_16x16[1]->set_transparent_pen(0x00);
}


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


                                Screen Drawing


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

u32 esd16_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int layers_ctrl = -1;

	screen.priority().fill(0, cliprect);

#ifdef MAME_DEBUG
if (machine().input().code_pressed(KEYCODE_Z))
{
	int msk = 0;
	if (machine().input().code_pressed(KEYCODE_Q))  msk |= 1;
	if (machine().input().code_pressed(KEYCODE_W))  msk |= 2;
	if (machine().input().code_pressed(KEYCODE_A))  msk |= 4;
	if (msk != 0) layers_ctrl &= msk;
}
#endif

	if (layers_ctrl & 1)
	{
		if (m_head_layersize[0] & 0x0001)
		{
			m_tilemap_16x16[0]->set_scrollx(0, m_scroll[0][0]);
			m_tilemap_16x16[0]->set_scrolly(0, m_scroll[0][1]);
			m_tilemap_16x16[0]->draw(screen, bitmap, cliprect, 0, 0);
		}
		else
		{
			m_tilemap[0]->set_scrollx(0, m_scroll[0][0]);
			m_tilemap[0]->set_scrolly(0, m_scroll[0][1]);
			m_tilemap[0]->draw(screen, bitmap, cliprect, 0, 0);
		}
	}
	else
	{
		bitmap.fill(0, cliprect);
	}


	if (layers_ctrl & 2)
	{
		if (m_head_layersize[0] & 0x0002)
		{
			m_tilemap_16x16[1]->set_scrollx(0, m_scroll[1][0]);
			m_tilemap_16x16[1]->set_scrolly(0, m_scroll[1][1]);
			m_tilemap_16x16[1]->draw(screen, bitmap, cliprect, 0, 1);
		}
		else
		{
			m_tilemap[1]->set_scrollx(0, m_scroll[1][0]);
			m_tilemap[1]->set_scrolly(0, m_scroll[1][1]);
			m_tilemap[1]->draw(screen, bitmap, cliprect, 0, 1);
		}

	}

	if (layers_ctrl & 4) m_sprgen->draw_sprites(bitmap, cliprect, m_spriteram, 0x400);

//  popmessage("%04x %04x %04x %04x %04x",head_unknown1[0],head_layersize[0],head_unknown3[0],head_unknown4[0],head_unknown5[0]);
	return 0;
}