home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v2.zip / DDKX86 / DBCSDD / SRC_DBCS / VDHV / VDHFONT.C < prev    next >
C/C++ Source or Header  |  1995-04-14  |  12KB  |  257 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT (C) Microsoft Corporation, 1989                                 */
  4. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  5. /*                                                                           */
  6. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  7. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  8. /*    drivers. You may use this code in accordance with the IBM License      */
  9. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  10. /*    Copyright statement may not be removed.                                */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13. /*****************************************************************************
  14.  *
  15.  * SOURCE FILE NAME = VDHFONT.c
  16.  *
  17.  * DESCRIPTIVE NAME = Base video device handlers - Font support
  18.  *
  19.  *
  20.  * VERSION = V2.0
  21.  *
  22.  * DATE
  23.  *
  24.  * DESCRIPTION   This source file contains VDH entry points which get/set
  25.  *               the current font.
  26.  *
  27.  * FUNCTIONS     GetCurrentFont, SetCurrentFont, SetHWFont, FindFont
  28.  *
  29.  * NOTES
  30.  *
  31.  * STRUCTURES
  32.  *
  33.  * EXTERNAL REFERENCES  SaveRegs, RestoreRegs
  34.  *                      AccessHardware, AccessFont
  35.  *
  36.  * EXTERNAL FUNCTIONS
  37.  *
  38. */
  39.  
  40. /*
  41.  ╔════════════════════════════════════════════════════════════════════════════╗
  42.  ║  Include files                                                             ║
  43.  ╚════════════════════════════════════════════════════════════════════════════╝
  44. */
  45. #define INCL_BASE               /* ALL of OS/2 Base                */
  46. #include <os2.h>
  47.  
  48. #include "vdhctl.h"             /* Conditional compilation control */
  49. #include "vdh.h"                /* Type definitions                */
  50. #include "fntcalls.h"           /* FNTCALLS definition         */   //J-TS00
  51.  
  52. /*
  53.  ╔════════════════════════════════════════════════════════════════════════════╗
  54.  ║  Externally defined global variables                                       ║
  55.  ╚════════════════════════════════════════════════════════════════════════════╝
  56. */
  57. extern USHORT VGA_PRESENT;      /* TRUE if VGA VDH has been installed */
  58. extern USHORT (APIENTRY *ChainedCallVectorTable[MaxFn])();           /* @T24 */
  59.  
  60. /**********************  START OF SPECIFICATIONS  ***********************/
  61. /*                                                                      */
  62. /*  SUBROUTINE NAME: GetCurrentFont                                     */
  63. /*                                                                      */
  64. /*  DESCRIPTIVE NAME: Get color lookup table                            */
  65. /*                                                                      */
  66. /*  FUNCTION: GetCurrentFont is called by BVS to return the current     */
  67. /*            active video font.                                        */
  68. /*                                                                      */
  69. /*  ENTRY POINT: GetCurrentFont                                         */
  70. /*    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 267 )   */
  71. /*                                                                      */
  72. /*  INPUT: (Passed on stack)                                            */
  73. /*             FAR *Environment ( Environment buffer for the session )  */
  74. /*             FAR *ParmBlock                                           */
  75. /*                     USHORT Length = length of this packet            */
  76. /*                     USHORT Flags  = 0 - Environment buffer only      */
  77. /*                                     1 - Hardware also                */
  78. /*                     UCHAR far *FontBuffer                            */
  79. /*                     USHORT     FontLength                            */
  80. /*                     USHORT     PelColumns                            */
  81. /*                     USHORT     PelRows                               */
  82. /*             ULONG Function ( Call vector table entry = 267 )         */
  83. /*                                                                      */
  84. /*  EXIT-NORMAL: AX = 0                                                 */
  85. /*               Current font is returned to caller                     */
  86. /*                                                                      */
  87. /*  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS                            */
  88. /*                                                                      */
  89. /*  INTERNAL REFERENCES:                                                */
  90. /*    ROUTINES: NONE                                                    */
  91. /*                                                                      */
  92. /*  EXTERNAL REFERENCES:                                                */
  93. /*    ROUTINES: PhysToUVirt, FreePhysToUVirt                            */
  94. /*              AccessFont                                              */
  95. /*                                                                      */
  96. /***********************  END OF SPECIFICATIONS  ************************/
  97.  
  98. USHORT EXPENTRY GetCurrentFont( Environment, ParmBlock, Function )
  99. ENVIRONMENT far *Environment;
  100. VDH_FONT far *ParmBlock;
  101. ULONG Function;
  102. {
  103. USHORT rc,
  104.        FontSize,
  105.        EnvBufferPassed;
  106.  
  107.   /*SaveRegs();*/ /*@B14*/
  108.  
  109.   rc = ERROR_VIO_INVALID_PARMS;
  110.   EnvBufferPassed = SEG( Environment );             /* Non-zero = TRUE     */
  111.  
  112.   if ( EnvBufferPassed &&
  113.       !Environment->NATIVE_MODE &&
  114.        VGA_PRESENT               ) {
  115.                                                     /* VGA Mode */
  116.     rc = ChainedVDHGetCurrentFont(
  117.                    (ENVIRONMENT far *)&Environment->VGAEnvironment,
  118.                    ParmBlock, Function );
  119.  
  120.   } else {                                          /* ATLAS Mode */
  121.  
  122.     if (   EnvBufferPassed &&
  123.          ( Function == FnGetFont ) &&                   /* Valid function request */
  124.          ( ParmBlock->Length >= sizeof( VDH_FONT ) ) && /* Valid Length */
  125.          ( ParmBlock->Flags <= 3 ) ) {                  /* Valid flags  */
  126.  
  127.       rc = NO_ERROR;                                    /* Parameters are OK */
  128.       if ( Environment->ModeData.fbType & GRAPHICS )    /* Graphic mode?  */
  129.         rc = ERROR_VIO_MODE;
  130.       else if ( ParmBlock->Flags & GET_ROM_FONT )       /* Get ROM font? */
  131.         rc = ERROR_VIO_FONT;
  132.  
  133.       if ( !rc ) {
  134.  
  135.         FontSize = 256 * 19;
  136.  
  137.         if ( ( ParmBlock->FontLength == NULL ) &&   /* Return font size only */
  138.              ( ParmBlock->FontBuffer == NULL ) ) {  /*                  @T11 */
  139.  
  140.           ParmBlock->FontLength = FontSize;
  141.  
  142.         } else if ( ParmBlock->FontLength < FontSize ) {
  143.  
  144.           rc = ERROR_VIO_INVALID_LENGTH;
  145.  
  146.         } else {    /* Return complete font information */
  147.  
  148.           ParmBlock->PelColumns =  8;
  149.           ParmBlock->PelRows    = 19;
  150.           ParmBlock->FontLength = FontSize; /* in case too much specified */
  151.  
  152.           if ((rc = FNTGETFONT ( 0, 256, ParmBlock->FontBuffer )))
  153.             rc = ERROR_VIO_FONT;
  154.  
  155.         }
  156.       }
  157.     }
  158.   } /* Device Chaining */
  159.  
  160.   /*RestoreRegs();*/ /*@B14*/
  161.   return( rc );
  162. }
  163.  
  164. /**********************  START OF SPECIFICATIONS  ***********************/
  165. /*                                                                      */
  166. /*  SUBROUTINE NAME: SetCurrentFont                                     */
  167. /*                                                                      */
  168. /*  DESCRIPTIVE NAME: Set color lookup table                            */
  169. /*                                                                      */
  170. /*  FUNCTION: SetCurrentFont is called by BVS to load the specified     */
  171. /*            video text font                                           */
  172. /*                                                                      */
  173. /*  ENTRY POINT: SetCurrentFont                                         */
  174. /*    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 268 )   */
  175. /*                                                                      */
  176. /*  INPUT: (Passed on stack)                                            */
  177. /*             FAR *Environment ( Environment buffer for the session )  */
  178. /*             FAR *ParmBlock                                           */
  179. /*                     USHORT Length = length of this packet            */
  180. /*                     USHORT Flags  = 0 - Environment buffer only      */
  181. /*                                     1 - Hardware also                */
  182. /*                     UCHAR far *FontBuffer                            */
  183. /*                     USHORT     FontLength                            */
  184. /*                     USHORT     PelColumns                            */
  185. /*                     USHORT     PelRows                               */
  186. /*             ULONG Function ( Call vector table entry = 268 )         */
  187. /*                                                                      */
  188. /*  EXIT-NORMAL: AX = 0                                                 */
  189. /*               Current font is set                                    */
  190. /*                                                                      */
  191. /*  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS                            */
  192. /*                                                                      */
  193. /*  INTERNAL REFERENCES:                                                */
  194. /*    ROUTINES: NONE                                                    */
  195. /*                                                                      */
  196. /*  EXTERNAL REFERENCES:                                                */
  197. /*    ROUTINES: PhysToUVirt, FreePhysToUVirt                            */
  198. /*              AccessFont                                              */
  199. /*                                                                      */
  200. /***********************  END OF SPECIFICATIONS  ************************/
  201. USHORT EXPENTRY SetCurrentFont( Environment, ParmBlock, Function )
  202. ENVIRONMENT far *Environment;
  203. VDH_FONT far *ParmBlock;
  204. ULONG Function;
  205. {
  206. FarAddress VideoFontBuffer;
  207. USHORT rc,
  208.        FontLength,
  209.        EnvBufferPassed;
  210.  
  211.   /*SaveRegs();*/ /*@B14*/                  /* Preserve registers and flags */
  212.  
  213.   rc = ERROR_VIO_INVALID_PARMS;
  214.   EnvBufferPassed = SEG( Environment );             /* Non-zero = TRUE     */
  215.  
  216.   if ( EnvBufferPassed &&
  217.       !Environment->NATIVE_MODE &&
  218.        VGA_PRESENT               ) {
  219.                                                     /* VGA Mode */
  220.     rc = ChainedVDHSetCurrentFont(
  221.                    (ENVIRONMENT far *)&Environment->VGAEnvironment,
  222.                     ParmBlock, Function );
  223.  
  224.   } else {                                          /* ATLAS Mode */
  225.  
  226.     if ( ( Function == FnSetFont ) &&                   /* Valid function request */
  227.          ( ParmBlock->Length >= sizeof( VDH_FONT ) ) && /* Valid Length */
  228.          ( ParmBlock->Flags <= 1 )                   && /* Valid flags  */
  229.          ( EnvBufferPassed ) ) {
  230.  
  231.       rc = ERROR_VIO_MODE;                                  /* Preset invalid mode */
  232.       if ( !(Environment->ModeData.fbType & GRAPHICS) ) {   /* Text mode only      */
  233.  
  234.         rc = NO_ERROR;                                     /* Parameters are OK */
  235.         if ( ParmBlock->FontLength < 256 * 19 )
  236.           rc = ERROR_VIO_INVALID_LENGTH;
  237.         else
  238.           if (  ParmBlock->PelRows    != 19   ||
  239.                 ParmBlock->PelColumns != 8 )
  240.             rc = ERROR_VIO_USER_FONT;
  241.  
  242.         if ( !rc ) {
  243.  
  244.           if ((rc = FNTSETFONT ( 0, 256, ParmBlock->FontBuffer ))) {
  245.             rc = ERROR_VIO_FONT;
  246.           } else {
  247.             Environment->UserFont = USER_FONT_SELECTABLE;
  248.           }
  249.         }
  250.       }
  251.     }
  252.   } /* Device Chaining */
  253.  
  254.   /*RestoreRegs();*/ /*@B14*/           /* Restore registers and flags */
  255.   return( rc );
  256. }
  257.