trunk/src/mame/drivers/artmagic.c
| r32354 | r32355 | |
| 148 | 148 | * |
| 149 | 149 | *************************************/ |
| 150 | 150 | |
| 151 | | static void ultennis_protection(running_machine &machine) |
| 151 | void artmagic_state::ultennis_protection() |
| 152 | 152 | { |
| 153 | | artmagic_state *state = machine.driver_data<artmagic_state>(); |
| 154 | 153 | /* check the command byte */ |
| 155 | | switch (state->m_prot_input[0]) |
| 154 | switch (m_prot_input[0]) |
| 156 | 155 | { |
| 157 | 156 | 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(); |
| 160 | 159 | break; |
| 161 | 160 | |
| 162 | 161 | case 0x01: /* 01 aaaa bbbb cccc dddd (xxxx) */ |
| 163 | | if (state->m_prot_input_index == 9) |
| 162 | if (m_prot_input_index == 9) |
| 164 | 163 | { |
| 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); |
| 169 | 168 | UINT16 x = a - b; |
| 170 | 169 | if ((INT16)x >= 0) |
| 171 | 170 | x = (x * c) >> 16; |
| 172 | 171 | else |
| 173 | 172 | x = -(((UINT16)-x * c) >> 16); |
| 174 | 173 | 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; |
| 178 | 177 | } |
| 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; |
| 181 | 180 | break; |
| 182 | 181 | |
| 183 | 182 | case 0x02: /* 02 aaaa bbbb cccc (xxxxxxxx) */ |
| r32354 | r32355 | |
| 194 | 193 | |
| 195 | 194 | question is: what is the 3rd value doing there? |
| 196 | 195 | */ |
| 197 | | if (state->m_prot_input_index == 7) |
| 196 | if (m_prot_input_index == 7) |
| 198 | 197 | { |
| 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));*/ |
| 202 | 201 | 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; |
| 208 | 207 | } |
| 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; |
| 211 | 210 | break; |
| 212 | 211 | |
| 213 | 212 | case 0x03: /* 03 (xxxx) */ |
| 214 | | if (state->m_prot_input_index == 1) |
| 213 | if (m_prot_input_index == 1) |
| 215 | 214 | { |
| 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; |
| 220 | 219 | } |
| 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; |
| 223 | 222 | break; |
| 224 | 223 | |
| 225 | 224 | case 0x04: /* 04 aaaa */ |
| 226 | | if (state->m_prot_input_index == 3) |
| 225 | if (m_prot_input_index == 3) |
| 227 | 226 | { |
| 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; |
| 231 | 230 | } |
| 232 | 231 | break; |
| 233 | 232 | |
| 234 | 233 | 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; |
| 237 | 236 | break; |
| 238 | 237 | } |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | 240 | |
| 242 | | static void cheesech_protection(running_machine &machine) |
| 241 | void artmagic_state::cheesech_protection() |
| 243 | 242 | { |
| 244 | | artmagic_state *state = machine.driver_data<artmagic_state>(); |
| 245 | 243 | /* check the command byte */ |
| 246 | | switch (state->m_prot_input[0]) |
| 244 | switch (m_prot_input[0]) |
| 247 | 245 | { |
| 248 | 246 | 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(); |
| 251 | 249 | break; |
| 252 | 250 | |
| 253 | 251 | case 0x01: /* 01 aaaa bbbb (xxxx) */ |
| 254 | | if (state->m_prot_input_index == 5) |
| 252 | if (m_prot_input_index == 5) |
| 255 | 253 | { |
| 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); |
| 258 | 256 | UINT16 c = 0x4000; /* seems to be hard-coded */ |
| 259 | 257 | UINT16 d = 0x00a0; /* seems to be hard-coded */ |
| 260 | 258 | UINT16 x = a - b; |
| r32354 | r32355 | |
| 263 | 261 | else |
| 264 | 262 | x = -(((UINT16)-x * c) >> 16); |
| 265 | 263 | 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; |
| 269 | 267 | } |
| 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; |
| 272 | 270 | break; |
| 273 | 271 | |
| 274 | 272 | case 0x03: /* 03 (xxxx) */ |
| 275 | | if (state->m_prot_input_index == 1) |
| 273 | if (m_prot_input_index == 1) |
| 276 | 274 | { |
| 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; |
| 281 | 279 | } |
| 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; |
| 284 | 282 | break; |
| 285 | 283 | |
| 286 | 284 | case 0x04: /* 04 aaaa */ |
| 287 | | if (state->m_prot_input_index == 3) |
| 285 | if (m_prot_input_index == 3) |
| 288 | 286 | { |
| 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; |
| 292 | 290 | } |
| 293 | 291 | break; |
| 294 | 292 | |
| 295 | 293 | 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; |
| 298 | 296 | break; |
| 299 | 297 | } |
| 300 | 298 | } |
| 301 | 299 | |
| 302 | 300 | |
| 303 | | static void stonebal_protection(running_machine &machine) |
| 301 | void artmagic_state::stonebal_protection() |
| 304 | 302 | { |
| 305 | | artmagic_state *state = machine.driver_data<artmagic_state>(); |
| 306 | 303 | /* check the command byte */ |
| 307 | | switch (state->m_prot_input[0]) |
| 304 | switch (m_prot_input[0]) |
| 308 | 305 | { |
| 309 | 306 | case 0x01: /* 01 aaaa bbbb cccc dddd (xxxx) */ |
| 310 | | if (state->m_prot_input_index == 9) |
| 307 | if (m_prot_input_index == 9) |
| 311 | 308 | { |
| 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); |
| 316 | 313 | UINT16 x = a - b; |
| 317 | 314 | if ((INT16)x >= 0) |
| 318 | 315 | x = (x * d) >> 16; |
| 319 | 316 | else |
| 320 | 317 | x = -(((UINT16)-x * d) >> 16); |
| 321 | 318 | 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; |
| 325 | 322 | } |
| 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; |
| 328 | 325 | break; |
| 329 | 326 | |
| 330 | 327 | case 0x02: /* 02 aaaa (xx) */ |
| 331 | | if (state->m_prot_input_index == 3) |
| 328 | if (m_prot_input_index == 3) |
| 332 | 329 | { |
| 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);*/ |
| 334 | 331 | 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; |
| 337 | 334 | } |
| 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; |
| 340 | 337 | break; |
| 341 | 338 | |
| 342 | 339 | case 0x03: /* 03 (xxxx) */ |
| 343 | | if (state->m_prot_input_index == 1) |
| 340 | if (m_prot_input_index == 1) |
| 344 | 341 | { |
| 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; |
| 349 | 346 | } |
| 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; |
| 352 | 349 | break; |
| 353 | 350 | |
| 354 | 351 | case 0x04: /* 04 aaaa */ |
| 355 | | if (state->m_prot_input_index == 3) |
| 352 | if (m_prot_input_index == 3) |
| 356 | 353 | { |
| 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; |
| 360 | 357 | } |
| 361 | 358 | break; |
| 362 | 359 | |
| 363 | 360 | 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; |
| 366 | 363 | break; |
| 367 | 364 | } |
| 368 | 365 | } |
| r32354 | r32355 | |
| 393 | 390 | m_prot_bit_index = 0; |
| 394 | 391 | |
| 395 | 392 | /* update the protection state */ |
| 396 | | (*m_protection_handler)(machine()); |
| 393 | (this->*m_protection_handler)(); |
| 397 | 394 | } |
| 398 | 395 | } |
| 399 | 396 | |