1 // license:BSD-3-Clause
2 // copyright-holders:Roberto Fresca
3 /****************************************************************************************
4
5 LUCKY 74 - WING CO.,LTD.
6 ------------------------
7
8 *** VIDEO HARDWARE ***
9
10
11 Written by Roberto Fresca.
12
13
14 Games running on this hardware:
15
16 * Lucky 74 (bootleg, set 1), 1988, Wing Co.,Ltd.
17 * Lucky 74 (bootleg, set 2), 1988, Wing Co.,Ltd.
18
19
20 *****************************************************************************************
21
22
23 Color Circuitry
24 ---------------
25
26 Here is a little diagram showing how the color PROMs are connected to a 74174
27 and therefore to a resistor network that derives to the RGB connector.
28
29
30 220
31 (E6)24s10-12 -+- 74174-02 ---/\/\/\----+
32 (E7)24s10-12 _| |
33 470 |
34 (E6)24s10-11 -+- 74174-10 ---/\/\/\----+
35 (E7)24s10-11 _| |
36 1K |
37 (E6)24s10-10 -+- 74174-12 ---/\/\/\----+
38 (E7)24s10-10 _| |
39 2K |
40 (E6)24s10-09 -+- 74174-15 ---/\/\/\----+---> Red
41 (E7)24s10-09 _| |
42 /
43 1K \
44 /
45 |
46 _
47
48 220
49 (D6)24s10-12 -+- 74174-02 ---/\/\/\----+
50 (D7)24s10-12 _| |
51 470 |
52 (D6)24s10-11 -+- 74174-10 ---/\/\/\----+
53 (D7)24s10-11 _| |
54 1K |
55 (D6)24s10-10 -+- 74174-12 ---/\/\/\----+
56 (D7)24s10-10 _| |
57 2K |
58 (D6)24s10-09 -+- 74174-15 ---/\/\/\----+---> Green
59 (D7)24s10-09 _| |
60 /
61 1K \
62 /
63 |
64 _
65
66 220
67 (C6)24s10-12 -+- 74174-02 ---/\/\/\----+
68 (C7)24s10-12 _| |
69 470 |
70 (C6)24s10-11 -+- 74174-10 ---/\/\/\----+
71 (C7)24s10-11 _| |
72 1K |
73 (C6)24s10-10 -+- 74174-12 ---/\/\/\----+
74 (C7)24s10-10 _| |
75 2K |
76 (C6)24s10-09 -+- 74174-15 ---/\/\/\----+---> Blue
77 (C7)24s10-09 _| |
78 /
79 1K \
80 /
81 |
82 _
83
84
85 Regarding the above diagram, there are 2 different states controlled by both 06B53P.
86 Each state arrange a different palette that will be assigned to each graphics bank.
87
88 As we can see here, same pin of different PROMs are connected together in parallel.
89
90 To reproduce the states, we need to create a double-sized palette and fill the first
91 half with the values created through state 1, then fill the second half with proper
92 values from state 2.
93
94
95 ****************************************************************************************/
96
97
98 #include "emu.h"
99 #include "video/resnet.h"
100 #include "includes/lucky74.h"
101
102
fg_videoram_w(offs_t offset,uint8_t data)103 void lucky74_state::fg_videoram_w(offs_t offset, uint8_t data)
104 {
105 m_fg_videoram[offset] = data;
106 m_fg_tilemap->mark_tile_dirty(offset);
107 }
108
fg_colorram_w(offs_t offset,uint8_t data)109 void lucky74_state::fg_colorram_w(offs_t offset, uint8_t data)
110 {
111 m_fg_colorram[offset] = data;
112 m_fg_tilemap->mark_tile_dirty(offset);
113 }
114
bg_videoram_w(offs_t offset,uint8_t data)115 void lucky74_state::bg_videoram_w(offs_t offset, uint8_t data)
116 {
117 m_bg_videoram[offset] = data;
118 m_bg_tilemap->mark_tile_dirty(offset);
119 }
120
bg_colorram_w(offs_t offset,uint8_t data)121 void lucky74_state::bg_colorram_w(offs_t offset, uint8_t data)
122 {
123 m_bg_colorram[offset] = data;
124 m_bg_tilemap->mark_tile_dirty(offset);
125 }
126
127
palette(palette_device & palette) const128 void lucky74_state::palette(palette_device &palette) const
129 {
130 // There are 2 states (see the technical notes).
131 // We're constructing a double-sized palette with one half for each state.
132 uint8_t const *const color_prom = memregion("proms")->base();
133 static constexpr int resistances_rgb[4] = { 2000, 1000, 470, 220 };
134
135 double weights_r[4], weights_g[4], weights_b[4];
136 compute_resistor_weights(0, 255, -1.0,
137 4, resistances_rgb, weights_r, 1000, 0,
138 4, resistances_rgb, weights_g, 1000, 0,
139 4, resistances_rgb, weights_b, 1000, 0);
140
141 for (int i = 0; i < 256; i++)
142 {
143 int bit0, bit1, bit2, bit3;
144
145 // red component (this 1, PROM E6)
146 bit0 = BIT(color_prom[0x000 + i], 0);
147 bit1 = BIT(color_prom[0x000 + i], 1);
148 bit2 = BIT(color_prom[0x000 + i], 2);
149 bit3 = BIT(color_prom[0x000 + i], 3);
150 int const r1 = combine_weights(weights_r, bit0, bit1, bit2, bit3);
151
152 // red component (this 2, PROM E7)
153 bit0 = BIT(color_prom[0x100 + i], 0);
154 bit1 = BIT(color_prom[0x100 + i], 1);
155 bit2 = BIT(color_prom[0x100 + i], 2);
156 bit3 = BIT(color_prom[0x100 + i], 3);
157 int const r2 = combine_weights(weights_r, bit0, bit1, bit2, bit3);
158
159 // green component (this 1, PROM D6)
160 bit0 = BIT(color_prom[0x200 + i], 0);
161 bit1 = BIT(color_prom[0x200 + i], 1);
162 bit2 = BIT(color_prom[0x200 + i], 2);
163 bit3 = BIT(color_prom[0x200 + i], 3);
164 int const g1 = combine_weights(weights_g, bit0, bit1, bit2, bit3);
165
166 // green component (this 2, PROM D7)
167 bit0 = BIT(color_prom[0x300 + i], 0);
168 bit1 = BIT(color_prom[0x300 + i], 1);
169 bit2 = BIT(color_prom[0x300 + i], 2);
170 bit3 = BIT(color_prom[0x300 + i], 3);
171 int const g2 = combine_weights(weights_g, bit0, bit1, bit2, bit3);
172
173 // blue component (this 1, PROM C6)
174 bit0 = BIT(color_prom[0x400 + i], 0);
175 bit1 = BIT(color_prom[0x400 + i], 1);
176 bit2 = BIT(color_prom[0x400 + i], 2);
177 bit3 = BIT(color_prom[0x400 + i], 3);
178 int const b1 = combine_weights(weights_b, bit0, bit1, bit2, bit3);
179
180 // blue component (this 2, PROM C7)
181 bit0 = BIT(color_prom[0x500 + i], 0);
182 bit1 = BIT(color_prom[0x500 + i], 1);
183 bit2 = BIT(color_prom[0x500 + i], 2);
184 bit3 = BIT(color_prom[0x500 + i], 3);
185 int const b2 = combine_weights(weights_b, bit0, bit1, bit2, bit3);
186
187
188 // PROMs circuitry, 1st state
189 palette.set_pen_color(i, rgb_t(r1, g1, b1));
190
191 // PROMs circuitry, 2nd state
192 palette.set_pen_color(i + 256, rgb_t(r2, g2, b2));
193 }
194 }
195
196
TILE_GET_INFO_MEMBER(lucky74_state::get_fg_tile_info)197 TILE_GET_INFO_MEMBER(lucky74_state::get_fg_tile_info)
198 {
199 /* - bits -
200 7654 3210
201 ---- xxxx tiles color.
202 xxxx ---- tiles page offset.
203 */
204 int bank = 0;
205 int attr = m_fg_colorram[tile_index];
206 int code = m_fg_videoram[tile_index] + ((attr & 0xf0) << 4);
207 int color = (attr & 0x0f);
208
209 tileinfo.set(bank, code, color, 0);
210 }
211
TILE_GET_INFO_MEMBER(lucky74_state::get_bg_tile_info)212 TILE_GET_INFO_MEMBER(lucky74_state::get_bg_tile_info)
213 {
214 /* - bits -
215 7654 3210
216 ---- xxxx tiles color.
217 xxxx ---- tiles page offset.
218 */
219 int bank = 1;
220 int attr = m_bg_colorram[tile_index];
221 int code = m_bg_videoram[tile_index] + ((attr & 0xf0) << 4);
222 int color = (attr & 0x0f);
223
224 tileinfo.set(bank, code, color, 0);
225 }
226
227
video_start()228 void lucky74_state::video_start()
229 {
230 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(lucky74_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64, 32);
231 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(lucky74_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64, 32);
232
233 m_fg_tilemap->set_transparent_pen(0);
234 }
235
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)236 uint32_t lucky74_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
237 {
238 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
239 m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
240 return 0;
241 }
242