summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/snk6502.cpp
blob: 345b9b8097209f6c3a5592dfd7daf212a079b71a (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
296
297
298
299
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria, Dan Boris
/***************************************************************************

  snk6502.c

  Functions to emulate the video hardware of the machine.

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

#include "emu.h"
#include "includes/snk6502.h"
#include "audio/snk6502.h"


#define TOTAL_COLORS(gfxn) (m_gfxdecode->gfx(gfxn)->colors() * m_gfxdecode->gfx(gfxn)->granularity())
#define COLOR(gfxn,offs) (m_gfxdecode->gfx(gfxn)->colorbase() + offs)



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

  Convert the color PROMs into a more useable format.

  Zarzon has a different PROM layout from the others.

***************************************************************************/
void snk6502_state::snk6502_palette(palette_device &palette)
{
	uint8_t 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 = 0;
		bit1 = BIT(color_prom[i], 6);
		bit2 = BIT(color_prom[i], 7);

		int const b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		m_palette_val[i] = rgb_t(r, g, b);
	}

	m_backcolor = 0;    // background color can be changed by the game

	for (int i = 0; i < TOTAL_COLORS(0); i++)
		palette.set_pen_color(COLOR(0, i), m_palette_val[i]);

	for (int i = 0; i < TOTAL_COLORS(1); i++)
	{
		if (i % 4 == 0)
			palette.set_pen_color(COLOR(1, i), m_palette_val[4 * m_backcolor + 0x20]);
		else
			palette.set_pen_color(COLOR(1, i), m_palette_val[i + 0x20]);
	}
}

WRITE8_MEMBER(snk6502_state::videoram_w)
{
	m_videoram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(snk6502_state::videoram2_w)
{
	m_videoram2[offset] = data;
	m_fg_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(snk6502_state::colorram_w)
{
	m_colorram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset);
	m_fg_tilemap->mark_tile_dirty(offset);
}

WRITE8_MEMBER(snk6502_state::charram_w)
{
	if (m_charram[offset] != data)
	{
		m_charram[offset] = data;
		m_gfxdecode->gfx(0)->mark_dirty((offset/8) % 256);
	}
}


WRITE8_MEMBER(snk6502_state::flipscreen_w)
{
	/* bits 0-2 select background color */

	if (m_backcolor != (data & 7))
	{
		m_backcolor = data & 7;

		for (int i = 0;i < 32;i += 4)
			m_palette->set_pen_color(COLOR(1, i), m_palette_val[4 * m_backcolor + 0x20]);
	}

	/* bit 3 selects char bank */

	int bank = (~data & 0x08) >> 3;

	if (m_charbank != bank)
	{
		m_charbank = bank;
		machine().tilemap().mark_all_dirty();
	}

	/* bit 7 flips screen */

	if (flip_screen() != (data & 0x80))
	{
		flip_screen_set(data & 0x80);
		machine().tilemap().mark_all_dirty();
	}
}

WRITE8_MEMBER(fantasy_state::fantasy_flipscreen_w)
{
	m_sound->sound_w(space, offset | 0x03, data, mem_mask);
	flipscreen_w(space, offset, data, mem_mask);
}

WRITE8_MEMBER(snk6502_state::scrollx_w)
{
	m_bg_tilemap->set_scrollx(0, data);
}

WRITE8_MEMBER(snk6502_state::scrolly_w)
{
	m_bg_tilemap->set_scrolly(0, data);
}


TILE_GET_INFO_MEMBER(snk6502_state::get_bg_tile_info)
{
	int code = m_videoram[tile_index] + 256 * m_charbank;
	int color = (m_colorram[tile_index] & 0x38) >> 3;

	SET_TILE_INFO_MEMBER(1, code, color, 0);
}

TILE_GET_INFO_MEMBER(snk6502_state::get_fg_tile_info)
{
	int code = m_videoram2[tile_index];
	int color = m_colorram[tile_index] & 0x07;

	SET_TILE_INFO_MEMBER(0, code, color, 0);
}

VIDEO_START_MEMBER(snk6502_state,snk6502)
{
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snk6502_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snk6502_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);

	m_fg_tilemap->set_transparent_pen(0);

	m_gfxdecode->gfx(0)->set_source(m_charram);
	machine().save().register_postload(save_prepost_delegate(FUNC(snk6502_state::postload), this));
}

void snk6502_state::postload()
{
	m_gfxdecode->gfx(0)->mark_all_dirty();
}

VIDEO_START_MEMBER(snk6502_state,pballoon)
{
	VIDEO_START_CALL_MEMBER( snk6502 );

	m_bg_tilemap->set_scrolldy(-16, -16);
	m_fg_tilemap->set_scrolldy(-16, -16);
}


uint32_t snk6502_state::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
{
	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	return 0;
}

/* Satan of Saturn */

void snk6502_state::satansat_palette(palette_device &palette)
{
	uint8_t 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 = 0;
		bit1 = BIT(color_prom[i], 6);
		bit2 = BIT(color_prom[i], 7);

		int const b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		m_palette_val[i] = rgb_t(r, g, b);
	}

	m_backcolor = 0;    // background color can be changed by the game

	for (int i = 0; i < TOTAL_COLORS(0); i++)
		palette.set_pen_color(COLOR(0, i), m_palette_val[4 * (i % 4) + (i / 4)]);

	for (int i = 0; i < TOTAL_COLORS(1); i++)
	{
		if (i % 4 == 0)
			palette.set_pen_color(COLOR(1, i), m_palette_val[m_backcolor + 0x10]);
		else
			palette.set_pen_color(COLOR(1, i), m_palette_val[4 * (i % 4) + (i / 4) + 0x10]);
	}
}

WRITE8_MEMBER(snk6502_state::satansat_b002_w)
{
	/* bit 0 flips screen */

	if (flip_screen() != (data & 0x01))
	{
		flip_screen_set(data & 0x01);
		machine().tilemap().mark_all_dirty();
	}

	/* bit 1 enables interrupts */
	m_irq_mask = data & 2;

	/* other bits unused */
}

WRITE8_MEMBER(snk6502_state::satansat_backcolor_w)
{
	/* bits 0-1 select background color. Other bits unused. */

	if (m_backcolor != (data & 0x03))
	{
		m_backcolor = data & 0x03;

		for (int i = 0; i < 16; i += 4)
			m_palette->set_pen_color(COLOR(1, i), m_palette_val[m_backcolor + 0x10]);
	}
}

TILE_GET_INFO_MEMBER(snk6502_state::satansat_get_bg_tile_info)
{
	int code = m_videoram[tile_index];
	int color = (m_colorram[tile_index] & 0x0c) >> 2;

	SET_TILE_INFO_MEMBER(1, code, color, 0);
}

TILE_GET_INFO_MEMBER(snk6502_state::satansat_get_fg_tile_info)
{
	int code = m_videoram2[tile_index];
	int color = m_colorram[tile_index] & 0x03;

	SET_TILE_INFO_MEMBER(0, code, color, 0);
}

VIDEO_START_MEMBER(snk6502_state,satansat)
{
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snk6502_state::satansat_get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snk6502_state::satansat_get_fg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);

	m_fg_tilemap->set_transparent_pen(0);

	m_gfxdecode->gfx(0)->set_source(m_charram);
	machine().save().register_postload(save_prepost_delegate(FUNC(snk6502_state::postload), this));
}