src/mame/machine/snessdd1.c
| r5573 | r5574 | |
| 1 | | static UINT8 sdd1_read(running_machine* machine, UINT16 addr); |
| 1 | static UINT8 sdd1_read(running_machine* machine, UINT32 addr); |
| 2 | 2 | |
| 3 | 3 | typedef struct //Input Manager |
| 4 | 4 | { |
| r5573 | r5574 | |
| 538 | 538 | static void sdd1_init(running_machine* machine) |
| 539 | 539 | { |
| 540 | 540 | snes_sdd1.sdd1emu = SDD1emu_ctor(machine); |
| 541 | snes_sdd1.buffer.data = auto_alloc_array_clear(machine, UINT8, 0x10000); |
| 541 | 542 | } |
| 542 | 543 | |
| 543 | | static UINT8 sdd1_mmio_read(running_machine* machine, UINT16 addr) |
| 544 | static UINT8 sdd1_mmio_read(const address_space *space, UINT16 addr) |
| 544 | 545 | { |
| 546 | UINT8 val = 0xff; |
| 545 | 547 | addr &= 0xffff; |
| 546 | 548 | |
| 547 | 549 | switch(addr) |
| 548 | 550 | { |
| 549 | 551 | case 0x4804: |
| 550 | | return (snes_sdd1.mmc[0] >> 20) & 7; |
| 552 | val = (snes_sdd1.mmc[0] >> 20) & 7; |
| 551 | 553 | case 0x4805: |
| 552 | | return (snes_sdd1.mmc[1] >> 20) & 7; |
| 554 | val = (snes_sdd1.mmc[1] >> 20) & 7; |
| 553 | 555 | case 0x4806: |
| 554 | | return (snes_sdd1.mmc[2] >> 20) & 7; |
| 556 | val = (snes_sdd1.mmc[2] >> 20) & 7; |
| 555 | 557 | case 0x4807: |
| 556 | | return (snes_sdd1.mmc[3] >> 20) & 7; |
| 558 | val = (snes_sdd1.mmc[3] >> 20) & 7; |
| 557 | 559 | } |
| 558 | 560 | |
| 559 | | return 0xff; |
| 561 | printf("SDD1::mmio_read(%04x) = %02x\n", addr, val); |
| 562 | return val; |
| 560 | 563 | } |
| 561 | 564 | |
| 562 | | static void sdd1_mmio_write(running_machine* machine, UINT16 addr, UINT8 data) |
| 565 | static void sdd1_mmio_write(const address_space *space, UINT16 addr, UINT8 data) |
| 563 | 566 | { |
| 567 | printf("SDD1::mmio_write(%04x, %02x)\n", addr, data); |
| 564 | 568 | addr &= 0xffff; |
| 565 | 569 | |
| 566 | 570 | if((addr & 0x4380) == 0x4300) |
| r5573 | r5574 | |
| 570 | 574 | { |
| 571 | 575 | case 2: |
| 572 | 576 | snes_sdd1.dma[channel].addr = (snes_sdd1.dma[channel].addr & 0xffff00) + (data << 0); |
| 577 | printf( "dma[%d].addr = %06x\n", channel, snes_sdd1.dma[channel].addr ); |
| 573 | 578 | break; |
| 574 | 579 | case 3: |
| 575 | 580 | snes_sdd1.dma[channel].addr = (snes_sdd1.dma[channel].addr & 0xff00ff) + (data << 8); |
| 581 | printf( "dma[%d].addr = %06x\n", channel, snes_sdd1.dma[channel].addr ); |
| 576 | 582 | break; |
| 577 | 583 | case 4: |
| 578 | 584 | snes_sdd1.dma[channel].addr = (snes_sdd1.dma[channel].addr & 0x00ffff) + (data << 16); |
| 585 | printf( "dma[%d].addr = %06x\n", channel, snes_sdd1.dma[channel].addr ); |
| 579 | 586 | break; |
| 580 | 587 | |
| 581 | 588 | case 5: |
| 582 | | snes_sdd1.dma[channel].addr = (snes_sdd1.dma[channel].addr & 0xff00) + (data << 0); |
| 589 | snes_sdd1.dma[channel].size = (snes_sdd1.dma[channel].size & 0xff00) + (data << 0); |
| 590 | printf( "dma[%d].size = %04x\n", channel, snes_sdd1.dma[channel].size ); |
| 583 | 591 | break; |
| 584 | 592 | case 6: |
| 585 | | snes_sdd1.dma[channel].addr = (snes_sdd1.dma[channel].addr & 0x00ff) + (data << 8); |
| 593 | snes_sdd1.dma[channel].size = (snes_sdd1.dma[channel].size & 0x00ff) + (data << 8); |
| 594 | printf( "dma[%d].size = %04x\n", channel, snes_sdd1.dma[channel].size ); |
| 586 | 595 | break; |
| 587 | 596 | } |
| 588 | | snes_ram[addr] = data; |
| 597 | snes_w_io(space, addr & 0x7f, data); |
| 589 | 598 | return; |
| 590 | 599 | } |
| 591 | 600 | |
| r5573 | r5574 | |
| 613 | 622 | } |
| 614 | 623 | } |
| 615 | 624 | |
| 616 | | static UINT8 sdd1_read(running_machine* machine, UINT16 addr) |
| 625 | static UINT8 sdd1_read(running_machine* machine, UINT32 addr) |
| 617 | 626 | { |
| 627 | printf( "sdd1.read(%06x)\n", addr ); |
| 618 | 628 | if(snes_sdd1.sdd1_enable & snes_sdd1.xfer_enable) |
| 619 | 629 | { |
| 620 | 630 | // at least one channel has S-DD1 decompression enabled... |
| 621 | 631 | UINT32 i; |
| 632 | printf( " sdd1_enable and xfer_enable are set, let's go\n" ); |
| 622 | 633 | for(i = 0; i < 8; i++) |
| 623 | 634 | { |
| 624 | 635 | if(snes_sdd1.sdd1_enable & snes_sdd1.xfer_enable & (1 << i)) |
| 625 | 636 | { |
| 637 | printf( " channel %d is enabled\n", i ); |
| 626 | 638 | // S-DD1 always uses fixed transfer mode, so address will not change during transfer |
| 627 | 639 | if(addr == snes_sdd1.dma[i].addr) |
| 628 | 640 | { |
| 629 | 641 | UINT8 data; |
| 642 | printf( " addresses match\n" ); |
| 630 | 643 | if(!snes_sdd1.buffer.ready) |
| 631 | 644 | { |
| 632 | 645 | UINT8 temp; |
| r5573 | r5574 | |
| 639 | 652 | // so temporarily disable decompression mode for decompress() call. |
| 640 | 653 | temp = snes_sdd1.sdd1_enable; |
| 641 | 654 | snes_sdd1.sdd1_enable = 0; |
| 655 | printf( " buffer is not ready, decompressing %05x bytes at addr %06x\n", snes_sdd1.buffer.size, addr ); |
| 642 | 656 | SDD1emu_decompress(snes_sdd1.sdd1emu, addr, snes_sdd1.buffer.size, snes_sdd1.buffer.data); |
| 643 | 657 | snes_sdd1.sdd1_enable = temp; |
| 644 | 658 | |
| r5573 | r5574 | |
| 647 | 661 | |
| 648 | 662 | // fetch a decompressed byte; once buffer is depleted, disable channel and invalidate buffer |
| 649 | 663 | data = snes_sdd1.buffer.data[(UINT16)snes_sdd1.buffer.offset++]; |
| 664 | printf( " fetched byte: %02x\n", data ); |
| 650 | 665 | if(snes_sdd1.buffer.offset >= snes_sdd1.buffer.size) |
| 651 | 666 | { |
| 667 | printf( " we're done\n" ); |
| 652 | 668 | snes_sdd1.buffer.ready = 0; |
| 653 | 669 | snes_sdd1.xfer_enable &= ~(1 << i); |
| 654 | 670 | } |
| r5573 | r5574 | |
| 659 | 675 | } // channel loop |
| 660 | 676 | } // S-DD1 decompressor enabled |
| 661 | 677 | |
| 678 | printf( "returning a generic memory read from %06x\n", snes_sdd1.mmc[(addr >> 20) & 3] + (addr & 0x0fffff) ); |
| 662 | 679 | return memory_read_byte(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), snes_sdd1.mmc[(addr >> 20) & 3] + (addr & 0x0fffff)); |
| 663 | 680 | } |
| 664 | 681 | |
| 665 | 682 | static void sdd1_reset(running_machine *machine) |
| 666 | 683 | { |
| 684 | UINT8 i; |
| 685 | |
| 686 | snes_sdd1.sdd1_enable = 0; |
| 687 | snes_sdd1.xfer_enable = 0; |
| 688 | |
| 689 | snes_sdd1.mmc[0] = 0 << 20; |
| 690 | snes_sdd1.mmc[1] = 1 << 20; |
| 691 | snes_sdd1.mmc[2] = 2 << 20; |
| 692 | snes_sdd1.mmc[3] = 3 << 20; |
| 693 | |
| 694 | for(i = 0; i < 8; i++) |
| 695 | { |
| 696 | snes_sdd1.dma[i].addr = 0; |
| 697 | snes_sdd1.dma[i].size = 0; |
| 698 | } |
| 699 | |
| 700 | snes_sdd1.buffer.ready = 0; |
| 667 | 701 | } |
src/mame/machine/snes.c
| r5573 | r5574 | |
| 1354 | 1354 | break; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | | logerror("Unsupported MMIO write: offset %08x = %02x\n", offset, data); |
| 1358 | | |
| 1359 | 1357 | snes_ram[offset] = data; |
| 1360 | 1358 | } |
| 1361 | 1359 | |
| r5573 | r5574 | |
| 1520 | 1518 | UINT8 value; |
| 1521 | 1519 | UINT16 address = offset & 0xffff; |
| 1522 | 1520 | |
| 1523 | | if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1521 | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1524 | 1522 | { |
| 1523 | //printf( "snes_r_bank3: %08x\n", offset ); |
| 1524 | return snes_ram[0x400000 + offset]; |
| 1525 | } |
| 1526 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1527 | { |
| 1525 | 1528 | if ((address < 0x8000) && (snes_cart.mode == SNES_MODE_20)) //FIXME: check this |
| 1526 | 1529 | value = snes_ram[0x200000 + ((offset & ~0x8000) | 0x8000)]; /* Reserved */ |
| 1527 | 1530 | else |
| r5573 | r5574 | |
| 1669 | 1672 | snes_w_io(space, address, data); |
| 1670 | 1673 | else if (address < 0x8000) |
| 1671 | 1674 | { |
| 1672 | | if (snes_has_addon_chip == HAS_OBC1) |
| 1675 | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1676 | snes_ram[0x700000 + (address & 0x1fff)] = data; |
| 1677 | else if (snes_has_addon_chip == HAS_OBC1) |
| 1673 | 1678 | obc1_write(space, offset, data); |
| 1674 | 1679 | else if ((snes_has_addon_chip == HAS_DSP2) && (offset >= 0x200000)) |
| 1675 | 1680 | DSP2_write(data); |
| r5573 | r5574 | |
| 2478 | 2483 | |
| 2479 | 2484 | WRITE8_HANDLER( superfx_w_bank3 ) |
| 2480 | 2485 | { |
| 2486 | //printf( "superfx_w_bank3: %08x = %02x\n", 0x600000 + offset, data ); |
| 2481 | 2487 | snes_ram[0x600000 + offset] = data; |
| 2482 | 2488 | } |
src/emu/cpu/superfx/superfx.c
| r5573 | r5574 | |
| 530 | 530 | |
| 531 | 531 | addr &= 0xffff; |
| 532 | 532 | |
| 533 | //printf( "superfx_mmio_write: %08x = %02x\n", addr, data ); |
| 534 | |
| 533 | 535 | if(addr >= 0x3100 && addr <= 0x32ff) |
| 534 | 536 | { |
| 535 | 537 | return superfx_cache_mmio_write(cpustate, addr - 0x3100, data); |
| r5573 | r5574 | |
| 573 | 575 | break; |
| 574 | 576 | |
| 575 | 577 | case 0x3033: |
| 576 | | cpustate->bramr = data; |
| 578 | cpustate->bramr = data & 1; |
| 577 | 579 | break; |
| 578 | 580 | |
| 579 | 581 | case 0x3034: |
| 580 | | cpustate->pbr = data; |
| 582 | cpustate->pbr = data & 0x7f; |
| 581 | 583 | superfx_cache_flush(cpustate); |
| 582 | 584 | break; |
| 583 | 585 | |
| r5573 | r5574 | |
| 591 | 593 | break; |
| 592 | 594 | |
| 593 | 595 | case 0x3039: |
| 594 | | cpustate->clsr = data; |
| 596 | cpustate->clsr = data & 1; |
| 595 | 597 | superfx_update_speed(cpustate); |
| 596 | 598 | break; |
| 597 | 599 | |
| r5573 | r5574 | |
| 1169 | 1171 | { // DIV2 |
| 1170 | 1172 | cpustate->sfr &= ~SUPERFX_SFR_CY; |
| 1171 | 1173 | cpustate->sfr |= (*(cpustate->sreg) & 1) ? SUPERFX_SFR_CY : 0; |
| 1172 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, ((INT16)(*(cpustate->sreg)) >> 1) + ((*(cpustate->sreg) + 1) >> 16)); |
| 1174 | superfx_gpr_write(cpustate, cpustate->dreg_idx, ((INT16)(*(cpustate->sreg)) >> 1) + ((UINT32)(*(cpustate->sreg) + 1) >> 16)); |
| 1173 | 1175 | superfx_dreg_sfr_sz_update(cpustate); |
| 1174 | 1176 | superfx_regs_reset(cpustate); |
| 1175 | 1177 | } |
| r5573 | r5574 | |
| 1194 | 1196 | } |
| 1195 | 1197 | else |
| 1196 | 1198 | { // LJMP |
| 1197 | | cpustate->pbr = cpustate->r[op & 0xf]; |
| 1199 | cpustate->pbr = cpustate->r[op & 0xf] & 0x7f; |
| 1198 | 1200 | superfx_gpr_write(cpustate, 15, *(cpustate->sreg)); |
| 1199 | 1201 | cpustate->cbr = cpustate->r[15] & 0xfff0; |
| 1200 | 1202 | superfx_cache_flush(cpustate); |
| r5573 | r5574 | |
| 1319 | 1321 | break; |
| 1320 | 1322 | case SUPERFX_SFR_ALT2: // RAMB |
| 1321 | 1323 | superfx_rambuffer_sync(cpustate); |
| 1322 | | cpustate->rambr = *(cpustate->sreg); |
| 1324 | cpustate->rambr = ((*(cpustate->sreg)) & 1) ? 1 : 0; |
| 1323 | 1325 | superfx_regs_reset(cpustate); |
| 1324 | 1326 | break; |
| 1325 | 1327 | case SUPERFX_SFR_ALT3: // ROMB |
| 1326 | 1328 | superfx_rombuffer_sync(cpustate); |
| 1327 | | cpustate->rombr = *(cpustate->sreg); |
| 1329 | cpustate->rombr = *(cpustate->sreg) & 0x7f; |
| 1328 | 1330 | superfx_regs_reset(cpustate); |
| 1329 | 1331 | break; |
| 1330 | 1332 | } |
src/mess/machine/snescart.c
| r5573 | r5574 | |
| 552 | 552 | /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and |
| 553 | 553 | * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real) |
| 554 | 554 | */ |
| 555 | | while (read_blocks < 128 && read_blocks < total_blocks) |
| 555 | if((temp_buffer[0x007fd6] >= 0x13 && temp_buffer[0x007fd6] <= 0x15) || temp_buffer[0x007fd6] == 0xa) |
| 556 | 556 | { |
| 557 | | /* Loading data */ |
| 558 | | image_fread(image, &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000); |
| 559 | | /* Mirroring */ |
| 560 | | memcpy(&snes_ram[0x808000 + (read_blocks * 0x10000)], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000); |
| 561 | | read_blocks++; |
| 557 | while (read_blocks < 64 && read_blocks < total_blocks) |
| 558 | { |
| 559 | /* Loading data primary: banks 0-3f from 8000-ffff*/ |
| 560 | image_fread(image, &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000); |
| 561 | /* Mirroring at banks 80-bf from 8000-ffff */ |
| 562 | memcpy(&snes_ram[0x808000 + (read_blocks * 0x10000)], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000); |
| 563 | read_blocks++; |
| 564 | } |
| 565 | |
| 566 | image_fseek(image, offset, SEEK_SET); |
| 567 | /* Loading data secondary, filling full 64k banks from 0x400000 to 600000 */ |
| 568 | image_fread(image, &snes_ram[0x400000], total_blocks * 0x8000); |
| 569 | /* mirror at c00000-e00000 */ |
| 570 | memcpy( &snes_ram[0xc00000], &snes_ram[0x400000], total_blocks * 0x8000); |
| 562 | 571 | } |
| 563 | | /* Filling banks up to 0x7f and their mirrors */ |
| 564 | | while (read_blocks % 128) |
| 572 | else |
| 565 | 573 | { |
| 566 | | int j = 0, repeat_blocks; |
| 567 | | while ((read_blocks % (128 >> j)) && j < 7) |
| 568 | | j++; |
| 569 | | repeat_blocks = read_blocks % (128 >> (j - 1)); |
| 574 | while (read_blocks < 128 && read_blocks < total_blocks) |
| 575 | { |
| 576 | /* Loading data */ |
| 577 | image_fread(image, &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000); |
| 578 | /* Mirroring */ |
| 579 | memcpy(&snes_ram[0x808000 + (read_blocks * 0x10000)], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000); |
| 580 | read_blocks++; |
| 581 | } |
| 582 | /* Filling banks up to 0x7f and their mirrors */ |
| 583 | while (read_blocks % 128) |
| 584 | { |
| 585 | int j = 0, repeat_blocks; |
| 586 | while ((read_blocks % (128 >> j)) && j < 7) |
| 587 | j++; |
| 588 | repeat_blocks = read_blocks % (128 >> (j - 1)); |
| 570 | 589 | |
| 571 | | memcpy( &snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 572 | | memcpy( &snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 573 | | read_blocks += repeat_blocks; |
| 590 | memcpy( &snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 591 | memcpy( &snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 592 | read_blocks += repeat_blocks; |
| 593 | } |
| 574 | 594 | } |
| 575 | 595 | break; |
| 576 | 596 | } |
| r5573 | r5574 | |
| 757 | 777 | logerror( "\tNMI Address: %2X%2Xh\n", snes_r_bank1(space, 0x00fffb), snes_r_bank1(space, 0x00fffa) ); |
| 758 | 778 | logerror( "\tStart Address: %2X%2Xh\n\n", snes_r_bank1(space, 0x00fffd), snes_r_bank1(space, 0x00fffc) ); |
| 759 | 779 | |
| 780 | logerror( "\tMode: %d\n", snes_cart.mode); |
| 781 | |
| 760 | 782 | if (!supported_type) |
| 761 | 783 | logerror("WARNING: This cart type \"%s\" is not supported yet!\n", types[snes_has_addon_chip]); |
| 762 | 784 | } |