1 #include "driver.h"
2 #include "tilemap.h"
3 #include "vidhrdw/generic.h"
4 #include "vidhrdw/konamiic.h"
5 
6 #define SPRITEROM_MEM_REGION REGION_GFX1
7 #define ZOOMROM0_MEM_REGION REGION_GFX2
8 #define ZOOMROM1_MEM_REGION REGION_GFX3
9 #define ZOOMROM2_MEM_REGION REGION_GFX4
10 
11 static int sprite_colorbase, zoom_colorbase[3];
12 
13 extern unsigned char* ultraman_regs;
14 
15 /***************************************************************************
16 
17   Callbacks for the K051960
18 
19 ***************************************************************************/
20 
sprite_callback(int * code,int * color,int * priority,int * shadow)21 static void sprite_callback(int *code,int *color,int *priority,int *shadow)
22 {
23 	*priority = (*color & 0x80) >> 7;
24 	*color = sprite_colorbase + ((*color & 0x7e) >> 1);
25 }
26 
27 
28 /***************************************************************************
29 
30   Callbacks for the K051316
31 
32 ***************************************************************************/
33 
zoom_callback_0(int * code,int * color)34 static void zoom_callback_0(int *code,int *color)
35 {
36 	unsigned short data = READ_WORD(&ultraman_regs[0x18]);
37 	*code |= ((*color & 0x07) << 8) | (data & 0x02) << 10;
38 	*color = zoom_colorbase[0] + ((*color & 0xf8) >> 3);
39 }
40 
zoom_callback_1(int * code,int * color)41 static void zoom_callback_1(int *code,int *color)
42 {
43 	unsigned short data = READ_WORD(&ultraman_regs[0x18]);
44 	*code |= ((*color & 0x07) << 8) | (data & 0x08) << 8;
45 	*color = zoom_colorbase[1] + ((*color & 0xf8) >> 3);
46 }
47 
zoom_callback_2(int * code,int * color)48 static void zoom_callback_2(int *code,int *color)
49 {
50 	unsigned short data = READ_WORD(&ultraman_regs[0x18]);
51 	*code |= ((*color & 0x07) << 8) | (data & 0x20) << 6;
52 	*color = zoom_colorbase[2] + ((*color & 0xf8) >> 3);
53 }
54 
55 
56 
57 /***************************************************************************
58 
59 	Start the video hardware emulation.
60 
61 ***************************************************************************/
62 
ultraman_vh_start(void)63 int ultraman_vh_start(void)
64 {
65 	sprite_colorbase = 192;
66 	zoom_colorbase[0] = 0;
67 	zoom_colorbase[1] = 64;
68 	zoom_colorbase[2] = 128;
69 
70 	if (K051960_vh_start(SPRITEROM_MEM_REGION,NORMAL_PLANE_ORDER,sprite_callback))
71 	{
72 		return 1;
73 	}
74 
75 	if (K051316_vh_start_0(ZOOMROM0_MEM_REGION,4,zoom_callback_0))
76 	{
77 		K051960_vh_stop();
78 		return 1;
79 	}
80 
81 	if (K051316_vh_start_1(ZOOMROM1_MEM_REGION,4,zoom_callback_1))
82 	{
83 		K051960_vh_stop();
84 		K051316_vh_stop_0();
85 		return 1;
86 	}
87 
88 	if (K051316_vh_start_2(ZOOMROM2_MEM_REGION,4,zoom_callback_2))
89 	{
90 		K051960_vh_stop();
91 		K051316_vh_stop_0();
92 		K051316_vh_stop_1();
93 		return 1;
94 	}
95 
96 	K051316_set_offset(0, 8, 0);
97 	K051316_set_offset(1, 8, 0);
98 	K051316_set_offset(2, 8, 0);
99 
100 	return 0;
101 }
102 
ultraman_vh_stop(void)103 void ultraman_vh_stop(void)
104 {
105 	K051960_vh_stop();
106 	K051316_vh_stop_0();
107 	K051316_vh_stop_1();
108 	K051316_vh_stop_2();
109 }
110 
111 
112 
113 /***************************************************************************
114 
115 	Display Refresh
116 
117 ***************************************************************************/
118 
ultraman_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)119 void ultraman_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
120 {
121 	int i;
122 
123 	K051316_tilemap_update_0();
124 	K051316_tilemap_update_1();
125 	K051316_tilemap_update_2();
126 
127 	palette_init_used_colors();
128 	K051960_mark_sprites_colors();
129 
130 	/* set transparent pens for the K051316 */
131 	for (i = 0;i < 64;i++)
132 	{
133 		palette_used_colors[(zoom_colorbase[0] + i) * 16] = PALETTE_COLOR_TRANSPARENT;
134 		palette_used_colors[(zoom_colorbase[1] + i) * 16] = PALETTE_COLOR_TRANSPARENT;
135 		palette_used_colors[(zoom_colorbase[2] + i) * 16] = PALETTE_COLOR_TRANSPARENT;
136 	}
137 
138 	if (palette_recalc())
139 		tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
140 
141 	tilemap_render(ALL_TILEMAPS);
142 
143 	fillbitmap(bitmap,Machine->pens[zoom_colorbase[2] * 16],&Machine->visible_area);
144 
145 	K051316_zoom_draw_2(bitmap,0);
146 	K051316_zoom_draw_1(bitmap,0);
147 	K051960_sprites_draw(bitmap,0,0);
148 	K051316_zoom_draw_0(bitmap,0);
149 	K051960_sprites_draw(bitmap,1,1);
150 }
151