src/mess/machine/genesis.c
| r5653 | r5654 | |
| 25 | 25 | #include "includes/genesis.h" |
| 26 | 26 | |
| 27 | 27 | |
| 28 | | static UINT16 squirrel_king_extra = 0; |
| 29 | | static UINT16 lion2_prot1_data, lion2_prot2_data; |
| 30 | | static UINT16 realtek_bank_addr=0, realtek_bank_size=0, realtek_old_bank_addr; |
| 31 | | static UINT16 g_l3alt_pdat; |
| 32 | | static UINT16 g_l3alt_pcmd; |
| 33 | | |
| 34 | | static int genesis_last_loaded_image_length = -1; |
| 35 | | |
| 36 | | |
| 37 | 28 | #define MAX_MD_CART_SIZE 0x500000 |
| 38 | 29 | |
| 39 | 30 | /* where a fresh copy of rom is stashed for reset and banking setup */ |
| 40 | 31 | #define VIRGIN_COPY_GEN 0xd00000 |
| 41 | 32 | |
| 42 | | static UINT16 *genesis_sram, *megadriv_backupram; |
| 43 | | static int genesis_sram_start = 0; |
| 44 | | static int genesis_sram_end = 0; |
| 45 | | static int genesis_sram_active = 0; |
| 46 | | static int genesis_sram_readonly = 0; |
| 47 | | static int has_serial_eeprom = 0; |
| 48 | | static int sram_handlers_installed = 0; |
| 49 | | |
| 50 | | |
| 51 | | enum |
| 33 | enum t_cart_type |
| 52 | 34 | { |
| 53 | 35 | STANDARD = 0, |
| 54 | 36 | SSF2, /* Super Street Fighter 2 */ |
| 55 | | LIONK3, /* Lion King 3 */ |
| 37 | LIONK3, /* Lion King 3 */ |
| 56 | 38 | SKINGKONG, /* Super King Kong 99 */ |
| 57 | | SDK99, /* Super Donkey Kong 99 */ |
| 39 | SDK99, /* Super Donkey Kong 99 */ |
| 58 | 40 | REDCLIFF, /* Romance of the Three Kingdoms - Battle of Red Cliffs, already decoded from .mdx format */ |
| 59 | 41 | REDCL_EN, /* The encoded version... */ |
| 60 | | RADICA, /* Radica TV games.. these probably should be a seperate driver since they are a seperate 'console' */ |
| 61 | | KOF99, /* King of Fighters '99 */ |
| 42 | RADICA, /* Radica TV games.. these probably should be a seperate driver since they are a seperate 'console' */ |
| 43 | KOF99, /* King of Fighters '99 */ |
| 62 | 44 | SOULBLAD, /* Soul Blade */ |
| 63 | 45 | MJLOVER, /* Mahjong Lover */ |
| 64 | 46 | SQUIRRELK, /* Squirrel King */ |
| 65 | | SMOUSE, /* Smart Mouse */ |
| 47 | SMOUSE, /* Smart Mouse */ |
| 66 | 48 | SMB, /* Super Mario Bros. */ |
| 67 | 49 | SMB2, /* Super Mario Bros. 2 */ |
| 68 | | KAIJU, |
| 50 | KAIJU, /* Pokemon Stadium */ |
| 69 | 51 | CHINFIGHT3, /* Chinese Fighters 3 */ |
| 70 | | LIONK2, /* Lion King 2 */ |
| 52 | LIONK2, /* Lion King 2 */ |
| 71 | 53 | BUGSLIFE, /* A Bug's Life */ |
| 72 | | ELFWOR, /* Elf Wor */ |
| 54 | ELFWOR, /* Elf Wor */ |
| 73 | 55 | ROCKMANX3, /* Rockman X3 */ |
| 74 | 56 | SBUBBOB, /* Super Bubble Bobble */ |
| 75 | | KOF98, /* King of Fighters '98 */ |
| 57 | KOF98, /* King of Fighters '98 */ |
| 76 | 58 | REALTEC, /* Whac a Critter/Mallet legend, Defend the Earth, Funnyworld/Ballonboy */ |
| 77 | 59 | SUP19IN1, /* Super 19 in 1 */ |
| 78 | | SUP15IN1, /* Super 15 in 1 */ |
| 60 | SUP15IN1 /* Super 15 in 1 */ |
| 79 | 61 | }; |
| 80 | 62 | |
| 81 | 63 | |
| 82 | | static int cart_type = STANDARD; |
| 64 | static enum t_cart_type cart_type; |
| 83 | 65 | |
| 84 | 66 | |
| 67 | static UINT16 squirrel_king_extra; |
| 68 | static UINT16 lion2_prot1_data, lion2_prot2_data; |
| 69 | static UINT16 realtec_bank_addr, realtec_bank_size, realtec_old_bank_addr; |
| 70 | static UINT16 g_l3alt_pdat; |
| 71 | static UINT16 g_l3alt_pcmd; |
| 72 | |
| 73 | static int genesis_last_loaded_image_length; |
| 74 | |
| 75 | static UINT16 *genesis_sram, *megadriv_backupram; |
| 76 | static int genesis_sram_start, genesis_sram_end; |
| 77 | static int genesis_sram_active, genesis_sram_readonly; |
| 78 | static int sram_handlers_installed; |
| 79 | |
| 80 | static int has_serial_eeprom; |
| 81 | |
| 82 | |
| 85 | 83 | /************************************* |
| 86 | 84 | * |
| 87 | 85 | * Handlers for custom mappers |
| r5653 | r5654 | |
| 93 | 91 | static int lastoffset = -1,lastdata = -1; |
| 94 | 92 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 95 | 93 | |
| 96 | | if ((lastoffset != offset) || (lastdata != data)) { |
| 94 | if ((lastoffset != offset) || (lastdata != data)) |
| 95 | { |
| 97 | 96 | lastoffset = offset; lastdata = data; |
| 98 | | switch (offset<<1) |
| 97 | switch (offset << 1) |
| 99 | 98 | { |
| 100 | 99 | case 0x00: /* write protect register // this is not a write protect, but seems to do nothing useful but reset bank0 after the checksum test (red screen otherwise) */ |
| 101 | | if (data == 2) { |
| 102 | | memcpy(ROM + 0x000000, ROM + 0x400000+(((data&0xf)-2)*0x080000), 0x080000); |
| 100 | if (data == 2) |
| 101 | { |
| 102 | memcpy(ROM + 0x000000, ROM + 0x400000 + (((data & 0xf) - 2) * 0x080000), 0x080000); |
| 103 | 103 | } |
| 104 | 104 | break; |
| 105 | 105 | case 0x02: /* 0x080000 - 0x0FFFFF */ |
| 106 | | memcpy(ROM + 0x080000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 106 | memcpy(ROM + 0x080000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 107 | 107 | break; |
| 108 | 108 | case 0x04: /* 0x100000 - 0x17FFFF */ |
| 109 | | memcpy(ROM + 0x100000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 109 | memcpy(ROM + 0x100000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 110 | 110 | break; |
| 111 | 111 | case 0x06: /* 0x180000 - 0x1FFFFF */ |
| 112 | | memcpy(ROM + 0x180000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 112 | memcpy(ROM + 0x180000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 113 | 113 | break; |
| 114 | 114 | case 0x08: /* 0x200000 - 0x27FFFF */ |
| 115 | | memcpy(ROM + 0x200000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 115 | memcpy(ROM + 0x200000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 116 | 116 | break; |
| 117 | 117 | case 0x0a: /* 0x280000 - 0x2FFFFF */ |
| 118 | | memcpy(ROM + 0x280000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 118 | memcpy(ROM + 0x280000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 119 | 119 | break; |
| 120 | 120 | case 0x0c: /* 0x300000 - 0x37FFFF */ |
| 121 | | memcpy(ROM + 0x300000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 121 | memcpy(ROM + 0x300000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 122 | 122 | break; |
| 123 | 123 | case 0x0e: /* 0x380000 - 0x3FFFFF */ |
| 124 | | memcpy(ROM + 0x380000, ROM + 0x400000+((data&0xf)*0x080000), 0x080000); |
| 124 | memcpy(ROM + 0x380000, ROM + 0x400000 + ((data & 0xf) * 0x080000), 0x080000); |
| 125 | 125 | break; |
| 126 | 126 | } |
| 127 | 127 | } |
| r5653 | r5654 | |
| 142 | 142 | { |
| 143 | 143 | int retdata = 0; |
| 144 | 144 | |
| 145 | | offset &=0x7; |
| 145 | offset &= 0x07; |
| 146 | 146 | |
| 147 | 147 | switch (offset) |
| 148 | 148 | { |
| r5653 | r5654 | |
| 152 | 152 | switch (g_l3alt_pcmd) |
| 153 | 153 | { |
| 154 | 154 | case 1: |
| 155 | | retdata = g_l3alt_pdat>>1; |
| 155 | retdata = g_l3alt_pdat >> 1; |
| 156 | 156 | break; |
| 157 | 157 | |
| 158 | 158 | case 2: |
| 159 | | retdata = g_l3alt_pdat>>4; |
| 160 | | retdata |= (g_l3alt_pdat&0x0f)<<4; |
| 159 | retdata = g_l3alt_pdat >> 4; |
| 160 | retdata |= (g_l3alt_pdat & 0x0f) << 4; |
| 161 | 161 | break; |
| 162 | 162 | |
| 163 | 163 | default: |
| 164 | | /* printf("unk prot case %d\n",g_l3alt_pcmd); */ |
| 165 | | retdata = (((g_l3alt_pdat>>7)&1)<<0); |
| 166 | | retdata |=(((g_l3alt_pdat>>6)&1)<<1); |
| 167 | | retdata |=(((g_l3alt_pdat>>5)&1)<<2); |
| 168 | | retdata |=(((g_l3alt_pdat>>4)&1)<<3); |
| 169 | | retdata |=(((g_l3alt_pdat>>3)&1)<<4); |
| 170 | | retdata |=(((g_l3alt_pdat>>2)&1)<<5); |
| 171 | | retdata |=(((g_l3alt_pdat>>1)&1)<<6); |
| 172 | | retdata |=(((g_l3alt_pdat>>0)&1)<<7); |
| 164 | /* printf("unk prot case %d\n", g_l3alt_pcmd); */ |
| 165 | retdata = (((g_l3alt_pdat >> 7) & 1) << 0); |
| 166 | retdata |= (((g_l3alt_pdat >> 6) & 1) << 1); |
| 167 | retdata |= (((g_l3alt_pdat >> 5) & 1) << 2); |
| 168 | retdata |= (((g_l3alt_pdat >> 4) & 1) << 3); |
| 169 | retdata |= (((g_l3alt_pdat >> 3) & 1) << 4); |
| 170 | retdata |= (((g_l3alt_pdat >> 2) & 1) << 5); |
| 171 | retdata |= (((g_l3alt_pdat >> 1) & 1) << 6); |
| 172 | retdata |= (((g_l3alt_pdat >> 0) & 1) << 7); |
| 173 | 173 | break; |
| 174 | 174 | } |
| 175 | 175 | break; |
| r5653 | r5654 | |
| 180 | 180 | break; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | | /* printf("%06x: g_l3alt_pdat_w %04x g_l3alt_pcmd_w %04x return %04x\n",activecpu_get_pc(), g_l3alt_pdat,g_l3alt_pcmd,retdata); */ |
| 183 | /* printf("%06x: g_l3alt_pdat_w %04x g_l3alt_pcmd_w %04x return %04x\n", activecpu_get_pc(), g_l3alt_pdat, g_l3alt_pcmd, retdata); */ |
| 184 | 184 | |
| 185 | 185 | return retdata; |
| 186 | | |
| 187 | 186 | } |
| 188 | 187 | |
| 189 | | static WRITE16_HANDLER( g_l3alt_protw ) |
| 188 | static WRITE16_HANDLER( g_l3alt_prot_w ) |
| 190 | 189 | { |
| 191 | | offset &=0x7; |
| 190 | offset &= 0x7; |
| 192 | 191 | |
| 193 | 192 | switch (offset) |
| 194 | 193 | { |
| r5653 | r5654 | |
| 206 | 205 | |
| 207 | 206 | static WRITE16_HANDLER( g_l3alt_bank_w ) |
| 208 | 207 | { |
| 209 | | offset &=0x7; |
| 208 | offset &= 0x7; |
| 210 | 209 | |
| 211 | 210 | switch (offset) |
| 212 | 211 | { |
| r5653 | r5654 | |
| 214 | 213 | { |
| 215 | 214 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 216 | 215 | /* printf("%06x data %04x\n",activecpu_get_pc(), data); */ |
| 217 | | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN + (data&0xffff)*0x8000], 0x8000); |
| 216 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN + (data & 0xffff) * 0x8000], 0x8000); |
| 218 | 217 | } |
| 219 | 218 | break; |
| 220 | 219 | |
| r5653 | r5654 | |
| 229 | 228 | |
| 230 | 229 | static WRITE16_HANDLER( realtec_402000_w ) |
| 231 | 230 | { |
| 232 | | realtek_bank_addr = 0; |
| 233 | | realtek_bank_size = (data>>8)&0x1f; |
| 231 | realtec_bank_addr = 0; |
| 232 | realtec_bank_size = (data >> 8) & 0x1f; |
| 234 | 233 | } |
| 235 | 234 | |
| 236 | 235 | static WRITE16_HANDLER( realtec_400000_w ) |
| r5653 | r5654 | |
| 239 | 238 | |
| 240 | 239 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 241 | 240 | |
| 242 | | realtek_old_bank_addr = realtek_bank_addr; |
| 243 | | realtek_bank_addr = (realtek_bank_addr & 0x7) | bankdata<<3; |
| 241 | realtec_old_bank_addr = realtec_bank_addr; |
| 242 | realtec_bank_addr = (realtec_bank_addr & 0x7) | bankdata << 3; |
| 244 | 243 | |
| 245 | | memcpy(ROM, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 246 | | memcpy(ROM+ realtek_bank_size*0x20000, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 244 | memcpy(ROM, ROM + (realtec_bank_addr * 0x20000) + 0x400000, realtec_bank_size * 0x20000); |
| 245 | memcpy(ROM + realtec_bank_size * 0x20000, ROM + (realtec_bank_addr * 0x20000) + 0x400000, realtec_bank_size * 0x20000); |
| 247 | 246 | } |
| 248 | 247 | |
| 249 | 248 | static WRITE16_HANDLER( realtec_404000_w ) |
| r5653 | r5654 | |
| 251 | 250 | int bankdata = (data >> 8) & 0x3; |
| 252 | 251 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 253 | 252 | |
| 254 | | realtek_old_bank_addr = realtek_bank_addr; |
| 255 | | realtek_bank_addr = (realtek_bank_addr & 0xf8)|bankdata; |
| 253 | realtec_old_bank_addr = realtec_bank_addr; |
| 254 | realtec_bank_addr = (realtec_bank_addr & 0xf8) | bankdata; |
| 256 | 255 | |
| 257 | | if (realtek_old_bank_addr != realtek_bank_addr) |
| 256 | if (realtec_old_bank_addr != realtec_bank_addr) |
| 258 | 257 | { |
| 259 | | memcpy(ROM, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 260 | | memcpy(ROM+ realtek_bank_size*0x20000, ROM + (realtek_bank_addr*0x20000)+0x400000, realtek_bank_size*0x20000); |
| 258 | memcpy(ROM, ROM + (realtec_bank_addr * 0x20000)+ 0x400000, realtec_bank_size * 0x20000); |
| 259 | memcpy(ROM + realtec_bank_size * 0x20000, ROM + (realtec_bank_addr * 0x20000) + 0x400000, realtec_bank_size * 0x20000); |
| 261 | 260 | } |
| 262 | 261 | } |
| 263 | 262 | |
| r5653 | r5654 | |
| 265 | 264 | { |
| 266 | 265 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 267 | 266 | |
| 268 | | if (data==0xf100) // *hit player |
| 267 | if (data == 0xf100) // *hit player |
| 269 | 268 | { |
| 270 | 269 | int x; |
| 271 | | for (x=0;x<0x100000;x+=0x10000) |
| 270 | for (x = 0; x < 0x100000; x += 0x10000) |
| 272 | 271 | { |
| 273 | 272 | memcpy(ROM + x, ROM + 0x410000, 0x10000); |
| 274 | 273 | } |
| 275 | 274 | } |
| 276 | | else if (data==0xd700) // title screen.. |
| 275 | else if (data == 0xd700) // title screen.. |
| 277 | 276 | { |
| 278 | 277 | int x; |
| 279 | | for (x=0;x<0x100000;x+=0x10000) |
| 278 | for (x = 0; x < 0x100000; x += 0x10000) |
| 280 | 279 | { |
| 281 | 280 | memcpy(ROM + x, ROM + 0x470000, 0x10000); |
| 282 | 281 | } |
| 283 | 282 | } |
| 284 | | else if (data==0xd300) // character hits floor |
| 283 | else if (data == 0xd300) // character hits floor |
| 285 | 284 | { |
| 286 | 285 | int x; |
| 287 | | for (x=0;x<0x100000;x+=0x10000) |
| 286 | for (x = 0; x < 0x100000; x += 0x10000) |
| 288 | 287 | { |
| 289 | 288 | memcpy(ROM + x, ROM + 0x430000, 0x10000); |
| 290 | 289 | } |
| 291 | 290 | } |
| 292 | | else if (data==0x0000) |
| 291 | else if (data == 0x0000) |
| 293 | 292 | { |
| 294 | 293 | int x; |
| 295 | | for (x=0;x<0x100000;x+=0x10000) |
| 294 | for (x = 0; x < 0x100000; x += 0x10000) |
| 296 | 295 | { |
| 297 | | memcpy(ROM + x, ROM + 0x400000+x, 0x10000); |
| 296 | memcpy(ROM + x, ROM + 0x400000 + x, 0x10000); |
| 298 | 297 | } |
| 299 | 298 | } |
| 300 | 299 | else |
| 301 | 300 | { |
| 302 | | logerror("%06x chifi3, bankw? %04x %04x\n",cpu_get_pc(space->cpu), offset,data); |
| 301 | logerror("%06x chifi3, bankw? %04x %04x\n", cpu_get_pc(space->cpu), offset, data); |
| 303 | 302 | } |
| 304 | 303 | |
| 305 | 304 | } |
| r5653 | r5654 | |
| 316 | 315 | 04cefa chifi3, prot_r? 65262 |
| 317 | 316 | */ |
| 318 | 317 | |
| 319 | | if (cpu_get_pc(space->cpu)==0x01782) // makes 'VS' screen appear |
| 318 | if (cpu_get_pc(space->cpu) == 0x01782) // makes 'VS' screen appear |
| 320 | 319 | { |
| 321 | | retdat = cpu_get_reg(space->cpu, M68K_D3)&0xff; |
| 322 | | retdat<<=8; |
| 320 | retdat = cpu_get_reg(space->cpu, M68K_D3) & 0xff; |
| 321 | retdat <<= 8; |
| 323 | 322 | return retdat; |
| 324 | 323 | } |
| 325 | | else if (cpu_get_pc(space->cpu)==0x1c24) // background gfx etc. |
| 324 | else if (cpu_get_pc(space->cpu) == 0x1c24) // background gfx etc. |
| 326 | 325 | { |
| 327 | | retdat = cpu_get_reg(space->cpu, M68K_D3)&0xff; |
| 328 | | retdat<<=8; |
| 326 | retdat = cpu_get_reg(space->cpu, M68K_D3) & 0xff; |
| 327 | retdat <<= 8; |
| 329 | 328 | return retdat; |
| 330 | 329 | } |
| 331 | | else if (cpu_get_pc(space->cpu)==0x10c4a) // unknown |
| 330 | else if (cpu_get_pc(space->cpu) == 0x10c4a) // unknown |
| 332 | 331 | { |
| 333 | 332 | return mame_rand(space->machine); |
| 334 | 333 | } |
| 335 | | else if (cpu_get_pc(space->cpu)==0x10c50) // unknown |
| 334 | else if (cpu_get_pc(space->cpu) == 0x10c50) // unknown |
| 336 | 335 | { |
| 337 | 336 | return mame_rand(space->machine); |
| 338 | 337 | } |
| 339 | | else if (cpu_get_pc(space->cpu)==0x10c52) // relates to the game speed.. |
| 338 | else if (cpu_get_pc(space->cpu) == 0x10c52) // relates to the game speed.. |
| 340 | 339 | { |
| 341 | | retdat = cpu_get_reg(space->cpu, M68K_D4)&0xff; |
| 342 | | retdat<<=8; |
| 340 | retdat = cpu_get_reg(space->cpu, M68K_D4) & 0xff; |
| 341 | retdat <<= 8; |
| 343 | 342 | return retdat; |
| 344 | 343 | } |
| 345 | | else if (cpu_get_pc(space->cpu)==0x061ae) |
| 344 | else if (cpu_get_pc(space->cpu) == 0x061ae) |
| 346 | 345 | { |
| 347 | | retdat = cpu_get_reg(space->cpu, M68K_D3)&0xff; |
| 348 | | retdat<<=8; |
| 346 | retdat = cpu_get_reg(space->cpu, M68K_D3) & 0xff; |
| 347 | retdat <<= 8; |
| 349 | 348 | return retdat; |
| 350 | 349 | } |
| 351 | | else if (cpu_get_pc(space->cpu)==0x061b0) |
| 350 | else if (cpu_get_pc(space->cpu) == 0x061b0) |
| 352 | 351 | { |
| 353 | | retdat = cpu_get_reg(space->cpu, M68K_D3)&0xff; |
| 354 | | retdat<<=8; |
| 352 | retdat = cpu_get_reg(space->cpu, M68K_D3) & 0xff; |
| 353 | retdat <<= 8; |
| 355 | 354 | return retdat; |
| 356 | 355 | } |
| 357 | 356 | else |
| 358 | 357 | { |
| 359 | | logerror("%06x chifi3, prot_r? %04x\n",cpu_get_pc(space->cpu), offset); |
| 358 | logerror("%06x chifi3, prot_r? %04x\n", cpu_get_pc(space->cpu), offset); |
| 360 | 359 | } |
| 361 | 360 | |
| 362 | 361 | return 0; |
| r5653 | r5654 | |
| 365 | 364 | static WRITE16_HANDLER( s19in1_bank ) |
| 366 | 365 | { |
| 367 | 366 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 368 | | memcpy(ROM + 0x000000, ROM + 0x400000+((offset << 1)*0x10000), 0x80000); |
| 367 | memcpy(ROM + 0x000000, ROM + 0x400000 + ((offset << 1) * 0x10000), 0x80000); |
| 369 | 368 | } |
| 370 | 369 | |
| 371 | 370 | // Kaiju? (Pokemon Stadium) handler from HazeMD |
| 372 | 371 | static WRITE16_HANDLER( g_kaiju_bank_w ) |
| 373 | 372 | { |
| 374 | 373 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 375 | | memcpy(ROM + 0x000000, ROM + 0x400000+(data&0x7f)*0x8000, 0x8000); |
| 374 | memcpy(ROM + 0x000000, ROM + 0x400000 + (data & 0x7f) * 0x8000, 0x8000); |
| 376 | 375 | } |
| 377 | 376 | |
| 378 | 377 | // Soulblade handler from HazeMD |
| r5653 | r5654 | |
| 459 | 458 | { |
| 460 | 459 | int bank = offset&0x3f; |
| 461 | 460 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 462 | | memcpy(ROM, ROM + (bank*0x10000)+0x400000, 0x400000); |
| 461 | memcpy(ROM, ROM + (bank * 0x10000) + 0x400000, 0x400000); |
| 463 | 462 | return 0; |
| 464 | 463 | } |
| 465 | 464 | |
| r5653 | r5654 | |
| 577 | 576 | |
| 578 | 577 | static void alloc_sram(running_machine *machine) |
| 579 | 578 | { |
| 580 | | genesis_sram = alloc_array_or_die(UINT16, (genesis_sram_end - genesis_sram_start) / sizeof(UINT16)); |
| 581 | | image_battery_load(devtag_get_device(machine, "cart"), genesis_sram, genesis_sram_end - genesis_sram_start); |
| 582 | | memcpy(megadriv_backupram, genesis_sram, genesis_sram_end - genesis_sram_start); |
| 579 | genesis_sram = alloc_array_or_die(UINT16, (genesis_sram_end - genesis_sram_start + 1) / sizeof(UINT16)); |
| 580 | image_battery_load(devtag_get_device(machine, "cart"), genesis_sram, genesis_sram_end - genesis_sram_start + 1); |
| 581 | memcpy(megadriv_backupram, genesis_sram, genesis_sram_end - genesis_sram_start + 1); |
| 583 | 582 | } |
| 584 | 583 | |
| 585 | 584 | static READ16_HANDLER( genesis_sram_read ) |
| r5653 | r5654 | |
| 596 | 595 | else |
| 597 | 596 | { |
| 598 | 597 | ROM = memory_region(space->machine, "maincpu"); |
| 599 | | rom_offset = genesis_sram_start + (offset<<1); |
| 598 | rom_offset = genesis_sram_start + (offset << 1); |
| 600 | 599 | |
| 601 | | return (UINT16) ROM[rom_offset] | (ROM[rom_offset+1] << 8); |
| 600 | return (UINT16) ROM[rom_offset] | (ROM[rom_offset + 1] << 8); |
| 602 | 601 | } |
| 603 | 602 | } |
| 604 | 603 | |
| r5653 | r5654 | |
| 648 | 647 | unsigned char *ROM; |
| 649 | 648 | UINT32 mirroraddr; |
| 650 | 649 | |
| 650 | /* SRAM data */ |
| 651 | sram_handlers_installed = 0; |
| 652 | genesis_sram_readonly = 0; |
| 653 | genesis_sram_active = 0; |
| 654 | |
| 651 | 655 | ROM = memory_region(machine, "maincpu"); |
| 652 | 656 | |
| 653 | 657 | if (cart_type == SSF2) |
| r5653 | r5654 | |
| 661 | 665 | |
| 662 | 666 | if (cart_type == LIONK3 || cart_type == SKINGKONG) |
| 663 | 667 | { |
| 668 | g_l3alt_pdat = g_l3alt_pcmd = 0; |
| 664 | 669 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 665 | 670 | memcpy(&ROM[0x200000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 666 | 671 | |
| 667 | | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 672 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_prot_w); |
| 668 | 673 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 669 | 674 | } |
| 670 | 675 | |
| 671 | 676 | if (cart_type == SDK99) |
| 672 | 677 | { |
| 678 | g_l3alt_pdat = g_l3alt_pcmd = 0; |
| 679 | |
| 673 | 680 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x300000); /* default rom */ |
| 674 | 681 | memcpy(&ROM[0x300000], &ROM[VIRGIN_COPY_GEN], 0x100000); /* default rom */ |
| 675 | 682 | |
| 676 | | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 683 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_prot_w); |
| 677 | 684 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 678 | 685 | } |
| 679 | 686 | |
| r5653 | r5654 | |
| 729 | 736 | |
| 730 | 737 | if (cart_type == SQUIRRELK) |
| 731 | 738 | { |
| 739 | squirrel_king_extra = 0; |
| 732 | 740 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_r); |
| 733 | 741 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_w); |
| 734 | 742 | } |
| r5653 | r5654 | |
| 769 | 777 | |
| 770 | 778 | if (cart_type == LIONK2) |
| 771 | 779 | { |
| 780 | lion2_prot1_data = lion2_prot2_data = 0; |
| 781 | |
| 772 | 782 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, lion2_prot1_r); |
| 773 | 783 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, lion2_prot2_r); |
| 774 | 784 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, lion2_prot1_w); |
| r5653 | r5654 | |
| 814 | 824 | |
| 815 | 825 | if (cart_type == REALTEC) |
| 816 | 826 | { |
| 817 | | realtek_old_bank_addr = -1; |
| 818 | | |
| 819 | 827 | /* Realtec mapper!*/ |
| 828 | realtec_bank_addr = realtec_bank_size = 0; |
| 829 | realtec_old_bank_addr = -1; |
| 830 | |
| 820 | 831 | memcpy(&ROM[0x400000], &ROM[relocate], 0x80000); |
| 821 | 832 | |
| 822 | 833 | for (mirroraddr = 0; mirroraddr < 0x400000; mirroraddr += 0x2000) |
| r5653 | r5654 | |
| 845 | 856 | progresses. Currently EEPROM is not emulated. */ |
| 846 | 857 | if (!has_serial_eeprom) |
| 847 | 858 | { |
| 859 | /* Info from DGen: If SRAM does not overlap main ROM, set it active by |
| 860 | default since a few games can't manage to properly switch it on/off. */ |
| 861 | if (genesis_last_loaded_image_length <= genesis_sram_start) |
| 862 | genesis_sram_active = 1; |
| 863 | |
| 848 | 864 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle); |
| 849 | 865 | |
| 850 | 866 | /* Sonic 1 included in Sonic Classics doesn't have SRAM and |
| r5653 | r5654 | |
| 854 | 870 | install_sram_rw_handlers (machine); |
| 855 | 871 | } |
| 856 | 872 | |
| 857 | | |
| 858 | 873 | /* install NOP handler for TMSS */ |
| 859 | 874 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa14000, 0xa14003, 0, 0, genesis_TMSS_bank_w); |
| 860 | 875 | } |
| r5653 | r5654 | |
| 868 | 883 | |
| 869 | 884 | /************************************* |
| 870 | 885 | * |
| 871 | | * Driver initialization |
| 872 | | * |
| 873 | | *************************************/ |
| 874 | | |
| 875 | | |
| 876 | | static void genesis_machine_stop(running_machine *machine) |
| 877 | | { |
| 878 | | } |
| 879 | | |
| 880 | | DRIVER_INIT( gencommon ) |
| 881 | | { |
| 882 | | if (genesis_sram) |
| 883 | | { |
| 884 | | add_exit_callback(machine, genesis_machine_stop); |
| 885 | | } |
| 886 | | } |
| 887 | | |
| 888 | | |
| 889 | | |
| 890 | | /************************************* |
| 891 | | * |
| 892 | 886 | * Cart handling |
| 893 | 887 | * |
| 894 | 888 | *************************************/ |
| r5653 | r5654 | |
| 1003 | 997 | rawROM = memory_region(image->machine, "maincpu"); |
| 1004 | 998 | ROM = rawROM /*+ 512 */; |
| 1005 | 999 | |
| 1000 | genesis_last_loaded_image_length = -1; |
| 1006 | 1001 | length = image_fread(image, rawROM + 0x2000, 0x600000); |
| 1007 | 1002 | logerror("image length = 0x%x\n", length); |
| 1008 | 1003 | |
| r5653 | r5654 | |
| 1095 | 1090 | memcpy(&ROM[VIRGIN_COPY_GEN], &ROM[0x000000], MAX_MD_CART_SIZE); /* store a copy of data for MACHINE_RESET processing */ |
| 1096 | 1091 | } |
| 1097 | 1092 | |
| 1093 | /* Default cartridge type */ |
| 1094 | cart_type = STANDARD; |
| 1098 | 1095 | |
| 1099 | 1096 | /* Detect carts which need additional handlers */ |
| 1100 | 1097 | { |
| r5653 | r5654 | |
| 1221 | 1218 | |
| 1222 | 1219 | logerror("cart type: %d\n", cart_type); |
| 1223 | 1220 | |
| 1224 | | /* check if cart has battery save */ |
| 1225 | 1221 | genesis_sram = NULL; |
| 1226 | | sram_detected = sram_handlers_installed = has_serial_eeprom = 0; |
| 1222 | sram_detected = 0; |
| 1223 | genesis_sram_start = genesis_sram_end = 0; |
| 1224 | has_serial_eeprom = 0; |
| 1227 | 1225 | |
| 1226 | /* check if cart has battery save */ |
| 1227 | |
| 1228 | 1228 | /* For games using SRAM, unfortunately there are ROMs without info |
| 1229 | 1229 | about it in header. The solution adopted is do the mapping anyway, |
| 1230 | 1230 | then active SRAM later if the game will access it. */ |
| r5653 | r5654 | |
| 1236 | 1236 | genesis_sram_end = (ROM[0x1b9] << 24 | ROM[0x1b8] << 16 | ROM[0x1bb] << 8 | ROM[0x1ba]); |
| 1237 | 1237 | |
| 1238 | 1238 | if ((genesis_sram_start > genesis_sram_end) || ((genesis_sram_end - genesis_sram_start) >= 0x10000)) // we assume at most 64k of SRAM (HazeMD uses at most 64k). is this correct? |
| 1239 | | genesis_sram_end = genesis_sram_start + 0x10000; |
| 1239 | genesis_sram_end = genesis_sram_start + 0x0FFFF; |
| 1240 | 1240 | |
| 1241 | | /* for some games using serial EEPROM, SRAM will be detected |
| 1242 | | as size 0 or 1. Currently EEPROM is not emulated. */ |
| 1241 | /* for some games using serial EEPROM, difference between SRAM |
| 1242 | end to start is 0 or 1. Currently EEPROM is not emulated. */ |
| 1243 | 1243 | if ((genesis_sram_end - genesis_sram_start) < 2) |
| 1244 | 1244 | has_serial_eeprom = 1; |
| 1245 | 1245 | else |
| r5653 | r5654 | |
| 1249 | 1249 | { |
| 1250 | 1250 | /* set default SRAM positions, with size = 64k */ |
| 1251 | 1251 | genesis_sram_start = 0x200000; |
| 1252 | | genesis_sram_end = genesis_sram_start + 0x10000; |
| 1252 | genesis_sram_end = genesis_sram_start + 0xffff; |
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | if (genesis_sram_start & 1) |
| r5653 | r5654 | |
| 1265 | 1265 | backup RAM, but only if the value is 0xFFFF, to not break MLBPA Sports |
| 1266 | 1266 | Talk Baseball. With this hack some games at least run (NBA Jam, Evander |
| 1267 | 1267 | Holyfield's Real Deal Boxing, Greatest Heavyweights of the Ring) */ |
| 1268 | | if (has_serial_eeprom && megadriv_backupram[0] == 0xFFFF) |
| 1269 | | megadriv_backupram[0] = 0xFF00; |
| 1268 | if (has_serial_eeprom && megadriv_backupram[0] == 0xffff) |
| 1269 | megadriv_backupram[0] = 0xff00; |
| 1270 | 1270 | |
| 1271 | | /* Info from DGen: If SRAM does not overlap main ROM, set it active by |
| 1272 | | default since a few games can't manage to properly switch it on/off. */ |
| 1273 | | if (genesis_last_loaded_image_length <= genesis_sram_start) |
| 1274 | | genesis_sram_active = 1; |
| 1275 | | |
| 1276 | 1271 | if (sram_detected) |
| 1277 | | logerror("SRAM detected from header: starting location %X - SRAM Length %X\n", genesis_sram_start, genesis_sram_end - genesis_sram_start); |
| 1272 | logerror("SRAM detected from header: starting location %X - SRAM Length %X\n", genesis_sram_start, genesis_sram_end - genesis_sram_start + 1); |
| 1278 | 1273 | |
| 1279 | 1274 | return INIT_PASS; |
| 1280 | 1275 | } |
| r5653 | r5654 | |
| 1285 | 1280 | static DEVICE_IMAGE_UNLOAD( genesis_cart ) |
| 1286 | 1281 | { |
| 1287 | 1282 | /* Write out the battery file if necessary */ |
| 1288 | | if ((genesis_sram != NULL) && (genesis_sram_end - genesis_sram_start > 0)) |
| 1283 | if (genesis_sram != NULL) |
| 1289 | 1284 | { |
| 1290 | | image_battery_save(image, genesis_sram, genesis_sram_end - genesis_sram_start); |
| 1285 | image_battery_save(image, genesis_sram, genesis_sram_end - genesis_sram_start + 1); |
| 1286 | free(genesis_sram); |
| 1291 | 1287 | } |
| 1292 | 1288 | } |
| 1293 | 1289 | |