1 // license:BSD-3-Clause
2 // copyright-holders:Roberto Fresca
3 /**********************************************************************************
4 
5     SNOOKER 10 / SANDII'
6 
7     Video Hardware.
8     Written by Roberto Fresca.
9 
10 
11 ***********************************************************************************
12 
13     Resistor Network for all PCBs:
14 
15      74LS373
16     .-------.
17     |     02|--> 1  KOhms resistor --> \
18     |     05|--> 470 Ohms resistor -->  > 100 Ohms pull-down resistor --> RED
19     |     06|--> 220 Ohms resistor --> /
20     |       |
21     |     09|--> 1  KOhms resistor --> \
22     |     12|--> 470 Ohms resistor -->  > 100 Ohms pull-down resistor --> BLUE
23     |     15|--> 220 Ohms resistor --> /
24     |       |
25     |     16|--> 470 Ohms resistor --> \  100 Ohms pull-down resistor --> GREEN
26     |     19|--> 220 Ohms resistor --> /
27     '-------'
28 
29 **********************************************************************************/
30 
31 #include "emu.h"
32 #include "video/resnet.h"
33 #include "includes/snookr10.h"
34 
35 
snookr10_videoram_w(offs_t offset,uint8_t data)36 void snookr10_state::snookr10_videoram_w(offs_t offset, uint8_t data)
37 {
38 	m_videoram[offset] = data;
39 	m_bg_tilemap->mark_tile_dirty(offset);
40 }
41 
snookr10_colorram_w(offs_t offset,uint8_t data)42 void snookr10_state::snookr10_colorram_w(offs_t offset, uint8_t data)
43 {
44 	m_colorram[offset] = data;
45 	m_bg_tilemap->mark_tile_dirty(offset);
46 }
47 
48 
snookr10_palette(palette_device & palette) const49 void snookr10_state::snookr10_palette(palette_device &palette) const
50 {
51 	uint8_t const *const color_prom = memregion("proms")->base();
52 	/* GGBBBRRR */
53 
54 	static constexpr int resistances_rb[3] = { 1000, 470, 220 };
55 	static constexpr int resistances_g [2] = { 470, 220 };
56 
57 	double weights_r[3], weights_b[3], weights_g[2];
58 	compute_resistor_weights(0, 255,    -1.0,
59 			3,  resistances_rb, weights_r,  100,    0,
60 			3,  resistances_rb, weights_b,  100,    0,
61 			2,  resistances_g,  weights_g,  100,    0);
62 
63 	for (int i = 0; i < palette.entries(); i++)
64 	{
65 		int bit0, bit1, bit2;
66 
67 		// red component
68 		bit0 = BIT(color_prom[i], 0);
69 		bit1 = BIT(color_prom[i], 1);
70 		bit2 = BIT(color_prom[i], 2);
71 		int const r = combine_weights(weights_r, bit0, bit1, bit2);
72 
73 		// blue component
74 		bit0 = BIT(color_prom[i], 3);
75 		bit1 = BIT(color_prom[i], 4);
76 		bit2 = BIT(color_prom[i], 5);
77 		int const b = combine_weights(weights_b, bit0, bit1, bit2);
78 
79 		// green component
80 		bit0 = BIT(color_prom[i], 6);
81 		bit1 = BIT(color_prom[i], 7);
82 		int const g = combine_weights(weights_g, bit0, bit1);
83 
84 		palette.set_pen_color(i, rgb_t(r, g, b));
85 	}
86 }
87 
TILE_GET_INFO_MEMBER(snookr10_state::get_bg_tile_info)88 TILE_GET_INFO_MEMBER(snookr10_state::get_bg_tile_info)
89 {
90 /*  - bits -
91     7654 3210
92     xxxx ----   tiles color.
93     ---- xxxx   seems unused.
94 */
95 	int offs = tile_index;
96 	int attr = m_videoram[offs] + (m_colorram[offs] << 8);
97 	int code = attr & 0xfff;
98 	int color = m_colorram[offs] >> 4;
99 
100 	tileinfo.set(0, code, color, 0);
101 }
102 
103 
104 /**********************************************************
105 
106   Apple 10 palette and tile matrix / video RAM
107   are encrypted/scrambled.
108 
109   For more information, see the driver notes.
110 
111 **********************************************************/
112 
apple10_palette(palette_device & palette) const113 void snookr10_state::apple10_palette(palette_device &palette) const
114 {
115 	uint8_t const *const color_prom = memregion("proms")->base();
116 	/* GGBBBRRR */
117 
118 	static constexpr int resistances_rb[3] = { 1000, 470, 220 };
119 	static constexpr int resistances_g [2] = { 470, 220 };
120 
121 	double weights_r[3], weights_b[3], weights_g[2];
122 	compute_resistor_weights(0, 255,    -1.0,
123 			3,  resistances_rb, weights_r,  100,    0,
124 			3,  resistances_rb, weights_b,  100,    0,
125 			2,  resistances_g,  weights_g,  100,    0);
126 
127 	for (int i = 0; i < palette.entries(); i++)
128 	{
129 		int bit0, bit1, bit2;
130 
131 		/* red component */
132 		bit0 = BIT(color_prom[i], 0);
133 		bit1 = BIT(color_prom[i], 1);
134 		bit2 = BIT(color_prom[i], 2);
135 		int const r = combine_weights(weights_r, bit0, bit1, bit2);
136 
137 		/* blue component */
138 		bit0 = BIT(color_prom[i], 3);
139 		bit1 = BIT(color_prom[i], 4);
140 		bit2 = BIT(color_prom[i], 5);
141 		int const b = combine_weights(weights_b, bit0, bit1, bit2);
142 
143 		/* green component */
144 		bit0 = BIT(color_prom[i], 6);
145 		bit1 = BIT(color_prom[i], 7);
146 		int const g = combine_weights(weights_g, bit0, bit1);
147 
148 		/* encrypted color matrix */
149 		int const cn = bitswap<8>(i, 4, 5, 6, 7, 2, 3, 0, 1);
150 
151 		palette.set_pen_color(cn, rgb_t(r, g, b));
152 	}
153 }
154 
TILE_GET_INFO_MEMBER(snookr10_state::apple10_get_bg_tile_info)155 TILE_GET_INFO_MEMBER(snookr10_state::apple10_get_bg_tile_info)
156 {
157 /*  - bits -
158     7654 3210
159     xxxx ----   tiles color.
160     ---- xxxx   seems unused.
161 */
162 	int offs = tile_index;
163 	int attr = m_videoram[offs] + (m_colorram[offs] << 8);
164 	int code = bitswap<16>((attr & 0xfff),15,14,13,12,8,9,10,11,0,1,2,3,4,5,6,7); /* encrypted tile matrix */
165 	int color = m_colorram[offs] >> 4;
166 
167 	tileinfo.set(0, code, color, 0);
168 }
169 
170 
171 /**********************************************************
172 
173   Crystals Colours palette and tile matrix / video RAM
174   are encrypted/scrambled.
175 
176   For more information, see the driver notes.
177 
178 **********************************************************/
179 
crystalc_palette(palette_device & palette) const180 void snookr10_state::crystalc_palette(palette_device &palette) const
181 {
182 	uint8_t const *const color_prom = memregion("proms")->base();
183 	/* GGBBBRRR */
184 
185 	static constexpr int resistances_rb[3] = { 1000, 470, 220 };
186 	static constexpr int resistances_g [2] = { 470, 220 };
187 
188 	double weights_r[3], weights_b[3], weights_g[2];
189 	compute_resistor_weights(0, 255,    -1.0,
190 			3,  resistances_rb, weights_r,  100,    0,
191 			3,  resistances_rb, weights_b,  100,    0,
192 			2,  resistances_g,  weights_g,  100,    0);
193 
194 	for (int i = 0; i < palette.entries(); i++)
195 	{
196 		int bit0, bit1, bit2;
197 
198 		// red component
199 		bit0 = BIT(color_prom[i], 0);
200 		bit1 = BIT(color_prom[i], 1);
201 		bit2 = BIT(color_prom[i], 2);
202 		int const r = combine_weights(weights_r, bit0, bit1, bit2);
203 
204 		// blue component
205 		bit0 = BIT(color_prom[i], 3);
206 		bit1 = BIT(color_prom[i], 4);
207 		bit2 = BIT(color_prom[i], 5);
208 		int const b = combine_weights(weights_b, bit0, bit1, bit2);
209 
210 		// green component
211 		bit0 = BIT(color_prom[i], 6);
212 		bit1 = BIT(color_prom[i], 7);
213 		int const g = combine_weights(weights_g, bit0, bit1);
214 
215 		// encrypted color matrix
216 		int const cn = bitswap<8>(i, 7, 5, 6, 4, 3, 2, 1, 0);
217 
218 		palette.set_pen_color(cn, rgb_t(r, g, b));
219 	}
220 }
221 
TILE_GET_INFO_MEMBER(snookr10_state::crystalc_get_bg_tile_info)222 TILE_GET_INFO_MEMBER(snookr10_state::crystalc_get_bg_tile_info)
223 {
224 /*  - bits -
225     7654 3210
226     xxxx ----   tiles color.
227     ---- xxxx   seems unused.
228 */
229 	int offs = tile_index;
230 	int attr = m_videoram[offs] + (m_colorram[offs] << 8);
231 	int code = bitswap<16>((attr & 0xfff),15,14,13,12,0,10,5,1,7,6,9,4,3,2,8,11); /* encrypted tile matrix */
232 	int color = m_colorram[offs] >> 4;
233 
234 	tileinfo.set(0, code, color, 0);
235 }
236 
237 
video_start()238 void snookr10_state::video_start()
239 {
240 	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snookr10_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 4, 8, 128, 30);
241 }
242 
VIDEO_START_MEMBER(snookr10_state,apple10)243 VIDEO_START_MEMBER(snookr10_state, apple10)
244 {
245 	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snookr10_state::apple10_get_bg_tile_info)), TILEMAP_SCAN_ROWS, 4, 8, 128, 30);
246 }
247 
VIDEO_START_MEMBER(snookr10_state,crystalc)248 VIDEO_START_MEMBER(snookr10_state, crystalc)
249 {
250 	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(snookr10_state::crystalc_get_bg_tile_info)), TILEMAP_SCAN_ROWS, 4, 8, 128, 30);
251 }
252 
screen_update_snookr10(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)253 uint32_t snookr10_state::screen_update_snookr10(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
254 {
255 	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
256 	return 0;
257 }
258