home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / OS2-DD / ddebug.c < prev    next >
C/C++ Source or Header  |  1993-01-16  |  3KB  |  154 lines

  1. /*****************************************************************************
  2.  * $Id: ddebug.c,v 1.4 1992/10/14 16:50:28 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: ddebug.c,v $
  5.  * Revision 1.4  1992/10/14  16:50:28  ak
  6.  * Allow either PhysToVirt or GDT selector to access video.
  7.  * Note that PhysToVirt cannot be used in interrupt time.
  8.  *
  9.  * Revision 1.3  1992/07/24  11:34:11  ak
  10.  * OS/2 2.0
  11.  * BASEDEV drivers
  12.  * VGA debugging
  13.  *
  14.  * Revision 1.2  1992/01/06  20:09:26  ak
  15.  * *** empty log message ***
  16.  *
  17.  * Revision 1.1.1.1  1992/01/06  19:54:09  ak
  18.  * Alpha version.
  19.  *
  20.  * Revision 1.1  1992/01/06  19:54:07  ak
  21.  * Initial revision
  22.  *
  23.  *****************************************************************************/
  24.  
  25. #include "dd.h"
  26. #define INCL_DOS
  27. #include <os2.h>
  28. #include <string.h>
  29. #ifdef __ZTC__
  30. # define _fmemcpy(d,s,n) movedata(Segment(s), Offset(s), Segment(d), Offset(d), n)
  31. #else
  32. # include <memory.h>
  33. #endif
  34.  
  35. #define UseSel        0    /* GDT selector or PhysToVirt? */
  36.         /* note that PhysToVirt cannot be used at interrupt time */
  37.  
  38. #define DefaultAddress     0x0B8000L
  39. #define NCols        80
  40. #define NRows        25
  41. #define LineSize    (NCols * sizeof(word))
  42. #define ScreenSize    (NRows * LineSize)
  43. #define Attrib        0x0700
  44.  
  45. static int    row, col;
  46. dword        video_address;
  47. #if UseSel
  48. static word    video_sel;
  49. static word    _far * screen;
  50. static dword    prev_address;
  51. #endif
  52.  
  53. void _cdecl
  54. _STI_ddebug()
  55. {
  56.     if (video_address == 0)
  57.         video_address = DefaultAddress;
  58. #if UseSel
  59.     prev_address = video_address;
  60.     if (AllocGDTSelector(&video_sel, 1))
  61.         video_sel = 0;
  62.     if (PhysToGDTSelector(video_address, ScreenSize, video_sel))
  63.         screen = 0;
  64.     else
  65.         screen = Pointer(video_sel, 0);
  66. #endif
  67.     row = col = 0;
  68. }
  69.  
  70. void
  71. putc(byte c)
  72. {
  73.     if (inInitPhase()) {
  74.         USHORT nw;
  75.         static byte cr = 0x0D;
  76.         if (c == '\n')
  77.             DosWrite(1, &cr, 1, &nw);
  78.         DosWrite(1, &c, 1, &nw);
  79.     } else if (c == '\t') {
  80.         do putc(' '); while (col & 7);
  81.     } else {
  82.         word _far *scr;
  83.         if (inProtMode()) {
  84. #if UseSel
  85.             if (video_address != prev_address) {
  86.                 video_address = prev_address;
  87.                 if (video_sel
  88.                  && PhysToGDTSelector(video_address, ScreenSize,
  89.                             video_sel) == 0)
  90.                     screen = Pointer(video_sel, 0);
  91.             }
  92.             scr = screen;
  93. #else
  94.             scr = PhysToVirt(video_address, NRows * NCols * 2);
  95. #endif
  96.         } else
  97.             scr = (word _far *)(video_address << 12);
  98.         if (scr) {
  99.             if (c == '\n' || col == 80) {
  100.                 col = 0;
  101.                 row += 1;
  102.             }
  103.             if (row == NRows) {
  104.                 int i;
  105.                 _fmemmove(scr, scr + NCols, (NRows - 1) * NCols * 2);
  106.                 for (i = 0; i < NCols; ++i)
  107.                     scr[(NRows - 1) * NCols + i] = ' ' + Attrib;
  108.                 row = NRows - 1;
  109.             }
  110.             if (c != '\n')
  111.                 scr[row * NCols + col++] = c | Attrib;
  112. #if !UseSel
  113.             UnPhysToVirt();
  114. #endif
  115.         }
  116.     }
  117. }
  118.  
  119. void
  120. puts(char _far *s)
  121. {
  122.     while (*s)
  123.         putc(*s++);
  124. }
  125.  
  126. void
  127. putx(dword x)
  128. {
  129.     int i = 32 - 4;
  130.     for (; i != 0; i -= 4)
  131.         if (x >= 1L << i)
  132.             break;
  133.     for (; i >= 0; i -= 4)
  134.         putc("0123456789ABCDEF"[x >> i & 0x0F]);
  135. }
  136.  
  137. void
  138. putd(long x)
  139. {
  140.     if (x == -0x80000000L) {
  141.         puts("-2147483648");
  142.         return;
  143.     }
  144.     if (x < 0) {
  145.         putc('-');
  146.         x = -x;
  147.     }
  148.     if (x >= 10) {
  149.         putd(x / 10);
  150.         x %= 10;
  151.     }
  152.     putc("0123456789"[x]);
  153. }
  154.