#pragma message ( "including line.cc" );

/*
fuer sich nicht ueberschneidende linien gilt:
     *(dest+offset)>>=4;//(*(overlay_memory+offset))>>4;
man muesste im vorhinein abfragen, ob ergebnis null ist,
dann ist die flaeche schon korrigiert!
ansonsten /16 teile...

was ist schneller?

1.  *(dest+offset)=(*(overlay_memory+offset))>>4;

2.a.  if !(*(dest+offset)>>=4) *(dest+offset)<<=4;
  b.  d=dest+offset; if !(*(d)>>=4) *(d)<<=4;

3.a.  if (*(dest+offset)>>4) *(dest+offset)>>=4;
  b.  d=dest+offset; if (*(d)>>4) *(d)>>=4;

alle drei varianten sind korrekt! liefern das gleiche ergebnis!
*/
{
#ifdef DEBUG_MSG
 T_PUCHAR  back=back_pic->mem_zeiger;

 #ifndef LINE_WITH_COLOR
 T_UCHAR  pixel;
 #endif

#endif

#ifndef BANKED
 T_PUCHAR  dest=(T_PUCHAR )svdc->videoMem;
#endif
 T_SWORD   dx=0,dy=0,err=0,inc=0;
/**************************/
/* Do straight line cases */
/**************************/
 if (iX1==iX2)
 {
  if (iY1>iY2)
  {
   fSwap(&iY1,&iY2);
  }
  do
  {
   /******************************************************************************************/
   /* not to be put out of loop, offset can get to high... (high iY1 are pointing to maxline)*/
   /******************************************************************************************/
   offset=vlinestartpos[(T_UWORD)iY1]+(T_ULONG)iX1;
   #include "pwrite.cc"
  }
  while(iY1++!=iY2);
 }
 else if (iY1==iY2)
 {
  if (iX1>iX2)
  {
   fSwap(&iX1,&iX2);
  }
  offset=vlinestartpos[(T_UWORD)iY1]+(T_ULONG)iX1;
  do
  {
   #include "pwrite.cc"
   offset++;
  }
  while(iX1++!=iX2);
 }
 else
 {
  /*************/
  /* X Variant */
  /*************/
  dx=iX2-iX1;
  dy=iY2-iY1;
  if(abs(dx)>=abs(dy))
  {
   if (iY1==1) iY1++;
   if (iY2==1) iY2++;
   if (iX1>iX2)
   {
    fSwap(&iX1,&iX2);
    fSwap(&iY1,&iY2);
    dx=iX2-iX1;
    dy=iY2-iY1;
   }
   err=-(dx>>1);
   if (dy>0)
   {
    inc=1;
   }
   else
   {
    inc=-1;
    dy=-dy;
   }
   do
   {
    /**************************/
    /* Calulate byte position */
    /**************************/
    offset=vlinestartpos[(T_UWORD)iY1]+(T_ULONG)iX1;
    #include "pwrite.cc"
    /**********************/
    /* Check error status */
    /**********************/
    err+=dy;
    if(err>0)
    {
     err-=dx;
     iY1+=inc;
    }
   }
   while(iX1++!=iX2);
  }
  else
  {
   if (iX1==0) iX1++;
   if (iX2==0) iX2++;
   if (iY1>iY2)
   {
    fSwap(&iX1,&iX2);
    fSwap(&iY1,&iY2);
    dx=iX2-iX1;
    dy=iY2-iY1;
   }
   err=-(dy>>1);
   if (dx>0)
   {
    inc=1;
   }
   else
   {
    inc=-1;
    dx=-dx;
   }
   do
   {
    /**************************/
    /* Calulate byte position */
    /**************************/
    offset=vlinestartpos[(T_UWORD)iY1]+(T_ULONG)iX1;
    #include "pwrite.cc"
    /**********************/
    /* Check error status */
    /**********************/
    err+=dx;
    if(err>=0)
    {
     err-=dy;
     iX1+=inc;
    }
   }
   while(iY1++!=iY2);
  }
 }
}
