1 #include "driver.h"
2 #include "state.h"
3 #include "vidhrdw/generic.h"
4 #include "vidhrdw/taitoic.h"
5 
6 static struct mame_bitmap* pixel_layer = 0;
7 
8 static UINT16* video_ram = NULL;
9 
10 static UINT16 video_ctrl = 0;
11 static UINT16 video_mask = 0;
12 
13 static UINT8* line_dirty = NULL;
14 
mark_all_dirty(void)15 static void mark_all_dirty(void)
16 {
17 	memset(line_dirty, 1, 256);
18 }
19 
20 
21 /******************************************************
22           INITIALISATION AND CLEAN-UP
23 ******************************************************/
24 
VIDEO_START(volfied)25 VIDEO_START( volfied )
26 {
27 	pixel_layer = auto_bitmap_alloc(Machine->drv->screen_width, Machine->drv->screen_height);
28 	if (pixel_layer == NULL)
29 		return 1;
30 
31 	line_dirty = auto_malloc(256);
32 	if (line_dirty == NULL)
33 		return 1;
34 
35 	video_ram = auto_malloc(0x40000 * sizeof (UINT16));
36 	if (video_ram == NULL)
37 		return 1;
38 
39 	state_save_register_UINT16("volfied", 0, "video_ram",   video_ram,    0x40000);
40 	state_save_register_UINT16("volfied", 0, "video_ctrl",  &video_ctrl,  1);
41 	state_save_register_UINT16("volfied", 0, "video_mask",  &video_mask,  1);
42 
43 	state_save_register_func_postload (mark_all_dirty);
44 
45 	return PC090OJ_vh_start(0, 0, 0, 0);
46 }
47 
48 
49 /*******************************************************
50           READ AND WRITE HANDLERS
51 *******************************************************/
52 
READ16_HANDLER(volfied_video_ram_r)53 READ16_HANDLER( volfied_video_ram_r )
54 {
55 	return video_ram[offset];
56 }
57 
WRITE16_HANDLER(volfied_video_ram_w)58 WRITE16_HANDLER( volfied_video_ram_w )
59 {
60 	mem_mask |= ~video_mask;
61 
62 	line_dirty[(offset >> 9) & 0xff] = 1;
63 
64 	COMBINE_DATA(&video_ram[offset]);
65 }
66 
WRITE16_HANDLER(volfied_video_ctrl_w)67 WRITE16_HANDLER( volfied_video_ctrl_w )
68 {
69 	if (ACCESSING_LSB && (data & 1) != (video_ctrl & 1))
70 	{
71 		mark_all_dirty();    /* screen switch */
72 	}
73 
74 	COMBINE_DATA(&video_ctrl);
75 }
76 
READ16_HANDLER(volfied_video_ctrl_r)77 READ16_HANDLER( volfied_video_ctrl_r )
78 {
79 	/* Could this be some kind of hardware collision detection? If bit 6 is
80 	   set the game will check for collisions with the large enemy, whereas
81 	   bit 5 does the same for small enemies. Bit 7 is also used although
82 	   its purpose is unclear. This register is usually read during a VBI
83 	   and stored in work RAM for later use. */
84 
85 	return 0x60;
86 }
87 
WRITE16_HANDLER(volfied_video_mask_w)88 WRITE16_HANDLER( volfied_video_mask_w )
89 {
90 	COMBINE_DATA(&video_mask);
91 }
92 
WRITE16_HANDLER(volfied_sprite_ctrl_w)93 WRITE16_HANDLER( volfied_sprite_ctrl_w )
94 {
95 	PC090OJ_sprite_ctrl = (data & 0x3c) >> 2;
96 }
97 
98 
99 /*******************************************************
100 				SCREEN REFRESH
101 *******************************************************/
102 
refresh_pixel_layer(void)103 static void refresh_pixel_layer(void)
104 {
105 	int x, y;
106 
107 	/*********************************************************
108 
109 	VIDEO RAM has 2 screens x 256 rows x 512 columns x 16 bits
110 
111 	x---------------  select image
112 	-x--------------  ?             (used for 3-D corners)
113 	--x-------------  ?             (used for 3-D walls)
114 	---xxxx---------  image B
115 	-------xxx------  palette index bits #8 to #A
116 	----------x-----  ?
117 	-----------x----  ?
118 	------------xxxx  image A
119 
120 	*********************************************************/
121 
122 	UINT16* p = video_ram;
123 
124 	if (video_ctrl & 1)
125 	{
126 		p += 0x20000;
127 	}
128 
129 	for (y = 0; y < Machine->drv->screen_height; y++)
130 	{
131 		if (line_dirty[y])
132 		{
133 			for (x = 0; x < Machine->drv->screen_width; x++)
134 			{
135 				int color = (p[x] << 2) & 0x700;
136 
137 				if (p[x] & 0x8000)
138 				{
139 					color |= 0x800 | ((p[x] >> 9) & 0xf);
140 
141 					if (p[x] & 0x2000)
142 					{
143 						color &= ~0xf;	  /* hack */
144 					}
145 				}
146 				else
147 				{
148 					color |= p[x] & 0xf;
149 				}
150 
151 				plot_pixel(pixel_layer, x, y, Machine->pens[color]);
152 			}
153 
154 			line_dirty[y] = 0;
155 		}
156 
157 		p += 512;
158 	}
159 }
160 
VIDEO_UPDATE(volfied)161 VIDEO_UPDATE( volfied )
162 {
163 	fillbitmap(priority_bitmap, 0, cliprect);
164 
165 	refresh_pixel_layer();
166 
167 	copybitmap(bitmap, pixel_layer, 0, 0, 0, 0, cliprect, TRANSPARENCY_NONE, 0);
168 
169 	PC090OJ_draw_sprites(bitmap, cliprect, 0);
170 }
171