src/mame/machine/snes7110.c
| r0 | r5808 | |
| 1 | static const UINT32 spc7110_decomp_buffer_size = 64; |
| 2 | |
| 3 | static const UINT8 spc7110_evolution_table[53][4] = |
| 4 | { |
| 5 | { 0x5a, 1, 1, 1 }, |
| 6 | { 0x25, 6, 2, 0 }, |
| 7 | { 0x11, 8, 3, 0 }, |
| 8 | { 0x08, 10, 4, 0 }, |
| 9 | { 0x03, 12, 5, 0 }, |
| 10 | { 0x01, 15, 5, 0 }, |
| 11 | |
| 12 | { 0x5a, 7, 7, 1 }, |
| 13 | { 0x3f, 19, 8, 0 }, |
| 14 | { 0x2c, 21, 9, 0 }, |
| 15 | { 0x20, 22, 10, 0 }, |
| 16 | { 0x17, 23, 11, 0 }, |
| 17 | { 0x11, 25, 12, 0 }, |
| 18 | { 0x0c, 26, 13, 0 }, |
| 19 | { 0x09, 28, 14, 0 }, |
| 20 | { 0x07, 29, 15, 0 }, |
| 21 | { 0x05, 31, 16, 0 }, |
| 22 | { 0x04, 32, 17, 0 }, |
| 23 | { 0x03, 34, 18, 0 }, |
| 24 | { 0x02, 35, 5, 0 }, |
| 25 | |
| 26 | { 0x5a, 20, 20, 1 }, |
| 27 | { 0x48, 39, 21, 0 }, |
| 28 | { 0x3a, 40, 22, 0 }, |
| 29 | { 0x2e, 42, 23, 0 }, |
| 30 | { 0x26, 44, 24, 0 }, |
| 31 | { 0x1f, 45, 25, 0 }, |
| 32 | { 0x19, 46, 26, 0 }, |
| 33 | { 0x15, 25, 27, 0 }, |
| 34 | { 0x11, 26, 28, 0 }, |
| 35 | { 0x0e, 26, 29, 0 }, |
| 36 | { 0x0b, 27, 30, 0 }, |
| 37 | { 0x09, 28, 31, 0 }, |
| 38 | { 0x08, 29, 32, 0 }, |
| 39 | { 0x07, 30, 33, 0 }, |
| 40 | { 0x05, 31, 34, 0 }, |
| 41 | { 0x04, 33, 35, 0 }, |
| 42 | { 0x04, 33, 36, 0 }, |
| 43 | { 0x03, 34, 37, 0 }, |
| 44 | { 0x02, 35, 38, 0 }, |
| 45 | { 0x02, 36, 5, 0 }, |
| 46 | |
| 47 | { 0x58, 39, 40, 1 }, |
| 48 | { 0x4d, 47, 41, 0 }, |
| 49 | { 0x43, 48, 42, 0 }, |
| 50 | { 0x3b, 49, 43, 0 }, |
| 51 | { 0x34, 50, 44, 0 }, |
| 52 | { 0x2e, 51, 45, 0 }, |
| 53 | { 0x29, 44, 46, 0 }, |
| 54 | { 0x25, 45, 24, 0 }, |
| 55 | |
| 56 | { 0x56, 47, 48, 1 }, |
| 57 | { 0x4f, 47, 49, 0 }, |
| 58 | { 0x47, 48, 50, 0 }, |
| 59 | { 0x41, 49, 51, 0 }, |
| 60 | { 0x3c, 50, 52, 0 }, |
| 61 | { 0x37, 51, 43, 0 }, |
| 62 | }; |
| 63 | |
| 64 | static const UINT8 spc7110_mode2_context_table[32][2] = |
| 65 | { |
| 66 | { 1, 2 }, |
| 67 | |
| 68 | { 3, 8 }, |
| 69 | { 13, 14 }, |
| 70 | |
| 71 | { 15, 16 }, |
| 72 | { 17, 18 }, |
| 73 | { 19, 20 }, |
| 74 | { 21, 22 }, |
| 75 | { 23, 24 }, |
| 76 | { 25, 26 }, |
| 77 | { 25, 26 }, |
| 78 | { 25, 26 }, |
| 79 | { 25, 26 }, |
| 80 | { 25, 26 }, |
| 81 | { 27, 28 }, |
| 82 | { 29, 30 }, |
| 83 | |
| 84 | { 31, 31 }, |
| 85 | { 31, 31 }, |
| 86 | { 31, 31 }, |
| 87 | { 31, 31 }, |
| 88 | { 31, 31 }, |
| 89 | { 31, 31 }, |
| 90 | { 31, 31 }, |
| 91 | { 31, 31 }, |
| 92 | { 31, 31 }, |
| 93 | { 31, 31 }, |
| 94 | { 31, 31 }, |
| 95 | { 31, 31 }, |
| 96 | { 31, 31 }, |
| 97 | { 31, 31 }, |
| 98 | { 31, 31 }, |
| 99 | { 31, 31 }, |
| 100 | |
| 101 | { 31, 31 }, |
| 102 | }; |
| 103 | |
| 104 | typedef struct |
| 105 | { |
| 106 | running_machine *machine; |
| 107 | |
| 108 | UINT32 decomp_mode; |
| 109 | UINT32 decomp_offset; |
| 110 | |
| 111 | UINT8 *decomp_buffer; |
| 112 | UINT32 decomp_buffer_rdoffset; |
| 113 | UINT32 decomp_buffer_wroffset; |
| 114 | UINT32 decomp_buffer_length; |
| 115 | |
| 116 | struct ContextState |
| 117 | { |
| 118 | UINT8 index; |
| 119 | UINT8 invert; |
| 120 | } context[32]; |
| 121 | |
| 122 | UINT32 morton16[2][256]; |
| 123 | UINT32 morton32[4][256]; |
| 124 | } SPC7110Decomp; |
| 125 | |
| 126 | static SPC7110Decomp* SPC7110Decomp_ctor(running_machine *machine); |
| 127 | static void SPC7110Decomp_reset(SPC7110Decomp *thisptr); |
| 128 | static void SPC7110Decomp_init(SPC7110Decomp *thisptr, running_machine *machine, UINT32 mode, UINT32 offset, UINT32 index); |
| 129 | static UINT8 SPC7110Decomp_read(SPC7110Decomp *thisptr); |
| 130 | static void SPC7110Decomp_write(SPC7110Decomp *thisptr, UINT8 data); |
| 131 | static UINT8 SPC7110Decomp_dataread(SPC7110Decomp *thisptr); |
| 132 | static void SPC7110Decomp_mode0(SPC7110Decomp *thisptr, UINT8 init); |
| 133 | static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init); |
| 134 | static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init); |
| 135 | static UINT8 SPC7110Decomp_probability(SPC7110Decomp *thisptr, UINT32 n); |
| 136 | static UINT8 SPC7110Decomp_next_lps(SPC7110Decomp *thisptr, UINT32 n); |
| 137 | static UINT8 SPC7110Decomp_next_mps(SPC7110Decomp *thisptr, UINT32 n); |
| 138 | static UINT8 SPC7110Decomp_toggle_invert(SPC7110Decomp *thisptr, UINT32 n); |
| 139 | static UINT32 SPC7110Decomp_morton_2x8(SPC7110Decomp *thisptr, UINT32 data); |
| 140 | static UINT32 SPC7110Decomp_morton_4x8(SPC7110Decomp *thisptr, UINT32 data); |
| 141 | |
| 142 | static SPC7110Decomp* SPC7110Decomp_ctor(running_machine *machine) |
| 143 | { |
| 144 | UINT32 i; |
| 145 | SPC7110Decomp* newclass = (SPC7110Decomp*)auto_alloc_array(machine, UINT8, sizeof(SPC7110Decomp)); |
| 146 | newclass->decomp_buffer = (UINT8*)auto_alloc_array(machine, UINT8, spc7110_decomp_buffer_size); |
| 147 | SPC7110Decomp_reset(newclass); |
| 148 | |
| 149 | for(i = 0; i < 256; i++) |
| 150 | { |
| 151 | #define map(x, y) (((i >> x) & 1) << y) |
| 152 | //2x8-bit |
| 153 | newclass->morton16[1][i] = map(7, 15) + map(6, 7) + map(5, 14) + map(4, 6) |
| 154 | + map(3, 13) + map(2, 5) + map(1, 12) + map(0, 4); |
| 155 | newclass->morton16[0][i] = map(7, 11) + map(6, 3) + map(5, 10) + map(4, 2) |
| 156 | + map(3, 9) + map(2, 1) + map(1, 8) + map(0, 0); |
| 157 | //4x8-bit |
| 158 | newclass->morton32[3][i] = map(7, 31) + map(6, 23) + map(5, 15) + map(4, 7) |
| 159 | + map(3, 30) + map(2, 22) + map(1, 14) + map(0, 6); |
| 160 | newclass->morton32[2][i] = map(7, 29) + map(6, 21) + map(5, 13) + map(4, 5) |
| 161 | + map(3, 28) + map(2, 20) + map(1, 12) + map(0, 4); |
| 162 | newclass->morton32[1][i] = map(7, 27) + map(6, 19) + map(5, 11) + map(4, 3) |
| 163 | + map(3, 26) + map(2, 18) + map(1, 10) + map(0, 2); |
| 164 | newclass->morton32[0][i] = map(7, 25) + map(6, 17) + map(5, 9) + map(4, 1) |
| 165 | + map(3, 24) + map(2, 16) + map(1, 8) + map(0, 0); |
| 166 | #undef map |
| 167 | } |
| 168 | |
| 169 | return newclass; |
| 170 | } |
| 171 | |
| 172 | static void SPC7110Decomp_reset(SPC7110Decomp *thisptr) |
| 173 | { |
| 174 | //mode 3 is invalid; this is treated as a special case to always return 0x00 |
| 175 | //set to mode 3 so that reading decomp port before starting first decomp will return 0x00 |
| 176 | thisptr->decomp_mode = 3; |
| 177 | |
| 178 | thisptr->decomp_buffer_rdoffset = 0; |
| 179 | thisptr->decomp_buffer_wroffset = 0; |
| 180 | thisptr->decomp_buffer_length = 0; |
| 181 | } |
| 182 | |
| 183 | static void SPC7110Decomp_init(SPC7110Decomp *thisptr, running_machine *machine, UINT32 mode, UINT32 offset, UINT32 index) |
| 184 | { |
| 185 | UINT32 i; |
| 186 | |
| 187 | thisptr->machine = machine; |
| 188 | |
| 189 | thisptr->decomp_mode = mode; |
| 190 | thisptr->decomp_offset = offset; |
| 191 | |
| 192 | thisptr->decomp_buffer_rdoffset = 0; |
| 193 | thisptr->decomp_buffer_wroffset = 0; |
| 194 | thisptr->decomp_buffer_length = 0; |
| 195 | |
| 196 | //reset context states |
| 197 | for(i = 0; i < 32; i++) |
| 198 | { |
| 199 | thisptr->context[i].index = 0; |
| 200 | thisptr->context[i].invert = 0; |
| 201 | } |
| 202 | |
| 203 | switch(thisptr->decomp_mode) |
| 204 | { |
| 205 | case 0: SPC7110Decomp_mode0(thisptr, 1); break; |
| 206 | case 1: SPC7110Decomp_mode1(thisptr, 1); break; |
| 207 | case 2: SPC7110Decomp_mode2(thisptr, 1); break; |
| 208 | } |
| 209 | |
| 210 | //decompress up to requested output data index |
| 211 | while(index--) |
| 212 | { |
| 213 | SPC7110Decomp_read(thisptr); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | static UINT8 SPC7110Decomp_read(SPC7110Decomp *thisptr) |
| 218 | { |
| 219 | UINT8 data; |
| 220 | |
| 221 | if(thisptr->decomp_buffer_length == 0) { |
| 222 | //decompress at least (spc7110_decomp_buffer_size / 2) bytes to the buffer |
| 223 | switch(thisptr->decomp_mode) { |
| 224 | case 0: |
| 225 | SPC7110Decomp_mode0(thisptr, 0); |
| 226 | break; |
| 227 | |
| 228 | case 1: |
| 229 | SPC7110Decomp_mode1(thisptr, 0); |
| 230 | break; |
| 231 | |
| 232 | case 2: |
| 233 | SPC7110Decomp_mode2(thisptr, 0); |
| 234 | break; |
| 235 | |
| 236 | default: |
| 237 | return 0x00; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | data = thisptr->decomp_buffer[thisptr->decomp_buffer_rdoffset++]; |
| 242 | thisptr->decomp_buffer_rdoffset &= spc7110_decomp_buffer_size - 1; |
| 243 | thisptr->decomp_buffer_length--; |
| 244 | return data; |
| 245 | } |
| 246 | |
| 247 | static void SPC7110Decomp_write(SPC7110Decomp *thisptr, UINT8 data) |
| 248 | { |
| 249 | thisptr->decomp_buffer[thisptr->decomp_buffer_wroffset++] = data; |
| 250 | thisptr->decomp_buffer_wroffset &= spc7110_decomp_buffer_size - 1; |
| 251 | thisptr->decomp_buffer_length++; |
| 252 | } |
| 253 | |
| 254 | static UINT8 SPC7110Decomp_dataread(SPC7110Decomp *thisptr) |
| 255 | { |
| 256 | UINT8 *ROM = memory_region(thisptr->machine, "cart"); |
| 257 | UINT32 size = snes_rom_size - 0x100000; |
| 258 | while(thisptr->decomp_offset >= size) |
| 259 | { |
| 260 | thisptr->decomp_offset -= size; |
| 261 | } |
| 262 | return ROM[0x100000 + thisptr->decomp_offset++]; |
| 263 | } |
| 264 | |
| 265 | static void SPC7110Decomp_mode0(SPC7110Decomp *thisptr, UINT8 init) |
| 266 | { |
| 267 | static UINT8 val, in, span; |
| 268 | static INT32 out, inverts, lps, in_count; |
| 269 | |
| 270 | if(init == 1) |
| 271 | { |
| 272 | out = inverts = lps = 0; |
| 273 | span = 0xff; |
| 274 | val = SPC7110Decomp_dataread(thisptr); |
| 275 | in = SPC7110Decomp_dataread(thisptr); |
| 276 | in_count = 8; |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | while(thisptr->decomp_buffer_length < (spc7110_decomp_buffer_size >> 1)) |
| 281 | { |
| 282 | UINT32 bit; |
| 283 | for(bit = 0; bit < 8; bit++) |
| 284 | { |
| 285 | //get context |
| 286 | UINT8 mask = (1 << (bit & 3)) - 1; |
| 287 | UINT8 con = mask + ((inverts & mask) ^ (lps & mask)); |
| 288 | UINT32 prob, mps, flag_lps; |
| 289 | UINT32 shift = 0; |
| 290 | if(bit > 3) |
| 291 | { |
| 292 | con += 15; |
| 293 | } |
| 294 | |
| 295 | //get prob and mps |
| 296 | prob = SPC7110Decomp_probability(thisptr, con); |
| 297 | mps = (((out >> 15) & 1) ^ thisptr->context[con].invert); |
| 298 | |
| 299 | //get bit |
| 300 | if(val <= span - prob) //mps |
| 301 | { |
| 302 | span = span - prob; |
| 303 | out = (out << 1) + mps; |
| 304 | flag_lps = 0; |
| 305 | } |
| 306 | else //lps |
| 307 | { |
| 308 | val = val - (span - (prob - 1)); |
| 309 | span = prob - 1; |
| 310 | out = (out << 1) + 1 - mps; |
| 311 | flag_lps = 1; |
| 312 | } |
| 313 | |
| 314 | //renormalize |
| 315 | while(span < 0x7f) |
| 316 | { |
| 317 | shift++; |
| 318 | |
| 319 | span = (span << 1) + 1; |
| 320 | val = (val << 1) + (in >> 7); |
| 321 | |
| 322 | in <<= 1; |
| 323 | if(--in_count == 0) |
| 324 | { |
| 325 | in = SPC7110Decomp_dataread(thisptr); |
| 326 | in_count = 8; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | //update processing info |
| 331 | lps = (lps << 1) + flag_lps; |
| 332 | inverts = (inverts << 1) + thisptr->context[con].invert; |
| 333 | |
| 334 | //update context state |
| 335 | if(flag_lps & SPC7110Decomp_toggle_invert(thisptr, con)) |
| 336 | { |
| 337 | thisptr->context[con].invert ^= 1; |
| 338 | } |
| 339 | if(flag_lps) |
| 340 | { |
| 341 | thisptr->context[con].index = SPC7110Decomp_next_lps(thisptr, con); |
| 342 | } |
| 343 | else if(shift) |
| 344 | { |
| 345 | thisptr->context[con].index = SPC7110Decomp_next_mps(thisptr, con); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | //save byte |
| 350 | SPC7110Decomp_write(thisptr, out); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init) |
| 355 | { |
| 356 | static INT32 pixelorder[4], realorder[4]; |
| 357 | static UINT8 in, val, span; |
| 358 | static INT32 out, inverts, lps, in_count; |
| 359 | |
| 360 | if(init == 1) |
| 361 | { |
| 362 | UINT32 i; |
| 363 | for(i = 0; i < 4; i++) |
| 364 | { |
| 365 | pixelorder[i] = i; |
| 366 | } |
| 367 | out = inverts = lps = 0; |
| 368 | span = 0xff; |
| 369 | val = SPC7110Decomp_dataread(thisptr); |
| 370 | in = SPC7110Decomp_dataread(thisptr); |
| 371 | in_count = 8; |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | while(thisptr->decomp_buffer_length < (spc7110_decomp_buffer_size >> 1)) |
| 376 | { |
| 377 | UINT8 data; |
| 378 | UINT32 pixel; |
| 379 | for(pixel = 0; pixel < 8; pixel++) |
| 380 | { |
| 381 | //get first symbol context |
| 382 | UINT32 a = ((out >> (1 * 2)) & 3); |
| 383 | UINT32 b = ((out >> (7 * 2)) & 3); |
| 384 | UINT32 c = ((out >> (8 * 2)) & 3); |
| 385 | UINT32 con = (a == b) ? (b != c) : (b == c) ? 2 : 4 - (a == c); |
| 386 | UINT32 bit; |
| 387 | |
| 388 | //update pixel order |
| 389 | UINT32 m, n; |
| 390 | for(m = 0; m < 4; m++) |
| 391 | { |
| 392 | if(pixelorder[m] == a) |
| 393 | { |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | for(n = m; n > 0; n--) |
| 398 | { |
| 399 | pixelorder[n] = pixelorder[n - 1]; |
| 400 | } |
| 401 | pixelorder[0] = a; |
| 402 | |
| 403 | //calculate the real pixel order |
| 404 | for(m = 0; m < 4; m++) |
| 405 | { |
| 406 | realorder[m] = pixelorder[m]; |
| 407 | } |
| 408 | |
| 409 | //rotate reference pixel c value to top |
| 410 | for(m = 0; m < 4; m++) |
| 411 | { |
| 412 | if(realorder[m] == c) |
| 413 | { |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | for(n = m; n > 0; n--) |
| 418 | { |
| 419 | realorder[n] = realorder[n - 1]; |
| 420 | } |
| 421 | realorder[0] = c; |
| 422 | |
| 423 | //rotate reference pixel b value to top |
| 424 | for(m = 0; m < 4; m++) |
| 425 | { |
| 426 | if(realorder[m] == b) |
| 427 | { |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | for(n = m; n > 0; n--) |
| 432 | { |
| 433 | realorder[n] = realorder[n - 1]; |
| 434 | } |
| 435 | realorder[0] = b; |
| 436 | |
| 437 | //rotate reference pixel a value to top |
| 438 | for(m = 0; m < 4; m++) |
| 439 | { |
| 440 | if(realorder[m] == a) |
| 441 | { |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | for(n = m; n > 0; n--) |
| 446 | { |
| 447 | realorder[n] = realorder[n - 1]; |
| 448 | } |
| 449 | realorder[0] = a; |
| 450 | |
| 451 | //get 2 symbols |
| 452 | for(bit = 0; bit < 2; bit++) |
| 453 | { |
| 454 | //get prob |
| 455 | UINT32 prob = SPC7110Decomp_probability(thisptr, con); |
| 456 | UINT32 shift = 0; |
| 457 | |
| 458 | //get symbol |
| 459 | UINT32 flag_lps; |
| 460 | if(val <= span - prob) //mps |
| 461 | { |
| 462 | span = span - prob; |
| 463 | flag_lps = 0; |
| 464 | } |
| 465 | else //lps |
| 466 | { |
| 467 | val = val - (span - (prob - 1)); |
| 468 | span = prob - 1; |
| 469 | flag_lps = 1; |
| 470 | } |
| 471 | |
| 472 | //renormalize |
| 473 | while(span < 0x7f) |
| 474 | { |
| 475 | shift++; |
| 476 | |
| 477 | span = (span << 1) + 1; |
| 478 | val = (val << 1) + (in >> 7); |
| 479 | |
| 480 | in <<= 1; |
| 481 | if(--in_count == 0) |
| 482 | { |
| 483 | in = SPC7110Decomp_dataread(thisptr); |
| 484 | in_count = 8; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | //update processing info |
| 489 | lps = (lps << 1) + flag_lps; |
| 490 | inverts = (inverts << 1) + thisptr->context[con].invert; |
| 491 | |
| 492 | //update context state |
| 493 | if(flag_lps & SPC7110Decomp_toggle_invert(thisptr, con)) |
| 494 | { |
| 495 | thisptr->context[con].invert ^= 1; |
| 496 | } |
| 497 | if(flag_lps) |
| 498 | { |
| 499 | thisptr->context[con].index = SPC7110Decomp_next_lps(thisptr, con); |
| 500 | } |
| 501 | else if(shift) |
| 502 | { |
| 503 | thisptr->context[con].index = SPC7110Decomp_next_mps(thisptr, con); |
| 504 | } |
| 505 | |
| 506 | //get next context |
| 507 | con = 5 + (con << 1) + ((lps ^ inverts) & 1); |
| 508 | } |
| 509 | |
| 510 | //get pixel |
| 511 | b = realorder[(lps ^ inverts) & 3]; |
| 512 | out = (out << 2) + b; |
| 513 | } |
| 514 | |
| 515 | //turn pixel data into bitplanes |
| 516 | data = SPC7110Decomp_morton_2x8(thisptr, out); |
| 517 | SPC7110Decomp_write(thisptr, data >> 8); |
| 518 | SPC7110Decomp_write(thisptr, data >> 0); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init) |
| 523 | { |
| 524 | static INT32 pixelorder[16], realorder[16]; |
| 525 | static UINT8 bitplanebuffer[16], buffer_index; |
| 526 | static UINT8 in, val, span; |
| 527 | static INT32 out0, out1, inverts, lps, in_count; |
| 528 | |
| 529 | if(init == 1) |
| 530 | { |
| 531 | UINT32 i; |
| 532 | for(i = 0; i < 16; i++) |
| 533 | { |
| 534 | pixelorder[i] = i; |
| 535 | } |
| 536 | buffer_index = 0; |
| 537 | out0 = out1 = inverts = lps = 0; |
| 538 | span = 0xff; |
| 539 | val = SPC7110Decomp_dataread(thisptr); |
| 540 | in = SPC7110Decomp_dataread(thisptr); |
| 541 | in_count = 8; |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | while(thisptr->decomp_buffer_length < (spc7110_decomp_buffer_size >> 1)) |
| 546 | { |
| 547 | UINT32 data; |
| 548 | UINT32 pixel; |
| 549 | for(pixel = 0; pixel < 8; pixel++) |
| 550 | { |
| 551 | //get first symbol context |
| 552 | UINT32 a = ((out0 >> (0 * 4)) & 15); |
| 553 | UINT32 b = ((out0 >> (7 * 4)) & 15); |
| 554 | UINT32 c = ((out1 >> (0 * 4)) & 15); |
| 555 | UINT32 con = 0; |
| 556 | UINT32 refcon = (a == b) ? (b != c) : (b == c) ? 2 : 4 - (a == c); |
| 557 | UINT32 bit; |
| 558 | |
| 559 | //update pixel order |
| 560 | UINT32 m, n; |
| 561 | for(m = 0; m < 16; m++) |
| 562 | { |
| 563 | if(pixelorder[m] == a) |
| 564 | { |
| 565 | break; |
| 566 | } |
| 567 | } |
| 568 | for(n = m; n > 0; n--) |
| 569 | { |
| 570 | pixelorder[n] = pixelorder[n - 1]; |
| 571 | } |
| 572 | pixelorder[0] = a; |
| 573 | |
| 574 | //calculate the real pixel order |
| 575 | for(m = 0; m < 16; m++) |
| 576 | { |
| 577 | realorder[m] = pixelorder[m]; |
| 578 | } |
| 579 | |
| 580 | //rotate reference pixel c value to top |
| 581 | for(m = 0; m < 16; m++) |
| 582 | { |
| 583 | if(realorder[m] == c) |
| 584 | { |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | for(n = m; n > 0; n--) |
| 589 | { |
| 590 | realorder[n] = realorder[n - 1]; |
| 591 | } |
| 592 | realorder[0] = c; |
| 593 | |
| 594 | //rotate reference pixel b value to top |
| 595 | for(m = 0; m < 16; m++) |
| 596 | { |
| 597 | if(realorder[m] == b) |
| 598 | { |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | for(n = m; n > 0; n--) |
| 603 | { |
| 604 | realorder[n] = realorder[n - 1]; |
| 605 | } |
| 606 | realorder[0] = b; |
| 607 | |
| 608 | //rotate reference pixel a value to top |
| 609 | for(m = 0; m < 16; m++) |
| 610 | { |
| 611 | if(realorder[m] == a) |
| 612 | { |
| 613 | break; |
| 614 | } |
| 615 | } |
| 616 | for(n = m; n > 0; n--) |
| 617 | { |
| 618 | realorder[n] = realorder[n - 1]; |
| 619 | } |
| 620 | realorder[0] = a; |
| 621 | |
| 622 | //get 4 symbols |
| 623 | for(bit = 0; bit < 4; bit++) |
| 624 | { |
| 625 | UINT32 invertbit, shift; |
| 626 | |
| 627 | //get prob |
| 628 | UINT32 prob = SPC7110Decomp_probability(thisptr, con); |
| 629 | |
| 630 | //get symbol |
| 631 | UINT32 flag_lps; |
| 632 | if(val <= span - prob) //mps |
| 633 | { |
| 634 | span = span - prob; |
| 635 | flag_lps = 0; |
| 636 | } |
| 637 | else //lps |
| 638 | { |
| 639 | val = val - (span - (prob - 1)); |
| 640 | span = prob - 1; |
| 641 | flag_lps = 1; |
| 642 | } |
| 643 | |
| 644 | //renormalize |
| 645 | shift = 0; |
| 646 | while(span < 0x7f) |
| 647 | { |
| 648 | shift++; |
| 649 | |
| 650 | span = (span << 1) + 1; |
| 651 | val = (val << 1) + (in >> 7); |
| 652 | |
| 653 | in <<= 1; |
| 654 | if(--in_count == 0) |
| 655 | { |
| 656 | in = SPC7110Decomp_dataread(thisptr); |
| 657 | in_count = 8; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | //update processing info |
| 662 | lps = (lps << 1) + flag_lps; |
| 663 | invertbit = thisptr->context[con].invert; |
| 664 | inverts = (inverts << 1) + invertbit; |
| 665 | |
| 666 | //update context state |
| 667 | if(flag_lps & SPC7110Decomp_toggle_invert(thisptr, con)) |
| 668 | { |
| 669 | thisptr->context[con].invert ^= 1; |
| 670 | } |
| 671 | if(flag_lps) |
| 672 | { |
| 673 | thisptr->context[con].index = SPC7110Decomp_next_lps(thisptr, con); |
| 674 | } |
| 675 | else if(shift) |
| 676 | { |
| 677 | thisptr->context[con].index = SPC7110Decomp_next_mps(thisptr, con); |
| 678 | } |
| 679 | |
| 680 | //get next context |
| 681 | con = spc7110_mode2_context_table[con][flag_lps ^ invertbit] + (con == 1 ? refcon : 0); |
| 682 | } |
| 683 | |
| 684 | //get pixel |
| 685 | b = realorder[(lps ^ inverts) & 0x0f]; |
| 686 | out1 = (out1 << 4) + ((out0 >> 28) & 0x0f); |
| 687 | out0 = (out0 << 4) + b; |
| 688 | } |
| 689 | |
| 690 | //convert pixel data into bitplanes |
| 691 | data = SPC7110Decomp_morton_4x8(thisptr, out0); |
| 692 | SPC7110Decomp_write(thisptr, data >> 24); |
| 693 | SPC7110Decomp_write(thisptr, data >> 16); |
| 694 | bitplanebuffer[buffer_index++] = data >> 8; |
| 695 | bitplanebuffer[buffer_index++] = data >> 0; |
| 696 | |
| 697 | if(buffer_index == 16) |
| 698 | { |
| 699 | UINT32 i; |
| 700 | for(i = 0; i < 16; i++) |
| 701 | { |
| 702 | SPC7110Decomp_write(thisptr, bitplanebuffer[i]); |
| 703 | } |
| 704 | buffer_index = 0; |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | static UINT8 SPC7110Decomp_probability(SPC7110Decomp *thisptr, UINT32 n) |
| 710 | { |
| 711 | return spc7110_evolution_table[thisptr->context[n].index][0]; |
| 712 | } |
| 713 | |
| 714 | static UINT8 SPC7110Decomp_next_lps(SPC7110Decomp *thisptr, UINT32 n) |
| 715 | { |
| 716 | return spc7110_evolution_table[thisptr->context[n].index][1]; |
| 717 | } |
| 718 | |
| 719 | static UINT8 SPC7110Decomp_next_mps(SPC7110Decomp *thisptr, UINT32 n) |
| 720 | { |
| 721 | return spc7110_evolution_table[thisptr->context[n].index][2]; |
| 722 | } |
| 723 | |
| 724 | static UINT8 SPC7110Decomp_toggle_invert(SPC7110Decomp *thisptr, UINT32 n) |
| 725 | { |
| 726 | return spc7110_evolution_table[thisptr->context[n].index][3]; |
| 727 | } |
| 728 | |
| 729 | static UINT32 SPC7110Decomp_morton_2x8(SPC7110Decomp *thisptr, UINT32 data) |
| 730 | { |
| 731 | //reverse morton lookup: de-interleave two 8-bit values |
| 732 | //15, 13, 11, 9, 7, 5, 3, 1 -> 15- 8 |
| 733 | //14, 12, 10, 8, 6, 4, 2, 0 -> 7- 0 |
| 734 | return thisptr->morton16[0][(data >> 0) & 255] + thisptr->morton16[1][(data >> 8) & 255]; |
| 735 | } |
| 736 | |
| 737 | static UINT32 SPC7110Decomp_morton_4x8(SPC7110Decomp *thisptr, UINT32 data) |
| 738 | { |
| 739 | //reverse morton lookup: de-interleave four 8-bit values |
| 740 | //31, 27, 23, 19, 15, 11, 7, 3 -> 31-24 |
| 741 | //30, 26, 22, 18, 14, 10, 6, 2 -> 23-16 |
| 742 | //29, 25, 21, 17, 13, 9, 5, 1 -> 15- 8 |
| 743 | //28, 24, 20, 16, 12, 8, 4, 0 -> 7- 0 |
| 744 | return thisptr->morton32[0][(data >> 0) & 255] + thisptr->morton32[1][(data >> 8) & 255] |
| 745 | + thisptr->morton32[2][(data >> 16) & 255] + thisptr->morton32[3][(data >> 24) & 255]; |
| 746 | } |
| 747 | |
| 748 | static void spc7110_mmio_write(running_machine *machine, UINT32 addr, UINT8 data); |
| 749 | static UINT8 spc7110_mmio_read(running_machine *machine, UINT32 addr); |
| 750 | |
| 751 | enum RTC_State |
| 752 | { |
| 753 | RTCS_Inactive, |
| 754 | RTCS_ModeSelect, |
| 755 | RTCS_IndexSelect, |
| 756 | RTCS_Write |
| 757 | }; |
| 758 | |
| 759 | enum RTC_Mode |
| 760 | { |
| 761 | RTCM_Linear = 0x03, |
| 762 | RTCM_Indexed = 0x0c |
| 763 | }; |
| 764 | |
| 765 | static const UINT32 spc7110_months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
| 766 | |
| 767 | typedef struct |
| 768 | { |
| 769 | //================== |
| 770 | //decompression unit |
| 771 | //================== |
| 772 | UINT8 r4801; // compression table low |
| 773 | UINT8 r4802; // compression table high |
| 774 | UINT8 r4803; // compression table bank |
| 775 | UINT8 r4804; // compression table index |
| 776 | UINT8 r4805; // decompression buffer index low |
| 777 | UINT8 r4806; // decompression buffer index high |
| 778 | UINT8 r4807; // ??? |
| 779 | UINT8 r4808; // ??? |
| 780 | UINT8 r4809; // compression length low |
| 781 | UINT8 r480a; // compression length high |
| 782 | UINT8 r480b; // decompression control register |
| 783 | UINT8 r480c; // decompression status |
| 784 | |
| 785 | SPC7110Decomp* decomp; |
| 786 | |
| 787 | UINT8 r4811; // data pointer low |
| 788 | UINT8 r4812; // data pointer high |
| 789 | UINT8 r4813; // data pointer bank |
| 790 | UINT8 r4814; // data adjust low |
| 791 | UINT8 r4815; // data adjust high |
| 792 | UINT8 r4816; // data increment low |
| 793 | UINT8 r4817; // data increment high |
| 794 | UINT8 r4818; // data port control register |
| 795 | |
| 796 | UINT8 r481x; |
| 797 | |
| 798 | UINT8 r4814_latch; |
| 799 | UINT8 r4815_latch; |
| 800 | |
| 801 | //========= |
| 802 | //math unit |
| 803 | //========= |
| 804 | UINT8 r4820; // 16-bit multiplicand B0, 32-bit dividend B0 |
| 805 | UINT8 r4821; // 16-bit multiplicand B1, 32-bit dividend B1 |
| 806 | UINT8 r4822; // 32-bit dividend B2 |
| 807 | UINT8 r4823; // 32-bit dividend B3 |
| 808 | UINT8 r4824; // 16-bit multiplier B0 |
| 809 | UINT8 r4825; // 16-bit multiplier B1 |
| 810 | UINT8 r4826; // 16-bit divisor B0 |
| 811 | UINT8 r4827; // 16-bit divisor B1 |
| 812 | UINT8 r4828; // 32-bit product B0, 32-bit quotient B0 |
| 813 | UINT8 r4829; // 32-bit product B1, 32-bit quotient B1 |
| 814 | UINT8 r482a; // 32-bit product B2, 32-bit quotient B2 |
| 815 | UINT8 r482b; // 32-bit product B3, 32-bit quotient B3 |
| 816 | UINT8 r482c; // 16-bit remainder B0 |
| 817 | UINT8 r482d; // 16-bit remainder B1 |
| 818 | UINT8 r482e; // math control register |
| 819 | UINT8 r482f; // math status |
| 820 | |
| 821 | //=================== |
| 822 | //memory mapping unit |
| 823 | //=================== |
| 824 | UINT8 r4830; // SRAM write enable |
| 825 | UINT8 r4831; // $[d0-df]:[0000-ffff] mapping |
| 826 | UINT8 r4832; // $[e0-ef]:[0000-ffff] mapping |
| 827 | UINT8 r4833; // $[f0-ff]:[0000-ffff] mapping |
| 828 | UINT8 r4834; // ??? |
| 829 | |
| 830 | UINT32 dx_offset; |
| 831 | UINT32 ex_offset; |
| 832 | UINT32 fx_offset; |
| 833 | |
| 834 | //==================== |
| 835 | //real-time clock unit |
| 836 | //==================== |
| 837 | UINT8 r4840; // RTC latch |
| 838 | UINT8 r4841; // RTC index/data port |
| 839 | UINT8 r4842; // RTC status |
| 840 | |
| 841 | UINT32 rtc_state; |
| 842 | UINT32 rtc_mode; |
| 843 | UINT32 rtc_index; |
| 844 | |
| 845 | } _snes_spc7110_t; |
| 846 | |
| 847 | static _snes_spc7110_t snes_spc7110; |
| 848 | |
| 849 | static void spc7110_init(running_machine* machine) |
| 850 | { |
| 851 | snes_spc7110.r4801 = 0x00; |
| 852 | snes_spc7110.r4802 = 0x00; |
| 853 | snes_spc7110.r4803 = 0x00; |
| 854 | snes_spc7110.r4804 = 0x00; |
| 855 | snes_spc7110.r4805 = 0x00; |
| 856 | snes_spc7110.r4806 = 0x00; |
| 857 | snes_spc7110.r4807 = 0x00; |
| 858 | snes_spc7110.r4808 = 0x00; |
| 859 | snes_spc7110.r4809 = 0x00; |
| 860 | snes_spc7110.r480a = 0x00; |
| 861 | snes_spc7110.r480b = 0x00; |
| 862 | snes_spc7110.r480c = 0x00; |
| 863 | |
| 864 | snes_spc7110.r4811 = 0x00; |
| 865 | snes_spc7110.r4812 = 0x00; |
| 866 | snes_spc7110.r4813 = 0x00; |
| 867 | snes_spc7110.r4814 = 0x00; |
| 868 | snes_spc7110.r4815 = 0x00; |
| 869 | snes_spc7110.r4816 = 0x00; |
| 870 | snes_spc7110.r4817 = 0x00; |
| 871 | snes_spc7110.r4818 = 0x00; |
| 872 | |
| 873 | snes_spc7110.r481x = 0x00; |
| 874 | snes_spc7110.r4814_latch = 0; |
| 875 | snes_spc7110.r4815_latch = 0; |
| 876 | |
| 877 | snes_spc7110.r4820 = 0x00; |
| 878 | snes_spc7110.r4821 = 0x00; |
| 879 | snes_spc7110.r4822 = 0x00; |
| 880 | snes_spc7110.r4823 = 0x00; |
| 881 | snes_spc7110.r4824 = 0x00; |
| 882 | snes_spc7110.r4825 = 0x00; |
| 883 | snes_spc7110.r4826 = 0x00; |
| 884 | snes_spc7110.r4827 = 0x00; |
| 885 | snes_spc7110.r4828 = 0x00; |
| 886 | snes_spc7110.r4829 = 0x00; |
| 887 | snes_spc7110.r482a = 0x00; |
| 888 | snes_spc7110.r482b = 0x00; |
| 889 | snes_spc7110.r482c = 0x00; |
| 890 | snes_spc7110.r482d = 0x00; |
| 891 | snes_spc7110.r482e = 0x00; |
| 892 | snes_spc7110.r482f = 0x00; |
| 893 | |
| 894 | snes_spc7110.r4830 = 0x00; |
| 895 | spc7110_mmio_write(machine, 0x4831, 0); |
| 896 | spc7110_mmio_write(machine, 0x4832, 1); |
| 897 | spc7110_mmio_write(machine, 0x4833, 2); |
| 898 | snes_spc7110.r4834 = 0x00; |
| 899 | |
| 900 | snes_spc7110.r4840 = 0x00; |
| 901 | snes_spc7110.r4841 = 0x00; |
| 902 | snes_spc7110.r4842 = 0x00; |
| 903 | |
| 904 | snes_spc7110.decomp = SPC7110Decomp_ctor(machine); |
| 905 | } |
| 906 | |
| 907 | static UINT32 spc7110_datarom_addr(UINT32 addr) |
| 908 | { |
| 909 | UINT32 size = snes_rom_size - 0x100000; |
| 910 | while(addr >= size) |
| 911 | { |
| 912 | addr -= size; |
| 913 | } |
| 914 | return addr + 0x100000; |
| 915 | } |
| 916 | |
| 917 | static UINT32 spc7110_data_pointer(void) |
| 918 | { |
| 919 | return snes_spc7110.r4811 + (snes_spc7110.r4812 << 8) + (snes_spc7110.r4813 << 16); |
| 920 | } |
| 921 | |
| 922 | static UINT32 spc7110_data_adjust(void) |
| 923 | { |
| 924 | return snes_spc7110.r4814 + (snes_spc7110.r4815 << 8); |
| 925 | } |
| 926 | |
| 927 | static UINT32 spc7110_data_increment(void) |
| 928 | { |
| 929 | return snes_spc7110.r4816 + (snes_spc7110.r4817 << 8); |
| 930 | } |
| 931 | |
| 932 | static void spc7110_set_data_pointer(UINT32 addr) |
| 933 | { |
| 934 | snes_spc7110.r4811 = addr; |
| 935 | snes_spc7110.r4812 = addr >> 8; |
| 936 | snes_spc7110.r4813 = addr >> 16; |
| 937 | } |
| 938 | |
| 939 | static void spc7110_set_data_adjust(UINT32 addr) |
| 940 | { |
| 941 | snes_spc7110.r4814 = addr; |
| 942 | snes_spc7110.r4815 = addr >> 8; |
| 943 | } |
| 944 | |
| 945 | static UINT8 spc7110_mmio_read(running_machine *machine, UINT32 addr) |
| 946 | { |
| 947 | UINT8 *ROM = memory_region(machine, "cart"); |
| 948 | |
| 949 | addr &= 0xffff; |
| 950 | |
| 951 | switch(addr) |
| 952 | { |
| 953 | //================== |
| 954 | //decompression unit |
| 955 | //================== |
| 956 | |
| 957 | case 0x4800: |
| 958 | { |
| 959 | UINT16 counter = (snes_spc7110.r4809 + (snes_spc7110.r480a << 8)); |
| 960 | counter--; |
| 961 | snes_spc7110.r4809 = counter; |
| 962 | snes_spc7110.r480a = counter >> 8; |
| 963 | return SPC7110Decomp_read(snes_spc7110.decomp); |
| 964 | } |
| 965 | case 0x4801: return snes_spc7110.r4801; |
| 966 | case 0x4802: return snes_spc7110.r4802; |
| 967 | case 0x4803: return snes_spc7110.r4803; |
| 968 | case 0x4804: return snes_spc7110.r4804; |
| 969 | case 0x4805: return snes_spc7110.r4805; |
| 970 | case 0x4806: return snes_spc7110.r4806; |
| 971 | case 0x4807: return snes_spc7110.r4807; |
| 972 | case 0x4808: return snes_spc7110.r4808; |
| 973 | case 0x4809: return snes_spc7110.r4809; |
| 974 | case 0x480a: return snes_spc7110.r480a; |
| 975 | case 0x480b: return snes_spc7110.r480b; |
| 976 | case 0x480c: |
| 977 | { |
| 978 | UINT8 status = snes_spc7110.r480c; |
| 979 | snes_spc7110.r480c &= 0x7f; |
| 980 | return status; |
| 981 | } |
| 982 | |
| 983 | //============== |
| 984 | //data port unit |
| 985 | //============== |
| 986 | |
| 987 | case 0x4810: |
| 988 | { |
| 989 | UINT8 data; |
| 990 | UINT32 addr, adjust, adjustaddr; |
| 991 | |
| 992 | if(snes_spc7110.r481x != 0x07) return 0x00; |
| 993 | |
| 994 | addr = spc7110_data_pointer(); |
| 995 | adjust = spc7110_data_adjust(); |
| 996 | if(snes_spc7110.r4818 & 8) |
| 997 | { |
| 998 | adjust = (INT16)adjust; //16-bit sign extend |
| 999 | } |
| 1000 | |
| 1001 | adjustaddr = addr; |
| 1002 | if(snes_spc7110.r4818 & 2) |
| 1003 | { |
| 1004 | adjustaddr += adjust; |
| 1005 | spc7110_set_data_adjust(adjust + 1); |
| 1006 | } |
| 1007 | |
| 1008 | data = ROM[spc7110_datarom_addr(adjustaddr)]; |
| 1009 | if(!(snes_spc7110.r4818 & 2)) |
| 1010 | { |
| 1011 | UINT32 increment = (snes_spc7110.r4818 & 1) ? spc7110_data_increment() : 1; |
| 1012 | if(snes_spc7110.r4818 & 4) |
| 1013 | { |
| 1014 | increment = (INT16)increment; //16-bit sign extend |
| 1015 | } |
| 1016 | |
| 1017 | if((snes_spc7110.r4818 & 16) == 0) |
| 1018 | { |
| 1019 | spc7110_set_data_pointer(addr + increment); |
| 1020 | } |
| 1021 | else |
| 1022 | { |
| 1023 | spc7110_set_data_adjust(adjust + increment); |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | return data; |
| 1028 | } |
| 1029 | case 0x4811: return snes_spc7110.r4811; |
| 1030 | case 0x4812: return snes_spc7110.r4812; |
| 1031 | case 0x4813: return snes_spc7110.r4813; |
| 1032 | case 0x4814: return snes_spc7110.r4814; |
| 1033 | case 0x4815: return snes_spc7110.r4815; |
| 1034 | case 0x4816: return snes_spc7110.r4816; |
| 1035 | case 0x4817: return snes_spc7110.r4817; |
| 1036 | case 0x4818: return snes_spc7110.r4818; |
| 1037 | case 0x481a: |
| 1038 | { |
| 1039 | UINT8 data; |
| 1040 | UINT32 addr, adjust; |
| 1041 | if(snes_spc7110.r481x != 0x07) |
| 1042 | { |
| 1043 | return 0x00; |
| 1044 | } |
| 1045 | |
| 1046 | addr = spc7110_data_pointer(); |
| 1047 | adjust = spc7110_data_adjust(); |
| 1048 | if(snes_spc7110.r4818 & 8) |
| 1049 | { |
| 1050 | adjust = (INT16)adjust; //16-bit sign extend |
| 1051 | } |
| 1052 | |
| 1053 | data = ROM[spc7110_datarom_addr(addr + adjust)]; |
| 1054 | if((snes_spc7110.r4818 & 0x60) == 0x60) |
| 1055 | { |
| 1056 | if((snes_spc7110.r4818 & 16) == 0) |
| 1057 | { |
| 1058 | spc7110_set_data_pointer(addr + adjust); |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | spc7110_set_data_adjust(adjust + adjust); |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | return data; |
| 1067 | } |
| 1068 | |
| 1069 | //========= |
| 1070 | //math unit |
| 1071 | //========= |
| 1072 | |
| 1073 | case 0x4820: return snes_spc7110.r4820; |
| 1074 | case 0x4821: return snes_spc7110.r4821; |
| 1075 | case 0x4822: return snes_spc7110.r4822; |
| 1076 | case 0x4823: return snes_spc7110.r4823; |
| 1077 | case 0x4824: return snes_spc7110.r4824; |
| 1078 | case 0x4825: return snes_spc7110.r4825; |
| 1079 | case 0x4826: return snes_spc7110.r4826; |
| 1080 | case 0x4827: return snes_spc7110.r4827; |
| 1081 | case 0x4828: return snes_spc7110.r4828; |
| 1082 | case 0x4829: return snes_spc7110.r4829; |
| 1083 | case 0x482a: return snes_spc7110.r482a; |
| 1084 | case 0x482b: return snes_spc7110.r482b; |
| 1085 | case 0x482c: return snes_spc7110.r482c; |
| 1086 | case 0x482d: return snes_spc7110.r482d; |
| 1087 | case 0x482e: return snes_spc7110.r482e; |
| 1088 | case 0x482f: |
| 1089 | { |
| 1090 | UINT8 status = snes_spc7110.r482f; |
| 1091 | snes_spc7110.r482f &= 0x7f; |
| 1092 | return status; |
| 1093 | } |
| 1094 | |
| 1095 | //=================== |
| 1096 | //memory mapping unit |
| 1097 | //=================== |
| 1098 | |
| 1099 | case 0x4830: return snes_spc7110.r4830; |
| 1100 | case 0x4831: return snes_spc7110.r4831; |
| 1101 | case 0x4832: return snes_spc7110.r4832; |
| 1102 | case 0x4833: return snes_spc7110.r4833; |
| 1103 | case 0x4834: return snes_spc7110.r4834; |
| 1104 | |
| 1105 | } |
| 1106 | |
| 1107 | return 0xff; |
| 1108 | } |
| 1109 | |
| 1110 | static void spc7110_mmio_write(running_machine *machine, UINT32 addr, UINT8 data) |
| 1111 | { |
| 1112 | UINT8 *ROM = memory_region(machine, "cart"); |
| 1113 | |
| 1114 | addr &= 0xffff; |
| 1115 | |
| 1116 | switch(addr) |
| 1117 | { |
| 1118 | //================== |
| 1119 | //decompression unit |
| 1120 | //================== |
| 1121 | |
| 1122 | case 0x4801: snes_spc7110.r4801 = data; break; |
| 1123 | case 0x4802: snes_spc7110.r4802 = data; break; |
| 1124 | case 0x4803: snes_spc7110.r4803 = data; break; |
| 1125 | case 0x4804: snes_spc7110.r4804 = data; break; |
| 1126 | case 0x4805: snes_spc7110.r4805 = data; break; |
| 1127 | case 0x4806: |
| 1128 | { |
| 1129 | UINT32 table, index, length, addr, mode, offset; |
| 1130 | snes_spc7110.r4806 = data; |
| 1131 | |
| 1132 | table = (snes_spc7110.r4801 + (snes_spc7110.r4802 << 8) + (snes_spc7110.r4803 << 16)); |
| 1133 | index = (snes_spc7110.r4804 << 2); |
| 1134 | length = (snes_spc7110.r4809 + (snes_spc7110.r480a << 8)); |
| 1135 | addr = spc7110_datarom_addr(table + index); |
| 1136 | mode = (ROM[addr + 0]); |
| 1137 | offset = (ROM[addr + 1] << 16) |
| 1138 | + (ROM[addr + 2] << 8) |
| 1139 | + (ROM[addr + 3] << 0); |
| 1140 | |
| 1141 | SPC7110Decomp_init(snes_spc7110.decomp, machine, mode, offset, (snes_spc7110.r4805 + (snes_spc7110.r4806 << 8)) << mode); |
| 1142 | snes_spc7110.r480c = 0x80; |
| 1143 | } break; |
| 1144 | |
| 1145 | case 0x4807: snes_spc7110.r4807 = data; break; |
| 1146 | case 0x4808: snes_spc7110.r4808 = data; break; |
| 1147 | case 0x4809: snes_spc7110.r4809 = data; break; |
| 1148 | case 0x480a: snes_spc7110.r480a = data; break; |
| 1149 | case 0x480b: snes_spc7110.r480b = data; break; |
| 1150 | |
| 1151 | //============== |
| 1152 | //data port unit |
| 1153 | //============== |
| 1154 | |
| 1155 | case 0x4811: snes_spc7110.r4811 = data; snes_spc7110.r481x |= 0x01; break; |
| 1156 | case 0x4812: snes_spc7110.r4812 = data; snes_spc7110.r481x |= 0x02; break; |
| 1157 | case 0x4813: snes_spc7110.r4813 = data; snes_spc7110.r481x |= 0x04; break; |
| 1158 | case 0x4814: |
| 1159 | { |
| 1160 | snes_spc7110.r4814 = data; |
| 1161 | snes_spc7110.r4814_latch = 1; |
| 1162 | if(!snes_spc7110.r4815_latch) |
| 1163 | { |
| 1164 | break; |
| 1165 | } |
| 1166 | if(!(snes_spc7110.r4818 & 2)) |
| 1167 | { |
| 1168 | break; |
| 1169 | } |
| 1170 | if(snes_spc7110.r4818 & 0x10) |
| 1171 | { |
| 1172 | break; |
| 1173 | } |
| 1174 | |
| 1175 | if((snes_spc7110.r4818 & 0x60) == 0x20) |
| 1176 | { |
| 1177 | UINT32 increment = spc7110_data_adjust() & 0xff; |
| 1178 | if(snes_spc7110.r4818 & 8) |
| 1179 | { |
| 1180 | increment = (INT8)increment; //8-bit sign extend |
| 1181 | } |
| 1182 | spc7110_set_data_pointer(spc7110_data_pointer() + increment); |
| 1183 | } |
| 1184 | else if((snes_spc7110.r4818 & 0x60) == 0x40) |
| 1185 | { |
| 1186 | UINT32 increment = spc7110_data_adjust(); |
| 1187 | if(snes_spc7110.r4818 & 8) |
| 1188 | { |
| 1189 | increment = (INT16)increment; //16-bit sign extend |
| 1190 | } |
| 1191 | spc7110_set_data_pointer(spc7110_data_pointer() + increment); |
| 1192 | } |
| 1193 | break; |
| 1194 | } |
| 1195 | |
| 1196 | case 0x4815: |
| 1197 | { |
| 1198 | snes_spc7110.r4815 = data; |
| 1199 | snes_spc7110.r4815_latch = 1; |
| 1200 | if(!snes_spc7110.r4814_latch) |
| 1201 | { |
| 1202 | break; |
| 1203 | } |
| 1204 | if(!(snes_spc7110.r4818 & 2)) |
| 1205 | { |
| 1206 | break; |
| 1207 | } |
| 1208 | if(snes_spc7110.r4818 & 0x10) |
| 1209 | { |
| 1210 | break; |
| 1211 | } |
| 1212 | |
| 1213 | if((snes_spc7110.r4818 & 0x60) == 0x20) |
| 1214 | { |
| 1215 | UINT32 increment = spc7110_data_adjust() & 0xff; |
| 1216 | if(snes_spc7110.r4818 & 8) |
| 1217 | { |
| 1218 | increment = (INT8)increment; //8-bit sign extend |
| 1219 | } |
| 1220 | spc7110_set_data_pointer(spc7110_data_pointer() + increment); |
| 1221 | } |
| 1222 | else if((snes_spc7110.r4818 & 0x60) == 0x40) |
| 1223 | { |
| 1224 | UINT32 increment = spc7110_data_adjust(); |
| 1225 | if(snes_spc7110.r4818 & 8) |
| 1226 | { |
| 1227 | increment = (INT16)increment; //16-bit sign extend |
| 1228 | } |
| 1229 | spc7110_set_data_pointer(spc7110_data_pointer() + increment); |
| 1230 | } |
| 1231 | break; |
| 1232 | } |
| 1233 | |
| 1234 | case 0x4816: snes_spc7110.r4816 = data; break; |
| 1235 | case 0x4817: snes_spc7110.r4817 = data; break; |
| 1236 | case 0x4818: |
| 1237 | { |
| 1238 | if(snes_spc7110.r481x != 0x07) break; |
| 1239 | |
| 1240 | snes_spc7110.r4818 = data; |
| 1241 | snes_spc7110.r4814_latch = snes_spc7110.r4815_latch = 0; |
| 1242 | break; |
| 1243 | } |
| 1244 | |
| 1245 | //========= |
| 1246 | //math unit |
| 1247 | //========= |
| 1248 | |
| 1249 | case 0x4820: snes_spc7110.r4820 = data; break; |
| 1250 | case 0x4821: snes_spc7110.r4821 = data; break; |
| 1251 | case 0x4822: snes_spc7110.r4822 = data; break; |
| 1252 | case 0x4823: snes_spc7110.r4823 = data; break; |
| 1253 | case 0x4824: snes_spc7110.r4824 = data; break; |
| 1254 | case 0x4825: |
| 1255 | { |
| 1256 | snes_spc7110.r4825 = data; |
| 1257 | |
| 1258 | if(snes_spc7110.r482e & 1) { |
| 1259 | //signed 16-bit x 16-bit multiplication |
| 1260 | INT16 r0 = (INT16)(snes_spc7110.r4824 + (snes_spc7110.r4825 << 8)); |
| 1261 | INT16 r1 = (INT16)(snes_spc7110.r4820 + (snes_spc7110.r4821 << 8)); |
| 1262 | |
| 1263 | INT32 result = r0 * r1; |
| 1264 | snes_spc7110.r4828 = result; |
| 1265 | snes_spc7110.r4829 = result >> 8; |
| 1266 | snes_spc7110.r482a = result >> 16; |
| 1267 | snes_spc7110.r482b = result >> 24; |
| 1268 | } else { |
| 1269 | //unsigned 16-bit x 16-bit multiplication |
| 1270 | UINT16 r0 = (UINT16)(snes_spc7110.r4824 + (snes_spc7110.r4825 << 8)); |
| 1271 | UINT16 r1 = (UINT16)(snes_spc7110.r4820 + (snes_spc7110.r4821 << 8)); |
| 1272 | |
| 1273 | UINT32 result = r0 * r1; |
| 1274 | snes_spc7110.r4828 = result; |
| 1275 | snes_spc7110.r4829 = result >> 8; |
| 1276 | snes_spc7110.r482a = result >> 16; |
| 1277 | snes_spc7110.r482b = result >> 24; |
| 1278 | } |
| 1279 | |
| 1280 | snes_spc7110.r482f = 0x80; |
| 1281 | break; |
| 1282 | } |
| 1283 | |
| 1284 | case 0x4826: snes_spc7110.r4826 = data; break; |
| 1285 | case 0x4827: |
| 1286 | { |
| 1287 | snes_spc7110.r4827 = data; |
| 1288 | |
| 1289 | if(snes_spc7110.r482e & 1) |
| 1290 | { |
| 1291 | //signed 32-bit x 16-bit division |
| 1292 | INT32 dividend = (INT32)(snes_spc7110.r4820 + (snes_spc7110.r4821 << 8) + (snes_spc7110.r4822 << 16) + (snes_spc7110.r4823 << 24)); |
| 1293 | INT16 divisor = (INT16)(snes_spc7110.r4826 + (snes_spc7110.r4827 << 8)); |
| 1294 | |
| 1295 | INT32 quotient; |
| 1296 | INT16 remainder; |
| 1297 | |
| 1298 | if(divisor) |
| 1299 | { |
| 1300 | quotient = (INT32)(dividend / divisor); |
| 1301 | remainder = (INT32)(dividend % divisor); |
| 1302 | } |
| 1303 | else |
| 1304 | { |
| 1305 | //illegal division by zero |
| 1306 | quotient = 0; |
| 1307 | remainder = dividend & 0xffff; |
| 1308 | } |
| 1309 | |
| 1310 | snes_spc7110.r4828 = quotient; |
| 1311 | snes_spc7110.r4829 = quotient >> 8; |
| 1312 | snes_spc7110.r482a = quotient >> 16; |
| 1313 | snes_spc7110.r482b = quotient >> 24; |
| 1314 | |
| 1315 | snes_spc7110.r482c = remainder; |
| 1316 | snes_spc7110.r482d = remainder >> 8; |
| 1317 | } |
| 1318 | else |
| 1319 | { |
| 1320 | //unsigned 32-bit x 16-bit division |
| 1321 | UINT32 dividend = (UINT32)(snes_spc7110.r4820 + (snes_spc7110.r4821 << 8) + (snes_spc7110.r4822 << 16) + (snes_spc7110.r4823 << 24)); |
| 1322 | UINT16 divisor = (UINT16)(snes_spc7110.r4826 + (snes_spc7110.r4827 << 8)); |
| 1323 | |
| 1324 | UINT32 quotient; |
| 1325 | UINT16 remainder; |
| 1326 | |
| 1327 | if(divisor) |
| 1328 | { |
| 1329 | quotient = (UINT32)(dividend / divisor); |
| 1330 | remainder = (UINT16)(dividend % divisor); |
| 1331 | } |
| 1332 | else |
| 1333 | { |
| 1334 | //illegal division by zero |
| 1335 | quotient = 0; |
| 1336 | remainder = dividend & 0xffff; |
| 1337 | } |
| 1338 | |
| 1339 | snes_spc7110.r4828 = quotient; |
| 1340 | snes_spc7110.r4829 = quotient >> 8; |
| 1341 | snes_spc7110.r482a = quotient >> 16; |
| 1342 | snes_spc7110.r482b = quotient >> 24; |
| 1343 | |
| 1344 | snes_spc7110.r482c = remainder; |
| 1345 | snes_spc7110.r482d = remainder >> 8; |
| 1346 | } |
| 1347 | |
| 1348 | snes_spc7110.r482f = 0x80; |
| 1349 | break; |
| 1350 | } |
| 1351 | |
| 1352 | case 0x482e: |
| 1353 | { |
| 1354 | //reset math unit |
| 1355 | snes_spc7110.r4820 = snes_spc7110.r4821 = snes_spc7110.r4822 = snes_spc7110.r4823 = 0; |
| 1356 | snes_spc7110.r4824 = snes_spc7110.r4825 = snes_spc7110.r4826 = snes_spc7110.r4827 = 0; |
| 1357 | snes_spc7110.r4828 = snes_spc7110.r4829 = snes_spc7110.r482a = snes_spc7110.r482b = 0; |
| 1358 | snes_spc7110.r482c = snes_spc7110.r482d = 0; |
| 1359 | |
| 1360 | snes_spc7110.r482e = data; |
| 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | //=================== |
| 1365 | //memory mapping unit |
| 1366 | //=================== |
| 1367 | |
| 1368 | case 0x4830: snes_spc7110.r4830 = data; break; |
| 1369 | |
| 1370 | case 0x4831: |
| 1371 | { |
| 1372 | snes_spc7110.r4831 = data; |
| 1373 | snes_spc7110.dx_offset = spc7110_datarom_addr((data & 7) * 0x100000); |
| 1374 | break; |
| 1375 | } |
| 1376 | |
| 1377 | case 0x4832: |
| 1378 | { |
| 1379 | snes_spc7110.r4832 = data; |
| 1380 | snes_spc7110.ex_offset = spc7110_datarom_addr((data & 7) * 0x100000); |
| 1381 | break; |
| 1382 | } |
| 1383 | |
| 1384 | case 0x4833: |
| 1385 | { |
| 1386 | snes_spc7110.r4833 = data; |
| 1387 | snes_spc7110.fx_offset = spc7110_datarom_addr((data & 7) * 0x100000); |
| 1388 | break; |
| 1389 | } |
| 1390 | |
| 1391 | case 0x4834: snes_spc7110.r4834 = data; break; |
| 1392 | } |
| 1393 | } |
src/mame/machine/snesst10.c
| r0 | r5808 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | snesst10.c |
| 4 | |
| 5 | File to handle emulation of the SNES "Seta ST-010" add-on chip. |
| 6 | |
| 7 | Code based on original work by The Dumper, Matthew Kendora, |
| 8 | Overload and Feather. |
| 9 | This implementation is based on byuu's BSNES C++ version |
| 10 | |
| 11 | ***************************************************************************/ |
| 12 | |
| 13 | typedef struct |
| 14 | { |
| 15 | INT16 x1, y1, quadrant, theta, o1; |
| 16 | UINT8 *ram; |
| 17 | } _snes_st010_t; |
| 18 | |
| 19 | static _snes_st010_t snes_st010; |
| 20 | |
| 21 | static const INT16 st010_sin_table[256] = { |
| 22 | 0x0000, 0x0324, 0x0648, 0x096a, 0x0c8c, 0x0fab, 0x12c8, 0x15e2, |
| 23 | 0x18f9, 0x1c0b, 0x1f1a, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, |
| 24 | 0x30fb, 0x33df, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, |
| 25 | 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, |
| 26 | 0x5a82, 0x5cb3, 0x5ed7, 0x60eb, 0x62f1, 0x64e8, 0x66cf, 0x68a6, |
| 27 | 0x6a6d, 0x6c23, 0x6dc9, 0x6f5e, 0x70e2, 0x7254, 0x73b5, 0x7504, |
| 28 | 0x7641, 0x776b, 0x7884, 0x7989, 0x7a7c, 0x7b5c, 0x7c29, 0x7ce3, |
| 29 | 0x7d89, 0x7e1d, 0x7e9c, 0x7f09, 0x7f61, 0x7fa6, 0x7fd8, 0x7ff5, |
| 30 | 0x7fff, 0x7ff5, 0x7fd8, 0x7fa6, 0x7f61, 0x7f09, 0x7e9c, 0x7e1d, |
| 31 | 0x7d89, 0x7ce3, 0x7c29, 0x7b5c, 0x7a7c, 0x7989, 0x7884, 0x776b, |
| 32 | 0x7641, 0x7504, 0x73b5, 0x7254, 0x70e2, 0x6f5e, 0x6dc9, 0x6c23, |
| 33 | 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f1, 0x60eb, 0x5ed7, 0x5cb3, |
| 34 | 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, |
| 35 | 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33df, |
| 36 | 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f1a, 0x1c0b, |
| 37 | 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8c, 0x096a, 0x0648, 0x0324, |
| 38 | 0x0000, -0x0324, -0x0648, -0x096b, -0x0c8c, -0x0fab, -0x12c8, -0x15e2, |
| 39 | -0x18f9, -0x1c0b, -0x1f1a, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11, |
| 40 | -0x30fb, -0x33df, -0x36ba, -0x398d, -0x3c56, -0x3f17, -0x41ce, -0x447a, |
| 41 | -0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842, |
| 42 | -0x5a82, -0x5cb3, -0x5ed7, -0x60ec, -0x62f1, -0x64e8, -0x66cf, -0x68a6, |
| 43 | -0x6a6d, -0x6c23, -0x6dc9, -0x6f5e, -0x70e2, -0x7254, -0x73b5, -0x7504, |
| 44 | -0x7641, -0x776b, -0x7884, -0x7989, -0x7a7c, -0x7b5c, -0x7c29, -0x7ce3, |
| 45 | -0x7d89, -0x7e1d, -0x7e9c, -0x7f09, -0x7f61, -0x7fa6, -0x7fd8, -0x7ff5, |
| 46 | -0x7fff, -0x7ff5, -0x7fd8, -0x7fa6, -0x7f61, -0x7f09, -0x7e9c, -0x7e1d, |
| 47 | -0x7d89, -0x7ce3, -0x7c29, -0x7b5c, -0x7a7c, -0x7989, -0x7883, -0x776b, |
| 48 | -0x7641, -0x7504, -0x73b5, -0x7254, -0x70e2, -0x6f5e, -0x6dc9, -0x6c23, |
| 49 | -0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f1, -0x60eb, -0x5ed7, -0x5cb3, |
| 50 | -0x5a82, -0x5842, -0x55f5, -0x539a, -0x5133, -0x4ebf, -0x4c3f, -0x49b3, |
| 51 | -0x471c, -0x447a, -0x41cd, -0x3f17, -0x3c56, -0x398c, -0x36b9, -0x33de, |
| 52 | -0x30fb, -0x2e10, -0x2b1f, -0x2826, -0x2527, -0x2223, -0x1f19, -0x1c0b, |
| 53 | -0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324 |
| 54 | }; |
| 55 | |
| 56 | static const INT16 st010_mode7_scale[176] = { |
| 57 | 0x0380, 0x0325, 0x02da, 0x029c, 0x0268, 0x023b, 0x0215, 0x01f3, |
| 58 | 0x01d5, 0x01bb, 0x01a3, 0x018e, 0x017b, 0x016a, 0x015a, 0x014b, |
| 59 | 0x013e, 0x0132, 0x0126, 0x011c, 0x0112, 0x0109, 0x0100, 0x00f8, |
| 60 | 0x00f0, 0x00e9, 0x00e3, 0x00dc, 0x00d6, 0x00d1, 0x00cb, 0x00c6, |
| 61 | 0x00c1, 0x00bd, 0x00b8, 0x00b4, 0x00b0, 0x00ac, 0x00a8, 0x00a5, |
| 62 | 0x00a2, 0x009e, 0x009b, 0x0098, 0x0095, 0x0093, 0x0090, 0x008d, |
| 63 | 0x008b, 0x0088, 0x0086, 0x0084, 0x0082, 0x0080, 0x007e, 0x007c, |
| 64 | 0x007a, 0x0078, 0x0076, 0x0074, 0x0073, 0x0071, 0x006f, 0x006e, |
| 65 | 0x006c, 0x006b, 0x0069, 0x0068, 0x0067, 0x0065, 0x0064, 0x0063, |
| 66 | 0x0062, 0x0060, 0x005f, 0x005e, 0x005d, 0x005c, 0x005b, 0x005a, |
| 67 | 0x0059, 0x0058, 0x0057, 0x0056, 0x0055, 0x0054, 0x0053, 0x0052, |
| 68 | 0x0051, 0x0051, 0x0050, 0x004f, 0x004e, 0x004d, 0x004d, 0x004c, |
| 69 | 0x004b, 0x004b, 0x004a, 0x0049, 0x0048, 0x0048, 0x0047, 0x0047, |
| 70 | 0x0046, 0x0045, 0x0045, 0x0044, 0x0044, 0x0043, 0x0042, 0x0042, |
| 71 | 0x0041, 0x0041, 0x0040, 0x0040, 0x003f, 0x003f, 0x003e, 0x003e, |
| 72 | 0x003d, 0x003d, 0x003c, 0x003c, 0x003b, 0x003b, 0x003a, 0x003a, |
| 73 | 0x003a, 0x0039, 0x0039, 0x0038, 0x0038, 0x0038, 0x0037, 0x0037, |
| 74 | 0x0036, 0x0036, 0x0036, 0x0035, 0x0035, 0x0035, 0x0034, 0x0034, |
| 75 | 0x0034, 0x0033, 0x0033, 0x0033, 0x0032, 0x0032, 0x0032, 0x0031, |
| 76 | 0x0031, 0x0031, 0x0030, 0x0030, 0x0030, 0x0030, 0x002f, 0x002f, |
| 77 | 0x002f, 0x002e, 0x002e, 0x002e, 0x002e, 0x002d, 0x002d, 0x002d, |
| 78 | 0x002d, 0x002c, 0x002c, 0x002c, 0x002c, 0x002b, 0x002b, 0x002b |
| 79 | }; |
| 80 | |
| 81 | static const UINT8 st010_arctan[32][32] = { |
| 82 | { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, |
| 83 | 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }, |
| 84 | { 0x80, 0xa0, 0xad, 0xb3, 0xb6, 0xb8, 0xb9, 0xba, 0xbb, 0xbb, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, |
| 85 | 0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf }, |
| 86 | { 0x80, 0x93, 0xa0, 0xa8, 0xad, 0xb0, 0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xbb, |
| 87 | 0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd }, |
| 88 | { 0x80, 0x8d, 0x98, 0xa0, 0xa6, 0xaa, 0xad, 0xb0, 0xb1, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb7, 0xb8, |
| 89 | 0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc }, |
| 90 | { 0x80, 0x8a, 0x93, 0x9a, 0xa0, 0xa5, 0xa8, 0xab, 0xad, 0xaf, 0xb0, 0xb2, 0xb3, 0xb4, 0xb5, 0xb5, |
| 91 | 0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb }, |
| 92 | { 0x80, 0x88, 0x90, 0x96, 0x9b, 0xa0, 0xa4, 0xa7, 0xa9, 0xab, 0xad, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, |
| 93 | 0xb4, 0xb4, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xb9 }, |
| 94 | { 0x80, 0x87, 0x8d, 0x93, 0x98, 0x9c, 0xa0, 0xa3, 0xa6, 0xa8, 0xaa, 0xac, 0xad, 0xae, 0xb0, 0xb0, |
| 95 | 0xb1, 0xb2, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8 }, |
| 96 | { 0x80, 0x86, 0x8b, 0x90, 0x95, 0x99, 0x9d, 0xa0, 0xa3, 0xa5, 0xa7, 0xa9, 0xaa, 0xac, 0xad, 0xae, |
| 97 | 0xaf, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7 }, |
| 98 | { 0x80, 0x85, 0x8a, 0x8f, 0x93, 0x97, 0x9a, 0x9d, 0xa0, 0xa2, 0xa5, 0xa6, 0xa8, 0xaa, 0xab, 0xac, |
| 99 | 0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5, 0xb5 }, |
| 100 | { 0x80, 0x85, 0x89, 0x8d, 0x91, 0x95, 0x98, 0x9b, 0x9e, 0xa0, 0xa0, 0xa4, 0xa6, 0xa7, 0xa9, 0xaa, |
| 101 | 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb4 }, |
| 102 | { 0x80, 0x84, 0x88, 0x8c, 0x90, 0x93, 0x96, 0x99, 0x9b, 0x9e, 0xa0, 0xa2, 0xa4, 0xa5, 0xa7, 0xa8, |
| 103 | 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3 }, |
| 104 | { 0x80, 0x84, 0x87, 0x8b, 0x8e, 0x91, 0x94, 0x97, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5, 0xa6, |
| 105 | 0xa7, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2 }, |
| 106 | { 0x80, 0x83, 0x87, 0x8a, 0x8d, 0x90, 0x93, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5, |
| 107 | 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1 }, |
| 108 | { 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x94, 0x96, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa2, 0xa3, |
| 109 | 0xa4, 0xa5, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xaf, 0xb0 }, |
| 110 | { 0x80, 0x83, 0x86, 0x89, 0x8b, 0x8e, 0x90, 0x93, 0x95, 0x97, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa1, |
| 111 | 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xad, 0xad, 0xae, 0xae, 0xaf }, |
| 112 | { 0x80, 0x83, 0x85, 0x88, 0x8b, 0x8d, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9b, 0x9d, 0x9f, 0xa0, |
| 113 | 0xa1, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xab, 0xab, 0xac, 0xad, 0xad, 0xae }, |
| 114 | { 0x80, 0x83, 0x85, 0x88, 0x8a, 0x8c, 0x8f, 0x91, 0x93, 0x95, 0x97, 0x99, 0x9a, 0x9c, 0x9d, 0x9f, |
| 115 | 0xa0, 0xa1, 0xa2, 0xa3, 0xa5, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xab, 0xac, 0xad }, |
| 116 | { 0x80, 0x82, 0x85, 0x87, 0x89, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x97, 0x99, 0x9b, 0x9c, 0x9d, |
| 117 | 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac }, |
| 118 | { 0x80, 0x82, 0x85, 0x87, 0x89, 0x8b, 0x8d, 0x8f, 0x91, 0x93, 0x95, 0x96, 0x98, 0x99, 0x9b, 0x9c, |
| 119 | 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab }, |
| 120 | { 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x9a, 0x9b, |
| 121 | 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa }, |
| 122 | { 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x99, 0x9a, |
| 123 | 0x9b, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9 }, |
| 124 | { 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8f, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x99, |
| 125 | 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8 }, |
| 126 | { 0x80, 0x82, 0x84, 0x86, 0x87, 0x89, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x98, |
| 127 | 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7 }, |
| 128 | { 0x80, 0x82, 0x84, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x8f, 0x91, 0x92, 0x94, 0x95, 0x96, 0x98, |
| 129 | 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6 }, |
| 130 | { 0x80, 0x82, 0x83, 0x85, 0x87, 0x88, 0x8a, 0x8c, 0x8d, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x96, 0x97, |
| 131 | 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5 }, |
| 132 | { 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x94, 0x95, 0x96, |
| 133 | 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa4 }, |
| 134 | { 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x89, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x95, |
| 135 | 0x96, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4 }, |
| 136 | { 0x80, 0x82, 0x83, 0x85, 0x86, 0x87, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93, 0x95, |
| 137 | 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2, 0xa3 }, |
| 138 | { 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x89, 0x8a, 0x8b, 0x8d, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94, |
| 139 | 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2 }, |
| 140 | { 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x88, 0x8a, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, |
| 141 | 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1, 0xa1 }, |
| 142 | { 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8b, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93, |
| 143 | 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1 }, |
| 144 | { 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, |
| 145 | 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0 } |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | static INT16 st010_sin( INT16 theta ) |
| 150 | { |
| 151 | return st010_sin_table[(theta >> 8) & 0xff]; |
| 152 | } |
| 153 | |
| 154 | static INT16 st010_cos( INT16 theta ) |
| 155 | { |
| 156 | return st010_sin_table[((theta + 0x4000) >> 8) & 0xff]; |
| 157 | } |
| 158 | |
| 159 | static UINT8 st010_readb( UINT16 address ) |
| 160 | { |
| 161 | return snes_st010.ram[address & 0xfff]; |
| 162 | } |
| 163 | |
| 164 | static UINT16 st010_readw( UINT16 address ) |
| 165 | { |
| 166 | return (st010_readb(address + 0) << 0) | |
| 167 | (st010_readb(address + 1) << 8); |
| 168 | } |
| 169 | |
| 170 | static UINT32 st010_readd( UINT16 address ) |
| 171 | { |
| 172 | return (st010_readb(address + 0) << 0) | |
| 173 | (st010_readb(address + 1) << 8) | |
| 174 | (st010_readb(address + 2) << 16) | |
| 175 | (st010_readb(address + 3) << 24); |
| 176 | } |
| 177 | |
| 178 | static void st010_writeb( UINT16 address, UINT8 data ) |
| 179 | { |
| 180 | snes_st010.ram[address & 0xfff] = data; |
| 181 | } |
| 182 | |
| 183 | static void st010_writew( UINT16 address, UINT16 data ) |
| 184 | { |
| 185 | st010_writeb(address + 0, data >> 0); |
| 186 | st010_writeb(address + 1, data >> 8); |
| 187 | } |
| 188 | |
| 189 | static void st010_writed( UINT16 address, UINT32 data ) |
| 190 | { |
| 191 | st010_writeb(address + 0, data >> 0); |
| 192 | st010_writeb(address + 1, data >> 8); |
| 193 | st010_writeb(address + 2, data >> 16); |
| 194 | st010_writeb(address + 3, data >> 24); |
| 195 | } |
| 196 | |
| 197 | // |
| 198 | |
| 199 | static void st010_op_01_do_work(INT16 x0, INT16 y0) { |
| 200 | if((x0 < 0) && (y0 < 0)) { |
| 201 | snes_st010.x1 = -x0; |
| 202 | snes_st010.y1 = -y0; |
| 203 | snes_st010.quadrant = -0x8000; |
| 204 | } else if(x0 < 0) { |
| 205 | snes_st010.x1 = y0; |
| 206 | snes_st010.y1 = -x0; |
| 207 | snes_st010.quadrant = -0x4000; |
| 208 | } else if(y0 < 0) { |
| 209 | snes_st010.x1 = -y0; |
| 210 | snes_st010.y1 = x0; |
| 211 | snes_st010.quadrant = 0x4000; |
| 212 | } else { |
| 213 | snes_st010.x1 = x0; |
| 214 | snes_st010.y1 = y0; |
| 215 | snes_st010.quadrant = 0x0000; |
| 216 | } |
| 217 | |
| 218 | while((snes_st010.x1 > 0x1f) || (snes_st010.y1 > 0x1f)) { |
| 219 | if(snes_st010.x1 > 1) { snes_st010.x1 >>= 1; } |
| 220 | if(snes_st010.y1 > 1) { snes_st010.y1 >>= 1; } |
| 221 | } |
| 222 | |
| 223 | if(snes_st010.y1 == 0) { snes_st010.quadrant += 0x4000; } |
| 224 | |
| 225 | snes_st010.theta = (st010_arctan[snes_st010.y1][snes_st010.x1] << 8) ^ snes_st010.quadrant; |
| 226 | } |
| 227 | |
| 228 | // |
| 229 | |
| 230 | static void st010_op_01( void ) { |
| 231 | INT16 x0 = st010_readw(0x0000); |
| 232 | INT16 y0 = st010_readw(0x0002); |
| 233 | |
| 234 | st010_op_01_do_work(x0, y0); |
| 235 | |
| 236 | st010_writew(0x0000, snes_st010.x1); |
| 237 | st010_writew(0x0002, snes_st010.y1); |
| 238 | st010_writew(0x0004, snes_st010.quadrant); |
| 239 | //st010_writew(0x0006, y0); //Overload's docs note this write occurs, SNES9x disagrees |
| 240 | st010_writew(0x0010, snes_st010.theta); |
| 241 | } |
| 242 | |
| 243 | static void st010_op_02( void ) { |
| 244 | INT16 positions = st010_readw(0x0024); |
| 245 | UINT16 *places = (UINT16*)(snes_st010.ram + 0x0040); |
| 246 | UINT16 *drivers = (UINT16*)(snes_st010.ram + 0x0080); |
| 247 | |
| 248 | UINT8 sorted; |
| 249 | UINT16 temp; |
| 250 | int i; |
| 251 | if(positions > 1) { |
| 252 | do { |
| 253 | sorted = 1; |
| 254 | for(i = 0; i < positions - 1; i++) { |
| 255 | if(places[i] < places[i + 1]) { |
| 256 | temp = places[i + 1]; |
| 257 | places[i + 1] = places[i]; |
| 258 | places[i] = temp; |
| 259 | |
| 260 | temp = drivers[i + 1]; |
| 261 | drivers[i + 1] = drivers[i]; |
| 262 | drivers[i] = temp; |
| 263 | |
| 264 | sorted = 0; |
| 265 | } |
| 266 | } |
| 267 | positions--; |
| 268 | } while(!sorted); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | static void st010_op_03( void ) { |
| 273 | INT16 x0 = st010_readw(0x0000); |
| 274 | INT16 y0 = st010_readw(0x0002); |
| 275 | INT16 multiplier = st010_readw(0x0004); |
| 276 | INT32 x1, y1; |
| 277 | |
| 278 | x1 = x0 * multiplier << 1; |
| 279 | y1 = y0 * multiplier << 1; |
| 280 | |
| 281 | st010_writed(0x0010, x1); |
| 282 | st010_writed(0x0014, y1); |
| 283 | } |
| 284 | |
| 285 | static void st010_op_04( void ) { |
| 286 | INT16 x = st010_readw(0x0000); |
| 287 | INT16 y = st010_readw(0x0002); |
| 288 | INT16 square; |
| 289 | //calculate the vector length of (x,y) |
| 290 | square = sqrt((double)(y * y + x * x)); |
| 291 | |
| 292 | st010_writew(0x0010, square); |
| 293 | } |
| 294 | |
| 295 | // same as op_01_do_work, but we are only interested in the angle! |
| 296 | static void st010_op_05_do_work(INT16 x0, INT16 y0) { |
| 297 | INT16 x1, y1, quadrant; |
| 298 | if((x0 < 0) && (y0 < 0)) { |
| 299 | x1 = -x0; |
| 300 | y1 = -y0; |
| 301 | quadrant = -0x8000; |
| 302 | } else if(x0 < 0) { |
| 303 | x1 = y0; |
| 304 | y1 = -x0; |
| 305 | quadrant = -0x4000; |
| 306 | } else if(y0 < 0) { |
| 307 | x1 = -y0; |
| 308 | y1 = x0; |
| 309 | quadrant = 0x4000; |
| 310 | } else { |
| 311 | x1 = x0; |
| 312 | y1 = y0; |
| 313 | quadrant = 0x0000; |
| 314 | } |
| 315 | |
| 316 | while((x1 > 0x1f) || (y1 > 0x1f)) { |
| 317 | if(x1 > 1) { x1 >>= 1; } |
| 318 | if(y1 > 1) { y1 >>= 1; } |
| 319 | } |
| 320 | |
| 321 | if(y1 == 0) { quadrant += 0x4000; } |
| 322 | |
| 323 | snes_st010.o1 = (st010_arctan[y1][x1] << 8) ^ quadrant; |
| 324 | } |
| 325 | |
| 326 | static void st010_op_05( void ) { |
| 327 | INT32 dx, dy; |
| 328 | UINT16 o1 = 0; |
| 329 | UINT8 wrap = 0; |
| 330 | |
| 331 | //target (x,y) coordinates |
| 332 | INT16 ypos_max = st010_readw(0x00c0); |
| 333 | INT16 xpos_max = st010_readw(0x00c2); |
| 334 | |
| 335 | //current coordinates and direction |
| 336 | INT32 ypos = st010_readd(0x00c4); |
| 337 | INT32 xpos = st010_readd(0x00c8); |
| 338 | UINT16 rot = st010_readw(0x00cc); |
| 339 | |
| 340 | //physics |
| 341 | UINT16 speed = st010_readw(0x00d4); |
| 342 | UINT16 accel = st010_readw(0x00d6); |
| 343 | UINT16 speed_max = st010_readw(0x00d8); |
| 344 | UINT16 old_speed; |
| 345 | |
| 346 | //special condition acknowledgement |
| 347 | INT16 system = st010_readw(0x00da); |
| 348 | INT16 flags = st010_readw(0x00dc); |
| 349 | |
| 350 | //new target coordinates |
| 351 | INT16 ypos_new = st010_readw(0x00de); |
| 352 | INT16 xpos_new = st010_readw(0x00e0); |
| 353 | |
| 354 | //mask upper bit |
| 355 | xpos_new &= 0x7fff; |
| 356 | |
| 357 | //get the current distance |
| 358 | dx = xpos_max - (xpos >> 16); |
| 359 | dy = ypos_max - (ypos >> 16); |
| 360 | |
| 361 | //quirk: clear and move in9 |
| 362 | st010_writew(0x00d2, 0xffff); |
| 363 | st010_writew(0x00da, 0x0000); |
| 364 | |
| 365 | //grab the target angle |
| 366 | st010_op_05_do_work(dy, dx); |
| 367 | o1 = (UINT8)snes_st010.o1; |
| 368 | |
| 369 | //check for wrapping |
| 370 | if(abs(o1 - rot) > 0x8000) { |
| 371 | o1 += 0x8000; |
| 372 | rot += 0x8000; |
| 373 | wrap = 1; |
| 374 | } |
| 375 | |
| 376 | old_speed = speed; |
| 377 | |
| 378 | //special case |
| 379 | if(abs(o1 - rot) == 0x8000) { |
| 380 | speed = 0x100; |
| 381 | } |
| 382 | |
| 383 | //slow down for sharp curves |
| 384 | else if(abs(o1 - rot) >= 0x1000) { |
| 385 | UINT32 slow = abs(o1 - rot); |
| 386 | slow >>= 4; //scaling |
| 387 | speed -= slow; |
| 388 | } |
| 389 | |
| 390 | //otherwise accelerate |
| 391 | else { |
| 392 | speed += accel; |
| 393 | if(speed > speed_max) { |
| 394 | speed = speed_max; //clip speed |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | //prevent negative/positive overflow |
| 399 | if(abs(old_speed - speed) > 0x8000) { |
| 400 | if(old_speed < speed) { speed = 0; } |
| 401 | else speed = 0xff00; |
| 402 | } |
| 403 | |
| 404 | //adjust direction by so many degrees |
| 405 | //be careful of negative adjustments |
| 406 | if((o1 > rot && (o1 - rot) > 0x80) || (o1 < rot && (rot - o1) >= 0x80)) { |
| 407 | if(o1 < rot) { rot -= 0x280; } |
| 408 | else if(o1 > rot) { rot += 0x280; } |
| 409 | } |
| 410 | |
| 411 | //turn off wrapping |
| 412 | if(wrap) { rot -= 0x8000; } |
| 413 | |
| 414 | //now check the distances (store for later) |
| 415 | dx = (xpos_max << 16) - xpos; |
| 416 | dy = (ypos_max << 16) - ypos; |
| 417 | dx >>= 16; |
| 418 | dy >>= 16; |
| 419 | |
| 420 | //if we're in so many units of the target, signal it |
| 421 | if((system && (dy <= 6 && dy >= -8) && (dx <= 126 && dx >= -128)) || (!system && (dx <= 6 && dx >= -8) && (dy <= 126 && dy >= -128))) { |
| 422 | //announce our new destination and flag it |
| 423 | xpos_max = xpos_new & 0x7fff; |
| 424 | ypos_max = ypos_new; |
| 425 | flags |= 0x08; |
| 426 | } |
| 427 | |
| 428 | //update position |
| 429 | xpos -= (st010_cos(rot) * 0x400 >> 15) * (speed >> 8) << 1; |
| 430 | ypos -= (st010_sin(rot) * 0x400 >> 15) * (speed >> 8) << 1; |
| 431 | |
| 432 | //quirk: mask upper byte |
| 433 | xpos &= 0x1fffffff; |
| 434 | ypos &= 0x1fffffff; |
| 435 | |
| 436 | st010_writew(0x00c0, ypos_max); |
| 437 | st010_writew(0x00c2, xpos_max); |
| 438 | st010_writed(0x00c4, ypos); |
| 439 | st010_writed(0x00c8, xpos); |
| 440 | st010_writew(0x00cc, rot); |
| 441 | st010_writew(0x00d4, speed); |
| 442 | st010_writew(0x00dc, flags); |
| 443 | } |
| 444 | |
| 445 | static void st010_op_06( void ) { |
| 446 | INT16 multiplicand = st010_readw(0x0000); |
| 447 | INT16 multiplier = st010_readw(0x0002); |
| 448 | INT32 product; |
| 449 | |
| 450 | product = multiplicand * multiplier << 1; |
| 451 | |
| 452 | st010_writed(0x0010, product); |
| 453 | } |
| 454 | |
| 455 | static void st010_op_07( void ) { |
| 456 | INT16 theta = st010_readw(0x0000); |
| 457 | |
| 458 | INT16 data; |
| 459 | int i, offset; |
| 460 | for(i = 0, offset = 0; i < 176; i++) { |
| 461 | data = st010_mode7_scale[i] * st010_cos(theta) >> 15; |
| 462 | st010_writew(0x00f0 + offset, data); |
| 463 | st010_writew(0x0510 + offset, data); |
| 464 | |
| 465 | data = st010_mode7_scale[i] * st010_sin(theta) >> 15; |
| 466 | st010_writew(0x0250 + offset, data); |
| 467 | if(data) { data = ~data; } |
| 468 | st010_writew(0x03b0 + offset, data); |
| 469 | |
| 470 | offset += 2; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | static void st010_op_08( void ) { |
| 475 | INT16 x0 = st010_readw(0x0000); |
| 476 | INT16 y0 = st010_readw(0x0002); |
| 477 | INT16 theta = st010_readw(0x0004); |
| 478 | INT16 x1, y1; |
| 479 | |
| 480 | x1 = (y0 * st010_sin(theta) >> 15) + (x0 * st010_cos(theta) >> 15); |
| 481 | y1 = (y0 * st010_cos(theta) >> 15) - (x0 * st010_sin(theta) >> 15); |
| 482 | |
| 483 | st010_writew(0x0010, x1); |
| 484 | st010_writew(0x0012, y1); |
| 485 | } |
| 486 | |
| 487 | // init, reset & handlers |
| 488 | |
| 489 | UINT8 st010_read( UINT16 address ) |
| 490 | { |
| 491 | return st010_readb(address); |
| 492 | } |
| 493 | |
| 494 | void st010_write( UINT16 address, UINT8 data ) |
| 495 | { |
| 496 | st010_writeb(address, data); |
| 497 | |
| 498 | if ((address & 0xfff) == 0x0021 && (data & 0x80)) |
| 499 | { |
| 500 | switch (snes_st010.ram[0x0020]) |
| 501 | { |
| 502 | case 0x01: st010_op_01(); break; |
| 503 | case 0x02: st010_op_02(); break; |
| 504 | case 0x03: st010_op_03(); break; |
| 505 | case 0x04: st010_op_04(); break; |
| 506 | case 0x05: st010_op_05(); break; |
| 507 | case 0x06: st010_op_06(); break; |
| 508 | case 0x07: st010_op_07(); break; |
| 509 | case 0x08: st010_op_08(); break; |
| 510 | } |
| 511 | |
| 512 | snes_st010.ram[0x0021] &= ~0x80; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | |
| 517 | void st010_init( running_machine* machine ) |
| 518 | { |
| 519 | snes_st010.ram = (UINT8*)auto_alloc_array(machine, UINT8, 0x1000); |
| 520 | } |
| 521 | |
| 522 | void st010_reset( void ) |
| 523 | { |
| 524 | snes_st010.x1 = 0; |
| 525 | snes_st010.y1 = 0; |
| 526 | snes_st010.quadrant = 0; |
| 527 | snes_st010.theta = 0; |
| 528 | memset(snes_st010.ram, 0, 0x1000); |
| 529 | } |