home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / monomsg.zip / MONOMSG.C next >
C/C++ Source or Header  |  1991-02-28  |  3KB  |  81 lines

  1. /***************************************************************************
  2. monomsg : Display a string on the monochrome screen
  3. Author    : Jon Roper
  4. Date    : 12/12/90
  5.  
  6. Use for debugging Windows programs.
  7.  
  8. This routine will display a string on the 25th line of the monochrome
  9. monitor.  It prepends a sequence number to the message.  If the message
  10. is a duplicate of the previous message the message is updated with a number
  11. appended showing the number of times the routine was called with a duplicate
  12. message.
  13.  
  14. If the message is not a duplicate the screen is scrolled 1 line prior to
  15. displaying the new message.
  16.  
  17. NOTE - message length is not checked, messages longer than about 60 bytes
  18. may cause havoc.
  19.  
  20. 1-29-91 Added code to allow running in protected mode (monobuf.asm)
  21. ***************************************************************************/
  22. #include <dos.h>
  23. #include <stdio.h>
  24. #include <windows.h>
  25.  
  26. unsigned int MONOBUFFER;
  27.  
  28. unsigned int FAR PASCAL DpmSelectorFromSegment(WORD);
  29.  
  30.  
  31. void monomsg(msg)
  32. char *msg;           /* Display this message on the monochrome screen  */
  33. {
  34. OFSTRUCT    fstruct;
  35. static HANDLE       fp;
  36. static int dups;       /* number of duplicate messages              */
  37. static prev_msg[256];  /* previous message                  */
  38. static int n;           /* Line number                      */
  39. struct SREGS regs;     /* registers                      */
  40. int i;               /* every program needs one              */
  41. char buf[128];           /* sprintf buffer                  */
  42. /**************************************************************************/
  43.  
  44.     if (!fp)
  45.     { /* call to get virtual address of monochrome buffer */
  46.     MONOBUFFER = DpmSelectorFromSegment(0xb000);
  47.     fp=OpenFile("monomsg.txt",&fstruct,
  48.         OF_CREATE|OF_WRITE);
  49.     }
  50.     if (!n)
  51.     monoscroll(25);     /* first time in scroll all the data off  */
  52.     if (!strcmp(prev_msg,msg))    /* same message, don't scroll             */
  53.     {
  54.     ++dups;           /* how many duplicate messages received */
  55.     sprintf(buf,"%4d %s [%04d]",n,prev_msg,dups+1); /* msg with dup # */
  56.     }
  57.     else
  58.     {
  59.     dups = 0;               /* this is not a duplicate line      */
  60.     ++n;                   /* line number displayed       */
  61.     sprintf(buf,"%4d %s",n,msg);   /* Setup message with msg number   */
  62.     monoscroll(1);               /* scroll monochrome screen 1 line */
  63.     }
  64.     segread(®s);  /* Get ds register                   */
  65.     buf[80] = 0;     /* Make sure we don't run off the screen.            */
  66.     for (i = 0; i < strlen(buf); ++i)  /*  display message on 25th line   */
  67.     movedata(regs.ds,buf+i,MONOBUFFER,(i+(24*80))*2,1); /* poke into memory */
  68.     strcpy(prev_msg,msg);  /* save message for next time around       */
  69.     write(fp,buf,strlen(buf));
  70.     write(fp,"\n",1);
  71. }
  72. /***************************************************************************
  73. Scroll the monochrome screen lines number of times
  74. ***************************************************************************/
  75. monoscroll(lines)
  76. int lines;                  /* how many lines to scroll off      */
  77. {
  78.     while (lines--)
  79.     movedata(MONOBUFFER,160,MONOBUFFER,0,25*160);
  80. }
  81.