#include <dos.h>

locate(row, col)
int   row, col;
{
   union REGS inregs;

   if ((r < 25) and (c < 80))
   {
      inregs.h.ah = 2;
      inregs.h.dh = r;
      inregs.h.dl = c;
      inregs.h.bh = 0;
      int86( VIDEO, &inregs, &inregs);
   }
   return;
}

readcursor(r, c)
unsigned *r, *c;
{
   union REGS inregs;

   inregs.h.ah = 3;
   inregs.h.bh = 0;
   int86( VIDEO, &inregs, &inregs);
   *r = inregs.h.dh;
   *c = inregs.h.dl;
   return;
}

scroll(r1, c1, r2, c2, num, attr)
unsigned r1, r2, c1, c2, num, attr;
{
   union REGS inregs;

   inregs.x.ax = (0x600 bitor num);
   inregs.x.cx = (r1 shl 8) bitor c1;
   inregs.x.dx = (r2 shl 8) bitor c2;
   inregs.h.bh = attr;
   int86( VIDEO, &inregs, &inregs);
   return;
}

putstr (s, attr)
char *s;
unsigned attr;
{
   union REGS inregs;
   int   r,c;

   readcursor( &r, &c);
   inregs.x.cx = 1;
   inregs.x.bx = attr;
   inregs.h.ah = 9;
   while ( inregs.h.al = *s++)
   {
      int86( VIDEO, &inregs, &inregs);
      locate(r, ++c);
   }
   locate(r, c);
   return;
}
cls()
{
   union REGS inregs;

   inregs.x.ax = 0x600;
   inregs.x.cx = 0;
   inregs.x.dx = 0x184f;
   inregs.h.bh = 7;
   int86( VIDEO, &inregs, &inregs);
   return;
}


main()
{
   unsigned    i;
   char        dummy [80];

   i = 5298;
   cls();
   locate(0, 0);
   putstr( "This is a test...", 2);
   locate(10, 20);
   putstr( "This is a test...",14);
   locate(24, 0);
   putstr( "This is a test...", 3);
   locate(16,75);
   putstr( "This is a test...", 4);
   sprintf(dummy, "The value of i is now %d.",i);
   locate(18,0);
   putstr( dummy, 6);
}
