#include <stdio.h>

typedef  unsigned int  (far * VIDBUF);
#define  CGABUF   (VIDBUF) (0xb800L << 16)
#define  MGABUF   (VIDBUF) (0xb000L << 16)
#define  CGASTAT  0x3da

vidbuf(vbuff, retrace, direction)
int *vbuff, retrace, direction;
{
   int i;
   VIDBUF  scr_ofs;

   if (vidmode() == 7)
   {
      retrace = 0;
      scr_ofs = MGABUF;
   }
   else
      scr_ofs = CGABUF;

   i = 2000;
   while (i)
   {
      if (retrace)
      {
         while( (inp(CGASTAT) & 1) == 1);
         while( (inp(CGASTAT) & 1) != 1);
      }
      if (! direction)
         *vbuff = *scr_ofs;
      else
         *scr_ofs = *vbuff;
      vbuff++;scr_ofs++;i--;
   }
}
