src/mame/machine/playch10.c
| r5325 | r5326 | |
| 3 | 3 | #include "machine/rp5h01.h" |
| 4 | 4 | #include "includes/playch10.h" |
| 5 | 5 | |
| 6 | /* prototypes */ |
| 7 | void pc10_set_mirroring( int mirroring ); |
| 8 | WRITE8_HANDLER( pc10_nt_w ); |
| 9 | READ8_HANDLER( pc10_nt_r ); |
| 10 | WRITE8_HANDLER( pc10_chr_w ); |
| 11 | READ8_HANDLER( pc10_chr_r ); |
| 12 | void pc10_set_videorom_bank( running_machine *machine, int first, int count, int bank, int size ); |
| 13 | void set_videoram_bank( running_machine *machine, int first, int count, int bank, int size ); |
| 14 | |
| 15 | typedef struct |
| 16 | { |
| 17 | int writable; // 1 for RAM, 0 for ROM |
| 18 | UINT8* chr; // direct access to the memory |
| 19 | } chr_bank; |
| 20 | |
| 21 | |
| 6 | 22 | /* Globals */ |
| 7 | 23 | int pc10_sdcs; /* ShareD Chip Select */ |
| 8 | 24 | int pc10_dispmask; /* Display Mask */ |
| r5325 | r5326 | |
| 21 | 37 | |
| 22 | 38 | static int MMC2_bank[4], MMC2_bank_latch[2]; |
| 23 | 39 | |
| 40 | static UINT8* vrom; // used for games with cart gfx loaded (a,c,e,f,g,h) |
| 41 | static UINT8* vram = NULL; // used for boards h, b, d, i, k (Presumably, 8K. 16K didn't work in MESS) |
| 42 | static UINT8* nametable[4]; // For non-mirroring boards, this can be moved to a direct mapping |
| 43 | static UINT8* nt_ram = NULL; // Per-board size! Some boards clearly need 4K. Some MAY use 2K. Research needed. |
| 44 | static chr_bank chr_page[8]; // Simple wrapper for ROM/RAM, since we could be banking either (Hboard) |
| 45 | |
| 24 | 46 | /************************************* |
| 25 | 47 | * |
| 26 | 48 | * Init machine |
| 27 | 49 | * |
| 28 | 50 | *************************************/ |
| 51 | |
| 29 | 52 | MACHINE_RESET( pc10 ) |
| 30 | 53 | { |
| 31 | | const device_config *ppu = devtag_get_device(machine, "ppu"); |
| 32 | 54 | const device_config *rp5h01 = devtag_get_device(machine, "rp5h01"); |
| 33 | 55 | |
| 34 | 56 | /* initialize latches and flip-flops */ |
| r5325 | r5326 | |
| 51 | 73 | rp5h01_reset_w(rp5h01, 0, 1); |
| 52 | 74 | rp5h01_enable_w(rp5h01, 0, 1); |
| 53 | 75 | |
| 54 | | ppu2c0x_set_mirroring( ppu, mirroring ); |
| 76 | pc10_set_mirroring(mirroring); |
| 55 | 77 | } |
| 56 | 78 | |
| 79 | MACHINE_START( pc10 ) |
| 80 | { |
| 81 | vrom = memory_region(machine, "gfx2"); |
| 82 | |
| 83 | /* allocate 4K of nametable ram here */ |
| 84 | /* move to individual boards as documentation of actual boards allows */ |
| 85 | nt_ram = auto_alloc_array(machine, UINT8, 0x1000); |
| 86 | |
| 87 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0, 0x1fff, 0, 0, pc10_chr_r, pc10_chr_w); |
| 88 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, pc10_nt_r, pc10_nt_w); |
| 89 | |
| 90 | if (NULL != vram) |
| 91 | set_videoram_bank(machine, 0, 8, 0, 8); |
| 92 | else pc10_set_videorom_bank(machine, 0, 8, 0, 8); |
| 93 | |
| 94 | } |
| 95 | |
| 96 | MACHINE_START( playch10_hboard ) |
| 97 | { |
| 98 | vrom = memory_region(machine, "gfx2"); |
| 99 | |
| 100 | /* allocate 4K of nametable ram here */ |
| 101 | /* move to individual boards as documentation of actual boards allows */ |
| 102 | nt_ram = auto_alloc_array(machine, UINT8, 0x1000); |
| 103 | /* allocate vram */ |
| 104 | |
| 105 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 106 | |
| 107 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0, 0x1fff, 0, 0, pc10_chr_r, pc10_chr_w); |
| 108 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, pc10_nt_r, pc10_nt_w); |
| 109 | } |
| 110 | |
| 57 | 111 | /************************************* |
| 58 | 112 | * |
| 59 | 113 | * BIOS ports handling |
| r5325 | r5326 | |
| 103 | 157 | |
| 104 | 158 | WRITE8_HANDLER( pc10_GAMERES_w ) |
| 105 | 159 | { |
| 106 | | cputag_set_input_line(space->machine, "cart", INPUT_LINE_RESET, ( data & 1 ) ? CLEAR_LINE : ASSERT_LINE ); |
| 160 | cputag_set_input_line(space->machine, "cart", INPUT_LINE_RESET, (data & 1) ? CLEAR_LINE : ASSERT_LINE ); |
| 107 | 161 | } |
| 108 | 162 | |
| 109 | 163 | WRITE8_HANDLER( pc10_GAMESTOP_w ) |
| 110 | 164 | { |
| 111 | | cputag_set_input_line(space->machine, "cart", INPUT_LINE_HALT, ( data & 1 ) ? CLEAR_LINE : ASSERT_LINE ); |
| 165 | cputag_set_input_line(space->machine, "cart", INPUT_LINE_HALT, (data & 1) ? CLEAR_LINE : ASSERT_LINE ); |
| 112 | 166 | } |
| 113 | 167 | |
| 114 | 168 | WRITE8_HANDLER( pc10_PPURES_w ) |
| 115 | 169 | { |
| 116 | | if ( data & 1 ) |
| 170 | if (data & 1) |
| 117 | 171 | devtag_reset(space->machine, "ppu"); |
| 118 | 172 | } |
| 119 | 173 | |
| r5325 | r5326 | |
| 126 | 180 | |
| 127 | 181 | WRITE8_HANDLER( pc10_CARTSEL_w ) |
| 128 | 182 | { |
| 129 | | cart_sel &= ~( 1 << offset ); |
| 130 | | cart_sel |= ( data & 1 ) << offset; |
| 183 | cart_sel &= ~(1 << offset); |
| 184 | cart_sel |= (data & 1) << offset; |
| 131 | 185 | } |
| 132 | 186 | |
| 133 | 187 | |
| r5325 | r5326 | |
| 136 | 190 | * RP5H01 handling |
| 137 | 191 | * |
| 138 | 192 | *************************************/ |
| 193 | |
| 139 | 194 | READ8_HANDLER( pc10_prot_r ) |
| 140 | 195 | { |
| 141 | 196 | const device_config *rp5h01 = devtag_get_device(space->machine, "rp5h01"); |
| r5325 | r5326 | |
| 179 | 234 | * Input Ports |
| 180 | 235 | * |
| 181 | 236 | *************************************/ |
| 237 | |
| 182 | 238 | WRITE8_HANDLER( pc10_in0_w ) |
| 183 | 239 | { |
| 184 | 240 | /* Toggling bit 0 high then low resets both controllers */ |
| 185 | | if ( data & 1 ) |
| 241 | if (data & 1) |
| 186 | 242 | return; |
| 187 | 243 | |
| 188 | 244 | /* load up the latches */ |
| r5325 | r5326 | |
| 190 | 246 | input_latch[1] = input_port_read(space->machine, "P2"); |
| 191 | 247 | |
| 192 | 248 | /* apply any masking from the BIOS */ |
| 193 | | if ( cntrl_mask ) |
| 249 | if (cntrl_mask) |
| 194 | 250 | { |
| 195 | 251 | /* mask out select and start */ |
| 196 | 252 | input_latch[0] &= ~0x0c; |
| r5325 | r5326 | |
| 199 | 255 | |
| 200 | 256 | READ8_HANDLER( pc10_in0_r ) |
| 201 | 257 | { |
| 202 | | int ret = ( input_latch[0] ) & 1; |
| 258 | int ret = (input_latch[0]) & 1; |
| 203 | 259 | |
| 204 | 260 | /* shift */ |
| 205 | 261 | input_latch[0] >>= 1; |
| r5325 | r5326 | |
| 213 | 269 | |
| 214 | 270 | READ8_HANDLER( pc10_in1_r ) |
| 215 | 271 | { |
| 216 | | int ret = ( input_latch[1] ) & 1; |
| 272 | int ret = (input_latch[1]) & 1; |
| 217 | 273 | |
| 218 | 274 | /* shift */ |
| 219 | 275 | input_latch[1] >>= 1; |
| 220 | 276 | |
| 221 | 277 | /* do the gun thing */ |
| 222 | | if ( pc10_gun_controller ) |
| 278 | if (pc10_gun_controller) |
| 223 | 279 | { |
| 224 | 280 | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 225 | 281 | int trigger = input_port_read(space->machine, "P1"); |
| r5325 | r5326 | |
| 231 | 287 | ret |= 0x08; |
| 232 | 288 | |
| 233 | 289 | /* get the pixel at the gun position */ |
| 234 | | pix = ppu2c0x_get_pixel( ppu, x, y ); |
| 290 | pix = ppu2c0x_get_pixel(ppu, x, y); |
| 235 | 291 | |
| 236 | 292 | /* get the color base from the ppu */ |
| 237 | | color_base = ppu2c0x_get_colorbase( ppu ); |
| 293 | color_base = ppu2c0x_get_colorbase(ppu); |
| 238 | 294 | |
| 239 | 295 | /* look at the screen and see if the cursor is over a bright pixel */ |
| 240 | | if ( ( pix == color_base+0x20 ) || ( pix == color_base+0x30 ) || |
| 241 | | ( pix == color_base+0x33 ) || ( pix == color_base+0x34 ) ) |
| 296 | if ((pix == color_base + 0x20) || (pix == color_base + 0x30) || |
| 297 | (pix == color_base + 0x33) || (pix == color_base + 0x34)) |
| 242 | 298 | { |
| 243 | 299 | ret &= ~0x08; /* sprite hit */ |
| 244 | 300 | } |
| 245 | 301 | |
| 246 | 302 | /* now, add the trigger if not masked */ |
| 247 | | if ( !cntrl_mask ) |
| 303 | if (!cntrl_mask) |
| 248 | 304 | { |
| 249 | | ret |= ( trigger & 2 ) << 3; |
| 305 | ret |= (trigger & 2) << 3; |
| 250 | 306 | } |
| 251 | 307 | } |
| 252 | 308 | |
| r5325 | r5326 | |
| 256 | 312 | |
| 257 | 313 | return ret; |
| 258 | 314 | } |
| 315 | /************************************* |
| 316 | * |
| 317 | * PPU External bus handlers |
| 318 | * |
| 319 | *************************************/ |
| 259 | 320 | |
| 321 | WRITE8_HANDLER( pc10_nt_w ) |
| 322 | { |
| 323 | int page = ((offset & 0xc00) >> 10); |
| 324 | nametable[page][offset & 0x3ff] = data; |
| 325 | } |
| 260 | 326 | |
| 327 | READ8_HANDLER( pc10_nt_r ) |
| 328 | { |
| 329 | int page = ((offset & 0xc00) >> 10); |
| 330 | return nametable[page][offset & 0x3ff]; |
| 331 | } |
| 332 | |
| 333 | WRITE8_HANDLER( pc10_chr_w ) |
| 334 | { |
| 335 | int bank = offset >> 10; |
| 336 | if (chr_page[bank].writable) |
| 337 | { |
| 338 | chr_page[bank].chr[offset & 0x3ff] = data; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | READ8_HANDLER( pc10_chr_r ) |
| 343 | { |
| 344 | int bank = offset >> 10; |
| 345 | return chr_page[bank].chr[offset & 0x3ff]; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | void pc10_set_mirroring( int mirroring ) |
| 350 | { |
| 351 | switch (mirroring) |
| 352 | { |
| 353 | case PPU_MIRROR_LOW: |
| 354 | nametable[0] = nametable[1] = nametable[2] = nametable[3] = nt_ram; |
| 355 | break; |
| 356 | case PPU_MIRROR_HIGH: |
| 357 | nametable[0] = nametable[1] = nametable[2] = nametable[3] = nt_ram + 0x400; |
| 358 | break; |
| 359 | case PPU_MIRROR_HORZ: |
| 360 | nametable[0] = nt_ram; |
| 361 | nametable[1] = nt_ram; |
| 362 | nametable[2] = nt_ram + 0x400; |
| 363 | nametable[3] = nt_ram + 0x400; |
| 364 | break; |
| 365 | case PPU_MIRROR_VERT: |
| 366 | nametable[0] = nt_ram; |
| 367 | nametable[1] = nt_ram + 0x400; |
| 368 | nametable[2] = nt_ram; |
| 369 | nametable[3] = nt_ram + 0x400; |
| 370 | break; |
| 371 | case PPU_MIRROR_NONE: |
| 372 | default: |
| 373 | nametable[0] = nt_ram; |
| 374 | nametable[1] = nt_ram + 0x400; |
| 375 | nametable[2] = nt_ram + 0x800; |
| 376 | nametable[3] = nt_ram + 0xc00; |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /* SIZE MAPPINGS *\ |
| 382 | * old new * |
| 383 | * 512 8 * |
| 384 | * 256 4 * |
| 385 | * 128 2 * |
| 386 | * 64 1 * |
| 387 | \*****************/ |
| 388 | |
| 389 | void pc10_set_videorom_bank( running_machine *machine, int first, int count, int bank, int size ) |
| 390 | { |
| 391 | int i, len; |
| 392 | /* first = first bank to map */ |
| 393 | /* count = number of 1K banks to map */ |
| 394 | /* bank = index of the bank */ |
| 395 | /* size = size of indexed banks (in KB) */ |
| 396 | /* note that this follows the original PPU banking and might be overly complex */ |
| 397 | |
| 398 | /* yeah, this is probably a horrible assumption to make.*/ |
| 399 | /* but the driver is 100% consistant */ |
| 400 | |
| 401 | len = memory_region_length(machine, "gfx2"); |
| 402 | len /= 0x400; // convert to KB |
| 403 | len /= size; // convert to bank resolution |
| 404 | len--; // convert to mask |
| 405 | bank &= len; // should be the right mask |
| 406 | |
| 407 | for (i = 0; i < count; i++) |
| 408 | { |
| 409 | chr_page[i + first].writable = 0; |
| 410 | chr_page[i + first].chr=vrom + (i * 0x400) + (bank * size * 0x400); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | void set_videoram_bank( running_machine *machine, int first, int count, int bank, int size ) |
| 415 | { |
| 416 | int i; |
| 417 | /* first = first bank to map */ |
| 418 | /* count = number of 1K banks to map */ |
| 419 | /* bank = index of the bank */ |
| 420 | /* size = size of indexed banks (in KB) */ |
| 421 | /* note that this follows the original PPU banking and might be overly complex */ |
| 422 | |
| 423 | /* assumes 8K of vram */ |
| 424 | /* need 8K to fill address space */ |
| 425 | /* only pinbot (8k) banks at all */ |
| 426 | |
| 427 | for (i = 0; i < count; i++) |
| 428 | { |
| 429 | chr_page[i + first].writable = 1; |
| 430 | chr_page[i + first].chr = vram + (((i * 0x400) + (bank * size * 0x400)) & 0x1fff); |
| 431 | } |
| 432 | } |
| 433 | |
| 261 | 434 | /************************************* |
| 262 | 435 | * |
| 263 | 436 | * Common init for all games |
| 264 | 437 | * |
| 265 | 438 | *************************************/ |
| 439 | |
| 266 | 440 | DRIVER_INIT( playch10 ) |
| 267 | 441 | { |
| 442 | vram = NULL; |
| 443 | |
| 268 | 444 | /* set the controller to default */ |
| 269 | 445 | pc10_gun_controller = 0; |
| 270 | 446 | |
| r5325 | r5326 | |
| 285 | 461 | /* common init */ |
| 286 | 462 | DRIVER_INIT_CALL(playch10); |
| 287 | 463 | |
| 464 | /* we have no vram, make sure switching games doesn't point to an old allocation */ |
| 465 | vram = NULL; |
| 466 | |
| 288 | 467 | /* set the control type */ |
| 289 | 468 | pc10_gun_controller = 1; |
| 290 | 469 | } |
| r5325 | r5326 | |
| 312 | 491 | /* basically, a MMC1 mapper from the nes */ |
| 313 | 492 | static int size16k, switchlow, vrom4k; |
| 314 | 493 | |
| 315 | | int reg = ( offset >> 13 ); |
| 494 | int reg = (offset >> 13); |
| 316 | 495 | |
| 317 | 496 | /* reset mapper */ |
| 318 | | if ( data & 0x80 ) |
| 497 | if (data & 0x80) |
| 319 | 498 | { |
| 320 | 499 | mmc1_shiftreg = mmc1_shiftcount = 0; |
| 321 | 500 | |
| r5325 | r5326 | |
| 327 | 506 | } |
| 328 | 507 | |
| 329 | 508 | /* see if we need to clock in data */ |
| 330 | | if ( mmc1_shiftcount < 5 ) |
| 509 | if (mmc1_shiftcount < 5) |
| 331 | 510 | { |
| 332 | 511 | mmc1_shiftreg >>= 1; |
| 333 | | mmc1_shiftreg |= ( data & 1 ) << 4; |
| 512 | mmc1_shiftreg |= (data & 1) << 4; |
| 334 | 513 | mmc1_shiftcount++; |
| 335 | 514 | } |
| 336 | 515 | |
| 337 | 516 | /* are we done shifting? */ |
| 338 | | if ( mmc1_shiftcount == 5 ) |
| 517 | if (mmc1_shiftcount == 5) |
| 339 | 518 | { |
| 340 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 341 | | |
| 342 | 519 | /* reset count */ |
| 343 | 520 | mmc1_shiftcount = 0; |
| 344 | 521 | |
| 345 | 522 | /* apply data to registers */ |
| 346 | | switch( reg ) |
| 523 | switch (reg) |
| 347 | 524 | { |
| 348 | 525 | case 0: /* mirroring and options */ |
| 349 | 526 | { |
| r5325 | r5326 | |
| 353 | 530 | size16k = mmc1_shiftreg & 0x08; |
| 354 | 531 | switchlow = mmc1_shiftreg & 0x04; |
| 355 | 532 | |
| 356 | | switch( mmc1_shiftreg & 3 ) |
| 533 | switch (mmc1_shiftreg & 3) |
| 357 | 534 | { |
| 358 | 535 | case 0: |
| 359 | 536 | _mirroring = PPU_MIRROR_LOW; |
| r5325 | r5326 | |
| 374 | 551 | } |
| 375 | 552 | |
| 376 | 553 | /* apply mirroring */ |
| 377 | | ppu2c0x_set_mirroring( ppu, _mirroring ); |
| 554 | pc10_set_mirroring(_mirroring); |
| 378 | 555 | } |
| 379 | 556 | break; |
| 380 | 557 | |
| 381 | 558 | case 1: /* video rom banking - bank 0 - 4k or 8k */ |
| 382 | | ppu2c0x_set_videorom_bank( ppu, 0, ( vrom4k ) ? 4 : 8, ( mmc1_shiftreg & 0x1f ), 256 ); |
| 559 | pc10_set_videorom_bank(space->machine, 0, (vrom4k) ? 4 : 8, (mmc1_shiftreg & 0x1f), 4); |
| 383 | 560 | break; |
| 384 | 561 | |
| 385 | 562 | case 2: /* video rom banking - bank 1 - 4k only */ |
| 386 | | if ( vrom4k ) |
| 387 | | ppu2c0x_set_videorom_bank( ppu, 4, 4, ( mmc1_shiftreg & 0x1f ), 256 ); |
| 563 | if (vrom4k) |
| 564 | pc10_set_videorom_bank(space->machine, 4, 4, (mmc1_shiftreg & 0x1f), 4); |
| 388 | 565 | break; |
| 389 | 566 | |
| 390 | 567 | case 3: /* program banking */ |
| 391 | 568 | { |
| 392 | | int bank = ( mmc1_shiftreg & mmc1_rom_mask ) * 0x4000; |
| 393 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 569 | int bank = (mmc1_shiftreg & mmc1_rom_mask) * 0x4000; |
| 570 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 394 | 571 | |
| 395 | | if ( !size16k ) |
| 572 | if (!size16k) |
| 396 | 573 | { |
| 397 | 574 | /* switch 32k */ |
| 398 | | memcpy( &prg[0x08000], &prg[0x010000+bank], 0x8000 ); |
| 575 | memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x8000); |
| 399 | 576 | } |
| 400 | 577 | else |
| 401 | 578 | { |
| 402 | 579 | /* switch 16k */ |
| 403 | | if ( switchlow ) |
| 580 | if (switchlow) |
| 404 | 581 | { |
| 405 | 582 | /* low */ |
| 406 | | memcpy( &prg[0x08000], &prg[0x010000+bank], 0x4000 ); |
| 583 | memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x4000); |
| 407 | 584 | } |
| 408 | 585 | else |
| 409 | 586 | { |
| 410 | 587 | /* high */ |
| 411 | | memcpy( &prg[0x0c000], &prg[0x010000+bank], 0x4000 ); |
| 588 | memcpy(&prg[0x0c000], &prg[0x010000 + bank], 0x4000); |
| 412 | 589 | } |
| 413 | 590 | } |
| 414 | 591 | } |
| r5325 | r5326 | |
| 418 | 595 | } |
| 419 | 596 | |
| 420 | 597 | /**********************************************************************************/ |
| 421 | | |
| 422 | 598 | /* A Board games (Track & Field, Gradius) */ |
| 423 | 599 | |
| 424 | 600 | static WRITE8_HANDLER( aboard_vrom_switch_w ) |
| 425 | 601 | { |
| 426 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 427 | | ppu2c0x_set_videorom_bank( ppu, 0, 8, ( data & 3 ), 512 ); |
| 602 | pc10_set_videorom_bank(space->machine, 0, 8, (data & 3), 8); |
| 428 | 603 | } |
| 429 | 604 | |
| 430 | 605 | DRIVER_INIT( pcaboard ) |
| r5325 | r5326 | |
| 437 | 612 | |
| 438 | 613 | /* set the mirroring here */ |
| 439 | 614 | mirroring = PPU_MIRROR_VERT; |
| 615 | |
| 616 | /* we have no vram, make sure switching games doesn't point to an old allocation */ |
| 617 | vram = NULL; |
| 440 | 618 | } |
| 441 | 619 | |
| 442 | 620 | /**********************************************************************************/ |
| 443 | | |
| 444 | 621 | /* B Board games (Contra, Rush N' Attach, Pro Wrestling) */ |
| 445 | 622 | |
| 446 | 623 | static WRITE8_HANDLER( bboard_rom_switch_w ) |
| 447 | 624 | { |
| 448 | | int bankoffset = 0x10000 + ( ( data & 7 ) * 0x4000 ); |
| 449 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 625 | int bankoffset = 0x10000 + ((data & 7) * 0x4000); |
| 626 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 450 | 627 | |
| 451 | | memcpy( &prg[0x08000], &prg[bankoffset], 0x4000 ); |
| 628 | memcpy(&prg[0x08000], &prg[bankoffset], 0x4000); |
| 452 | 629 | } |
| 453 | 630 | |
| 454 | 631 | DRIVER_INIT( pcbboard ) |
| 455 | 632 | { |
| 456 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 633 | UINT8 *prg = memory_region(machine, "cart"); |
| 457 | 634 | |
| 458 | 635 | /* We do manual banking, in case the code falls through */ |
| 459 | 636 | /* Copy the initial banks */ |
| 460 | | memcpy( &prg[0x08000], &prg[0x28000], 0x8000 ); |
| 637 | memcpy(&prg[0x08000], &prg[0x28000], 0x8000); |
| 461 | 638 | |
| 462 | 639 | /* Roms are banked at $8000 to $bfff */ |
| 463 | 640 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, bboard_rom_switch_w ); |
| r5325 | r5326 | |
| 465 | 642 | /* common init */ |
| 466 | 643 | DRIVER_INIT_CALL(playch10); |
| 467 | 644 | |
| 645 | /* allocate vram */ |
| 646 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 647 | |
| 468 | 648 | /* set the mirroring here */ |
| 469 | 649 | mirroring = PPU_MIRROR_VERT; |
| 650 | /* special init */ |
| 651 | set_videoram_bank(machine, 0, 8, 0, 8); |
| 470 | 652 | } |
| 471 | 653 | |
| 472 | 654 | /**********************************************************************************/ |
| 473 | | |
| 474 | 655 | /* C Board games (The Goonies) */ |
| 475 | 656 | |
| 476 | 657 | static WRITE8_HANDLER( cboard_vrom_switch_w ) |
| 477 | 658 | { |
| 478 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 479 | | ppu2c0x_set_videorom_bank( ppu, 0, 8, ( ( data >> 1 ) & 1 ), 512 ); |
| 659 | pc10_set_videorom_bank(space->machine, 0, 8, ((data >> 1) & 1), 8); |
| 480 | 660 | } |
| 481 | 661 | |
| 482 | 662 | DRIVER_INIT( pccboard ) |
| r5325 | r5326 | |
| 484 | 664 | /* switches vrom with writes to $6000 */ |
| 485 | 665 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x6000, 0x6000, 0, 0, cboard_vrom_switch_w ); |
| 486 | 666 | |
| 667 | /* we have no vram, make sure switching games doesn't point to an old allocation */ |
| 668 | vram = NULL; |
| 669 | |
| 487 | 670 | /* common init */ |
| 488 | 671 | DRIVER_INIT_CALL(playch10); |
| 489 | 672 | } |
| 490 | 673 | |
| 491 | 674 | /**********************************************************************************/ |
| 492 | | |
| 493 | 675 | /* D Board games (Rad Racer) */ |
| 494 | 676 | |
| 495 | 677 | DRIVER_INIT( pcdboard ) |
| 496 | 678 | { |
| 497 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 679 | UINT8 *prg = memory_region(machine, "cart"); |
| 498 | 680 | |
| 499 | 681 | /* We do manual banking, in case the code falls through */ |
| 500 | 682 | /* Copy the initial banks */ |
| 501 | | memcpy( &prg[0x08000], &prg[0x28000], 0x8000 ); |
| 683 | memcpy(&prg[0x08000], &prg[0x28000], 0x8000); |
| 502 | 684 | |
| 503 | 685 | mmc1_rom_mask = 0x07; |
| 504 | 686 | |
| 505 | 687 | /* MMC mapper at writes to $8000-$ffff */ |
| 506 | 688 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, mmc1_rom_switch_w ); |
| 507 | 689 | |
| 690 | |
| 508 | 691 | /* common init */ |
| 509 | 692 | DRIVER_INIT_CALL(playch10); |
| 693 | /* allocate vram */ |
| 694 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 695 | /* special init */ |
| 696 | set_videoram_bank(machine, 0, 8, 0, 8); |
| 510 | 697 | } |
| 511 | 698 | |
| 512 | 699 | /* D Board games with extra ram (Metroid) */ |
| r5325 | r5326 | |
| 519 | 706 | |
| 520 | 707 | /* common init */ |
| 521 | 708 | DRIVER_INIT_CALL(pcdboard); |
| 709 | |
| 710 | /* allocate vram */ |
| 711 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 712 | /* special init */ |
| 713 | set_videoram_bank(machine, 0, 8, 0, 8); |
| 522 | 714 | } |
| 523 | 715 | |
| 524 | 716 | /**********************************************************************************/ |
| 525 | | |
| 526 | 717 | /* E Board games (Mike Tyson's Punchout) - BROKEN - FIX ME */ |
| 527 | 718 | |
| 528 | 719 | /* callback for the ppu_latch */ |
| 529 | 720 | static void mapper9_latch( const device_config *ppu, offs_t offset ) |
| 530 | 721 | { |
| 531 | 722 | |
| 532 | | if( (offset & 0x1ff0) == 0x0fd0 && MMC2_bank_latch[0] != 0xfd ) |
| 723 | if((offset & 0x1ff0) == 0x0fd0 && MMC2_bank_latch[0] != 0xfd) |
| 533 | 724 | { |
| 534 | 725 | MMC2_bank_latch[0] = 0xfd; |
| 535 | | ppu2c0x_set_videorom_bank( ppu, 0, 4, MMC2_bank[0], 256 ); |
| 726 | pc10_set_videorom_bank(ppu->space[0]->machine, 0, 4, MMC2_bank[0], 4); |
| 536 | 727 | } |
| 537 | | else if( (offset & 0x1ff0) == 0x0fe0 && MMC2_bank_latch[0] != 0xfe ) |
| 728 | else if((offset & 0x1ff0) == 0x0fe0 && MMC2_bank_latch[0] != 0xfe) |
| 538 | 729 | { |
| 539 | 730 | MMC2_bank_latch[0] = 0xfe; |
| 540 | | ppu2c0x_set_videorom_bank( ppu, 0, 4, MMC2_bank[1], 256 ); |
| 731 | pc10_set_videorom_bank(ppu->space[0]->machine, 0, 4, MMC2_bank[1], 4); |
| 541 | 732 | } |
| 542 | | else if( (offset & 0x1ff0) == 0x1fd0 && MMC2_bank_latch[1] != 0xfd ) |
| 733 | else if((offset & 0x1ff0) == 0x1fd0 && MMC2_bank_latch[1] != 0xfd) |
| 543 | 734 | { |
| 544 | 735 | MMC2_bank_latch[1] = 0xfd; |
| 545 | | ppu2c0x_set_videorom_bank( ppu, 4, 4, MMC2_bank[2], 256 ); |
| 736 | pc10_set_videorom_bank(ppu->space[0]->machine, 4, 4, MMC2_bank[2], 4); |
| 546 | 737 | } |
| 547 | | else if( (offset & 0x1ff0) == 0x1fe0 && MMC2_bank_latch[1] != 0xfe ) |
| 738 | else if((offset & 0x1ff0) == 0x1fe0 && MMC2_bank_latch[1] != 0xfe) |
| 548 | 739 | { |
| 549 | 740 | MMC2_bank_latch[1] = 0xfe; |
| 550 | | ppu2c0x_set_videorom_bank( ppu, 4, 4, MMC2_bank[3], 256 ); |
| 741 | pc10_set_videorom_bank(ppu->space[0]->machine, 4, 4, MMC2_bank[3], 4); |
| 551 | 742 | } |
| 552 | 743 | } |
| 553 | 744 | |
| 554 | 745 | static WRITE8_HANDLER( eboard_rom_switch_w ) |
| 555 | 746 | { |
| 556 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 557 | | |
| 558 | 747 | /* a variation of mapper 9 on a nes */ |
| 559 | | switch( offset & 0x7000 ) |
| 748 | switch (offset & 0x7000) |
| 560 | 749 | { |
| 561 | 750 | case 0x2000: /* code bank switching */ |
| 562 | 751 | { |
| 563 | | int bankoffset = 0x10000 + ( data & 0x0f ) * 0x2000; |
| 564 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 565 | | memcpy( &prg[0x08000], &prg[bankoffset], 0x2000 ); |
| 752 | int bankoffset = 0x10000 + (data & 0x0f) * 0x2000; |
| 753 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 754 | memcpy(&prg[0x08000], &prg[bankoffset], 0x2000); |
| 566 | 755 | } |
| 567 | 756 | break; |
| 568 | 757 | |
| 569 | 758 | case 0x3000: /* gfx bank 0 - 4k */ |
| 570 | 759 | MMC2_bank[0] = data; |
| 571 | | if( MMC2_bank_latch[0] == 0xfd ) |
| 572 | | ppu2c0x_set_videorom_bank( ppu, 0, 4, data, 256 ); |
| 760 | if (MMC2_bank_latch[0] == 0xfd) |
| 761 | pc10_set_videorom_bank(space->machine, 0, 4, data, 4); |
| 573 | 762 | break; |
| 574 | 763 | |
| 575 | 764 | case 0x4000: /* gfx bank 0 - 4k */ |
| 576 | 765 | MMC2_bank[1] = data; |
| 577 | | if( MMC2_bank_latch[0] == 0xfe ) |
| 578 | | ppu2c0x_set_videorom_bank( ppu, 0, 4, data, 256 ); |
| 766 | if (MMC2_bank_latch[0] == 0xfe) |
| 767 | pc10_set_videorom_bank(space->machine, 0, 4, data, 4); |
| 579 | 768 | break; |
| 580 | 769 | |
| 581 | 770 | case 0x5000: /* gfx bank 1 - 4k */ |
| 582 | 771 | MMC2_bank[2] = data; |
| 583 | | if( MMC2_bank_latch[1] == 0xfd ) |
| 584 | | ppu2c0x_set_videorom_bank( ppu, 4, 4, data, 256 ); |
| 772 | if (MMC2_bank_latch[1] == 0xfd) |
| 773 | pc10_set_videorom_bank(space->machine, 4, 4, data, 4); |
| 585 | 774 | break; |
| 586 | 775 | |
| 587 | 776 | case 0x6000: /* gfx bank 1 - 4k */ |
| 588 | 777 | MMC2_bank[3] = data; |
| 589 | | if( MMC2_bank_latch[1] == 0xfe ) |
| 590 | | ppu2c0x_set_videorom_bank( ppu, 4, 4, data, 256 ); |
| 778 | if (MMC2_bank_latch[1] == 0xfe) |
| 779 | pc10_set_videorom_bank(space->machine, 4, 4, data, 4); |
| 591 | 780 | break; |
| 592 | 781 | |
| 593 | 782 | case 0x7000: /* mirroring */ |
| 594 | | ppu2c0x_set_mirroring( ppu, data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT ); |
| 783 | pc10_set_mirroring(data ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT); |
| 595 | 784 | |
| 596 | 785 | break; |
| 597 | 786 | } |
| r5325 | r5326 | |
| 599 | 788 | |
| 600 | 789 | DRIVER_INIT( pceboard ) |
| 601 | 790 | { |
| 602 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 791 | UINT8 *prg = memory_region(machine, "cart"); |
| 603 | 792 | |
| 793 | /* we have no vram, make sure switching games doesn't point to an old allocation */ |
| 794 | vram = NULL; |
| 795 | |
| 604 | 796 | /* We do manual banking, in case the code falls through */ |
| 605 | 797 | /* Copy the initial banks */ |
| 606 | | memcpy( &prg[0x08000], &prg[0x28000], 0x8000 ); |
| 798 | memcpy(&prg[0x08000], &prg[0x28000], 0x8000); |
| 607 | 799 | |
| 608 | 800 | /* basically a mapper 9 on a nes */ |
| 609 | 801 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, eboard_rom_switch_w ); |
| r5325 | r5326 | |
| 620 | 812 | } |
| 621 | 813 | |
| 622 | 814 | /**********************************************************************************/ |
| 623 | | |
| 624 | 815 | /* F Board games (Ninja Gaiden, Double Dragon) */ |
| 625 | 816 | |
| 626 | 817 | DRIVER_INIT( pcfboard ) |
| 627 | 818 | { |
| 628 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 819 | UINT8 *prg = memory_region(machine, "cart"); |
| 629 | 820 | |
| 821 | /* we have no vram, make sure switching games doesn't point to an old allocation */ |
| 822 | vram = NULL; |
| 823 | |
| 630 | 824 | /* We do manual banking, in case the code falls through */ |
| 631 | 825 | /* Copy the initial banks */ |
| 632 | | memcpy( &prg[0x08000], &prg[0x28000], 0x8000 ); |
| 826 | memcpy(&prg[0x08000], &prg[0x28000], 0x8000); |
| 633 | 827 | |
| 634 | 828 | mmc1_rom_mask = 0x07; |
| 635 | 829 | |
| r5325 | r5326 | |
| 648 | 842 | memory_install_readwrite8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x6000, 0x6fff, 0, 0, (read8_space_func)SMH_BANK(1), (write8_space_func)SMH_BANK(1) ); |
| 649 | 843 | memory_set_bankptr(machine, 1, auto_alloc_array(machine, UINT8, 0x1000)); |
| 650 | 844 | |
| 845 | vram = NULL; |
| 846 | |
| 651 | 847 | /* common init */ |
| 652 | 848 | DRIVER_INIT_CALL(pcfboard); |
| 653 | 849 | } |
| 654 | 850 | |
| 655 | 851 | /**********************************************************************************/ |
| 656 | | |
| 657 | 852 | /* G Board games (Super Mario Bros. 3) */ |
| 658 | 853 | |
| 659 | 854 | static int gboard_scanline_counter; |
| r5325 | r5326 | |
| 665 | 860 | |
| 666 | 861 | static void gboard_scanline_cb( const device_config *device, int scanline, int vblank, int blanked ) |
| 667 | 862 | { |
| 668 | | if ( !vblank && !blanked ) |
| 863 | if (!vblank && !blanked) |
| 669 | 864 | { |
| 670 | | if ( --gboard_scanline_counter == -1 ) |
| 865 | if (--gboard_scanline_counter == -1) |
| 671 | 866 | { |
| 672 | 867 | gboard_scanline_counter = gboard_scanline_latch; |
| 673 | 868 | generic_pulse_irq_line(cputag_get_cpu(device->machine, "cart"), 0); |
| r5325 | r5326 | |
| 681 | 876 | |
| 682 | 877 | /* basically, a MMC3 mapper from the nes */ |
| 683 | 878 | |
| 684 | | switch( offset & 0x7001 ) |
| 879 | switch (offset & 0x7001) |
| 685 | 880 | { |
| 686 | 881 | case 0x0000: |
| 687 | 882 | gboard_command = data; |
| 688 | 883 | |
| 689 | | if ( gboard_last_bank != ( data & 0xc0 ) ) |
| 884 | if (gboard_last_bank != (data & 0xc0)) |
| 690 | 885 | { |
| 691 | 886 | int bank; |
| 692 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 887 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 693 | 888 | |
| 694 | 889 | /* reset the banks */ |
| 695 | | if ( gboard_command & 0x40 ) |
| 890 | if (gboard_command & 0x40) |
| 696 | 891 | { |
| 697 | 892 | /* high bank */ |
| 698 | 893 | bank = gboard_banks[0] * 0x2000 + 0x10000; |
| 699 | 894 | |
| 700 | | memcpy( &prg[0x0c000], &prg[bank], 0x2000 ); |
| 701 | | memcpy( &prg[0x08000], &prg[0x4c000], 0x2000 ); |
| 895 | memcpy(&prg[0x0c000], &prg[bank], 0x2000); |
| 896 | memcpy(&prg[0x08000], &prg[0x4c000], 0x2000); |
| 702 | 897 | } |
| 703 | 898 | else |
| 704 | 899 | { |
| 705 | 900 | /* low bank */ |
| 706 | 901 | bank = gboard_banks[0] * 0x2000 + 0x10000; |
| 707 | 902 | |
| 708 | | memcpy( &prg[0x08000], &prg[bank], 0x2000 ); |
| 709 | | memcpy( &prg[0x0c000], &prg[0x4c000], 0x2000 ); |
| 903 | memcpy(&prg[0x08000], &prg[bank], 0x2000); |
| 904 | memcpy(&prg[0x0c000], &prg[0x4c000], 0x2000); |
| 710 | 905 | } |
| 711 | 906 | |
| 712 | 907 | /* mid bank */ |
| 713 | 908 | bank = gboard_banks[1] * 0x2000 + 0x10000; |
| 714 | | memcpy( &prg[0x0a000], &prg[bank], 0x2000 ); |
| 909 | memcpy(&prg[0x0a000], &prg[bank], 0x2000); |
| 715 | 910 | |
| 716 | 911 | gboard_last_bank = data & 0xc0; |
| 717 | 912 | } |
| r5325 | r5326 | |
| 720 | 915 | case 0x0001: |
| 721 | 916 | { |
| 722 | 917 | UINT8 cmd = gboard_command & 0x07; |
| 723 | | int page = ( gboard_command & 0x80 ) >> 5; |
| 918 | int page = (gboard_command & 0x80) >> 5; |
| 724 | 919 | int bank; |
| 725 | 920 | |
| 726 | | switch( cmd ) |
| 921 | switch (cmd) |
| 727 | 922 | { |
| 728 | 923 | case 0: /* char banking */ |
| 729 | 924 | case 1: /* char banking */ |
| 730 | 925 | data &= 0xfe; |
| 731 | | page ^= ( cmd << 1 ); |
| 732 | | ppu2c0x_set_videorom_bank( ppu, page, 2, data, 64 ); |
| 926 | page ^= (cmd << 1); |
| 927 | pc10_set_videorom_bank(space->machine, page, 2, data, 1); |
| 733 | 928 | break; |
| 734 | 929 | |
| 735 | 930 | case 2: /* char banking */ |
| r5325 | r5326 | |
| 737 | 932 | case 4: /* char banking */ |
| 738 | 933 | case 5: /* char banking */ |
| 739 | 934 | page ^= cmd + 2; |
| 740 | | ppu2c0x_set_videorom_bank( ppu, page, 1, data, 64 ); |
| 935 | pc10_set_videorom_bank(space->machine, page, 1, data, 1); |
| 741 | 936 | break; |
| 742 | 937 | |
| 743 | 938 | case 6: /* program banking */ |
| 744 | 939 | { |
| 745 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 746 | | if ( gboard_command & 0x40 ) |
| 940 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 941 | if (gboard_command & 0x40) |
| 747 | 942 | { |
| 748 | 943 | /* high bank */ |
| 749 | 944 | gboard_banks[0] = data & 0x1f; |
| 750 | | bank = ( gboard_banks[0] ) * 0x2000 + 0x10000; |
| 945 | bank = (gboard_banks[0]) * 0x2000 + 0x10000; |
| 751 | 946 | |
| 752 | | memcpy( &prg[0x0c000], &prg[bank], 0x2000 ); |
| 753 | | memcpy( &prg[0x08000], &prg[0x4c000], 0x2000 ); |
| 947 | memcpy(&prg[0x0c000], &prg[bank], 0x2000); |
| 948 | memcpy(&prg[0x08000], &prg[0x4c000], 0x2000); |
| 754 | 949 | } |
| 755 | 950 | else |
| 756 | 951 | { |
| 757 | 952 | /* low bank */ |
| 758 | 953 | gboard_banks[0] = data & 0x1f; |
| 759 | | bank = ( gboard_banks[0] ) * 0x2000 + 0x10000; |
| 954 | bank = (gboard_banks[0]) * 0x2000 + 0x10000; |
| 760 | 955 | |
| 761 | | memcpy( &prg[0x08000], &prg[bank], 0x2000 ); |
| 762 | | memcpy( &prg[0x0c000], &prg[0x4c000], 0x2000 ); |
| 956 | memcpy(&prg[0x08000], &prg[bank], 0x2000); |
| 957 | memcpy(&prg[0x0c000], &prg[0x4c000], 0x2000); |
| 763 | 958 | } |
| 764 | 959 | } |
| 765 | 960 | break; |
| r5325 | r5326 | |
| 767 | 962 | case 7: /* program banking */ |
| 768 | 963 | { |
| 769 | 964 | /* mid bank */ |
| 770 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 965 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 771 | 966 | gboard_banks[1] = data & 0x1f; |
| 772 | 967 | bank = gboard_banks[1] * 0x2000 + 0x10000; |
| 773 | 968 | |
| 774 | | memcpy( &prg[0x0a000], &prg[bank], 0x2000 ); |
| 969 | memcpy(&prg[0x0a000], &prg[bank], 0x2000); |
| 775 | 970 | } |
| 776 | 971 | break; |
| 777 | 972 | } |
| r5325 | r5326 | |
| 779 | 974 | break; |
| 780 | 975 | |
| 781 | 976 | case 0x2000: /* mirroring */ |
| 782 | | if( !gboard_4screen ) |
| 977 | if (!gboard_4screen) |
| 783 | 978 | { |
| 784 | | if ( data & 0x40 ) |
| 785 | | ppu2c0x_set_mirroring( ppu, PPU_MIRROR_HIGH ); |
| 979 | if (data & 0x40) |
| 980 | pc10_set_mirroring(PPU_MIRROR_HIGH); |
| 786 | 981 | else |
| 787 | | ppu2c0x_set_mirroring( ppu, ( data & 1 ) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT ); |
| 982 | pc10_set_mirroring((data & 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT); |
| 788 | 983 | } |
| 789 | 984 | break; |
| 790 | 985 | |
| r5325 | r5326 | |
| 801 | 996 | break; |
| 802 | 997 | |
| 803 | 998 | case 0x6000: /* disable irqs */ |
| 804 | | ppu2c0x_set_scanline_callback( ppu, 0 ); |
| 999 | ppu2c0x_set_scanline_callback(ppu, 0); |
| 805 | 1000 | break; |
| 806 | 1001 | |
| 807 | 1002 | case 0x6001: /* enable irqs */ |
| 808 | | ppu2c0x_set_scanline_callback( ppu, gboard_scanline_cb ); |
| 1003 | ppu2c0x_set_scanline_callback(ppu, gboard_scanline_cb); |
| 809 | 1004 | break; |
| 810 | 1005 | } |
| 811 | 1006 | } |
| 812 | 1007 | |
| 813 | 1008 | DRIVER_INIT( pcgboard ) |
| 814 | 1009 | { |
| 815 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 1010 | UINT8 *prg = memory_region(machine, "cart"); |
| 1011 | vram = NULL; |
| 816 | 1012 | |
| 817 | 1013 | /* We do manual banking, in case the code falls through */ |
| 818 | 1014 | /* Copy the initial banks */ |
| 819 | | memcpy( &prg[0x08000], &prg[0x4c000], 0x4000 ); |
| 820 | | memcpy( &prg[0x0c000], &prg[0x4c000], 0x4000 ); |
| 1015 | memcpy(&prg[0x08000], &prg[0x4c000], 0x4000); |
| 1016 | memcpy(&prg[0x0c000], &prg[0x4c000], 0x4000); |
| 821 | 1017 | |
| 822 | 1018 | /* MMC3 mapper at writes to $8000-$ffff */ |
| 823 | 1019 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, gboard_rom_switch_w ); |
| r5325 | r5326 | |
| 838 | 1034 | |
| 839 | 1035 | DRIVER_INIT( pcgboard_type2 ) |
| 840 | 1036 | { |
| 1037 | vram = NULL; |
| 841 | 1038 | /* common init */ |
| 842 | 1039 | DRIVER_INIT_CALL(pcgboard); |
| 843 | 1040 | |
| r5325 | r5326 | |
| 846 | 1043 | } |
| 847 | 1044 | |
| 848 | 1045 | /**********************************************************************************/ |
| 849 | | |
| 850 | 1046 | /* i Board games (Captain Sky Hawk, Solar Jetman) */ |
| 851 | 1047 | |
| 852 | 1048 | static WRITE8_HANDLER( iboard_rom_switch_w ) |
| 853 | 1049 | { |
| 854 | 1050 | int bank = data & 7; |
| 855 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 856 | | UINT8 *prg = memory_region( space->machine, "cart" ); |
| 1051 | UINT8 *prg = memory_region(space->machine, "cart"); |
| 857 | 1052 | |
| 858 | | if ( data & 0x10 ) |
| 859 | | ppu2c0x_set_mirroring( ppu, PPU_MIRROR_HIGH ); |
| 1053 | if (data & 0x10) |
| 1054 | pc10_set_mirroring(PPU_MIRROR_HIGH); |
| 860 | 1055 | else |
| 861 | | ppu2c0x_set_mirroring( ppu, PPU_MIRROR_LOW ); |
| 1056 | pc10_set_mirroring(PPU_MIRROR_LOW); |
| 862 | 1057 | |
| 863 | | memcpy( &prg[0x08000], &prg[bank * 0x8000 + 0x10000], 0x8000 ); |
| 1058 | memcpy(&prg[0x08000], &prg[bank * 0x8000 + 0x10000], 0x8000); |
| 864 | 1059 | } |
| 865 | 1060 | |
| 866 | 1061 | DRIVER_INIT( pciboard ) |
| 867 | 1062 | { |
| 868 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 1063 | UINT8 *prg = memory_region(machine, "cart"); |
| 869 | 1064 | |
| 870 | 1065 | /* We do manual banking, in case the code falls through */ |
| 871 | 1066 | /* Copy the initial banks */ |
| 872 | | memcpy( &prg[0x08000], &prg[0x10000], 0x8000 ); |
| 1067 | memcpy(&prg[0x08000], &prg[0x10000], 0x8000); |
| 873 | 1068 | |
| 874 | 1069 | /* Roms are banked at $8000 to $bfff */ |
| 875 | 1070 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, iboard_rom_switch_w ); |
| 876 | 1071 | |
| 877 | 1072 | /* common init */ |
| 878 | 1073 | DRIVER_INIT_CALL(playch10); |
| 1074 | |
| 1075 | /* allocate vram */ |
| 1076 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 1077 | /* special init */ |
| 1078 | set_videoram_bank(machine, 0, 8, 0, 8); |
| 879 | 1079 | } |
| 880 | 1080 | |
| 881 | 1081 | /**********************************************************************************/ |
| 882 | | |
| 883 | 1082 | /* H Board games (PinBot) */ |
| 884 | 1083 | |
| 885 | 1084 | static WRITE8_HANDLER( hboard_rom_switch_w ) |
| 886 | 1085 | { |
| 887 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 888 | | |
| 889 | | switch( offset & 0x7001 ) |
| 1086 | switch (offset & 0x7001) |
| 890 | 1087 | { |
| 891 | 1088 | case 0x0001: |
| 892 | 1089 | { |
| 893 | 1090 | UINT8 cmd = gboard_command & 0x07; |
| 894 | | int page = ( gboard_command & 0x80 ) >> 5; |
| 1091 | int page = (gboard_command & 0x80) >> 5; |
| 895 | 1092 | |
| 896 | | switch( cmd ) |
| 1093 | switch (cmd) |
| 897 | 1094 | { |
| 898 | 1095 | case 0: /* char banking */ |
| 899 | 1096 | case 1: /* char banking */ |
| 900 | 1097 | data &= 0xfe; |
| 901 | | page ^= ( cmd << 1 ); |
| 902 | | if ( data & 0x20 ) |
| 1098 | page ^= (cmd << 1); |
| 1099 | if (data & 0x40) |
| 903 | 1100 | { |
| 904 | | ppu2c0x_set_videoram_bank( ppu, page, 2, data, 64 ); |
| 1101 | set_videoram_bank(space->machine, page, 2, data, 1); |
| 905 | 1102 | } |
| 906 | 1103 | else |
| 907 | 1104 | { |
| 908 | | ppu2c0x_set_videorom_bank( ppu, page, 2, data, 64 ); |
| 1105 | pc10_set_videorom_bank(space->machine, page, 2, data, 1); |
| 909 | 1106 | } |
| 910 | 1107 | return; |
| 911 | 1108 | |
| r5325 | r5326 | |
| 914 | 1111 | case 4: /* char banking */ |
| 915 | 1112 | case 5: /* char banking */ |
| 916 | 1113 | page ^= cmd + 2; |
| 917 | | if ( data & 0x40 ) |
| 1114 | if (data & 0x40) |
| 918 | 1115 | { |
| 919 | | ppu2c0x_set_videoram_bank( ppu, page, 1, data, 64 ); |
| 1116 | set_videoram_bank(space->machine, page, 1, data, 1); |
| 920 | 1117 | } |
| 921 | 1118 | else |
| 922 | 1119 | { |
| 923 | | ppu2c0x_set_videorom_bank( ppu, page, 1, data, 64 ); |
| 1120 | pc10_set_videorom_bank(space->machine, page, 1, data, 1); |
| 924 | 1121 | } |
| 925 | 1122 | return; |
| 926 | 1123 | } |
| r5325 | r5326 | |
| 932 | 1129 | |
| 933 | 1130 | DRIVER_INIT( pchboard ) |
| 934 | 1131 | { |
| 935 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 936 | | memcpy( &prg[0x08000], &prg[0x4c000], 0x4000 ); |
| 937 | | memcpy( &prg[0x0c000], &prg[0x4c000], 0x4000 ); |
| 1132 | UINT8 *prg = memory_region(machine, "cart"); |
| 1133 | memcpy(&prg[0x08000], &prg[0x4c000], 0x4000); |
| 1134 | memcpy(&prg[0x0c000], &prg[0x4c000], 0x4000); |
| 938 | 1135 | |
| 939 | 1136 | /* Roms are banked at $8000 to $bfff */ |
| 940 | 1137 | memory_install_write8_handler(cputag_get_address_space(machine, "cart", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, hboard_rom_switch_w ); |
| r5325 | r5326 | |
| 955 | 1152 | } |
| 956 | 1153 | |
| 957 | 1154 | /**********************************************************************************/ |
| 958 | | |
| 959 | 1155 | /* K Board games (Mario Open Golf) */ |
| 960 | 1156 | |
| 961 | 1157 | DRIVER_INIT( pckboard ) |
| 962 | 1158 | { |
| 963 | | UINT8 *prg = memory_region( machine, "cart" ); |
| 1159 | UINT8 *prg = memory_region(machine, "cart"); |
| 964 | 1160 | |
| 965 | 1161 | /* We do manual banking, in case the code falls through */ |
| 966 | 1162 | /* Copy the initial banks */ |
| 967 | | memcpy( &prg[0x08000], &prg[0x48000], 0x8000 ); |
| 1163 | memcpy(&prg[0x08000], &prg[0x48000], 0x8000); |
| 968 | 1164 | |
| 969 | 1165 | mmc1_rom_mask = 0x0f; |
| 970 | 1166 | |
| r5325 | r5326 | |
| 977 | 1173 | |
| 978 | 1174 | /* common init */ |
| 979 | 1175 | DRIVER_INIT_CALL(playch10); |
| 1176 | |
| 1177 | /* allocate vram */ |
| 1178 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 1179 | /* special init */ |
| 1180 | set_videoram_bank(machine, 0, 8, 0, 8); |
| 980 | 1181 | } |
src/mame/machine/vsnes.c
| r5325 | r5326 | |
| 22 | 22 | static int sound_fix=0; |
| 23 | 23 | static UINT8 last_bank; |
| 24 | 24 | |
| 25 | /* PPU notes */ |
| 26 | /* nametable is, per Lord Nightmare, always 4K per PPU */ |
| 27 | /* The vsnes system has relatively few banking options for CHR */ |
| 28 | /* Each driver will use ROM or RAM for CHR, never both, and RAM is never banked */ |
| 29 | /* This leads to the memory system being an optimal place to perform banking */ |
| 30 | |
| 31 | /* need double pointers for vsdual */ |
| 32 | static UINT8* vram = NULL; |
| 33 | static UINT8* vrom[2]; |
| 34 | static UINT8* nt_ram[2]; |
| 35 | static UINT8* nt_page[2][4]; // because mirroring is used. |
| 36 | |
| 37 | /* Prototypes for mapping board components to PPU bus */ |
| 38 | WRITE8_HANDLER( vsnes_nt0_w ); |
| 39 | WRITE8_HANDLER( vsnes_nt1_w ); |
| 40 | READ8_HANDLER( vsnes_nt0_r ); |
| 41 | READ8_HANDLER( vsnes_nt1_r ); |
| 42 | void v_set_videorom_bank( running_machine* machine, int start, int count, int bank, int bank_size_in_kb ); |
| 43 | |
| 25 | 44 | /************************************* |
| 26 | 45 | * |
| 27 | 46 | * Color Mapping |
| r5325 | r5326 | |
| 92 | 111 | /* this is the protection. color codes are shuffled around */ |
| 93 | 112 | /* the ones with value 0xff are unknown */ |
| 94 | 113 | |
| 95 | | if ( addr >= 0x3f00 ) |
| 114 | if (addr >= 0x3f00) |
| 96 | 115 | { |
| 97 | | int newdata = remapped_colortable[ data & 0x3f ]; |
| 116 | int newdata = remapped_colortable[data & 0x3f]; |
| 98 | 117 | |
| 99 | | if ( newdata != 0xff ) |
| 118 | if (newdata != 0xff) |
| 100 | 119 | data = newdata; |
| 101 | 120 | |
| 102 | 121 | #ifdef MAME_DEBUG |
| 103 | 122 | else |
| 104 | | popmessage( "Unmatched color %02x, at address %04x", data & 0x3f, addr ); |
| 123 | popmessage("Unmatched color %02x, at address %04x", data & 0x3f, addr); |
| 105 | 124 | #endif |
| 106 | 125 | } |
| 107 | 126 | |
| r5325 | r5326 | |
| 113 | 132 | * Input Ports |
| 114 | 133 | * |
| 115 | 134 | *************************************/ |
| 135 | |
| 116 | 136 | WRITE8_HANDLER( vsnes_in0_w ) |
| 117 | 137 | { |
| 118 | 138 | /* Toggling bit 0 high then low resets both controllers */ |
| 119 | | if ( data & 1 ) |
| 139 | if (data & 1) |
| 120 | 140 | { |
| 121 | 141 | /* load up the latches */ |
| 122 | 142 | input_latch[0] = input_port_read(space->machine, "IN0"); |
| r5325 | r5326 | |
| 126 | 146 | |
| 127 | 147 | static READ8_HANDLER( gun_in0_r ) |
| 128 | 148 | { |
| 129 | | int ret = ( input_latch[0] ) & 1; |
| 149 | int ret = (input_latch[0]) & 1; |
| 130 | 150 | |
| 131 | 151 | /* shift */ |
| 132 | 152 | input_latch[0] >>= 1; |
| 133 | 153 | |
| 134 | 154 | ret |= input_port_read(space->machine, "COINS"); /* merge coins, etc */ |
| 135 | | ret |= ( input_port_read(space->machine, "DSW0") & 3 ) << 3; /* merge 2 dipswitches */ |
| 155 | ret |= (input_port_read(space->machine, "DSW0") & 3) << 3; /* merge 2 dipswitches */ |
| 136 | 156 | |
| 137 | 157 | /* The gun games expect a 1 returned on every 5th read after sound_fix is reset*/ |
| 138 | 158 | /* Info Supplied by Ben Parnell <xodnizel@home.com> of FCE Ultra fame */ |
| r5325 | r5326 | |
| 148 | 168 | |
| 149 | 169 | } |
| 150 | 170 | |
| 151 | | |
| 152 | 171 | READ8_HANDLER( vsnes_in0_r ) |
| 153 | 172 | { |
| 154 | 173 | |
| 155 | | int ret = ( input_latch[0] ) & 1; |
| 174 | int ret = (input_latch[0]) & 1; |
| 156 | 175 | |
| 157 | 176 | /* shift */ |
| 158 | 177 | input_latch[0] >>= 1; |
| 159 | 178 | |
| 160 | 179 | ret |= input_port_read(space->machine, "COINS"); /* merge coins, etc */ |
| 161 | | ret |= ( input_port_read(space->machine, "DSW0") & 3 ) << 3; /* merge 2 dipswitches */ |
| 180 | ret |= (input_port_read(space->machine, "DSW0") & 3) << 3; /* merge 2 dipswitches */ |
| 162 | 181 | |
| 163 | 182 | return ret; |
| 164 | 183 | |
| 165 | 184 | } |
| 166 | 185 | |
| 167 | | |
| 168 | 186 | READ8_HANDLER( vsnes_in1_r ) |
| 169 | 187 | { |
| 170 | | int ret = ( input_latch[1] ) & 1; |
| 188 | int ret = (input_latch[1]) & 1; |
| 171 | 189 | |
| 172 | 190 | ret |= input_port_read(space->machine, "DSW0") & ~3; /* merge the rest of the dipswitches */ |
| 173 | 191 | |
| r5325 | r5326 | |
| 180 | 198 | WRITE8_HANDLER( vsnes_in0_1_w ) |
| 181 | 199 | { |
| 182 | 200 | /* Toggling bit 0 high then low resets both controllers */ |
| 183 | | if ( data & 1 ) |
| 201 | if (data & 1) |
| 184 | 202 | { |
| 185 | 203 | /* load up the latches */ |
| 186 | 204 | input_latch[2] = input_port_read(space->machine, "IN2"); |
| r5325 | r5326 | |
| 190 | 208 | |
| 191 | 209 | READ8_HANDLER( vsnes_in0_1_r ) |
| 192 | 210 | { |
| 193 | | int ret = ( input_latch[2] ) & 1; |
| 211 | int ret = (input_latch[2]) & 1; |
| 194 | 212 | |
| 195 | 213 | /* shift */ |
| 196 | 214 | input_latch[2] >>= 1; |
| 197 | 215 | |
| 198 | 216 | ret |= input_port_read(space->machine, "COINS2"); /* merge coins, etc */ |
| 199 | | ret |= ( input_port_read(space->machine, "DSW1") & 3 ) << 3; /* merge 2 dipswitches */ |
| 217 | ret |= (input_port_read(space->machine, "DSW1") & 3) << 3; /* merge 2 dipswitches */ |
| 200 | 218 | return ret; |
| 201 | 219 | } |
| 202 | 220 | |
| 203 | 221 | READ8_HANDLER( vsnes_in1_1_r ) |
| 204 | 222 | { |
| 205 | | int ret = ( input_latch[3] ) & 1; |
| 223 | int ret = (input_latch[3]) & 1; |
| 206 | 224 | |
| 207 | 225 | ret |= input_port_read(space->machine, "DSW1") & ~3; /* merge the rest of the dipswitches */ |
| 208 | 226 | |
| r5325 | r5326 | |
| 229 | 247 | input_latch[2] = input_latch[3] = 0; |
| 230 | 248 | |
| 231 | 249 | /* if we need to remap, install the callback */ |
| 232 | | if ( remapped_colortable ) |
| 233 | | ppu2c0x_set_vidaccess_callback( ppu, remap_colors ); |
| 250 | if (remapped_colortable) |
| 251 | ppu2c0x_set_vidaccess_callback(ppu, remap_colors); |
| 234 | 252 | } |
| 235 | 253 | |
| 236 | 254 | /************************************* |
| r5325 | r5326 | |
| 238 | 256 | * Init machine |
| 239 | 257 | * |
| 240 | 258 | *************************************/ |
| 259 | |
| 241 | 260 | MACHINE_RESET( vsdual ) |
| 242 | 261 | { |
| 243 | 262 | const device_config *ppu1 = devtag_get_device(machine, "ppu1"); |
| r5325 | r5326 | |
| 247 | 266 | input_latch[2] = input_latch[3] = 0; |
| 248 | 267 | |
| 249 | 268 | /* if we need to remap, install the callback */ |
| 250 | | if ( remapped_colortable ) |
| 269 | if (remapped_colortable) |
| 251 | 270 | { |
| 252 | | ppu2c0x_set_vidaccess_callback( ppu1, remap_colors ); |
| 253 | | ppu2c0x_set_vidaccess_callback( ppu2, remap_colors ); |
| 271 | ppu2c0x_set_vidaccess_callback(ppu1, remap_colors); |
| 272 | ppu2c0x_set_vidaccess_callback(ppu2, remap_colors); |
| 254 | 273 | } |
| 255 | 274 | } |
| 256 | 275 | |
| 257 | 276 | /************************************* |
| 258 | 277 | * |
| 278 | * Machine start functions |
| 279 | * |
| 280 | *************************************/ |
| 281 | |
| 282 | MACHINE_START( vsnes ) |
| 283 | { |
| 284 | /* establish nametable ram */ |
| 285 | nt_ram[0] = auto_alloc_array(machine, UINT8, 0x1000); |
| 286 | /* set mirroring */ |
| 287 | nt_page[0][0] = nt_ram[0]; |
| 288 | nt_page[0][1] = nt_ram[0] + 0x400; |
| 289 | nt_page[0][2] = nt_ram[0] + 0x800; |
| 290 | nt_page[0][3] = nt_ram[0] + 0xc00; |
| 291 | |
| 292 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, vsnes_nt0_r, vsnes_nt0_w); |
| 293 | |
| 294 | vrom[0] = memory_region(machine, "gfx1"); |
| 295 | |
| 296 | /* establish chr banks */ |
| 297 | /* bank 1 is used already! */ |
| 298 | /* DRIVER_INIT is called first - means we can handle this different for VRAM games! */ |
| 299 | if (NULL != vrom[0]) |
| 300 | { |
| 301 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x03ff, 0, 0, SMH_BANK(2), 0); |
| 302 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0400, 0x07ff, 0, 0, SMH_BANK(3), 0); |
| 303 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0800, 0x0bff, 0, 0, SMH_BANK(4), 0); |
| 304 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0c00, 0x0fff, 0, 0, SMH_BANK(5), 0); |
| 305 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1000, 0x13ff, 0, 0, SMH_BANK(6), 0); |
| 306 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1400, 0x17ff, 0, 0, SMH_BANK(7), 0); |
| 307 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1800, 0x1bff, 0, 0, SMH_BANK(8), 0); |
| 308 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x1c00, 0x1fff, 0, 0, SMH_BANK(9), 0); |
| 309 | v_set_videorom_bank(machine, 0, 8, 0, 8); |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(2), SMH_BANK(2)); |
| 314 | memory_set_bankptr(machine, 2, vram); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /************************************* |
| 319 | * |
| 320 | * Init machine |
| 321 | * |
| 322 | *************************************/ |
| 323 | |
| 324 | MACHINE_START( vsdual ) |
| 325 | { |
| 326 | vrom[0] = memory_region(machine, "gfx1"); |
| 327 | vrom[1] = memory_region(machine, "gfx2"); |
| 328 | |
| 329 | /* establish nametable ram */ |
| 330 | nt_ram[0] = auto_alloc_array(machine, UINT8, 0x1000); |
| 331 | nt_ram[1] = auto_alloc_array(machine, UINT8, 0x1000); |
| 332 | /* set mirroring */ |
| 333 | nt_page[0][0] = nt_ram[0]; |
| 334 | nt_page[0][1] = nt_ram[0] + 0x400; |
| 335 | nt_page[0][2] = nt_ram[0] + 0x800; |
| 336 | nt_page[0][3] = nt_ram[0] + 0xc00; |
| 337 | nt_page[1][0] = nt_ram[1]; |
| 338 | nt_page[1][1] = nt_ram[1] + 0x400; |
| 339 | nt_page[1][2] = nt_ram[1] + 0x800; |
| 340 | nt_page[1][3] = nt_ram[1] + 0xc00; |
| 341 | |
| 342 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, vsnes_nt0_r, vsnes_nt0_w); |
| 343 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu2"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, vsnes_nt1_r, vsnes_nt1_w); |
| 344 | // read only! |
| 345 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu1"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(2), 0); |
| 346 | // read only! |
| 347 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu2"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(3), 0); |
| 348 | memory_set_bankptr(machine, 2, vrom[0]); |
| 349 | memory_set_bankptr(machine, 3, vrom[1]); |
| 350 | } |
| 351 | |
| 352 | /************************************* |
| 353 | * |
| 354 | * External mappings for PPU bus |
| 355 | * |
| 356 | *************************************/ |
| 357 | |
| 358 | WRITE8_HANDLER( vsnes_nt0_w ) |
| 359 | { |
| 360 | int page = ((offset & 0xc00) >> 10); |
| 361 | nt_page[0][page][offset & 0x3ff] = data; |
| 362 | |
| 363 | } |
| 364 | |
| 365 | WRITE8_HANDLER( vsnes_nt1_w ) |
| 366 | { |
| 367 | int page = ((offset & 0xc00) >> 10); |
| 368 | nt_page[1][page][offset & 0x3ff] = data; |
| 369 | |
| 370 | } |
| 371 | |
| 372 | READ8_HANDLER( vsnes_nt0_r ) |
| 373 | { |
| 374 | int page = ((offset&0xc00) >> 10); |
| 375 | return nt_page[0][page][offset & 0x3ff]; |
| 376 | } |
| 377 | |
| 378 | READ8_HANDLER( vsnes_nt1_r ) |
| 379 | { |
| 380 | int page = ((offset & 0xc00) >> 10); |
| 381 | return nt_page[1][page][offset & 0x3ff]; |
| 382 | } |
| 383 | |
| 384 | void v_set_mirroring( int ppu, int mirroring ) |
| 385 | { |
| 386 | switch (mirroring) |
| 387 | { |
| 388 | case PPU_MIRROR_LOW: |
| 389 | nt_page[ppu][0] = nt_page[ppu][1] = nt_page[ppu][2] = nt_page[ppu][3] = nt_ram[ppu]; |
| 390 | break; |
| 391 | case PPU_MIRROR_HIGH: |
| 392 | nt_page[ppu][0] = nt_page[ppu][1] = nt_page[ppu][2] = nt_page[ppu][3] = nt_ram[ppu] + 0x400; |
| 393 | break; |
| 394 | case PPU_MIRROR_HORZ: |
| 395 | nt_page[ppu][0] = nt_ram[ppu]; |
| 396 | nt_page[ppu][1] = nt_ram[ppu]; |
| 397 | nt_page[ppu][2] = nt_ram[ppu] + 0x400; |
| 398 | nt_page[ppu][3] = nt_ram[ppu] + 0x400; |
| 399 | break; |
| 400 | case PPU_MIRROR_VERT: |
| 401 | nt_page[ppu][0] = nt_ram[ppu]; |
| 402 | nt_page[ppu][1] = nt_ram[ppu] + 0x400; |
| 403 | nt_page[ppu][2] = nt_ram[ppu]; |
| 404 | nt_page[ppu][3] = nt_ram[ppu] + 0x400; |
| 405 | break; |
| 406 | case PPU_MIRROR_NONE: |
| 407 | default: |
| 408 | nt_page[ppu][0] = nt_ram[ppu]; |
| 409 | nt_page[ppu][1] = nt_ram[ppu] + 0x400; |
| 410 | nt_page[ppu][2] = nt_ram[ppu] + 0x800; |
| 411 | nt_page[ppu][3] = nt_ram[ppu] + 0xc00; |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | } |
| 416 | |
| 417 | void v_set_videorom_bank( running_machine* machine, int start, int count, int bank, int bank_size_in_kb ) |
| 418 | { |
| 419 | int i, j; |
| 420 | int offset = bank * (bank_size_in_kb * 0x400); |
| 421 | /* automatically add 2 to all start values (because the PPU is bank 2) */ |
| 422 | /* bank_size_in_kb is used to determine how large the "bank" parameter is */ |
| 423 | /* count determines the size of the area mapped */ |
| 424 | for (i = 0; i < count; i++, offset += 0x400) |
| 425 | { |
| 426 | j = i + start + 2; |
| 427 | memory_set_bankptr(machine, j, vrom[0] + offset); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /************************************* |
| 432 | * |
| 259 | 433 | * Common init for all games |
| 260 | 434 | * |
| 261 | 435 | *************************************/ |
| 436 | |
| 262 | 437 | static void init_vsnes(running_machine *machine) |
| 263 | 438 | { |
| 264 | 439 | /* set the controller to default */ |
| r5325 | r5326 | |
| 276 | 451 | |
| 277 | 452 | static WRITE8_HANDLER( vsnormal_vrom_banking ) |
| 278 | 453 | { |
| 279 | | const device_config *ppu1 = devtag_get_device(space->machine, "ppu1"); |
| 280 | | |
| 281 | 454 | /* switch vrom */ |
| 282 | | ppu2c0x_set_videorom_bank( ppu1, 0, 8, ( data & 4 ) ? 1 : 0, 512 ); |
| 455 | v_set_videorom_bank(space->machine, 0, 8, (data & 4) ? 1 : 0, 8); |
| 283 | 456 | |
| 284 | 457 | /* bit 1 ( data & 2 ) enables writes to extra ram, we ignore it */ |
| 285 | 458 | |
| 286 | 459 | /* move along */ |
| 287 | | vsnes_in0_w( space, offset, data ); |
| 460 | vsnes_in0_w(space, offset, data); |
| 288 | 461 | } |
| 289 | 462 | |
| 290 | 463 | /* Most games switch VROM Banks in controller 0 write */ |
| r5325 | r5326 | |
| 301 | 474 | |
| 302 | 475 | /* This PPU has registers mapped at $2000 and $2001 inverted */ |
| 303 | 476 | /* and no remapped color */ |
| 304 | | if ( offset == 0 ) |
| 477 | if (offset == 0) |
| 305 | 478 | { |
| 306 | | ppu2c0x_w( ppu1, 1, data ); |
| 479 | ppu2c0x_w(ppu1, 1, data); |
| 307 | 480 | return; |
| 308 | 481 | } |
| 309 | 482 | |
| 310 | | ppu2c0x_w( ppu1, 0, data ); |
| 483 | ppu2c0x_w(ppu1, 0, data); |
| 311 | 484 | } |
| 312 | 485 | |
| 313 | 486 | /**********************************************************************************/ |
| 314 | | |
| 315 | 487 | /* Super Mario Bros. Extra ram at $6000 (NV?) and remapped colors */ |
| 316 | 488 | |
| 317 | 489 | DRIVER_INIT( suprmrio ) |
| r5325 | r5326 | |
| 333 | 505 | } |
| 334 | 506 | |
| 335 | 507 | /**********************************************************************************/ |
| 336 | | |
| 337 | 508 | /* Gun Games - VROM Banking in controller 0 write */ |
| 338 | 509 | |
| 339 | 510 | static WRITE8_HANDLER( gun_in0_w ) |
| r5325 | r5326 | |
| 344 | 515 | if (vsnes_do_vrom_bank) |
| 345 | 516 | { |
| 346 | 517 | /* switch vrom */ |
| 347 | | ppu2c0x_set_videorom_bank( ppu1, 0, 8, ( data & 4 ) ? 1 : 0, 512 ); |
| 518 | v_set_videorom_bank(space->machine, 0, 8, (data & 4) ? 1 : 0, 8); |
| 348 | 519 | } |
| 349 | 520 | |
| 350 | 521 | /* here we do things a little different */ |
| 351 | | if ( data & 1 ) |
| 522 | if (data & 1) |
| 352 | 523 | { |
| 353 | 524 | |
| 354 | 525 | /* load up the latches */ |
| 355 | 526 | input_latch[0] = input_port_read(space->machine, "IN0"); |
| 356 | 527 | |
| 357 | 528 | /* do the gun thing */ |
| 358 | | if ( vsnes_gun_controller ) |
| 529 | if (vsnes_gun_controller) |
| 359 | 530 | { |
| 360 | 531 | int x = input_port_read(space->machine, "GUNX"); |
| 361 | 532 | int y = input_port_read(space->machine, "GUNY"); |
| 362 | 533 | UINT32 pix, color_base; |
| 363 | 534 | |
| 364 | 535 | /* get the pixel at the gun position */ |
| 365 | | pix = ppu2c0x_get_pixel( ppu1, x, y ); |
| 536 | pix = ppu2c0x_get_pixel(ppu1, x, y); |
| 366 | 537 | |
| 367 | 538 | /* get the color base from the ppu */ |
| 368 | | color_base = ppu2c0x_get_colorbase( ppu1 ); |
| 539 | color_base = ppu2c0x_get_colorbase(ppu1); |
| 369 | 540 | |
| 370 | 541 | /* look at the screen and see if the cursor is over a bright pixel */ |
| 371 | | if ( ( pix == color_base+0x20 ) || ( pix == color_base+0x30 ) || |
| 372 | | ( pix == color_base+0x33 ) || ( pix == color_base+0x34 ) ) |
| 542 | if ((pix == color_base + 0x20 ) || (pix == color_base + 0x30) || |
| 543 | (pix == color_base + 0x33 ) || (pix == color_base + 0x34)) |
| 373 | 544 | { |
| 374 | 545 | input_latch[0] |= 0x40; |
| 375 | 546 | } |
| r5325 | r5326 | |
| 378 | 549 | input_latch[1] = input_port_read(space->machine, "IN1"); |
| 379 | 550 | } |
| 380 | 551 | |
| 381 | | if ( ( zapstore & 1 ) && ( !( data & 1 ) ) ) |
| 552 | if ((zapstore & 1) && (!(data & 1))) |
| 382 | 553 | /* reset sound_fix to keep sound from hanging */ |
| 383 | 554 | { |
| 384 | 555 | sound_fix = 0; |
| r5325 | r5326 | |
| 401 | 572 | } |
| 402 | 573 | |
| 403 | 574 | /**********************************************************************************/ |
| 404 | | |
| 405 | 575 | /* The Goonies, VS Gradius: ROMs bankings at $8000-$ffff */ |
| 406 | 576 | |
| 407 | 577 | static WRITE8_HANDLER( goonies_rom_banking ) |
| 408 | 578 | { |
| 409 | | const device_config *ppu1 = devtag_get_device(space->machine, "ppu1"); |
| 410 | | int reg = ( offset >> 12 ) & 0x07; |
| 411 | | int bankoffset = ( data & 7 ) * 0x2000 + 0x10000; |
| 579 | int reg = (offset >> 12) & 0x07; |
| 580 | int bankoffset = (data & 7) * 0x2000 + 0x10000; |
| 412 | 581 | |
| 413 | | switch( reg ) |
| 582 | switch (reg) |
| 414 | 583 | { |
| 415 | 584 | case 0: /* code bank 0 */ |
| 416 | 585 | case 2: /* code bank 1 */ |
| 417 | 586 | case 4: /* code bank 2 */ |
| 418 | 587 | { |
| 419 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 420 | | memcpy( &prg[0x08000 + reg*0x1000], &prg[bankoffset], 0x2000 ); |
| 588 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 589 | memcpy(&prg[0x08000 + reg * 0x1000], &prg[bankoffset], 0x2000); |
| 421 | 590 | } |
| 422 | 591 | break; |
| 423 | 592 | |
| 424 | 593 | case 6: /* vrom bank 0 */ |
| 425 | | ppu2c0x_set_videorom_bank( ppu1, 0, 4, data, 256 ); |
| 594 | v_set_videorom_bank(space->machine, 0, 4, data, 4); |
| 426 | 595 | break; |
| 427 | 596 | |
| 428 | 597 | case 7: /* vrom bank 1 */ |
| 429 | | ppu2c0x_set_videorom_bank( ppu1, 4, 4, data, 256 ); |
| 598 | v_set_videorom_bank(space->machine, 4, 4, data, 4); |
| 430 | 599 | break; |
| 431 | 600 | } |
| 432 | 601 | } |
| r5325 | r5326 | |
| 435 | 604 | { |
| 436 | 605 | /* We do manual banking, in case the code falls through */ |
| 437 | 606 | /* Copy the initial banks */ |
| 438 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 439 | | memcpy( &prg[0x08000], &prg[0x18000], 0x8000 ); |
| 607 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 608 | memcpy(&prg[0x08000], &prg[0x18000], 0x8000); |
| 440 | 609 | |
| 441 | 610 | /* banking is done with writes to the $8000-$ffff area */ |
| 442 | 611 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, goonies_rom_banking ); |
| r5325 | r5326 | |
| 452 | 621 | { |
| 453 | 622 | /* We do manual banking, in case the code falls through */ |
| 454 | 623 | /* Copy the initial banks */ |
| 455 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 456 | | memcpy( &prg[0x08000], &prg[0x18000], 0x8000 ); |
| 624 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 625 | memcpy(&prg[0x08000], &prg[0x18000], 0x8000); |
| 457 | 626 | |
| 458 | 627 | /* banking is done with writes to the $8000-$ffff area */ |
| 459 | 628 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, goonies_rom_banking ); |
| r5325 | r5326 | |
| 496 | 665 | } |
| 497 | 666 | |
| 498 | 667 | /***********************************************************************/ |
| 499 | | |
| 500 | 668 | /* Vs. Gumshoe */ |
| 501 | 669 | |
| 502 | 670 | static READ8_HANDLER( vsgshoe_security_r ) |
| 503 | 671 | { |
| 504 | 672 | /* low part must be 0x1c */ |
| 505 | | return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x1c; |
| 673 | return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x1c; |
| 506 | 674 | } |
| 507 | 675 | |
| 508 | 676 | static WRITE8_HANDLER( vsgshoe_gun_in0_w ) |
| r5325 | r5326 | |
| 511 | 679 | int addr; |
| 512 | 680 | if((data & 0x04) != old_bank) |
| 513 | 681 | { |
| 514 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 682 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 515 | 683 | old_bank = data & 0x04; |
| 516 | 684 | addr = old_bank ? 0x12000: 0x10000; |
| 517 | | memcpy (&prg[0x08000], &prg[addr], 0x2000); |
| 685 | memcpy(&prg[0x08000], &prg[addr], 0x2000); |
| 518 | 686 | } |
| 519 | 687 | |
| 520 | 688 | gun_in0_w(space, offset, data); |
| r5325 | r5326 | |
| 523 | 691 | DRIVER_INIT( vsgshoe ) |
| 524 | 692 | { |
| 525 | 693 | /* set up the default bank */ |
| 526 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 694 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 527 | 695 | memcpy (&prg[0x08000], &prg[0x12000], 0x2000); |
| 528 | 696 | |
| 529 | 697 | /* Protection */ |
| r5325 | r5326 | |
| 541 | 709 | } |
| 542 | 710 | |
| 543 | 711 | /**********************************************************************************/ |
| 544 | | |
| 545 | 712 | /* Dr Mario: ROMs bankings at $8000-$ffff */ |
| 546 | 713 | |
| 547 | 714 | static int drmario_shiftreg; |
| r5325 | r5326 | |
| 549 | 716 | |
| 550 | 717 | static WRITE8_HANDLER( drmario_rom_banking ) |
| 551 | 718 | { |
| 552 | | const device_config *ppu1 = devtag_get_device(space->machine, "ppu1"); |
| 553 | | |
| 554 | 719 | /* basically, a MMC1 mapper from the nes */ |
| 555 | 720 | static int size16k, switchlow, vrom4k; |
| 556 | 721 | |
| 557 | | int reg = ( offset >> 13 ); |
| 722 | int reg = (offset >> 13); |
| 558 | 723 | |
| 559 | 724 | /* reset mapper */ |
| 560 | | if ( data & 0x80 ) |
| 725 | if (data & 0x80) |
| 561 | 726 | { |
| 562 | 727 | drmario_shiftreg = drmario_shiftcount = 0; |
| 563 | 728 | |
| r5325 | r5326 | |
| 570 | 735 | } |
| 571 | 736 | |
| 572 | 737 | /* see if we need to clock in data */ |
| 573 | | if ( drmario_shiftcount < 5 ) |
| 738 | if (drmario_shiftcount < 5) |
| 574 | 739 | { |
| 575 | 740 | drmario_shiftreg >>= 1; |
| 576 | | drmario_shiftreg |= ( data & 1 ) << 4; |
| 741 | drmario_shiftreg |= (data & 1) << 4; |
| 577 | 742 | drmario_shiftcount++; |
| 578 | 743 | } |
| 579 | 744 | |
| 580 | 745 | /* are we done shifting? */ |
| 581 | | if ( drmario_shiftcount == 5 ) |
| 746 | if (drmario_shiftcount == 5) |
| 582 | 747 | { |
| 583 | 748 | /* reset count */ |
| 584 | 749 | drmario_shiftcount = 0; |
| 585 | 750 | |
| 586 | 751 | /* apply data to registers */ |
| 587 | | switch( reg ) |
| 752 | switch (reg) |
| 588 | 753 | { |
| 589 | 754 | case 0: /* mirroring and options */ |
| 590 | 755 | { |
| r5325 | r5326 | |
| 594 | 759 | size16k = drmario_shiftreg & 0x08; |
| 595 | 760 | switchlow = drmario_shiftreg & 0x04; |
| 596 | 761 | |
| 597 | | switch( drmario_shiftreg & 3 ) |
| 762 | switch (drmario_shiftreg & 3) |
| 598 | 763 | { |
| 599 | 764 | case 0: |
| 600 | 765 | mirroring = PPU_MIRROR_LOW; |
| r5325 | r5326 | |
| 615 | 780 | } |
| 616 | 781 | |
| 617 | 782 | /* apply mirroring */ |
| 618 | | ppu2c0x_set_mirroring( ppu1, mirroring ); |
| 783 | v_set_mirroring(1, mirroring); |
| 619 | 784 | } |
| 620 | 785 | break; |
| 621 | 786 | |
| 622 | 787 | case 1: /* video rom banking - bank 0 - 4k or 8k */ |
| 623 | | ppu2c0x_set_videorom_bank( ppu1, 0, ( vrom4k ) ? 4 : 8, drmario_shiftreg, ( vrom4k ) ? 256 : 512 ); |
| 788 | v_set_videorom_bank(space->machine, 0, (vrom4k) ? 4 : 8, drmario_shiftreg, (vrom4k) ? 4 : 8); |
| 624 | 789 | break; |
| 625 | 790 | |
| 626 | 791 | case 2: /* video rom banking - bank 1 - 4k only */ |
| 627 | | if ( vrom4k ) |
| 628 | | ppu2c0x_set_videorom_bank( ppu1, 4, 4, drmario_shiftreg, 256 ); |
| 792 | if (vrom4k) |
| 793 | v_set_videorom_bank(space->machine, 4, 4, drmario_shiftreg, 4); |
| 629 | 794 | break; |
| 630 | 795 | |
| 631 | 796 | case 3: /* program banking */ |
| 632 | 797 | { |
| 633 | | int bank = ( drmario_shiftreg & 0x03 ) * 0x4000; |
| 634 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 798 | int bank = (drmario_shiftreg & 0x03) * 0x4000; |
| 799 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 635 | 800 | |
| 636 | | if ( !size16k ) |
| 801 | if (!size16k) |
| 637 | 802 | { |
| 638 | 803 | /* switch 32k */ |
| 639 | | memcpy( &prg[0x08000], &prg[0x010000+bank], 0x8000 ); |
| 804 | memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x8000); |
| 640 | 805 | } |
| 641 | 806 | else |
| 642 | 807 | { |
| 643 | 808 | /* switch 16k */ |
| 644 | | if ( switchlow ) |
| 809 | if (switchlow) |
| 645 | 810 | { |
| 646 | 811 | /* low */ |
| 647 | | memcpy( &prg[0x08000], &prg[0x010000+bank], 0x4000 ); |
| 812 | memcpy(&prg[0x08000], &prg[0x010000 + bank], 0x4000); |
| 648 | 813 | } |
| 649 | 814 | else |
| 650 | 815 | { |
| 651 | 816 | /* high */ |
| 652 | | memcpy( &prg[0x0c000], &prg[0x010000+bank], 0x4000 ); |
| 817 | memcpy(&prg[0x0c000], &prg[0x010000 + bank], 0x4000); |
| 653 | 818 | } |
| 654 | 819 | } |
| 655 | 820 | } |
| r5325 | r5326 | |
| 664 | 829 | { |
| 665 | 830 | /* We do manual banking, in case the code falls through */ |
| 666 | 831 | /* Copy the initial banks */ |
| 667 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 668 | | memcpy( &prg[0x08000], &prg[0x10000], 0x4000 ); |
| 669 | | memcpy( &prg[0x0c000], &prg[0x1c000], 0x4000 ); |
| 832 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 833 | memcpy(&prg[0x08000], &prg[0x10000], 0x4000); |
| 834 | memcpy(&prg[0x0c000], &prg[0x1c000], 0x4000); |
| 670 | 835 | |
| 671 | 836 | /* MMC1 mapper at writes to $8000-$ffff */ |
| 672 | 837 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, drmario_rom_banking ); |
| r5325 | r5326 | |
| 682 | 847 | } |
| 683 | 848 | |
| 684 | 849 | /***********************************************************************/ |
| 685 | | |
| 686 | 850 | /* Excite Bike */ |
| 687 | 851 | |
| 688 | 852 | DRIVER_INIT( excitebk ) |
| r5325 | r5326 | |
| 714 | 878 | } |
| 715 | 879 | |
| 716 | 880 | /**********************************************************************************/ |
| 717 | | |
| 718 | 881 | /* Mach Rider */ |
| 719 | 882 | |
| 720 | 883 | DRIVER_INIT( machridr ) |
| r5325 | r5326 | |
| 733 | 896 | } |
| 734 | 897 | |
| 735 | 898 | /**********************************************************************************/ |
| 736 | | |
| 737 | 899 | /* VS Slalom */ |
| 738 | 900 | |
| 739 | 901 | DRIVER_INIT( vsslalom ) |
| r5325 | r5326 | |
| 748 | 910 | } |
| 749 | 911 | |
| 750 | 912 | /**********************************************************************************/ |
| 751 | | |
| 752 | 913 | /* Castelvania: ROMs bankings at $8000-$ffff */ |
| 753 | 914 | |
| 754 | 915 | static WRITE8_HANDLER( castlevania_rom_banking ) |
| 755 | 916 | { |
| 756 | | int rombank = 0x10000 + ( data & 7 ) * 0x4000; |
| 757 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 917 | int rombank = 0x10000 + (data & 7) * 0x4000; |
| 918 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 758 | 919 | |
| 759 | | memcpy( &prg[0x08000], &prg[rombank], 0x4000 ); |
| 920 | memcpy(&prg[0x08000], &prg[rombank], 0x4000); |
| 760 | 921 | } |
| 761 | 922 | |
| 762 | 923 | DRIVER_INIT( cstlevna ) |
| 763 | 924 | { |
| 764 | 925 | /* when starting the game, the 1st 16k and the last 16k are loaded into the 2 banks */ |
| 765 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 766 | | memcpy( &prg[0x08000], &prg[0x28000], 0x8000 ); |
| 926 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 927 | memcpy(&prg[0x08000], &prg[0x28000], 0x8000); |
| 767 | 928 | |
| 768 | 929 | /* banking is done with writes to the $8000-$ffff area */ |
| 769 | 930 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, castlevania_rom_banking ); |
| r5325 | r5326 | |
| 775 | 936 | /* we need to remap color tables */ |
| 776 | 937 | /* this *is* the VS games protection, I guess */ |
| 777 | 938 | remapped_colortable = rp2c04002_colortable; |
| 939 | |
| 940 | /* allocate vram */ |
| 941 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 778 | 942 | } |
| 779 | 943 | |
| 780 | 944 | /**********************************************************************************/ |
| 781 | | |
| 782 | 945 | /* VS Top Gun: ROMs bankings at $8000-$ffff, plus some protection */ |
| 783 | 946 | |
| 784 | 947 | static READ8_HANDLER( topgun_security_r ) |
| 785 | 948 | { |
| 786 | 949 | /* low part must be 0x1b */ |
| 787 | | return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x1b; |
| 950 | return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x1b; |
| 788 | 951 | } |
| 789 | 952 | |
| 790 | 953 | DRIVER_INIT( topgun ) |
| 791 | 954 | { |
| 792 | 955 | /* when starting the game, the 1st 16k and the last 16k are loaded into the 2 banks */ |
| 793 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 794 | | memcpy( &prg[0x08000], &prg[0x28000], 0x8000 ); |
| 956 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 957 | memcpy(&prg[0x08000], &prg[0x28000], 0x8000); |
| 795 | 958 | |
| 796 | 959 | /* banking is done with writes to the $8000-$ffff area */ |
| 797 | 960 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, castlevania_rom_banking ); |
| r5325 | r5326 | |
| 802 | 965 | |
| 803 | 966 | /* common init */ |
| 804 | 967 | init_vsnes(machine); |
| 968 | |
| 969 | /* allocate vram */ |
| 970 | vram = auto_alloc_array(machine, UINT8, 0x2000); |
| 971 | |
| 805 | 972 | } |
| 806 | 973 | |
| 807 | 974 | /**********************************************************************************/ |
| r5325 | r5326 | |
| 813 | 980 | |
| 814 | 981 | static void mapper4_set_prg (const address_space *space) |
| 815 | 982 | { |
| 816 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 983 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 817 | 984 | MMC3_prg0 &= MMC3_prg_mask; |
| 818 | 985 | MMC3_prg1 &= MMC3_prg_mask; |
| 819 | 986 | |
| 820 | 987 | if (MMC3_cmd & 0x40) |
| 821 | 988 | { |
| 822 | | memcpy( &prg[0x8000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 ); |
| 823 | | memcpy( &prg[0xc000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000 ); |
| 989 | memcpy(&prg[0x8000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000); |
| 990 | memcpy(&prg[0xc000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000); |
| 824 | 991 | } |
| 825 | 992 | else |
| 826 | 993 | { |
| 827 | | memcpy( &prg[0x8000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000 ); |
| 828 | | memcpy( &prg[0xc000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 ); |
| 994 | memcpy(&prg[0x8000], &prg[0x2000 * (MMC3_prg0) + 0x10000], 0x2000); |
| 995 | memcpy(&prg[0xc000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000); |
| 829 | 996 | } |
| 830 | | memcpy( &prg[0xa000], &prg[0x2000 * (MMC3_prg1) + 0x10000], 0x2000 ); |
| 997 | memcpy(&prg[0xa000], &prg[0x2000 * (MMC3_prg1) + 0x10000], 0x2000); |
| 831 | 998 | } |
| 832 | 999 | |
| 833 | 1000 | static void mapper4_set_chr (const address_space *space) |
| 834 | 1001 | { |
| 835 | | const device_config *ppu1 = devtag_get_device(space->machine, "ppu1"); |
| 836 | 1002 | UINT8 chr_page = (MMC3_cmd & 0x80) >> 5; |
| 837 | | ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 0, 2, MMC3_chr[0], 1); |
| 838 | | ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 2, 2, MMC3_chr[1], 1); |
| 839 | | ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 4, 1, MMC3_chr[2], 1); |
| 840 | | ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 5, 1, MMC3_chr[3], 1); |
| 841 | | ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 6, 1, MMC3_chr[4], 1); |
| 842 | | ppu2c0x_set_videorom_bank(ppu1, chr_page ^ 7, 1, MMC3_chr[5], 1); |
| 1003 | v_set_videorom_bank(space->machine, chr_page ^ 0, 2, MMC3_chr[0], 1); |
| 1004 | v_set_videorom_bank(space->machine, chr_page ^ 2, 2, MMC3_chr[1], 1); |
| 1005 | v_set_videorom_bank(space->machine, chr_page ^ 4, 1, MMC3_chr[2], 1); |
| 1006 | v_set_videorom_bank(space->machine, chr_page ^ 5, 1, MMC3_chr[3], 1); |
| 1007 | v_set_videorom_bank(space->machine, chr_page ^ 6, 1, MMC3_chr[4], 1); |
| 1008 | v_set_videorom_bank(space->machine, chr_page ^ 7, 1, MMC3_chr[5], 1); |
| 843 | 1009 | } |
| 844 | 1010 | |
| 845 | 1011 | #define BOTTOM_VISIBLE_SCANLINE 239 /* The bottommost visible scanline */ |
| 846 | 1012 | #define NUM_SCANLINE 262 |
| 847 | 1013 | |
| 848 | | static void mapper4_irq ( const device_config *device, int scanline, int vblank, int blanked ) |
| 1014 | static void mapper4_irq( const device_config *device, int scanline, int vblank, int blanked ) |
| 849 | 1015 | { |
| 850 | | mame_printf_debug("entra\n"); |
| 851 | 1016 | if ((scanline < BOTTOM_VISIBLE_SCANLINE) || (scanline == NUM_SCANLINE - 1)) |
| 852 | 1017 | { |
| 853 | 1018 | if ((IRQ_enable) && !blanked) |
| r5325 | r5326 | |
| 875 | 1040 | if (last_bank != (data & 0xc0)) |
| 876 | 1041 | { |
| 877 | 1042 | /* Reset the banks */ |
| 878 | | mapper4_set_prg (space); |
| 879 | | mapper4_set_chr (space); |
| 1043 | mapper4_set_prg(space); |
| 1044 | mapper4_set_chr(space); |
| 880 | 1045 | |
| 881 | 1046 | } |
| 882 | 1047 | last_bank = data & 0xc0; |
| r5325 | r5326 | |
| 889 | 1054 | { |
| 890 | 1055 | case 0: case 1: |
| 891 | 1056 | data &= 0xfe; |
| 892 | | MMC3_chr[cmd] = data * 64; |
| 893 | | mapper4_set_chr (space); |
| 1057 | MMC3_chr[cmd] = data; |
| 1058 | mapper4_set_chr(space); |
| 894 | 1059 | |
| 895 | 1060 | break; |
| 896 | 1061 | |
| 897 | 1062 | case 2: case 3: case 4: case 5: |
| 898 | | MMC3_chr[cmd] = data * 64; |
| 899 | | mapper4_set_chr (space); |
| 1063 | MMC3_chr[cmd] = data; |
| 1064 | mapper4_set_chr(space); |
| 900 | 1065 | |
| 901 | 1066 | break; |
| 902 | 1067 | |
| 903 | 1068 | case 6: |
| 904 | 1069 | MMC3_prg0 = data; |
| 905 | | mapper4_set_prg (space); |
| 1070 | mapper4_set_prg(space); |
| 906 | 1071 | break; |
| 907 | 1072 | |
| 908 | 1073 | case 7: |
| 909 | 1074 | MMC3_prg1 = data; |
| 910 | | mapper4_set_prg (space); |
| 1075 | mapper4_set_prg(space); |
| 911 | 1076 | break; |
| 912 | 1077 | } |
| 913 | 1078 | break; |
| 914 | 1079 | } |
| 915 | 1080 | case 0x2000: /* $a000 */ |
| 916 | 1081 | if (data & 0x40) |
| 917 | | ppu2c0x_set_mirroring(ppu1, PPU_MIRROR_HIGH); |
| 1082 | v_set_mirroring(1, PPU_MIRROR_HIGH); |
| 918 | 1083 | else |
| 919 | 1084 | { |
| 920 | 1085 | if (data & 0x01) |
| 921 | | ppu2c0x_set_mirroring(ppu1, PPU_MIRROR_HORZ); |
| 1086 | v_set_mirroring(1, PPU_MIRROR_HORZ); |
| 922 | 1087 | else |
| 923 | | ppu2c0x_set_mirroring(ppu1, PPU_MIRROR_VERT); |
| 1088 | v_set_mirroring(1, PPU_MIRROR_VERT); |
| 924 | 1089 | } |
| 925 | 1090 | break; |
| 926 | 1091 | |
| r5325 | r5326 | |
| 963 | 1128 | |
| 964 | 1129 | DRIVER_INIT( MMC3 ) |
| 965 | 1130 | { |
| 966 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 1131 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 967 | 1132 | IRQ_enable = IRQ_count = IRQ_count_latch = 0; |
| 968 | 1133 | MMC3_prg0 = 0xfe; |
| 969 | 1134 | MMC3_prg1 = 0xff; |
| r5325 | r5326 | |
| 973 | 1138 | |
| 974 | 1139 | MMC3_prg_mask = ((MMC3_prg_chunks << 1) - 1); |
| 975 | 1140 | |
| 976 | | memcpy( &prg[0x8000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 ); |
| 977 | | memcpy( &prg[0xa000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x12000], 0x2000 ); |
| 978 | | memcpy( &prg[0xc000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x10000], 0x2000 ); |
| 979 | | memcpy( &prg[0xe000], &prg[(MMC3_prg_chunks-1) * 0x4000 + 0x12000], 0x2000 ); |
| 1141 | memcpy(&prg[0x8000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000); |
| 1142 | memcpy(&prg[0xa000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x12000], 0x2000); |
| 1143 | memcpy(&prg[0xc000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x10000], 0x2000); |
| 1144 | memcpy(&prg[0xe000], &prg[(MMC3_prg_chunks - 1) * 0x4000 + 0x12000], 0x2000); |
| 980 | 1145 | |
| 981 | 1146 | /* MMC3 mapper at writes to $8000-$ffff */ |
| 982 | 1147 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, mapper4_w ); |
| r5325 | r5326 | |
| 991 | 1156 | |
| 992 | 1157 | /* Vs. RBI Baseball */ |
| 993 | 1158 | |
| 994 | | static READ8_HANDLER( rbi_hack_r) |
| 1159 | static READ8_HANDLER( rbi_hack_r ) |
| 995 | 1160 | { |
| 996 | 1161 | /* Supplied by Ben Parnell <xodnizel@home.com> of FCE Ultra fame */ |
| 997 | 1162 | |
| r5325 | r5326 | |
| 1040 | 1205 | |
| 1041 | 1206 | static READ8_HANDLER( supxevs_read_prot_2_r ) |
| 1042 | 1207 | { |
| 1043 | | if( supxevs_prot_index ) |
| 1208 | if (supxevs_prot_index) |
| 1044 | 1209 | return 0; |
| 1045 | 1210 | else |
| 1046 | 1211 | return 0x01; |
| r5325 | r5326 | |
| 1048 | 1213 | |
| 1049 | 1214 | static READ8_HANDLER( supxevs_read_prot_3_r ) |
| 1050 | 1215 | { |
| 1051 | | if( supxevs_prot_index ) |
| 1216 | if (supxevs_prot_index) |
| 1052 | 1217 | return 0xd1; |
| 1053 | 1218 | else |
| 1054 | 1219 | return 0x89; |
| r5325 | r5326 | |
| 1056 | 1221 | |
| 1057 | 1222 | static READ8_HANDLER( supxevs_read_prot_4_r ) |
| 1058 | 1223 | { |
| 1059 | | if( supxevs_prot_index ) |
| 1224 | if (supxevs_prot_index) |
| 1060 | 1225 | { |
| 1061 | 1226 | supxevs_prot_index = 0; |
| 1062 | 1227 | return 0x3e; |
| r5325 | r5326 | |
| 1094 | 1259 | 0xd4, 0x5c, 0x3e, 0x26, 0x87, 0x83, 0x13, 0x00 |
| 1095 | 1260 | }; |
| 1096 | 1261 | |
| 1097 | | if ( offset == 0 ) |
| 1262 | if (offset == 0) |
| 1098 | 1263 | { |
| 1099 | 1264 | security_counter = 0; |
| 1100 | 1265 | return 0; |
| r5325 | r5326 | |
| 1136 | 1301 | |
| 1137 | 1302 | static WRITE8_HANDLER( mapper68_rom_banking ) |
| 1138 | 1303 | { |
| 1139 | | const device_config *ppu1 = devtag_get_device(space->machine, "ppu1"); |
| 1140 | | |
| 1141 | 1304 | switch (offset & 0x7000) |
| 1142 | 1305 | { |
| 1143 | 1306 | case 0x0000: |
| 1144 | | ppu2c0x_set_videorom_bank(ppu1,0,2,data,128); |
| 1307 | v_set_videorom_bank(space->machine, 0, 2, data, 2); |
| 1145 | 1308 | |
| 1146 | 1309 | break; |
| 1147 | 1310 | case 0x1000: |
| 1148 | | ppu2c0x_set_videorom_bank(ppu1,2,2,data,128); |
| 1311 | v_set_videorom_bank(space->machine, 2, 2, data, 2); |
| 1149 | 1312 | |
| 1150 | 1313 | break; |
| 1151 | 1314 | case 0x2000: |
| 1152 | | ppu2c0x_set_videorom_bank(ppu1,4,2,data,128); |
| 1315 | v_set_videorom_bank(space->machine, 4, 2, data, 2); |
| 1153 | 1316 | |
| 1154 | 1317 | break; |
| 1155 | 1318 | case 0x3000: /* ok? */ |
| 1156 | | ppu2c0x_set_videorom_bank(ppu1,6,2,data,128); |
| 1319 | v_set_videorom_bank(space->machine, 6, 2, data, 2); |
| 1157 | 1320 | |
| 1158 | 1321 | break; |
| 1159 | 1322 | |
| 1160 | 1323 | case 0x7000: |
| 1161 | 1324 | { |
| 1162 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 1163 | | memcpy( &prg[0x08000], &prg[0x10000 +data*0x4000], 0x4000 ); |
| 1325 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 1326 | memcpy(&prg[0x08000], &prg[0x10000 + data * 0x4000], 0x4000); |
| 1164 | 1327 | } |
| 1165 | 1328 | break; |
| 1166 | 1329 | |
| r5325 | r5326 | |
| 1174 | 1337 | /* when starting a mapper 68 game the first 16K ROM bank in the cart is loaded into $8000 |
| 1175 | 1338 | the LAST 16K ROM bank is loaded into $C000. The last 16K of ROM cannot be swapped. */ |
| 1176 | 1339 | |
| 1177 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 1178 | | memcpy( &prg[0x08000], &prg[0x10000], 0x4000 ); |
| 1179 | | memcpy( &prg[0x0c000], &prg[0x2c000], 0x4000 ); |
| 1340 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 1341 | memcpy(&prg[0x08000], &prg[0x10000], 0x4000); |
| 1342 | memcpy(&prg[0x0c000], &prg[0x2c000], 0x4000); |
| 1180 | 1343 | |
| 1181 | 1344 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x8000, 0xffff, 0, 0, mapper68_rom_banking ); |
| 1182 | 1345 | |
| r5325 | r5326 | |
| 1190 | 1353 | /* Vs. Raid on Bungeling Bay (Japan) */ |
| 1191 | 1354 | |
| 1192 | 1355 | static int ret; |
| 1193 | | static WRITE8_HANDLER ( set_bnglngby_irq_w ) |
| 1356 | static WRITE8_HANDLER( set_bnglngby_irq_w ) |
| 1194 | 1357 | { |
| 1195 | 1358 | ret = data; |
| 1196 | | cputag_set_input_line(space->machine, "maincpu", 0, ( data & 2 ) ? ASSERT_LINE : CLEAR_LINE ); |
| 1359 | cputag_set_input_line(space->machine, "maincpu", 0, (data & 2) ? ASSERT_LINE : CLEAR_LINE); |
| 1197 | 1360 | /* other values ??? */ |
| 1198 | 1361 | /* 0, 4, 84 */ |
| 1199 | 1362 | } |
| 1200 | 1363 | |
| 1201 | | static READ8_HANDLER ( set_bnglngby_irq_r ) |
| 1364 | static READ8_HANDLER( set_bnglngby_irq_r ) |
| 1202 | 1365 | { |
| 1203 | 1366 | return ret; |
| 1204 | 1367 | } |
| r5325 | r5326 | |
| 1228 | 1391 | static READ8_HANDLER( jajamaru_security_r ) |
| 1229 | 1392 | { |
| 1230 | 1393 | /* low part must be 0x40 */ |
| 1231 | | return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x40; |
| 1394 | return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x40; |
| 1232 | 1395 | } |
| 1233 | 1396 | |
| 1234 | 1397 | DRIVER_INIT( jajamaru ) |
| 1235 | 1398 | { |
| 1236 | | //It executes an illegal opcode: 0x04 at 0x9e67 and 0x9e1c |
| 1237 | | //At 0x9e5d and 0x9e12 there is a conditional jump to it |
| 1238 | | //Maybe it should be a DOP (double NOP) |
| 1399 | // It executes an illegal opcode: 0x04 at 0x9e67 and 0x9e1c |
| 1400 | // At 0x9e5d and 0x9e12 there is a conditional jump to it |
| 1401 | // Maybe it should be a DOP (double NOP) |
| 1239 | 1402 | |
| 1240 | 1403 | /* Protection */ |
| 1241 | 1404 | memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x2002, 0x2002, 0, 0, jajamaru_security_r ); |
| r5325 | r5326 | |
| 1249 | 1412 | } |
| 1250 | 1413 | |
| 1251 | 1414 | /***********************************************************************/ |
| 1252 | | |
| 1253 | 1415 | /* Vs. Mighty Bomb Jack */ |
| 1254 | 1416 | |
| 1255 | 1417 | static READ8_HANDLER( mightybj_security_r ) |
| 1256 | 1418 | { |
| 1257 | 1419 | /* low part must be 0x3d */ |
| 1258 | | return ppu2c0x_r( devtag_get_device(space->machine, "ppu1"), 2 ) | 0x3d; |
| 1420 | return ppu2c0x_r(devtag_get_device(space->machine, "ppu1"), 2) | 0x3d; |
| 1259 | 1421 | } |
| 1260 | 1422 | |
| 1261 | 1423 | DRIVER_INIT( mightybj ) |
| r5325 | r5326 | |
| 1274 | 1436 | static WRITE8_HANDLER( vstennis_vrom_banking ) |
| 1275 | 1437 | { |
| 1276 | 1438 | const device_config *other_cpu = (space->cpu == cputag_get_cpu(space->machine, "maincpu")) ? cputag_get_cpu(space->machine, "sub") : cputag_get_cpu(space->machine, "maincpu"); |
| 1277 | | const device_config *ppu1 = devtag_get_device(space->machine, "ppu1"); |
| 1278 | | const device_config *ppu2 = devtag_get_device(space->machine, "ppu2"); |
| 1279 | 1439 | |
| 1280 | 1440 | /* switch vrom */ |
| 1281 | | ppu2c0x_set_videorom_bank( (space->cpu == cputag_get_cpu(space->machine, "maincpu")) ? ppu1 : ppu2, 0, 8, ( data & 4 ) ? 1 : 0, 512 ); |
| 1441 | (space->cpu == cputag_get_cpu(space->machine, "maincpu")) ? memory_set_bankptr(space->machine, 2, (data & 4) ? vrom[0] + 0x2000 : vrom[0]) : memory_set_bankptr(space->machine, 3, (data & 4) ? vrom[1] + 0x2000 : vrom[1]); |
| 1282 | 1442 | |
| 1283 | 1443 | /* bit 1 ( data & 2 ) triggers irq on the other cpu */ |
| 1284 | | cpu_set_input_line(other_cpu, 0, ( data & 2 ) ? CLEAR_LINE : ASSERT_LINE ); |
| 1444 | cpu_set_input_line(other_cpu, 0, (data & 2) ? CLEAR_LINE : ASSERT_LINE); |
| 1285 | 1445 | |
| 1286 | 1446 | /* move along */ |
| 1287 | 1447 | if (space->cpu == cputag_get_cpu(space->machine, "maincpu")) |
| 1288 | | vsnes_in0_w( space, offset, data ); |
| 1448 | vsnes_in0_w(space, offset, data); |
| 1289 | 1449 | else |
| 1290 | | vsnes_in0_1_w( space, offset, data ); |
| 1450 | vsnes_in0_1_w(space, offset, data); |
| 1291 | 1451 | } |
| 1292 | 1452 | |
| 1293 | 1453 | DRIVER_INIT( vstennis ) |
| 1294 | 1454 | { |
| 1295 | | UINT8 *prg = memory_region( machine, "maincpu" ); |
| 1455 | UINT8 *prg = memory_region(machine, "maincpu"); |
| 1296 | 1456 | |
| 1297 | 1457 | /* vrom switching is enabled with bit 2 of $4016 */ |
| 1298 | 1458 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4016, 0x4016, 0, 0, vstennis_vrom_banking ); |
| r5325 | r5326 | |
| 1311 | 1471 | DRIVER_INIT( wrecking ) |
| 1312 | 1472 | { |
| 1313 | 1473 | /* only differance between this and vstennis is the colors */ |
| 1314 | | |
| 1315 | 1474 | DRIVER_INIT_CALL(vstennis); |
| 1316 | 1475 | remapped_colortable = rp2c04002_colortable; |
| 1317 | 1476 | } |
| r5325 | r5326 | |
| 1322 | 1481 | DRIVER_INIT( balonfgt ) |
| 1323 | 1482 | { |
| 1324 | 1483 | /* only differance between this and vstennis is the colors */ |
| 1325 | | |
| 1326 | 1484 | DRIVER_INIT_CALL(vstennis); |
| 1327 | 1485 | |
| 1328 | 1486 | remapped_colortable = rp2c04003_colortable; |
| r5325 | r5326 | |
| 1335 | 1493 | DRIVER_INIT( vsbball ) |
| 1336 | 1494 | { |
| 1337 | 1495 | /* only differance between this and vstennis is the colors */ |
| 1338 | | |
| 1339 | 1496 | DRIVER_INIT_CALL(vstennis); |
| 1340 | 1497 | |
| 1341 | 1498 | remapped_colortable = rp2c04001_colortable; |
| 1342 | | |
| 1343 | 1499 | } |
| 1344 | 1500 | |
| 1345 | 1501 | |
| r5325 | r5326 | |
| 1349 | 1505 | DRIVER_INIT( iceclmrj ) |
| 1350 | 1506 | { |
| 1351 | 1507 | /* only differance between this and vstennis is the colors */ |
| 1352 | | |
| 1353 | 1508 | DRIVER_INIT_CALL(vstennis); |
| 1354 | 1509 | |
| 1355 | 1510 | remapped_colortable = rp2c05004_colortable; |
| 1356 | | |
| 1357 | 1511 | } |
| 1358 | 1512 | |
| 1359 | 1513 | /**********************************************************************/ |
| 1360 | 1514 | /* Battle City */ |
| 1515 | |
| 1361 | 1516 | DRIVER_INIT( btlecity ) |
| 1362 | 1517 | { |
| 1363 | 1518 | init_vsnes(machine); |
| r5325 | r5326 | |
| 1367 | 1522 | |
| 1368 | 1523 | /***********************************************************************/ |
| 1369 | 1524 | /* Tetris */ |
| 1525 | |
| 1370 | 1526 | DRIVER_INIT( vstetris ) |
| 1371 | 1527 | { |
| 1372 | 1528 | /* extra ram at $6000 is enabled with bit 1 of $4016 */ |
src/mame/video/ppu2c0x.c
| r5325 | r5326 | |
| 5 | 5 | Written by Ernesto Corvi. |
| 6 | 6 | This code is heavily based on Brad Oliver's MESS implementation. |
| 7 | 7 | |
| 8 | | ******************************************************************************/ |
| 8 | 2009-04: Changed NES PPU to be a device (Nathan Woods) |
| 9 | 2009-07: Changed NES PPU to use a device memory map (Robert Bohms) |
| 9 | 10 | |
| 10 | | /****************************************************************************** |
| 11 | Current known bugs |
| 11 | 12 | |
| 12 | | Current known bugs |
| 13 | General: |
| 13 | 14 | |
| 14 | | General: |
| 15 | * PPU timing is imprecise for updates that happen mid-scanline. Some games |
| 16 | may demand more precision. |
| 15 | 17 | |
| 16 | | * PPU timing is imprecise for updates that happen mid-scanline. Some games |
| 17 | | may demand more precision. |
| 18 | NES-specific: |
| 18 | 19 | |
| 19 | | NES-specific: |
| 20 | * Micro Machines has minor rendering glitches (needs better timing). |
| 21 | * Mach Rider has minor road rendering glitches (needs better timing). |
| 20 | 22 | |
| 21 | | * Micro Machines has minor rendering glitches (needs better timing). |
| 22 | | |
| 23 | | * Mach Rider has minor road rendering glitches (needs better timing). |
| 24 | | |
| 25 | 23 | ******************************************************************************/ |
| 26 | 24 | |
| 27 | 25 | #include "driver.h" |
| r5325 | r5326 | |
| 125 | 123 | PROTOTYPES |
| 126 | 124 | ***************************************************************************/ |
| 127 | 125 | |
| 128 | | static void update_scanline(const device_config *device); |
| 126 | static void update_scanline( const device_config *device ); |
| 129 | 127 | |
| 130 | 128 | static TIMER_CALLBACK( scanline_callback ); |
| 131 | 129 | static TIMER_CALLBACK( hblank_callback ); |
| r5325 | r5326 | |
| 134 | 132 | void (*ppu_latch)( const device_config *device, offs_t offset ); |
| 135 | 133 | |
| 136 | 134 | /* palette handlers */ |
| 137 | | WRITE8_HANDLER(ppu2c0x_palette_write); |
| 138 | | READ8_HANDLER(ppu2c0x_palette_read); |
| 135 | WRITE8_HANDLER( ppu2c0x_palette_write ); |
| 136 | READ8_HANDLER( ppu2c0x_palette_read ); |
| 139 | 137 | /* name and attribute table functions */ |
| 140 | | WRITE8_HANDLER(ppu2c0x_name_write); |
| 141 | | READ8_HANDLER(ppu2c0x_name_read); |
| 138 | WRITE8_HANDLER( ppu2c0x_name_write ); |
| 139 | READ8_HANDLER( ppu2c0x_name_read ); |
| 142 | 140 | /* name and attribute table functions */ |
| 143 | | WRITE8_HANDLER(ppu2c0x_chr_write); |
| 144 | | READ8_HANDLER(ppu2c0x_chr_read); |
| 141 | WRITE8_HANDLER( ppu2c0x_chr_write ); |
| 142 | READ8_HANDLER( ppu2c0x_chr_read ); |
| 145 | 143 | |
| 146 | 144 | |
| 147 | 145 | /*************************************************************************** |
| 148 | 146 | INLINE FUNCTIONS |
| 149 | 147 | ***************************************************************************/ |
| 150 | 148 | |
| 151 | | INLINE ppu2c0x_chip *get_token(const device_config *device) |
| 149 | INLINE ppu2c0x_chip *get_token( const device_config *device ) |
| 152 | 150 | { |
| 153 | 151 | assert(device != NULL); |
| 154 | 152 | assert((device->type == PPU_2C02) || (device->type == PPU_2C03B) |
| r5325 | r5326 | |
| 158 | 156 | } |
| 159 | 157 | |
| 160 | 158 | |
| 161 | | INLINE const ppu2c0x_interface *get_interface(const device_config *device) |
| 159 | INLINE const ppu2c0x_interface *get_interface( const device_config *device ) |
| 162 | 160 | { |
| 163 | 161 | assert(device != NULL); |
| 164 | 162 | assert((device->type == PPU_2C02) || (device->type == PPU_2C03B) |
| r5325 | r5326 | |
| 181 | 179 | /* default address map */ |
| 182 | 180 | // make this INTERNAL, default should just be enough to avoid compile errors, print error messages! |
| 183 | 181 | static ADDRESS_MAP_START( ppu2c0x, 0, 8 ) |
| 184 | | AM_RANGE(0x3F00, 0x3fff) AM_READWRITE (ppu2c0x_palette_read, ppu2c0x_palette_write) |
| 182 | AM_RANGE(0x3f00, 0x3fff) AM_READWRITE (ppu2c0x_palette_read, ppu2c0x_palette_write) |
| 185 | 183 | ADDRESS_MAP_END |
| 186 | 184 | |
| 187 | | void ppu2c0x_init_palette(running_machine *machine, int first_entry ) |
| 185 | void ppu2c0x_init_palette( running_machine *machine, int first_entry ) |
| 188 | 186 | { |
| 189 | 187 | |
| 190 | 188 | /* This routine builds a palette using a transformation from */ |
| r5325 | r5326 | |
| 268 | 266 | break; |
| 269 | 267 | } |
| 270 | 268 | |
| 271 | | u = sat * cos( rad ); |
| 272 | | v = sat * sin( rad ); |
| 269 | u = sat * cos(rad); |
| 270 | v = sat * sin(rad); |
| 273 | 271 | |
| 274 | 272 | /* Transform to RGB */ |
| 275 | | R = ( y + Kv * v ) * 255.0; |
| 276 | | G = ( y - ( Kb * Ku * u + Kr * Kv * v) / (1 - Kb - Kr) ) * 255.0; |
| 277 | | B = ( y + Ku * u ) * 255.0; |
| 273 | R = (y + Kv * v) * 255.0; |
| 274 | G = (y - (Kb * Ku * u + Kr * Kv * v) / (1 - Kb - Kr)) * 255.0; |
| 275 | B = (y + Ku * u) * 255.0; |
| 278 | 276 | |
| 279 | 277 | /* Clipping, in case of saturation */ |
| 280 | | if ( R < 0 ) |
| 278 | if (R < 0) |
| 281 | 279 | R = 0; |
| 282 | | if ( R > 255 ) |
| 280 | if (R > 255) |
| 283 | 281 | R = 255; |
| 284 | | if ( G < 0 ) |
| 282 | if (G < 0) |
| 285 | 283 | G = 0; |
| 286 | | if ( G > 255 ) |
| 284 | if (G > 255) |
| 287 | 285 | G = 255; |
| 288 | | if ( B < 0 ) |
| 286 | if (B < 0) |
| 289 | 287 | B = 0; |
| 290 | | if ( B > 255 ) |
| 288 | if (B > 255) |
| 291 | 289 | B = 255; |
| 292 | 290 | |
| 293 | 291 | /* Round, and set the value */ |
| 294 | | palette_set_color_rgb(machine, first_entry++, floor(R+.5), floor(G+.5), floor(B+.5)); |
| 292 | palette_set_color_rgb(machine, first_entry++, floor(R + .5), floor(G + .5), floor(B + .5)); |
| 295 | 293 | } |
| 296 | 294 | } |
| 297 | 295 | } |
| r5325 | r5326 | |
| 302 | 300 | /* the charlayout we use for the chargen */ |
| 303 | 301 | static const gfx_layout ppu_charlayout = |
| 304 | 302 | { |
| 305 | | 8,8, /* 8*8 characters */ |
| 303 | 8, 8, /* 8*8 characters */ |
| 306 | 304 | 0, |
| 307 | 305 | 2, /* 2 bits per pixel */ |
| 308 | 306 | { 8*8, 0 }, /* the two bitplanes are separated */ |
| r5325 | r5326 | |
| 320 | 318 | static DEVICE_START( ppu2c0x ) |
| 321 | 319 | { |
| 322 | 320 | ppu2c0x_chip *chip = get_token(device); |
| 323 | | //const ppu2c0x_interface *intf = get_interface(device); |
| 321 | // const ppu2c0x_interface *intf = get_interface(device); |
| 324 | 322 | |
| 325 | 323 | memset(chip, 0, sizeof(*chip)); |
| 326 | 324 | chip->scanlines_per_frame = (int) device_get_info_int(device, PPU2C0XINFO_INT_SCANLINES_PER_FRAME); |
| r5325 | r5326 | |
| 334 | 332 | |
| 335 | 333 | /* allocate a screen bitmap, videomem and spriteram, a dirtychar array and the monochromatic colortable */ |
| 336 | 334 | chip->bitmap = auto_bitmap_alloc(device->machine, VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT, video_screen_get_format(device->machine->primary_screen)); |
| 337 | | chip->spriteram = auto_alloc_array_clear(device->machine, UINT8, SPRITERAM_SIZE ); |
| 338 | | chip->colortable = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH( default_colortable ) ); |
| 339 | | chip->colortable_mono = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH( default_colortable_mono ) ); |
| 335 | chip->spriteram = auto_alloc_array_clear(device->machine, UINT8, SPRITERAM_SIZE); |
| 336 | chip->colortable = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH(default_colortable)); |
| 337 | chip->colortable_mono = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH(default_colortable_mono)); |
| 340 | 338 | } |
| 341 | 339 | |
| 342 | 340 | static TIMER_CALLBACK( hblank_callback ) |
| r5325 | r5326 | |
| 345 | 343 | ppu2c0x_chip *this_ppu = get_token(device); |
| 346 | 344 | int *ppu_regs = &this_ppu->regs[0]; |
| 347 | 345 | |
| 348 | | int blanked = ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) ) == 0; |
| 349 | | int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE-1) && (this_ppu->scanline < this_ppu->scanlines_per_frame-1)) ? 1 : 0; |
| 346 | int blanked = (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0; |
| 347 | int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (this_ppu->scanline < this_ppu->scanlines_per_frame - 1)) ? 1 : 0; |
| 350 | 348 | |
| 351 | | // update_scanline (device); |
| 349 | // update_scanline(device); |
| 352 | 350 | |
| 353 | 351 | if (this_ppu->hblank_callback_proc) |
| 354 | 352 | (*this_ppu->hblank_callback_proc) (device, this_ppu->scanline, vblank, blanked); |
| r5325 | r5326 | |
| 370 | 368 | timer_adjust_oneshot(this_ppu->nmi_timer, attotime_never, 0); |
| 371 | 369 | } |
| 372 | 370 | |
| 373 | | static void draw_background(const device_config *device, UINT8 *line_priority ) |
| 371 | static void draw_background( const device_config *device, UINT8 *line_priority ) |
| 374 | 372 | { |
| 375 | 373 | const ppu2c0x_interface *intf = get_interface(device); |
| 376 | 374 | ppu2c0x_chip *this_ppu = get_token(device); |
| r5325 | r5326 | |
| 383 | 381 | const int *nes_vram = &this_ppu->nes_vram[0]; |
| 384 | 382 | const int tile_page = this_ppu->tile_page; |
| 385 | 383 | |
| 386 | | int start_x = ( this_ppu->x_fine ^ 0x07 ) - 7; |
| 384 | int start_x = (this_ppu->x_fine ^ 0x07) - 7; |
| 387 | 385 | UINT16 back_pen; |
| 388 | 386 | UINT16 *dest; |
| 389 | 387 | |
| r5325 | r5326 | |
| 392 | 390 | |
| 393 | 391 | const pen_t *color_table; |
| 394 | 392 | const pen_t *paldata; |
| 395 | | //const UINT8 *sd; |
| 393 | // const UINT8 *sd; |
| 396 | 394 | |
| 397 | | int tilecount=0; |
| 395 | int tilecount = 0; |
| 398 | 396 | |
| 399 | 397 | /* setup the color mask and colortable to use */ |
| 400 | | if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO ) |
| 398 | if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO) |
| 401 | 399 | { |
| 402 | 400 | color_mask = 0xf0; |
| 403 | 401 | color_table = this_ppu->colortable_mono; |
| r5325 | r5326 | |
| 409 | 407 | } |
| 410 | 408 | |
| 411 | 409 | /* cache the background pen */ |
| 412 | | back_pen = (this_ppu->back_color & color_mask)+intf->color_base; |
| 410 | back_pen = (this_ppu->back_color & color_mask) + intf->color_base; |
| 413 | 411 | |
| 414 | 412 | /* determine where in the nametable to start drawing from */ |
| 415 | 413 | /* based on the current scanline and scroll regs */ |
| 416 | 414 | scroll_x_coarse = refresh_data & 0x1f; |
| 417 | | scroll_y_coarse = ( refresh_data & 0x3e0 ) >> 5; |
| 418 | | scroll_y_fine = ( refresh_data & 0x7000 ) >> 12; |
| 415 | scroll_y_coarse = (refresh_data & 0x3e0) >> 5; |
| 416 | scroll_y_fine = (refresh_data & 0x7000) >> 12; |
| 419 | 417 | |
| 420 | 418 | x = scroll_x_coarse; |
| 421 | 419 | |
| 422 | 420 | /* get the tile index */ |
| 423 | | tile_index = ( ( refresh_data & 0xc00 ) | 0x2000 ) + scroll_y_coarse * 32; |
| 421 | tile_index = ((refresh_data & 0xc00) | 0x2000) + scroll_y_coarse * 32; |
| 424 | 422 | |
| 425 | 423 | /* set up dest */ |
| 426 | 424 | dest = ((UINT16 *) bitmap->base) + (bitmap->rowpixels * scanline) + start_x; |
| 427 | 425 | |
| 428 | 426 | /* draw the 32 or 33 tiles that make up a line */ |
| 429 | | while ( tilecount <34) |
| 427 | while (tilecount < 34) |
| 430 | 428 | { |
| 431 | 429 | int color_byte; |
| 432 | 430 | int color_bits; |
| r5325 | r5326 | |
| 439 | 437 | index1 = tile_index + x; |
| 440 | 438 | |
| 441 | 439 | |
| 442 | | //this is attribute table stuff! (actually read 2 in PPUspeak)! |
| 440 | // this is attribute table stuff! (actually read 2 in PPUspeak)! |
| 443 | 441 | /* Figure out which byte in the color table to use */ |
| 444 | | pos = ( ( index1 & 0x380 ) >> 4 ) | ( ( index1 & 0x1f ) >> 2 ); |
| 442 | pos = ((index1 & 0x380) >> 4) | ((index1 & 0x1f) >> 2); |
| 445 | 443 | page = (index1 & 0x0c00) >> 10; |
| 446 | 444 | address = 0x3c0 + pos; |
| 447 | | color_byte = memory_read_byte(device->space[0], (((page*0x400)+address)&0xfff)+0x2000); |
| 445 | color_byte = memory_read_byte(device->space[0], (((page * 0x400) + address) & 0xfff) + 0x2000); |
| 448 | 446 | |
| 449 | 447 | /* figure out which bits in the color table to use */ |
| 450 | | color_bits = ( ( index1 & 0x40 ) >> 4 ) + ( index1 & 0x02 ); |
| 448 | color_bits = ((index1 & 0x40) >> 4) + (index1 & 0x02); |
| 451 | 449 | |
| 452 | | //page2 is the output of the nametable read (this section is the FIRST read per tile!) |
| 450 | // page2 is the output of the nametable read (this section is the FIRST read per tile!) |
| 453 | 451 | address = index1 & 0x3ff; |
| 454 | 452 | page2 = memory_read_byte(device->space[0], index1); |
| 455 | | index2 = nes_vram[ ( page2 >> 6 ) | tile_page ] + ( page2 & 0x3f ); |
| 453 | index2 = nes_vram[(page2 >> 6) | tile_page] + (page2 & 0x3f); |
| 456 | 454 | |
| 457 | | //27/12/2002 |
| 458 | | if( ppu_latch ) |
| 455 | // 27/12/2002 |
| 456 | if (ppu_latch) |
| 459 | 457 | { |
| 460 | | (*ppu_latch)(device, ( tile_page << 10 ) | ( page2 << 4 )); |
| 458 | (*ppu_latch)(device, (tile_page << 10) | (page2 << 4)); |
| 461 | 459 | } |
| 462 | 460 | |
| 463 | | if(start_x < VISIBLE_SCREEN_WIDTH ) |
| 461 | if (start_x < VISIBLE_SCREEN_WIDTH) |
| 464 | 462 | { |
| 465 | | UINT8 plane1, plane2;//use extended size so I can shift! |
| 466 | | paldata = &color_table[ 4 * ( ( ( color_byte >> color_bits ) & 0x03 ) ) ]; |
| 467 | | //start = scroll_y_fine * line_modulo; |
| 463 | UINT8 plane1, plane2; // use extended size so I can shift! |
| 464 | paldata = &color_table[4 * (((color_byte >> color_bits) & 0x03))]; |
| 465 | // start = scroll_y_fine * line_modulo; |
| 468 | 466 | |
| 469 | | //need to read 0x0000 or 0x1000 + 16*nametable data |
| 470 | | address=((this_ppu->tile_page)?0x1000:0)+(page2*16); |
| 471 | | //plus something that accounts for y |
| 472 | | //address-=(scanline%8); |
| 473 | | address+=scroll_y_fine; |
| 467 | // need to read 0x0000 or 0x1000 + 16*nametable data |
| 468 | address = ((this_ppu->tile_page) ? 0x1000 : 0) + (page2 * 16); |
| 469 | // plus something that accounts for y |
| 470 | // address -= (scanline % 8); |
| 471 | address += scroll_y_fine; |
| 474 | 472 | |
| 475 | | plane1= memory_read_byte(device->space[0], (address&0x1FFF)); |
| 476 | | plane2= memory_read_byte(device->space[0], (address+8)&0x1FFF); |
| 477 | | //plane2= plane2<<1; |
| 473 | plane1 = memory_read_byte(device->space[0], (address & 0x1fff)); |
| 474 | plane2 = memory_read_byte(device->space[0], (address + 8) & 0x1fff); |
| 475 | // plane2 = plane2 << 1; |
| 478 | 476 | |
| 479 | | // sd = gfx_element_get_data(device->machine->gfx[gfx_bank], index2 % total_elements) + start; |
| 477 | // sd = gfx_element_get_data(device->machine->gfx[gfx_bank], index2 % total_elements) + start; |
| 480 | 478 | |
| 481 | 479 | /* render the pixel */ |
| 482 | | for( i = 0; i < 8; i++ ) |
| 480 | for (i = 0; i < 8; i++) |
| 483 | 481 | { |
| 484 | 482 | UINT8 pix; |
| 485 | | pix=((plane1>>7)&1)|(((plane2>>7)&1)<<1); |
| 486 | | plane1=plane1<<1; |
| 487 | | plane2=plane2<<1; |
| 488 | | if ( ( start_x+i ) >= 0 && ( start_x+i ) < VISIBLE_SCREEN_WIDTH ) |
| 483 | pix = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1); |
| 484 | plane1 = plane1 << 1; |
| 485 | plane2 = plane2 << 1; |
| 486 | if ((start_x + i) >= 0 && (start_x + i) < VISIBLE_SCREEN_WIDTH) |
| 489 | 487 | { |
| 490 | 488 | |
| 491 | | if ( pix ) |
| 489 | if (pix) |
| 492 | 490 | { |
| 493 | 491 | pen = paldata[pix]; |
| 494 | | line_priority[ start_x+i ] |= 0x02; |
| 492 | line_priority[start_x + i] |= 0x02; |
| 495 | 493 | } |
| 496 | 494 | else |
| 497 | 495 | { |
| r5325 | r5326 | |
| 506 | 504 | |
| 507 | 505 | /* move to next tile over and toggle the horizontal name table if necessary */ |
| 508 | 506 | x++; |
| 509 | | if ( x > 31 ) |
| 507 | if (x > 31) |
| 510 | 508 | { |
| 511 | 509 | x = 0; |
| 512 | 510 | tile_index ^= 0x400; |
| r5325 | r5326 | |
| 516 | 514 | } |
| 517 | 515 | |
| 518 | 516 | /* if the left 8 pixels for the background are off, blank 'em */ |
| 519 | | if ( !( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8 ) ) |
| 517 | if (!(ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8)) |
| 520 | 518 | { |
| 521 | 519 | dest = ((UINT16 *) bitmap->base) + (bitmap->rowpixels * scanline); |
| 522 | | for( i = 0; i < 8; i++ ) |
| 520 | for (i = 0; i < 8; i++) |
| 523 | 521 | { |
| 524 | 522 | *(dest++) = back_pen; |
| 525 | | line_priority[ i ] ^= 0x02; |
| 523 | line_priority[i] ^= 0x02; |
| 526 | 524 | } |
| 527 | 525 | } |
| 528 | 526 | } |
| 529 | 527 | |
| 530 | | static void draw_sprites(const device_config *device, UINT8 *line_priority ) |
| 528 | static void draw_sprites( const device_config *device, UINT8 *line_priority ) |
| 531 | 529 | { |
| 532 | | //const ppu2c0x_interface *intf = get_interface(device); |
| 530 | // const ppu2c0x_interface *intf = get_interface(device); |
| 533 | 531 | ppu2c0x_chip *this_ppu = get_token(device); |
| 534 | 532 | |
| 535 | 533 | /* cache some values locally */ |
| r5325 | r5326 | |
| 553 | 551 | int first_pixel; |
| 554 | 552 | |
| 555 | 553 | const pen_t *paldata; |
| 556 | | //const UINT8 *sd; |
| 554 | // const UINT8 *sd; |
| 557 | 555 | int pixel; |
| 558 | 556 | |
| 559 | 557 | /* determine if the sprites are 8x8 or 8x16 */ |
| 560 | | size = ( ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE ) ? 16 : 8; |
| 558 | size = (ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE) ? 16 : 8; |
| 561 | 559 | |
| 562 | 560 | first_pixel = (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES_L8)? 0: 8; |
| 563 | 561 | |
| 564 | | for( spriteIndex = 0; spriteIndex < SPRITERAM_SIZE; spriteIndex += 4 ) |
| 562 | for (spriteIndex = 0; spriteIndex < SPRITERAM_SIZE; spriteIndex += 4) |
| 565 | 563 | { |
| 566 | 564 | UINT8 plane1; |
| 567 | 565 | UINT8 plane2; |
| 568 | 566 | |
| 569 | 567 | spriteYPos = sprite_ram[spriteIndex] + 1; |
| 570 | | spriteXPos = sprite_ram[spriteIndex+3]; |
| 568 | spriteXPos = sprite_ram[spriteIndex + 3]; |
| 571 | 569 | |
| 572 | 570 | // The sprite collision acts funny on the last pixel of a scanline. |
| 573 | 571 | // The various scanline latches update while the last few pixels |
| r5325 | r5326 | |
| 585 | 583 | } |
| 586 | 584 | |
| 587 | 585 | /* if the sprite isn't visible, skip it */ |
| 588 | | if ( ( spriteYPos + size <= scanline ) || ( spriteYPos > scanline ) ) |
| 586 | if ((spriteYPos + size <= scanline) || (spriteYPos > scanline)) |
| 589 | 587 | continue; |
| 590 | 588 | |
| 591 | 589 | /* clear our drawn flag */ |
| 592 | 590 | drawn = 0; |
| 593 | 591 | |
| 594 | | tile = sprite_ram[spriteIndex+1]; |
| 595 | | color = ( sprite_ram[spriteIndex+2] & 0x03 ) + 4; |
| 596 | | pri = sprite_ram[spriteIndex+2] & 0x20; |
| 597 | | flipx = sprite_ram[spriteIndex+2] & 0x40; |
| 598 | | flipy = sprite_ram[spriteIndex+2] & 0x80; |
| 592 | tile = sprite_ram[spriteIndex + 1]; |
| 593 | color = (sprite_ram[spriteIndex + 2] & 0x03) + 4; |
| 594 | pri = sprite_ram[spriteIndex + 2] & 0x20; |
| 595 | flipx = sprite_ram[spriteIndex + 2] & 0x40; |
| 596 | flipy = sprite_ram[spriteIndex + 2] & 0x80; |
| 599 | 597 | |
| 600 | | if ( size == 16 ) |
| 598 | if (size == 16) |
| 601 | 599 | { |
| 602 | 600 | /* if it's 8x16 and odd-numbered, draw the other half instead */ |
| 603 | | if ( tile & 0x01 ) |
| 601 | if (tile & 0x01) |
| 604 | 602 | { |
| 605 | 603 | tile &= ~0x01; |
| 606 | 604 | tile |= 0x100; |
| r5325 | r5326 | |
| 609 | 607 | page = tile >> 6; |
| 610 | 608 | } |
| 611 | 609 | else |
| 612 | | page = ( tile >> 6 ) | sprite_page; |
| 610 | page = (tile >> 6) | sprite_page; |
| 613 | 611 | |
| 614 | 612 | |
| 615 | | //index1 = this_ppu->nes_vram[page] + ( tile & 0x3f ); |
| 613 | // index1 = this_ppu->nes_vram[page] + (tile & 0x3f); |
| 616 | 614 | |
| 617 | | if ( ppu_latch ) |
| 618 | | (*ppu_latch)(device, ( sprite_page << 10 ) | ( (tile & 0xff) << 4 )); |
| 615 | if (ppu_latch) |
| 616 | (*ppu_latch)(device, (sprite_page << 10) | ((tile & 0xff) << 4)); |
| 619 | 617 | |
| 620 | 618 | /* compute the character's line to draw */ |
| 621 | 619 | sprite_line = scanline - spriteYPos; |
| 622 | 620 | |
| 623 | 621 | |
| 624 | | if ( flipy ) |
| 625 | | sprite_line = ( size - 1 ) - sprite_line; |
| 622 | if (flipy) |
| 623 | sprite_line = (size - 1) - sprite_line; |
| 626 | 624 | |
| 627 | 625 | paldata = &color_table[4 * color]; |
| 628 | 626 | |
| 629 | | if(size==16 && sprite_line > 7) |
| 627 | if (size == 16 && sprite_line > 7) |
| 630 | 628 | { |
| 631 | 629 | tile++; |
| 632 | | sprite_line -=8; |
| 630 | sprite_line -= 8; |
| 633 | 631 | } |
| 634 | | |
| 635 | 632 | |
| 636 | | index1=tile*16; |
| 637 | | if(size==8) |
| 638 | | index1+=((sprite_page==0)?0:0x1000); |
| 633 | index1 = tile * 16; |
| 634 | if (size == 8) |
| 635 | index1 += ((sprite_page == 0) ? 0 : 0x1000); |
| 639 | 636 | |
| 640 | | plane1=memory_read_byte(device->space[0],(index1+sprite_line)&0x1FFF); |
| 641 | | plane2=memory_read_byte(device->space[0],(index1+sprite_line+8)&0x1FFF); |
| 637 | plane1 = memory_read_byte(device->space[0], (index1 + sprite_line) & 0x1fff); |
| 638 | plane2 = memory_read_byte(device->space[0], (index1 + sprite_line + 8) & 0x1fff); |
| 642 | 639 | |
| 643 | 640 | // sd = gfx_element_get_data(device->machine->gfx[gfx_bank], index1 % total_elements) + start; |
| 644 | 641 | // if (size > 8) |
| 645 | 642 | // gfx_element_get_data(device->machine->gfx[gfx_bank], (index1 + 1) % total_elements); |
| 646 | 643 | |
| 647 | | if ( pri ) |
| 644 | if (pri) |
| 648 | 645 | { |
| 649 | 646 | /* draw the low-priority sprites */ |
| 650 | | |
| 651 | | for ( pixel = 0; pixel < 8; pixel++ ) |
| 647 | for (pixel = 0; pixel < 8; pixel++) |
| 652 | 648 | { |
| 653 | 649 | // UINT8 pixelData = flipx ? sd[7-pixel] : sd[pixel]; |
| 654 | 650 | UINT8 pixelData; |
| 655 | | if(flipx) |
| 651 | if (flipx) |
| 656 | 652 | { |
| 657 | | pixelData=(plane1&1)+((plane2&1)<<1); |
| 658 | | plane1=plane1>>1; |
| 659 | | plane2=plane2>>1; |
| 660 | | //sd[7-pixel] |
| 653 | pixelData = (plane1 & 1) + ((plane2 & 1) << 1); |
| 654 | plane1 = plane1 >> 1; |
| 655 | plane2 = plane2 >> 1; |
| 656 | // sd[7 - pixel] |
| 661 | 657 | } |
| 662 | 658 | else |
| 663 | 659 | { |
| 664 | | pixelData=((plane1>>7)&1)|(((plane2>>7)&1)<<1); |
| 665 | | plane1=plane1<<1; |
| 666 | | plane2=plane2<<1; |
| 667 | | |
| 668 | | //sd[pixel]; |
| 660 | pixelData = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1); |
| 661 | plane1 = plane1 << 1; |
| 662 | plane2 = plane2 << 1; |
| 663 | // sd[pixel]; |
| 669 | 664 | } |
| 670 | 665 | |
| 671 | 666 | /* is this pixel non-transparent? */ |
| 672 | | if ( spriteXPos + pixel >= first_pixel) |
| 667 | if (spriteXPos + pixel >= first_pixel) |
| 673 | 668 | { |
| 674 | 669 | if (pixelData) |
| 675 | 670 | { |
| 676 | 671 | /* has the background (or another sprite) already been drawn here? */ |
| 677 | | if ( !line_priority[ spriteXPos + pixel ] ) |
| 672 | if (!line_priority[spriteXPos + pixel]) |
| 678 | 673 | { |
| 679 | 674 | /* no, draw */ |
| 680 | | if ( ( spriteXPos + pixel ) < VISIBLE_SCREEN_WIDTH ) |
| 675 | if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH) |
| 681 | 676 | *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData]; |
| 682 | 677 | drawn = 1; |
| 683 | 678 | } |
| 684 | 679 | /* indicate that a sprite was drawn at this location, even if it's not seen */ |
| 685 | | if ( ( spriteXPos + pixel ) < VISIBLE_SCREEN_WIDTH ) |
| 686 | | line_priority[ spriteXPos + pixel ] |= 0x01; |
| 680 | if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH) |
| 681 | line_priority[spriteXPos + pixel] |= 0x01; |
| 687 | 682 | } |
| 688 | 683 | |
| 689 | 684 | /* set the "sprite 0 hit" flag if appropriate */ |
| 690 | | if ( spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && ( line_priority[ spriteXPos + pixel ] & 0x02 )) |
| 685 | if (spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && (line_priority[spriteXPos + pixel] & 0x02)) |
| 691 | 686 | ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT; |
| 692 | 687 | } |
| 693 | 688 | } |
| r5325 | r5326 | |
| 695 | 690 | else |
| 696 | 691 | { |
| 697 | 692 | /* draw the high-priority sprites */ |
| 698 | | |
| 699 | | for ( pixel = 0; pixel < 8; pixel++ ) |
| 693 | for (pixel = 0; pixel < 8; pixel++) |
| 700 | 694 | { |
| 701 | 695 | UINT8 pixelData; |
| 702 | | if(flipx) |
| 696 | if (flipx) |
| 703 | 697 | { |
| 704 | | pixelData=(plane1&1)+((plane2&1)<<1); |
| 705 | | plane1=plane1>>1; |
| 706 | | plane2=plane2>>1; |
| 707 | | //sd[7-pixel] |
| 698 | pixelData = (plane1 & 1) + ((plane2 & 1) << 1); |
| 699 | plane1 = plane1 >> 1; |
| 700 | plane2 = plane2 >> 1; |
| 701 | // sd[7 - pixel] |
| 708 | 702 | } |
| 709 | 703 | else |
| 710 | 704 | { |
| 711 | | pixelData=((plane1>>7)&1)|(((plane2>>7)&1)<<1); |
| 712 | | plane1=plane1<<1; |
| 713 | | plane2=plane2<<1; |
| 714 | | |
| 715 | | //sd[pixel]; |
| 705 | pixelData = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1); |
| 706 | plane1 = plane1 << 1; |
| 707 | plane2 = plane2 << 1; |
| 708 | // sd[pixel]; |
| 716 | 709 | } |
| 717 | 710 | |
| 718 | | |
| 719 | 711 | /* is this pixel non-transparent? */ |
| 720 | | if ( spriteXPos + pixel >= first_pixel) |
| 712 | if (spriteXPos + pixel >= first_pixel) |
| 721 | 713 | { |
| 722 | 714 | if (pixelData) |
| 723 | 715 | { |
| 724 | 716 | /* has another sprite been drawn here? */ |
| 725 | | if ( !( line_priority[ spriteXPos + pixel ] & 0x01 ) ) |
| 717 | if (!(line_priority[spriteXPos + pixel] & 0x01)) |
| 726 | 718 | { |
| 727 | 719 | /* no, draw */ |
| 728 | | if ( ( spriteXPos + pixel ) < VISIBLE_SCREEN_WIDTH ) |
| 720 | if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH) |
| 729 | 721 | { |
| 730 | 722 | *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData]; |
| 731 | | line_priority[ spriteXPos + pixel ] |= 0x01; |
| 723 | line_priority[spriteXPos + pixel] |= 0x01; |
| 732 | 724 | } |
| 733 | 725 | drawn = 1; |
| 734 | 726 | } |
| 735 | 727 | } |
| 736 | 728 | |
| 737 | 729 | /* set the "sprite 0 hit" flag if appropriate */ |
| 738 | | if ( spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && ( line_priority[ spriteXPos + pixel ] & 0x02 )) |
| 730 | if (spriteIndex == 0 && (pixelData & 0x03) && ((spriteXPos + pixel) < 255) && (line_priority[spriteXPos + pixel] & 0x02)) |
| 739 | 731 | ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT; |
| 740 | 732 | } |
| 741 | 733 | } |
| 742 | 734 | } |
| 743 | 735 | |
| 744 | | if ( drawn ) |
| 736 | if (drawn) |
| 745 | 737 | { |
| 746 | 738 | /* if there are more than 8 sprites on this line, set the flag */ |
| 747 | 739 | spriteCount++; |
| 748 | | if ( spriteCount == 8 ) |
| 740 | if (spriteCount == 8) |
| 749 | 741 | { |
| 750 | 742 | ppu_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES; |
| 751 | 743 | // logerror ("> 8 sprites, scanline: %d\n", scanline); |
| r5325 | r5326 | |
| 762 | 754 | * Scanline Rendering and Update |
| 763 | 755 | * |
| 764 | 756 | *************************************/ |
| 765 | | static void render_scanline(const device_config *device) |
| 757 | |
| 758 | static void render_scanline( const device_config *device ) |
| 766 | 759 | { |
| 767 | 760 | ppu2c0x_chip *this_ppu = get_token(device); |
| 768 | 761 | const ppu2c0x_interface *intf = get_interface(device); |
| 769 | | UINT8 line_priority[VISIBLE_SCREEN_WIDTH]; |
| 770 | | int *ppu_regs = &this_ppu->regs[0]; |
| 762 | UINT8 line_priority[VISIBLE_SCREEN_WIDTH]; |
| 763 | int *ppu_regs = &this_ppu->regs[0]; |
| 771 | 764 | |
| 772 | 765 | /* lets see how long it takes */ |
| 773 | 766 | profiler_mark(PROFILER_USER1); |
| 774 | 767 | |
| 775 | 768 | /* clear the line priority for this scanline */ |
| 776 | | memset( line_priority, 0, VISIBLE_SCREEN_WIDTH ); |
| 769 | memset(line_priority, 0, VISIBLE_SCREEN_WIDTH); |
| 777 | 770 | |
| 778 | 771 | /* clear the sprite count for this line */ |
| 779 | 772 | ppu_regs[PPU_STATUS] &= ~PPU_STATUS_8SPRITES; |
| 780 | 773 | |
| 781 | 774 | /* see if we need to render the background */ |
| 782 | | if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND ) |
| 783 | | draw_background(device, line_priority ); |
| 775 | if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND) |
| 776 | draw_background(device, line_priority); |
| 784 | 777 | else |
| 785 | 778 | { |
| 786 | 779 | bitmap_t *bitmap = this_ppu->bitmap; |
| r5325 | r5326 | |
| 790 | 783 | int i; |
| 791 | 784 | |
| 792 | 785 | /* setup the color mask and colortable to use */ |
| 793 | | if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO ) |
| 786 | if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO) |
| 794 | 787 | color_mask = 0xf0; |
| 795 | 788 | else |
| 796 | 789 | color_mask = 0xff; |
| 797 | 790 | |
| 798 | 791 | /* cache the background pen */ |
| 799 | | back_pen = (this_ppu->back_color & color_mask)+intf->color_base; |
| 792 | back_pen = (this_ppu->back_color & color_mask) + intf->color_base; |
| 800 | 793 | |
| 801 | 794 | // Fill this scanline with the background pen. |
| 802 | | for (i = 0; i < bitmap->width; i ++) |
| 795 | for (i = 0; i < bitmap->width; i++) |
| 803 | 796 | *BITMAP_ADDR16(bitmap, scanline, i) = back_pen; |
| 804 | 797 | } |
| 805 | 798 | |
| 806 | 799 | /* if sprites are on, draw them */ |
| 807 | | if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES ) |
| 808 | | draw_sprites( device, line_priority ); |
| 800 | if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES) |
| 801 | draw_sprites(device, line_priority); |
| 809 | 802 | |
| 810 | 803 | /* done updating, whew */ |
| 811 | 804 | profiler_mark(PROFILER_END); |
| 812 | 805 | } |
| 813 | 806 | |
| 814 | | static void update_scanline(const device_config *device) |
| 807 | static void update_scanline( const device_config *device ) |
| 815 | 808 | { |
| 816 | 809 | ppu2c0x_chip *this_ppu = get_token(device); |
| 817 | 810 | const ppu2c0x_interface *intf = get_interface(device); |
| 818 | 811 | int scanline = this_ppu->scanline; |
| 819 | 812 | int *ppu_regs = &this_ppu->regs[0]; |
| 820 | 813 | |
| 821 | | if ( scanline <= PPU_BOTTOM_VISIBLE_SCANLINE ) |
| 814 | if (scanline <= PPU_BOTTOM_VISIBLE_SCANLINE) |
| 822 | 815 | { |
| 823 | 816 | /* Render this scanline if appropriate */ |
| 824 | | if ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) ) |
| 817 | if (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) |
| 825 | 818 | { |
| 826 | 819 | /* If background or sprites are enabled, copy the ppu address latch */ |
| 827 | 820 | /* Copy only the scroll x-coarse and the x-overflow bit */ |
| 828 | 821 | this_ppu->refresh_data &= ~0x041f; |
| 829 | | this_ppu->refresh_data |= ( this_ppu->refresh_latch & 0x041f ); |
| 822 | this_ppu->refresh_data |= (this_ppu->refresh_latch & 0x041f); |
| 830 | 823 | |
| 831 | | //logerror(" updating refresh_data: %04x (scanline: %d)\n", this_ppu->refresh_data, this_ppu->scanline); |
| 832 | | render_scanline( device ); |
| 824 | // logerror("updating refresh_data: %04x (scanline: %d)\n", this_ppu->refresh_data, this_ppu->scanline); |
| 825 | render_scanline(device); |
| 833 | 826 | } |
| 834 | 827 | else |
| 835 | 828 | { |
| r5325 | r5326 | |
| 840 | 833 | int i; |
| 841 | 834 | |
| 842 | 835 | /* setup the color mask and colortable to use */ |
| 843 | | if ( ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO ) |
| 836 | if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO) |
| 844 | 837 | color_mask = 0xf0; |
| 845 | 838 | else |
| 846 | 839 | color_mask = 0xff; |
| r5325 | r5326 | |
| 862 | 855 | back_pen = penNum + intf->color_base; |
| 863 | 856 | } |
| 864 | 857 | else |
| 865 | | back_pen = (this_ppu->back_color & color_mask)+intf->color_base; |
| 858 | back_pen = (this_ppu->back_color & color_mask) + intf->color_base; |
| 866 | 859 | |
| 867 | 860 | // Fill this scanline with the background pen. |
| 868 | | for (i = 0; i < bitmap->width; i ++) |
| 861 | for (i = 0; i < bitmap->width; i++) |
| 869 | 862 | *BITMAP_ADDR16(bitmap, scanline, i) = back_pen; |
| 870 | 863 | } |
| 871 | 864 | |
| r5325 | r5326 | |
| 873 | 866 | this_ppu->refresh_data += 0x1000; |
| 874 | 867 | |
| 875 | 868 | /* if it's rolled, increment the coarse y-scroll */ |
| 876 | | if ( this_ppu->refresh_data & 0x8000 ) |
| 869 | if (this_ppu->refresh_data & 0x8000) |
| 877 | 870 | { |
| 878 | 871 | UINT16 tmp; |
| 879 | | tmp = ( this_ppu->refresh_data & 0x03e0 ) + 0x20; |
| 872 | tmp = (this_ppu->refresh_data & 0x03e0) + 0x20; |
| 880 | 873 | this_ppu->refresh_data &= 0x7c1f; |
| 881 | 874 | |
| 882 | 875 | /* handle bizarro scrolling rollover at the 30th (not 32nd) vertical tile */ |
| 883 | | if ( tmp == 0x03c0 ) |
| 876 | if (tmp == 0x03c0) |
| 884 | 877 | this_ppu->refresh_data ^= 0x0800; |
| 885 | 878 | else |
| 886 | | this_ppu->refresh_data |= ( tmp & 0x03e0 ); |
| 879 | this_ppu->refresh_data |= (tmp & 0x03e0); |
| 887 | 880 | |
| 888 | | //logerror("updating refresh_data: %04x\n", this_ppu->refresh_data); |
| 889 | | } |
| 881 | // logerror("updating refresh_data: %04x\n", this_ppu->refresh_data); |
| 882 | } |
| 890 | 883 | } |
| 891 | 884 | |
| 892 | 885 | } |
| r5325 | r5326 | |
| 896 | 889 | const device_config *device = (const device_config *)ptr; |
| 897 | 890 | ppu2c0x_chip *this_ppu = get_token(device); |
| 898 | 891 | int *ppu_regs = &this_ppu->regs[0]; |
| 899 | | int blanked = ( ppu_regs[PPU_CONTROL1] & ( PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES ) ) == 0; |
| 900 | | int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE-1) && (this_ppu->scanline < this_ppu->scanlines_per_frame-1)) ? 1 : 0; |
| 892 | int blanked = (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0; |
| 893 | int vblank = ((this_ppu->scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (this_ppu->scanline < this_ppu->scanlines_per_frame - 1)) ? 1 : 0; |
| 901 | 894 | int next_scanline; |
| 902 | 895 | |
| 903 | 896 | /* if a callback is available, call it */ |
| 904 | | if ( this_ppu->scanline_callback_proc != NULL ) |
| 905 | | (*this_ppu->scanline_callback_proc)( device, this_ppu->scanline, vblank, blanked ); |
| 897 | if (this_ppu->scanline_callback_proc != NULL) |
| 898 | (*this_ppu->scanline_callback_proc)(device, this_ppu->scanline, vblank, blanked); |
| 906 | 899 | |
| 907 | 900 | /* update the scanline that just went by */ |
| 908 | | update_scanline( device ); |
| 901 | update_scanline(device); |
| 909 | 902 | |
| 910 | 903 | /* increment our scanline count */ |
| 911 | 904 | this_ppu->scanline++; |
| 912 | 905 | |
| 913 | | //logerror("starting scanline %d (MAME %d, beam %d)\n", this_ppu->scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)); |
| 906 | // logerror("starting scanline %d (MAME %d, beam %d)\n", this_ppu->scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen)); |
| 914 | 907 | |
| 915 | 908 | /* Note: this is called at the _end_ of each scanline */ |
| 916 | 909 | if (this_ppu->scanline == PPU_VBLANK_FIRST_SCANLINE) |
| 917 | 910 | { |
| 918 | | logerror("vlbank starting\n"); |
| 911 | // logerror("vblank starting\n"); |
| 919 | 912 | /* We just entered VBLANK */ |
| 920 | 913 | ppu_regs[PPU_STATUS] |= PPU_STATUS_VBLANK; |
| 921 | 914 | |
| r5325 | r5326 | |
| 930 | 923 | } |
| 931 | 924 | } |
| 932 | 925 | |
| 933 | | if ( this_ppu->scanline == this_ppu->scanlines_per_frame - 1 ) |
| 926 | if (this_ppu->scanline == this_ppu->scanlines_per_frame - 1) |
| 934 | 927 | { |
| 935 | | logerror("vlbank ending\n"); |
| 928 | // logerror("vblank ending\n"); |
| 936 | 929 | /* clear the vblank & sprite hit flag */ |
| 937 | | ppu_regs[PPU_STATUS] &= ~( PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT ); |
| 930 | ppu_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT); |
| 938 | 931 | } |
| 939 | 932 | |
| 940 | 933 | /* see if we rolled */ |
| 941 | | else if ( this_ppu->scanline == this_ppu->scanlines_per_frame ) |
| 934 | else if (this_ppu->scanline == this_ppu->scanlines_per_frame) |
| 942 | 935 | { |
| 943 | 936 | /* if background or sprites are enabled, copy the ppu address latch */ |
| 944 | | if ( !blanked ) |
| 937 | if (!blanked) |
| 945 | 938 | this_ppu->refresh_data = this_ppu->refresh_latch; |
| 946 | 939 | |
| 947 | 940 | /* reset the scanline count */ |
| 948 | 941 | this_ppu->scanline = 0; |
| 949 | | //logerror(" sprite 0 x: %d y: %d num: %d\n", this_ppu->spriteram[3], this_ppu->spriteram[0]+1, this_ppu->spriteram[1]); |
| 942 | // logerror("sprite 0 x: %d y: %d num: %d\n", this_ppu->spriteram[3], this_ppu->spriteram[0] + 1, this_ppu->spriteram[1]); |
| 950 | 943 | } |
| 951 | 944 | |
| 952 | | next_scanline = this_ppu->scanline+1; |
| 945 | next_scanline = this_ppu->scanline + 1; |
| 953 | 946 | if (next_scanline == this_ppu->scanlines_per_frame) |
| 954 | 947 | next_scanline = 0; |
| 955 | 948 | |
| r5325 | r5326 | |
| 991 | 984 | this_ppu->scanline_callback_proc = 0; |
| 992 | 985 | this_ppu->vidaccess_callback_proc = 0; |
| 993 | 986 | |
| 994 | | for( i = 0; i < PPU_MAX_REG; i++ ) |
| 987 | for (i = 0; i < PPU_MAX_REG; i++) |
| 995 | 988 | this_ppu->regs[i] = 0; |
| 996 | 989 | |
| 997 | 990 | /* initialize the rest of the members */ |
| r5325 | r5326 | |
| 1011 | 1004 | { |
| 1012 | 1005 | int color_base = intf->color_base; |
| 1013 | 1006 | |
| 1014 | | for( i = 0; i < ARRAY_LENGTH( default_colortable_mono ); i++ ) |
| 1007 | for (i = 0; i < ARRAY_LENGTH(default_colortable_mono); i++) |
| 1015 | 1008 | { |
| 1016 | 1009 | /* monochromatic table */ |
| 1017 | 1010 | this_ppu->colortable_mono[i] = default_colortable_mono[i] + color_base; |
| r5325 | r5326 | |
| 1022 | 1015 | } |
| 1023 | 1016 | |
| 1024 | 1017 | /* set the vram bank-switch values to the default */ |
| 1025 | | for( i = 0; i < 8; i++ ) |
| 1018 | for (i = 0; i < 8; i++) |
| 1026 | 1019 | this_ppu->nes_vram[i] = i * 64; |
| 1027 | 1020 | |
| 1028 | | //if ( this_ppu->has_videorom ) |
| 1029 | | // ppu2c0x_set_videorom_bank( device, 0, 8, 0, 512 ); |
| 1021 | // if (this_ppu->has_videorom) |
| 1022 | // ppu2c0x_set_videorom_bank(device, 0, 8, 0, 512); |
| 1030 | 1023 | } |
| 1031 | 1024 | |
| 1032 | 1025 | /************************************* |
| r5325 | r5326 | |
| 1035 | 1028 | * |
| 1036 | 1029 | *************************************/ |
| 1037 | 1030 | |
| 1038 | | WRITE8_HANDLER (ppu2c0x_palette_write) |
| 1031 | WRITE8_HANDLER( ppu2c0x_palette_write ) |
| 1039 | 1032 | { |
| 1040 | 1033 | ppu2c0x_chip *this_ppu = get_token(space->cpu); |
| 1041 | 1034 | const ppu2c0x_interface *intf = get_interface(space->cpu); |
| 1042 | 1035 | int color_base = intf->color_base; |
| 1043 | 1036 | |
| 1044 | 1037 | int colorEmphasis = (this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS) * 2; |
| 1045 | | //it's a palette |
| 1046 | | //transparent pens are mirrored! |
| 1047 | | if(offset&0x3) |
| 1038 | // it's a palette |
| 1039 | // transparent pens are mirrored! |
| 1040 | if (offset & 0x3) |
| 1048 | 1041 | { |
| 1049 | | this_ppu->palette_ram[offset&0x1F]=data; |
| 1050 | | this_ppu->colortable[ offset & 0x1f ] = color_base + data + colorEmphasis; |
| 1042 | this_ppu->palette_ram[offset & 0x1f] = data; |
| 1043 | this_ppu->colortable[offset & 0x1f] = color_base + data + colorEmphasis; |
| 1051 | 1044 | this_ppu->colortable_mono[offset & 0x1f] = color_base + (data & 0xf0) + colorEmphasis; |
| 1052 | 1045 | } |
| 1053 | 1046 | else |
| 1054 | 1047 | { |
| 1055 | 1048 | int i; |
| 1056 | | this_ppu->back_color = data; |
| 1057 | | for( i = 0; i < 32; i += 4 ) |
| 1049 | if (0 == (offset & 0xf)) |
| 1058 | 1050 | { |
| 1059 | | this_ppu->colortable[ i ] = color_base + data + colorEmphasis; |
| 1060 | | this_ppu->colortable_mono[i] = color_base + (data & 0xf0) + colorEmphasis; |
| 1051 | this_ppu->back_color = data; |
| 1052 | for (i = 0; i < 32; i += 4) |
| 1053 | { |
| 1054 | this_ppu->colortable[i] = color_base + data + colorEmphasis; |
| 1055 | this_ppu->colortable_mono[i] = color_base + (data & 0xf0) + colorEmphasis; |
| 1056 | } |
| 1061 | 1057 | } |
| 1062 | | this_ppu->palette_ram[offset&0xF]=this_ppu->palette_ram[(offset&0xF)+0x10]=data; |
| 1058 | this_ppu->palette_ram[offset & 0xf] = this_ppu->palette_ram[(offset & 0xf) + 0x10] = data; |
| 1063 | 1059 | } |
| 1064 | 1060 | } |
| 1065 | 1061 | |
| 1066 | | READ8_HANDLER (ppu2c0x_palette_read) |
| 1062 | READ8_HANDLER( ppu2c0x_palette_read ) |
| 1067 | 1063 | { |
| 1068 | 1064 | ppu2c0x_chip *this_ppu = get_token(space->cpu); |
| 1069 | 1065 | { |
| 1070 | | //it's a palette |
| 1071 | | //ERROR: doesn't currently handle monochrome! |
| 1066 | // it's a palette |
| 1067 | // ERROR: doesn't currently handle monochrome! |
| 1072 | 1068 | if (this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO) |
| 1073 | | return (this_ppu->palette_ram[offset&0x1F]&0x30); |
| 1074 | | else return (this_ppu->palette_ram[offset&0x1F]&0x3F); |
| 1069 | return (this_ppu->palette_ram[offset & 0x1f] & 0x30); |
| 1070 | else return (this_ppu->palette_ram[offset & 0x1f] & 0x3f); |
| 1075 | 1071 | } |
| 1076 | 1072 | } |
| 1077 | 1073 | |
| r5325 | r5326 | |
| 1085 | 1081 | { |
| 1086 | 1082 | ppu2c0x_chip *this_ppu = get_token(device); |
| 1087 | 1083 | |
| 1088 | | if ( offset >= PPU_MAX_REG ) |
| 1084 | if (offset >= PPU_MAX_REG) |
| 1089 | 1085 | { |
| 1090 | | logerror( "PPU %s(r): Attempting to read past the chip\n", device->tag ); |
| 1086 | logerror("PPU %s(r): Attempting to read past the chip\n", device->tag); |
| 1091 | 1087 | offset &= PPU_MAX_REG - 1; |
| 1092 | 1088 | } |
| 1093 | 1089 | |
| 1094 | 1090 | // see which register to read |
| 1095 | | switch( offset & 7 ) |
| 1091 | switch (offset & 7) |
| 1096 | 1092 | { |
| 1097 | 1093 | case PPU_STATUS: |
| 1098 | 1094 | // The top 3 bits of the status register are the only ones that report data. The |
| r5325 | r5326 | |
| 1112 | 1108 | break; |
| 1113 | 1109 | |
| 1114 | 1110 | case PPU_DATA: |
| 1115 | | if ( ppu_latch ) |
| 1116 | | (*ppu_latch)( device, this_ppu->videomem_addr & 0x3fff ); |
| 1111 | if (ppu_latch) |
| 1112 | (*ppu_latch)(device, this_ppu->videomem_addr & 0x3fff); |
| 1117 | 1113 | |
| 1118 | | if ( this_ppu->videomem_addr >= 0x3f00 ) |
| 1114 | if (this_ppu->videomem_addr >= 0x3f00) |
| 1119 | 1115 | { |
| 1120 | 1116 | this_ppu->data_latch = memory_read_byte(device->space[0], this_ppu->videomem_addr); |
| 1121 | | //buffer the mirrored NT data |
| 1122 | | this_ppu->buffered_data =memory_read_byte(device->space[0], this_ppu->videomem_addr&0x2FFF); |
| 1117 | // buffer the mirrored NT data |
| 1118 | this_ppu->buffered_data = memory_read_byte(device->space[0], this_ppu->videomem_addr & 0x2fff); |
| 1123 | 1119 | } |
| 1124 | 1120 | else |
| 1125 | 1121 | { |
| 1126 | 1122 | this_ppu->data_latch = this_ppu->buffered_data; |
| 1127 | | this_ppu->buffered_data =memory_read_byte(device->space[0], this_ppu->videomem_addr); |
| 1123 | this_ppu->buffered_data = memory_read_byte(device->space[0], this_ppu->videomem_addr); |
| 1128 | 1124 | } |
| 1129 | 1125 | |
| 1130 | | |
| 1131 | 1126 | this_ppu->videomem_addr += this_ppu->add; |
| 1132 | 1127 | break; |
| 1133 | 1128 | |
| r5325 | r5326 | |
| 1153 | 1148 | |
| 1154 | 1149 | color_base = intf->color_base; |
| 1155 | 1150 | |
| 1156 | | if ( offset >= PPU_MAX_REG ) |
| 1151 | if (offset >= PPU_MAX_REG) |
| 1157 | 1152 | { |
| 1158 | | logerror( "PPU: Attempting to write past the chip\n" ); |
| 1153 | logerror("PPU: Attempting to write past the chip\n"); |
| 1159 | 1154 | offset &= PPU_MAX_REG - 1; |
| 1160 | 1155 | } |
| 1161 | 1156 | |
| r5325 | r5326 | |
| 1163 | 1158 | if (this_ppu->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE) |
| 1164 | 1159 | { |
| 1165 | 1160 | const device_config *screen = device->machine->primary_screen; |
| 1166 | | logerror(" PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, this_ppu->scanline, video_screen_get_vpos(screen), video_screen_get_hpos(screen)); |
| 1161 | logerror("PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, this_ppu->scanline, video_screen_get_vpos(screen), video_screen_get_hpos(screen)); |
| 1167 | 1162 | } |
| 1168 | 1163 | #endif |
| 1169 | 1164 | |
| 1170 | | switch( offset & 7 ) |
| 1165 | switch (offset & 7) |
| 1171 | 1166 | { |
| 1172 | 1167 | case PPU_CONTROL0: |
| 1173 | 1168 | this_ppu->regs[PPU_CONTROL0] = data; |
| 1174 | 1169 | |
| 1175 | 1170 | /* update the name table number on our refresh latches */ |
| 1176 | 1171 | this_ppu->refresh_latch &= 0x73ff; |
| 1177 | | this_ppu->refresh_latch |= ( data & 3 ) << 10; |
| 1172 | this_ppu->refresh_latch |= (data & 3) << 10; |
| 1178 | 1173 | |
| 1179 | 1174 | /* the char ram bank points either 0x0000 or 0x1000 (page 0 or page 4) */ |
| 1180 | | this_ppu->tile_page = ( data & PPU_CONTROL0_CHR_SELECT ) >> 2; |
| 1181 | | this_ppu->sprite_page = ( data & PPU_CONTROL0_SPR_SELECT ) >> 1; |
| 1175 | this_ppu->tile_page = (data & PPU_CONTROL0_CHR_SELECT) >> 2; |
| 1176 | this_ppu->sprite_page = (data & PPU_CONTROL0_SPR_SELECT) >> 1; |
| 1182 | 1177 | |
| 1183 | | this_ppu->add = ( data & PPU_CONTROL0_INC ) ? 32 : 1; |
| 1184 | | //logerror(" control0 write: %02x (scanline: %d)\n", data, this_ppu->scanline); |
| 1178 | this_ppu->add = (data & PPU_CONTROL0_INC) ? 32 : 1; |
| 1179 | // logerror("control0 write: %02x (scanline: %d)\n", data, this_ppu->scanline); |
| 1185 | 1180 | break; |
| 1186 | 1181 | |
| 1187 | 1182 | case PPU_CONTROL1: |
| 1188 | 1183 | /* if color intensity has changed, change all the color tables to reflect them */ |
| 1189 | | if ( ( data & PPU_CONTROL1_COLOR_EMPHASIS ) != ( this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS ) ) |
| 1184 | if ((data & PPU_CONTROL1_COLOR_EMPHASIS) != (this_ppu->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS)) |
| 1190 | 1185 | { |
| 1191 | 1186 | int i; |
| 1192 | 1187 | for (i = 0; i <= 0x1f; i ++) |
| 1193 | 1188 | { |
| 1194 | | UINT8 oldColor = this_ppu->videomem[i+0x3f00]; |
| 1189 | UINT8 oldColor = this_ppu->palette_ram[i]; |
| 1195 | 1190 | |
| 1196 | | this_ppu->colortable[i] = color_base + oldColor + (data & PPU_CONTROL1_COLOR_EMPHASIS)*2; |
| 1191 | this_ppu->colortable[i] = color_base + oldColor + (data & PPU_CONTROL1_COLOR_EMPHASIS) * 2; |
| 1197 | 1192 | } |
| 1198 | 1193 | } |
| 1199 | 1194 | |
| 1200 | | //logerror(" control1 write: %02x (scanline: %d)\n", data, this_ppu->scanline); |
| 1195 | // logerror("control1 write: %02x (scanline: %d)\n", data, this_ppu->scanline); |
| 1201 | 1196 | this_ppu->regs[PPU_CONTROL1] = data; |
| 1202 | 1197 | break; |
| 1203 | 1198 | |
| r5325 | r5326 | |
| 1210 | 1205 | if (this_ppu->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE) |
| 1211 | 1206 | data = 0xff; |
| 1212 | 1207 | this_ppu->spriteram[this_ppu->regs[PPU_SPRITE_ADDRESS]] = data; |
| 1213 | | this_ppu->regs[PPU_SPRITE_ADDRESS] = ( this_ppu->regs[PPU_SPRITE_ADDRESS] + 1 ) & 0xff; |
| 1208 | this_ppu->regs[PPU_SPRITE_ADDRESS] = (this_ppu->regs[PPU_SPRITE_ADDRESS] + 1) & 0xff; |
| 1214 | 1209 | break; |
| 1215 | 1210 | |
| 1216 | 1211 | case PPU_SCROLL: |
| 1217 | | if ( this_ppu->toggle ) |
| 1212 | if (this_ppu->toggle) |
| 1218 | 1213 | { |
| 1219 | 1214 | /* second write */ |
| 1220 | 1215 | this_ppu->refresh_latch &= 0x0c1f; |
| 1221 | | this_ppu->refresh_latch |= ( data & 0xf8 ) << 2; |
| 1222 | | this_ppu->refresh_latch |= ( data & 0x07 ) << 12; |
| 1223 | | //logerror(" scroll write 2: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1216 | this_ppu->refresh_latch |= (data & 0xf8) << 2; |
| 1217 | this_ppu->refresh_latch |= (data & 0x07) << 12; |
| 1218 | // logerror("scroll write 2: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1224 | 1219 | } |
| 1225 | 1220 | else |
| 1226 | 1221 | { |
| r5325 | r5326 | |
| 1229 | 1224 | this_ppu->refresh_latch |= (data & 0xf8) >> 3; |
| 1230 | 1225 | |
| 1231 | 1226 | this_ppu->x_fine = data & 7; |
| 1232 | | //logerror(" scroll write 1: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1227 | // logerror("scroll write 1: %d, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1233 | 1228 | } |
| 1234 | 1229 | |
| 1235 | 1230 | this_ppu->toggle ^= 1; |
| 1236 | 1231 | break; |
| 1237 | 1232 | |
| 1238 | 1233 | case PPU_ADDRESS: |
| 1239 | | if ( this_ppu->toggle ) |
| 1234 | if (this_ppu->toggle) |
| 1240 | 1235 | { |
| 1241 | 1236 | /* second write */ |
| 1242 | 1237 | this_ppu->refresh_latch &= 0x7f00; |
| r5325 | r5326 | |
| 1244 | 1239 | this_ppu->refresh_data = this_ppu->refresh_latch; |
| 1245 | 1240 | |
| 1246 | 1241 | this_ppu->videomem_addr = this_ppu->refresh_latch; |
| 1247 | | //logerror(" vram addr write 2: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1242 | // logerror("vram addr write 2: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1248 | 1243 | } |
| 1249 | 1244 | else |
| 1250 | 1245 | { |
| 1251 | 1246 | /* first write */ |
| 1252 | 1247 | this_ppu->refresh_latch &= 0x00ff; |
| 1253 | | this_ppu->refresh_latch |= ( data & 0x3f ) << 8; |
| 1254 | | //logerror(" vram addr write 1: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1248 | this_ppu->refresh_latch |= (data & 0x3f) << 8; |
| 1249 | // logerror("vram addr write 1: %02x, %04x (scanline: %d)\n", data, this_ppu->refresh_latch, this_ppu->scanline); |
| 1255 | 1250 | } |
| 1256 | 1251 | |
| 1257 | 1252 | this_ppu->toggle ^= 1; |
| r5325 | r5326 | |
| 1261 | 1256 | { |
| 1262 | 1257 | int tempAddr = this_ppu->videomem_addr & 0x3fff; |
| 1263 | 1258 | |
| 1264 | | if ( ppu_latch ) |
| 1265 | | (*ppu_latch)( device, tempAddr ); |
| 1259 | if (ppu_latch) |
| 1260 | (*ppu_latch)(device, tempAddr); |
| 1266 | 1261 | |
| 1267 | 1262 | /* if there's a callback, call it now */ |
| 1268 | | if ( this_ppu->vidaccess_callback_proc ) |
| 1269 | | data = (*this_ppu->vidaccess_callback_proc)( device, tempAddr, data ); |
| 1263 | if (this_ppu->vidaccess_callback_proc) |
| 1264 | data = (*this_ppu->vidaccess_callback_proc)(device, tempAddr, data); |
| 1270 | 1265 | |
| 1271 | 1266 | /* see if it's on the chargen portion */ |
| 1272 | | if ( tempAddr < 0x2000 ) |
| 1267 | if (tempAddr < 0x2000) |
| 1273 | 1268 | { |
| 1274 | 1269 | /* if we have a videorom mapped there, dont write and log the problem */ |
| 1275 | | if ( this_ppu->has_videorom && !this_ppu->has_videoram ) |
| 1270 | if (this_ppu->has_videorom && !this_ppu->has_videoram) |
| 1276 | 1271 | { |
| 1277 | 1272 | /* if there is a vidaccess callback, assume it coped with it */ |
| 1278 | | if ( this_ppu->vidaccess_callback_proc == NULL ) |
| 1279 | | logerror( "PPU: Attempting to write to the chargen when there's a ROM there!\n" ); |
| 1273 | if (this_ppu->vidaccess_callback_proc == NULL) |
| 1274 | logerror("PPU: Attempting to write to the chargen when there's a ROM there!\n"); |
| 1280 | 1275 | } |
| 1281 | 1276 | else |
| 1282 | 1277 | { |
| 1283 | 1278 | /* store the data */ |
| 1284 | | memory_write_byte(device->space[0], tempAddr,data); |
| 1279 | memory_write_byte(device->space[0], tempAddr, data); |
| 1285 | 1280 | |
| 1286 | 1281 | /* mark the char dirty */ |
| 1287 | | //gfx_element_mark_dirty(device->machine->gfx[intf->gfx_layout_number], tempAddr >> 4); |
| 1282 | // gfx_element_mark_dirty(device->machine->gfx[intf->gfx_layout_number], tempAddr >> 4); |
| 1288 | 1283 | } |
| 1289 | 1284 | } |
| 1290 | 1285 | |
| r5325 | r5326 | |
| 1308 | 1303 | * Sprite DMA |
| 1309 | 1304 | * |
| 1310 | 1305 | *************************************/ |
| 1311 | | void ppu2c0x_spriteram_dma (const address_space *space, const device_config *device, const UINT8 page) |
| 1306 | |
| 1307 | void ppu2c0x_spriteram_dma( const address_space *space, const device_config *device, const UINT8 page ) |
| 1312 | 1308 | { |
| 1313 | 1309 | int i; |
| 1314 | 1310 | int address = page << 8; |
| 1315 | 1311 | |
| 1316 | | //logerror(" sprite DMA: %d (scanline: %d)\n", page, this_ppu->scanline); |
| 1312 | // logerror("sprite DMA: %d (scanline: %d)\n", page, this_ppu->scanline); |
| 1317 | 1313 | for (i = 0; i < SPRITERAM_SIZE; i++) |
| 1318 | 1314 | { |
| 1319 | 1315 | UINT8 spriteData = memory_read_byte(space, address + i); |
| 1320 | 1316 | memory_write_byte(space, 0x2004, spriteData); |
| 1321 | | // ppu2c0x_w (device, PPU_SPRITE_DATA, spriteData); |
| 1317 | // ppu2c0x_w(device, PPU_SPRITE_DATA, spriteData); |
| 1322 | 1318 | } |
| 1323 | 1319 | |
| 1324 | 1320 | // should last 513 CPU cycles. |
| r5325 | r5326 | |
| 1346 | 1342 | void ppu2c0x_render( const device_config *device, bitmap_t *bitmap, int flipx, int flipy, int sx, int sy ) |
| 1347 | 1343 | { |
| 1348 | 1344 | ppu2c0x_chip *this_ppu = get_token(device); |
| 1349 | | copybitmap( bitmap, this_ppu->bitmap, flipx, flipy, sx, sy, 0 ); |
| 1345 | copybitmap(bitmap, this_ppu->bitmap, flipx, flipy, sx, sy, 0); |
| 1350 | 1346 | } |
| 1351 | 1347 | |
| 1352 | 1348 | /************************************* |
| r5325 | r5326 | |
| 1359 | 1355 | { |
| 1360 | 1356 | ppu2c0x_chip *this_ppu = get_token(device); |
| 1361 | 1357 | |
| 1362 | | if ( x >= VISIBLE_SCREEN_WIDTH ) |
| 1358 | if (x >= VISIBLE_SCREEN_WIDTH) |
| 1363 | 1359 | x = VISIBLE_SCREEN_WIDTH - 1; |
| 1364 | 1360 | |
| 1365 | | if ( y >= VISIBLE_SCREEN_HEIGHT ) |
| 1361 | if (y >= VISIBLE_SCREEN_HEIGHT) |
| 1366 | 1362 | y = VISIBLE_SCREEN_HEIGHT - 1; |
| 1367 | 1363 | |
| 1368 | 1364 | return *BITMAP_ADDR16(this_ppu->bitmap, y, x); |
src/mame/drivers/vsnes.c
| r5325 | r5326 | |
| 1768 | 1768 | MDRV_CPU_PROGRAM_MAP(vsnes_cpu1_map) |
| 1769 | 1769 | /* some carts also trigger IRQs */ |
| 1770 | 1770 | MDRV_MACHINE_RESET(vsnes) |
| 1771 | MDRV_MACHINE_START(vsnes) |
| 1771 | 1772 | |
| 1772 | 1773 | /* video hardware */ |
| 1773 | 1774 | MDRV_SCREEN_ADD("screen", RASTER) |
| r5325 | r5326 | |
| 1806 | 1807 | MDRV_CPU_PROGRAM_MAP(vsnes_cpu2_map) |
| 1807 | 1808 | /* some carts also trigger IRQs */ |
| 1808 | 1809 | MDRV_MACHINE_RESET(vsdual) |
| 1810 | MDRV_MACHINE_START(vsdual) |
| 1809 | 1811 | |
| 1810 | 1812 | /* video hardware */ |
| 1811 | 1813 | MDRV_PALETTE_LENGTH(2*8*4*16) |
| r5325 | r5326 | |
| 1852 | 1854 | /******************************************************************************/ |
| 1853 | 1855 | |
| 1854 | 1856 | |
| 1855 | | ROM_START( suprmrio) |
| 1857 | ROM_START( suprmrio ) |
| 1856 | 1858 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 1857 | 1859 | ROM_LOAD( "mds-sm4.1d", 0x8000, 0x2000, CRC(be4d5436) SHA1(08162a7c987f1939d09bebdb676f596c86abf465) ) |
| 1858 | 1860 | ROM_LOAD( "mds-sm4.1c", 0xa000, 0x2000, CRC(0011fc5a) SHA1(5c2c49938a12affc03e64e5bdab307998be20020) ) |
| r5325 | r5326 | |
| 1864 | 1866 | ROM_LOAD( "mds-sm4.2a", 0x2000, 0x2000, CRC(15506b86) SHA1(69ecf7a3cc8bf719c1581ec7c0d68798817d416f) ) |
| 1865 | 1867 | ROM_END |
| 1866 | 1868 | |
| 1867 | | ROM_START( suprmria ) |
| 1869 | ROM_START( suprmrioa ) |
| 1868 | 1870 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 1869 | 1871 | ROM_LOAD( "mds-sm4.1d", 0x8000, 0x2000, CRC(be4d5436) SHA1(08162a7c987f1939d09bebdb676f596c86abf465) ) |
| 1870 | 1872 | ROM_LOAD( "mds-sm4.1c", 0xa000, 0x2000, CRC(5e3fb550) SHA1(de4494e4dd52f7f7b04cf1d9019fd89fb90eaca9) ) /* this rom differs by TWO BYTES from the other version in suprmrio. this version has been dumped/observed on two known boards and one anonymous board */ |
| r5325 | r5326 | |
| 1900 | 1902 | ROM_LOAD( "ic-2a", 0x2000, 0x2000, CRC(4ec44fb3) SHA1(676e0ab574dec08df562c6f278e8a9cc7c8afa41) ) |
| 1901 | 1903 | ROM_END |
| 1902 | 1904 | |
| 1903 | | ROM_START( iceclmbj ) |
| 1905 | ROM_START( iceclimbj ) |
| 1904 | 1906 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 1905 | 1907 | ROM_LOAD( "mds-ic4-4_6d_b.bin", 0x8000, 0x2000, CRC(0ea5f9cb) SHA1(3ba6228ac8011371fc36ce9dde4fc158a81a99a2) ) |
| 1906 | 1908 | ROM_LOAD( "mds-ic4-4_6c_b.bin", 0xa000, 0x2000, CRC(51fe438e) SHA1(f40812d4275dabaac6f9539e1300c08d07992654) ) |
| r5325 | r5326 | |
| 2011 | 2013 | ROM_LOAD( "mds-eb4.2a", 0x2000, 0x2000, CRC(a9b49a05) SHA1(c14706e6a5524f81e79c101e32deef9f3d60de3f) ) |
| 2012 | 2014 | ROM_END |
| 2013 | 2015 | |
| 2014 | | ROM_START( excitbkj ) |
| 2016 | ROM_START( excitebkj ) |
| 2015 | 2017 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 2016 | 2018 | ROM_LOAD( "mds-eb4-4_6d_a.bin", 0x8000, 0x2000, CRC(6aa87037) SHA1(f3313700955498800a3d59c523ba2a4e0cf443bc) ) |
| 2017 | 2019 | ROM_LOAD( "mds-eb4-4_6c_a.bin", 0xa000, 0x2000, CRC(bdb317db) SHA1(a8b3e8deb1e625d764aaffe86a513bc7ede51a46) ) |
| r5325 | r5326 | |
| 2035 | 2037 | ROM_LOAD( "11.bin", 0x2000, 0x2000, CRC(f0034c04) SHA1(402dcf6ad443baeee3038ecab12db008a1ad2787) ) |
| 2036 | 2038 | ROM_END |
| 2037 | 2039 | |
| 2038 | | ROM_START( ladygolf) |
| 2040 | ROM_START( ladygolf ) |
| 2039 | 2041 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 2040 | 2042 | ROM_LOAD( "lg-1d", 0x8000, 0x2000, CRC(8b2ab436) SHA1(145a75f30f1fab5b1babf01ada9ed23f59c2c18d) ) |
| 2041 | 2043 | ROM_LOAD( "lg-1c", 0xa000, 0x2000, CRC(bda6b432) SHA1(c8322f07df0adbd70cb49f2284b046478a3a57c1) ) |
| r5325 | r5326 | |
| 2071 | 2073 | ROM_LOAD( "mr-2a", 0x2000, 0x2000, CRC(685899d8) SHA1(02b6a9bc21367c481d0091fa8a8f2d1b841244bf) ) |
| 2072 | 2074 | ROM_END |
| 2073 | 2075 | |
| 2074 | | ROM_START( machridj ) |
| 2076 | ROM_START( machridrj ) |
| 2075 | 2077 | ROM_REGION( 0x10000,"maincpu",0 ) /* 6502 memory */ |
| 2076 | 2078 | ROM_LOAD( "mds-mr4-1_1d_or_6d_a.bin", 0x8000, 0x2000, CRC(ab7e0594) SHA1(fc5982a93791608a20e5ec9e3a4b71d702bda354) ) |
| 2077 | 2079 | ROM_LOAD( "mds-mr4-1_1c_or_6c_a.bin", 0xa000, 0x2000, CRC(d4a341c3) SHA1(c799e40d0ebd1447032d8767fb2caeee6b33f31a) ) |
| r5325 | r5326 | |
| 2083 | 2085 | ROM_LOAD( "mds-mr4-1_2a_or_8a_a.bin", 0x2000, 0x2000, CRC(ccfedc5a) SHA1(3d6321681fbe256d7c71037205d45d22fc264569) ) |
| 2084 | 2086 | ROM_END |
| 2085 | 2087 | |
| 2086 | | ROM_START(smgolf) |
| 2088 | ROM_START( smgolf ) |
| 2087 | 2089 | ROM_REGION( 0x10000,"maincpu",0 ) /* 6502 memory */ |
| 2088 | 2090 | ROM_LOAD( "golf-1d", 0x8000, 0x2000, CRC(a3e286d3) SHA1(ee7539a46e0e062ffd63d84e8b83de29b860a501) ) |
| 2089 | 2091 | ROM_LOAD( "golf-1c", 0xa000, 0x2000, CRC(e477e48b) SHA1(2ebcc548ac8defc521860d2d2f585be0eee6620e) ) |
| r5325 | r5326 | |
| 2119 | 2121 | ROM_LOAD( "pb-8a", 0x2000, 0x2000, CRC(cbe98a28) SHA1(c00c5f15a33611bfe3ad420b93b1cc2cae011c3e) ) |
| 2120 | 2122 | ROM_END |
| 2121 | 2123 | |
| 2122 | | ROM_START( vspinblj ) |
| 2124 | ROM_START( vspinbalj ) |
| 2123 | 2125 | ROM_REGION( 0x10000, "maincpu", 0 ) /* 6502 memory */ |
| 2124 | 2126 | ROM_LOAD( "mds-pn3_6d_b.bin", 0x8000, 0x2000, CRC(fd50c42e) SHA1(4a3ea9e85b60caf8b6975fd2798bc59e86ec257f) ) |
| 2125 | 2127 | ROM_LOAD( "mds-pn3_6c_b.bin", 0xa000, 0x2000, CRC(59beb9e5) SHA1(682b31dfbdf1ee44fd5d5d63169ab35409e93546) ) |
| r5325 | r5326 | |
| 2359 | 2361 | ROM_LOAD( "mds-ba_8a_a.bin", 0x2000, 0x2000, CRC(3f7edb00) SHA1(f59d24f15bdb8903187eabc1578dcb60443614ed) ) |
| 2360 | 2362 | ROM_END |
| 2361 | 2363 | |
| 2362 | | ROM_START( vsbbalja ) |
| 2364 | ROM_START( vsbballja ) |
| 2363 | 2365 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 2364 | 2366 | ROM_LOAD( "mds-ba_1d_a-2.bin", 0x08000, 0x02000, CRC(f3820b70) SHA1(c50d0c2e34f646dd186ee0f2774e94add733f21d) ) |
| 2365 | 2367 | ROM_LOAD( "mds-ba_1c_a-2.bin", 0x0a000, 0x02000, CRC(39fbbf28) SHA1(9941defda548f2c51cf62f0ad62a041ee9a69c37) ) |
| r5325 | r5326 | |
| 2381 | 2383 | ROM_LOAD( "mds-ba_8a_a.bin", 0x2000, 0x2000, CRC(3f7edb00) SHA1(f59d24f15bdb8903187eabc1578dcb60443614ed) ) |
| 2382 | 2384 | ROM_END |
| 2383 | 2385 | |
| 2384 | | ROM_START( vsbbaljb ) |
| 2386 | ROM_START( vsbballjb ) |
| 2385 | 2387 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 2386 | 2388 | ROM_LOAD( "mds-ba_1d_a-3.bin", 0x08000, 0x02000, CRC(e234d609) SHA1(a148d6b57fbc9d5f91737fa30c2df2c2b66df404) ) |
| 2387 | 2389 | ROM_LOAD( "mds-ba_1c_a-3.bin", 0x0a000, 0x02000, CRC(ca1a9591) SHA1(3544f244c59d3dab40c2745e84775b7c1defaf54) ) |
| r5325 | r5326 | |
| 2425 | 2427 | ROM_LOAD( "mds-te.8a", 0x2000, 0x2000, CRC(d91eb295) SHA1(6b69bcef5421a6bcde89a2d1f514853f9f7992c3) ) |
| 2426 | 2428 | ROM_END |
| 2427 | 2429 | |
| 2428 | | ROM_START( vstennij ) |
| 2430 | ROM_START( vstennisj ) |
| 2429 | 2431 | ROM_REGION( 0x10000,"maincpu", 0 ) /* 6502 memory */ |
| 2430 | 2432 | ROM_LOAD( "mds-te_1d_a-3.bin", 0x08000, 0x2000, CRC(8d88fbe5) SHA1(1aa172d02d0d47325edf2f5ea4fc3c1c52f1efbe) ) |
| 2431 | 2433 | ROM_LOAD( "mds-te_1c_a-2.bin", 0x0a000, 0x2000, CRC(5f00c129) SHA1(e9954ebedc037be0a177286bbfc2ecdaa9223d85) ) |
| r5325 | r5326 | |
| 2501 | 2503 | GAME( 1990, drmario, 0, vsnes, drmario, drmario, ROT0, "Nintendo", "Vs. Dr. Mario", 0 ) |
| 2502 | 2504 | GAME( 1985, duckhunt, 0, vsnes, duckhunt, duckhunt, ROT0, "Nintendo", "Vs. Duck Hunt", 0 ) |
| 2503 | 2505 | GAME( 1984, excitebk, 0, vsnes, excitebk, excitebk, ROT0, "Nintendo", "Vs. Excitebike", 0 ) |
| 2504 | | GAME( 1984, excitbkj, excitebk, vsnes, excitebk, excitbkj, ROT0, "Nintendo", "Vs. Excitebike (Japan)", 0 ) |
| 2506 | GAME( 1984, excitebkj,excitebk, vsnes, excitebk, excitbkj, ROT0, "Nintendo", "Vs. Excitebike (Japan)", 0 ) |
| 2505 | 2507 | GAME( 1986, goonies, 0, vsnes, goonies, goonies, ROT0, "Konami", "Vs. The Goonies", 0 ) |
| 2506 | 2508 | GAME( 1985, hogalley, 0, vsnes, hogalley, hogalley, ROT0, "Nintendo", "Vs. Hogan's Alley", 0 ) |
| 2507 | 2509 | GAME( 1984, iceclimb, 0, vsnes, iceclimb, suprmrio, ROT0, "Nintendo", "Vs. Ice Climber", 0 ) |
| 2508 | | GAME( 1984, iceclmbj, iceclimb, vsnes, iceclmbj, suprmrio, ROT0, "Nintendo", "Vs. Ice Climber (Japan)", 0 ) |
| 2510 | GAME( 1984, iceclimbj,iceclimb, vsnes, iceclmbj, suprmrio, ROT0, "Nintendo", "Vs. Ice Climber (Japan)", 0 ) |
| 2509 | 2511 | GAME( 1985, machridr, 0, vsnes, machridr, machridr, ROT0, "Nintendo", "Vs. Mach Rider (Endurance Course Version)", GAME_IMPERFECT_GRAPHICS ) |
| 2510 | | GAME( 1985, machridj, machridr, vsnes, machridj, vspinbal, ROT0, "Nintendo", "Vs. Mach Rider (Japan, Fighting Course Version)", GAME_IMPERFECT_GRAPHICS ) |
| 2512 | GAME( 1985, machridrj,machridr, vsnes, machridj, vspinbal, ROT0, "Nintendo", "Vs. Mach Rider (Japan, Fighting Course Version)", GAME_IMPERFECT_GRAPHICS ) |
| 2511 | 2513 | GAME( 1986, rbibb, 0, vsnes, rbibb, rbibb, ROT0, "Namco", "Vs. Atari R.B.I. Baseball (set 1)", 0 ) |
| 2512 | 2514 | GAME( 1986, rbibba, rbibb, vsnes, rbibb, rbibb, ROT0, "Namco", "Vs. Atari R.B.I. Baseball (set 2)", 0 ) |
| 2513 | 2515 | GAME( 1986, suprmrio, 0, vsnes, suprmrio, suprmrio, ROT0, "Nintendo", "Vs. Super Mario Bros.", 0 ) |
| 2514 | | GAME( 1986, suprmria, suprmrio, vsnes, suprmrio, suprmrio, ROT0, "Nintendo", "Vs. Super Mario Bros. (alt)", 0 ) |
| 2516 | GAME( 1986, suprmrioa,suprmrio, vsnes, suprmrio, suprmrio, ROT0, "Nintendo", "Vs. Super Mario Bros. (alt)", 0 ) |
| 2515 | 2517 | GAME( 1988, skatekds, suprmrio, vsnes, suprmrio, suprmrio, ROT0, "hack", "Vs. Skate Kids. (Graphic hack of Super Mario Bros.)", 0 ) |
| 2516 | 2518 | GAME( 1985, vsskykid, 0, vsnes, vsskykid, MMC3, ROT0, "Namco", "Vs. Super SkyKid" , 0 ) |
| 2517 | 2519 | GAME( 1987, tkoboxng, 0, vsnes, tkoboxng, tkoboxng, ROT0, "Namco LTD.","Vs. TKO Boxing", GAME_WRONG_COLORS | GAME_IMPERFECT_GRAPHICS ) |
| r5325 | r5326 | |
| 2519 | 2521 | GAME( 1984, smgolfj, smgolf, vsnes, golf, vsnormal, ROT0, "Nintendo", "Vs. Stroke & Match Golf (Men Version) (Japan)", 0 ) |
| 2520 | 2522 | GAME( 1984, ladygolf, smgolf, vsnes, golf, machridr, ROT0, "Nintendo", "Vs. Stroke & Match Golf (Ladies Version)", 0 ) |
| 2521 | 2523 | GAME( 1984, vspinbal, 0, vsnes, vspinbal, vspinbal, ROT0, "Nintendo", "Vs. Pinball", 0 ) |
| 2522 | | GAME( 1984, vspinblj, vspinbal, vsnes, vspinblj, vsnormal, ROT0, "Nintendo", "Vs. Pinball (Japan)", 0 ) |
| 2524 | GAME( 1984, vspinbalj,vspinbal, vsnes, vspinblj, vsnormal, ROT0, "Nintendo", "Vs. Pinball (Japan)", 0 ) |
| 2523 | 2525 | GAME( 1986, vsslalom, 0, vsnes, vsslalom, vsslalom, ROT0, "Rare LTD.", "Vs. Slalom", GAME_IMPERFECT_GRAPHICS ) |
| 2524 | 2526 | GAME( 1985, vssoccer, 0, vsnes, vssoccer, excitebk, ROT0, "Nintendo", "Vs. Soccer", 0 ) |
| 2525 | 2527 | GAME( 1986, vsgradus, 0, vsnes, vsgradus, vsgradus, ROT0, "Konami", "Vs. Gradius", 0 ) |
| r5325 | r5326 | |
| 2535 | 2537 | |
| 2536 | 2538 | /* Dual games */ |
| 2537 | 2539 | GAME( 1984, vstennis, 0, vsdual, vstennis, vstennis, ROT0, "Nintendo", "Vs. Tennis" , 0 ) |
| 2538 | | GAME( 1984, vstennij, vstennis, vsdual, vstennis, vstennis, ROT0, "Nintendo", "Vs. Tennis (Japan)" , 0 ) |
| 2540 | GAME( 1984, vstennisj,vstennis, vsdual, vstennis, vstennis, ROT0, "Nintendo", "Vs. Tennis (Japan)" , 0 ) |
| 2539 | 2541 | GAME( 1984, wrecking, 0, vsdual, wrecking, wrecking, ROT0, "Nintendo", "Vs. Wrecking Crew", 0 ) |
| 2540 | 2542 | GAME( 1984, balonfgt, 0, vsdual, balonfgt, balonfgt, ROT0, "Nintendo", "Vs. Balloon Fight", 0 ) |
| 2541 | 2543 | GAME( 1984, vsmahjng, 0, vsdual, vsmahjng, vstennis, ROT0, "Nintendo", "Vs. Mahjang (Japan)" , 0 ) |
| 2542 | 2544 | GAME( 1984, vsbball, 0, vsdual, vsbball, vsbball, ROT0, "Nintendo of America", "Vs. BaseBall", 0 ) |
| 2543 | 2545 | GAME( 1984, vsbballj, vsbball, vsdual, vsbballj, vsbball, ROT0, "Nintendo of America", "Vs. BaseBall (Japan set 1)", 0 ) |
| 2544 | | GAME( 1984, vsbbalja, vsbball, vsdual, vsbballj, vsbball, ROT0, "Nintendo of America", "Vs. BaseBall (Japan set 2)", 0 ) |
| 2546 | GAME( 1984, vsbballja,vsbball, vsdual, vsbballj, vsbball, ROT0, "Nintendo of America", "Vs. BaseBall (Japan set 2)", 0 ) |
| 2545 | 2547 | GAME( 1984, iceclmrj, 0, vsdual, iceclmrj, iceclmrj, ROT0, "Nintendo", "Vs. Ice Climber Dual (Japan)" , 0 ) |
| 2546 | 2548 | |
| 2547 | 2549 | /* Not Working (bad dumps) */ |
| 2548 | 2550 | GAME( 1985, smgolfb, smgolf, vsnes, golf, machridr, ROT0, "Nintendo", "Vs. Stroke & Match Golf (Men Version, set 2)", GAME_NOT_WORKING ) |
| 2549 | | GAME( 1984, vsbbaljb, vsbball, vsdual, vsbballj, vsbball, ROT0, "Nintendo of America", "Vs. BaseBall (Japan set 3)", GAME_NOT_WORKING ) |
| 2551 | GAME( 1984, vsbballjb,vsbball, vsdual, vsbballj, vsbball, ROT0, "Nintendo of America", "Vs. BaseBall (Japan set 3)", GAME_NOT_WORKING ) |
src/mame/drivers/multigam.c
| r5325 | r5326 | |
| 47 | 47 | |
| 48 | 48 | /****************************************************** |
| 49 | 49 | |
| 50 | PPU external bus interface |
| 51 | |
| 52 | *******************************************************/ |
| 53 | static UINT8* nt_ram; |
| 54 | static UINT8* nt_page[4]; |
| 55 | |
| 56 | void set_mirroring(int mirroring) |
| 57 | { |
| 58 | switch(mirroring) |
| 59 | { |
| 60 | case PPU_MIRROR_LOW: |
| 61 | nt_page[0] = nt_page[1] = nt_page[2] = nt_page[3] = nt_ram; |
| 62 | break; |
| 63 | case PPU_MIRROR_HIGH: |
| 64 | nt_page[0] = nt_page[1] = nt_page[2] = nt_page[3] = nt_ram + 0x400; |
| 65 | break; |
| 66 | case PPU_MIRROR_HORZ: |
| 67 | nt_page[0] = nt_ram; |
| 68 | nt_page[1] = nt_ram; |
| 69 | nt_page[2] = nt_ram + 0x400; |
| 70 | nt_page[3] = nt_ram + 0x400; |
| 71 | break; |
| 72 | case PPU_MIRROR_VERT: |
| 73 | nt_page[0] = nt_ram; |
| 74 | nt_page[1] = nt_ram + 0x400; |
| 75 | nt_page[2] = nt_ram; |
| 76 | nt_page[3] = nt_ram + 0x400; |
| 77 | break; |
| 78 | case PPU_MIRROR_NONE: |
| 79 | default: |
| 80 | nt_page[0] = nt_ram; |
| 81 | nt_page[1] = nt_ram + 0x400; |
| 82 | nt_page[2] = nt_ram + 0x800; |
| 83 | nt_page[3] = nt_ram + 0xc00; |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | static WRITE8_HANDLER (multigam_nt_w) |
| 88 | { |
| 89 | int page = ((offset & 0xc00) >> 10); |
| 90 | nt_page[page][offset & 0x3ff] = data; |
| 91 | } |
| 92 | static READ8_HANDLER (multigam_nt_r) |
| 93 | { |
| 94 | int page = ((offset & 0xc00) >> 10); |
| 95 | return nt_page[page][offset & 0x3ff]; |
| 96 | } |
| 97 | |
| 98 | void set_videorom_bank(running_machine* machine, int start, int count, int bank, int bank_size_in_kb) |
| 99 | { |
| 100 | int i, j; |
| 101 | int offset = bank * (bank_size_in_kb * 0x400); |
| 102 | /* bank_size_in_kb is used to determine how large the "bank" parameter is */ |
| 103 | /* count determines the size of the area mapped in KB */ |
| 104 | for (i = 0; i < count; i++) |
| 105 | { |
| 106 | j = i + start + 1; |
| 107 | memory_set_bankptr(machine, j, memory_region(machine, "gfx1") + offset); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /****************************************************** |
| 112 | |
| 50 | 113 | NES interface |
| 51 | 114 | |
| 52 | 115 | *******************************************************/ |
| 53 | 116 | |
| 54 | 117 | static WRITE8_HANDLER( sprite_dma_w ) |
| 55 | 118 | { |
| 56 | | int source = ( data & 7 ); |
| 57 | | ppu2c0x_spriteram_dma( space, devtag_get_device(space->machine, "ppu"), source ); |
| 119 | int source = (data & 7); |
| 120 | ppu2c0x_spriteram_dma(space, devtag_get_device(space->machine, "ppu"), source); |
| 58 | 121 | } |
| 59 | 122 | |
| 60 | 123 | static READ8_DEVICE_HANDLER( psg_4015_r ) |
| r5325 | r5326 | |
| 92 | 155 | |
| 93 | 156 | static WRITE8_HANDLER( multigam_IN0_w ) |
| 94 | 157 | { |
| 95 | | if ( data & 0x01 ) |
| 158 | if (data & 0x01) |
| 96 | 159 | { |
| 97 | 160 | return; |
| 98 | 161 | } |
| r5325 | r5326 | |
| 131 | 194 | static WRITE8_HANDLER(multigam_switch_prg_rom) |
| 132 | 195 | { |
| 133 | 196 | /* switch PRG rom */ |
| 134 | | UINT8* dst = memory_region( space->machine, "maincpu" ); |
| 135 | | UINT8* src = memory_region( space->machine, "user1" ); |
| 197 | UINT8* dst = memory_region(space->machine, "maincpu"); |
| 198 | UINT8* src = memory_region(space->machine, "user1"); |
| 136 | 199 | |
| 137 | | if ( data & 0x80 ) |
| 200 | if (data & 0x80) |
| 138 | 201 | { |
| 139 | | if ( data & 0x01 ) |
| 202 | if (data & 0x01) |
| 140 | 203 | { |
| 141 | 204 | data &= ~0x01; |
| 142 | 205 | } |
| 143 | | memcpy( &dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000 ); |
| 206 | memcpy(&dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000); |
| 144 | 207 | } |
| 145 | 208 | else |
| 146 | 209 | { |
| 147 | | memcpy( &dst[0x8000], &src[data*0x4000], 0x4000 ); |
| 148 | | memcpy( &dst[0xc000], &src[data*0x4000], 0x4000 ); |
| 210 | memcpy(&dst[0x8000], &src[data*0x4000], 0x4000); |
| 211 | memcpy(&dst[0xc000], &src[data*0x4000], 0x4000); |
| 149 | 212 | } |
| 150 | 213 | }; |
| 151 | 214 | |
| 152 | 215 | static WRITE8_HANDLER(multigam_switch_gfx_rom) |
| 153 | 216 | { |
| 154 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 155 | | ppu2c0x_set_videorom_bank( ppu, 0, 8, data /*& 0x3f*/, 512 ); |
| 156 | | ppu2c0x_set_mirroring( ppu, data & 0x40 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT ); |
| 217 | memory_set_bankptr(space->machine, 1, memory_region(space->machine, "gfx1") + (0x2000 * data)); |
| 218 | set_mirroring(data & 0x40 ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT); |
| 157 | 219 | multigam_game_gfx_bank = data; |
| 158 | 220 | }; |
| 159 | 221 | |
| 160 | 222 | |
| 161 | 223 | static WRITE8_HANDLER(multigam_mapper2_w) |
| 162 | 224 | { |
| 163 | | if ( multigam_game_gfx_bank & 0x80 ) |
| 225 | if (multigam_game_gfx_bank & 0x80) |
| 164 | 226 | { |
| 165 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 166 | | ppu2c0x_set_videorom_bank( ppu, 0, 8, multigam_game_gfx_bank + (data & 0xf), 512 ); |
| 227 | memory_set_bankptr(space->machine, 1, memory_region(space->machine, "gfx1") + (0x2000 * ((data & 0xf) + multigam_game_gfx_bank))); |
| 167 | 228 | } |
| 168 | 229 | else |
| 169 | 230 | { |
| 170 | | logerror( "Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data ); |
| 231 | logerror("Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data); |
| 171 | 232 | } |
| 172 | 233 | } |
| 173 | 234 | |
| r5325 | r5326 | |
| 210 | 271 | |
| 211 | 272 | static void multigam3_mmc3_scanline_cb( const device_config *device, int scanline, int vblank, int blanked ) |
| 212 | 273 | { |
| 213 | | if ( !vblank && !blanked ) |
| 274 | if (!vblank && !blanked) |
| 214 | 275 | { |
| 215 | | if ( --multigam3_mmc3_scanline_counter == -1 ) |
| 276 | if (--multigam3_mmc3_scanline_counter == -1) |
| 216 | 277 | { |
| 217 | 278 | multigam3_mmc3_scanline_counter = multigam3_mmc3_scanline_latch; |
| 218 | 279 | generic_pulse_irq_line(cputag_get_cpu(device->machine, "maincpu"), 0); |
| r5325 | r5326 | |
| 227 | 288 | /* basically, a MMC3 mapper from the nes */ |
| 228 | 289 | static int multigam3_mmc3_command; |
| 229 | 290 | |
| 230 | | switch( offset & 0x7001 ) |
| 291 | switch(offset & 0x7001) |
| 231 | 292 | { |
| 232 | 293 | case 0x0000: |
| 233 | 294 | multigam3_mmc3_command = data; |
| 234 | 295 | |
| 235 | | if ( multigam3_mmc3_last_bank != ( data & 0xc0 ) ) |
| 296 | if (multigam3_mmc3_last_bank != (data & 0xc0)) |
| 236 | 297 | { |
| 237 | 298 | int bank; |
| 238 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 239 | | UINT8 *src = memory_region( space->machine, "user1" ); |
| 299 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 300 | UINT8 *src = memory_region(space->machine, "user1"); |
| 240 | 301 | |
| 241 | 302 | /* reset the banks */ |
| 242 | | if ( multigam3_mmc3_command & 0x40 ) |
| 303 | if (multigam3_mmc3_command & 0x40) |
| 243 | 304 | { |
| 244 | 305 | /* high bank */ |
| 245 | 306 | bank = multigam3_mmc3_banks[0] * 0x2000 + 0xa0000; |
| 246 | 307 | |
| 247 | | memcpy( &prg[0x0c000], &src[bank], 0x2000 ); |
| 248 | | memcpy( &prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000 ); |
| 308 | memcpy(&prg[0x0c000], &src[bank], 0x2000); |
| 309 | memcpy(&prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000); |
| 249 | 310 | } |
| 250 | 311 | else |
| 251 | 312 | { |
| 252 | 313 | /* low bank */ |
| 253 | 314 | bank = multigam3_mmc3_banks[0] * 0x2000 + 0xa0000; |
| 254 | 315 | |
| 255 | | memcpy( &prg[0x08000], &src[bank], 0x2000 ); |
| 256 | | memcpy( &prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000 ); |
| 316 | memcpy(&prg[0x08000], &src[bank], 0x2000); |
| 317 | memcpy(&prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000); |
| 257 | 318 | } |
| 258 | 319 | |
| 259 | 320 | /* mid bank */ |
| 260 | 321 | bank = multigam3_mmc3_banks[1] * 0x2000 + 0xa0000; |
| 261 | | memcpy( &prg[0x0a000], &src[bank], 0x2000 ); |
| 322 | memcpy(&prg[0x0a000], &src[bank], 0x2000); |
| 262 | 323 | |
| 263 | 324 | multigam3_mmc3_last_bank = data & 0xc0; |
| 264 | 325 | } |
| r5325 | r5326 | |
| 267 | 328 | case 0x0001: |
| 268 | 329 | { |
| 269 | 330 | UINT8 cmd = multigam3_mmc3_command & 0x07; |
| 270 | | int page = ( multigam3_mmc3_command & 0x80 ) >> 5; |
| 331 | int page = (multigam3_mmc3_command & 0x80) >> 5; |
| 271 | 332 | int bank; |
| 272 | 333 | |
| 273 | | switch( cmd ) |
| 334 | switch (cmd) |
| 274 | 335 | { |
| 275 | 336 | case 0: /* char banking */ |
| 276 | 337 | case 1: /* char banking */ |
| 277 | 338 | data &= 0xfe; |
| 278 | | page ^= ( cmd << 1 ); |
| 279 | | ppu2c0x_set_videorom_bank( ppu, page, 2, 0x180 + data, 64 ); |
| 339 | page ^= (cmd << 1); |
| 340 | set_videorom_bank(space->machine, page, 2, 0x180 + data, 1); |
| 280 | 341 | break; |
| 281 | 342 | |
| 282 | 343 | case 2: /* char banking */ |
| r5325 | r5326 | |
| 284 | 345 | case 4: /* char banking */ |
| 285 | 346 | case 5: /* char banking */ |
| 286 | 347 | page ^= cmd + 2; |
| 287 | | ppu2c0x_set_videorom_bank( ppu, page, 1, 0x180 + data, 64 ); |
| 348 | set_videorom_bank(space->machine, page, 1, 0x180 + data, 1); |
| 288 | 349 | break; |
| 289 | 350 | |
| 290 | 351 | case 6: /* program banking */ |
| 291 | 352 | { |
| 292 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 293 | | UINT8 *src = memory_region( space->machine, "user1" ); |
| 294 | | if ( multigam3_mmc3_command & 0x40 ) |
| 353 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 354 | UINT8 *src = memory_region(space->machine, "user1"); |
| 355 | if (multigam3_mmc3_command & 0x40) |
| 295 | 356 | { |
| 296 | 357 | /* high bank */ |
| 297 | 358 | multigam3_mmc3_banks[0] = data & 0x1f; |
| 298 | | bank = ( multigam3_mmc3_banks[0] ) * 0x2000 + 0xa0000; |
| 359 | bank = (multigam3_mmc3_banks[0]) * 0x2000 + 0xa0000; |
| 299 | 360 | |
| 300 | | memcpy( &prg[0x0c000], &src[bank], 0x2000 ); |
| 301 | | memcpy( &prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000 ); |
| 361 | memcpy(&prg[0x0c000], &src[bank], 0x2000); |
| 362 | memcpy(&prg[0x08000], &src[0xa0000 + 0x3c000], 0x2000); |
| 302 | 363 | } |
| 303 | 364 | else |
| 304 | 365 | { |
| 305 | 366 | /* low bank */ |
| 306 | 367 | multigam3_mmc3_banks[0] = data & 0x1f; |
| 307 | | bank = ( multigam3_mmc3_banks[0] ) * 0x2000 + 0xa0000; |
| 368 | bank = (multigam3_mmc3_banks[0]) * 0x2000 + 0xa0000; |
| 308 | 369 | |
| 309 | | memcpy( &prg[0x08000], &src[bank], 0x2000 ); |
| 310 | | memcpy( &prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000 ); |
| 370 | memcpy(&prg[0x08000], &src[bank], 0x2000); |
| 371 | memcpy(&prg[0x0c000], &src[0xa0000 + 0x3c000], 0x2000); |
| 311 | 372 | } |
| 312 | 373 | } |
| 313 | 374 | break; |
| r5325 | r5326 | |
| 315 | 376 | case 7: /* program banking */ |
| 316 | 377 | { |
| 317 | 378 | /* mid bank */ |
| 318 | | UINT8 *prg = memory_region( space->machine, "maincpu" ); |
| 319 | | UINT8 *src = memory_region( space->machine, "user1" ); |
| 379 | UINT8 *prg = memory_region(space->machine, "maincpu"); |
| 380 | UINT8 *src = memory_region(space->machine, "user1"); |
| 320 | 381 | |
| 321 | 382 | multigam3_mmc3_banks[1] = data & 0x1f; |
| 322 | 383 | bank = multigam3_mmc3_banks[1] * 0x2000 + 0xa0000; |
| 323 | 384 | |
| 324 | | memcpy( &prg[0x0a000], &src[bank], 0x2000 ); |
| 385 | memcpy(&prg[0x0a000], &src[bank], 0x2000); |
| 325 | 386 | } |
| 326 | 387 | break; |
| 327 | 388 | } |
| r5325 | r5326 | |
| 329 | 390 | break; |
| 330 | 391 | |
| 331 | 392 | case 0x2000: /* mirroring */ |
| 332 | | if( !multigam3_mmc3_4screen ) |
| 393 | if (!multigam3_mmc3_4screen) |
| 333 | 394 | { |
| 334 | | if ( data & 0x40 ) |
| 335 | | ppu2c0x_set_mirroring( ppu, PPU_MIRROR_HIGH ); |
| 395 | if (data & 0x40) |
| 396 | set_mirroring(PPU_MIRROR_HIGH); |
| 336 | 397 | else |
| 337 | | ppu2c0x_set_mirroring( ppu, ( data & 1 ) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT ); |
| 398 | set_mirroring((data & 1) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT); |
| 338 | 399 | } |
| 339 | 400 | break; |
| 340 | 401 | |
| r5325 | r5326 | |
| 351 | 412 | break; |
| 352 | 413 | |
| 353 | 414 | case 0x6000: /* disable irqs */ |
| 354 | | ppu2c0x_set_scanline_callback( ppu, 0 ); |
| 415 | ppu2c0x_set_scanline_callback(ppu, 0); |
| 355 | 416 | break; |
| 356 | 417 | |
| 357 | 418 | case 0x6001: /* enable irqs */ |
| 358 | | ppu2c0x_set_scanline_callback( ppu, multigam3_mmc3_scanline_cb ); |
| 419 | ppu2c0x_set_scanline_callback(ppu, multigam3_mmc3_scanline_cb); |
| 359 | 420 | break; |
| 360 | 421 | } |
| 361 | 422 | } |
| 362 | 423 | |
| 363 | 424 | static void multigam_init_smb3(running_machine *machine) |
| 364 | 425 | { |
| 365 | | UINT8* dst = memory_region( machine, "maincpu" ); |
| 366 | | UINT8* src = memory_region( machine, "user1" ); |
| 426 | UINT8* dst = memory_region(machine, "maincpu"); |
| 427 | UINT8* src = memory_region(machine, "user1"); |
| 367 | 428 | |
| 368 | 429 | memcpy(&dst[0x8000], &src[0xa0000 + 0x3c000], 0x4000); |
| 369 | 430 | memcpy(&dst[0xc000], &src[0xa0000 + 0x3c000], 0x4000); |
| r5325 | r5326 | |
| 383 | 444 | |
| 384 | 445 | static WRITE8_HANDLER(multigm3_mapper2_w) |
| 385 | 446 | { |
| 386 | | if ( multigam_game_gfx_bank & 0x80 ) |
| 447 | if (multigam_game_gfx_bank & 0x80) |
| 387 | 448 | { |
| 388 | | const device_config *ppu = devtag_get_device(space->machine, "ppu"); |
| 389 | | ppu2c0x_set_videorom_bank( ppu, 0, 8, (multigam_game_gfx_bank & 0xfc) + (data & 0x3), 512 ); |
| 449 | set_videorom_bank(space->machine, 0, 8, (multigam_game_gfx_bank & 0xfc) + (data & 0x3), 8); |
| 390 | 450 | } |
| 391 | 451 | else |
| 392 | 452 | { |
| 393 | | logerror( "Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data ); |
| 453 | logerror("Unmapped multigam_mapper2_w: offset = %04X, data = %02X\n", offset, data); |
| 394 | 454 | } |
| 395 | 455 | }; |
| 396 | 456 | |
| 397 | 457 | static WRITE8_HANDLER(multigm3_switch_prg_rom) |
| 398 | 458 | { |
| 399 | 459 | /* switch PRG rom */ |
| 400 | | UINT8* dst = memory_region( space->machine, "maincpu" ); |
| 401 | | UINT8* src = memory_region( space->machine, "user1" ); |
| 460 | UINT8* dst = memory_region(space->machine, "maincpu"); |
| 461 | UINT8* src = memory_region(space->machine, "user1"); |
| 402 | 462 | |
| 403 | | if ( data == 0xa8 ) |
| 463 | if (data == 0xa8) |
| 404 | 464 | { |
| 405 | 465 | multigam_init_smb3(space->machine); |
| 406 | 466 | return; |
| r5325 | r5326 | |
| 411 | 471 | memory_set_bankptr(space->machine, 1, memory_region(space->machine, "maincpu") + 0x6000); |
| 412 | 472 | } |
| 413 | 473 | |
| 414 | | if ( data & 0x80 ) |
| 474 | if (data & 0x80) |
| 415 | 475 | { |
| 416 | | if ( data & 0x01 ) |
| 476 | if (data & 0x01) |
| 417 | 477 | { |
| 418 | 478 | data &= ~0x01; |
| 419 | 479 | } |
| 420 | | memcpy( &dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000 ); |
| 480 | memcpy(&dst[0x8000], &src[(data & 0x7f) * 0x4000], 0x8000); |
| 421 | 481 | } |
| 422 | 482 | else |
| 423 | 483 | { |
| 424 | | memcpy( &dst[0x8000], &src[data*0x4000], 0x4000 ); |
| 425 | | memcpy( &dst[0xc000], &src[data*0x4000], 0x4000 ); |
| 484 | memcpy(&dst[0x8000], &src[data*0x4000], 0x4000); |
| 485 | memcpy(&dst[0xc000], &src[data*0x4000], 0x4000); |
| 426 | 486 | } |
| 427 | 487 | }; |
| 428 | 488 | |
| r5325 | r5326 | |
| 530 | 590 | |
| 531 | 591 | static PALETTE_INIT( multigam ) |
| 532 | 592 | { |
| 533 | | ppu2c0x_init_palette(machine, 0 ); |
| 593 | ppu2c0x_init_palette(machine, 0); |
| 534 | 594 | } |
| 535 | 595 | |
| 536 | 596 | static void ppu_irq( const device_config *device, int *ppu_regs ) |
| 537 | 597 | { |
| 538 | | cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE ); |
| 598 | cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); |
| 539 | 599 | } |
| 540 | 600 | |
| 541 | 601 | /* our ppu interface */ |
| r5325 | r5326 | |
| 555 | 615 | static VIDEO_UPDATE( multigam ) |
| 556 | 616 | { |
| 557 | 617 | /* render the ppu */ |
| 558 | | ppu2c0x_render( devtag_get_device(screen->machine, "ppu"), bitmap, 0, 0, 0, 0 ); |
| 618 | ppu2c0x_render(devtag_get_device(screen->machine, "ppu"), bitmap, 0, 0, 0, 0); |
| 559 | 619 | return 0; |
| 560 | 620 | } |
| 561 | 621 | |
| r5325 | r5326 | |
| 580 | 640 | multigm3_switch_prg_rom(space, 0, 0x01 ); |
| 581 | 641 | }; |
| 582 | 642 | |
| 643 | static MACHINE_START( multigam ) |
| 644 | { |
| 645 | nt_ram = auto_alloc_array(machine, UINT8, 0x1000); |
| 646 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, multigam_nt_r, multigam_nt_w); |
| 647 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x1fff, 0, 0, SMH_BANK(1), 0); |
| 648 | memory_set_bankptr(machine, 1, memory_region(machine, "gfx1")); |
| 649 | } |
| 583 | 650 | |
| 651 | static MACHINE_START( multigm3 ) |
| 652 | { |
| 653 | nt_ram = auto_alloc_array(machine, UINT8, 0x1000); |
| 654 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x2000, 0x3eff, 0, 0, multigam_nt_r, multigam_nt_w); |
| 655 | |
| 656 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0000, 0x03ff, 0, 0, SMH_BANK(1), 0); |
| 657 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0400, 0x07ff, 0, 0, SMH_BANK(2), 0); |
| 658 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0800, 0x0bff, 0, 0, SMH_BANK(3), 0); |
| 659 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x0c00, 0x0fff, 0, 0, SMH_BANK(4), 0); |
| 660 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1000, 0x13ff, 0, 0, SMH_BANK(5), 0); |
| 661 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1400, 0x17ff, 0, 0, SMH_BANK(6), 0); |
| 662 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1800, 0x1bff, 0, 0, SMH_BANK(7), 0); |
| 663 | memory_install_readwrite8_handler(cpu_get_address_space(cputag_get_cpu(machine, "ppu"), ADDRESS_SPACE_PROGRAM), 0x1c00, 0x1fff, 0, 0, SMH_BANK(8), 0); |
| 664 | }; |
| 665 | |
| 584 | 666 | static MACHINE_DRIVER_START( multigam ) |
| 585 | 667 | /* basic machine hardware */ |
| 586 | 668 | MDRV_CPU_ADD("maincpu", N2A03, N2A03_DEFAULTCLOCK) |
| 587 | 669 | MDRV_CPU_PROGRAM_MAP(multigam_map) |
| 588 | 670 | |
| 589 | 671 | MDRV_MACHINE_RESET( multigam ) |
| 672 | MDRV_MACHINE_START( multigam ) |
| 590 | 673 | |
| 591 | 674 | /* video hardware */ |
| 592 | 675 | MDRV_SCREEN_ADD("screen", RASTER) |
| r5325 | r5326 | |
| 620 | 703 | MDRV_CPU_MODIFY("maincpu") |
| 621 | 704 | MDRV_CPU_PROGRAM_MAP(multigm3_map) |
| 622 | 705 | |
| 706 | MDRV_MACHINE_START( multigm3 ) |
| 623 | 707 | MDRV_MACHINE_RESET( multigm3 ) |
| 624 | 708 | MACHINE_DRIVER_END |
| 625 | 709 | |
| r5325 | r5326 | |
| 704 | 788 | static DRIVER_INIT( multigam ) |
| 705 | 789 | { |
| 706 | 790 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 707 | | multigam_switch_prg_rom( space, 0x0, 0x01 ); |
| 791 | multigam_switch_prg_rom(space, 0x0, 0x01); |
| 708 | 792 | } |
| 709 | 793 | |
| 710 | 794 | static void multigm3_decrypt(UINT8* mem, int memsize, const UINT8* decode_nibble) |
| r5325 | r5326 | |
| 727 | 811 | |
| 728 | 812 | multigmc_mmc3_6000_ram = auto_alloc_array(machine, UINT8, 0x2000); |
| 729 | 813 | |
| 730 | | multigam_switch_prg_rom( space, 0x0, 0x01 ); |
| 814 | multigam_switch_prg_rom(space, 0x0, 0x01); |
| 731 | 815 | } |
| 732 | 816 | |
| 733 | 817 | GAME( 1992, multigam, 0, multigam, multigam, multigam, ROT0, "unknown", "Multi Game (set 1)", 0 ) |
src/mess/machine/nes.c
| r5325 | r5326 | |
| 70 | 70 | return state->cart; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | | static void init_nes_core (running_machine *machine) |
| 73 | static void init_nes_core(running_machine *machine) |
| 74 | 74 | { |
| 75 | 75 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 76 | 76 | |
| r5325 | r5326 | |
| 157 | 157 | } |
| 158 | 158 | else |
| 159 | 159 | { |
| 160 | | logerror ("Mapper %d is not yet supported, defaulting to no mapper.\n",nes.mapper); |
| 160 | logerror("Mapper %d is not yet supported, defaulting to no mapper.\n",nes.mapper); |
| 161 | 161 | mmc_write_low = mmc_write_mid = mmc_write = NULL; |
| 162 | 162 | mmc_read_low = NULL; |
| 163 | 163 | } |
| r5325 | r5326 | |
| 171 | 171 | /* memory subsystem is set up. When this routine is called */ |
| 172 | 172 | /* everything is ready, so we can just copy over the data */ |
| 173 | 173 | /* we loaded before. */ |
| 174 | | memcpy (nes_battery_ram, battery_data, BATTERY_SIZE); |
| 174 | memcpy(nes_battery_ram, battery_data, BATTERY_SIZE); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | int nes_ppu_vidaccess( const device_config *device, int address, int data ) |
| r5325 | r5326 | |
| 199 | 199 | nes.mid_ram_enable = 1; |
| 200 | 200 | |
| 201 | 201 | /* Reset the mapper variables. Will also mark the char-gen ram as dirty */ |
| 202 | | mapper_reset (machine, nes.mapper); |
| 202 | mapper_reset(machine, nes.mapper); |
| 203 | 203 | |
| 204 | 204 | /* Reset the serial input ports */ |
| 205 | 205 | in_0.shift = 0; |
| 206 | 206 | in_1.shift = 0; |
| 207 | 207 | |
| 208 | | cputag_reset( machine, "maincpu" ); |
| 208 | cputag_reset(machine, "maincpu"); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | MACHINE_START( nes ) |
| r5325 | r5326 | |
| 223 | 223 | |
| 224 | 224 | |
| 225 | 225 | |
| 226 | | READ8_HANDLER ( nes_IN0_r ) |
| 226 | READ8_HANDLER( nes_IN0_r ) |
| 227 | 227 | { |
| 228 | 228 | nes_state *state = space->machine->driver_data; |
| 229 | 229 | int ret; |
| r5325 | r5326 | |
| 242 | 242 | UINT32 pix, color_base; |
| 243 | 243 | |
| 244 | 244 | /* get the pixel at the gun position */ |
| 245 | | pix = ppu2c0x_get_pixel( state->ppu, x, y ); |
| 245 | pix = ppu2c0x_get_pixel(state->ppu, x, y); |
| 246 | 246 | |
| 247 | 247 | /* get the color base from the ppu */ |
| 248 | | color_base = ppu2c0x_get_colorbase( state->ppu ); |
| 248 | color_base = ppu2c0x_get_colorbase(state->ppu); |
| 249 | 249 | |
| 250 | 250 | /* look at the screen and see if the cursor is over a bright pixel */ |
| 251 | | if ( ( pix == color_base + 0x20 ) || ( pix == color_base + 0x30 ) || |
| 252 | | ( pix == color_base + 0x33 ) || ( pix == color_base + 0x34 ) ) |
| 251 | if ((pix == color_base + 0x20) || (pix == color_base + 0x30) || |
| 252 | (pix == color_base + 0x33) || (pix == color_base + 0x34)) |
| 253 | 253 | { |
| 254 | 254 | ret &= ~0x08; /* sprite hit */ |
| 255 | 255 | } |
| r5325 | r5326 | |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | if (LOG_JOY) |
| 264 | | logerror ("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc( space->cpu ), in_0.shift, in_0.i0); |
| 264 | logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_0.shift, in_0.i0); |
| 265 | 265 | |
| 266 | 266 | in_0.shift++; |
| 267 | 267 | return ret; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | | READ8_HANDLER ( nes_IN1_r ) |
| 270 | READ8_HANDLER( nes_IN1_r ) |
| 271 | 271 | { |
| 272 | 272 | nes_state *state = space->machine->driver_data; |
| 273 | 273 | int ret; |
| r5325 | r5326 | |
| 287 | 287 | UINT32 pix, color_base; |
| 288 | 288 | |
| 289 | 289 | /* get the pixel at the gun position */ |
| 290 | | pix = ppu2c0x_get_pixel( state->ppu, x, y ); |
| 290 | pix = ppu2c0x_get_pixel(state->ppu, x, y); |
| 291 | 291 | |
| 292 | 292 | /* get the color base from the ppu */ |
| 293 | | color_base = ppu2c0x_get_colorbase( state->ppu ); |
| 293 | color_base = ppu2c0x_get_colorbase(state->ppu); |
| 294 | 294 | |
| 295 | 295 | /* look at the screen and see if the cursor is over a bright pixel */ |
| 296 | | if ( ( pix == color_base + 0x20 ) || ( pix == color_base + 0x30 ) || |
| 297 | | ( pix == color_base + 0x33 ) || ( pix == color_base + 0x34 ) ) |
| 296 | if ((pix == color_base + 0x20) || (pix == color_base + 0x30) || |
| 297 | (pix == color_base + 0x33) || (pix == color_base + 0x34)) |
| 298 | 298 | { |
| 299 | 299 | ret &= ~0x08; /* sprite hit */ |
| 300 | 300 | } |
| r5325 | r5326 | |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | if (LOG_JOY) |
| 321 | | logerror ("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc( space->cpu ), in_1.shift, in_1.i0); |
| 321 | logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_1.shift, in_1.i0); |
| 322 | 322 | |
| 323 | 323 | in_1.shift++; |
| 324 | 324 | return ret; |
| r5325 | r5326 | |
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | | WRITE8_HANDLER ( nes_IN0_w ) |
| 396 | WRITE8_HANDLER( nes_IN0_w ) |
| 397 | 397 | { |
| 398 | 398 | int cfg; |
| 399 | 399 | nes_input in_2; |
| r5325 | r5326 | |
| 402 | 402 | if (data & 0x01) return; |
| 403 | 403 | |
| 404 | 404 | if (LOG_JOY) |
| 405 | | logerror ("joy 0 bits read: %d\n", in_0.shift); |
| 405 | logerror("joy 0 bits read: %d\n", in_0.shift); |
| 406 | 406 | |
| 407 | 407 | /* Toggling bit 0 high then low resets both controllers */ |
| 408 | 408 | in_0.shift = 0; |
| r5325 | r5326 | |
| 428 | 428 | |
| 429 | 429 | |
| 430 | 430 | |
| 431 | | WRITE8_HANDLER ( nes_IN1_w ) |
| 431 | WRITE8_HANDLER( nes_IN1_w ) |
| 432 | 432 | { |
| 433 | 433 | } |
| 434 | 434 | |
| r5325 | r5326 | |
| 450 | 450 | |
| 451 | 451 | if ((magic[0] != 'N') || (magic[1] != 'E') || (magic[2] != 'S')) |
| 452 | 452 | { |
| 453 | | logerror("BAD section hit during LOAD ROM.\n"); |
| 453 | logerror("%s is NOT a file in iNES format.\n", image_filename(image)); |
| 454 | 454 | return INIT_FAIL; |
| 455 | 455 | } |
| 456 | 456 | |
| r5325 | r5326 | |
| 458 | 458 | |
| 459 | 459 | if (mapinfo) |
| 460 | 460 | { |
| 461 | | if (4 == sscanf(mapinfo,"%d %d %d %d",&mapint1,&mapint2,&mapint3,&mapint4)) |
| 461 | if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4)) |
| 462 | 462 | { |
| 463 | 463 | nes.mapper = mapint1; |
| 464 | 464 | local_options = mapint2; |
| r5325 | r5326 | |
| 481 | 481 | { |
| 482 | 482 | // image_extrainfo() resets the file position back to start. |
| 483 | 483 | // Let's skip past the magic header once again. |
| 484 | | image_fseek (image, 4, SEEK_SET); |
| 484 | image_fseek(image, 4, SEEK_SET); |
| 485 | 485 | |
| 486 | | image_fread (image, &nes.prg_chunks, 1); |
| 487 | | image_fread (image, &nes.chr_chunks, 1); |
| 486 | image_fread(image, &nes.prg_chunks, 1); |
| 487 | image_fread(image, &nes.chr_chunks, 1); |
| 488 | 488 | /* Read the first ROM option byte (offset 6) */ |
| 489 | | image_fread (image, &m, 1); |
| 489 | image_fread(image, &m, 1); |
| 490 | 490 | |
| 491 | 491 | /* Interpret the iNES header flags */ |
| 492 | 492 | nes.mapper = (m & 0xf0) >> 4; |
| r5325 | r5326 | |
| 494 | 494 | |
| 495 | 495 | |
| 496 | 496 | /* Read the second ROM option byte (offset 7) */ |
| 497 | | image_fread (image, &m, 1); |
| 497 | image_fread(image, &m, 1); |
| 498 | 498 | |
| 499 | 499 | /* Check for skanky headers */ |
| 500 | | image_fread (image, &skank, 8); |
| 500 | image_fread(image, &skank, 8); |
| 501 | 501 | |
| 502 | 502 | /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */ |
| 503 | 503 | /* We only check the first 4 unused bytes for now */ |
| r5325 | r5326 | |
| 525 | 525 | if (nes.four_screen_vram) logerror("-- 4-screen VRAM\n"); |
| 526 | 526 | |
| 527 | 527 | /* Free the regions that were allocated by the ROM loader */ |
| 528 | | memory_region_free (image->machine, "maincpu"); |
| 529 | | memory_region_free (image->machine, "gfx1"); |
| 528 | memory_region_free(image->machine, "maincpu"); |
| 529 | memory_region_free(image->machine, "gfx1"); |
| 530 | 530 | |
| 531 | 531 | /* Allocate them again with the proper size */ |
| 532 | 532 | memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000,0); |
| r5325 | r5326 | |
| 539 | 539 | nes.wram = memory_region(image->machine, "user1"); |
| 540 | 540 | |
| 541 | 541 | /* Position past the header */ |
| 542 | | image_fseek (image, 16, SEEK_SET); |
| 542 | image_fseek(image, 16, SEEK_SET); |
| 543 | 543 | |
| 544 | 544 | /* Load the 0x200 byte trainer at 0x7000 if it exists */ |
| 545 | 545 | if (nes.trainer) |
| 546 | 546 | { |
| 547 | | image_fread (image, &nes.wram[0x1000], 0x200); |
| 547 | image_fread(image, &nes.wram[0x1000], 0x200); |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /* Read in the program chunks */ |
| 551 | 551 | if (nes.prg_chunks == 1) |
| 552 | 552 | { |
| 553 | | image_fread (image, &nes.rom[0x14000], 0x4000); |
| 553 | image_fread(image, &nes.rom[0x14000], 0x4000); |
| 554 | 554 | /* Mirror this bank into $8000 */ |
| 555 | | memcpy (&nes.rom[0x10000], &nes.rom [0x14000], 0x4000); |
| 555 | memcpy(&nes.rom[0x10000], &nes.rom [0x14000], 0x4000); |
| 556 | 556 | } |
| 557 | 557 | else |
| 558 | | image_fread (image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks); |
| 558 | image_fread(image, &nes.rom[0x10000], 0x4000 * nes.prg_chunks); |
| 559 | 559 | |
| 560 | 560 | #if SPLIT_PRG |
| 561 | 561 | { |
| r5325 | r5326 | |
| 564 | 564 | |
| 565 | 565 | for (i = 0; i < nes.prg_chunks; i ++) |
| 566 | 566 | { |
| 567 | | sprintf (outname, "%s.p%d", battery_name, i); |
| 568 | | prgout = fopen (outname, "wb"); |
| 567 | sprintf(outname, "%s.p%d", battery_name, i); |
| 568 | prgout = fopen(outname, "wb"); |
| 569 | 569 | if (prgout) |
| 570 | 570 | { |
| 571 | | fwrite (&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout); |
| 572 | | fclose (prgout); |
| 571 | fwrite(&nes.rom[0x10000 + 0x4000 * i], 1, 0x4000, prgout); |
| 572 | fclose(prgout); |
| 573 | 573 | } |
| 574 | 574 | } |
| 575 | 575 | } |
| r5325 | r5326 | |
| 582 | 582 | /* Read in any chr chunks */ |
| 583 | 583 | if (nes.chr_chunks > 0) |
| 584 | 584 | { |
| 585 | | image_fread (image, nes.vrom, nes.chr_chunks * 0x2000); |
| 585 | image_fread(image, nes.vrom, nes.chr_chunks * 0x2000); |
| 586 | 586 | if (nes.mapper == 2) |
| 587 | 587 | logerror("Warning: VROM has been found in VRAM-based mapper. Either the mapper is set wrong or the ROM image is incorrect.\n"); |
| 588 | 588 | } |
| r5325 | r5326 | |
| 634 | 634 | if ((magic[0] == 'F') && (magic[1] == 'D') && (magic[2] == 'S')) |
| 635 | 635 | { |
| 636 | 636 | /* Skip past the redundant header */ |
| 637 | | image_fseek (image, 0x10, SEEK_SET); |
| 637 | image_fseek(image, 0x10, SEEK_SET); |
| 638 | 638 | } |
| 639 | 639 | else |
| 640 | 640 | /* otherwise, point to the start of the image */ |
| 641 | | image_fseek (image, 0, SEEK_SET); |
| 641 | image_fseek(image, 0, SEEK_SET); |
| 642 | 642 | |
| 643 | 643 | /* read in all the sides */ |
| 644 | | while (!image_feof (image)) |
| 644 | while (!image_feof(image)) |
| 645 | 645 | { |
| 646 | 646 | nes_fds.sides ++; |
| 647 | 647 | nes_fds.data = image_realloc(image, nes_fds.data, nes_fds.sides * 65500); |
| 648 | 648 | if (!nes_fds.data) |
| 649 | 649 | return INIT_FAIL; |
| 650 | | image_fread (image, nes_fds.data + ((nes_fds.sides - 1) * 65500), 65500); |
| 650 | image_fread(image, nes_fds.data + ((nes_fds.sides - 1) * 65500), 65500); |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | logerror("Number of sides: %d\n", nes_fds.sides); |