Previous 15994 Revisions Next

r940 Sunday 9th September, 2007 at 13:45:11 UTC by Wilbert Pol
[PCE] Improved background-sprite priority handling. (bug #1361)
[src/mess/video]vdc.c

src/mess/video/vdc.c
r939r940
5353void draw_black_line(int line);
5454void draw_overscan_line(int line);
5555void pce_refresh_line(int bitmap_line, int line);
56void pce_refresh_sprites(int bitmap_line, int line);
56void pce_refresh_sprites(int bitmap_line, int line, UINT8 *drawn);
5757void vdc_do_dma(void);
5858
5959INTERRUPT_GEN( pce_interrupt )
r939r940
469469    /* pointer to the name table (Background Attribute Table) in VRAM */
470470    UINT8 *bat = &(vdc.vram[nt_row << (v_width+1)]);
471471
472   /* 0 - no sprite and background pixels drawn
473      1 - background pixel drawn
474      otherwise is 2 + sprite# */
475   UINT8 drawn[VDC_WPF];
476
472477   /* Are we in greyscale mode or in color mode? */
473478   int color_base = vdc.vce_control & 0x80 ? 512 : 0;
474479
r939r940
478483    int cell_palette;
479484    int x, c, i;
480485
486   /* clear our priority/sprite collision detection buffer. */
487   memset(drawn, 0, VDC_WPF);
488
481489    /* character blanking bit */
482490    if(!(vdc.vdc_data[CR].w & CR_BB))
483491    {
r939r940
526534               c &= 0x0F;
527535
528536            if ( phys_x >= 0 && phys_x < vdc.physical_width ) {
537               drawn[ phys_x ] = c ? 1 : 0;
529538               line_buffer[ pixel ] = Machine->pens[color_base + vdc.vce_data[c].w];
530539               pixel++;
531540               if ( vdc.physical_width != 512 ) {
r939r940
542551   /* Sprite rendering is independant of BG drawing! */
543552   if(vdc.vdc_data[CR].w & CR_SB)
544553   {
545      pce_refresh_sprites(bitmap_line, line);
554      pce_refresh_sprites(bitmap_line, line, drawn);
546555   }
547556}
548557
r939r940
580589    }
581590}
582591
583void pce_refresh_sprites(int bitmap_line, int line)
592void pce_refresh_sprites(int bitmap_line, int line, UINT8 *drawn)
584593{
585594    int i;
586595   UINT8 sprites_drawn=0;
587596   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];
590597
591598   /* Are we in greyscale mode or in color mode? */
592599   int color_base = vdc.vce_control & 0x80 ? 512 : 0;
593600
594   /* clear our sprite-to-sprite clipping buffer. */
595   memset(drawn, 0, VDC_WPF);
596601   /* count up: Highest priority is Sprite 0 */
597602   for(i=0; i<64; i++)
598603   {
r939r940
614619      char buf[16];
615620
616621      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;
618623
619624      /* no need to draw an object that's ABOVE where we are. */
620625      if((obj_y + obj_h)<line) continue;
r939r940
656661            {
657662               if(((obj_x + x)<(vdc.physical_width))&&((obj_x + x)>=0))
658663               {
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 ) {
664667                           line_buffer[pixel_x] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w];
665668                           if ( vdc.physical_width != 512 ) {
666669                              if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) {
667670                                 line_buffer[pixel_x + 1] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w];
668671                              }
669672                           }
670                           drawn[obj_x+x]=i+1;
671673                        }
674                        drawn[obj_x+x]=i+2;
672675                     }
673                     else if (drawn[obj_x+x]==1)
676                     /* Check for sprite #0 collision */
677                     else if (drawn[obj_x+x]==2)
674678                     {
675679                        if(vdc.vdc_data[CR].w&CR_CC)
676680                           cpunum_set_input_line(0, 0, ASSERT_LINE);
r939r940
697701            {
698702               if(((obj_x + x)<(vdc.physical_width))&&((obj_x + x)>=0))
699703               {
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 ) {
705707                           line_buffer[pixel_x] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w];
706708                           if ( vdc.physical_width != 512 ) {
707709                              if ( pixel_x + 1 < ( ( ( obj_x + x + 1 ) * 512 ) / vdc.physical_width ) ) {
708710                                 line_buffer[pixel_x + 1] = Machine->pens[color_base + vdc.vce_data[0x100 + (palette << 4) + buf[x]].w];
709711                              }
710712                           }
711                           drawn[obj_x + x]=i+1;
712713                        }
714                        drawn[obj_x + x]=i+2;
713715                     }
714                     else if (drawn[obj_x+x]==1)
715                     {
716                     /* Check for sprite #0 collision */
717                     else if ( drawn[obj_x+x] == 2 ) {
716718                        if(vdc.vdc_data[CR].w&CR_CC)
717719                           cpunum_set_input_line(0, 0, ASSERT_LINE);
718720                        vdc.status|=VDC_CR;
719
720
721721                     }
722722                  }
723723               }
r939r940
729729               }
730730            }
731731
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++)
736743               {
737                  if ( buf[x] )
744                  if(((obj_x + 0x10 + x)<(vdc.physical_width))&&((obj_x + 0x10 + x)>=0))
738745                  {
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;
749757                        }
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                        }
750764                     }
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;
756770                     }
757771                  }
758772               }
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               }
765773            }
766774         }
767775      }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team