Previous 199869 Revisions Next

r32355 Wednesday 24th September, 2014 at 16:22:10 UTC by Osso
artmagic.c: moved protection handlers to the driver class (nw)
[src/mame/drivers]artmagic.c
[src/mame/includes]artmagic.h

trunk/src/mame/includes/artmagic.h
r32354r32355
3232   required_device<tlc34076_device> m_tlc34076;
3333   
3434   required_shared_ptr<UINT16> m_control;
35   required_shared_ptr<UINT16> m_vram0;
36   required_shared_ptr<UINT16> m_vram1;
3537   
3638   UINT8 m_tms_irq;
3739   UINT8 m_hack_irq;
r32354r32355
4244   UINT8 m_prot_output_bit;
4345   UINT8 m_prot_bit_index;
4446   UINT16 m_prot_save;
45   void (*m_protection_handler)(running_machine &);
46   required_shared_ptr<UINT16> m_vram0;
47   required_shared_ptr<UINT16> m_vram1;
47   typedef void (artmagic_state::*prot_func)();
48   prot_func m_protection_handler;
49   void ultennis_protection();
50   void cheesech_protection();
51   void stonebal_protection();
52   
4853   int m_xor[16];
4954   int m_is_stoneball;
5055   UINT16 *m_blitter_base;
trunk/src/mame/drivers/artmagic.c
r32354r32355
148148 *
149149 *************************************/
150150
151static void ultennis_protection(running_machine &machine)
151void artmagic_state::ultennis_protection()
152152{
153   artmagic_state *state = machine.driver_data<artmagic_state>();
154153   /* check the command byte */
155   switch (state->m_prot_input[0])
154   switch (m_prot_input[0])
156155   {
157156      case 0x00:  /* reset */
158         state->m_prot_input_index = state->m_prot_output_index = 0;
159         state->m_prot_output[0] = machine.rand();
157         m_prot_input_index = m_prot_output_index = 0;
158         m_prot_output[0] = machine().rand();
160159         break;
161160
162161      case 0x01:  /* 01 aaaa bbbb cccc dddd (xxxx) */
163         if (state->m_prot_input_index == 9)
162         if (m_prot_input_index == 9)
164163         {
165            UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);
166            UINT16 b = state->m_prot_input[3] | (state->m_prot_input[4] << 8);
167            UINT16 c = state->m_prot_input[5] | (state->m_prot_input[6] << 8);
168            UINT16 d = state->m_prot_input[7] | (state->m_prot_input[8] << 8);
164            UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);
165            UINT16 b = m_prot_input[3] | (m_prot_input[4] << 8);
166            UINT16 c = m_prot_input[5] | (m_prot_input[6] << 8);
167            UINT16 d = m_prot_input[7] | (m_prot_input[8] << 8);
169168            UINT16 x = a - b;
170169            if ((INT16)x >= 0)
171170               x = (x * c) >> 16;
172171            else
173172               x = -(((UINT16)-x * c) >> 16);
174173            x += d;
175            state->m_prot_output[0] = x;
176            state->m_prot_output[1] = x >> 8;
177            state->m_prot_output_index = 0;
174            m_prot_output[0] = x;
175            m_prot_output[1] = x >> 8;
176            m_prot_output_index = 0;
178177         }
179         else if (state->m_prot_input_index >= 11)
180            state->m_prot_input_index = 0;
178         else if (m_prot_input_index >= 11)
179            m_prot_input_index = 0;
181180         break;
182181
183182      case 0x02:  /* 02 aaaa bbbb cccc (xxxxxxxx) */
r32354r32355
194193
195194             question is: what is the 3rd value doing there?
196195         */
197         if (state->m_prot_input_index == 7)
196         if (m_prot_input_index == 7)
198197         {
199            UINT16 a = (INT16)(state->m_prot_input[1] | (state->m_prot_input[2] << 8));
200            UINT16 b = (INT16)(state->m_prot_input[3] | (state->m_prot_input[4] << 8));
201            /*UINT16 c = (INT16)(state->m_prot_input[5] | (state->m_prot_input[6] << 8));*/
198            UINT16 a = (INT16)(m_prot_input[1] | (m_prot_input[2] << 8));
199            UINT16 b = (INT16)(m_prot_input[3] | (m_prot_input[4] << 8));
200            /*UINT16 c = (INT16)(m_prot_input[5] | (m_prot_input[6] << 8));*/
202201            UINT32 x = a * a * (b/2);
203            state->m_prot_output[0] = x;
204            state->m_prot_output[1] = x >> 8;
205            state->m_prot_output[2] = x >> 16;
206            state->m_prot_output[3] = x >> 24;
207            state->m_prot_output_index = 0;
202            m_prot_output[0] = x;
203            m_prot_output[1] = x >> 8;
204            m_prot_output[2] = x >> 16;
205            m_prot_output[3] = x >> 24;
206            m_prot_output_index = 0;
208207         }
209         else if (state->m_prot_input_index >= 11)
210            state->m_prot_input_index = 0;
208         else if (m_prot_input_index >= 11)
209            m_prot_input_index = 0;
211210         break;
212211
213212      case 0x03:  /* 03 (xxxx) */
214         if (state->m_prot_input_index == 1)
213         if (m_prot_input_index == 1)
215214         {
216            UINT16 x = state->m_prot_save;
217            state->m_prot_output[0] = x;
218            state->m_prot_output[1] = x >> 8;
219            state->m_prot_output_index = 0;
215            UINT16 x = m_prot_save;
216            m_prot_output[0] = x;
217            m_prot_output[1] = x >> 8;
218            m_prot_output_index = 0;
220219         }
221         else if (state->m_prot_input_index >= 3)
222            state->m_prot_input_index = 0;
220         else if (m_prot_input_index >= 3)
221            m_prot_input_index = 0;
223222         break;
224223
225224      case 0x04:  /* 04 aaaa */
226         if (state->m_prot_input_index == 3)
225         if (m_prot_input_index == 3)
227226         {
228            UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);
229            state->m_prot_save = a;
230            state->m_prot_input_index = state->m_prot_output_index = 0;
227            UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);
228            m_prot_save = a;
229            m_prot_input_index = m_prot_output_index = 0;
231230         }
232231         break;
233232
234233      default:
235         logerror("protection command %02X: unknown\n", state->m_prot_input[0]);
236         state->m_prot_input_index = state->m_prot_output_index = 0;
234         logerror("protection command %02X: unknown\n", m_prot_input[0]);
235         m_prot_input_index = m_prot_output_index = 0;
237236         break;
238237   }
239238}
240239
241240
242static void cheesech_protection(running_machine &machine)
241void artmagic_state::cheesech_protection()
243242{
244   artmagic_state *state = machine.driver_data<artmagic_state>();
245243   /* check the command byte */
246   switch (state->m_prot_input[0])
244   switch (m_prot_input[0])
247245   {
248246      case 0x00:  /* reset */
249         state->m_prot_input_index = state->m_prot_output_index = 0;
250         state->m_prot_output[0] = machine.rand();
247         m_prot_input_index = m_prot_output_index = 0;
248         m_prot_output[0] = machine().rand();
251249         break;
252250
253251      case 0x01:  /* 01 aaaa bbbb (xxxx) */
254         if (state->m_prot_input_index == 5)
252         if (m_prot_input_index == 5)
255253         {
256            UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);
257            UINT16 b = state->m_prot_input[3] | (state->m_prot_input[4] << 8);
254            UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);
255            UINT16 b = m_prot_input[3] | (m_prot_input[4] << 8);
258256            UINT16 c = 0x4000;      /* seems to be hard-coded */
259257            UINT16 d = 0x00a0;      /* seems to be hard-coded */
260258            UINT16 x = a - b;
r32354r32355
263261            else
264262               x = -(((UINT16)-x * c) >> 16);
265263            x += d;
266            state->m_prot_output[0] = x;
267            state->m_prot_output[1] = x >> 8;
268            state->m_prot_output_index = 0;
264            m_prot_output[0] = x;
265            m_prot_output[1] = x >> 8;
266            m_prot_output_index = 0;
269267         }
270         else if (state->m_prot_input_index >= 7)
271            state->m_prot_input_index = 0;
268         else if (m_prot_input_index >= 7)
269            m_prot_input_index = 0;
272270         break;
273271
274272      case 0x03:  /* 03 (xxxx) */
275         if (state->m_prot_input_index == 1)
273         if (m_prot_input_index == 1)
276274         {
277            UINT16 x = state->m_prot_save;
278            state->m_prot_output[0] = x;
279            state->m_prot_output[1] = x >> 8;
280            state->m_prot_output_index = 0;
275            UINT16 x = m_prot_save;
276            m_prot_output[0] = x;
277            m_prot_output[1] = x >> 8;
278            m_prot_output_index = 0;
281279         }
282         else if (state->m_prot_input_index >= 3)
283            state->m_prot_input_index = 0;
280         else if (m_prot_input_index >= 3)
281            m_prot_input_index = 0;
284282         break;
285283
286284      case 0x04:  /* 04 aaaa */
287         if (state->m_prot_input_index == 3)
285         if (m_prot_input_index == 3)
288286         {
289            UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);
290            state->m_prot_save = a;
291            state->m_prot_input_index = state->m_prot_output_index = 0;
287            UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);
288            m_prot_save = a;
289            m_prot_input_index = m_prot_output_index = 0;
292290         }
293291         break;
294292
295293      default:
296         logerror("protection command %02X: unknown\n", state->m_prot_input[0]);
297         state->m_prot_input_index = state->m_prot_output_index = 0;
294         logerror("protection command %02X: unknown\n", m_prot_input[0]);
295         m_prot_input_index = m_prot_output_index = 0;
298296         break;
299297   }
300298}
301299
302300
303static void stonebal_protection(running_machine &machine)
301void artmagic_state::stonebal_protection()
304302{
305   artmagic_state *state = machine.driver_data<artmagic_state>();
306303   /* check the command byte */
307   switch (state->m_prot_input[0])
304   switch (m_prot_input[0])
308305   {
309306      case 0x01:  /* 01 aaaa bbbb cccc dddd (xxxx) */
310         if (state->m_prot_input_index == 9)
307         if (m_prot_input_index == 9)
311308         {
312            UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);
313            UINT16 b = state->m_prot_input[3] | (state->m_prot_input[4] << 8);
314            UINT16 c = state->m_prot_input[5] | (state->m_prot_input[6] << 8);
315            UINT16 d = state->m_prot_input[7] | (state->m_prot_input[8] << 8);
309            UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);
310            UINT16 b = m_prot_input[3] | (m_prot_input[4] << 8);
311            UINT16 c = m_prot_input[5] | (m_prot_input[6] << 8);
312            UINT16 d = m_prot_input[7] | (m_prot_input[8] << 8);
316313            UINT16 x = a - b;
317314            if ((INT16)x >= 0)
318315               x = (x * d) >> 16;
319316            else
320317               x = -(((UINT16)-x * d) >> 16);
321318            x += c;
322            state->m_prot_output[0] = x;
323            state->m_prot_output[1] = x >> 8;
324            state->m_prot_output_index = 0;
319            m_prot_output[0] = x;
320            m_prot_output[1] = x >> 8;
321            m_prot_output_index = 0;
325322         }
326         else if (state->m_prot_input_index >= 11)
327            state->m_prot_input_index = 0;
323         else if (m_prot_input_index >= 11)
324            m_prot_input_index = 0;
328325         break;
329326
330327      case 0x02:  /* 02 aaaa (xx) */
331         if (state->m_prot_input_index == 3)
328         if (m_prot_input_index == 3)
332329         {
333            /*UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);*/
330            /*UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);*/
334331            UINT8 x = 0xa5;
335            state->m_prot_output[0] = x;
336            state->m_prot_output_index = 0;
332            m_prot_output[0] = x;
333            m_prot_output_index = 0;
337334         }
338         else if (state->m_prot_input_index >= 4)
339            state->m_prot_input_index = 0;
335         else if (m_prot_input_index >= 4)
336            m_prot_input_index = 0;
340337         break;
341338
342339      case 0x03:  /* 03 (xxxx) */
343         if (state->m_prot_input_index == 1)
340         if (m_prot_input_index == 1)
344341         {
345            UINT16 x = state->m_prot_save;
346            state->m_prot_output[0] = x;
347            state->m_prot_output[1] = x >> 8;
348            state->m_prot_output_index = 0;
342            UINT16 x = m_prot_save;
343            m_prot_output[0] = x;
344            m_prot_output[1] = x >> 8;
345            m_prot_output_index = 0;
349346         }
350         else if (state->m_prot_input_index >= 3)
351            state->m_prot_input_index = 0;
347         else if (m_prot_input_index >= 3)
348            m_prot_input_index = 0;
352349         break;
353350
354351      case 0x04:  /* 04 aaaa */
355         if (state->m_prot_input_index == 3)
352         if (m_prot_input_index == 3)
356353         {
357            UINT16 a = state->m_prot_input[1] | (state->m_prot_input[2] << 8);
358            state->m_prot_save = a;
359            state->m_prot_input_index = state->m_prot_output_index = 0;
354            UINT16 a = m_prot_input[1] | (m_prot_input[2] << 8);
355            m_prot_save = a;
356            m_prot_input_index = m_prot_output_index = 0;
360357         }
361358         break;
362359
363360      default:
364         logerror("protection command %02X: unknown\n", state->m_prot_input[0]);
365         state->m_prot_input_index = state->m_prot_output_index = 0;
361         logerror("protection command %02X: unknown\n", m_prot_input[0]);
362         m_prot_input_index = m_prot_output_index = 0;
366363         break;
367364   }
368365}
r32354r32355
393390      m_prot_bit_index = 0;
394391
395392      /* update the protection state */
396      (*m_protection_handler)(machine());
393      (this->*m_protection_handler)();
397394   }
398395}
399396

Previous 199869 Revisions Next


© 1997-2024 The MAME Team