trunk/src/mess/machine/sns_sa1.c
| r24027 | r24028 | |
| 38 | 38 | haruaug3a, pebble, haruaug3: uses SA-1 DMA |
| 39 | 39 | itoibass: boots, some missing gfx |
| 40 | 40 | jikkparo: plays OK |
| 41 | | jl96drem: sprites corrupt in gameplay, SA-1 DMA/character conversion? |
| 42 | | jumpind: boots and runs, uses SA-1 DMA and character conversion |
| 41 | jl96drem: plays OK |
| 42 | jumpind: boots and runs, uses SA-1 normal DMA only but has corrupt gfx |
| 43 | 43 | kakinoki: S-CPU crashes after pressing start |
| 44 | 44 | kirby3j, kirby3: uses SA-1 DMA |
| 45 | 45 | kirbysdb, kirbyss, kirbyfun, kirbysd, kirbysda: plays OK |
| 46 | | marvelou: plays OK, some gfx corruption |
| 46 | marvelou: plays OK, uses SA-1 normal DMA only but has corrupt gfx |
| 47 | 47 | miniyonk: plays OK |
| 48 | 48 | panicbw: plays OK |
| 49 | 49 | pgaeuro, pgaeurou, pga96, pga96u, pga, pgaj: plays OK |
| r24027 | r24028 | |
| 56 | 56 | shinshog: plays OK |
| 57 | 57 | shogisai: plays OK |
| 58 | 58 | shogisa2: plays OK |
| 59 | | smrpgj, smrpg: boots, can't start game (SRAM mapping?) |
| 59 | smrpgj, smrpg: needs SA-1 character conversion for level up Bonus Chance (possible to get past now) |
| 60 | 60 | srobotg: some corrupt in-game GFX, may be SNES rendering errors |
| 61 | 61 | sshogi3: plays OK |
| 62 | 62 | taikyoid: plays OK |
| r24027 | r24028 | |
| 66 | 66 | |
| 67 | 67 | ***********************************************************************************************************/ |
| 68 | 68 | |
| 69 | | |
| 70 | 69 | #include "emu.h" |
| 71 | 70 | #include "machine/sns_sa1.h" |
| 72 | 71 | |
| r24027 | r24028 | |
| 142 | 141 | m_vcr = 0; |
| 143 | 142 | m_scpu_sie = m_sa1_sie = 0; |
| 144 | 143 | m_scpu_flags = m_sa1_flags = 0; |
| 144 | m_dma_ctrl = 0; |
| 145 | m_dma_ccparam = 0; |
| 146 | m_dma_cnt = 0; |
| 145 | 147 | |
| 146 | 148 | // sa-1 CPU starts out not running? |
| 147 | 149 | m_sa1->set_input_line(INPUT_LINE_HALT, ASSERT_LINE); |
| r24027 | r24028 | |
| 190 | 192 | |
| 191 | 193 | // handle this separately to avoid accessing recursively the regs? |
| 192 | 194 | |
| 193 | | inline UINT8 sns_sa1_device::var_length_read(address_space &space, UINT32 offset) |
| 195 | UINT8 sns_sa1_device::var_length_read(address_space &space, UINT32 offset) |
| 194 | 196 | { |
| 195 | 197 | // handle 0xffea/0xffeb/0xffee/0xffef |
| 196 | 198 | if ((offset & 0xffffe0) == 0x00ffe0) |
| r24027 | r24028 | |
| 211 | 213 | return read_h(space, (offset & 0x7fffff)); |
| 212 | 214 | |
| 213 | 215 | if ((offset & 0x40e000) == 0x006000) //$00-3f|80-bf:6000-7fff |
| 214 | | return read_bwram((m_bwram_sa1 * 0x2000) + (offset & 0x1fff)); |
| 216 | return read_bwram((m_bwram_snes * 0x2000) + (offset & 0x1fff)); |
| 215 | 217 | |
| 216 | 218 | if ((offset & 0xf00000) == 0x400000) //$40-4f:0000-ffff |
| 217 | 219 | return read_bwram(offset & 0xfffff); |
| r24027 | r24028 | |
| 225 | 227 | return 0; |
| 226 | 228 | } |
| 227 | 229 | |
| 230 | void sns_sa1_device::dma_transfer(address_space &space) |
| 231 | { |
| 232 | // printf("DMA src %08x (%d), dst %08x (%d) cnt %d\n", m_src_addr, m_dma_ctrl & 3, m_dst_addr, m_dma_ctrl & 4, m_dma_cnt); |
| 233 | |
| 234 | while (m_dma_cnt--) |
| 235 | { |
| 236 | UINT8 data = 0; // open bus? |
| 237 | UINT32 dma_src = m_src_addr++; |
| 238 | UINT32 dma_dst = m_dst_addr++; |
| 239 | |
| 240 | // source and destination cannot be the same |
| 241 | // source = { 0=ROM, 1=BWRAM, 2=IRAM } |
| 242 | // destination = { 0=IRAM, 1=BWRAM } |
| 243 | if ((m_dma_ctrl & 0x03) == 1 && (m_dma_ctrl & 0x04) == 0x04) continue; |
| 244 | if ((m_dma_ctrl & 0x03) == 2 && (m_dma_ctrl & 0x04) == 0x00) continue; |
| 245 | |
| 246 | switch (m_dma_ctrl & 0x03) |
| 247 | { |
| 248 | case 0: // ROM |
| 249 | if ((dma_src & 0x408000) == 0x008000 && (dma_src & 0x800000) == 0x000000) |
| 250 | { |
| 251 | data = read_l(space, (dma_src & 0x7fffff)); |
| 252 | } |
| 253 | if ((dma_src & 0x408000) == 0x008000 && (dma_src & 0x800000) == 0x800000) |
| 254 | { |
| 255 | data = read_h(space, (dma_src & 0x7fffff)); |
| 256 | } |
| 257 | if ((dma_src & 0xc00000) == 0xc00000) |
| 258 | { |
| 259 | data = read_h(space, (dma_src & 0x7fffff)); |
| 260 | } |
| 261 | break; |
| 262 | |
| 263 | case 1: // BWRAM |
| 264 | if ((dma_src & 0x40e000) == 0x006000) |
| 265 | { |
| 266 | data = read_bwram((m_bwram_sa1 * 0x2000) + (dma_src & 0x1fff)); |
| 267 | } |
| 268 | if ((dma_src & 0xf00000) == 0x400000) |
| 269 | { |
| 270 | data = read_bwram(dma_src & 0xfffff); |
| 271 | } |
| 272 | break; |
| 273 | |
| 274 | case 2: // IRAM |
| 275 | data = read_iram(dma_src); |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | switch (m_dma_ctrl & 0x04) |
| 280 | { |
| 281 | case 0x00: // IRAM |
| 282 | write_iram(dma_dst, data); |
| 283 | break; |
| 284 | |
| 285 | case 0x04: // BWRAM |
| 286 | if ((dma_dst & 0x40e000) == 0x006000) |
| 287 | { |
| 288 | write_bwram((m_bwram_sa1 * 0x2000) + (dma_dst & 0x1fff), data); |
| 289 | } |
| 290 | if ((dma_dst & 0xf00000) == 0x400000) |
| 291 | { |
| 292 | write_bwram(dma_dst & 0xfffff, data); |
| 293 | } |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | m_sa1_flags |= SA1_IRQ_DMA; |
| 299 | recalc_irqs(); |
| 300 | } |
| 301 | |
| 302 | void sns_sa1_device::dma_cctype1_transfer(address_space &space) |
| 303 | { |
| 304 | m_scpu_flags |= SCPU_IRQ_CHARCONV; |
| 305 | recalc_irqs(); |
| 306 | } |
| 307 | |
| 308 | void sns_sa1_device::dma_cctype2_transfer(address_space &space) |
| 309 | { |
| 310 | } |
| 311 | |
| 228 | 312 | UINT8 sns_sa1_device::read_regs(address_space &space, UINT32 offset) |
| 229 | 313 | { |
| 230 | 314 | UINT8 value = 0xff; |
| r24027 | r24028 | |
| 321 | 405 | return value; |
| 322 | 406 | } |
| 323 | 407 | |
| 324 | | void sns_sa1_device::write_regs(UINT32 offset, UINT8 data) |
| 408 | void sns_sa1_device::write_regs(address_space &space, UINT32 offset, UINT8 data) |
| 325 | 409 | { |
| 326 | 410 | offset &= 0x1ff; // $2200 + offset gives the reg value to compare with docs |
| 327 | 411 | |
| r24027 | r24028 | |
| 544 | 628 | case 0x030: |
| 545 | 629 | // SA-1 DCNT 00h DMA Control (W) |
| 546 | 630 | // printf("%02x to SA-1 DMA control\n", data); |
| 631 | m_dma_ctrl = data; |
| 547 | 632 | break; |
| 548 | 633 | case 0x031: |
| 549 | 634 | // Both CDMA 00h Character Conversion DMA Parameters (W) |
| 635 | m_dma_ccparam = data; |
| 550 | 636 | break; |
| 551 | 637 | case 0x032: |
| 552 | 638 | // DMA Source Device Start Address Low |
| r24027 | r24028 | |
| 567 | 653 | case 0x036: |
| 568 | 654 | // DMA Dest Device Start Address Mid |
| 569 | 655 | m_dst_addr = (m_dst_addr & 0xff00ff) | (data << 8); |
| 570 | | break; |
| 656 | if (m_dma_ctrl & 0x80) |
| 657 | { |
| 658 | if (!(m_dma_ctrl & 0x20) && !(m_dma_ctrl & 0x04)) // Normal DMA to IRAM |
| 659 | { |
| 660 | dma_transfer(space); |
| 661 | // printf("SA-1: normal DMA to IRAM\n"); |
| 662 | } |
| 663 | |
| 664 | if (m_dma_ctrl & 0x20 && m_dma_ctrl & 0x10) // CC DMA Type 1 |
| 665 | { |
| 666 | // printf("SA-1: CC DMA type 1\n"); |
| 667 | dma_cctype1_transfer(space); |
| 668 | } |
| 669 | } |
| 670 | break; |
| 571 | 671 | case 0x037: |
| 572 | 672 | // DMA Dest Device Start Address High |
| 573 | 673 | m_dst_addr = (m_dst_addr & 0xffff00) | (data << 16); |
| 674 | if (m_dma_ctrl & 0x80) |
| 675 | { |
| 676 | if (!(m_dma_ctrl & 0x20) && m_dma_ctrl & 0x04) // Normal DMA to BWRAM |
| 677 | { |
| 678 | // printf("SA-1: normal DMA to BWRAM\n"); |
| 679 | dma_transfer(space); |
| 680 | } |
| 681 | } |
| 574 | 682 | break; |
| 575 | 683 | case 0x038: |
| 576 | 684 | // SA-1 DTC - DMA Terminal Counter Lsb (W) |
| 685 | m_dma_cnt &= 0xff00; |
| 686 | m_dma_cnt |= data; |
| 577 | 687 | break; |
| 578 | 688 | case 0x039: |
| 579 | 689 | // SA-1 DTC - DMA Terminal Counter Msb (W) |
| 690 | m_dma_cnt &= 0x00ff; |
| 691 | m_dma_cnt |= (data<<8); |
| 580 | 692 | break; |
| 581 | 693 | case 0x03f: |
| 582 | 694 | // Format for BWRAM when mapped to bitmap |
| r24027 | r24028 | |
| 600 | 712 | case 0x04f: |
| 601 | 713 | // Bit Map Register File (2240h..224Fh) |
| 602 | 714 | m_brf_reg[offset & 0x0f] = data; |
| 715 | if ((offset & 0x07) == 7 && m_dma_ctrl & 0x80) |
| 716 | { |
| 717 | if (m_dma_ctrl & 0x20 && !(m_dma_ctrl & 0x10)) // CC DMA Type 2 |
| 718 | { |
| 719 | // printf("SA-1: CC DMA type 2\n"); |
| 720 | dma_cctype2_transfer(space); |
| 721 | } |
| 722 | } |
| 603 | 723 | break; |
| 604 | 724 | case 0x050: |
| 605 | 725 | // Math control |
| r24027 | r24028 | |
| 773 | 893 | { |
| 774 | 894 | int bank = 0; |
| 775 | 895 | |
| 896 | if (offset == 0xffea && BIT(m_scpu_ctrl, 4)) return (m_nmi_vector >> 0) & 0xff; |
| 897 | if (offset == 0xffeb && BIT(m_scpu_ctrl, 4)) return (m_nmi_vector >> 8) & 0xff; |
| 898 | if (offset == 0xffee && BIT(m_scpu_ctrl, 6)) return (m_irq_vector >> 0) & 0xff; |
| 899 | if (offset == 0xffef && BIT(m_scpu_ctrl, 6)) return (m_irq_vector >> 8) & 0xff; |
| 900 | |
| 776 | 901 | // ROM is mapped to [00-3f][8000-ffff] only here |
| 777 | 902 | if (offset < 0x200000) |
| 778 | 903 | { |
| r24027 | r24028 | |
| 868 | 993 | UINT16 address = offset & 0xffff; |
| 869 | 994 | |
| 870 | 995 | if (offset < 0x400000 && address >= 0x2200 && address < 0x2400) |
| 871 | | write_regs(address & 0x1ff, data); // SA-1 Regs |
| 996 | write_regs(space, address & 0x1ff, data); // SA-1 Regs |
| 872 | 997 | |
| 873 | 998 | if (offset < 0x400000 && address >= 0x3000 && address < 0x3800) |
| 874 | 999 | write_iram(address & 0x7ff, data); // Internal SA-1 RAM (2K) |
| r24027 | r24028 | |
| 932 | 1057 | } |
| 933 | 1058 | else if (address < 0x8000) |
| 934 | 1059 | return read_bwram((m_bwram_sa1 * 0x2000) + (offset & 0x1fff) + (m_bwram_sa1_source * 0x100000)); // SA-1 BWRAM |
| 935 | | else if (address == 0xffee) |
| 1060 | else if (offset == 0xffee) |
| 936 | 1061 | { |
| 937 | 1062 | return m_sa1_irq & 0xff; |
| 938 | 1063 | } |
| 939 | | else if (address == 0xffef) |
| 1064 | else if (offset == 0xffef) |
| 940 | 1065 | { |
| 941 | 1066 | return m_sa1_irq>>8; |
| 942 | 1067 | } |
| 943 | | else if (address == 0xffea) |
| 1068 | else if (offset == 0xffea) |
| 944 | 1069 | { |
| 945 | 1070 | return m_sa1_nmi & 0xff; |
| 946 | 1071 | } |
| 947 | | else if (address == 0xffeb) |
| 1072 | else if (offset == 0xffeb) |
| 948 | 1073 | { |
| 949 | 1074 | return m_sa1_nmi>>8; |
| 950 | 1075 | } |
| 951 | | else if (address == 0xfffc) |
| 1076 | else if (offset == 0xfffc) |
| 952 | 1077 | { |
| 953 | 1078 | return m_sa1_reset & 0xff; |
| 954 | 1079 | } |
| 955 | | else if (address == 0xfffd) |
| 1080 | else if (offset == 0xfffd) |
| 956 | 1081 | { |
| 957 | 1082 | return m_sa1_reset>>8; |
| 958 | 1083 | } |
| r24027 | r24028 | |
| 979 | 1104 | if (address < 0x0800) |
| 980 | 1105 | write_iram(offset, data); // Internal SA-1 RAM (2K) |
| 981 | 1106 | else if (address >= 0x2200 && address < 0x2400) |
| 982 | | write_regs(offset & 0x1ff, data); // SA-1 Regs |
| 1107 | write_regs(space, offset & 0x1ff, data); // SA-1 Regs |
| 983 | 1108 | else if (address >= 0x3000 && address < 0x3800) |
| 984 | 1109 | write_iram(offset, data); // Internal SA-1 RAM (2K) |
| 985 | 1110 | } |