src/mess/video/vdc.c
| r939 | r940 | |
| 53 | 53 | void draw_black_line(int line); |
| 54 | 54 | void draw_overscan_line(int line); |
| 55 | 55 | void pce_refresh_line(int bitmap_line, int line); |
| 56 | | void pce_refresh_sprites(int bitmap_line, int line); |
| 56 | void pce_refresh_sprites(int bitmap_line, int line, UINT8 *drawn); |
| 57 | 57 | void vdc_do_dma(void); |
| 58 | 58 | |
| 59 | 59 | INTERRUPT_GEN( pce_interrupt ) |
| r939 | r940 | |
| 469 | 469 | /* pointer to the name table (Background Attribute Table) in VRAM */ |
| 470 | 470 | UINT8 *bat = &(vdc.vram[nt_row << (v_width+1)]); |
| 471 | 471 | |
| 472 | /* 0 - no sprite and background pixels drawn |
| 473 | 1 - background pixel drawn |
| 474 | otherwise is 2 + sprite# */ |
| 475 | UINT8 drawn[VDC_WPF]; |
| 476 | |
| 472 | 477 | /* Are we in greyscale mode or in color mode? */ |
| 473 | 478 | int color_base = vdc.vce_control & 0x80 ? 512 : 0; |
| 474 | 479 | |
| r939 | r940 | |
| 478 | 483 | int cell_palette; |
| 479 | 484 | int x, c, i; |
| 480 | 485 | |
| 486 | /* clear our priority/sprite collision detection buffer. */ |
| 487 | memset(drawn, 0, VDC_WPF); |
| 488 | |
| 481 | 489 | /* character blanking bit */ |
| 482 | 490 | if(!(vdc.vdc_data[CR].w & CR_BB)) |
| 483 | 491 | { |
| r939 | r940 | |
| 526 | 534 | c &= 0x0F; |
| 527 | 535 | |
| 528 | 536 | if ( phys_x >= 0 && phys_x < vdc.physical_width ) { |
| 537 | drawn[ phys_x ] = c ? 1 : 0; |
| 529 | 538 | line_buffer[ pixel ] = Machine->pens[color_base + vdc.vce_data[c].w]; |
| 530 | 539 | pixel++; |
| 531 | 540 | if ( vdc.physical_width != 512 ) { |
| r939 | r940 | |
| 542 | 551 | /* Sprite rendering is independant of BG drawing! */ |
| 543 | 552 | if(vdc.vdc_data[CR].w & CR_SB) |
| 544 | 553 | { |
| 545 | | pce_refresh_sprites(bitmap_line, line); |
| 554 | pce_refresh_sprites(bitmap_line, line, drawn); |
| 546 | 555 | } |
| 547 | 556 | } |
| 548 | 557 | |
| r939 | r940 | |
| 580 | 589 | } |
| 581 | 590 | } |
| 582 | 591 | |
| 583 | | void pce_refresh_sprites(int bitmap_line, int line) |
| 592 | void pce_refresh_sprites(int bitmap_line, int line, UINT8 *drawn) |
| 584 | 593 | { |
| 585 | 594 | int i; |
| 586 | 595 | UINT8 sprites_drawn=0; |
| 587 | 596 | UINT16 *line_buffer= BITMAP_ADDR16( vdc.bmp, bitmap_line, 86 ); |
| 588 | | /* 0 -> no sprite pixels drawn, otherwise is sprite #+1 */ |
| 589 | | UINT8 drawn[VDC_WPF]; |
| 590 | 597 | |
| 591 | 598 | /* Are we in greyscale mode or in color mode? */ |
| 592 | 599 | int color_base = vdc.vce_control & 0x80 ? 512 : 0; |
| 593 | 600 | |
| 594 | | /* clear our sprite-to-sprite clipping buffer. */ |
| 595 | | memset(drawn, 0, VDC_WPF); |
| 596 | 601 | /* count up: Highest priority is Sprite 0 */ |
| 597 | 602 | for(i=0; i<64; i++) |
| 598 | 603 | { |
| r939 | r940 | |
| 614 | 619 | char buf[16]; |
| 615 | 620 | |
| 616 | 621 | if ((obj_y == -64) || (obj_y > line)) continue; |
| 617 | | if ((obj_x == -32) || (obj_x > vdc.physical_width)) continue; |
| 622 | if ((obj_x == -32) || (obj_x >= vdc.physical_width)) continue; |
| 618 | 623 | |
| 619 | 624 | /* no need to draw an object that's ABOVE where we are. */ |
| 620 | 625 | if((obj_y + obj_h)<line) continue; |
| r939 | r940 | |
| 656 | 661 | { |
| 657 | 662 | if(((obj_x + x)<(vdc.physical_width))&&((obj_x + x)>=0)) |
| 658 | 663 | { |
| 659 | | if ( buf[x] ) |
| 660 | | { |
| 661 | | if(!drawn[obj_x+x]) |
| 662 | | { |
| 663 | | if(priority || (line_buffer[pixel_x] == Machine->pens[color_base + vdc.vce_data[0].w])) { |
| 664 | if ( buf[x] ) { |
| 665 | if( drawn[obj_x+x] < 2 ) { |
| 666 | if(priority || drawn[obj_x+x] == 0 ) { |
| 664 | 667 | line_buffer[pixel_x] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 665 | 668 | if ( vdc.physical_width != 512 ) { |
| 666 | 669 | if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) { |
| 667 | 670 | line_buffer[pixel_x + 1] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 668 | 671 | } |
| 669 | 672 | } |
| 670 | | drawn[obj_x+x]=i+1; |
| 671 | 673 | } |
| 674 | drawn[obj_x+x]=i+2; |
| 672 | 675 | } |
| 673 | | else if (drawn[obj_x+x]==1) |
| 676 | /* Check for sprite #0 collision */ |
| 677 | else if (drawn[obj_x+x]==2) |
| 674 | 678 | { |
| 675 | 679 | if(vdc.vdc_data[CR].w&CR_CC) |
| 676 | 680 | cpunum_set_input_line(0, 0, ASSERT_LINE); |
| r939 | r940 | |
| 697 | 701 | { |
| 698 | 702 | if(((obj_x + x)<(vdc.physical_width))&&((obj_x + x)>=0)) |
| 699 | 703 | { |
| 700 | | if ( buf[x] ) |
| 701 | | { |
| 702 | | if(!drawn[obj_x+x]) |
| 703 | | { |
| 704 | | if(priority || (line_buffer[pixel_x] == Machine->pens[color_base + vdc.vce_data[0].w])) { |
| 704 | if ( buf[x] ) { |
| 705 | if( drawn[obj_x+x] < 2 ) { |
| 706 | if ( priority || drawn[obj_x+x] == 0 ) { |
| 705 | 707 | line_buffer[pixel_x] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 706 | 708 | if ( vdc.physical_width != 512 ) { |
| 707 | 709 | if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) { |
| 708 | 710 | line_buffer[pixel_x + 1] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 709 | 711 | } |
| 710 | 712 | } |
| 711 | | drawn[obj_x + x]=i+1; |
| 712 | 713 | } |
| 714 | drawn[obj_x + x]=i+2; |
| 713 | 715 | } |
| 714 | | else if (drawn[obj_x+x]==1) |
| 715 | | { |
| 716 | /* Check for sprite #0 collision */ |
| 717 | else if ( drawn[obj_x+x] == 2 ) { |
| 716 | 718 | if(vdc.vdc_data[CR].w&CR_CC) |
| 717 | 719 | cpunum_set_input_line(0, 0, ASSERT_LINE); |
| 718 | 720 | vdc.status|=VDC_CR; |
| 719 | | |
| 720 | | |
| 721 | 721 | } |
| 722 | 722 | } |
| 723 | 723 | } |
| r939 | r940 | |
| 729 | 729 | } |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | | conv_obj(obj_i + (cgypos << 2) + (hf ? 0 : 2), obj_l, hf, vf, buf); |
| 733 | | for(x=0;x<16;x++) |
| 734 | | { |
| 735 | | if(((obj_x + 0x10 + x)<(vdc.physical_width))&&((obj_x + 0x10 + x)>=0)) |
| 732 | /* 32 pixel wide sprites are counted as 2 sprites and the right half |
| 733 | is only drawn if there are 2 open slots. |
| 734 | */ |
| 735 | sprites_drawn++; |
| 736 | if( sprites_drawn > 16 ) { |
| 737 | vdc.status |= VDC_OR; |
| 738 | if(vdc.vdc_data[CR].w&CR_OV) |
| 739 | cpunum_set_input_line(0, 0, ASSERT_LINE); |
| 740 | } else { |
| 741 | conv_obj(obj_i + (cgypos << 2) + (hf ? 0 : 2), obj_l, hf, vf, buf); |
| 742 | for(x=0;x<16;x++) |
| 736 | 743 | { |
| 737 | | if ( buf[x] ) |
| 744 | if(((obj_x + 0x10 + x)<(vdc.physical_width))&&((obj_x + 0x10 + x)>=0)) |
| 738 | 745 | { |
| 739 | | if(!drawn[obj_x+0x10+x]) |
| 740 | | { |
| 741 | | if(priority || (line_buffer[pixel_x] == Machine->pens[color_base + vdc.vce_data[0].w])) { |
| 742 | | line_buffer[pixel_x] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 743 | | if ( vdc.physical_width != 512 ) { |
| 744 | | if ( pixel_x + 1 < ( ( ( obj_x + x + 17 ) * 512 ) / vdc.physical_width ) ) { |
| 745 | | line_buffer[pixel_x + 1] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 746 | | } |
| 747 | | } |
| 748 | | drawn[obj_x + 0x10 + x]=i+1; |
| 746 | if ( buf[x] ) { |
| 747 | if( drawn[obj_x+0x10+x] < 2 ) { |
| 748 | if( priority || drawn[obj_x+0x10+x] == 0 ) { |
| 749 | line_buffer[pixel_x] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 750 | if ( vdc.physical_width != 512 ) { |
| 751 | if ( pixel_x + 1 < ( ( ( obj_x + x + 17 ) * 512 ) / vdc.physical_width ) ) { |
| 752 | line_buffer[pixel_x + 1] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w]; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | drawn[obj_x + 0x10 + x]=i+2; |
| 749 | 757 | } |
| 758 | /* Check for sprite #0 collision */ |
| 759 | else if ( drawn[obj_x+0x10+x]==2 ) { |
| 760 | if(vdc.vdc_data[CR].w&CR_CC) |
| 761 | cpunum_set_input_line(0, 0, ASSERT_LINE); |
| 762 | vdc.status|=VDC_CR; |
| 763 | } |
| 750 | 764 | } |
| 751 | | else if (drawn[obj_x+0x10+x]==1) |
| 752 | | { |
| 753 | | if(vdc.vdc_data[CR].w&CR_CC) |
| 754 | | cpunum_set_input_line(0, 0, ASSERT_LINE); |
| 755 | | vdc.status|=VDC_CR; |
| 765 | } |
| 766 | pixel_x += 1; |
| 767 | if ( vdc.physical_width != 512 ) { |
| 768 | if ( pixel_x < ( ( ( obj_x + x + 17 ) * 512 ) / vdc.physical_width ) ) { |
| 769 | pixel_x += 1; |
| 756 | 770 | } |
| 757 | 771 | } |
| 758 | 772 | } |
| 759 | | pixel_x += 1; |
| 760 | | if ( vdc.physical_width != 512 ) { |
| 761 | | if ( pixel_x < ( ( ( obj_x + x + 17 ) * 512 ) / vdc.physical_width ) ) { |
| 762 | | pixel_x += 1; |
| 763 | | } |
| 764 | | } |
| 765 | 773 | } |
| 766 | 774 | } |
| 767 | 775 | } |