summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/munchmo.cpp
blob: 42f92b055fc29f1aae47f4d12c148ad3c64c523c (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
// license:BSD-3-Clause
// copyright-holders:Phil Stroffolino
#include "emu.h"
#include "includes/munchmo.h"


void munchmo_state::munchmo_palette(palette_device &palette) const
{
	u8 const *const color_prom = memregion("proms")->base();

	for (int i = 0; i < palette.entries(); i++)
	{
		int bit0, bit1, bit2;

		// red component
		bit0 = BIT(color_prom[i], 0);
		bit1 = BIT(color_prom[i], 1);
		bit2 = BIT(color_prom[i], 2);
		int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		// green component
		bit0 = BIT(color_prom[i], 3);
		bit1 = BIT(color_prom[i], 4);
		bit2 = BIT(color_prom[i], 5);
		int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		// blue component
		bit0 = BIT(color_prom[i], 6);
		bit1 = BIT(color_prom[i], 7);
		int const b = 0x4f * bit0 + 0xa8 * bit1;

		palette.set_pen_color(i, rgb_t(r, g, b));
	}
}

WRITE_LINE_MEMBER(munchmo_state::palette_bank_0_w)
{
	m_palette_bank = (state ? 1 : 0) | (m_palette_bank & 2);
}

WRITE_LINE_MEMBER(munchmo_state::palette_bank_1_w)
{
	m_palette_bank = (state ? 2 : 0) | (m_palette_bank & 1);
}

WRITE_LINE_MEMBER(munchmo_state::flipscreen_w)
{
	m_flipscreen = state;
}


void munchmo_state::video_start()
{
	m_tmpbitmap = std::make_unique<bitmap_ind16>(512, 512);
}

void munchmo_state::draw_status( bitmap_ind16 &bitmap, const rectangle &cliprect )
{
	gfx_element *gfx = m_gfxdecode->gfx(0);
	int row;

	for (row = 0; row < 4; row++)
	{
		int sy, sx = (row & 1) * 8;
		const u8 *source = m_status_vram + (~row & 1) * 32;
		if (row <= 1)
		{
			source += 2 * 32;
			sx += 256 + 32 + 16;
		}

		for (sy = 0; sy < 256; sy += 8)
		{
				gfx->opaque(bitmap,cliprect,
				*source++,
				0, /* color */
				0,0, /* no flip */
				sx,sy );
		}
	}
}

void munchmo_state::draw_background( bitmap_ind16 &bitmap, const rectangle &cliprect )
{
/*
    ROM B1.2C contains 256 tilemaps defining 4x4 configurations of
    the tiles in ROM B2.2B
*/
	u8 *rom = memregion("gfx2")->base();
	gfx_element *gfx = m_gfxdecode->gfx(1);
	int offs;

	for (offs = 0; offs < 0x100; offs++)
	{
		int sy = (offs % 16) * 32;
		int sx = (offs / 16) * 32;
		int tile_number = m_videoram[offs];
		int row, col;

		for (row = 0; row < 4; row++)
		{
			for (col = 0; col < 4; col++)
			{
					gfx->opaque(*m_tmpbitmap,m_tmpbitmap->cliprect(),
					rom[col + tile_number * 4 + row * 0x400],
					m_palette_bank,
					0,0, /* flip */
					sx + col * 8, sy + row * 8 );
			}
		}
	}

	{
		int scrollx = -(m_vreg[2] *2 + (m_vreg[3] >> 7)) - 64 - 128 - 16;
		int scrolly = 0;

		copyscrollbitmap(bitmap, *m_tmpbitmap, 1, &scrollx, 1, &scrolly, cliprect);
	}
}

void munchmo_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
{
	int scroll = m_vreg[2];
	int flags = m_vreg[3];                           /*   XB?????? */
	int xadjust = - 128 - 16 - ((flags & 0x80) ? 1 : 0);
	int bank = (flags & 0x40) ? 1 : 0;
	gfx_element *gfx = m_gfxdecode->gfx(2 + bank);
	int color_base = m_palette_bank * 4 + 3;
	int i, j;
	int firstsprite = m_vreg[0] & 0x3f;
	for (i = firstsprite; i < firstsprite + 0x40; i++)
	{
		for (j = 0; j < 8; j++)
		{
			int offs = (j << 6) | (i & 0x3f);
			int tile_number = m_sprite_tile[offs];       /*   ETTTTTTT */
			int attributes = m_sprite_attr[offs];        /*   XYYYYYCC */
			int sx = m_sprite_xpos[offs];                /*   XXXXXXX? */
			int sy = (offs >> 6) << 5;                  /* Y YY------ */
			sy += (attributes >> 2) & 0x1f;
			if( attributes & 0x80 )
			{
				sx = (sx >> 1) | (tile_number & 0x80);
				sx = 2 * ((- 32 - scroll - sx) & 0xff) + xadjust;
					gfx->transpen(bitmap,cliprect,
					0x7f - (tile_number & 0x7f),
					color_base - (attributes & 0x03),
					0,0,                            /* no flip */
					sx,sy, 7 );
			}
		}
	}
}

u32 munchmo_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	draw_background(bitmap, cliprect);
	draw_sprites(bitmap, cliprect);
	draw_status(bitmap, cliprect);
	return 0;
}