home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / tools / bgi_tool / debug.c < prev    next >
Text File  |  1989-06-19  |  47KB  |  1,345 lines

  1.  
  2. /*
  3.  
  4.     DEBUG.C - sample debugging BGI driver
  5.  
  6.     Copyright (c) 1988,89 Borland International
  7.  
  8. */
  9.  
  10.  
  11.  
  12.  
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <dos.h>
  16.  
  17. /* ----------------------------- DEBUG.C ------------------------------ */
  18. /*                                                                      */
  19. /*      Function Protoypes for the debug driver.                        */
  20. /*                                                                      */
  21.  
  22. void save_regs( void );
  23. void banner( char *str );
  24. void putnum( unsigned number );
  25. void puthex( unsigned number );
  26. void dputs( char far *str );
  27. void crlf( void );
  28.  
  29. void far enter_graphics( void );
  30. void far leave_graphics( void );
  31. void far putpix( void );
  32. void far getpix( void );
  33. void far bits_per_pixel( void );
  34. void far set_visual( void );
  35. void far set_page( void );
  36. void far set_write_mode( void );
  37.  
  38. typedef void far (*FRFPTR)( void );     /* Pointer to Void/Void Funct   */
  39. typedef void     (*NRFPTR)( void );     /* Pointer to Void/Void Funct   */
  40.  
  41. /*                                                                      */
  42. /*      The following C structure defines a Device Status Block.        */
  43. /*                                                                      */
  44.  
  45. typedef struct {
  46.   unsigned char   stat;                 /* Current device status.       */
  47.   unsigned char   devtype;              /* Device Type Identifier.      */
  48.   unsigned int    xres;                 /* Device Full Resolution in X  */
  49.   unsigned int    yres;                 /* Device Full Resolution in Y  */
  50.   unsigned int    xefres;               /* Device Effective X Resolution*/
  51.   unsigned int    yefres;               /* Device Effective Y Resolution*/
  52.   unsigned int    xinch;                /* Device X Size in inches*1000 */
  53.   unsigned int    yinch;                /* Device Y Size in inches*1000 */
  54.   unsigned int    aspec;                /* Aspect Ratio * 10000         */
  55.   unsigned char   chsizx;               /* Standard char size X         */
  56.   unsigned char   chsizy;               /* Standard char size Y         */
  57.   unsigned char   fcolors;              /* Number of foreground colors  */
  58.   unsigned char   bcolors;              /* Number of background colors  */
  59. } STATUS;
  60.  
  61. /*                                                                      */
  62. /*      The following structure defines a palette record.               */
  63. /*                                                                      */
  64.  
  65. typedef struct {
  66.   unsigned char length;                 /* # of color entries in palette*/
  67.   unsigned char color[16];              /* Up to 16 color entries       */
  68.   } PALETTE;
  69.  
  70. /*                                                                      */
  71. /*      The following structure defines a utility function table.       */
  72. /*                                                                      */
  73.  
  74. typedef struct {
  75.   NRFPTR  goto_graph;                   /* Enter graphics mode function */
  76.   NRFPTR  exit_graph;                   /* Leave graphics mode function */
  77.   NRFPTR  putpix;                       /* Write a pixel function       */
  78.   NRFPTR  getpix;                       /* Read a pixel function        */
  79.   NRFPTR  bits_per_pixel;               /* Bits per pixel value         */
  80.   NRFPTR  set_page;                     /* Set the active drawing page  */
  81.   NRFPTR  set_visual;                   /* Set the active display page  */
  82.   NRFPTR  write_mode;                   /* Set the current write mode   */
  83.   } UTILITIES;
  84.  
  85. /*                                                                      */
  86. /*      This status block declares the debug driver to appear as an     */
  87. /*      EGA card in high resolution mode.                               */
  88. /*                                                                      */
  89.  
  90. STATUS  Stat_Block = {          /* Status block to fake an EGA driver   */
  91.   0,                            /* Current device status.               */
  92.   0,                            /* Device Type Identifier.              */
  93.   639,                          /* Device Full Resolution in X          */
  94.   479,                          /* Device Full Resolution in Y          */
  95.   639,                          /* Device Effective X Resolution        */
  96.   479,                          /* Device Effective Y Resolution        */
  97.   9000,                         /* Device X Size in inches*1000         */
  98.   7000,                         /* Device Y Size in inches*1000         */
  99.   10000,                        /* Aspect Ratio * 10000                 */
  100.   8  + 0x80,                    /* Standard char size X                 */
  101.   8  + 0x80,                    /* Standard char size Y                 */
  102.   16 + 0x80,                    /* Number of foreground colors          */
  103.   16 + 0x80                     /* Number of background colors          */
  104.   };
  105.  
  106. /*                                                                      */
  107. /*      This palette declares the default EGA palette.                  */
  108. /*                                                                      */
  109.  
  110. PALETTE Default_Palette = {     /* Define the palette for above EGA mode*/
  111.   16, { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07,
  112.         0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F  }
  113.   };
  114.  
  115. /*                                                                      */
  116. /*      The following structure defines the Bit Manipulation Utility    */
  117. /*      function table.                                                 */
  118. /*                                                                      */
  119.  
  120. UTILITIES Utility_Table = {             /* Bit Utilities Function Table */
  121.   (NRFPTR) enter_graphics,              /* Enter graphics mode function */
  122.   (NRFPTR) leave_graphics,              /* Leave graphics mode function */
  123.   (NRFPTR) putpix,                      /* Write a pixel function       */
  124.   (NRFPTR) getpix,                      /* Read a pixel function        */
  125.   (NRFPTR) bits_per_pixel,              /* Bits per pixel function      */
  126.   (NRFPTR) set_page,                    /* Set the active drawing page  */
  127.   (NRFPTR) set_visual,                  /* Set the active display page  */
  128.   (NRFPTR) set_write_mode               /* Set the current write mode   */
  129.   };
  130.  
  131. /*                                                                      */
  132. /*      The following defines the name of the modes for Driver.         */
  133. /*      NOTE: The string must start with a PASCAL style length.         */
  134. /*                                                                      */
  135.  
  136. char Name[] = "\030Debug Driver (640 x 480)";
  137.  
  138. /*      Driver Local Data Variables                                     */
  139.  
  140. char Buffer[80] = { 0 };                /* String output buffer         */
  141.  
  142. unsigned int    CP_X = 0, CP_Y = 0;     /* Current Drawing Pointer CP   */
  143.  
  144. unsigned int  ds = 0;                   /* DS on entry to the driver    */
  145. unsigned int  ax = 0, bx = 0, cx = 0, dx = 0;
  146. unsigned int  ah = 0, bh = 0, ch = 0, dh = 0;
  147. unsigned int  al = 0, bl = 0, cl = 0, dl = 0;
  148.  
  149. /* ----------------------------- INSTALL ------------------------------- */
  150. /*                                                                       */
  151. /*      The Install function is used to prepare the driver to use.       */
  152. /*      The calls to this function allow the kernal to inquire the       */
  153. /*      mode information, and allow the kernal to install the mode       */
  154. /*      infomation.                                                      */
  155. /*                                                                       */
  156.  
  157. void install( void )
  158. {
  159.  
  160.   save_regs();                          /* Save a copy of current regs  */
  161.  
  162.   banner( "INSTALL" );                  /* Announce the function type   */
  163.   switch( al ){                         /* Determine the command to use */
  164.  
  165.     case 0:                             /* Install Device Command       */
  166.       dputs( "    Install Device:   Mode Number: " );
  167.       putnum( cl );
  168.       dputs( "  AutoDetect Maximum: " );
  169.       putnum( ch );
  170.       crlf();
  171.  
  172.       _ES = _CS;                        /* Make ES:BX point to block    */
  173.       _BX = (unsigned int) &Stat_Block; /* BX points to status block    */
  174.       break;
  175.  
  176.     case 1:                             /* Mode Query Command           */
  177.       dputs( "    Mode Query Request (1 Mode)\r\n" );
  178.       _CX = 1;                          /* Return only 1 mode supported */
  179.       break;
  180.  
  181.     case 2:                             /* Mode Name Command            */
  182.       dputs( "    Mode Name Request: Mode " );
  183.       putnum( cx );
  184.       crlf();
  185.  
  186.       _ES = _CS;                        /* Make ES:BX point to name     */
  187.       _BX = (unsigned int) Name;        /* BX points to name string     */
  188.       break;
  189.  
  190.     default:                            /* Unknown Install Call         */
  191.       dputs( "    ERROR: Unknown Install Command: " );
  192.       puthex( al );
  193.       crlf();
  194.       break;
  195.     }                                   /* End of Install command case  */
  196. }
  197.  
  198. /* ----------------------------- INITIALIZE ---------------------------- */
  199. /*                                                                       */
  200. /*      The initialize function is uset to enter the graphics mode.      */
  201. /*      Once the kernal has established the mode, the Initialize         */
  202. /*      call is used to execute the entry to graphics mode.              */
  203. /*                                                                       */
  204.  
  205. void init( void )
  206. {
  207.  
  208.   save_regs();                          /* Save a copy of current regs  */
  209.  
  210.   banner( "INITIALIZE" );
  211.   dputs( "    Device Status Table at " );
  212.   puthex( _ES );
  213.   dputs( ":" );
  214.   puthex( bx );
  215.   crlf();
  216.  
  217. }
  218.  
  219. /* ----------------------------- CLEAR DEVICE -------------------------- */
  220. /*                                                                       */
  221. /*      The Clear Device call is used to ready the device for new        */
  222. /*      output. This would be a clear screen on graphics hardware,       */
  223. /*      formfeed on a printer or plotter, and a flush for file I/O.      */
  224. /*                                                                       */
  225.  
  226. void clear( void )
  227. {
  228.  
  229.   banner( "CLEAR DEVICE" );
  230.  
  231. }
  232.  
  233. /* ----------------------------- POST DEVICE --------------------------- */
  234. /*                                                                       */
  235. /*      The Post Device function is used to end the graphics output.     */
  236. /*      This would be used to begin printing a page on a printer,        */
  237. /*      set a graphics screen to visable, etc.                           */
  238. /*                                                                       */
  239.  
  240. void post( void )
  241. {
  242.  
  243.   banner( "POST DEVICE" );
  244.  
  245. }
  246.  
  247. /* ----------------------------- MOVE TO ------------------------------- */
  248. /*                                                                       */
  249. /*      This function is used to move the current pointer (CP). The      */
  250. /*      Current pointer is the system graphics cursor.                   */
  251. /*                                                                       */
  252.  
  253. void move( void )
  254. {
  255.  
  256.   save_regs();                          /* Save a copy of current regs  */
  257.  
  258.   banner( "MOVE" );
  259.   dputs( "    Move to:     X: " );
  260.   putnum( ax );
  261.   dputs( "  Y: " );
  262.   putnum( bx );
  263.   crlf();
  264.  
  265.   CP_X = ax;                            /* Update the current pointer   */
  266.   CP_Y = bx;
  267.  
  268. }
  269.  
  270. /* ----------------------------- DRAW TO ------------------------------- */
  271. /*                                                                       */
  272. /*      Draw To is used to draw a line vector from the CP to the         */
  273. /*      specified coordinate.                                            */
  274. /*                                                                       */
  275.  
  276. void draw( void )
  277. {
  278.  
  279.   save_regs();                          /* Save a copy of current regs  */
  280.  
  281.   banner( "DRAW" );
  282.   dputs( "    Draw to:     X: " );
  283.   putnum( ax );
  284.   dputs( "  Y: " );
  285.   putnum( bx );
  286.   crlf();
  287.  
  288.   CP_X = ax;                            /* Update the current pointer   */
  289.   CP_Y = bx;
  290.  
  291. }
  292.  
  293. /* ----------------------------- VECT ---------------------------------- */
  294. /*                                                                       */
  295. /*      Vector is used to draw lines when the beginning and ending       */
  296. /*      point are know. The parameters specify two vertices for          */
  297. /*      drawing the desire line.                                         */
  298. /*                                                                       */
  299.  
  300. void vect( void )
  301. {
  302.  
  303.   save_regs();                          /* Save a copy of current regs  */
  304.  
  305.   banner( "VECT" );
  306.   dputs( "    Vector From:  X: " );
  307.   putnum( ax );
  308.   dputs( "  Y: " );
  309.   putnum( bx );
  310.   dputs( "   To:  X: " );
  311.   putnum( cx );
  312.   dputs( "  Y: " );
  313.   putnum( dx );
  314.   crlf();
  315.  
  316. }
  317.  
  318. /* ----------------------------- POLYGON ------------------------------ */
  319. /*                                                                      */
  320. /*      The polygon command is used to implement all of the possible    */
  321. /*      polygon output syles. The parameters allow specifying a means   */
  322. /*      to draw a polygon using a static array, or by accruing points   */
  323. /*      through the moveto - lineto calls in a capture mode.            */
  324. /*                                                                      */
  325.  
  326. void polygon( void )
  327. {
  328.   int far *iptr = MK_FP( _ES, _BX );
  329.   int i;
  330.  
  331.   save_regs();
  332.  
  333.   banner( "POLYGON" );
  334.  
  335.   switch( ax ){                         /* Determine Polygon action     */
  336.     case 0:                             /* Start polygon definition     */
  337.       dputs( "    Start Polygon Definition\r\n" );
  338.       break;
  339.  
  340.     case 1:                             /* Close and trace polygon      */
  341.       dputs( "    Close and Trace Polygon\r\n" );
  342.       break;
  343.  
  344.     case 2:                             /* Close and fill polygon       */
  345.       dputs( "    Close, Trace, and Fill Polygon\r\n" );
  346.       break;
  347.  
  348.     case 3:                             /* Close and fill (no outline)  */
  349.       dputs( "    Close and Fill Polygon (No Outline)\r\n" );
  350.       break;
  351.  
  352.     case 4:                             /* Draw points, but no capture  */
  353.       dputs( "    Draw Points without Capture\r\n" );
  354.       break;
  355.  
  356.     case 5:                             /* End polygon capture mode     */
  357.       dputs( "    Turn Capture Off\r\n" );
  358.       break;
  359.  
  360.     case 6:                             /* Draw polygon from data array */
  361.       dputs( "    Draw Polygon:  " );
  362.       putnum( cx );
  363.       dputs( " Vertices\n\r" );
  364.       for( i=0 ; i<cx ; ++i ){          /* Display the vertex list      */
  365.         dputs( "      " );
  366.         putnum( i );
  367.         dputs( ":  X: " );
  368.         putnum( *iptr++ );
  369.         dputs( "  Y: " );
  370.         putnum( *iptr++ );
  371.         }
  372.       break;
  373.  
  374.     case 7:                             /* Fill polygon from data array */
  375.       dputs( "    Fill Polygon:  " );
  376.       putnum( cx );
  377.       dputs( " Vertices\n\r" );
  378.       for( i=0 ; i<cx ; ++i ){          /* Display the vertex list      */
  379.         dputs( "      " );
  380.         putnum( i );
  381.         dputs( ":  X: " );
  382.         putnum( *iptr++ );
  383.         dputs( "  Y: " );
  384.         putnum( *iptr++ );
  385.         }
  386.       break;
  387.  
  388.     default:                            /* Unknown polygon command      */
  389.       dputs( "    ERROR: Unknown Polygon Command (" );
  390.       putnum( ax );
  391.       dputs( "\r\n" );
  392.       break;
  393.  
  394.     }
  395.  
  396. }
  397.  
  398. /* ----------------------------- RECT ---------------------------------- */
  399. /*                                                                       */
  400. /*      This function is used to draw a filled rectangle to the output   */
  401. /*      device. The parameters are the coordinates of opposite corners   */
  402. /*      of the input rectangle. The rectangle call is also capable of    */
  403. /*      producing 3D bars with an additional depth and cap parameter.    */
  404. /*                                                                       */
  405.  
  406. void bar( void )
  407. {
  408.  
  409.   save_regs();                          /* Save a copy of current regs  */
  410.  
  411.   banner( "RECT" );
  412.   dputs( "    Upper Right:  X: " );
  413.   putnum( ax );
  414.   dputs( "  Y: " );
  415.   putnum( bx );
  416.   crlf();
  417.   dputs( "    3D Depth:  " );
  418.   putnum( cx );
  419.   dputs( " Top Flag: (" );
  420.   putnum( dx );
  421.   dputs( ") " );
  422.   dputs( dx ? "Yes\r\n" : "No\r\n" );
  423.  
  424. }
  425.  
  426. /* ----------------------------- PATBAR -------------------------------- */
  427. /*                                                                       */
  428. /*      The patbar function is used to draw rectangles which are filled  */
  429. /*      with the current drawing pattern. The parameters of PATBAR       */
  430. /*      at the coordinates of the opposing corners of the bar.           */
  431. /*                                                                       */
  432.  
  433. void patbar( void )
  434. {
  435.  
  436.   save_regs();                          /* Save a copy of current regs  */
  437.  
  438.   banner( "PATBAR");
  439.   dputs( "    Upper Left:   X: " );
  440.   putnum( ax );
  441.   dputs( "  Y: " );
  442.   putnum( bx );
  443.  
  444.   dputs( "    Lower Right:  X: " );
  445.   putnum( cx );
  446.   dputs( "  Y: " );
  447.   putnum( dx );
  448.   crlf();
  449.  
  450. }
  451.  
  452. /* ----------------------------- ARC ----------------------------------- */
  453. /*                                                                       */
  454. /*      The ARC command is used to output elliptical arcs. The input     */
  455. /*      parameters of the arc are the coordinate of the ARC center,      */
  456. /*      the X and Y radius, and the beginning and ending angle.          */
  457. /*                                                                       */
  458.  
  459. void arc( void )
  460. {
  461.  
  462.   save_regs();                          /* Save a copy of current regs  */
  463.  
  464.   banner( "ARC" );
  465.   dputs( "    X Radius: " );
  466.   putnum( cx );
  467.   dputs( "    Y Radius: " );
  468.   putnum( dx );
  469.   crlf();
  470.   dputs( "    Start Angle: " );
  471.   putnum( ax );
  472.   dputs( "    End Angle:   " );
  473.   putnum( bx );
  474.   crlf();
  475.  
  476. }
  477.  
  478. /* ---------------------------- PIESLICE ------------------------------- */
  479. /*                                                                       */
  480. /*      The sector command is used to output setors. The input           */
  481. /*      parameters of the sector are the coordinate of the center,       */
  482. /*      the X and Y radius, and the beginning and ending angle.          */
  483. /*                                                                       */
  484.  
  485. void pieslice( void )
  486. {
  487.  
  488.   save_regs();                          /* Save a copy of current regs  */
  489.  
  490.   banner( "PIESLICE" );
  491.   dputs( "    X Radius: " );
  492.   putnum( cx );
  493.   dputs( "    Y Radius: " );
  494.   putnum( dx );
  495.   crlf();
  496.   dputs( "    Start Angle: " );
  497.   putnum( ax );
  498.   dputs( "    End Angle:   " );
  499.   putnum( bx );
  500.   crlf();
  501.  
  502. }
  503.  
  504. /* -------------------------- FILLED ELLIPSE --------------------------- */
  505. /*                                                                       */
  506. /*      The input parameters of the elipse command is the coordinate     */
  507. /*      of the center and the x and y radii.                             */
  508. /*                                                                       */
  509.  
  510. void filled_ellipse( void )
  511. {
  512.  
  513.   save_regs();                          /* Save a copy of current regs  */
  514.  
  515.   banner( "FILLED ELLIPSE" );
  516.   dputs( "    X Radius: " );
  517.   putnum( ax );
  518.   dputs( "    Y Radius: " );
  519.   putnum( bx );
  520.   crlf();
  521.  
  522. }
  523.  
  524. /* ----------------------------- PALETTE ------------------------------- */
  525. /*                                                                       */
  526. /*      The palette command is the central command for loading the       */
  527. /*      device palette. This function support several modes to allow     */
  528. /*      for the varied palette and color systems.                        */
  529. /*                                                                       */
  530.  
  531. void palette( void )
  532. {
  533.   int flags, index;
  534.  
  535.   save_regs();                          /* Save a copy of current regs  */
  536.  
  537.   banner( "PALETTE" );
  538.  
  539.   flags = (ax >> 14) & 0x0003;          /* Get flag bits from command   */
  540.   index = ax & 0x3fff;                  /* Mask to get color index      */
  541.  
  542.   switch( flags ){                      /* Act according to flags       */
  543.     case 0:                             /* Set indexed color palette    */
  544.       dputs( "    Set Indexed Color:  Index: " );
  545.       putnum( index );
  546.       dputs( "   Color Value: " );
  547.       putnum( bx );
  548.       crlf();
  549.       break;
  550.     case 1:                             /* Undefine color command       */
  551.       dputs( "ERROR: Undefined Set Color Command (01)\r\n" );
  552.       break;
  553.     case 2:                             /* RGB - Index color            */
  554.       dputs( "    Set RGB Color:  Index: " );
  555.       putnum( index );
  556.       dputs( "  R: " );
  557.       putnum( bx );
  558.       dputs( "  G: " );
  559.       putnum( cx );
  560.       dputs( "  B: " );
  561.       putnum( dx );
  562.       crlf();
  563.       break;
  564.     case 3:                             /* Background color             */
  565.       dputs( "    Set Background Color:  Color Value: " );
  566.       putnum( bx );
  567.       crlf();
  568.       break;
  569.     }
  570.  
  571. }
  572.  
  573. /* ----------------------------- ALLPALETTE ---------------------------- */
  574. /*                                                                       */
  575. /*      The all palette command is used to load an entire palette in     */
  576. /*      a single output command. The current BGI limits the size of      */
  577. /*      the allpalette command to be the first 16 colors.                */
  578. /*                                                                       */
  579.  
  580. void allpalette( void )
  581. {
  582.   unsigned char far *pptr = MK_FP( _ES, _BX );
  583.   int i;
  584.  
  585.   banner( "ALLPALETTE" );
  586.   i = *pptr++;
  587.   dputs( "    Palette Size:  " );
  588.   putnum( i );
  589.   crlf();
  590.  
  591.   while( i-- ){
  592.     dputs( "      " );
  593.     putnum( *pptr++ );
  594.     crlf();
  595.     }
  596.  
  597. }
  598.  
  599. /* ----------------------------- COLOR --------------------------------- */
  600. /*                                                                       */
  601. /*      The color function takes an index and sets the active fore       */
  602. /*      and background colors for output devices.                        */
  603. /*                                                                       */
  604.  
  605. void color( void )
  606. {
  607.  
  608.   save_regs();                          /* Save a copy of current regs  */
  609.  
  610.   banner( "COLOR" );
  611.   dputs( "    Drawing Color:  " );
  612.   putnum( al );
  613.   dputs( "    Filling Color:  " );
  614.   putnum( ah );
  615.   crlf();
  616.  
  617. }
  618.  
  619. /* ----------------------------- FILLSTYLE ----------------------------- */
  620. /*                                                                       */
  621. /*      The fill style function is used to set the interior style of     */
  622. /*      the filled primatives.  The input to the function is the         */
  623. /*      filled pattern style number, or a flag and a pointer to load     */
  624. /*      an 8x8 bit pattern tile.                                         */
  625. /*                                                                       */
  626.  
  627. void fillstyle( void )
  628. {
  629.  
  630.   static char *fill_name[] = {          /* Names of line styles         */
  631.     "Empty",
  632.     "Solid",
  633.     "Line",
  634.     "Lt Slash",
  635.     "Slash",
  636.     "Bkslash",
  637.     "Ltbkslash",
  638.     "Hatch",
  639.     "Xhatch",
  640.     "Interleave",
  641.     "Wide dot",
  642.     "Close dot",
  643.     "User Defined"
  644.     };
  645.  
  646.   int i;
  647.   unsigned char far *pptr;
  648.  
  649.   save_regs();                          /* Save a copy of current regs  */
  650.   pptr = MK_FP( _ES, _BX );
  651.  
  652.   banner( "FILLSTYLE" );
  653.   dputs( "    Fill Style: (" );
  654.   putnum( al );
  655.   dputs( ")  " );
  656.   dputs( (al == 0xff) ? "User Defined" : fill_name[al] );
  657.   dputs( " Fill\r\n" );
  658.  
  659.   if( al == 0xff ){                     /* User defined line style      */
  660.     dputs( "    User Defined Fill Pattern:\r\n" );
  661.     dputs( "      " );
  662.     for( i=0 ; i<8 ; ++i ){
  663.       puthex( *pptr++ );
  664.       dputs( " " );
  665.       }
  666.     crlf();
  667.     }
  668.  
  669.  
  670. }
  671.  
  672. /* ----------------------------- LINESTYLE ----------------------------- */
  673. /*                                                                       */
  674. /*      The line style command is used to set the style of the lines     */
  675. /*      and borders of objects. The input to the fucntion is the line    */
  676. /*      style number, of a flag and a 16 bit pattern for user defined    */
  677. /*      line drawing styles.                                             */
  678. /*                                                                       */
  679.  
  680. void linestyle( void )
  681. {
  682.   static char *line_name[] = {          /* Names of line styles         */
  683.     "Solid",
  684.     "Dotted",
  685.     "Center",
  686.     "Dashed",
  687.     "User Defined"
  688.     };
  689.  
  690.   save_regs();                          /* Save a copy of current regs  */
  691.  
  692.   banner( "LINESTYLE" );
  693.   dputs( "    Line Style: (" );
  694.   putnum( al );
  695.   dputs( ")  " );
  696.   dputs( line_name[al] );
  697.   dputs( "Line    Line Width:  " );
  698.   putnum( cx );
  699.   crlf();
  700.  
  701.   if( al == 4 ){                        /* User defined line style      */
  702.     dputs( "    User Defined Line Pattern: " );
  703.     puthex( cx );
  704.     crlf();
  705.     }
  706.  
  707. }
  708.  
  709. /* ----------------------------- TEXTSTYLE ----------------------------- */
  710. /*                                                                       */
  711. /*      The text style command is used to define the output font,        */
  712. /*      text path, and text direction for font rendering.                */
  713. /*                                                                       */
  714.  
  715. void textstyle( void )
  716. {
  717.  
  718.   save_regs();                          /* Save a copy of current regs  */
  719.  
  720.   banner( "TEXTSTYLE" );
  721.   dputs( "    Font Number:  " );
  722.   putnum( al );
  723.   dputs( "    Font Path:    " );
  724.   putnum( ah );
  725.   crlf();
  726.   dputs( "    Character Size:  X:  " );
  727.   putnum( bx );
  728.   dputs( "    Y:  " );
  729.   putnum( cx );
  730.   crlf();
  731.  
  732.   _BX = bx;                             /* Return the input as default  */
  733.   _CX = cx;
  734.  
  735. }
  736.  
  737. /* ------------------------------ TEXT --------------------------------- */
  738. /*                                                                       */
  739. /*      The text output command takes a string and renders the string    */
  740. /*      on the output device. The input to the function is the text      */
  741. /*      and the string length.                                           */
  742. /*                                                                       */
  743.  
  744. void text( void )
  745. {
  746.   char far * cptr = MK_FP( _ES, _BX );
  747.   int i;
  748.  
  749.   save_regs();                          /* Save a copy of current regs  */
  750.  
  751.   banner( "TEXT" );
  752.  
  753.   dputs( "    Input Text: \"" );
  754.  
  755. /*      Read sting from the far memory to local memory.                 */
  756.  
  757.   for( i=0 ; i<cx ; ++i ) Buffer[i] = *cptr++;
  758.   Buffer[i] = '\0';                     /* Null terminate string        */
  759.  
  760.   dputs( Buffer );
  761.   dputs( "\"\r\n" );
  762.  
  763. }
  764.  
  765. /* ---------------------------- FLOODFILL ------------------------------ */
  766. /*                                                                       */
  767. /*      This function is a standard floodfill command The input to       */
  768. /*      the function is the seed point for the floodfill. The fill       */
  769. /*      is done in the current drawing color and pattern.                */
  770. /*                                                                       */
  771.  
  772. void floodfill( void )
  773. {
  774.  
  775.   save_regs();                          /* Save a copy of current regs  */
  776.  
  777.   banner( "FLOOD FILL" );
  778.   dputs( "    Seed Point:  X: " );
  779.   putnum( ax );
  780.   dputs( "  Y: " );
  781.   putnum( bx );
  782.   crlf();
  783.  
  784. }
  785.  
  786. /* ---------------------------- GETPIXEL  ------------------------------ */
  787. /*                                                                       */
  788. /*      This function is used to read a pixel from the screen.           */
  789. /*      The function input is the coordinates of the pixel to be         */
  790. /*      read.  The output from the function is the color of the          */
  791. /*      pixel that was read.                                             */
  792. /*                                                                       */
  793.  
  794. void getpixel( void )
  795. {
  796.  
  797.   save_regs();                          /* Save a copy of current regs  */
  798.  
  799.   banner( "GET PIXEL" );
  800.   dputs( "     Pixel Address:  X: " );
  801.   putnum( ax );
  802.   dputs( "  Y: " );
  803.   putnum( bx );
  804.   crlf();
  805.  
  806. }
  807.  
  808. /* ---------------------------- SETPIXEL  ------------------------------ */
  809. /*                                                                       */
  810. /*      This function is used to plot a pixel on the screen.             */
  811. /*      the function input is the coordinates of the pixel to be         */
  812. /*      plotted and the color value of the pixel.                        */
  813. /*                                                                       */
  814.  
  815. void setpixel( void )
  816. {
  817.  
  818.   save_regs();                          /* Save a copy of current regs  */
  819.  
  820.   banner( "SET PIXEL" );
  821.   dputs( "     Pixel Address:  X: " );
  822.   putnum( ax );
  823.   dputs( "  Y: " );
  824.   putnum( bx );
  825.   dputs( "  Value: " );
  826.   putnum( dl );
  827.   crlf();
  828.  
  829. }
  830.  
  831. /* ----------------------------- BITMAPUTIL --------------------------- */
  832. /*                                                                      */
  833. /*      This function returns the base of the bit manipulation utility  */
  834. /*      table. The entry does not perform any function.                 */
  835. /*                                                                      */
  836.  
  837. void bitmaputil( void )
  838. {
  839.  
  840.   banner( "BITMAPUTIL" );
  841.   dputs( "    Bit Map Utility Table Base: " );
  842.   puthex( _DS );
  843.   dputs( ":" );
  844.   puthex( (unsigned int) &Utility_Table );
  845.   crlf();
  846.  
  847.   _ES = _DS;                            /* ES:BX = table address        */
  848.   _BX = (unsigned int) &Utility_Table;  /* Assign Base of table address */
  849.  
  850. }
  851.  
  852. /* -------------------------------------------------------------------- */
  853. /*                                                                      */
  854. /*      The following defines the bit map utilities.                    */
  855. /*                                                                      */
  856. /*      These functions are accessed directly from the calling code,    */
  857. /*      and are not process via the normal BGI Interface. Therefore,    */
  858. /*      these routines must preserve the input data, and must be FAR    */
  859. /*      functions.                                                      */
  860. /*                                                                      */
  861.  
  862. void far enter_graphics( void )         /* Enter graphics mode function */
  863. {
  864.   unsigned int orgds = _DS;
  865.  
  866.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  867.   banner( "Bit Map Function: Enter Pixel Graphics Mode" );
  868.   _DS = orgds;                          /* Restore the original DS      */
  869.  
  870. }
  871.  
  872. void far leave_graphics( void )         /* Leave graphics mode function */
  873. {
  874.   unsigned int orgds = _DS;
  875.  
  876.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  877.   banner( "Bit Map: Leave Pixel Graphics Mode" );
  878.   _DS = orgds;                          /* Restore the original DS      */
  879.  
  880. }
  881.  
  882. void far putpix( void )                 /* Write a pixel function       */
  883. {
  884.   unsigned int arg   = _AX;
  885.   unsigned int orgds = _DS;
  886.  
  887.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  888.   save_regs();                          /* Save a copy of current regs  */
  889.  
  890.   banner( "Bit Map Function: Put Pixel" );
  891.   dputs( "     Pixel Address:  X: " );
  892.   putnum( arg );
  893.   dputs( "  Y: " );
  894.   putnum( bx );
  895.   dputs( "  Value: " );
  896.   putnum( dl );
  897.   crlf();
  898.   _DS = orgds;                          /* Restore the original DS      */
  899.  
  900. }
  901.  
  902. void far getpix( void )                 /* Read a pixel function        */
  903. {
  904.   unsigned int arg   = _AX;
  905.   unsigned int orgds = _DS;
  906.  
  907.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  908.   save_regs();                          /* Save a copy of current regs  */
  909.  
  910.   banner( "Bit Map Function: Get Pixel" );
  911.   dputs( "     Pixel Address:  X: " );
  912.   putnum( arg );
  913.   dputs( "  Y: " );
  914.   putnum( bx );
  915.   crlf();
  916.  
  917.   _DS = orgds;                          /* Restore the original DS      */
  918.   _DL = 5;                              /* Fake return value            */
  919.  
  920. }
  921.  
  922. void far bits_per_pixel( void )         /* returns the bits per pixel   */
  923. {
  924.   #define PIXEL_BITS 4
  925.  
  926.   save_regs();                          /* Save a copy of current regs  */
  927.   banner( "Bit Map Function: Bits Per Pixel" );
  928.   crlf();
  929.  
  930.   _AX = PIXEL_BITS;
  931. }
  932.  
  933. void far set_page( void )               /* Set the active drawing page  */
  934. {
  935.   unsigned int arg   = _AL;
  936.   unsigned int orgds = _DS;
  937.  
  938.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  939.   save_regs();                          /* Save a copy of current regs  */
  940.  
  941.   banner( "Bit Map Function: Set Active Page" );
  942.   dputs( "     Page Number:  " );
  943.   putnum( arg );
  944.   crlf();
  945.   _DS = orgds;                          /* Restore the original DS      */
  946.  
  947. }
  948.  
  949. void far set_visual( void )             /* Set the active display page  */
  950. {
  951.   unsigned int arg   = _AL;
  952.   unsigned int orgds = _DS;
  953.  
  954.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  955.   save_regs();                          /* Save a copy of current regs  */
  956.  
  957.   banner( "Bit Map Function: Set Visual Page" );
  958.   dputs( "     Page Number:  " );
  959.   putnum( arg );
  960.   crlf();
  961.   _DS = orgds;                          /* Restore the original DS      */
  962.  
  963. }
  964.  
  965. void far set_write_mode( void )         /* Set the current write mode   */
  966. {
  967.   unsigned int arg   = _AX;
  968.   unsigned int orgds = _DS;
  969.  
  970.   _DS = _CS;                            /* Point Data Seg to Code Seg   */
  971.   save_regs();                          /* Save a copy of current regs  */
  972.  
  973.   banner( "Bit Map Function: Set Write Mode" );
  974.   dputs( "     XOR Write Mode:  (" );
  975.   putnum( arg );
  976.   dputs( ")  " );
  977.   dputs( arg ? "On\r\n" : "Off\r\n" );
  978.   _DS = orgds;                          /* Restore the original DS      */
  979.  
  980. }
  981.  
  982.  
  983. /* ---------------------------- RESTOREBITMAP -------------------------- */
  984. /*                                                                       */
  985. /*      The restore bit map function is used to load a retangular        */
  986. /*      region from the host memory into the graphics memory. The        */
  987. /*      input to the routine is the region to write, a pointer to        */
  988. /*      the source in the host's memory, and the mode to use when        */
  989. /*      writing the region.                                              */
  990. /*                                                                       */
  991.  
  992. void restorebitmap( void )
  993. {
  994.   unsigned int si = _SI;
  995.   unsigned int di = _DI;
  996.  
  997.   save_regs();                          /* Save a copy of current regs  */
  998.  
  999.   banner( "RESTOREBITMAP" );
  1000.  
  1001.   dputs( "    Restore Buffer at  " );
  1002.   puthex( _ES );
  1003.   dputs( ":" );
  1004.   puthex( bx );
  1005.   crlf();
  1006.  
  1007.   dputs( "    Start  X:  " );
  1008.   putnum( si );
  1009.   dputs( "  Y: " );
  1010.   putnum( di );
  1011.   dputs( "    End  X:  " );
  1012.   putnum( cx );
  1013.   dputs( "  Y: " );
  1014.   putnum( dx );
  1015.   crlf();
  1016.  
  1017. }
  1018.  
  1019. /* ---------------------------- SAVEBITMAP ----------------------------- */
  1020. /*                                                                       */
  1021. /*      The save bit map function is used to write a rectangular         */
  1022. /*      region from the graphics memory to the host memory. The input    */
  1023. /*      to the function is the region to be read, and a pointer to       */
  1024. /*      a save buffer in the host memory.                                */
  1025. /*                                                                       */
  1026.  
  1027. void savebitmap( void )
  1028. {
  1029.   unsigned int si = _SI;
  1030.   unsigned int di = _DI;
  1031.  
  1032.   save_regs();                          /* Save a copy of current regs  */
  1033.  
  1034.   banner( "SAVEBITMAP" );
  1035.  
  1036.   dputs( "    Save Buffer at  " );
  1037.   puthex( _ES );
  1038.   dputs( ":" );
  1039.   puthex( bx );
  1040.   crlf();
  1041.  
  1042.   dputs( "    Start  X:  " );
  1043.   putnum( si );
  1044.   dputs( "  Y: " );
  1045.   putnum( di );
  1046.   dputs( "    End  X:  " );
  1047.   putnum( cx );
  1048.   dputs( "  Y: " );
  1049.   putnum( dx );
  1050.   crlf();
  1051.  
  1052. }
  1053.  
  1054. /* ---------------------------- SETCLIP -------------------------------- */
  1055. /*                                                                       */
  1056. /*      The setclip function defines a clipping rectangle on the         */
  1057. /*      output device.  The input to the function defines the            */
  1058. /*      coordinated of the opposing corners of the clipping rectangle.   */
  1059. /*                                                                       */
  1060. /*                                                                       */
  1061.  
  1062. void setclip( void )
  1063. {
  1064.  
  1065.   save_regs();                          /* Save a copy of current regs  */
  1066.  
  1067.   banner( "SETCLIP" );
  1068.   dputs( "    Upper Left:  X: " );
  1069.   putnum( ax );
  1070.   dputs( "  Y: " );
  1071.   putnum( bx );
  1072.   dputs( "  Lower Right:  X: " );
  1073.   putnum( cx );
  1074.   dputs( "  Y: " );
  1075.   putnum( dx );
  1076.   crlf();
  1077.  
  1078. }
  1079.  
  1080. /* ---------------------------- GETPIXEL ------------------------------- */
  1081. /*                                                                       */
  1082. /*      The GetPixel function is used to read a specific pixel value     */
  1083. /*      from the graphics screen. The input is the coordinate of the     */
  1084. /*      pixel to be read. The output is the pixel value.                 */
  1085. /*                                                                       */
  1086.  
  1087. void get_pixel( void )
  1088. {
  1089.  
  1090.   save_regs();                          /* Save a copy of current regs  */
  1091.  
  1092.   banner( "GET PIXEL" );
  1093.   dputs( "    Pixel Address:  X: " );
  1094.   putnum( ax );
  1095.   dputs( "  Y: " );
  1096.   putnum( bx );
  1097.   crlf();
  1098.  
  1099.   _DL = 5;                              /* Return 5 as fake value       */
  1100.  
  1101. }
  1102.  
  1103. /* ---------------------------- SETPIXEL ------------------------------- */
  1104. /*                                                                       */
  1105. /*      The SetPixel command is used to write a specific pixel to        */
  1106. /*      the graphics area. The input values are the coordinate of        */
  1107. /*      the pixel to write, and the pixel value to write.                */
  1108. /*                                                                       */
  1109.  
  1110. void set_pixel( void )
  1111. {
  1112.  
  1113.   save_regs();                          /* Save a copy of current regs  */
  1114.  
  1115.   banner( "SET PIXEL" );
  1116.   dputs( "    Pixel Address:  X: " );
  1117.   putnum( ax );
  1118.   dputs( "  Y: " );
  1119.   putnum( bx );
  1120.   dputs( "  Value:  " );
  1121.   putnum( dl );
  1122.   crlf();
  1123.  
  1124. }
  1125.  
  1126. /* ---------------------------- ESCAPE -------------------------------- */
  1127.  
  1128. void escape( void )
  1129. {
  1130.  
  1131.   save_regs();                          /* Save a copy of current regs  */
  1132.  
  1133.   banner( "ESCAPE" );
  1134.  
  1135. }
  1136.  
  1137. /* ---------------------------- TEXTSIZE ------------------------------- */
  1138. /*                                                                       */
  1139. /*      The textsize function allows the kernal to inquire the size      */
  1140. /*      of text strings. The input to the function is a pointer to       */
  1141. /*      text and the length of the string. The output is the horz        */
  1142. /*      and vert dimensions of the string in pixels.                     */
  1143. /*                                                                       */
  1144.  
  1145. void textsiz( void )
  1146. {
  1147.   char far * cptr;
  1148.   int i;
  1149.  
  1150.   save_regs();                          /* Save a copy of current regs  */
  1151.   cptr = MK_FP( _ES, _BX );             /* Make a pointer to the text   */
  1152.  
  1153.   banner( "TEXT SIZE" );
  1154.   dputs( "    Input Text: \"" );
  1155.  
  1156. /*      Read sting from the far memory to local memory.                 */
  1157.  
  1158.   for( i=0 ; i<cx ; ++i ) Buffer[i] = *cptr++;
  1159.   Buffer[i] = '\0';                     /* Null terminate string        */
  1160.  
  1161.   dputs( Buffer );
  1162.   dputs( "\"\r\n" );
  1163.  
  1164.   _BX = cx * 8;                         /* Return default size info     */
  1165.   _CX = 8;
  1166.  
  1167. }
  1168.  
  1169. /* ---------------------------- COLOR_QUERY --------------------------- */
  1170. /*                                                                      */
  1171. /*      This function allows the kernal to inquire the size and base    */
  1172. /*      colors for the current device.                                  */
  1173. /*                                                                      */
  1174.  
  1175. void color_query( void )
  1176. {
  1177.   int i;
  1178.  
  1179.   save_regs();                          /* Save a copy of current regs  */
  1180.  
  1181.   i = Stat_Block.fcolors & 0x7f;        /* Get color info w/o flag bit  */
  1182.  
  1183.   banner( "QUERY COLOR" );
  1184.   switch( al ){                         /* Act on the input command     */
  1185.     case 0:                             /* Color palette size query     */
  1186.       dputs( "    Color Table Size:  (Size: " );
  1187.       putnum( i );
  1188.       dputs( "  Maximum Color: " );
  1189.       putnum( i-1 );
  1190.       dputs( ")\r\n" );
  1191.       _BX = i;                          /* Return the table size        */
  1192.       _CX = i - 1;                      /* Return the maximum color #   */
  1193.       break;
  1194.  
  1195.     case 1:                             /* Default palette settings     */
  1196.       dputs( "    Default Palette Query\r\n" );
  1197.       _ES = _CS;                        /* Mask ES:BX point to default  */
  1198.       _BX = (unsigned int) &Default_Palette;
  1199.       break;
  1200.  
  1201.     default:
  1202.       dputs( "    ERROR: Unknown Color Query Command: " );
  1203.       puthex( al );
  1204.       crlf();
  1205.       break;
  1206.     }
  1207.  
  1208. }
  1209.  
  1210. /* ---------------------------- SETWINDOW ------------------------------ */
  1211. /*                                                                       */
  1212. /*      The setwindow function defines a VDC space on the output device  */
  1213. /*      The input to the function defines the VDC's to be set to the     */
  1214. /*      current clipping viewport.                                       */
  1215. /*                                                                       */
  1216. /*                                                                       */
  1217.  
  1218. void setwindow( void )
  1219. {
  1220.  
  1221.   save_regs();                          /* Save a copy of current regs  */
  1222.  
  1223.   banner( "SETWINDOW" );
  1224.   dputs( "    Upper Left:  X: " );
  1225.   putnum( ax );
  1226.   dputs( "  Y: " );
  1227.   putnum( bx );
  1228.   dputs( "  Lower Right:  X: " );
  1229.   putnum( cx );
  1230.   dputs( "  Y: " );
  1231.   putnum( dx );
  1232.   crlf();
  1233.  
  1234. }
  1235.  
  1236. /* ----------------------------- BANNER ------------------------------- */
  1237. /*                                                                      */
  1238. /*      This function sends a string to the console via a direct        */
  1239. /*      DOS Function 9. The string is place inside a standard banner    */
  1240. /*      before being sent to the console.                               */
  1241. /*                                                                      */
  1242.  
  1243. void banner( char *string )
  1244. {
  1245.   static char header[] = ">>> DEBUG: ";
  1246.  
  1247.   dputs( header );
  1248.   dputs( string );
  1249.   crlf();
  1250.  
  1251. }
  1252.  
  1253.  
  1254. /* ----------------------------- PUTNUM ------------------------------- */
  1255. /*                                                                      */
  1256. /*      This function converts a number to a decimal ASCII string.      */
  1257. /*      The string is then sent to the console via a DPUTS command.     */
  1258. /*                                                                      */
  1259.  
  1260. void putnum( unsigned number )          /* Output Decimal Number        */
  1261. {
  1262.   static char numstr[10] = "XXXXXXXX";  /* String for conversion space  */
  1263.  
  1264.   itoa( number, numstr, 10 );           /* Convert to decimal string    */
  1265.   dputs( numstr );                      /* Send number to console       */
  1266.  
  1267. }
  1268.  
  1269.  
  1270. /* ----------------------------- PUTHEX ------------------------------- */
  1271. /*                                                                      */
  1272. /*      This function converts a number to a hexidecimal ASCII string.  */
  1273. /*      The string is then sent to the console via a DPUTS command.     */
  1274. /*                                                                      */
  1275.  
  1276. void puthex( unsigned number )          /* Output Hexidecimal Number    */
  1277. {
  1278.   static char hextbl[] = "0123456789ABCDEF";
  1279.   static char numstr[] = "XXXX";       /* String space for conversion  */
  1280.  
  1281.   numstr[3] = hextbl[ number & 0x000f ];
  1282.   number >>= 4;
  1283.  
  1284.   numstr[2] = hextbl[ number & 0x000f ];
  1285.   number >>= 4;
  1286.  
  1287.   numstr[1] = hextbl[ number & 0x000f ];
  1288.   number >>= 4;
  1289.  
  1290.   numstr[0] = hextbl[ number & 0x000f ];
  1291.  
  1292.   dputs( numstr );                      /* Send number to console       */
  1293.  
  1294. }
  1295.  
  1296.  
  1297. /* ----------------------------- DPUTS -------------------------------- */
  1298. /*                                                                      */
  1299. /*      This function send a string to the console using DOS.           */
  1300. /*                                                                      */
  1301.  
  1302. void dputs( char far *str )             /* Output string to console     */
  1303. {
  1304.   char far *cptr = str;                 /* Point at input string        */
  1305.  
  1306.   while( *cptr ){                       /* Send NULL terminated string  */
  1307.     _AH = 2;                            /* DOS Charater output function */
  1308.     _DL = *cptr++;                      /* Pick up character to send    */
  1309.     geninterrupt( 0x21 );               /* Enter DOS to send character  */
  1310.     }
  1311.  
  1312. }
  1313.  
  1314. /* ----------------------------- CRLF --------------------------------- */
  1315. /*                                                                      */
  1316. /*      This function send a Carrage Return and Line Feed to the        */
  1317. /*      console.                                                        */
  1318. /*                                                                      */
  1319.  
  1320. void crlf( void )                       /* goto new line on screen      */
  1321. {
  1322.   static char str[] = "\r\n";           /* New line string to DOS       */
  1323.  
  1324.   dputs( str );                         /* Send string to console       */
  1325.  
  1326. }
  1327.  
  1328. /* ----------------------------- SAVEREGS ----------------------------- */
  1329. /*                                                                      */
  1330. /*      This function saves a copy of all of the input registers.       */
  1331. /*      This function is needed because C does hidden things with       */
  1332. /*      registers, which would require constant PUSH's and POP's.       */
  1333. /*                                                                      */
  1334.  
  1335. void save_regs( void )                  /* Save registers into memory   */
  1336. {
  1337.  
  1338.   ax = _AX;     al = _AL;       ah = _AH;
  1339.   bx = _BX;     bh = _BH;       bl = _BL;
  1340.   cx = _CX;     ch = _CH;       cl = _CL;
  1341.   dx = _DX;     dh = _DH;       dl = _DL;
  1342.  
  1343. }
  1344.  
  1345.