home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / VDH / VDHGETCP.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  15KB  |  381 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.         PAGE    58,132
  13.         TITLE   VdhGetCP.Asm -- Get CodePage Fonts from the Font File
  14.  
  15. ;/****************************************************************************
  16. ;*
  17. ;* SOURCE FILE NAME = VdhGetCP.Asm
  18. ;*
  19. ;* DESCRIPTIVE NAME = Get CodePage Fonts from the Font File 
  20. ;*
  21. ;*
  22. ;* VERSION      V2.0
  23. ;*
  24. ;* DATE         
  25. ;*
  26. ;* DESCRIPTION  Get CodePage Fonts from the Font File  
  27. ;*
  28. ;* FUNCTIONS    _GetCodePage 
  29. ;*              ReadFont
  30. ;*              RandomRead 
  31. ;*
  32. ;* NOTES        NONE
  33. ;*
  34. ;* STRUCTURES   NONE
  35. ;*
  36. ;* EXTERNAL REFERENCES  CDIB                              
  37. ;*
  38. ;* EXTERNAL FUNCTIONS   DOSOPEN, DOSREAD, DOSCHGFILEPTR, DOSCLOSE,  
  39. ;*                      DOSGETSHRSEG, DOSFREESEG
  40. ;*
  41. ;* CHANGE ACTIVITY =
  42. ;*   DATE      FLAG        APAR    CHANGE DESCRIPTION
  43. ;*   --------  ----------  -----   --------------------------------------
  44. ;*   mm/dd/yy  @Vr.mpppxx  xxxxx   xxxxxxx
  45. ;****************************************************************************/
  46.  
  47.         .286p
  48.  
  49.         INCLUDE cdib.inc                          ;CodePage Data Info Block
  50.         INCLUDE fontfile.inc                      ;Font File structures
  51.         .xlist
  52.         INCLUDE error2.inc                        ;Error codes
  53.         INCLUDE struc.inc                         ;Structured Macros
  54.         .list
  55.  
  56.         EXTRN   DOSGETSHRSEG:FAR                  ;Dos Get Shared Segment routine
  57.         EXTRN   DOSFREESEG:FAR                    ;Dos Free Segment routine
  58.  
  59.         EXTRN   DOSOPEN:FAR                       ;Dos Open routine
  60.         EXTRN   DOSREAD:FAR                       ;Dos Read routine
  61.         EXTRN   DOSCHGFILEPTR:FAR                 ;Dos Change File Ptr routine
  62.         EXTRN   DOSCLOSE:FAR                      ;Dos Close routine
  63.  
  64.         extrn   _SaveRegs:FAR
  65.         extrn   _RestoreRegs:FAR
  66.  
  67. VDHGSEG SEGMENT PARA PUBLIC 'DATA'      ;Global data segment for WDH
  68.  
  69. CDIBsel dw      0                                 ;CDIB selector
  70. Handle  dw      0                                 ;Font file handle
  71. CPID    dw      0                                 ;Selected CodePage Id
  72. NumFonts dw     0                                 ;Number of Fonts read
  73. TotalSize dw    0                                 ;Total Size of Fonts read
  74. FontSizes dw    0,0,0,0,0,0,0,0,0,0               ;Sizes of Fonts read
  75.         public  FontSizes
  76.  
  77. Buffer  fonthdr <>                                ;Read buffer for font headers
  78. Scratch dd      0                                 ;Scratch area
  79.  
  80. CDIBname db     '\SHAREMEM\DOS\CDIB',0  ;CDIB name
  81.  
  82. VDHGSEG ENDS
  83.  
  84. R2CSEG  SEGMENT BYTE PUBLIC 'CODE'
  85.         ASSUME  CS:R2CSEG
  86.  
  87. ;/****************************************************************************
  88. ;*
  89. ;* SUBROUTINE NAME:  GetPreparedCodePages          
  90. ;*                                                   
  91. ;* DESCRIPTIVE NAME:   Get the Prepared CodePages for the VDH  
  92. ;*                                                   
  93. ;* FUNCTION:   Copies the requested CodePage fonts to the callers 
  94. ;*             data area.                            
  95. ;*                                                   
  96. ;* NOTES:  Executes on Level 3                      
  97. ;*                                                   
  98. ;* ENTRY POINT:  GetPreparedCodePages               
  99. ;*   LINKAGE:  Call GetPreparedCodePages           
  100. ;*                                                   
  101. ;* INPUT:  DS = PPBVSCB, ES = CodePage Data Info Block (CDIB)  
  102. ;*         CX = Number of CodePages                 
  103. ;*         SI = Offset of CodePage substructure in CDIB  
  104. ;*                                                   
  105. ;* EXIT-NORMAL:  AX = 0                              
  106. ;*                                                   
  107. ;* EXIT-ERROR:  AX = DOSxxx return code            
  108. ;*                                                   
  109. ;* EFFECTS:  None                                    
  110. ;*                                                   
  111. ;* INTERNAL REFERENCES: None                         
  112. ;*   ROUTINES:  ReadFont, RandomRead                
  113. ;*                                                   
  114. ;* EXTERNAL REFERENCES:  CDIB                        
  115. ;*   ROUTINES: DOSOPEN, DOSREAD, DOSCHGFILEPTR, DOSCLOSE,  
  116. ;*             DOSGETSHRSEG, DOSFREESEG
  117. ;****************************************************************************/
  118.  
  119. ;/****************************************************************************
  120. ;*
  121. ;* FUNCTION NAME = _GetCodePage
  122. ;*
  123. ;* DESCRIPTION   = 
  124. ;*
  125. ;* INPUT         = 
  126. ;* OUTPUT        = NONE
  127. ;*
  128. ;* RETURN-NORMAL = NONE
  129. ;* RETURN-ERROR  = NONE
  130. ;*
  131. ;* PSEUDOCODE
  132. ;*
  133. ;*      Bgnsub CPInit
  134. ;*        Get the Screen information from the CDIB
  135. ;*        If CodePages specified
  136. ;*          Call DOSOPEN for the CodePage file
  137. ;*          If no error
  138. ;*            Call RandomRead to get the number of fonts from the header
  139. ;*            Do for each specified code page
  140. ;*              Do for each font in the font file
  141. ;*                Call RandomRead to get the font ptr from the file header
  142. ;*                Call RandomRead to get the complete font header
  143. ;*                If font is for this CodePage
  144. ;*                  Call ReadFont to update BVSCPnn
  145. ;*                Endif
  146. ;*              Enddo
  147. ;*            Enddo
  148. ;*            Call DOSCLOSE for the CodePage file
  149. ;*          Endif
  150. ;*        Endif
  151. ;*      Endsub
  152. ;*
  153. ;****************************************************************************/
  154.  
  155. _GetCodePage PROC FAR
  156.         public  _GetCodePage
  157.  
  158.         push    bp
  159.         mov     bp,sp
  160.         Call    _SaveRegs
  161.         push    ds
  162.  
  163.         push    VDHGSEG
  164.         pop     ds
  165.         sub     bx,bx
  166.  
  167.         mov     ds:NumFonts,bx                    ;Init number of fonts read to zero
  168.         mov     ds:TotalSize,bx                   ;Init size of fonts read to zero
  169.  
  170.         push    ds
  171.         push    offset CDIBname                   ;Ptr to CDIB name
  172.         push    ds
  173.         push    offset CDIBsel                    ;Ptr to CDIB selector
  174.         Call    DOSGETSHRSEG                      ;Get the CDIB selector
  175.  
  176.         .if     <zero ax> near
  177.             mov     es,ds:CDIBsel
  178.             mov     di,es:[bx].CDIB_codepage_ptr ;ES:DI = CodePage Info
  179.             mov     cx,es:[di].CDIB_cp_number_codepages
  180.  
  181.             mov     ax,ERROR_VIO_BAD_CP
  182.             mov     si,[bp+6]                     ;Get requested CP Id index
  183.             .if     <si b cx> near                ;Requested CP not available
  184.  
  185.                 imul    si,size CDIB_cp_id_section
  186.                 add     si,di
  187.                 mov     si,es:[si].CDIB_cp_first_id ;Get selected CP Id
  188.                 mov     ds:CPID,si               ;Save in global data
  189.  
  190.                 mov     di,es:[bx].CDIB_screen_ptr ;Get offset of screen
  191.                 .if     <nonzero di>             ;Screen substructure found
  192.                     mov     di,es:[di].CDIB_dev_filename_ptr ;Offset of file name
  193.                 .endif
  194.  
  195.                 .if     <nonzero di>             ;Filename specified
  196.                     push    es
  197.                     push    di                   ;Device name ASCIIZ string
  198.                     push    ds
  199.                     push    offset Handle ;Return for device handle
  200.                     push    ds
  201.                     push    offset Scratch ;Action Taken
  202.                     push    bx
  203.                     push    bx            ;File Size
  204.                     push    bx            ;File Attribute
  205.                     push    00001h        ;Open Flag = Fail if missing
  206.                     push    00020h        ;Open Mode = Read Only/Deny Write
  207.                     push    bx
  208.                     push    bx            ;Reserved (0:0)
  209.                     Call    DOSOPEN       ;Open the CodePage file
  210.  
  211.                     .if     <zero ax>
  212.                         sub              dx,dx
  213.                         sub              si,si ;Point to file header
  214.  
  215.                         push             ds
  216.                         pop              es
  217.                         mov              di,offset ds:Buffer ;ES:DI = Buffer ptr
  218.                         mov              cx,size fontfilehdr
  219.                         Call             RandomRead ;Read the font file header
  220.  
  221.                         .if              <zero ax>
  222.                             mov     cx,word ptr ds:Buffer+ffh_numfonts ;Number
  223.                             mov     si,word ptr ds:Buffer+ffh_ptroffset ;Offset
  224.  
  225.                             .repeat
  226.                                  push cx ;Number of fonts left in file
  227.                                  sub dx,dx
  228.                                  push si ;Fonthdr ptr
  229.  
  230.                                  push ds
  231.                                  pop es
  232.                                  mov di,offset ds:Buffer
  233.                                  mov cx,4
  234.                                  Call RandomRead ;Read the fonthdr ptr
  235.                                  .if <zero ax>
  236.  
  237.                                      mov     si,word ptr ds:Buffer
  238.                                      mov     dx,word ptr ds:Buffer+2 ;Get fonthdr ptr
  239.                                      mov     cx,size fonthdr
  240.                                      Call    RandomRead ;Read the fonthdr
  241.                                      .if     <zero ax>
  242.  
  243.                                   mov ax,ds:CPID
  244.                                   .if <ax eq <word ptr ds:Buffer+fh_cpid>>
  245.                                       Call    ReadFont
  246.                                   .endif
  247.  
  248.                                      .endif
  249.                                  .endif
  250.  
  251.                                  pop si
  252.                                  add si,4 ;Next ptr to font ptr
  253.                                  pop cx
  254.                             .loop                ;Until all fonts examined
  255.  
  256.                         .endif
  257.                         push                     ds:Handle
  258.                         Call                     DOSCLOSE ;Close the Font File
  259.                     .endif
  260.                 .endif
  261.  
  262.                 mov     ax,ERROR_VIO_BAD_CP ;Preset error code
  263.                 .if     <ds:NumFonts ne bx> ;Some fonts were loaded
  264.                     les     di,dword ptr [bp+8]
  265.                     mov     ax,ds:CPID
  266.                     stosw                         ;Return CodePage Id
  267.  
  268.                     sub     ax,ax                 ;Set good return code
  269.                 .endif
  270.             .endif
  271.  
  272.             push    ax
  273.             push    ds:CDIBsel
  274.             Call    DOSFREESEG                    ;Relinquish use of the CDIB
  275.             pop     ax
  276.         .endif
  277.  
  278.         pop     ds
  279.         Call    _RestoreRegs
  280.         pop     bp
  281.         RET
  282. _GetCodePage ENDP
  283.  
  284. ;/****************************************************************************
  285. ;*
  286. ;* FUNCTION NAME = ReadFont
  287. ;*
  288. ;* DESCRIPTION   = 
  289. ;*
  290. ;* INPUT         = 
  291. ;* OUTPUT        = NONE
  292. ;*
  293. ;* RETURN-NORMAL = NONE
  294. ;* RETURN-ERROR  = NONE
  295. ;*
  296. ;* PSEUDOCODE
  297. ;*
  298. ;*     Bgnsub ReadFont
  299. ;*       Call DOSREALLOCSEG to expand BVSCPnn to hold the this font
  300. ;*       Call RandomRead to read the entire font into BVSCPnn
  301. ;*     Endsub
  302. ;*
  303. ;****************************************************************************/
  304.  
  305. ReadFont PROC   NEAR
  306.         public  ReadFont
  307.  
  308.         les     di,[bp+12]                        ;Ptr to Font Buffer
  309.         add     di,ds:TotalSize                   ;Get the new segment address
  310.         mov     cx,word ptr ds:Buffer+fh_datalen  ;Get font length
  311.         sub     dx,dx
  312.         add     si,word ptr ds:Buffer+fh_dataoffset
  313.         adc     dx,bx                             ;32-bit Offset of font in file
  314.         Call    RandomRead                        ;Read the font data
  315.  
  316.         .if     <zero ax>
  317.             mov     si,ds:NumFonts
  318.             add     si,si
  319.             add     si,offset FontSizes
  320.             mov     ax,word ptr ds:Buffer+fh_cellcols
  321.             mov     [si],ax                       ;Save size of this font
  322.  
  323.             sub     al,al                         ;;;
  324.             mov     cx,ax                         ;Force maximum font size ;;;
  325.  
  326.             inc     ds:NumFonts                   ;Update count of fonts
  327.             add     ds:TotalSize,cx               ;Set next font offset
  328.         .endif
  329.  
  330.         RET
  331. ReadFont ENDP
  332.  
  333. ;/****************************************************************************
  334. ;*
  335. ;* FUNCTION NAME = RandomRead:
  336. ;*
  337. ;* DESCRIPTION   = 
  338. ;*
  339. ;* INPUT         = DX:SI = New file offset
  340. ;*                 ES:DI = Ptr to buffer
  341. ;*                 CX    = Length of buffer
  342. ;*
  343. ;* OUTPUT        = NONE
  344. ;*
  345. ;* RETURN-NORMAL = NONE
  346. ;* RETURN-ERROR  = NONE
  347. ;*
  348. ;* PSEUDOCODE
  349. ;*
  350. ;*     Bgnsub RandomRead
  351. ;*       Call DOSCHGFILEPTR to prepare for the random read
  352. ;*       Call DOSREAD to read the data
  353. ;*     Endsub
  354. ;*
  355. ;****************************************************************************/
  356.  
  357. RandomRead PROC NEAR
  358.         public  RandomRead
  359.  
  360.         push    ds:Handle                         ;File handle
  361.         push    dx
  362.         push    si                                ;Distance
  363.         push    bx                                ;Type = Abs from Start
  364.         push    ds
  365.         push    offset Scratch                    ;New ptr return area
  366.         Call    DOSCHGFILEPTR                     ;Set new file read location
  367.  
  368.         push    ds:Handle                         ;File handle
  369.         push    es
  370.         push    di                                ;Buffer ptr
  371.         push    cx                                ;Read Length
  372.         push    ds
  373.         push    offset Scratch                    ;Return Length
  374.         Call    DOSREAD                           ;Read from current location
  375.  
  376.         ret
  377. RandomRead ENDP
  378.  
  379. R2CSEG  ENDS
  380.         END
  381.