summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/unico.cpp
blob: b45b085b8e0771900e4124f96977c7dea8202dcb (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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// license:BSD-3-Clause
// copyright-holders:Luca Elia
/***************************************************************************

                              -= Unico Games =-

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


Note:   if MAME_DEBUG is defined, pressing Z with:

        Q / W / E       Shows Layer 0 / 1 / 2
        A               Shows Sprites

        Keys can be used together!


    [ 3 Scrolling Layers ]

        Tile Size:              16 x 16 x 8
        Layer Size (tiles):     64 x 64

    [ 512 Sprites ]

        Sprites are made of 16 x 16 x 8 tiles. Size can vary from 1 to
        16 tiles horizontally, while their height is always 1 tile.
        There seems to be 4 levels of priority (wrt layers) for each
        sprite, following this simple scheme:

        [if we denote the three layers with 0-3 (0 being the backmost)
         and the sprite with S]

        Sprite Priority         Order (back -> front)
                0                   S 0 1 2
                1                   0 S 1 2
                2                   0 1 S 2
                3                   0 1 2 S

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

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


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

                                    Palette

    Byte:   0   1   2   3
    Gun:    R   G   B   0

    6 Bits x Gun

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

WRITE16_MEMBER(unico_state::unico_palette_w)
{
	uint16_t data1, data2;
	COMBINE_DATA(&m_generic_paletteram_16[offset]);
	data1 = m_generic_paletteram_16[offset & ~1];
	data2 = m_generic_paletteram_16[offset |  1];
	m_palette->set_pen_color( offset/2,
			(data1 >> 8) & 0xFC,
			(data1 >> 0) & 0xFC,
			(data2 >> 8) & 0xFC );
}

WRITE32_MEMBER(zeropnt2_state::unico_palette32_w)
{
	uint32_t rgb0 = COMBINE_DATA(&m_generic_paletteram_32[offset]);
	m_palette->set_pen_color( offset,
			(rgb0 >> 24) & 0xFC,
			(rgb0 >> 16) & 0xFC,
			(rgb0 >>  8) & 0xFC );
}


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

                                Tilemaps

    Offset:     Bits:                   Value:

        0.w                             Code
        2.w     fedc ba98 7--- ----
                ---- ---- -6-- ----     Flip Y
                ---- ---- --5- ----     Flip X
                ---- ---- ---4 3210     Color

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


TILE_GET_INFO_MEMBER(unico_state::get_tile_info)
{
	uint16_t *vram = (uint16_t *)tilemap.user_data();
	uint16_t code = vram[2 * tile_index + 0 ];
	uint16_t attr = vram[2 * tile_index + 1 ];
	SET_TILE_INFO_MEMBER(1, code, attr & 0x1f, TILE_FLIPYX( attr >> 5 ));
}

READ16_MEMBER(unico_state::unico_vram_r) { return m_vram[offset]; }

WRITE16_MEMBER(unico_state::unico_vram_w)
{
	uint16_t *vram = m_vram.get();
	int tile = ((offset / 0x2000) + 1) % 3;
	COMBINE_DATA(&vram[offset]);
	m_tilemap[tile]->mark_tile_dirty((offset & 0x1fff)/2);
}


READ16_MEMBER(unico_state::unico_scroll_r) { return m_scroll[offset]; }
WRITE16_MEMBER(unico_state::unico_scroll_w) { COMBINE_DATA(&m_scroll[offset]); }
READ16_MEMBER(unico_state::unico_spriteram_r) { return m_spriteram[offset]; }
WRITE16_MEMBER(unico_state::unico_spriteram_w)  { COMBINE_DATA(&m_spriteram[offset]); }



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


                            Video Hardware Init


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


void unico_state::video_start()
{
	m_vram   = make_unique_clear<uint16_t[]>(0xc000 / 2);
	m_scroll = make_unique_clear<uint16_t[]>(0x18 / 2);
	m_spriteram = make_unique_clear<uint16_t[]>(0x800 / 2);

	save_pointer(NAME(m_vram), 0xc000/2);
	save_pointer(NAME(m_scroll), 0x18/2);
	save_pointer(NAME(m_spriteram), 0x800/2);

	m_tilemap[0] = &machine().tilemap().create(
			*m_gfxdecode, tilemap_get_info_delegate(FUNC(unico_state::get_tile_info),this),TILEMAP_SCAN_ROWS,
			16,16,  0x40, 0x40);

	m_tilemap[1] = &machine().tilemap().create(
			*m_gfxdecode, tilemap_get_info_delegate(FUNC(unico_state::get_tile_info),this),TILEMAP_SCAN_ROWS,
			16,16,  0x40, 0x40);

	m_tilemap[2] = &machine().tilemap().create(
			*m_gfxdecode, tilemap_get_info_delegate(FUNC(unico_state::get_tile_info),this),TILEMAP_SCAN_ROWS,
			16,16,  0x40, 0x40);

	m_tilemap[0]->set_user_data(&m_vram[0x8000/2]);
	m_tilemap[1]->set_user_data(&m_vram[0x0000/2]);
	m_tilemap[2]->set_user_data(&m_vram[0x4000/2]);

	m_sprites_scrolldx = -0x3f;
	m_sprites_scrolldy = -0x0e;

	m_tilemap[0]->set_scrolldx(-0x32,0);
	m_tilemap[1]->set_scrolldx(-0x30,0);
	m_tilemap[2]->set_scrolldx(-0x2e,0);

	m_tilemap[0]->set_scrolldy(-0x0f,0);
	m_tilemap[1]->set_scrolldy(-0x0f,0);
	m_tilemap[2]->set_scrolldy(-0x0f,0);

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




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

                                Sprites Drawing


        0.w                             X

        2.w                             Y

        4.w                             Code

        6.w     fe-- ---- ---- ----
                --dc ---- ---- ----     Priority
                ---- ba98 ---- ----     Number of tiles along X, minus 1
                ---- ---- 7--- ----
                ---- ---- -6-- ----     Flip Y?
                ---- ---- --5- ----     Flip X
                ---- ---- ---4 3210     Color


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

void unico_state::unico_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect)
{
	uint16_t *spriteram16 = m_spriteram.get();
	int offs;

	/* Draw them backwards, for pdrawgfx */
	for ( offs = (0x800-8)/2; offs >= 0 ; offs -= 8/2 )
	{
		int x, startx, endx, incx;

		int sx          =   spriteram16[ offs + 0 ];
		int sy          =   spriteram16[ offs + 1 ];
		int code        =   spriteram16[ offs + 2 ];
		int attr        =   spriteram16[ offs + 3 ];

		int flipx       =   attr & 0x020;
		int flipy       =   attr & 0x040;   // not sure

		int dimx        =   ((attr >> 8) & 0xf) + 1;

		int priority    =   ((attr >> 12) & 0x3);
		int pri_mask;

		switch( priority )
		{
			case 0:     pri_mask = 0xfe;    break;  // below all
			case 1:     pri_mask = 0xf0;    break;  // above layer 0
			case 2:     pri_mask = 0xfc;    break;  // above layer 1
			default:
			case 3:     pri_mask = 0x00;            // above all
		}

		sx  +=  m_sprites_scrolldx;
		sy  +=  m_sprites_scrolldy;

		sx  =   (sx & 0x1ff) - (sx & 0x200);
		sy  =   (sy & 0x1ff) - (sy & 0x200);

		if (flipx)  {   startx = sx+(dimx-1)*16;    endx = sx-16;       incx = -16; }
		else        {   startx = sx;                endx = sx+dimx*16;  incx = +16; }

		for (x = startx ; x != endx ; x += incx)
		{
			m_gfxdecode->gfx(0)->prio_transpen(bitmap,cliprect,
						code++,
						attr & 0x1f,
						flipx, flipy,
						x, sy,
						screen.priority(),
						pri_mask,0x00   );
		}
	}
}


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


                                Screen Drawing


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

