1 /***************************************************************************
2 
3   vidhrdw.c
4 
5   Functions to emulate the video hardware of the machine.
6 
7 ***************************************************************************/
8 
9 #include "driver.h"
10 #include "vidhrdw/generic.h"
11 #include "cpu/m6809/m6809.h"
12 
13 
14 static int flipscreen;
15 static int nmi_enable;
16 
17 
18 /***************************************************************************
19 
20   Convert the color PROMs into a more useable format.
21 
22   Yie Ar Kung-Fu has one 32x8 palette PROM, connected to the RGB output this
23   way:
24 
25   bit 7 -- 220 ohm resistor  -- BLUE
26         -- 470 ohm resistor  -- BLUE
27         -- 220 ohm resistor  -- GREEN
28         -- 470 ohm resistor  -- GREEN
29         -- 1  kohm resistor  -- GREEN
30         -- 220 ohm resistor  -- RED
31         -- 470 ohm resistor  -- RED
32   bit 0 -- 1  kohm resistor  -- RED
33 
34 ***************************************************************************/
yiear_vh_convert_color_prom(unsigned char * palette,unsigned short * colortable,const unsigned char * color_prom)35 void yiear_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
36 {
37 	int i;
38 
39 
40 	for (i = 0;i < Machine->drv->total_colors;i++)
41 	{
42 		int bit0,bit1,bit2;
43 
44 		/* red component */
45 		bit0 = (*color_prom >> 0) & 0x01;
46 		bit1 = (*color_prom >> 1) & 0x01;
47 		bit2 = (*color_prom >> 2) & 0x01;
48 		*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
49 
50 		/* green component */
51 		bit0 = (*color_prom >> 3) & 0x01;
52 		bit1 = (*color_prom >> 4) & 0x01;
53 		bit2 = (*color_prom >> 5) & 0x01;
54 		*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
55 
56 		/* blue component */
57 		bit0 = 0;
58 		bit1 = (*color_prom >> 6) & 0x01;
59 		bit2 = (*color_prom >> 7) & 0x01;
60 		*(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
61 
62 		color_prom++;
63 	}
64 }
65 
66 
WRITE_HANDLER(yiear_control_w)67 WRITE_HANDLER( yiear_control_w )
68 {
69 	/* bit 0 flips screen */
70 	if (flipscreen != (data & 1))
71 	{
72 		flipscreen = data & 1;
73 		memset(dirtybuffer,1,videoram_size);
74 	}
75 
76 	/* bit 1 is NMI enable */
77 	nmi_enable = data & 0x02;
78 
79 	/* bit 2 is IRQ enable */
80 	interrupt_enable_w(0, data & 0x04);
81 
82 	/* bits 3 and 4 are coin counters */
83 	coin_counter_w(0, (data >> 3) & 0x01);
84 	coin_counter_w(1, (data >> 4) & 0x01);
85 }
86 
87 
yiear_nmi_interrupt(void)88 int yiear_nmi_interrupt(void)
89 {
90 	/* can't use nmi_interrupt() because interrupt_enable_w() effects it */
91 	return nmi_enable ? M6809_INT_NMI : ignore_interrupt();
92 }
93 
94 
95 /***************************************************************************
96 
97   Draw the game screen in the given osd_bitmap.
98   Do NOT call osd_update_display() from this function, it will be called by
99   the main emulation engine.
100 
101 ***************************************************************************/
yiear_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)102 void yiear_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
103 {
104 	int offs;
105 
106 
107 	/* for every character in the Video RAM, check if it has been modified */
108 	/* since last time and update it accordingly. */
109 	for (offs = videoram_size - 2;offs >= 0;offs -= 2)
110 	{
111 		if (dirtybuffer[offs] || dirtybuffer[offs + 1])
112 		{
113 			int sx,sy,flipx,flipy;
114 
115 
116 			dirtybuffer[offs] = dirtybuffer[offs + 1] = 0;
117 
118 			sx = (offs/2) % 32;
119 			sy = (offs/2) / 32;
120 			flipx = videoram[offs] & 0x80;
121 			flipy = videoram[offs] & 0x40;
122 			if (flipscreen)
123 			{
124 				sx = 31 - sx;
125 				sy = 31 - sy;
126 				flipx = !flipx;
127 				flipy = !flipy;
128 			}
129 
130 			drawgfx(tmpbitmap,Machine->gfx[0],
131 				videoram[offs + 1] | ((videoram[offs] & 0x10) << 4),
132 				0,
133 				flipx,flipy,
134 				8*sx,8*sy,
135 				0,TRANSPARENCY_NONE,0);
136 		}
137 	}
138 
139 
140 	/* copy the temporary bitmap to the screen */
141 	copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
142 
143 
144 	/* draw sprites */
145 	for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
146 	{
147 		int sx,sy,flipx,flipy;
148 
149 
150 		sy    =  240 - spriteram[offs + 1];
151 		sx    =  spriteram_2[offs];
152 		flipx = ~spriteram[offs] & 0x40;
153 		flipy =  spriteram[offs] & 0x80;
154 
155 		if (flipscreen)
156 		{
157 			sy = 240 - sy;
158 			flipy = !flipy;
159 		}
160 
161 		if (offs < 0x26)
162 		{
163 			sy++;	/* fix title screen & garbage at the bottom of the screen */
164 		}
165 
166 		drawgfx(bitmap,Machine->gfx[1],
167 			spriteram_2[offs + 1] + 256 * (spriteram[offs] & 1),
168 			0,
169 			flipx,flipy,
170 			sx,sy,
171 			&Machine->visible_area,TRANSPARENCY_PEN,0);
172 	}
173 }
174