summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/fromance.cpp
blob: 06ffec1c4e27ec05a4df6a9717ddda47c88a6489 (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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// license:BSD-3-Clause
// copyright-holders:Takahiro Nogi. Bryan McPhail, Nicola Salmoria, Aaron Giles
/******************************************************************************

    Video Hardware for Video System Mahjong series and Pipe Dream.

    Driver by Takahiro Nogi <nogi@kt.rim.or.jp> 2001/02/04 -
    and Bryan McPhail, Nicola Salmoria, Aaron Giles

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

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




/*************************************
 *
 *  Tilemap callbacks
 *
 *************************************/

inline void fromance_state::get_fromance_tile_info( tile_data &tileinfo, int tile_index, int layer )
{
	int tile = ((m_local_videoram[layer][0x0000 + tile_index] & 0x80) << 9) |
				(m_local_videoram[layer][0x1000 + tile_index] << 8) |
				m_local_videoram[layer][0x2000 + tile_index];
	int color = m_local_videoram[layer][tile_index] & 0x7f;

	SET_TILE_INFO_MEMBER(layer, tile, color, 0);
}

TILE_GET_INFO_MEMBER(fromance_state::get_fromance_bg_tile_info){ get_fromance_tile_info(tileinfo, tile_index, 0); }
TILE_GET_INFO_MEMBER(fromance_state::get_fromance_fg_tile_info){ get_fromance_tile_info(tileinfo, tile_index, 1); }


inline void fromance_state::get_nekkyoku_tile_info( tile_data &tileinfo, int tile_index, int layer )
{
	int tile = (m_local_videoram[layer][0x0000 + tile_index] << 8) |
				m_local_videoram[layer][0x1000 + tile_index];
	int color = m_local_videoram[layer][tile_index + 0x2000] & 0x3f;

	SET_TILE_INFO_MEMBER(layer, tile, color, 0);
}

TILE_GET_INFO_MEMBER(fromance_state::get_nekkyoku_bg_tile_info){ get_nekkyoku_tile_info(tileinfo, tile_index, 0); }
TILE_GET_INFO_MEMBER(fromance_state::get_nekkyoku_fg_tile_info){ get_nekkyoku_tile_info(tileinfo, tile_index, 1); }



/*************************************
 *
 *  Video system start
 *
 *************************************/

void fromance_state::init_common(  )
{
	/* allocate local videoram */
	m_local_videoram[0] = std::make_unique<uint8_t[]>(0x1000 * 3);
	m_local_videoram[1] = std::make_unique<uint8_t[]>(0x1000 * 3);

	/* allocate local palette RAM */
	m_local_paletteram = std::make_unique<uint8_t[]>(0x800 * 2);

	/* configure tilemaps */
	m_fg_tilemap->set_transparent_pen(15);

	/* reset the timer */
	m_crtc_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(fromance_state::crtc_interrupt_gen),this));

	/* state save */
	save_item(NAME(m_selected_videoram));
	save_pointer(NAME(m_local_videoram[0].get()), 0x1000 * 3);
	save_pointer(NAME(m_local_videoram[1].get()), 0x1000 * 3);
	save_item(NAME(m_selected_paletteram));
	save_item(NAME(m_scrollx));
	save_item(NAME(m_scrolly));
	save_item(NAME(m_gfxreg));
	save_item(NAME(m_flipscreen));
	save_item(NAME(m_flipscreen_old));
	save_item(NAME(m_scrollx_ofs));
	save_item(NAME(m_scrolly_ofs));
	save_pointer(NAME(m_local_paletteram.get()), 0x800 * 2);
}

VIDEO_START_MEMBER(fromance_state,fromance)
{
	/* allocate tilemaps */
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(fromance_state::get_fromance_bg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 4, 64, 64);
	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(fromance_state::get_fromance_fg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 4, 64, 64);

	init_common();
}

VIDEO_START_MEMBER(fromance_state,nekkyoku)
{
	/* allocate tilemaps */
	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(fromance_state::get_nekkyoku_bg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 4, 64, 64);
	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(fromance_state::get_nekkyoku_fg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 4, 64, 64);

	init_common();
}

VIDEO_START_MEMBER(fromance_state,pipedrm)
{
	VIDEO_START_CALL_MEMBER(fromance);
	m_scrolly_ofs = 0x00;
}

VIDEO_START_MEMBER(fromance_state,hatris)
{
	VIDEO_START_CALL_MEMBER(fromance);
	m_scrollx_ofs = 0xB9;
	m_scrolly_ofs = 0x00;
}

/*************************************
 *
 *  Graphics control register
 *
 *************************************/

WRITE8_MEMBER(fromance_state::fromance_gfxreg_w)
{
	m_gfxreg = data;
	m_flipscreen = (data & 0x01);
	m_selected_videoram = (~data >> 1) & 1;
	m_selected_paletteram = (data >> 6) & 1;

	if (m_flipscreen != m_flipscreen_old)
	{
		m_flipscreen_old = m_flipscreen;
		machine().tilemap().set_flip_all(m_flipscreen ? (TILEMAP_FLIPX | TILEMAP_FLIPY) : 0);
	}
}



/*************************************
 *
 *  Banked palette RAM
 *
 *************************************/

READ8_MEMBER(fromance_state::fromance_paletteram_r)
{
	/* adjust for banking and read */
	offset |= m_selected_paletteram << 11;
	return m_local_paletteram[offset];
}


