#include <stdio.h>

#define RETRACE     1
#define NORETRACE   0
#define GET         0
#define PUT         1

char *str1 = "This is screen one.";
char *str2 = "This\nis screen\ntwo.";
char *str3 = "This is screen three.";

int scrbuff[2000];

int winbuff[2000];

int frame[7] = { {201},{187},{200},{188},{205},{186},{32} };

main()
{
   int c;
   int  row, col;

   cls();

   clrwin(0,0,24,79,(3 << 4) );
   c = getche();
   vputstr(2,0,str1,0x30,1);
   vputstr(3,0,str1,0x30,1);
   vputstr(4,0,str1,0x30,1);
   writestr(6,0,str2,0x30,1);
   vputnc(9,0,'%',0x3c,15,RETRACE);
   c = getche();
   vbufwin(winbuff,4,4,60,20,GET,RETRACE);
   vputbox(4,4,60,20,0x0e, 0x30, 1, frame);
   c = getche();
   vidbuf(scrbuff,RETRACE,GET);
   c = getche();
   vbufwin(winbuff,4,4,60,20,PUT,RETRACE);
   c = getche();
   cls();
   c = getche();
   vidbuf(scrbuff,RETRACE,PUT);
   c = getche();

}

writestr(row, col, str, attr, retrace)
int row, col;
char *str;
int  attr, retrace;
{
   int   c;

   while (c = *str++)
   {
      switch (c)
      {
         case  '\n' :
                      row++; col = 0; break;
         case  '\t' :
                      {
                         int i = col % 8;

                         while (i <= 8)
                         {
                            vputc(row, col++, ' ', attr, retrace);
                            i++;
                         }
                      }
                      break;
         default    :
                      vputc(row, col++, c, attr, retrace);
      }
   }
}
