home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / PEN / PENTKT / PENBASE / DISPLAY.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  13KB  |  380 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  4. ;
  5. ;    The following IBM OS/2 WARP source code is provided to you solely for
  6. ;    the purpose of assisting you in your development of OS/2 WARP device
  7. ;    drivers. You may use this code in accordance with the IBM License
  8. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  9. ;    Copyright statement may not be removed.;
  10. ;*****************************************************************************/
  11. ;      /*****************************************************************/
  12. ;      /*                                                               */
  13. ;      /*                                                               */
  14. ;      /*****************************************************************/
  15. ;      /******************* START OF SPECIFICATIONS *********************/
  16. ;      /*                                                               */
  17. ;      /*  SOURCE FILE NAME: DISPLAY.ASM                                */
  18. ;      /*                                                               */
  19. ;      /*  DESCRIPTIVE NAME: Display handler                            */
  20. ;      /*                                                               */
  21. ;      /*                                                               */
  22. ;      /*  STATUS:  Version 1.0                                         */
  23. ;      /*                                                               */
  24. ;      /*  NOTES: This module contains routines to manage the display   */
  25. ;      /*         backlight. The device dependent module is called      */
  26. ;      /*         to turn the backlight on and off. The device dependent*/
  27. ;      /*         module must call Dsp_Engine to report change of       */
  28. ;      /*         backlight status.                                     */
  29. ;      /*                                                               */
  30. ;      /*  ENTRY POINTS:                                                */
  31. ;      /*      See public statements                                    */
  32. ;      /*  EXTERNAL REFERENCES:                                         */
  33. ;      /*      See extrn statements                                     */
  34. ;      /*                                                               */
  35. ;      /******************* END  OF  SPECIFICATIONS *********************/
  36. .xlist
  37.   include pensegs.inc
  38.   include pen.inc
  39.   include penidc.inc
  40.   include penioctl.inc
  41.   include penei.inc
  42.   include struc.inc
  43. .list
  44.  
  45. .286p
  46.  
  47. ;------------------------------------------------------------------------------
  48. ; external data references
  49. ;------------------------------------------------------------------------------
  50.  
  51. extrn Device_Help  : dword
  52.  
  53. ;------------------------------------------------------------------------------
  54. ; external routines
  55. ;------------------------------------------------------------------------------
  56.  
  57. extrn Idc_ReportEvent : near
  58. extrn Idc_RequestCallback : near
  59. extrn Idc_CancelCallback : near
  60. extrn Idc_QueryActivity : near
  61. extrn Idc_SuppressStroke : near
  62. extrn Tim_Mill2Tick      : near
  63.  
  64. ;------------------------------------------------------------------------------
  65. ; local equates
  66. ;------------------------------------------------------------------------------
  67.  
  68. ON  equ 1
  69. OFF equ 0
  70.  
  71. ; The following set the frequency of checking the activity
  72. ; note: CNT1,CNT2,CNT3 must be less than 64 * Tim_MsecPerTick (31)
  73. ;       for math in SetInactPeriod to work
  74. LIMIT1 equ 60
  75. CNT1   equ 1      ; less than LIMIT1 seconds, check this many seconds
  76. LIMIT2 equ 300
  77. CNT2   equ 10     ; less than LIMIT2 seconds, check every this many seconds
  78. CNT3   equ 30     ; greater than LIMIT2 seconds, check every this many seconds
  79.  
  80. ;------------------------------------------------------------------------------
  81. ; local data declarations
  82. ;------------------------------------------------------------------------------
  83.  
  84. DSEG   segment
  85. displayDCB dw 0
  86. DSEG   ends
  87.  
  88. CSEG SEGMENT
  89.      ASSUME    CS:CGROUP, SS:nothing, ES:nothing, DS:DGROUP
  90.  
  91. ;---- ROUTINES TO SET DISPLAY STATE -------------------------------------------
  92. ;
  93. ;------------------------------------------------------------------------------
  94.  
  95. ;------------------------------------------------------------------------------
  96. ; Set the diplay state (turn it on or off)
  97. ;  al = command 1=turn on backlight 0=turn off backlight
  98. ;  bx = dcb
  99. ;------------------------------------------------------------------------------
  100. public Dsp_SDS
  101. Dsp_SDS proc
  102.   CALL_NZ_ERR [bx].dcb_@backlight     ; turn on/off the backlight
  103.   ret
  104. Dsp_SDS endp
  105.  
  106. ;---- ROUTINES TO MANAGE DISPLAY ENGINE ---------------------------------------
  107. ;
  108. ;------------------------------------------------------------------------------
  109. ;------------------------------------------------------------------------------
  110. ; Update display engine with backlight state info. Called by device dependent
  111. ; code to update display engine.
  112. ;  al = 1=backlight is on 0=backlight is off
  113. ;  bx = dcb
  114. ;------------------------------------------------------------------------------
  115. public Dsp_Engine
  116. Dsp_Engine    proc
  117.   .if <nonzero al>
  118.      jmp Dsp_StateOn
  119.   .endif
  120.   jmp Dsp_StateOff
  121. Dsp_Engine endp
  122.  
  123. ;------------------------------------------------------------------------------
  124. ; update state to on
  125. ; bx = dcb
  126. ;------------------------------------------------------------------------------
  127. public Dsp_StateOn
  128. Dsp_StateOn proc
  129.   call Dsp_CancelAutoOn
  130.  
  131.   .if  <bit [bx].dcb_DspFlags z DSP_STATE_ON>
  132.      or  [bx].dcb_DspFlags,DSP_STATE_ON
  133.      mov  di,[bx].dcb_@EiEvent
  134.      mov  [di].dev_state, ON
  135.      call Idc_ReportEvent         ; report the event
  136.   .endif
  137.  
  138.   call Dsp_StartAutoOff
  139.   ret
  140. Dsp_StateOn endp
  141.  
  142. ;------------------------------------------------------------------------------
  143. ; update state to off
  144. ; bx = dcb
  145. ;------------------------------------------------------------------------------
  146. public Dsp_StateOff
  147. Dsp_StateOff proc
  148.   call dsp_CancelAutoOff
  149.  
  150.   .if  <bit [bx].dcb_DspFlags nz DSP_STATE_ON>
  151.      and [bx].dcb_DspFlags, not DSP_STATE_ON
  152.      mov  di,[bx].dcb_@EiEvent
  153.      mov  [di].dev_state, OFF
  154.      call Idc_ReportEvent         ; report the event
  155.   .endif
  156.  
  157.   call dsp_StartAutoOn
  158.   ret
  159. Dsp_StateOff endp
  160.  
  161. ;---- AUTOMATIC BACKLIGHT CONTROL ---------------------------------------------
  162. ;
  163. ;------------------------------------------------------------------------------
  164. ;------------------------------------------------------------------------------
  165. ; Process requests to activate and disable automatic control. This should be
  166. ; called when ever the inactivity peroid changes or if the automatic enable
  167. ; changes.
  168. ;   bx = dcb
  169. ;------------------------------------------------------------------------------
  170. public Dsp_SetInactPeriod
  171. Dsp_SetInactPeriod proc
  172.  
  173.   .if <bit [bx].dcb_DspFlags z DSP_AUTO_ENABLED>
  174.      call Dsp_CancelAutoOff
  175.      call Dsp_CancelAutoOn
  176.   .else
  177.      call Dsp_Convert
  178.      .if <bit [bx].dcb_DspFlags nz DSP_STATE_ON>
  179.         call Dsp_StartAutoOff
  180.      .else
  181.         call Dsp_StartAutoOn
  182.      .endif
  183.   .endif
  184.   ret
  185. Dsp_SetInactPeriod endp
  186.  
  187. ;------------------------------------------------------------------------------
  188. ; Convert inactivity peroid in seconds to number of ticks between checks and
  189. ; number of checks needed.
  190. ;   bx = dcb
  191. ;------------------------------------------------------------------------------
  192. K2 equ dword ptr [bp-6]
  193. K1 equ word ptr  [bp-2]
  194.  
  195. public Dsp_Convert
  196. Dsp_Convert proc
  197.   .386p
  198.   enter 6,0
  199.   mov ecx,[bx].dcb_InactPeriod
  200.   .if <ecx be LIMIT1>
  201.      mov  eax, CNT1
  202.   .elseif <ecx be LIMIT2>
  203.      mov  eax, CNT2
  204.   .else
  205.      mov  eax, CNT3
  206.   .endif
  207.   mov  [K2], eax   ; put on the stack for latter divide
  208.  
  209. ; calculate number of ticks between activity checks
  210.  
  211.   mov  [K1], 1000
  212.   imul [K1]            ;convert seconds to milliseconds
  213.   call Tim_Mill2Tick   ;convert to tick count
  214.   mov  [bx].dcb_TicksPerCheck, ax
  215.  
  216. ; calculate number of checks needed
  217.  
  218.   mov  eax,ecx
  219.   xor  edx,edx
  220.   idiv [K2]
  221.   .if  <nonzero edx>
  222.      inc eax
  223.   .endif
  224.   mov  [bx].dcb_NumberChecks, eax
  225.  
  226.   leave
  227.   .286p
  228.   ret
  229. Dsp_Convert endp
  230.  
  231. ;------------------------------------------------------------------------------
  232. ; start an automatic on
  233. ; bx = dcb
  234. ;------------------------------------------------------------------------------
  235. public Dsp_StartAutoOn
  236. Dsp_StartAutoOn proc
  237.   .if <bit [bx].dcb_DspFlags nz DSP_AUTO_ENABLED>
  238.       call Idc_RequestCallback
  239.       or   [bx].dcb_DspFlags,DSP_AUTO_ON
  240.   .endif
  241.   ret
  242. Dsp_StartAutoOn endp
  243.  
  244. ;------------------------------------------------------------------------------
  245. ; start an automatic off. Blindly restart the counter if it is already going
  246. ; bx = dcb
  247. ;------------------------------------------------------------------------------
  248. public Dsp_StartAutoOff
  249. Dsp_StartAutoOff proc
  250.   .if <bit [bx].dcb_DspFlags nz DSP_AUTO_ENABLED>
  251.       .386p
  252.       mov  ax,[bx].dcb_TicksPerCheck
  253.       mov  [bx].dcb_CountDown1, ax
  254.       mov  eax,[bx].dcb_NumberChecks
  255.       mov  [bx].dcb_CountDown2, eax
  256.       .286p
  257.       or   [bx].dcb_DspFlags,DSP_AUTO_OFF
  258.   .endif
  259.   ret
  260. Dsp_StartAutoOff endp
  261.  
  262. ;------------------------------------------------------------------------------
  263. ; canel an automatic on
  264. ; bx = dcb
  265. ;------------------------------------------------------------------------------
  266. public Dsp_CancelAutoOn
  267. Dsp_CancelAutoOn proc
  268.   .if <bit [bx].dcb_DspFlags nz DSP_AUTO_ON>
  269.      and  [bx].dcb_DspFlags,not DSP_AUTO_ON
  270.      call Idc_CancelCallback
  271.   .endif
  272.   ret
  273. Dsp_CancelAutoOn endp
  274.  
  275. ;------------------------------------------------------------------------------
  276. ; canel an automatic off.
  277. ; bx = dcb
  278. ;------------------------------------------------------------------------------
  279. public Dsp_CancelAutoOff
  280. Dsp_CancelAutoOff proc
  281.   .if <bit [bx].dcb_DspFlags nz DSP_AUTO_OFF>
  282.       and  [bx].dcb_DspFlags,not DSP_AUTO_OFF
  283.   .endif
  284.   ret
  285. Dsp_CancelAutoOff endp
  286.  
  287. ;------------------------------------------------------------------------------
  288. ; process ticks to detect inactivity period
  289. ; bx = dcb
  290. ;------------------------------------------------------------------------------
  291. public dsp_tick
  292. dsp_tick    proc
  293.   .if <bit [bx].dcb_DspFlags nz DSP_AUTO_OFF>
  294.      sub [bx].dcb_CountDown1,1
  295.      .if Z OR
  296.      .if C
  297.         mov  ax,[bx].dcb_TicksPerCheck
  298.         mov  [bx].dcb_CountDown1, ax
  299.         call Idc_QueryActivity
  300.         .386p
  301.         xchg edx,[bx].dcb_LastActivity
  302.         .if <edx eq [bx].dcb_LastActivity>
  303.            sub [bx].dcb_CountDown2,1
  304.            .286p
  305.            .if Z OR
  306.            .if C
  307.               and [bx].dcb_DspFlags, not DSP_AUTO_OFF
  308.               mov  al,OFF
  309.               jmp  Dsp_SDS
  310.            .endif
  311.         .else
  312.            .386p
  313.            mov  eax,[bx].dcb_NumberChecks
  314.            mov  [bx].dcb_CountDown2, eax
  315.            .286p
  316.         .endif
  317.      .endif
  318.   .endif
  319.   ret
  320. dsp_tick    endp
  321.  
  322. ;------------------------------------------------------------------------------
  323. ; process callback after system activity to automatically turn display on
  324. ; bx = dcb
  325. ;------------------------------------------------------------------------------
  326. public Dsp_callback
  327. Dsp_callback    proc
  328.   mov  bx, displayDCB
  329.   .if <bit [bx].dcb_DspFlags nz DSP_AUTO_ON>
  330.      and [bx].dcb_DspFlags, not DSP_AUTO_ON
  331.      .if <bit [bx].dcb_DspFlags nz DSP_SUPPRESS>
  332.         call Idc_SuppressStroke
  333.      .endif
  334.      mov  al,ON
  335.      call Dsp_SDS
  336.   .endif
  337.   ret
  338. Dsp_callback    endp
  339.  
  340. ;------------------------------------------------------------------------------
  341. ; Get control bits for suppressing activity while the backlight is off
  342. ; returns
  343. ;   dx = lev_cntrl and bev_cntrl bits
  344. ;------------------------------------------------------------------------------
  345. public Dsp_GetSuppress
  346. Dsp_GetSuppress proc
  347.   push bx
  348.   mov  bx,displayDCB
  349.   .if  <nonzero bx> AND ; incase display not started
  350.   .if  <bit [bx].dcb_DspFlags z DSP_STATE_ON+DSP_OPAQUE>
  351.      mov dx,LOC_BKLT_OFF
  352.   .else
  353.      xor dx,dx
  354.   .endif
  355.   pop  bx
  356.   ret
  357. Dsp_GetSuppress endp
  358.  
  359. CSEG ends
  360. ;---- INITIALIZATION ROUTINES -------------------------------------------------
  361. ;
  362. ; note: this code is truncated from the driver after the INIT command returns
  363. ;       to OS/2
  364. ;------------------------------------------------------------------------------
  365.  
  366. ;------------------------------------------------------------------------------
  367. ; Initialize engine
  368. ;  bx = dcb
  369. ;------------------------------------------------------------------------------
  370. CSEGI segment
  371. public Dsp_Init
  372. Dsp_Init proc
  373.   mov  displayDCB,bx
  374.   mov  [bx].dcb_@Dev_DTTick  ,offset dsp_tick
  375.   call Dsp_SetInactPeriod
  376.   ret
  377. Dsp_Init endp
  378. CSEGI ends
  379. end
  380.