Talk:VDP2

From Yabause
Jump to: navigation, search

Here's some code I wrote recently to try and tackle some of the VDP2 features we haven't been able to implement in yabause. Maybe with a few people discussing this we can hammer out something that's fast and accurate.

static void FASTCALL Vdp2DrawScrollBitmap2(vdp2draw_struct *info)
{
   int i, j;
   int x, y;
   clipping_struct clip;
   int windowenabled = 0; // fix me
   int linewindow = 0; // fix me
   int linescrollenab = Vdp2Regs->SCRCTL & 0x7; // fix me
   u32 linescrolltbl;
   u32 wndtbl = 0; // fix me
   u32 *textdata=vdp2framebuffer;

   info->x *= -1; // this is needed to "un-fix" scroll x
   info->y *= -1; // this is needed to "un-fix" scroll y

   // this should be replaced with the correct values
   clip.xstart = 0; 
   clip.ystart = 0;
   clip.xend = vdp2width;
   clip.yend = vdp2height;

   if (linescrollenab)
     linescrolltbl = (Vdp2Regs->LSTA0.all & 0x7FFFE) << 1;

   for (j = 0; j < vdp2height; j++)
   {
      // precalculate the coordinate for the line(it's faster) and do line
      // scroll
      if (linescrollenab)
      {
         info->x = T1ReadLong(Vdp2Ram, linescrolltbl) >> 16;
         linescrolltbl += 4;
         info->y =  T1ReadWord(Vdp2Ram, linescrolltbl);
         linescrolltbl += 4;
         y = info->y;
      }
      else
         y = info->y+((int)(info->coordincy*(float)(j / info->mosaicymask * info->mosaicymask)));

      // if line window is enabled, adjust clipping values
      if (linewindow)
      {
         // Fetch new xstart and xend values from table
         clip.xstart = T1ReadWord(Vdp2Ram, wndtbl) & 0x3FF;
         wndtbl+=2;
         clip.xend = T1ReadWord(Vdp2Ram, wndtbl) & 0x3FF;
         wndtbl+=2;
      }

      for (i = 0; i < vdp2width; i++)
      {
         u32 color;

         x = info->x+((int)(info->coordincx*(float)(i / info->mosaicxmask * info->mosaicxmask)));

         // See if screen position is clipped, if it isn't, continue
         if (windowenabled)
         {
            if (i < clip.xstart || i > clip.xend ||
                j < clip.ystart || j > clip.yend)
            {
               textdata++;
               continue;
            }
         }

         // Fetch Pixel, if it isn't transparent, continue
         if (!Vdp2BitmapFetchPixel(info, x, y, &color))
         {
            textdata++;
            continue;
         }

         // check special priority somewhere here

         // Apply color offset and color calculation/special color calculation
         // and then continue.
         // We almost need to know well ahead of time what the top
         // and second pixel is in order to work this.

         textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
         textdata++;
      }
   }
}