1 // license:BSD-3-Clause
2 // copyright-holders:Nicola Salmoria
3 
4 #include "emu.h"
5 #include "includes/tmnt.h"
6 #include "screen.h"
7 
TILE_GET_INFO_MEMBER(glfgreat_state::glfgreat_get_roz_tile_info)8 TILE_GET_INFO_MEMBER(glfgreat_state::glfgreat_get_roz_tile_info)
9 {
10 	uint8_t *rom = memregion("user1")->base();
11 	int code;
12 
13 	tile_index += 0x40000 * m_roz_rom_bank;
14 
15 	code = rom[tile_index + 0x80000] + 256 * rom[tile_index] + 256 * 256 * ((rom[tile_index / 4 + 0x100000] >> (2 * (tile_index & 3))) & 3);
16 
17 	tileinfo.set(0, code & 0x3fff, code >> 14, 0);
18 }
19 
TILE_GET_INFO_MEMBER(prmrsocr_state::prmrsocr_get_roz_tile_info)20 TILE_GET_INFO_MEMBER(prmrsocr_state::prmrsocr_get_roz_tile_info)
21 {
22 	uint8_t *rom = memregion("user1")->base();
23 	int code = rom[tile_index + 0x20000] + 256 * rom[tile_index];
24 
25 	tileinfo.set(0, code & 0x1fff, code >> 13, 0);
26 }
27 
28 
29 
30 /***************************************************************************
31 
32   Callbacks for the K052109
33 
34 ***************************************************************************/
35 
36 /* Missing in Action */
37 
K052109_CB_MEMBER(tmnt_state::mia_tile_callback)38 K052109_CB_MEMBER(tmnt_state::mia_tile_callback)
39 {
40 	*flags = (*color & 0x04) ? TILE_FLIPX : 0;
41 	if (layer == 0)
42 	{
43 		*code |= ((*color & 0x01) << 8);
44 		*color = m_layer_colorbase[layer] + ((*color & 0x80) >> 5) + ((*color & 0x10) >> 1);
45 	}
46 	else
47 	{
48 		*code |= ((*color & 0x01) << 8) | ((*color & 0x18) << 6) | (bank << 11);
49 		*color = m_layer_colorbase[layer] + ((*color & 0xe0) >> 5);
50 	}
51 }
52 
K052109_CB_MEMBER(tmnt_state::cuebrick_tile_callback)53 K052109_CB_MEMBER(tmnt_state::cuebrick_tile_callback)
54 {
55 	if ((m_k052109->get_rmrd_line() == CLEAR_LINE) && (layer == 0))
56 	{
57 		*code |= ((*color & 0x01) << 8);
58 		*color = m_layer_colorbase[layer]  + ((*color & 0x0e) >> 1);
59 	}
60 	else
61 	{
62 		*code |= ((*color & 0xf) << 8);
63 		*color = m_layer_colorbase[layer] + ((*color & 0xe0) >> 5);
64 	}
65 }
66 
K052109_CB_MEMBER(tmnt_state::tmnt_tile_callback)67 K052109_CB_MEMBER(tmnt_state::tmnt_tile_callback)
68 {
69 	*code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9) | (bank << 13);
70 	*color = m_layer_colorbase[layer] + ((*color & 0xe0) >> 5);
71 }
72 
K052109_CB_MEMBER(tmnt_state::ssbl_tile_callback)73 K052109_CB_MEMBER(tmnt_state::ssbl_tile_callback)
74 {
75 	if (layer == 0)
76 	{
77 		*code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9) | (bank << 13);
78 	}
79 	else
80 	{
81 		*code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9) | (bank << 13);
82 //      osd_printf_debug("L%d: bank %d code %x color %x\n", layer, bank, *code, *color);
83 	}
84 
85 	*color = m_layer_colorbase[layer] + ((*color & 0xe0) >> 5);
86 }
87 
K052109_CB_MEMBER(tmnt_state::blswhstl_tile_callback)88 K052109_CB_MEMBER(tmnt_state::blswhstl_tile_callback)
89 {
90 	/* (color & 0x02) is flip y handled internally by the 052109 */
91 	*code |= ((*color & 0x01) << 8) | ((*color & 0x10) << 5) | ((*color & 0x0c) << 8) | (bank << 12) | m_blswhstl_rombank << 14;
92 	*color = m_layer_colorbase[layer] + ((*color & 0xe0) >> 5);
93 }
94 
95 
96 
97 /***************************************************************************
98 
99   Callbacks for the K051960
100 
101 ***************************************************************************/
102 
K051960_CB_MEMBER(tmnt_state::mia_sprite_callback)103 K051960_CB_MEMBER(tmnt_state::mia_sprite_callback)
104 {
105 	*color = m_sprite_colorbase + (*color & 0x0f);
106 }
107 
K051960_CB_MEMBER(tmnt_state::tmnt_sprite_callback)108 K051960_CB_MEMBER(tmnt_state::tmnt_sprite_callback)
109 {
110 	*code |= (*color & 0x10) << 9;
111 	*color = m_sprite_colorbase + (*color & 0x0f);
112 }
113 
K051960_CB_MEMBER(tmnt_state::punkshot_sprite_callback)114 K051960_CB_MEMBER(tmnt_state::punkshot_sprite_callback)
115 {
116 	int pri = 0x20 | ((*color & 0x60) >> 2);
117 	if (pri <= m_layerpri[2])
118 		*priority = 0;
119 	else if (pri > m_layerpri[2] && pri <= m_layerpri[1])
120 		*priority = 0xf0;
121 	else if (pri > m_layerpri[1] && pri <= m_layerpri[0])
122 		*priority = 0xf0 | 0xcc;
123 	else
124 		*priority = 0xf0 | 0xcc | 0xaa;
125 
126 	*code |= (*color & 0x10) << 9;
127 	*color = m_sprite_colorbase + (*color & 0x0f);
128 }
129 
K051960_CB_MEMBER(tmnt_state::thndrx2_sprite_callback)130 K051960_CB_MEMBER(tmnt_state::thndrx2_sprite_callback)
131 {
132 	int pri = 0x20 | ((*color & 0x60) >> 2);
133 	if (pri <= m_layerpri[2])
134 		*priority = 0;
135 	else if (pri > m_layerpri[2] && pri <= m_layerpri[1])
136 		*priority = 0xf0;
137 	else if (pri > m_layerpri[1] && pri <= m_layerpri[0])
138 		*priority = 0xf0 | 0xcc;
139 	else
140 		*priority = 0xf0 | 0xcc | 0xaa;
141 
142 	*color = m_sprite_colorbase + (*color & 0x0f);
143 }
144 
145 
146 /***************************************************************************
147 
148   Callbacks for the K053245
149 
150 ***************************************************************************/
151 
K05324X_CB_MEMBER(tmnt_state::lgtnfght_sprite_callback)152 K05324X_CB_MEMBER(tmnt_state::lgtnfght_sprite_callback)
153 {
154 	int pri = 0x20 | ((*color & 0x60) >> 2);
155 	if (pri <= m_layerpri[2])
156 		*priority = 0;
157 	else if (pri > m_layerpri[2] && pri <= m_layerpri[1])
158 		*priority = 0xf0;
159 	else if (pri > m_layerpri[1] && pri <= m_layerpri[0])
160 		*priority = 0xf0 | 0xcc;
161 	else
162 		*priority = 0xf0 | 0xcc | 0xaa;
163 
164 	*color = m_sprite_colorbase + (*color & 0x1f);
165 }
166 
K05324X_CB_MEMBER(tmnt_state::blswhstl_sprite_callback)167 K05324X_CB_MEMBER(tmnt_state::blswhstl_sprite_callback)
168 {
169 #if 0
170 if (machine().input().code_pressed(KEYCODE_Q) && (*color & 0x20)) *color = machine().rand();
171 if (machine().input().code_pressed(KEYCODE_W) && (*color & 0x40)) *color = machine().rand();
172 if (machine().input().code_pressed(KEYCODE_E) && (*color & 0x80)) *color = machine().rand();
173 #endif
174 	int pri = 0x20 | ((*color & 0x60) >> 2);
175 	if (pri <= m_layerpri[2])
176 		*priority = 0;
177 	else if (pri > m_layerpri[2] && pri <= m_layerpri[1])
178 		*priority = 0xf0;
179 	else if (pri > m_layerpri[1] && pri <= m_layerpri[0])
180 		*priority = 0xf0 | 0xcc;
181 	else
182 		*priority = 0xf0 | 0xcc | 0xaa;
183 
184 	*color = m_sprite_colorbase + (*color & 0x1f);
185 }
186 
K05324X_CB_MEMBER(prmrsocr_state::prmrsocr_sprite_callback)187 K05324X_CB_MEMBER(prmrsocr_state::prmrsocr_sprite_callback)
188 {
189 	int pri = 0x20 | ((*color & 0x60) >> 2);
190 	if (pri <= m_layerpri[2])
191 		*priority = 0;
192 	else if (pri > m_layerpri[2] && pri <= m_layerpri[1])
193 		*priority = 0xf0;
194 	else if (pri > m_layerpri[1] && pri <= m_layerpri[0])
195 		*priority = 0xf0 | 0xcc;
196 	else
197 		*priority = 0xf0 | 0xcc | 0xaa;
198 
199 	*code |= m_sprite_bank << 14;
200 	*color = m_sprite_colorbase + (*color & 0x1f);
201 }
202 
203 
204 
205 /***************************************************************************
206 
207   Start the video hardware emulation.
208 
209 ***************************************************************************/
210 
VIDEO_START_MEMBER(tmnt_state,cuebrick)211 VIDEO_START_MEMBER(tmnt_state,cuebrick)
212 {
213 	m_layer_colorbase[0] = 0;
214 	m_layer_colorbase[1] = 32;
215 	m_layer_colorbase[2] = 40;
216 	m_sprite_colorbase = 16;
217 }
218 
VIDEO_START_MEMBER(tmnt_state,mia)219 VIDEO_START_MEMBER(tmnt_state,mia)
220 {
221 	m_layer_colorbase[0] = 0;
222 	m_layer_colorbase[1] = 32;
223 	m_layer_colorbase[2] = 40;
224 	m_sprite_colorbase = 16;
225 
226 	m_tmnt_priorityflag = 0;
227 	save_item(NAME(m_tmnt_priorityflag));
228 }
229 
VIDEO_START_MEMBER(tmnt_state,tmnt)230 VIDEO_START_MEMBER(tmnt_state,tmnt)
231 {
232 	m_layer_colorbase[0] = 0;
233 	m_layer_colorbase[1] = 32;
234 	m_layer_colorbase[2] = 40;
235 	m_sprite_colorbase = 16;
236 
237 	m_tmnt_priorityflag = 0;
238 	save_item(NAME(m_tmnt_priorityflag));
239 
240 	m_palette->set_shadow_factor(0.75);
241 }
242 
VIDEO_START_MEMBER(tmnt_state,lgtnfght)243 VIDEO_START_MEMBER(tmnt_state,lgtnfght)/* also tmnt2, ssriders */
244 {
245 	m_k053245->set_z_rejection(0);
246 
247 	m_dim_c = m_dim_v = m_lastdim = m_lasten = 0;
248 
249 	save_item(NAME(m_dim_c));
250 	save_item(NAME(m_dim_v));
251 	save_item(NAME(m_lastdim));
252 	save_item(NAME(m_lasten));
253 }
254 
VIDEO_START_MEMBER(glfgreat_state,glfgreat)255 VIDEO_START_MEMBER(glfgreat_state,glfgreat)
256 {
257 	m_roz_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(glfgreat_state::glfgreat_get_roz_tile_info)), TILEMAP_SCAN_ROWS, 16, 16, 512, 512);
258 	m_roz_tilemap->set_transparent_pen(0);
259 
260 	m_controller_select = 0;
261 	m_roz_rom_bank = 0;
262 	m_roz_char_bank = 0;
263 	m_roz_rom_mode = 0;
264 	save_item(NAME(m_controller_select));
265 	save_item(NAME(m_roz_rom_bank));
266 	save_item(NAME(m_roz_char_bank));
267 	save_item(NAME(m_roz_rom_mode));
268 }
269 
VIDEO_START_MEMBER(prmrsocr_state,prmrsocr)270 VIDEO_START_MEMBER(prmrsocr_state,prmrsocr)
271 {
272 	m_roz_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(prmrsocr_state::prmrsocr_get_roz_tile_info)), TILEMAP_SCAN_ROWS, 16, 16, 512, 256);
273 	m_roz_tilemap->set_transparent_pen(0);
274 
275 	m_sprite_bank = 0;
276 	m_roz_char_bank = 0;
277 	save_item(NAME(m_sprite_bank));
278 	save_item(NAME(m_roz_char_bank));
279 }
280 
VIDEO_START_MEMBER(tmnt_state,blswhstl)281 VIDEO_START_MEMBER(tmnt_state,blswhstl)
282 {
283 	m_blswhstl_rombank = -1;
284 	save_item(NAME(m_blswhstl_rombank));
285 }
286 
287 
288 /***************************************************************************
289 
290   Memory handlers
291 
292 ***************************************************************************/
293 
tmnt_0a0000_w(offs_t offset,uint16_t data,uint16_t mem_mask)294 void tmnt_state::tmnt_0a0000_w(offs_t offset, uint16_t data, uint16_t mem_mask)
295 {
296 	if (ACCESSING_BITS_0_7)
297 	{
298 		/* bit 0/1 = coin counters */
299 		machine().bookkeeping().coin_counter_w(0, data & 0x01);
300 		machine().bookkeeping().coin_counter_w(1, data & 0x02);  /* 2 players version */
301 
302 		/* bit 3 high then low triggers irq on sound CPU */
303 		if (m_last == 0x08 && (data & 0x08) == 0)
304 			m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff); // Z80
305 
306 		m_last = data & 0x08;
307 
308 		/* bit 5 = irq enable */
309 		m_irq5_mask = data & 0x20;
310 
311 		/* bit 7 = enable char ROM reading through the video RAM */
312 		m_k052109->set_rmrd_line((data & 0x80) ? ASSERT_LINE : CLEAR_LINE);
313 
314 		/* other bits unused */
315 	}
316 }
317 
punkshot_0a0020_w(offs_t offset,uint16_t data,uint16_t mem_mask)318 void tmnt_state::punkshot_0a0020_w(offs_t offset, uint16_t data, uint16_t mem_mask)
319 {
320 	if (ACCESSING_BITS_0_7)
321 	{
322 		/* bit 0 = coin counter */
323 		machine().bookkeeping().coin_counter_w(0, data & 0x01);
324 
325 		/* bit 2 = trigger irq on sound CPU */
326 		if (m_last == 0x04 && (data & 0x04) == 0)
327 			m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff); // Z80
328 
329 		m_last = data & 0x04;
330 
331 		/* bit 3 = enable char ROM reading through the video RAM */
332 		m_k052109->set_rmrd_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
333 	}
334 }
335 
lgtnfght_0a0018_w(offs_t offset,uint16_t data,uint16_t mem_mask)336 void tmnt_state::lgtnfght_0a0018_w(offs_t offset, uint16_t data, uint16_t mem_mask)
337 {
338 	if (ACCESSING_BITS_0_7)
339 	{
340 		/* bit 0,1 = coin counter */
341 		machine().bookkeeping().coin_counter_w(0, data & 0x01);
342 		machine().bookkeeping().coin_counter_w(1, data & 0x02);
343 
344 		/* bit 2 = trigger irq on sound CPU */
345 		if (m_last == 0x00 && (data & 0x04) == 0x04)
346 			m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff); // Z80
347 
348 		m_last = data & 0x04;
349 
350 		/* bit 3 = enable char ROM reading through the video RAM */
351 		m_k052109->set_rmrd_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
352 	}
353 }
354 
blswhstl_700300_w(offs_t offset,uint16_t data,uint16_t mem_mask)355 void tmnt_state::blswhstl_700300_w(offs_t offset, uint16_t data, uint16_t mem_mask)
356 {
357 	if (ACCESSING_BITS_0_7)
358 	{
359 		/* bit 0,1 = coin counter */
360 		machine().bookkeeping().coin_counter_w(0,data & 0x01);
361 		machine().bookkeeping().coin_counter_w(1,data & 0x02);
362 
363 		/* bit 3 = enable char ROM reading through the video RAM */
364 		m_k052109->set_rmrd_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
365 
366 		/* bit 7 = select char ROM bank */
367 		if (m_blswhstl_rombank != ((data & 0x80) >> 7))
368 		{
369 			m_blswhstl_rombank = (data & 0x80) >> 7;
370 			machine().tilemap().mark_all_dirty();
371 		}
372 
373 		/* other bits unknown */
374 	}
375 }
376 
377 
glfgreat_rom_r(offs_t offset)378 uint16_t glfgreat_state::glfgreat_rom_r(offs_t offset)
379 {
380 	if (m_roz_rom_mode)
381 		return memregion("zoom")->base()[m_roz_char_bank * 0x80000 + offset];
382 	else if (offset < 0x40000)
383 	{
384 		uint8_t *usr = memregion("user1")->base();
385 		return usr[offset + 0x80000 + m_roz_rom_bank * 0x40000] + 256 * usr[offset + m_roz_rom_bank * 0x40000];
386 	}
387 	else
388 		return memregion("user1")->base()[((offset & 0x3ffff) >> 2) + 0x100000 + m_roz_rom_bank * 0x10000];
389 }
390 
glfgreat_122000_w(offs_t offset,uint16_t data,uint16_t mem_mask)391 void glfgreat_state::glfgreat_122000_w(offs_t offset, uint16_t data, uint16_t mem_mask)
392 {
393 	if (ACCESSING_BITS_0_7)
394 	{
395 		/* bit 0,1 = coin counter */
396 		machine().bookkeeping().coin_counter_w(0, data & 0x01);
397 		machine().bookkeeping().coin_counter_w(1, data & 0x02);
398 
399 		m_controller_select = (data & 0x0c) >> 2;
400 
401 		/* bit 4 = enable char ROM reading through the video RAM */
402 		m_k052109->set_rmrd_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
403 
404 		/* bit 5 = 53596 tile rom bank selection */
405 		if (m_roz_rom_bank != (data & 0x20) >> 5)
406 		{
407 			m_roz_rom_bank = (data & 0x20) >> 5;
408 			m_roz_tilemap->mark_all_dirty();
409 		}
410 
411 		/* bit 6,7 = 53596 char bank selection for ROM test */
412 		m_roz_char_bank = (data & 0xc0) >> 6;
413 	}
414 	if (ACCESSING_BITS_8_15)
415 	{
416 		/* bit 8 = 53596 char/rom selection for ROM test */
417 		m_roz_rom_mode = data & 0x100;
418 	}
419 }
420 
421 
ssriders_eeprom_w(offs_t offset,uint16_t data,uint16_t mem_mask)422 void tmnt_state::ssriders_eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask)
423 {
424 	if (ACCESSING_BITS_0_7)
425 	{
426 		/* bit 0 is data */
427 		/* bit 1 is cs (active low) */
428 		/* bit 2 is clock (active high) */
429 		ioport("EEPROMOUT")->write(data, 0xff);
430 
431 		/* bits 3-4 control palette dimming */
432 		/* 4 = DIMPOL = when set, negate SHAD */
433 		/* 3 = DIMMOD = when set, or BRIT with [negated] SHAD */
434 		m_dim_c = data & 0x18;
435 
436 		/* bit 5 selects sprite ROM for testing in TMNT2 (bits 5-7, actually, according to the schematics) */
437 		m_k053245->bankselect(((data & 0x20) >> 5) << 2);
438 	}
439 }
440 
ssriders_1c0300_w(offs_t offset,uint16_t data,uint16_t mem_mask)441 void tmnt_state::ssriders_1c0300_w(offs_t offset, uint16_t data, uint16_t mem_mask)
442 {
443 	if (ACCESSING_BITS_0_7)
444 	{
445 		/* bit 0,1 = coin counter */
446 		machine().bookkeeping().coin_counter_w(0, data & 0x01);
447 		machine().bookkeeping().coin_counter_w(1, data & 0x02);
448 
449 		/* bit 3 = enable char ROM reading through the video RAM */
450 		m_k052109->set_rmrd_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
451 
452 		/* bits 4-6 control palette dimming (DIM0-DIM2) */
453 		m_dim_v = (data & 0x70) >> 4;
454 	}
455 }
456 
prmrsocr_122000_w(offs_t offset,uint16_t data,uint16_t mem_mask)457 void prmrsocr_state::prmrsocr_122000_w(offs_t offset, uint16_t data, uint16_t mem_mask)
458 {
459 	if (ACCESSING_BITS_0_7)
460 	{
461 		/* bit 0,1 = coin counter */
462 		machine().bookkeeping().coin_counter_w(0, data & 0x01);
463 		machine().bookkeeping().coin_counter_w(1, data & 0x02);
464 
465 		/* bit 4 = enable char ROM reading through the video RAM */
466 		m_k052109->set_rmrd_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
467 
468 		/* bit 6 = sprite ROM bank */
469 		m_sprite_bank = (data & 0x40) >> 6;
470 		m_k053245->bankselect(m_sprite_bank << 2);
471 
472 		/* bit 7 = 53596 region selector for ROM test */
473 		m_roz_char_bank = (data & 0x80) >> 7;
474 
475 		/* other bits unknown (unused?) */
476 	}
477 }
478 
prmrsocr_rom_r(offs_t offset)479 uint16_t prmrsocr_state::prmrsocr_rom_r(offs_t offset)
480 {
481 	if(m_roz_char_bank)
482 		return memregion("zoom")->base()[offset];
483 	else
484 	{
485 		uint8_t *usr = memregion("user1")->base();
486 		return 256 * usr[offset] + usr[offset + 0x020000];
487 	}
488 }
489 
tmnt_priority_w(offs_t offset,uint16_t data,uint16_t mem_mask)490 void tmnt_state::tmnt_priority_w(offs_t offset, uint16_t data, uint16_t mem_mask)
491 {
492 	if (ACCESSING_BITS_0_7)
493 	{
494 		/* bit 2/3 = priority; other bits unused */
495 		/* bit2 = PRI bit3 = PRI2
496 		      sprite/playfield priority is controlled by these two bits, by bit 3
497 		      of the background tile color code, and by the SHADOW sprite
498 		      attribute bit.
499 		      Priorities are encoded in a PROM (G19 for TMNT). However, in TMNT,
500 		      the PROM only takes into account the PRI and SHADOW bits.
501 		      PRI  Priority
502 		       0   bg fg spr text
503 		       1   bg spr fg text
504 		      The SHADOW bit, when set, torns a sprite into a shadow which makes
505 		      color below it darker (this is done by turning off three resistors
506 		      in parallel with the RGB output).
507 
508 		      Note: the background color (color used when all of the four layers
509 		      are 0) is taken from the *foreground* palette, not the background
510 		      one as would be more intuitive.
511 		*/
512 		m_tmnt_priorityflag = (data & 0x0c) >> 2;
513 	}
514 }
515 
516 
517 
518 /***************************************************************************
519 
520   Display refresh
521 
522 ***************************************************************************/
523 
screen_update_mia(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)524 uint32_t tmnt_state::screen_update_mia(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
525 {
526 	m_k052109->tilemap_update();
527 
528 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 2, TILEMAP_DRAW_OPAQUE,0);
529 	if ((m_tmnt_priorityflag & 1) == 1) m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), 0, 0);
530 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 1, 0, 0);
531 	if ((m_tmnt_priorityflag & 1) == 0) m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), 0, 0);
532 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 0, 0, 0);
533 
534 	return 0;
535 }
536 
screen_update_tmnt(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)537 uint32_t tmnt_state::screen_update_tmnt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
538 {
539 	m_k052109->tilemap_update();
540 
541 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 2, TILEMAP_DRAW_OPAQUE,0);
542 	if ((m_tmnt_priorityflag & 1) == 1) m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), 0, 0);
543 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 1, 0, 0);
544 	if ((m_tmnt_priorityflag & 1) == 0) m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), 0, 0);
545 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 0, 0, 0);
546 
547 	return 0;
548 }
549 
550 
screen_update_punkshot(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)551 uint32_t tmnt_state::screen_update_punkshot(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
552 {
553 	m_sprite_colorbase = m_k053251->get_palette_index(k053251_device::CI1);
554 	m_layer_colorbase[0] = m_k053251->get_palette_index(k053251_device::CI2);
555 	m_layer_colorbase[1] = m_k053251->get_palette_index(k053251_device::CI4);
556 	m_layer_colorbase[2] = m_k053251->get_palette_index(k053251_device::CI3);
557 
558 	m_k052109->tilemap_update();
559 
560 	m_sorted_layer[0] = 0;
561 	m_layerpri[0] = m_k053251->get_priority(k053251_device::CI2);
562 	m_sorted_layer[1] = 1;
563 	m_layerpri[1] = m_k053251->get_priority(k053251_device::CI4);
564 	m_sorted_layer[2] = 2;
565 	m_layerpri[2] = m_k053251->get_priority(k053251_device::CI3);
566 
567 	konami_sortlayers3(m_sorted_layer, m_layerpri);
568 
569 	screen.priority().fill(0, cliprect);
570 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[0], TILEMAP_DRAW_OPAQUE, 1);
571 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[1], 0, 2);
572 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[2], 0, 4);
573 
574 	m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), -1, -1);
575 	return 0;
576 }
577 
578 
screen_update_lgtnfght(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)579 uint32_t tmnt_state::screen_update_lgtnfght(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
580 {
581 	int bg_colorbase;
582 
583 	bg_colorbase = m_k053251->get_palette_index(k053251_device::CI0);
584 	m_sprite_colorbase = m_k053251->get_palette_index(k053251_device::CI1);
585 	m_layer_colorbase[0] = m_k053251->get_palette_index(k053251_device::CI2);
586 	m_layer_colorbase[1] = m_k053251->get_palette_index(k053251_device::CI4);
587 	m_layer_colorbase[2] = m_k053251->get_palette_index(k053251_device::CI3);
588 
589 	m_k052109->tilemap_update();
590 
591 	m_sorted_layer[0] = 0;
592 	m_layerpri[0] = m_k053251->get_priority(k053251_device::CI2);
593 	m_sorted_layer[1] = 1;
594 	m_layerpri[1] = m_k053251->get_priority(k053251_device::CI4);
595 	m_sorted_layer[2] = 2;
596 	m_layerpri[2] = m_k053251->get_priority(k053251_device::CI3);
597 
598 	konami_sortlayers3(m_sorted_layer, m_layerpri);
599 
600 	screen.priority().fill(0, cliprect);
601 	bitmap.fill(16 * bg_colorbase, cliprect);
602 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[0], 0, 1);
603 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[1], 0, 2);
604 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[2], 0, 4);
605 
606 	m_k053245->sprites_draw(bitmap, cliprect, screen.priority());
607 	return 0;
608 }
609 
610 
glfgreat_ball_r()611 uint16_t glfgreat_state::glfgreat_ball_r()
612 {
613 #ifdef MAME_DEBUG
614 popmessage("%04x", m_glfgreat_pixel);
615 #endif
616 	/* if out of the ROZ layer palette range, it's in the water - return 0 */
617 	if (m_glfgreat_pixel < 0x400 || m_glfgreat_pixel >= 0x500)
618 		return 0;
619 	else
620 		return m_glfgreat_pixel & 0xff;
621 }
622 
screen_update_glfgreat(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)623 uint32_t tmnt_state::screen_update_glfgreat(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
624 {
625 	int bg_colorbase;
626 
627 	bg_colorbase = m_k053251->get_palette_index(k053251_device::CI0);
628 	m_sprite_colorbase  = m_k053251->get_palette_index(k053251_device::CI1);
629 	m_layer_colorbase[0] = m_k053251->get_palette_index(k053251_device::CI2);
630 	m_layer_colorbase[1] = m_k053251->get_palette_index(k053251_device::CI3) + 8;   /* weird... */
631 	m_layer_colorbase[2] = m_k053251->get_palette_index(k053251_device::CI4);
632 
633 	m_k052109->tilemap_update();
634 
635 	m_sorted_layer[0] = 0;
636 	m_layerpri[0] = m_k053251->get_priority(k053251_device::CI2);
637 	m_sorted_layer[1] = 1;
638 	m_layerpri[1] = m_k053251->get_priority(k053251_device::CI3);
639 	m_sorted_layer[2] = 2;
640 	m_layerpri[2] = m_k053251->get_priority(k053251_device::CI4);
641 
642 	konami_sortlayers3(m_sorted_layer, m_layerpri);
643 
644 	/* not sure about the 053936 priority, but it seems to work */
645 
646 	screen.priority().fill(0, cliprect);
647 	bitmap.fill(16 * bg_colorbase, cliprect);
648 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[0], 0, 1);
649 
650 	if (m_layerpri[0] >= 0x30 && m_layerpri[1] < 0x30)
651 	{
652 		m_k053936->zoom_draw(screen, bitmap, cliprect, m_roz_tilemap, 0, 1, 1);
653 		m_glfgreat_pixel = bitmap.pix(0x80, 0x105);
654 	}
655 
656 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[1], 0, 2);
657 
658 	if (m_layerpri[1] >= 0x30 && m_layerpri[2] < 0x30)
659 	{
660 		m_k053936->zoom_draw(screen, bitmap, cliprect, m_roz_tilemap, 0, 1, 1);
661 		m_glfgreat_pixel = bitmap.pix(0x80, 0x105);
662 	}
663 
664 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[2], 0, 4);
665 
666 	if (m_layerpri[2] >= 0x30)
667 	{
668 		m_k053936->zoom_draw(screen, bitmap, cliprect, m_roz_tilemap, 0, 1, 1);
669 		m_glfgreat_pixel = bitmap.pix(0x80, 0x105);
670 	}
671 
672 	m_k053245->sprites_draw(bitmap, cliprect, screen.priority());
673 	return 0;
674 }
675 
screen_update_tmnt2(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)676 uint32_t tmnt_state::screen_update_tmnt2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
677 {
678 	double brt;
679 	int i, newdim, newen, cb, ce;
680 
681 	newdim = m_dim_v | ((~m_dim_c & 0x10) >> 1);
682 	newen  = (m_k053251->get_priority(5) && m_k053251->get_priority(5) != 0x3e);
683 
684 	if (newdim != m_lastdim || newen != m_lasten)
685 	{
686 		brt = 1.0;
687 		if (newen)
688 			brt -= (1.0 - PALETTE_DEFAULT_SHADOW_FACTOR) * newdim / 8;
689 		m_lastdim = newdim;
690 		m_lasten = newen;
691 
692 		/*
693 		    Only affect the background and sprites, not text layer.
694 		    Instead of dimming each layer we dim the entire palette
695 		    except text colors because palette bases may change
696 		    anytime and there's no guarantee a dimmed color will be
697 		    reset properly.
698 		*/
699 
700 		// find the text layer's palette range
701 		cb = m_layer_colorbase[m_sorted_layer[2]] << 4;
702 		ce = cb + 128;
703 
704 		// dim all colors before it
705 		for (i = 0; i < cb; i++)
706 			m_palette->set_pen_contrast(i, brt);
707 
708 		// reset all colors in range
709 		for (i = cb; i < ce; i++)
710 			m_palette->set_pen_contrast(i, 1.0);
711 
712 		// dim all colors after it
713 		for (i = ce; i < 2048; i++)
714 			m_palette->set_pen_contrast(i, brt);
715 
716 		// toggle shadow/highlight
717 		if (~m_dim_c & 0x10)
718 			m_palette->set_shadow_mode(1);
719 		else
720 			m_palette->set_shadow_mode(0);
721 	}
722 
723 	screen_update_lgtnfght(screen, bitmap, cliprect);
724 	return 0;
725 }
726 
727 
screen_update_thndrx2(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)728 uint32_t tmnt_state::screen_update_thndrx2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
729 {
730 	int bg_colorbase;
731 
732 	bg_colorbase = m_k053251->get_palette_index(k053251_device::CI0);
733 	m_sprite_colorbase = m_k053251->get_palette_index(k053251_device::CI1);
734 	m_layer_colorbase[0] = m_k053251->get_palette_index(k053251_device::CI2);
735 	m_layer_colorbase[1] = m_k053251->get_palette_index(k053251_device::CI4);
736 	m_layer_colorbase[2] = m_k053251->get_palette_index(k053251_device::CI3);
737 
738 	m_k052109->tilemap_update();
739 
740 	m_sorted_layer[0] = 0;
741 	m_layerpri[0] = m_k053251->get_priority(k053251_device::CI2);
742 	m_sorted_layer[1] = 1;
743 	m_layerpri[1] = m_k053251->get_priority(k053251_device::CI4);
744 	m_sorted_layer[2] = 2;
745 	m_layerpri[2] = m_k053251->get_priority(k053251_device::CI3);
746 
747 	konami_sortlayers3(m_sorted_layer, m_layerpri);
748 
749 	screen.priority().fill(0, cliprect);
750 	bitmap.fill(16 * bg_colorbase, cliprect);
751 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[0], 0, 1);
752 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[1], 0, 2);
753 	m_k052109->tilemap_draw(screen, bitmap, cliprect, m_sorted_layer[2], 0, 4);
754 
755 	m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), -1, -1);
756 	return 0;
757 }
758 
759 
760 
761 /***************************************************************************
762 
763   Housekeeping
764 
765 ***************************************************************************/
766 
WRITE_LINE_MEMBER(tmnt_state::screen_vblank_blswhstl)767 WRITE_LINE_MEMBER(tmnt_state::screen_vblank_blswhstl)
768 {
769 	// on rising edge
770 	if (state)
771 	{
772 		m_k053245->clear_buffer();
773 	}
774 }
775