#include <conio.h>
#include <dos.h>

#define MEMC(s, o) (*(char _far *)((long)(s)<<16|(o)))
#define MEMW(s, o) (*(int  _far *)((long)(s)<<16|(o)))

union REGS inregs, outregs;

int video_segment = 0xb800;
int msg[] = { 0x7050, 0x7052, 0x7045, 0x7053, 0x7053, /* "PRESS            */
              0x7020, 0x7041, 0x704e, 0x7059,         /*  ANY              */
              0x7020, 0x704b, 0x7045, 0x7059,         /*  KEY              */
              0x7020, 0x7054, 0x704f, 0x7020,         /*  TO               */
              0x7045, 0x7058, 0x7049, 0x7054 };       /*  EXIT"            */

main()
   {
   int i;

   inregs.x.ax=3;                      /* Choose 80 x 25 mode.             */
   int86(0x10, &inregs, &outregs);     /* Set the mode using the BIOS.     */

   if (MEMC( 0x40, 0x10 ) & 0x10)      /* If monochrome...                 */
      video_segment = 0xb000;          /* ...then use the monochrome seg.  */

   inregs.h.ah=2;                      /* Move cursor off screen.          */
   inregs.h.bh=0;
   inregs.x.dx=0x1900;
   int86(0x10, &inregs, &outregs);

   for (i=0 ; i < 25 * 160 ; i += 2)   /* Fill screen with white blocks.   */
      MEMW( video_segment, i ) = 0x7020;

   for (i=0 ; i < sizeof (msg) ; i += 2) /* Put up exit message.           */
      MEMW( video_segment, i+0xf3a ) = msg[i/2];

   while (!kbhit())                    /* Exit when a key is pressed.      */
      {
      inregs.h.ah=4;                   /* ...read light pen coordinate     */
      int86(0x10, &inregs, &outregs);  /*    values from the BIOS.         */

      if (outregs.h.ah == 1)           /* If light pen values read...      */
         MEMW( video_segment,          /* ...then replace position with a  */
               160 * outregs.h.dh +    /*    black space.                  */
               2 * outregs.h.dl) = 0x720;
      }


   if (!getch())                       /* Remove the character from the    */
      getch();                         /*   keyboard buffer.               */

   inregs.x.ax=3;                      /* Choose 80 x 25 mode.             */
   int86(0x10, &inregs, &outregs);
   inregs.h.ah=2;                      /* Restore the cursor to the upper  */
   inregs.h.bh=0;                      /*   left.                          */
   inregs.x.dx=0;
   int86(0x10, &inregs, &outregs);
   }
