src/mame/machine/snes.c
| r7759 | r7760 | |
| 34 | 34 | static void snes_hdma_init(const address_space *space); |
| 35 | 35 | static void snes_hdma(const address_space *space); |
| 36 | 36 | |
| 37 | READ8_HANDLER(snes_io_dma_r); |
| 38 | WRITE8_HANDLER(snes_io_dma_w); |
| 39 | |
| 37 | 40 | struct snes_cart_info snes_cart; |
| 38 | 41 | |
| 39 | 42 | // add-on chip emulators |
| r7759 | r7760 | |
| 301 | 304 | return result; |
| 302 | 305 | } |
| 303 | 306 | |
| 307 | /* read & write to DMA addresses are defined separately, to be called by snessdd1 handlers */ |
| 308 | READ8_HANDLER( snes_io_dma_r ) |
| 309 | { |
| 310 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 311 | |
| 312 | switch (offset) |
| 313 | { |
| 314 | case DMAP0: case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/ |
| 315 | case DMAP4: case DMAP5: case DMAP6: case DMAP7: |
| 316 | return state->dma_channel[(offset >> 4) & 0x07].dmap; |
| 317 | case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/ |
| 318 | case BBAD4: case BBAD5: case BBAD6: case BBAD7: |
| 319 | return state->dma_channel[(offset >> 4) & 0x07].dest_addr; |
| 320 | case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/ |
| 321 | case A1T4L: case A1T5L: case A1T6L: case A1T7L: |
| 322 | return state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff; |
| 323 | case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/ |
| 324 | case A1T4H: case A1T5H: case A1T6H: case A1T7H: |
| 325 | return (state->dma_channel[(offset >> 4) & 0x07].src_addr >> 8) & 0xff; |
| 326 | case A1B0: case A1B1: case A1B2: case A1B3: /*0x43n4*/ |
| 327 | case A1B4: case A1B5: case A1B6: case A1B7: |
| 328 | return state->dma_channel[(offset >> 4) & 0x07].bank; |
| 329 | case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/ |
| 330 | case DAS4L: case DAS5L: case DAS6L: case DAS7L: |
| 331 | return state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff; |
| 332 | case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/ |
| 333 | case DAS4H: case DAS5H: case DAS6H: case DAS7H: |
| 334 | return (state->dma_channel[(offset >> 4) & 0x07].trans_size >> 8) & 0xff; |
| 335 | case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/ |
| 336 | case DSAB4: case DSAB5: case DSAB6: case DSAB7: |
| 337 | return state->dma_channel[(offset >> 4) & 0x07].ibank; |
| 338 | case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/ |
| 339 | case A2A4L: case A2A5L: case A2A6L: case A2A7L: |
| 340 | return state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff; |
| 341 | case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/ |
| 342 | case A2A4H: case A2A5H: case A2A6H: case A2A7H: |
| 343 | return (state->dma_channel[(offset >> 4) & 0x07].hdma_addr >> 8) & 0xff; |
| 344 | case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/ |
| 345 | case NTRL4: case NTRL5: case NTRL6: case NTRL7: |
| 346 | return state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter; |
| 347 | case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */ |
| 348 | case 0x434b: case 0x435b: case 0x436b: case 0x437b: |
| 349 | return state->dma_channel[(offset >> 4) & 0x07].unk; |
| 350 | } |
| 351 | |
| 352 | /* we should never arrive here */ |
| 353 | return snes_open_bus_r(space, 0); |
| 354 | } |
| 355 | |
| 356 | WRITE8_HANDLER( snes_io_dma_w ) |
| 357 | { |
| 358 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 359 | |
| 360 | switch (offset) |
| 361 | { |
| 362 | /* Below is all DMA related */ |
| 363 | case DMAP0: case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/ |
| 364 | case DMAP4: case DMAP5: case DMAP6: case DMAP7: |
| 365 | state->dma_channel[(offset >> 4) & 0x07].dmap = data; |
| 366 | break; |
| 367 | case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/ |
| 368 | case BBAD4: case BBAD5: case BBAD6: case BBAD7: |
| 369 | state->dma_channel[(offset >> 4) & 0x07].dest_addr = data; |
| 370 | break; |
| 371 | case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/ |
| 372 | case A1T4L: case A1T5L: case A1T6L: case A1T7L: |
| 373 | state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff00) | (data << 0); |
| 374 | break; |
| 375 | case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/ |
| 376 | case A1T4H: case A1T5H: case A1T6H: case A1T7H: |
| 377 | state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0x00ff) | (data << 8); |
| 378 | break; |
| 379 | case A1B0: case A1B1: case A1B2: case A1B3: /*0x43n4*/ |
| 380 | case A1B4: case A1B5: case A1B6: case A1B7: |
| 381 | state->dma_channel[(offset >> 4) & 0x07].bank = data; |
| 382 | break; |
| 383 | case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/ |
| 384 | case DAS4L: case DAS5L: case DAS6L: case DAS7L: |
| 385 | state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff00) | (data << 0); |
| 386 | break; |
| 387 | case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/ |
| 388 | case DAS4H: case DAS5H: case DAS6H: case DAS7H: |
| 389 | state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0x00ff) | (data << 8); |
| 390 | break; |
| 391 | case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/ |
| 392 | case DSAB4: case DSAB5: case DSAB6: case DSAB7: |
| 393 | state->dma_channel[(offset >> 4) & 0x07].ibank = data; |
| 394 | break; |
| 395 | case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/ |
| 396 | case A2A4L: case A2A5L: case A2A6L: case A2A7L: |
| 397 | state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff00) | (data << 0); |
| 398 | break; |
| 399 | case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/ |
| 400 | case A2A4H: case A2A5H: case A2A6H: case A2A7H: |
| 401 | state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0x00ff) | (data << 8); |
| 402 | break; |
| 403 | case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/ |
| 404 | case NTRL4: case NTRL5: case NTRL6: case NTRL7: |
| 405 | state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter = data; |
| 406 | break; |
| 407 | case 0x430b: case 0x431b: case 0x432b: case 0x433b: |
| 408 | case 0x434b: case 0x435b: case 0x436b: case 0x437b: |
| 409 | state->dma_channel[(offset >> 4) & 0x07].unk = data; |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | snes_ram[offset] = data; |
| 414 | } |
| 415 | |
| 304 | 416 | /* |
| 305 | 417 | * DR - Double read : address is read twice to return a 16bit value. |
| 306 | 418 | * low - This is the low byte of a 16 or 24 bit value |
| r7759 | r7760 | |
| 358 | 470 | } |
| 359 | 471 | } |
| 360 | 472 | |
| 473 | if (offset >= DMAP0 && offset < 0x4380) |
| 474 | { |
| 475 | return snes_io_dma_r(space, offset); |
| 476 | } |
| 477 | |
| 361 | 478 | /* offset is from 0x000000 */ |
| 362 | 479 | switch (offset) |
| 363 | 480 | { |
| r7759 | r7760 | |
| 416 | 533 | return state->joy4l; |
| 417 | 534 | case JOY4H: /* Joypad 4 status register (high) */ |
| 418 | 535 | return state->joy4h; |
| 419 | | case DMAP0: case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/ |
| 420 | | case DMAP4: case DMAP5: case DMAP6: case DMAP7: |
| 421 | | return state->dma_channel[(offset >> 4) & 0x07].dmap; |
| 422 | | case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/ |
| 423 | | case BBAD4: case BBAD5: case BBAD6: case BBAD7: |
| 424 | | return state->dma_channel[(offset >> 4) & 0x07].dest_addr; |
| 425 | | case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/ |
| 426 | | case A1T4L: case A1T5L: case A1T6L: case A1T7L: |
| 427 | | return state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff; |
| 428 | | case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/ |
| 429 | | case A1T4H: case A1T5H: case A1T6H: case A1T7H: |
| 430 | | return (state->dma_channel[(offset >> 4) & 0x07].src_addr >> 8) & 0xff; |
| 431 | | case A1B0: case A1B1: case A1B2: case A1B3: /*0x43n4*/ |
| 432 | | case A1B4: case A1B5: case A1B6: case A1B7: |
| 433 | | return state->dma_channel[(offset >> 4) & 0x07].bank; |
| 434 | | case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/ |
| 435 | | case DAS4L: case DAS5L: case DAS6L: case DAS7L: |
| 436 | | return state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff; |
| 437 | | case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/ |
| 438 | | case DAS4H: case DAS5H: case DAS6H: case DAS7H: |
| 439 | | return (state->dma_channel[(offset >> 4) & 0x07].trans_size >> 8) & 0xff; |
| 440 | | case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/ |
| 441 | | case DSAB4: case DSAB5: case DSAB6: case DSAB7: |
| 442 | | return state->dma_channel[(offset >> 4) & 0x07].ibank; |
| 443 | | case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/ |
| 444 | | case A2A4L: case A2A5L: case A2A6L: case A2A7L: |
| 445 | | return state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff; |
| 446 | | case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/ |
| 447 | | case A2A4H: case A2A5H: case A2A6H: case A2A7H: |
| 448 | | return (state->dma_channel[(offset >> 4) & 0x07].hdma_addr >> 8) & 0xff; |
| 449 | | case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/ |
| 450 | | case NTRL4: case NTRL5: case NTRL6: case NTRL7: |
| 451 | | return state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter; |
| 452 | | case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */ |
| 453 | | case 0x434b: case 0x435b: case 0x436b: case 0x437b: |
| 454 | | return state->dma_channel[(offset >> 4) & 0x07].unk; |
| 455 | 536 | |
| 456 | 537 | #ifndef MESS |
| 457 | 538 | case 0x4100: /* NSS Dip-Switches */ |
| r7759 | r7760 | |
| 537 | 618 | } |
| 538 | 619 | } |
| 539 | 620 | |
| 621 | if (offset >= DMAP0 && offset < 0x4380) |
| 622 | { |
| 623 | snes_io_dma_w(space, offset, data); |
| 624 | return; |
| 625 | } |
| 626 | |
| 540 | 627 | /* offset is from 0x000000 */ |
| 541 | 628 | switch (offset) |
| 542 | 629 | { |
| r7759 | r7760 | |
| 674 | 761 | logerror( "Write to read-only register: %X value: %X", offset, data ); |
| 675 | 762 | #endif /* MAME_DEBUG */ |
| 676 | 763 | return; |
| 677 | | /* Below is all DMA related */ |
| 678 | | case DMAP0: case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/ |
| 679 | | case DMAP4: case DMAP5: case DMAP6: case DMAP7: |
| 680 | | state->dma_channel[(offset >> 4) & 0x07].dmap = data; |
| 681 | | break; |
| 682 | | case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/ |
| 683 | | case BBAD4: case BBAD5: case BBAD6: case BBAD7: |
| 684 | | state->dma_channel[(offset >> 4) & 0x07].dest_addr = data; |
| 685 | | break; |
| 686 | | case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/ |
| 687 | | case A1T4L: case A1T5L: case A1T6L: case A1T7L: |
| 688 | | state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff00) | (data << 0); |
| 689 | | break; |
| 690 | | case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/ |
| 691 | | case A1T4H: case A1T5H: case A1T6H: case A1T7H: |
| 692 | | state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0x00ff) | (data << 8); |
| 693 | | break; |
| 694 | | case A1B0: case A1B1: case A1B2: case A1B3: /*0x43n4*/ |
| 695 | | case A1B4: case A1B5: case A1B6: case A1B7: |
| 696 | | state->dma_channel[(offset >> 4) & 0x07].bank = data; |
| 697 | | break; |
| 698 | | case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/ |
| 699 | | case DAS4L: case DAS5L: case DAS6L: case DAS7L: |
| 700 | | state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff00) | (data << 0); |
| 701 | | break; |
| 702 | | case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/ |
| 703 | | case DAS4H: case DAS5H: case DAS6H: case DAS7H: |
| 704 | | state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0x00ff) | (data << 8); |
| 705 | | break; |
| 706 | | case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/ |
| 707 | | case DSAB4: case DSAB5: case DSAB6: case DSAB7: |
| 708 | | state->dma_channel[(offset >> 4) & 0x07].ibank = data; |
| 709 | | break; |
| 710 | | case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/ |
| 711 | | case A2A4L: case A2A5L: case A2A6L: case A2A7L: |
| 712 | | state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff00) | (data << 0); |
| 713 | | break; |
| 714 | | case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/ |
| 715 | | case A2A4H: case A2A5H: case A2A6H: case A2A7H: |
| 716 | | state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0x00ff) | (data << 8); |
| 717 | | break; |
| 718 | | case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/ |
| 719 | | case NTRL4: case NTRL5: case NTRL6: case NTRL7: |
| 720 | | state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter = data; |
| 721 | | break; |
| 722 | | case 0x430b: case 0x431b: case 0x432b: case 0x433b: |
| 723 | | case 0x434b: case 0x435b: case 0x436b: case 0x437b: |
| 724 | | state->dma_channel[(offset >> 4) & 0x07].unk = data; |
| 725 | | break; |
| 726 | 764 | } |
| 727 | 765 | |
| 728 | 766 | snes_ram[offset] = data; |
| r7759 | r7760 | |
| 2067 | 2105 | UINT32 abus, abus_bank; |
| 2068 | 2106 | UINT16 length; |
| 2069 | 2107 | |
| 2070 | | /* FIXME: we also need to round to the nearest 8 master cycles */ |
| 2108 | /* FIXME: we also need to round to the nearest 8 master cycles */ |
| 2071 | 2109 | |
| 2072 | 2110 | /* overhead steals 8 master cycles, correct? */ |
| 2073 | 2111 | cpu_adjust_icount(space->cpu,-8); |
| r7759 | r7760 | |
| 2083 | 2121 | |
| 2084 | 2122 | //printf( "Making a transfer on channel %d\n", i ); |
| 2085 | 2123 | /* Find transfer addresses */ |
| 2086 | | abus = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 3] << 8) + snes_ram[SNES_DMA_BASE + (i * 0x10) + 2]; |
| 2087 | | abus_bank = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 4] << 16); |
| 2088 | | bbus = 0x2100 + snes_ram[SNES_DMA_BASE + (i * 0x10) + 1]; |
| 2124 | abus = state->dma_channel[i].src_addr; |
| 2125 | abus_bank = state->dma_channel[i].bank << 16; |
| 2126 | bbus = state->dma_channel[i].dest_addr + 0x2100; |
| 2089 | 2127 | |
| 2090 | | //printf( "Address: %06x\n", abus | abus_bank ); |
| 2128 | //printf("Address: %06x\n", abus | abus_bank); |
| 2091 | 2129 | /* Auto increment */ |
| 2092 | | if (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x8) |
| 2093 | | { |
| 2130 | if (state->dma_channel[i].dmap & 0x8) |
| 2094 | 2131 | increment = 0; |
| 2095 | | } |
| 2096 | 2132 | else |
| 2097 | 2133 | { |
| 2098 | | if (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x10) |
| 2134 | if (state->dma_channel[i].dmap & 0x10) |
| 2099 | 2135 | increment = -1; |
| 2100 | 2136 | else |
| 2101 | 2137 | increment = 1; |
| 2102 | 2138 | } |
| 2103 | 2139 | |
| 2104 | 2140 | /* Number of bytes to transfer */ |
| 2105 | | length = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 6] << 8) + snes_ram[SNES_DMA_BASE + (i * 0x10) + 5]; |
| 2141 | length = state->dma_channel[i].trans_size; |
| 2106 | 2142 | |
| 2107 | | // printf( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus, bbus, increment, snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x80 ? "PPU->CPU" : "CPU->PPU", snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07); |
| 2143 | // printf( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus | abus_bank, bbus, increment, state->dma_channel[i].dmap & 0x80 ? "PPU->CPU" : "CPU->PPU", state->dma_channel[i].dmap & 0x07); |
| 2108 | 2144 | |
| 2109 | 2145 | #ifdef SNES_DBG_DMA |
| 2110 | | mame_printf_debug( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus, bbus, increment, snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x80 ? "PPU->CPU" : "CPU->PPU", snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07); |
| 2146 | mame_printf_debug( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus | abus_bank, bbus, increment, state->dma_channel[i].dmap & 0x80 ? "PPU->CPU" : "CPU->PPU", state->dma_channel[i].dmap & 0x07); |
| 2111 | 2147 | #endif |
| 2112 | 2148 | |
| 2113 | | switch (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07) |
| 2149 | switch (state->dma_channel[i].dmap & 0x07) |
| 2114 | 2150 | { |
| 2115 | 2151 | case 0: /* 1 register write once */ |
| 2116 | 2152 | case 2: /* 1 register write twice */ |
| r7759 | r7760 | |
| 2179 | 2215 | break; |
| 2180 | 2216 | } |
| 2181 | 2217 | |
| 2182 | | /* We're done so write the new abus back to the registers */ |
| 2183 | | snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 2, abus & 0xff); |
| 2184 | | snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 3, (abus >> 8) & 0xff); |
| 2185 | | snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 5, 0); |
| 2186 | | snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 6, 0); |
| 2218 | /* We're done, so write the new abus back to the registers */ |
| 2219 | state->dma_channel[i].src_addr = abus; |
| 2220 | state->dma_channel[i].trans_size = 0; |
| 2187 | 2221 | |
| 2188 | | /* active channel takes 8 master cycles */ |
| 2222 | /* active channel takes 8 master cycles */ |
| 2189 | 2223 | cpu_adjust_icount(space->cpu,-8); |
| 2190 | 2224 | } |
| 2191 | 2225 | } |