WRITE8_MEMBER(fromance_state::fromance_paletteram_w)
{
	int palword;

	/* adjust for banking and modify */
	offset |= m_selected_paletteram << 11;
	m_local_paletteram[offset] = data;

	/* compute R,G,B */
	palword = (m_local_paletteram[offset | 1] << 8) | m_local_paletteram[offset & ~1];
	m_palette->set_pen_color(offset / 2, pal5bit(palword >> 10), pal5bit(palword >> 5), pal5bit(palword >> 0));
}



/*************************************
 *
 *  Video RAM read/write
 *
 *************************************/

READ8_MEMBER(fromance_state::fromance_videoram_r)
{
	return m_local_videoram[m_selected_videoram][offset];
}


WRITE8_MEMBER(fromance_state::fromance_videoram_w)
{
	m_local_videoram[m_selected_videoram][offset] = data;
	(m_selected_videoram ? m_fg_tilemap : m_bg_tilemap)->mark_tile_dirty(offset & 0x0fff);
}



/*************************************
 *
 *  Scroll registers
 *
 *************************************/

WRITE8_MEMBER(fromance_state::fromance_scroll_w)
{
	if (m_flipscreen)
	{
		switch (offset)
		{
			case 0:
				m_scrollx[1] = (data + (((m_gfxreg & 0x08) >> 3) * 0x100) - m_scrollx_ofs);
				break;
			case 1:
				m_scrolly[1] = (data + (((m_gfxreg & 0x04) >> 2) * 0x100) - m_scrolly_ofs); // - 0x10
				break;
			case 2:
				m_scrollx[0] = (data + (((m_gfxreg & 0x20) >> 5) * 0x100) - m_scrollx_ofs);
				break;
			case 3:
				m_scrolly[0] = (data + (((m_gfxreg & 0x10) >> 4) * 0x100) - m_scrolly_ofs);
				break;
		}
	}
	else
	{

		switch (offset)
		{
			case 0:
				m_scrollx[1] = (data + (((m_gfxreg & 0x08) >> 3) * 0x100) - 0x1f7);
				break;
			case 1:
				m_scrolly[1] = (data + (((m_gfxreg & 0x04) >> 2) * 0x100) - 0xf9);
				break;
			case 2:
				m_scrollx[0] = (data + (((m_gfxreg & 0x20) >> 5) * 0x100) - 0x1f7);
				break;
			case 3:
				m_scrolly[0] = (data + (((m_gfxreg & 0x10) >> 4) * 0x100) - 0xf9);
				break;
		}
	}
}



/*************************************
 *
 *  Fake video controller
 *
 *************************************/

TIMER_CALLBACK_MEMBER(fromance_state::crtc_interrupt_gen)
{
	m_subcpu->set_input_line(0, HOLD_LINE);
	if (param != 0)
		m_crtc_timer->adjust(m_screen->frame_period() / param, 0, m_screen->frame_period() / param);
}

/*
 0  1  2  3  4  5
57 63 69 71 1f 00 (all games)
4f 62 69 71 1f 04 nekkyoku
 8  9  A  B
7a 7b 7d 7f  (all games)
79 7a 7d 7f  nekkyoku (gameplay/title screen)
77 79 7d 7e  nekkyoku (gals display)
 */
// TODO: guesswork, looks fully programmable
void fromance_state::crtc_refresh()
{
	if (m_gga->reg(0) == 0) // sanity check
		return;

	rectangle visarea;
	attoseconds_t refresh;

	visarea.min_x = 0;
	visarea.min_y = 0;
	visarea.max_x = ((m_gga->reg(0)+1)*4) - 1;
	visarea.max_y = 240 - 1;

	refresh = HZ_TO_ATTOSECONDS(60);

	m_screen->configure(512, 256, visarea, refresh);
}

WRITE8_MEMBER(fromance_state::fromance_gga_data_w)
{
	switch (offset)
	{
		case 0x00:
			crtc_refresh();
			break;

		case 0x0b:
			// TODO: actually is never > 0x80?
			m_crtc_timer->adjust(m_screen->time_until_vblank_start(), (data > 0x80) ? 2 : 1);
			break;

		default:
			logerror("CRTC register %02X = %02X\n", offset, data);
			break;
	}
}


/*************************************
 *
 *  Main screen refresh
 *
 *************************************/

uint32_t fromance_state::screen_update_fromance(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	m_bg_tilemap->set_scrollx(0, m_scrollx[0]);
	m_bg_tilemap->set_scrolly(0, m_scrolly[0]);
	m_fg_tilemap->set_scrollx(0, m_scrollx[1]);
	m_fg_tilemap->set_scrolly(0, m_scrolly[1]);

	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	return 0;
}


uint32_t fromance_state::screen_update_pipedrm(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	uint8_t* sram = m_spriteram;

	/* there seems to be no logical mapping for the X scroll register -- maybe it's gone */
	m_bg_tilemap->set_scrolly(0, m_scrolly[1]);
	m_fg_tilemap->set_scrolly(0, m_scrolly[0]);

	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	m_spr_old->turbofrc_draw_sprites((uint16_t*)sram, m_spriteram.bytes(), 0, bitmap, cliprect, screen.priority(), 0);
	m_spr_old->turbofrc_draw_sprites((uint16_t*)sram, m_spriteram.bytes(), 0, bitmap, cliprect, screen.priority(), 1);
	return 0;
}