summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/mugsmash.c
blob: ecc0ae43622f0729e24bbbde19b338e77434202d (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
/* video/mugsmash.c - see drivers/mugsmash.c for more info */

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

static void draw_sprites(running_machine &machine, bitmap_t *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

    */

	mugsmash_state *state = machine.driver_data<mugsmash_state>();
	const UINT16 *source = state->m_spriteram;
	const UINT16 *finish = source + 0x2000;
	const gfx_element *gfx = machine.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;

		drawgfx_transpen(
				bitmap,
				cliprect,
				gfx,
				num,
				colour,
				flipx,0,
				xpos,ypos,0
				);

		source += 0x8;
	}
}

static TILE_GET_INFO( get_mugsmash_tile_info1 )
{

	/* fF-- cccc  nnnn nnnn */

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

	mugsmash_state *state = machine.driver_data<mugsmash_state>();
	int tileno, colour, fx;

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

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

WRITE16_HANDLER( mugsmash_videoram1_w )
{
	mugsmash_state *state = space->machine().driver_data<mugsmash_state>();

	state->m_videoram1[offset] = data;
	tilemap_mark_tile_dirty(state->m_tilemap1, offset / 2);
}

static TILE_GET_INFO( get_mugsmash_tile_info2 )
{

	/* fF-- cccc  nnnn nnnn */

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

	mugsmash_state *state = machine.driver_data<mugsmash_state>();
	int tileno, colour, fx;

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

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

WRITE16_HANDLER( mugsmash_videoram2_w )
{
	mugsmash_state *state = space->machine().driver_data<mugsmash_state>();

	state->m_videoram2[offset] = data;
	tilemap_mark_tile_dirty(state->m_tilemap2, offset / 2);
}

WRITE16_HANDLER (mugsmash_reg_w)
{
	mugsmash_state *state = space->machine().driver_data<mugsmash_state>();

	state->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:
		tilemap_set_scrollx(state->m_tilemap2, 0, state->m_regs1[2] + 7);
		break;
	case 1:
		tilemap_set_scrolly(state->m_tilemap2, 0, state->m_regs1[3] + 4);
		break;
	case 2:
		tilemap_set_scrollx(state->m_tilemap1, 0, state->m_regs1[0] + 3);
		break;
	case 3:
		tilemap_set_scrolly(state->m_tilemap1, 0, state->m_regs1[1] + 4);
		break;
	}
}

VIDEO_START( mugsmash )
{
	mugsmash_state *state = machine.driver_data<mugsmash_state>();

	state->m_tilemap1 = tilemap_create(machine, get_mugsmash_tile_info1, tilemap_scan_rows, 16, 16, 32, 32);
	tilemap_set_transparent_pen(state->m_tilemap1, 0);

	state->m_tilemap2 = tilemap_create(machine, get_mugsmash_tile_info2, tilemap_scan_rows, 16, 16, 32, 32);
}

SCREEN_UPDATE( mugsmash )
{
	mugsmash_state *state = screen->machine().driver_data<mugsmash_state>();

	tilemap_draw(bitmap, cliprect, state->m_tilemap2, 0, 0);
	tilemap_draw(bitmap, cliprect, state->m_tilemap1, 0, 0);
	draw_sprites(screen->machine(), bitmap, cliprect);
	return 0;
}