#include "vid.h"

#define  FALSE  0

VIDMEM vputn();

vbufwin(buffer, row, col, width, height, direction, retrace)
int   *buffer;
int   row, col, width, height, direction, retrace;
{
   VIDMEM scr_ofs, vstart;
   int    times;

   if (vidmode() == 7)
   {
      vstart = MGAMEM;
      retrace = FALSE;
   }
   else
      vstart = CGAMEM;

   vstart += row * 80;

   while (height)
   {
      scr_ofs = vstart + col;

      times = width;
      while(times)
      {
         if (retrace)
         {
            while( (inp(CGASTAT) & 1) == 1);
            while( (inp(CGASTAT) & 1) != 1);
         }
         if (! direction)
            *buffer = *scr_ofs;
         else
            *scr_ofs = *buffer;
         buffer++;scr_ofs++;times--;
      }
      height--;
      vstart += 80;
   }
}
