home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / VDH / IDHMAIN.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  39KB  |  997 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   IDHMAIN.Asm -- Install Device Handler
  14. ;/*****************************************************************************
  15. ;*
  16. ;* SOURCE FILE NAME = IDHMAIN.ASM
  17. ;*
  18. ;* DESCRIPTIVE NAME = BVS Device Handler for Installation
  19. ;*
  20. ;*
  21. ;* VERSION      V2.0
  22. ;*
  23. ;* DATE
  24. ;*
  25. ;* DESCRIPTION  This module is the control point for the Generic Device
  26. ;*              handler used by Installation and Initialization.
  27. ;*
  28. ;* FUNCTIONS    DEVENABLE
  29. ;*              InitEnv
  30. ;*              SaveRestEnv
  31. ;*              GetConfig
  32. ;*              RegSave
  33. ;*              RegRest
  34. ;*              _PhysToUVirt
  35. ;*              _FreePhysToUVirt
  36. ;*              GetScrHandle
  37. ;*              ExamineConfig
  38. ;*
  39. ;* NOTES        NONE
  40. ;*
  41. ;* STRUCTURES   NONE
  42. ;*
  43. ;* EXTERNAL REFERENCES
  44. ;*
  45. ;*              NONE
  46. ;*
  47. ;* EXTERNAL FUNCTIONS
  48. ;*
  49. ;*              NONE
  50. ;*
  51. ;* CHANGE ACTIVIY =
  52. ;*   DATE      FLAG       APAR    CHANGE DESCRIPTION
  53. ;*   --------  ---------- -----   --------------------------------------
  54. ;*   mm/dd/yy  @Vr.mpppxx xxxxx   xxxxxxx
  55. ;*   01/11/89  @T10       P3464   TPL, Use NULL input parameter for
  56. ;*                                free PVB IOCTL,
  57. ;*   01/16/89  @@A        P2986   STJ, Add enhanced GetConfig support
  58. ;*   03/07/89  @@S3       P3532   STJ, Use the new SCREEN IOCTL,
  59. ;*   03/13/89             D184    STJ, Identify additional displays for 8514/A
  60. ;*   03/25/89  @P1        D203    TPL, DCR 203 changes
  61. ;*   04/10/89             D198    STJ, Install BvsPrtSc and BvsWrtTTY as
  62. ;*                                default VDH routines
  63. ;*   05/09/89  @BB7       B702184 WKB, Restructure config data structure,
  64. ;*   05/22/89  @T30       D511    TPL, DCR 511 changes
  65. ;*   05/19/89  @T51       432.10  TPL, 2.0 UNIQUE, Removal of 3xbox code for 2.0
  66. ;*   07/14/89  @S17       B704811 STJ, Change PhystoUVirt from FAR to NEAR
  67. ;*   07/15/89  @T39       B784056 TPL, Remove hardware dependencies in VDHINIT
  68. ;*   07/24/89  @S20       B705116 STJ, 8514/A configs fixed,
  69. ;*   08/18/89  @S25       B706860 STJ, Use 1.0 length as default for GetXXXX
  70. ;*                                calls,
  71. ;*   11/30/89             D811    MS,  2.0 UNIQUE - DCR 811
  72. ;*   01/24/90  @T52       D704    TPL, 2.0 UNIQUE - DCR 704 work
  73. ;*   07/23/90  @T71       D1293   TPL, DCR 1293 - Support P70 device on Family 1 machines
  74. ;*   07/23/90  @T72       D1295   TPL, DCR 1295 - Support recognition of XGA device
  75. ;*   09/20/90             B716255 TPL, Return XGA present for Kauai-HS
  76. ;*   07/18/91             B724243 WKB, Correctly identify the Compaq plasma
  77. ;*                                display (CGA)
  78. ;*   04/09/93  @RAD         60272 YEE, Add global variable for machine type
  79. ;****************************************************************************/
  80.  
  81.         PUBLIC  __acrtused              ;@T39
  82. __acrtused equ  1                       ;C compiler work around         ;@T39
  83.  
  84.         INCLUDE idhequ.inc              ;Install Device Handler Equates
  85.         INCLUDE bvsparms.inc            ;BVS Parameter Equates
  86.         INCLUDE error2.inc              ;CP/DOS Error Codes
  87.         INCLUDE infoseg.inc             ;DOS Info Seg
  88.         .xlist
  89.         INCLUDE struc.inc               ;Structured Macros
  90.         .list
  91.  
  92.         extrn   BUFFERUPDATE:FAR        ;Text Buffer Update
  93.         extrn   GetCursorInfo:FAR       ;Get Cursor Info
  94.         extrn   SetCursorInfo:FAR       ;Set Cursor Info
  95.         extrn   GetMode:FAR             ;Get Mode
  96.         extrn   SetMode:FAR             ;Set Mode
  97.         extrn   GetCurPos:FAR           ;Get Physical Cursor Position
  98.         extrn   SetCurPos:FAR           ;Set Physical Cursor Position
  99.         extrn   GetVarInfo:FAR          ;Get Variable Information ;@@A
  100.         extrn   SetVarInfo:FAR          ;Set Variable Information ;@@A
  101.         extrn   SetCurType:FAR          ;Set Physical Cursor Shape ;@@A
  102.         extrn   GetDBCSInfo:FAR         ;Get DBCS Display Info          ;@P1
  103.         extrn   GetLVBInfo:FAR          ;Get LVB size Info              ;@P1
  104.         extrn   _getVideoType:NEAR      ;Get video adapter type         ;@T39
  105.         extrn   GetCodePage:NEAR        ;Get Prepare Code Page ;@@A
  106.         extrn   GetState:FAR            ;Get video date                 ;D811
  107.         extrn   SetState:FAR            ;Set video state                ;D811
  108.  
  109.         extrn   DOSOPEN:FAR             ;Open a file or device
  110.         extrn   DOSDEVIOCTL:FAR         ;Send a request to a device
  111.         extrn   BVHINSTANCE:WORD        ;BVH instance data              ;@T52
  112.  
  113. IDHGSEG SEGMENT WORD PUBLIC 'DATA'      ;Global data segment for IDH    ;@T52
  114.  
  115.         idhglobal <>                    ;Global data segment for IDH
  116.  
  117. _VideoHardware VHardware <>             ; video hardware configuration  ;@T39
  118.         public  _VideoHardware          ;@T39
  119.  
  120. ProtoEnv idhenvironment <>              ;Prototype environment block
  121.  
  122. Config  configdata <,cf_a_cga,cf_d_color,1000h,,,,size idhenvironment,0FA0h,0FA0h,-8+size configdata,-4+size configdata,1,cf_af_cga,1,cf_df_color> ;@@A @BB7
  123.         public  Config                  ;@@A
  124.  
  125. _hScreenDD dd   BVHINSTANCE             ;Screen DD Handle               ;@T52
  126.         public  _hScreenDD                                              ;@T52
  127. _pDMQSdata dd   0                       ;pointer to DMQS data           ;@ISO
  128.         public  _pDMQSdata                                              ;@ISO
  129. _machinetype dw   0                     ;family type indicator          ;@RAD
  130.         public  _machinetype                                            ;@RAD
  131. Scratch dw      0                       ;Scratch Area                   ;@T52
  132.  
  133.  
  134. ;/*
  135. ;** Table of addresses of IDH functions
  136. ;*/
  137.  
  138.  
  139.         public  FnTable
  140. FnTable dd      BufferUpdate            ;Text Buffer Update
  141.         dd      InitEnv                 ;Initialize Environment
  142.         dd      SaveRestEnv             ;Save Environment
  143.         dd      SaveRestEnv             ;Restore Environment
  144.         dd      GetConfig               ;Return Config Info
  145.         dd      GetDBCSInfo             ;Get DBCS Display Info          ;@P1
  146.         dd      0                       ;Get Color Lookup Table         ;D198
  147.         dd      0                       ;Set Color Lookup Table         ;D198
  148.         dd      GetCursorInfo           ;Get Cursor Info
  149.         dd      SetCursorInfo           ;Set Cursor Info
  150.         dd      0                       ;Get Font                       ;D198
  151.         dd      0                       ;Set Font                       ;D198
  152.         dd      GetMode                 ;Get Mode
  153.         dd      SetMode                 ;Set Mode
  154.         dd      0                       ;Get Palette Registers          ;D198
  155.         dd      0                       ;Set Palette Registers          ;D198
  156.         dd      0                       ;Get Phys Buf                   ;D198
  157.         dd      0                       ;Free Phys Buf                  ;D198
  158.         dd      GetVarInfo              ;Get Variable Info              ;@@A
  159.         dd      SetVarInfo              ;Set Variable Info              ;@@A
  160.         dd      0                       ;Extended VIO Call              ;D198
  161.         dd      0                       ;Print Screen                   ;D198
  162.         dd      0                       ;Write TTY                      ;D198
  163.         dd      GetLVBInfo              ;Get LVB Info Call              ;@P1
  164.         dd      GetState                ;get video state                ;D811
  165.         dd      SetState                ;set video state                ;D811
  166.  
  167. IDHGSEG ENDS
  168.  
  169. R2CSEG  SEGMENT BYTE PUBLIC 'CODE'
  170.         ASSUME  CS:R2CSEG
  171.  
  172. ;/****************************************************************************
  173. ;*
  174. ;*  SUBROUTINE NAME: DevEnable
  175. ;*
  176. ;*  DESCRIPTIVE NAME: Initialize call vector table
  177. ;*
  178. ;*  FUNCTION: DevEnable is called via the Presentation Manager DDI
  179. ;*            interface.  The entry points of all VDH routines are
  180. ;*            appropriately entered into the call vector table.
  181. ;*            In addition, display adapter configuration is verified.
  182. ;*
  183. ;*  ENTRY POINT: DevEnable
  184. ;*    LINKAGE:   CALL FAR
  185. ;*
  186. ;*  INPUT: (Passed on stack)
  187. ;*             FAR * Parameter2  ( far pointer to parameter 2 packet )
  188. ;*                      FAR *Flags
  189. ;*                      FAR *CallVectorTable (BVS's call table)
  190. ;*             FAR * Parameter1  ( far pointer to parameter 1 packet )
  191. ;*                      ULONG EngineVersion ( Graphics engine ver. )
  192. ;*                      ULONG TableSize ( Length of call table )
  193. ;*             ULONG Subfunction ( Enable subfunction )
  194. ;*         (Referenced)
  195. ;*             VDHEntryPoint[] (global data - table of entry points )
  196. ;*             HugeShift (global data - huge shift value)
  197. ;*             hScreenDD (global data - screen device driver handle)
  198. ;*
  199. ;*  EXIT-NORMAL: AX = 0
  200. ;*               Entries in VDHEntryPoint table are copied to
  201. ;*                  CallVectorTable
  202. ;*
  203. ;*  EXIT-ERROR: AX = ERROR_VIO_BAD_ADAPTER or
  204. ;*                   DosGetHugeShift error or
  205. ;*                   DosOpen error
  206. ;*
  207. ;*  EFFECTS: Huge shift value is saved in HugeShift
  208. ;*           Screen device driver handle is saved in hScreenDD
  209. ;*
  210. ;*  INTERNAL REFERENCES:
  211. ;*    ROUTINES: NONE
  212. ;*
  213. ;*  EXTERNAL REFERENCES:
  214. ;*    ROUTINES: RegSave, RegRest
  215. ;*
  216. ;****************************************************************************/
  217.  
  218. ;/*
  219. ;**  ASSUMPTION: DevEnable is called every time a VDH is loaded
  220. ;*/
  221.  
  222. DEVENABLE PROC  FAR
  223.         public  DEVENABLE
  224.         Call    RegSave
  225.  
  226.         mov     ax,-1                   ;PMERR_DEV_FUNC_NOT_INSTALLED ;Preset error
  227.         .if     <<word ptr [bp].stk_function> eq 1>
  228.             mov     ax,ERROR_VIO_INTERNAL_RESOURCE
  229.             .if     <[si+4] ae fn_NextAvail> ;Table large enough for this VDH
  230.  
  231.                 push    IDHGSEG
  232.                 pop     ds
  233.                 .if     <[bx].idh_ioport eq bx> ;This is first call by System
  234.  
  235.                     mov     si,offset FnTable ;DS:SI = local table
  236.                     les     di,dword ptr es:[di+4] ;Get Call Table Addr
  237.                     add     di,4*fn_BufferUpdate ;ES:DI = target table
  238.                     mov     cx,fn_NextAvail-fn_BufferUpdate ;# of entries ;D198
  239.                     .repeat             ;D198
  240.                         .if     <<word ptr [si+2]> ne bx> ;Supported ;D198
  241.                             movsw       ;D198
  242.                             movsw       ;Copy addr to table ;D198
  243.                         .else           ;D198
  244.                             add     si,4 ;D198
  245.                             add     di,4 ;Skip this entry ;D198
  246.                         .endif          ;D198
  247.                     .loop               ;D198
  248.  
  249.                     Call    ExamineConfig ;Get video configuration ;@@A
  250.                     mov     si,offset ProtoEnv ;@@A
  251.                     mov     ax,[bx].idh_fontsize ;Get size of character box ;@@A
  252.                     dec     ax          ;@@A
  253.                     mov     [si].env_endline,ax ;@@A
  254.                     dec     ax          ;@@A
  255.                     mov     [si].env_startline,ax ;Set default cursor shape ;@@A
  256.  
  257.                 .endif
  258.                 sub     ax,ax
  259.             .endif
  260.         .endif
  261.  
  262.         Call    RegRest
  263.         ret     12
  264. DEVENABLE ENDP
  265.  
  266. ;/****************************************************************************
  267. ;*
  268. ;*  SUBROUTINE NAME: InitEnv
  269. ;*
  270. ;*  DESCRIPTIVE NAME: Initialize environment
  271. ;*
  272. ;*  FUNCTION: InitEnv is called by BVS to initialize the video
  273. ;*            environment during the creation of a new session.  This
  274. ;*            includes initializing the adapter hardware and/or the
  275. ;*            environment buffer.
  276. ;*
  277. ;*  ENTRY POINT: InitEnv
  278. ;*    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 257 )
  279. ;*
  280. ;*  INPUT: (Passed on stack)
  281. ;*             FAR *Environment ( Environment buffer for the session )
  282. ;*             FAR *ParmBlock
  283. ;*                     USHORT Length = length of this packet
  284. ;*                     USHORT Flags  = 0 - Environment buffer only
  285. ;*                                     1 - Hardware also
  286. ;*             ULONG Function ( Call vector table entry = 257 )
  287. ;*         (Referenced)
  288. ;*             Modes[] (global data - table of supported video modes )
  289. ;*
  290. ;*  EXIT-NORMAL: AX = 0
  291. ;*               Environment buffer is initialized
  292. ;*
  293. ;*  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  294. ;*
  295. ;*  EFFECTS: If requested, display adapter hardware is initialized to
  296. ;*           highest resolution mode supported.
  297. ;*
  298. ;*  INTERNAL REFERENCES:
  299. ;*    ROUTINES: NONE
  300. ;*
  301. ;*  EXTERNAL REFERENCES:
  302. ;*    ROUTINES: NONE
  303. ;*
  304. ;****************************************************************************/
  305.  
  306. InitEnv PROC    FAR
  307.         public  InitEnv
  308.         Call    RegSave
  309.  
  310.         push    IDHGSEG
  311.         pop     ds
  312.         mov     si,offset ProtoEnv
  313.         mov     cx,size idhenvironment
  314.         rep     movsb                   ;Copy prototype enviroment
  315.         sub     ax,ax
  316.  
  317.         Call    RegRest
  318.         ret     12
  319. InitEnv ENDP
  320.  
  321. ;/****************************************************************************
  322. ;*
  323. ;*  SUBROUTINE NAME: SaveRestEnv
  324. ;*
  325. ;*  DESCRIPTIVE NAME: Save/Restore Environment
  326. ;*
  327. ;*  FUNCTION: SaveEnv is called by BVS prior to a screen switch
  328. ;*            in order to preserve the display adapter hardware state
  329. ;*            and/or the full or partial display buffer.
  330. ;*
  331. ;*  ENTRY POINT: SaveEnv
  332. ;*    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 258 )
  333. ;*
  334. ;*  FUNCTION: RestoreEnv is called by BVS following a screen switch
  335. ;*            in order to restore the display adapter hardware state
  336. ;*            and/or the full or partial display buffer.
  337. ;*
  338. ;*  ENTRY POINT: RestoreEnv
  339. ;*    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 259 )
  340. ;*
  341. ;*  INPUT: (Passed on stack)
  342. ;*             FAR *Environment ( Environment buffer for the session )
  343. ;*             FAR *ParmBlock
  344. ;*                     USHORT Length = length of this packet
  345. ;*                     USHORT Flags  = 2 - Hardware state
  346. ;*                                     4 - Full display buffer
  347. ;*                                     8 - Partial display buffer
  348. ;*                                    10 - 3xBox being saved
  349. ;*                     USHORT PVBHugeSEL = 1st huge selector for PVB
  350. ;*             ULONG Function ( Call vector table entry = 258 )
  351. ;*
  352. ;*  EXIT-NORMAL: AX = 0
  353. ;*               Hardware state and/or display buffer is saved in
  354. ;*                 environment buffer
  355. ;*
  356. ;*  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  357. ;*
  358. ;*  EFFECTS: No special processing is done for the 3xBox
  359. ;*
  360. ;*  INTERNAL REFERENCES:
  361. ;*    ROUTINES: NONE
  362. ;*
  363. ;*  EXTERNAL REFERENCES:
  364. ;*    ROUTINES: RegSave, RegRest, SetCurPos
  365. ;*
  366. ;****************************************************************************/
  367.  
  368. SaveRestEnv PROC FAR
  369.         public  SaveRestEnv
  370.         Call    RegSave
  371.  
  372.         mov     ax,fn_BufferUpdate
  373.         xchg    word ptr [bp].stk_function,ax ;Get old/Set new function
  374.  
  375.         .if     <ax eq fn_SaveEnv>
  376.  
  377.             mov     cx,sx_ReadCellStr   ;Set the subroutine index
  378.  
  379.         .else
  380.  
  381.             Call    SetCurPos           ;Set cursor location from Environment
  382.             Call    SetCurType          ;Set cursor shape from Environment ;@@A
  383.             mov     cx,sx_WriteCellStr  ;Set the subroutine index
  384.  
  385.         .endif
  386.  
  387.         mov     ax,[si].vp_sr_lvbsel    ;Get the LVB selector
  388.  
  389.         mov     [si].vp_parmlength,26   ;Set parameter list length
  390.         mov     [si].vp_flags,vp_f_physical
  391.         mov     [si].vp_index,cx        ;Set the subroutine index
  392.  
  393.         mov     [si].vp_lvbsel,ax       ;Set the LVB address            ;@P1
  394.         mov     [si].vp_offset,bx
  395.         mov     [si].vp_selector,ax     ;Set the string address
  396.  
  397.         mov     [si].vp_startrow,bx
  398.         mov     [si].vp_startcol,bx     ;Set the row and column
  399.  
  400.         mov     ax,word ptr es:[di].env_bufsize
  401.         mov     [si].vp_repeatlength,ax ;Setup the length
  402.  
  403.         Call    RegRest
  404.         jmp     BufferUpdate            ;Continue with Buffer Save/Restore
  405. SaveRestEnv ENDP
  406.  
  407. ;/****************************************************************************
  408. ;*
  409. ;*  SUBROUTINE NAME: GetConfig
  410. ;*
  411. ;*  DESCRIPTIVE NAME: Return video adapter configuration information
  412. ;*
  413. ;*  FUNCTION: GetConfig is called by BVS to identify the current
  414. ;*            display adapter.
  415. ;*
  416. ;*  ENTRY POINT: RetConfigInfo
  417. ;*    LINKAGE:   CALL FAR ( via BVS-DDI call vector table entry 260 )
  418. ;*
  419. ;*  INPUT: (Passed on stack)
  420. ;*             FAR *Environment ( Environment buffer for the session )
  421. ;*             FAR *ParmBlock
  422. ;*                     USHORT Length = length of this packet
  423. ;*                     USHORT Flags  = 0 ( reserved )
  424. ;*                     FAR *ConfigData = VioGetConfig structure
  425. ;*             ULONG Function ( Call vector table entry = 260 )
  426. ;*         (Referenced)
  427. ;*             MemorySize (global data - amount of video memory)
  428. ;*
  429. ;*  EXIT-NORMAL: AX = 0
  430. ;*               Configuration data is returned to caller
  431. ;*
  432. ;*  EXIT-ERROR: AX = ERROR_VIO_INVALID_PARMS
  433. ;*
  434. ;*  EFFECTS: NONE
  435. ;*
  436. ;*  INTERNAL REFERENCES:
  437. ;*    ROUTINES: NONE
  438. ;*
  439. ;*  EXTERNAL REFERENCES:
  440. ;*    ROUTINES: NONE
  441. ;*
  442. ;****************************************************************************/
  443.  
  444. GetConfig PROC  FAR
  445.         public  GetConfig
  446.         Call    RegSave
  447.  
  448.         mov     ax,ERROR_VIO_INVALID_LENGTH
  449.         .if     <[si].vp_parmlength eq 8> and
  450.         les     di,dword ptr [si].vp_offset ;Get address of config data
  451.         push    IDHGSEG
  452.         pop     ds
  453.  
  454.         mov     si,offset Config        ;Get offset of config data
  455.  
  456.         ; If _VideoHardware.display previously initialized in   ;B724243
  457.         ; another routine (such as DetectOEM) then reflect that ;B724243
  458.         ; update in the config data.                            ;B724243
  459.  
  460.         assume  ds:IDHGSEG                                      ;B724243
  461.         mov     cx, WORD PTR _VideoHardware.display             ;B724243
  462.         .if     <cx ne 0>                                       ;B724243
  463.             mov     WORD PTR ds:Config+cf_display, cx           ;B724243
  464.         .endif                                                  ;B724243
  465.  
  466.         mov     cx,es:[di].cf_length    ;Get length of config data
  467.  
  468.         .if     <cx a 1>
  469.  
  470.             mov     ax,cx
  471.             .if     <al a <size configdata>> ;@S25
  472.                 mov     al,cf_confignum ;@S25
  473.             .endif                      ;@S25
  474.  
  475.             push    di
  476.             sub     al,size cf_length
  477.             .if     <ns>
  478.                 movsw
  479.             .endif
  480.  
  481.             sub     al,size cf_adapter
  482.             .if     <ns>
  483.                 movsw
  484.             .endif
  485.  
  486.             sub     al,size cf_display
  487.             .if     <ns>
  488.                 movsw
  489.             .endif
  490.  
  491.             sub     al,size cf_memory
  492.             .if     <ns>
  493.                 movsw
  494.                 movsw
  495.             .endif
  496.  
  497.             sub     al,size cf_confignum
  498.             .if     <ns>
  499.                 movsw
  500.             .endif
  501.  
  502.             sub     al,size cf_version
  503.             .if     <ns>
  504.                 movsw
  505.             .endif
  506.  
  507.             sub     al,size cf_flags
  508.             .if     <ns>
  509.                 movsw
  510.             .endif
  511.  
  512.             sub     al,size cf_envsize
  513.             .if     <ns>
  514.                 movsw
  515.                 movsw
  516.             .endif
  517.  
  518.             sub     al,size cf_fullsize
  519.             .if     <ns>
  520.                 movsw
  521.                 movsw
  522.             .endif
  523.  
  524.             sub     al,size cf_partsize
  525.             .if     <ns>
  526.                 movsw
  527.                 movsw
  528.             .endif
  529.  
  530.             sub     al,size cf_adapteroff
  531.             .if     <ns>
  532.                 movsw
  533.             .endif
  534.  
  535.             sub     al,size cf_displayoff
  536.             .if     <ns>
  537.                 movsw
  538.             .endif
  539.  
  540.             sub     al,size cf_emadapters
  541.             .if     <ns>
  542.                 movsw
  543.             .endif
  544.  
  545.             sub     al,size cf_emdisplays
  546.             .if     <ns>
  547.                 movsw
  548.             .endif
  549.  
  550.             mov     ax,di
  551.             pop     di
  552.             sub     ax,di
  553.             .if     <al a 2>            ;More than just a length request
  554.                 stosw                   ;Update length in Mode data
  555.             .endif
  556.  
  557.             sub     ax,ax               ;Set good return code
  558.         .endif
  559.  
  560.         Call    RegRest
  561.         ret     12
  562. GetConfig ENDP
  563.  
  564. ;/****************************************************************************
  565. ;*
  566. ;* FUNCTION NAME = RegSave/RegRest
  567. ;*
  568. ;* DESCRIPTION   = Save and Restore all registers and flags for VDH routines.
  569. ;*                 RegSave also sets BX=0, DS:SI=ParmBlock, and ES:DI=EnvBlock
  570. ;*
  571. ;* INPUT         = NONE
  572. ;* OUTPUT        = NONE
  573. ;*
  574. ;* RETURN-NORMAL = NONE
  575. ;* RETURN-ERROR  = NONE
  576. ;*
  577. ;****************************************************************************/
  578.  
  579. RegSave PROC    NEAR                    ;Routine to save regs
  580.         public  RegSave
  581.  
  582.         pop     ax                      ;Get return address
  583.         pushf
  584.         pusha
  585.         push    ds
  586.         push    es                      ;Save all registers and flags
  587.         cld
  588.         mov     bp,sp
  589.         push    ax                      ;Restore return address
  590.  
  591.         sub     bx,bx                   ;Get zero reg for code optimization
  592.         lds     si,[bp].stk_parmblock   ;DS:SI = Parameter Block
  593.         les     di,[bp].stk_envblock    ;ES:DI = Environment Block
  594.  
  595.         ret
  596. RegSave ENDP
  597.  
  598. RegRest PROC    NEAR                    ;Routine to restore regs
  599.         public  RegRest
  600.  
  601.         mov     [bp].stk_regax,ax       ;Save return code
  602.         pop     ax
  603.         xchg    [bp].stk_flags,ax       ;Swap return address w/flags
  604.         push    ax
  605.  
  606.         popf
  607.         pop     es
  608.         pop     ds
  609.         popa                            ;Restore all registers and flags
  610.  
  611.         ret
  612. RegRest ENDP
  613.  
  614. ;/****************************************************************************
  615. ;*
  616. ;*  SUBROUTINE NAME: PhysToUVirt
  617. ;*
  618. ;*  DESCRIPTIVE NAME: Allocate an LDT sel:off to physical memory
  619. ;*
  620. ;*  FUNCTION: PhysToUVirt is called by routines who need access to
  621. ;*            either the physical display buffer, or the ROM font.
  622. ;*            This routine calls the screen device driver (SCREEN$)
  623. ;*            via DosDevIOCtl who, in turn, issues a
  624. ;*            DevHlp_PhysToUVirt call.
  625. ;*
  626. ;*  ENTRY POINT: PhysToUVirt
  627. ;*    LINKAGE:   CALL FAR
  628. ;*
  629. ;*  INPUT: (Passed on stack)
  630. ;*             FAR *PhysicalAddress ( Physical address )
  631. ;*             FAR *LDTSelector     ( Place to return LDT sel:off )
  632. ;*             USHORT Length        ( Size of physical memory area )
  633. ;*
  634. ;*  EXIT-NORMAL: AX = 0
  635. ;*               LDT sel:off is returned to caller
  636. ;*
  637. ;*  EXIT-ERROR: AX = DosDevIOCtl error
  638. ;*
  639. ;*  EFFECTS: NONE
  640. ;*
  641. ;*  INTERNAL REFERENCES:
  642. ;*    ROUTINES: NONE
  643. ;*
  644. ;*  EXTERNAL REFERENCES:
  645. ;*    ROUTINES: DosDevIOCtl
  646. ;*
  647. ;****************************************************************************/
  648.  
  649. _PhysToUVirt PROC NEAR                  ;@S17
  650.         public  _PhysToUVirt
  651.  
  652.         pushf
  653.         pusha
  654.         push    ds
  655.         push    es                      ;Save all registers and flags
  656.         cld
  657.         mov     bp,sp                   ;Equivalent to RegSave
  658.  
  659.         Call    GetScrHandle            ;Get current screen dd handle
  660.         .if     <zero ax>
  661.  
  662.             mov     ax,word ptr [bp].stk_envblock-2 ;Length of PVB ;@S17
  663.             les     di,[bp].stk_parmblock-2 ;Where to put selector ;@S17
  664.             mov     word ptr [bp].stk_parmblock-2,ax ;Overlay the stack parms ;@S17
  665.  
  666.             push    es
  667.             push    di                  ;Push selector/offset of PVB area
  668.             push    ss
  669.             lea     ax,[bp].stk_function-2 ;@S17
  670.             push    ax                  ;Push ptr to phys sel/off and length
  671.             push    75h                 ;Push function = Allocate       ;@T30
  672.             push    03h                 ;Push category = Video
  673.             push    dx                  ;Push device handle
  674.             Call    DOSDEVIOCTL         ;Get selector/offset of PVB
  675.  
  676.         .endif
  677.         Call    RegRest
  678.         ret
  679. _PhysToUVirt ENDP
  680.  
  681. ;/****************************************************************************
  682. ;*
  683. ;*  SUBROUTINE NAME: FreePhysToUVirt
  684. ;*
  685. ;*  DESCRIPTIVE NAME: Deallocate an LDT selector to physical memory
  686. ;*
  687. ;*  FUNCTION: FreePhysToUVirt is called by routines who are done
  688. ;*            accessing the memory allocated by PhysToUVirt.  This is
  689. ;*            done by calling the screen device driver (SCREEN$) via
  690. ;*            DosDevIOCtl who, in turn, issues a DevHlp_PhysToUVirt.
  691. ;*
  692. ;*  ENTRY POINT: FreePhysToUVirt
  693. ;*    LINKAGE:   CALL FAR
  694. ;*
  695. ;*  INPUT: (Passed on stack)
  696. ;*             USHORT LDTSelector  ( LDT selector to be deallocated )
  697. ;*
  698. ;*  EXIT-NORMAL: LDT selector is deallocated
  699. ;*
  700. ;*  EFFECTS: NONE
  701. ;*
  702. ;*  INTERNAL REFERENCES:
  703. ;*    ROUTINES: NONE
  704. ;*
  705. ;*  EXTERNAL REFERENCES:
  706. ;*    ROUTINES: DosDevIOCtl
  707. ;*
  708. ;****************************************************************************/
  709.  
  710. _FreePhysToUVirt PROC NEAR
  711.         public  _FreePhysToUVirt
  712.  
  713.         pushf
  714.         pusha
  715.         push    ds
  716.         push    es                      ;Save all registers and flags
  717.         cld
  718.         mov     bp,sp                   ;Equivalent to RegSave
  719.  
  720.         Call    GetScrHandle            ;Get current screen dd handle
  721.         .if     <zero ax>
  722.  
  723.             push    ax                  ;                               @T10
  724.             push    ax                  ;Push dummy ptr to PVB ptr      @T10
  725.             push    ss
  726.             lea     di,[bp].stk_function-2 ;@S17
  727.             push    di                  ;Push ptr to sel. to deallocate ;@T39
  728.             push    71h                 ;Push function = Deallocate
  729.             push    03h                 ;Push category = Video
  730.             push    dx                  ;Push device handle
  731.             Call    DOSDEVIOCTL         ;Delete selector/offset of PVB
  732.             .if     <zero ax>           ;@T39
  733.                 mov     dx,word ptr ss:[di] ;Get deallocated sel.   ;@T39
  734.                 .if     <[bp] eq dx>    ;ES selector saved?     ;@T39
  735.                     mov     [bp],ax     ;Clear it               ;@T39
  736.                 .endif                  ;                       ;@T39
  737.                 .if     <[bp+2] eq dx>  ;DS selector saved?     ;@T39
  738.                     mov     [bp+2],ax   ;Clear it               ;@T39
  739.                 .endif                  ;                       ;@T39
  740.             .endif                      ;@T39
  741.         .endif
  742.         Call    RegRest
  743.         ret
  744. _FreePhysToUVirt ENDP
  745.  
  746. ;/****************************************************************************
  747. ;*
  748. ;* FUNCTION NAME = GetScrHandle
  749. ;*
  750. ;* DESCRIPTION   = Get Screen Device Driver handle in DX
  751. ;*
  752. ;* INPUT         = NONE
  753. ;* OUTPUT        = NONE
  754. ;*
  755. ;* RETURN-NORMAL = NONE
  756. ;* RETURN-ERROR  = NONE
  757. ;*
  758. ;****************************************************************************/
  759.  
  760. GetScrHandle PROC NEAR
  761.         PUBLIC  GetScrHandle
  762.  
  763.         push    ds                                                      ;@T52
  764.         push    bx                                                      ;@T52
  765.         mov     ax,IDHGSEG                                              ;@T52
  766.         mov     es,ax
  767.         lds     bx,es:_hScreenDD                                        ;@T52
  768.         sub     ax,ax
  769.         mov     dx,ds:[bx]              ;@T39                           ;@T52
  770.         .if     <zero dx>
  771.             push    es                                                  ;@T52
  772.             push    idh_scr             ;Device name ASCIIZ string
  773.             push    ds                                                  ;@T52
  774.             push    bx                  ;Return for device handle  ;@T39,@T52
  775.             push    es
  776.             push    offset Scratch      ;Action Taken
  777.             push    dx
  778.             push    dx                  ;File Size
  779.             push    dx                  ;File Attribute
  780.             push    00001h              ;Open Flag
  781.             push    000C2h              ;Open Mode
  782.             push    dx
  783.             push    dx                  ;Reserved (0:0)
  784.             Call    DOSOPEN
  785.             mov     dx,ds:[bx]          ;@T39                           ;@T52
  786.         .endif
  787.         pop     bx                                                      ;@T52
  788.         pop     ds                                                      ;@T52
  789.  
  790.         ret
  791. GetScrHandle ENDP
  792.  
  793. ;/****************************************************************************
  794. ;*
  795. ;* FUNCTION NAME = ExamineConfig
  796. ;*
  797. ;* DESCRIPTION   = Identify the video configuration and set the config data.
  798. ;*
  799. ;* INPUT         = DS = IDHGSEG
  800. ;* OUTPUT        = ax, cx, di, si destroyed
  801. ;*
  802. ;* RETURN-NORMAL = NONE
  803. ;* RETURN-ERROR  = NONE
  804. ;*
  805. ;****************************************************************************/
  806.  
  807. ExamineConfig PROC NEAR                 ;@@A
  808.         public  ExamineConfig           ;@@A
  809.         assume  ds:IDHGSEG              ;@T39
  810.  
  811.         call    _getVideoType           ; get video configuration       ;@T39
  812.         mov     ax, _VideoHardware.fVideoType ;@T39
  813.  
  814.         sub     bx,bx                   ;@T39
  815.         mov     [bx].idh_ioport,3D4h    ;Preset the Color port
  816.         mov     di,offset ProtoEnv      ;Get offset of prototype env.   ;@T39
  817.         mov     si,offset Config        ;Get offset of config data      ;@T39
  818.  
  819. ;/*
  820. ;** use monochrome only if it's all that is available
  821. ;*/
  822.  
  823.         .if     <ax eq MPA_BIT> or      ; MPA Mono found?               ;@T39
  824.         .if     <ax eq EGM_BIT>         ; EGA Mono found?               ;@T39
  825.             mov     byte ptr [bx].idh_ioport,0B4h ;Use Mono port
  826.             mov     byte ptr [bx].idh_fontsize,14 ;14-pel font
  827.  
  828.             mov     word ptr [di].env_gcols,720
  829.             mov     word ptr [di].env_grows,350
  830.  
  831.             mov     [si].cf_adapter,cf_a_mpa ;Indicate Mono card ;@S20
  832.             mov     [si].cf_emadapters,cf_af_mpa ;Emulate Mono card ;@S20
  833.             mov     [si].cf_display,cf_d_mono ;Indicate Mono display
  834.             mov     word ptr [si].cf_memory,1000h ;Indicate Mono size
  835.             mov     [si].cf_emdisplays,cf_df_mono ;Emulate Mono display
  836.  
  837. ;/*
  838. ;** EGAs emulating MPAs use different values
  839. ;*/
  840.  
  841.             test    ax, EGM_BIT
  842.             .if     < nz >              ;EGA Mono found?
  843.                 mov     [si].cf_adapter,cf_a_ega
  844.                 mov     [si].cf_emadapters,cf_af_mpa+cf_af_ega
  845.             .endif
  846.         .endif
  847.  
  848.         test    ax, VGA_BITS
  849.         .if     < nz >                  ;VGA found?
  850.             mov     byte ptr [bx].idh_fontsize,16 ;16-pel font
  851.  
  852.             mov     [di].env_gcols,720
  853.             mov     [di].env_grows,400
  854.  
  855.             mov     [si].cf_adapter,cf_a_vga
  856.             mov     [si].cf_display,cf_d_vcolor ;@T39
  857.             test    ax, VGM_BIT         ;@T39
  858.             .if     <nz>                ;VGA with Mono display?         ;@T39
  859.                 mov     byte ptr [bx].idh_ioport,0B4h ;Use Mono port ;@S20
  860.                 mov     [si].cf_display,cf_d_vmono ;@T39
  861.             .endif                      ;@T39
  862.             mov     word ptr [si].cf_memory,bx
  863.             mov     word ptr [si].cf_memory+2,4 ;Always 256K of memory
  864.             mov     [si].cf_emadapters,cf_af_mpa+cf_af_cga+cf_af_ega+cf_af_vga
  865.             mov     [si].cf_emdisplays,cf_df_mono+cf_df_color+cf_df_ecolor+cf_df_vmono+cf_df_vcolor+cf_df_plasma
  866.  
  867.             test    ax, VGP_BIT
  868.             .if     <nz>                ;VGA with plaza display?
  869.                 test    ax, VGM_BIT     ;                               ;@T71
  870.                 .if     <nz>            ;P70 in Mono?                   ;@T71
  871.                     mov     byte ptr [bx].idh_ioport,0B4h ;Use Mono port ;@S20
  872.                 .endif                                                  ;@T71
  873.                 mov     [di].env_gcols,640
  874.                 mov     [si].cf_display,cf_d_plasma
  875.             .endif
  876.  
  877.             Call    GetCodePage
  878.  
  879.         .else   near
  880.  
  881.             test    ax, EGA_BIT OR EGC_BIT
  882.             .if     < nz > near         ;EGA found?
  883.  
  884.  
  885. ;/*
  886. ;** determine configuration of EGA in color modes,
  887. ;** mono modes determined by monochrome code above
  888. ;*/
  889.  
  890.  
  891.                 mov     [si].cf_adapter,cf_a_ega
  892.                 mov     [si].cf_emadapters,cf_af_cga+cf_af_ega
  893.  
  894.                 test    ax, EGA_BIT
  895.                 .if     < nz >          ;EGA with enhanced Color indicated
  896.                     mov     [di].env_grows,350
  897.                     mov     [si].cf_display,cf_d_ecolor
  898.                     mov     [si].cf_emdisplays,cf_df_color+cf_df_ecolor
  899.                     mov     byte ptr [bx].idh_fontsize,14 ;14-pel font
  900.                 .endif
  901.  
  902.                                         ; save memory size
  903.                 mov     cx, WORD PTR _VideoHardware.memory
  904.                 mov     word ptr [si].cf_memory,cx
  905.                 mov     cx, WORD PTR _VideoHardware.memory+2
  906.                 mov     word ptr [si].cf_memory+2,cx ;Set EGA memory
  907.  
  908.                 Call    GetCodePage
  909.             .endif
  910.         .endif
  911.  
  912. ;/*
  913. ;** if 8514 Adapter/Display present record information about it
  914. ;*/
  915.  
  916.         test    ax, A8514_BITS+XGA_BIT                                  ;B716255
  917.         .if     < nz > NEAR             ;8514 or XGA found?             ;@T72
  918.             test    ax, XGA_BIT         ;                               ;@T72
  919.             .if     < nz >              ;XGA found?                     ;@T72
  920.                 mov     [si].cf_adapter,cf_a_xga                        ;@T72
  921.                 add     [si].cf_emadapters,cf_af_xga                    ;@T72
  922.             .else                       ;8514a found                    ;@T72
  923.                 mov     [si].cf_adapter,cf_a_8514a
  924.                 add     [si].cf_emadapters,cf_af_8514a
  925.             .endif                                                      ;@T72
  926.  
  927.             test    ax, A8514M_BIT
  928.             .if     < nz >
  929.                 add     [si].cf_emdisplays,cf_df_8514+cf_df_8507_8604+cf_df_8515
  930.                 test    ax, XGA_BIT                                     ;@T72
  931.                 .if     < z >  OR       ;Only 8514a attached?           ;@T72
  932.                 test    ax, VGM_BIT                                     ;@T72
  933.                 .if     < nz >          ;Mono attached to VGA also?     ;@T72
  934.                     mov     byte ptr [bx].idh_ioport,0B4h ;Use Mono port ;@S20
  935.                     mov     [si].cf_display,cf_d_8507_8604 ;8514/A with 8507/8604
  936.                 .endif                                                  ;@T72
  937.             .endif
  938.  
  939.             test    ax, A8514A_BIT
  940.             .if     < nz >
  941.                 add     [si].cf_emdisplays,cf_df_8514+cf_df_8507_8604+cf_df_8515
  942.                 test    ax, XGA_BIT                                     ;@T72
  943.                 .if     < z >  OR                                       ;@T72
  944.                 test    ax, VGC_BIT                                     ;@T72
  945.                 .if     < nz >                                          ;@T72
  946.                     mov     [si].cf_display,cf_d_8514 ;8514/A with 8514
  947.                 .endif                                                  ;@T72
  948.             .endif
  949.  
  950.             test    ax, A8514_15_BIT
  951.             .if     < nz >
  952.                 add     [si].cf_emdisplays,cf_df_8514+cf_df_8507_8604+cf_df_8515
  953.                 test    ax, XGA_BIT                                     ;@T72
  954.                 .if     < z >  OR                                       ;@T72
  955.                 test    ax, VGC_BIT                                     ;@T72
  956.                 .if     < nz >                                          ;@T72
  957.                     mov     [si].cf_display,cf_d_8515 ;8514/A with 8515
  958.                 .endif                                                  ;@T72
  959.             .endif
  960.  
  961.             test    ax, A8514_03_BIT
  962.             .if     < nz >
  963.                 test    ax, XGA_BIT                                     ;@T72
  964.                 .if     < z >  OR       ;Only 8514a attached?           ;@T72
  965.                 test    ax, VGM_BIT                                     ;@T72
  966.                 .if     < nz >          ;Mono attached to VGA also?     ;@T72
  967.                     mov     byte ptr [bx].idh_ioport,0B4h ;Use Mono port ;@S20
  968.                     mov     [si].cf_display,cf_d_vmono ;8514/A with 8503
  969.                 .endif                                                  ;@T72
  970.             .endif
  971.  
  972.             test    ax, A8514C_BIT
  973.             .if     < nz >
  974.                 test    ax, XGA_BIT                                     ;@T72
  975.                 .if     < z >  OR                                       ;@T72
  976.                 test    ax, VGC_BIT                                     ;@T72
  977.                 .if     < nz >                                          ;@T72
  978.                     mov     [si].cf_display,cf_d_vcolor ;8514/A with 8512/3
  979.                 .endif                                                  ;@T72
  980.             .endif
  981.  
  982.             mov     cx, WORD PTR _VideoHardware.memory+2 ; save memory size
  983.             mov     word ptr [si].cf_memory+2,cx
  984.         .endif
  985.  
  986.         .if     <[bx].idh_ioport eq 3B4h> ;@S20
  987.             mov     word ptr [di].env_bufaddr,bx ;Use Mono buffer ;@S20
  988.             mov     word ptr [di].env_type,bx ;Use Mono mode ;@S20
  989.         .endif                          ;@S20
  990.  
  991.         ret
  992. ExamineConfig ENDP                      ;@@A
  993.  
  994. R2CSEG  ENDS
  995.         END
  996.  
  997.