src/mame/machine/snes.c
| r7660 | r7661 | |
| 2535 | 2535 | |
| 2536 | 2536 | *************************************/ |
| 2537 | 2537 | |
| 2538 | | static int dma_abus_valid( UINT32 address ) |
| 2538 | INLINE int dma_abus_valid( UINT32 address ) |
| 2539 | 2539 | { |
| 2540 | 2540 | if((address & 0x40ff00) == 0x2100) return 0; //$[00-3f|80-bf]:[2100-21ff] |
| 2541 | 2541 | if((address & 0x40fe00) == 0x4000) return 0; //$[00-3f|80-bf]:[4000-41ff] |
| r7660 | r7661 | |
| 2545 | 2545 | return 1; |
| 2546 | 2546 | } |
| 2547 | 2547 | |
| 2548 | INLINE UINT8 snes_abus_read( const address_space *space, UINT32 abus ) |
| 2549 | { |
| 2550 | if (!dma_abus_valid(abus)) |
| 2551 | return 0; |
| 2552 | |
| 2553 | return memory_read_byte(space, abus); |
| 2554 | } |
| 2555 | |
| 2548 | 2556 | INLINE void snes_dma_transfer( const address_space *space, UINT8 dma, UINT32 abus, UINT16 bbus ) |
| 2549 | 2557 | { |
| 2550 | 2558 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 2551 | | UINT32 src, dst; |
| 2552 | 2559 | |
| 2553 | 2560 | if (state->dma_channel[dma].dmap & 0x80) /* PPU->CPU */ |
| 2554 | 2561 | { |
| r7660 | r7661 | |
| 2564 | 2571 | if (!dma_abus_valid(abus)) |
| 2565 | 2572 | return; |
| 2566 | 2573 | |
| 2567 | | src = bbus; dst = abus; |
| 2574 | memory_write_byte(space, abus, memory_read_byte(space, bbus)); |
| 2575 | return; |
| 2568 | 2576 | } |
| 2569 | 2577 | } |
| 2570 | 2578 | else /* CPU->PPU */ |
| r7660 | r7661 | |
| 2578 | 2586 | } |
| 2579 | 2587 | else |
| 2580 | 2588 | { |
| 2581 | | src = abus; dst = bbus; |
| 2589 | memory_write_byte(space, bbus, snes_abus_read(space, abus)); |
| 2590 | return; |
| 2582 | 2591 | } |
| 2583 | 2592 | } |
| 2584 | | |
| 2585 | | memory_write_byte(space, dst, memory_read_byte(space, src)); |
| 2586 | 2593 | } |
| 2587 | 2594 | |
| 2588 | 2595 | /* WIP: These have the advantage to automatically update the address, but then we would need to |
| r7660 | r7661 | |
| 2599 | 2606 | return (state->dma_channel[dma].ibank << 16) | (state->dma_channel[dma].trans_size++); |
| 2600 | 2607 | } |
| 2601 | 2608 | |
| 2602 | | static UINT8 snes_hdma_read( const address_space *space, UINT32 abus ) |
| 2609 | INLINE int is_last_active_channel( running_machine *machine, int dma ) |
| 2603 | 2610 | { |
| 2604 | | if (!dma_abus_valid(abus)) |
| 2605 | | return 0; |
| 2606 | | |
| 2607 | | return memory_read_byte(space, abus); |
| 2608 | | } |
| 2609 | | |
| 2610 | | static int is_last_active_channel( running_machine *machine, int dma ) |
| 2611 | | { |
| 2612 | 2611 | snes_state *state = (snes_state *)machine->driver_data; |
| 2613 | 2612 | int i; |
| 2614 | 2613 | |
| r7660 | r7661 | |
| 2627 | 2626 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 2628 | 2627 | UINT32 abus = snes_get_hdma_addr(space->machine, dma); |
| 2629 | 2628 | |
| 2630 | | state->dma_channel[dma].hdma_line_counter = snes_hdma_read(space, abus); |
| 2629 | state->dma_channel[dma].hdma_line_counter = snes_abus_read(space, abus); |
| 2631 | 2630 | |
| 2632 | 2631 | if (state->dma_channel[dma].dmap & 0x40) |
| 2633 | 2632 | { |
| r7660 | r7661 | |
| 2636 | 2635 | otherwise expected */ |
| 2637 | 2636 | |
| 2638 | 2637 | abus = snes_get_hdma_addr(space->machine, dma); |
| 2639 | | state->dma_channel[dma].trans_size = snes_hdma_read(space, abus) << 8; |
| 2638 | state->dma_channel[dma].trans_size = snes_abus_read(space, abus) << 8; |
| 2640 | 2639 | |
| 2641 | 2640 | if (state->dma_channel[dma].hdma_line_counter || !is_last_active_channel(space->machine, dma)) |
| 2642 | 2641 | { |
| 2643 | 2642 | // we enter here if we have more transfers to be done or if there are other active channels after this one |
| 2644 | 2643 | abus = snes_get_hdma_addr(space->machine, dma); |
| 2645 | 2644 | state->dma_channel[dma].trans_size >>= 8; |
| 2646 | | state->dma_channel[dma].trans_size |= snes_hdma_read(space, abus) << 8; |
| 2645 | state->dma_channel[dma].trans_size |= snes_abus_read(space, abus) << 8; |
| 2647 | 2646 | } |
| 2648 | 2647 | } |
| 2649 | 2648 | |
src/mame/video/snes.c
| r7660 | r7661 | |
| 298 | 298 | /***************************************** |
| 299 | 299 | * snes_draw_tile() |
| 300 | 300 | * |
| 301 | | * Get pixel color with variable bit planes |
| 302 | | * from snes_vram and draw the tiles by |
| 303 | | * calling the appropriate routine |
| 301 | * Draw 8 pixels from the expected tile |
| 302 | * by reading the color planes from vram |
| 303 | * and by calling the appropriate routine |
| 304 | * (depending on layer and resolution) |
| 304 | 305 | *****************************************/ |
| 305 | 306 | |
| 306 | | INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, int tile_size, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
| 307 | INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires ) |
| 307 | 308 | { |
| 308 | 309 | UINT8 plane[8]; |
| 309 | | INT16 ii, jj, start_pixel; |
| 310 | | int tile, x_mos; |
| 310 | INT16 ii, jj; |
| 311 | int x_mos; |
| 311 | 312 | |
| 312 | | start_pixel = x; |
| 313 | for (ii = 0; ii < planes / 2; ii++) |
| 314 | { |
| 315 | plane[2 * ii + 0] = snes_vram[(tileaddr + 16 * ii + 0) % SNES_VRAM_SIZE]; |
| 316 | plane[2 * ii + 1] = snes_vram[(tileaddr + 16 * ii + 1) % SNES_VRAM_SIZE]; |
| 317 | } |
| 313 | 318 | |
| 314 | | /* if 8x8 tile we draw once; if 16x16 we draw twice */ |
| 315 | | for (tile = 0; tile < (1 << tile_size); tile++) |
| 319 | for (ii = x; ii < (x + 8); ii++) |
| 316 | 320 | { |
| 317 | | for (ii = 0; ii < planes / 2; ii++) |
| 318 | | { |
| 319 | | plane[2 * ii] = snes_vram[tileaddr + 16 * ii]; |
| 320 | | plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1]; |
| 321 | | } |
| 321 | UINT8 colour = 0; |
| 322 | UINT8 mosaic = snes_ppu.layer[layer].mosaic_enabled; |
| 322 | 323 | |
| 323 | | for (ii = x; ii < (x + 8); ii++) |
| 324 | | { |
| 325 | | UINT8 colour = 0; |
| 326 | | UINT8 mosaic = snes_ppu.layer[layer].mosaic_enabled; |
| 327 | | |
| 328 | 324 | #ifdef SNES_LAYER_DEBUG |
| 329 | | if (debug_options.mosaic_disabled) |
| 330 | | mosaic = 0; |
| 325 | if (debug_options.mosaic_disabled) |
| 326 | mosaic = 0; |
| 331 | 327 | #endif /* SNES_LAYER_DEBUG */ |
| 332 | 328 | |
| 333 | | if (flip) |
| 329 | if (flip) |
| 330 | { |
| 331 | for (jj = 0; jj < planes; jj++) |
| 332 | colour |= BIT(plane[jj], ii - x) ? (1 << jj) : 0; |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | for (jj = 0; jj < planes; jj++) |
| 337 | colour |= BIT(plane[jj], 7 - (ii - x)) ? (1 << jj) : 0; |
| 338 | } |
| 339 | |
| 340 | if (layer == SNES_OAM) |
| 341 | snes_draw_oamtile(ii, colour, pal, priority); |
| 342 | else if (!hires) |
| 343 | { |
| 344 | if (mosaic) |
| 334 | 345 | { |
| 335 | | for (jj = 0; jj < planes; jj++) |
| 336 | | colour |= BIT(plane[jj], ii - x) ? (1 << jj) : 0; |
| 346 | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++) |
| 347 | snes_draw_bgtile_lores(layer, ii + x_mos, colour, pal, direct_colors, priority); |
| 348 | ii += x_mos - 1; |
| 337 | 349 | } |
| 338 | 350 | else |
| 351 | snes_draw_bgtile_lores(layer, ii, colour, pal, direct_colors, priority); |
| 352 | } |
| 353 | else /* hires */ |
| 354 | { |
| 355 | if (mosaic) |
| 339 | 356 | { |
| 340 | | for (jj = 0; jj < planes; jj++) |
| 341 | | colour |= BIT(plane[jj], 7 - (ii - x)) ? (1 << jj) : 0; |
| 357 | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++) |
| 358 | snes_draw_bgtile_hires(layer, ii + x_mos, colour, pal, direct_colors, priority); |
| 359 | ii += x_mos - 1; |
| 342 | 360 | } |
| 343 | | |
| 344 | | if (layer == SNES_OAM) |
| 345 | | snes_draw_oamtile(ii, colour, pal, priority); |
| 346 | | else if (!hires) |
| 347 | | { |
| 348 | | if (mosaic) |
| 349 | | { |
| 350 | | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++) |
| 351 | | snes_draw_bgtile_lores(layer, ii + x_mos, colour, pal, direct_colors, priority); |
| 352 | | ii += x_mos - 1; |
| 353 | | } |
| 354 | | else |
| 355 | | snes_draw_bgtile_lores(layer, ii, colour, pal, direct_colors, priority); |
| 356 | | } |
| 357 | | else /* hires */ |
| 358 | | { |
| 359 | | if (mosaic) |
| 360 | | { |
| 361 | | for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++) |
| 362 | | snes_draw_bgtile_hires(layer, ii + x_mos, colour, pal, direct_colors, priority); |
| 363 | | ii += x_mos - 1; |
| 364 | | } |
| 365 | | else |
| 366 | | snes_draw_bgtile_hires(layer, ii, colour, pal, direct_colors, priority); |
| 367 | | } |
| 361 | else |
| 362 | snes_draw_bgtile_hires(layer, ii, colour, pal, direct_colors, priority); |
| 368 | 363 | } |
| 369 | | |
| 370 | | /* adjust tileaddr & x in case we have to draw again (for 16x16 tiles) */ |
| 371 | | if (!flip) |
| 372 | | tileaddr += (8 * planes); |
| 373 | | else |
| 374 | | tileaddr -= (8 * planes); |
| 375 | | |
| 376 | | x += 8; |
| 377 | 364 | } |
| 378 | 365 | } |
| 379 | 366 | |
| r7660 | r7661 | |
| 425 | 412 | |
| 426 | 413 | INLINE void snes_update_line( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors ) |
| 427 | 414 | { |
| 428 | | UINT32 tmap, tile, xoff, yoff; |
| 429 | | UINT32 charaddr; |
| 430 | | UINT16 ii = 0, vflip, hflip, pal, pal_direct; |
| 415 | UINT32 tmap, tile, xoff, yoff, charaddr, addr; |
| 416 | UINT16 ii = 0, vflip, hflip, pal, pal_direct, tilemap; |
| 417 | UINT8 xscroll, priority; |
| 431 | 418 | INT8 yscroll; |
| 432 | | UINT8 xscroll; |
| 433 | | UINT8 priority; |
| 434 | | UINT32 addr; |
| 435 | | UINT16 tilemap; |
| 436 | | /* scrolling */ |
| 419 | int tile_incr = 0; |
| 437 | 420 | UINT16 opt_bit = (layer == SNES_BG1) ? 13 : (layer == SNES_BG2) ? 14 : 0; |
| 438 | 421 | UINT8 tile_size; |
| 439 | 422 | /* variables depending on color_depth */ |
| r7660 | r7661 | |
| 494 | 477 | case SNES_OPT_MODE6: |
| 495 | 478 | haddr = snes_get_tmap_addr(SNES_BG3, snes_ppu.layer[SNES_BG3].tile_size, snes_ppu.layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((snes_ppu.layer[SNES_BG3].hoffs & 0x3ff) & ~7), (snes_ppu.layer[SNES_BG3].voffs & 0x3ff)); |
| 496 | 479 | vaddr = snes_get_tmap_addr(SNES_BG3, snes_ppu.layer[SNES_BG3].tile_size, snes_ppu.layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((snes_ppu.layer[SNES_BG3].hoffs & 0x3ff) & ~7), (snes_ppu.layer[SNES_BG3].voffs & 0x3ff) + 8); |
| 497 | | hval = snes_vram[haddr] | (snes_vram[haddr + 1] << 8); |
| 498 | | vval = snes_vram[vaddr] | (snes_vram[vaddr + 1] << 8); |
| 480 | hval = snes_vram[haddr % SNES_VRAM_SIZE] | (snes_vram[(haddr + 1) % SNES_VRAM_SIZE] << 8); |
| 481 | vval = snes_vram[vaddr % SNES_VRAM_SIZE] | (snes_vram[(vaddr + 1) % SNES_VRAM_SIZE] << 8); |
| 499 | 482 | if (BIT(hval, opt_bit)) |
| 500 | 483 | xpos = opt_x + (hval & ~7); |
| 501 | 484 | if (BIT(vval, opt_bit)) |
| r7660 | r7661 | |
| 503 | 486 | break; |
| 504 | 487 | case SNES_OPT_MODE4: |
| 505 | 488 | haddr = snes_get_tmap_addr(SNES_BG3, snes_ppu.layer[SNES_BG3].tile_size, snes_ppu.layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((snes_ppu.layer[SNES_BG3].hoffs & 0x3ff) & ~7), (snes_ppu.layer[SNES_BG3].voffs & 0x3ff)); |
| 506 | | hval = snes_vram[haddr] | (snes_vram[haddr + 1] << 8); |
| 489 | hval = snes_vram[haddr % SNES_VRAM_SIZE] | (snes_vram[(haddr + 1) % SNES_VRAM_SIZE] << 8); |
| 507 | 490 | if (BIT(hval, opt_bit)) |
| 508 | 491 | { |
| 509 | 492 | if (!BIT(hval, 15)) |
| r7660 | r7661 | |
| 527 | 510 | ppp = Tile palette. The number of entries in the palette depends on the Mode and the BG. |
| 528 | 511 | cccccccccc = Tile number. |
| 529 | 512 | */ |
| 530 | | tilemap = snes_vram[addr] | (snes_vram[addr + 1] << 8); |
| 513 | tilemap = snes_vram[addr % SNES_VRAM_SIZE] | (snes_vram[(addr + 1) % SNES_VRAM_SIZE] << 8); |
| 531 | 514 | vflip = BIT(tilemap, 15); |
| 532 | 515 | hflip = BIT(tilemap, 14); |
| 533 | 516 | priority = BIT(tilemap, 13) ? priority_a : priority_b; |
| r7660 | r7661 | |
| 566 | 549 | yscroll &= 7; |
| 567 | 550 | |
| 568 | 551 | if (vflip) |
| 569 | | yscroll = -yscroll + 7; |
| 552 | yscroll = 7 - yscroll; |
| 570 | 553 | |
| 571 | 554 | yscroll <<= 1; |
| 572 | 555 | |
| 573 | | if (hires) |
| 556 | /* if we have to draw 16 pixels, set tile_incr and adjust tile for horizontal flip */ |
| 557 | if (tile_size || hires) |
| 574 | 558 | { |
| 575 | | /* adjust tile for horizontal flip */ |
| 576 | 559 | if (hflip) |
| 560 | { |
| 577 | 561 | tile += 1; |
| 562 | tile_incr = -1; // next 8 pixels from previous tile (because of hflip) |
| 563 | } |
| 564 | else |
| 565 | tile_incr = 1; // next 8 pixels from next tile |
| 566 | } |
| 578 | 567 | |
| 568 | if (hires) |
| 569 | { |
| 579 | 570 | /* draw 16 pixels (the routine will automatically send half of them to the mainscreen scanline and half to the subscreen one) */ |
| 580 | | snes_draw_tile(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, (ii - xscroll) * 2, 1, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 571 | snes_draw_tile(color_planes, layer, charaddr + (((tile + 0) & 0x3ff) * 8 * color_planes) + yscroll, (ii - xscroll) * 2, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 572 | snes_draw_tile(color_planes, layer, charaddr + (((tile + tile_incr) & 0x3ff) * 8 * color_planes) + yscroll, (ii - xscroll) * 2 + 8, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 581 | 573 | ii += 8; |
| 582 | 574 | } |
| 583 | 575 | else |
| 584 | 576 | { |
| 585 | | /* adjust tile for horizontal flip */ |
| 586 | | if (tile_size && hflip) |
| 587 | | tile += 1; |
| 577 | snes_draw_tile(color_planes, layer, charaddr + ((tile & 0x3ff) * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 578 | ii += 8; |
| 588 | 579 | |
| 589 | | snes_draw_tile(color_planes, layer, charaddr + (tile * 8 * color_planes) + yscroll, ii - xscroll, tile_size, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 590 | | ii += (8 << tile_size); |
| 580 | if (tile_size) |
| 581 | { |
| 582 | snes_draw_tile(color_planes, layer, charaddr + (((tile + tile_incr) & 0x3ff) * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires); |
| 583 | ii += 8; |
| 584 | } |
| 591 | 585 | } |
| 592 | 586 | } |
| 593 | 587 | } |
| r7660 | r7661 | |
| 698 | 692 | case 0x01: /* Repeat if outside screen area */ |
| 699 | 693 | tx &= 0x3ff; |
| 700 | 694 | ty &= 0x3ff; |
| 701 | | tiled = snes_vram[(((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2] << 7; |
| 702 | | colour = snes_vram[tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1]; |
| 695 | tiled = snes_vram[((((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2) % SNES_VRAM_SIZE] << 7; |
| 696 | colour = snes_vram[(tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1) % SNES_VRAM_SIZE]; |
| 703 | 697 | break; |
| 704 | 698 | case 0x02: /* Single colour backdrop screen if outside screen area */ |
| 705 | 699 | if ((tx >= 0) && (tx < 1024) && (ty >= 0) && (ty < 1024)) |
| 706 | 700 | { |
| 707 | | tiled = snes_vram[(((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2] << 7; |
| 708 | | colour = snes_vram[tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1]; |
| 701 | tiled = snes_vram[((((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2) % SNES_VRAM_SIZE] << 7; |
| 702 | colour = snes_vram[(tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1) % SNES_VRAM_SIZE]; |
| 709 | 703 | } |
| 710 | 704 | else |
| 711 | 705 | colour = 0; |
| 712 | 706 | break; |
| 713 | 707 | case 0x03: /* Character 0x00 repeat if outside screen area */ |
| 714 | 708 | if ((tx >= 0) && (tx < 1024) && (ty >= 0) && (ty < 1024)) |
| 715 | | tiled = snes_vram[(((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2] << 7; |
| 709 | tiled = snes_vram[((((tx >> 3) & 0x7f) + (((ty >> 3) & 0x7f) * 128)) * 2) % SNES_VRAM_SIZE] << 7; |
| 716 | 710 | else |
| 717 | 711 | tiled = 0; |
| 718 | 712 | |
| 719 | | colour = snes_vram[tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1]; |
| 713 | colour = snes_vram[(tiled + ((tx & 0x07) * 2) + ((ty & 0x07) * 16) + 1) % SNES_VRAM_SIZE]; |
| 720 | 714 | break; |
| 721 | 715 | } |
| 722 | 716 | |
| r7660 | r7661 | |
| 1027 | 1021 | if (vflip) |
| 1028 | 1022 | { |
| 1029 | 1023 | ys = height - ys - 1; |
| 1030 | | line = (-1 * line) + 7; |
| 1024 | line = 7 - line; |
| 1031 | 1025 | } |
| 1032 | 1026 | line <<= 1; |
| 1033 | 1027 | tile <<= 5; |
| r7660 | r7661 | |
| 1115 | 1109 | } |
| 1116 | 1110 | #endif /* SNES_LAYER_DEBUG */ |
| 1117 | 1111 | |
| 1118 | | /* OAM tiles have fixed planes (4), fixed tile_size (8x8), no direct color and no hires, but otherwise work the same as BG ones */ |
| 1119 | | snes_draw_tile(4, SNES_OAM, charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, 0, pri, oam_tilelist[tile].hflip, 0, oam_tilelist[tile].pal, 0); |
| 1112 | /* OAM tiles have fixed planes (4), no direct color and no hires, but otherwise work the same as BG ones */ |
| 1113 | snes_draw_tile(4, SNES_OAM, charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, pri, oam_tilelist[tile].hflip, 0, oam_tilelist[tile].pal, 0); |
| 1120 | 1114 | } |
| 1121 | 1115 | } |
| 1122 | 1116 | |