summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/mugsmash.cpp
blob: a5adb0598195e2147b880c6d65b0265374e78b73 (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
// license:BSD-3-Clause
// copyright-holders:David Haywood
/* video/mugsmash.c - see drivers/mugsmash.c for more info */

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

void mugsmash_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect )
{
	/* Each Sprite takes 16 bytes, 5 used? */

	/* ---- ----  xxxx xxxx  ---- ----  aaaa aaaa  ---- ----  NNNN NNNN  ---- ----  nnnn nnnn  ---- ----  yyyy yyyy (rest unused?) */

	/* x = xpos LSB
	   y = ypos LSB
	   N = tile number MSB
	   n = tile number LSB
	   a = attribute / extra
	        f?XY cccc

	    f = x-flip
	    ? = unknown, probably y-flip
	    X = xpos MSB
	    y = ypos MSB
	    c = colour

	*/

	const uint16_t *source = m_spriteram;
	const uint16_t *finish = source + 0x2000;
	gfx_element *gfx = m_gfxdecode->gfx(0);

	while (source < finish)
	{
		int xpos = source[0] & 0x00ff;
		int ypos = source[4] & 0x00ff;
		int num = (source[3] & 0x00ff) | ((source[2] & 0x00ff) << 8);
		int attr = source[1];
		int flipx = (attr & 0x0080) >> 7;
		int colour = (attr & 0x000f);

		xpos += ((attr & 0x0020) >> 5) * 0x100;
		ypos += ((attr & 0x0010) >> 4) * 0x100;

		xpos -= 28;
		ypos -= 16;


				gfx->transpen(
				bitmap,
				cliprect,
				num,
				colour,
				flipx,0,
				xpos,ypos,0
				);

		source += 0x8;
	}
}

TILE_GET_INFO_MEMBER(mugsmash_state::get_mugsmash_tile_info1)
{
	/* fF-- cccc  nnnn nnnn */

	/* c = colour?
	   n = number?
	   F = flip-X
	   f = flip-Y
	*/

	int tileno, colour, fx;

	tileno = m_videoram1[tile_index * 2 + 1];
	colour = m_videoram1[tile_index * 2] & 0x000f;
	fx = (m_videoram1[tile_index * 2] & 0xc0) >> 6;

	SET_TILE_INFO_MEMBER(1, tileno, colour, TILE_FLIPYX(fx));
}

WRITE16_MEMBER(mugsmash_state::mugsmash_videoram1_w)
{
	m_videoram1[offset] = data;
	m_tilemap1->mark_tile_dirty(offset / 2);
}

TILE_GET_INFO_MEMBER(mugsmash_state::get_mugsmash_tile_info2)
{
	/* fF-- cccc  nnnn nnnn */

	/* c = colour?
	   n = number?
	   F = flip-X
	   f = flip-Y
	*/

	int tileno, colour, fx;

	tileno = m_videoram2[tile_index * 2 + 1];
	colour = m_videoram2[tile_index * 2] & 0x000f;
	fx = (m_videoram2[tile_index * 2] & 0xc0) >> 6;

	SET_TILE_INFO_MEMBER(1, tileno, 16 + colour, TILE_FLIPYX(fx));
}

WRITE16_MEMBER(mugsmash_state::mugsmash_videoram2_w)
{
	m_videoram2[offset] = data;
	m_tilemap2->mark_tile_dirty(offset / 2);
}

WRITE16_MEMBER(mugsmash_state::mugsmash_reg_w)
{
	m_regs1[offset] = data;
//  popmessage ("Regs %04x, %04x, %04x, %04x", mugsmash_regs1[0], mugsmash_regs1[1],mugsmash_regs1[2], mugsmash_regs1[3]);

	switch (offset)
	{
	case 0:
		m_tilemap2->set_scrollx(0, m_regs1[2] + 7);
		break;
	case 1:
		m_tilemap2->set_scrolly(0, m_regs1[3] + 4);
		break;
	case 2:
		m_tilemap1->set_scrollx(0, m_regs1[0] + 3);
		break;
	case 3:
		m_tilemap1->set_scrolly(0, m_regs1[1] + 4);
		break;
	}
}

void mugsmash_state::video_start()
{
	m_tilemap1 = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(mugsmash_state::get_mugsmash_tile_info1)), TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
	m_tilemap1->set_transparent_pen(0);

	m_tilemap2 = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(mugsmash_state::get_mugsmash_tile_info2)), TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
}

uint32_t mugsmash_state::screen_update_mugsmash(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	m_tilemap2->draw(screen, bitmap, cliprect, 0, 0);
	m_tilemap1->draw(screen, bitmap, cliprect, 0, 0);
	draw_sprites(bitmap, cliprect);
	return 0;
}