src/mame/drivers/megadriv.c
| r9243 | r9244 | |
| 619 | 619 | |
| 620 | 620 | static UINT16 vdp_get_word_from_68k_mem_default(running_machine *machine, UINT32 source) |
| 621 | 621 | { |
| 622 | // should we limit the valid areas here? |
| 623 | // how does this behave with the segacd etc? |
| 624 | // with the 32x it seems to see the raw cart? - using 68k space causes the character to vanish |
| 625 | // svp uses it's own function elsewhere... |
| 626 | |
| 622 | 627 | if (( source >= 0x000000 ) && ( source <= 0x3fffff )) |
| 623 | 628 | { |
| 624 | 629 | UINT16 *rom = (UINT16*)memory_region(machine, "maincpu"); |
| r9243 | r9244 | |
| 636 | 641 | return mame_rand(machine); |
| 637 | 642 | } |
| 638 | 643 | |
| 644 | |
| 639 | 645 | } |
| 640 | 646 | |
| 641 | 647 | /* Table from Charles Macdonald |
| r9243 | r9244 | |
| 2100 | 2106 | timer_set( space->machine, attotime_zero, NULL, 0, megadriv_z80_run_state ); |
| 2101 | 2107 | } |
| 2102 | 2108 | |
| 2109 | |
| 2110 | // just directly access the 68k space, this makes it easier to deal with |
| 2111 | // add-on hardware which changes the cpu mapping like the 32x and SegaCD. |
| 2112 | // - we might need to add exceptions for example, z80 reading / writing the |
| 2113 | // z80 area of the 68k if games misbehave |
| 2103 | 2114 | static READ8_HANDLER( z80_read_68k_banked_data ) |
| 2104 | 2115 | { |
| 2105 | | // genz80.z80_bank_addr contains the address to read |
| 2116 | address_space *space68k = space->machine->device<legacy_cpu_device>("maincpu")->space(); |
| 2117 | UINT8 ret = space68k->read_byte(genz80.z80_bank_addr+offset); |
| 2118 | return ret; |
| 2119 | } |
| 2106 | 2120 | |
| 2107 | | if ((genz80.z80_bank_addr >= 0x000000) && (genz80.z80_bank_addr <= 0x3fffff)) // ROM Addresses |
| 2108 | | { |
| 2109 | | UINT32 fulladdress; |
| 2110 | | fulladdress = genz80.z80_bank_addr + offset; |
| 2111 | | |
| 2112 | | return memory_region(space->machine, "maincpu")[fulladdress^1]; // ^1? better.. |
| 2113 | | |
| 2114 | | |
| 2115 | | } |
| 2116 | | else |
| 2117 | | { |
| 2118 | | if (_32x_is_connected) |
| 2119 | | { |
| 2120 | | if ((genz80.z80_bank_addr >= 0x880000) && (genz80.z80_bank_addr <= 0x900000)) // 'fixed' 512kb 32x rom |
| 2121 | | { |
| 2122 | | UINT32 fulladdress; |
| 2123 | | fulladdress = (genz80.z80_bank_addr + offset)&0x3ffff; |
| 2124 | | |
| 2125 | | return memory_region(space->machine, "gamecart")[fulladdress^1]; // ^1? better.. |
| 2126 | | |
| 2127 | | |
| 2128 | | } |
| 2129 | | else if ((genz80.z80_bank_addr >= 0x900000) && (genz80.z80_bank_addr <= 0x9fffff)) // 'banked' 1mb 32x rom |
| 2130 | | { |
| 2131 | | UINT32 fulladdress; |
| 2132 | | fulladdress = (genz80.z80_bank_addr + offset)&0x7ffff; |
| 2133 | | |
| 2134 | | fulladdress |= (_32x_68k_a15104_reg&0x3)*0x80000; |
| 2135 | | |
| 2136 | | return memory_region(space->machine, "gamecart")[fulladdress^1]; // ^1? better.. |
| 2137 | | |
| 2138 | | } |
| 2139 | | } |
| 2140 | | |
| 2141 | | printf("unhandled z80 bank read, gen.z80_bank_addr %08x\n",genz80.z80_bank_addr); |
| 2142 | | return 0x0000; |
| 2143 | | } |
| 2144 | | |
| 2121 | static WRITE8_HANDLER( z80_write_68k_banked_data ) |
| 2122 | { |
| 2123 | address_space *space68k = space->machine->device<legacy_cpu_device>("maincpu")->space(); |
| 2124 | space68k->write_byte(genz80.z80_bank_addr+offset,data); |
| 2145 | 2125 | } |
| 2146 | 2126 | |
| 2147 | 2127 | |
| r9243 | r9244 | |
| 2162 | 2142 | |
| 2163 | 2143 | } |
| 2164 | 2144 | |
| 2165 | | static WRITE8_HANDLER( z80_write_68k_banked_data ) |
| 2166 | | { |
| 2167 | | UINT32 fulladdress; |
| 2168 | | fulladdress = genz80.z80_bank_addr + offset; |
| 2169 | 2145 | |
| 2170 | 2146 | |
| 2171 | | // mame_printf_debug("z80_write_68k_banked_data %04x %02x\n",offset,data); |
| 2172 | | if ((fulladdress >= 0x000000) && (fulladdress <= 0x3fffff)) // ROM Addresses |
| 2173 | | { |
| 2174 | | |
| 2175 | | //mame_printf_debug("z80 write to 68k rom??\n"); |
| 2176 | | } |
| 2177 | | else if ((fulladdress >= 0xe00000) && (fulladdress <= 0xffffff)) // ROM Addresses |
| 2178 | | { |
| 2179 | | fulladdress &=0xffff; |
| 2180 | | /* Cheese Cat-Astrophe Starring Speedy Gonzales (E) (M4) [!] has no sound without this */ |
| 2181 | | if (fulladdress&1) megadrive_ram[fulladdress>>1] = (megadrive_ram[fulladdress>>1]&0xff00) | (data); |
| 2182 | | else megadrive_ram[fulladdress>>1] = (megadrive_ram[fulladdress>>1]&0x00ff) | (data <<8); |
| 2183 | | } |
| 2184 | | else if (fulladdress == 0xc00011) |
| 2185 | | { |
| 2186 | | /* quite a few early games write here, most of the later ones don't */ |
| 2187 | | sn76496_w(space->machine->device("snsnd"), 0, data); |
| 2188 | | } |
| 2189 | | else |
| 2190 | | { |
| 2191 | | |
| 2192 | | //printf("z80 write to 68k address %06x\n",fulladdress); |
| 2193 | | } |
| 2194 | | |
| 2195 | | } |
| 2196 | | |
| 2197 | 2147 | static READ8_HANDLER( megadriv_z80_vdp_read ) |
| 2198 | 2148 | { |
| 2199 | 2149 | mame_printf_debug("megadriv_z80_vdp_read %02x\n",offset); |