uint32_t unico_state::screen_update_unico(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int layers_ctrl = -1;

	m_tilemap[0]->set_scrollx(0, m_scroll[0x00]);
	m_tilemap[0]->set_scrolly(0, m_scroll[0x01]);

	m_tilemap[1]->set_scrollx(0, m_scroll[0x05]);
	m_tilemap[1]->set_scrolly(0, m_scroll[0x0a]);

	m_tilemap[2]->set_scrollx(0, m_scroll[0x04]);
	m_tilemap[2]->set_scrolly(0, m_scroll[0x02]);

#ifdef MAME_DEBUG
if ( machine().input().code_pressed(KEYCODE_Z) || machine().input().code_pressed(KEYCODE_X) )
{
	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_E))  msk |= 4;
	if (machine().input().code_pressed(KEYCODE_A))  msk |= 8;
	if (msk != 0) layers_ctrl &= msk;
}
#endif

	/* The background color is the first of the last palette */
	bitmap.fill(0x1f00, cliprect);
	screen.priority().fill(0, cliprect);

	if (layers_ctrl & 1)    m_tilemap[0]->draw(screen, bitmap, cliprect, 0,1);
	if (layers_ctrl & 2)    m_tilemap[1]->draw(screen, bitmap, cliprect, 0,2);
	if (layers_ctrl & 4)    m_tilemap[2]->draw(screen, bitmap, cliprect, 0,4);

	/* Sprites are drawn last, using pdrawgfx */
	if (layers_ctrl & 8)    unico_draw_sprites(screen,bitmap,cliprect);

	return 0;
}