home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / CLOCK / PTDBEEP.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  7KB  |  377 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    ,132
  13.     NAME    PTD
  14.     TITLE    Physical Timer Device Driver
  15.  
  16.  
  17. ;***    Physical Timer Device Driver (PTD)
  18. ;
  19. ;    SCCSID = @(#)ptdbeep.asm    6.6 91/10/22
  20. ;
  21. ;    DESCRIPTION
  22. ;    This module contains the PTD's beep services.
  23. ;
  24. ;    MODIFICATION HISTORY
  25. ;    04/07/89 MTS    Created.
  26.  
  27.  
  28.     .xlist
  29. INCL_MI     EQU    1
  30.     include mvdm.inc    ;mvdm definitions for dos macros
  31.     include ptimer.inc    ;physical timer public constants
  32.     include timer.inc    ;timer hardware constants
  33. INCL_ERRORS    EQU    1
  34.     include bseerr.inc    ;error numbers
  35.     include clkseg.inc    ;segment definitions
  36.     include clkdata.inc    ;physical timer constants
  37.     include vtdptd.inc    ;ptimer/vtimer interface constants
  38.     .list
  39.  
  40. ;***    Exports
  41. ;
  42.     PUBLIC    PTBeep,PTBeepOff
  43.  
  44. ;***    Imports
  45. ;
  46.     EXTRN    selClkData:WORD
  47.     EXTRN    fpfnVTProc:FWORD
  48.     EXTRN    fsPTFlags:WORD
  49.  
  50. ClkCode SEGMENT
  51.  
  52.  
  53. BeepFuncTable label word
  54.     dw    offset ClkCode:PTBeepOff
  55.     dw    offset ClkCode:PTBeepOn
  56.     dw    offset ClkCode:PTBeepFreq
  57.     dw    offset ClkCode:PTBeepOpen
  58.     dw    offset ClkCode:PTBeepClose
  59. BeepMaxFunc    EQU    ($-BeepFuncTable)/2-1
  60.  
  61.  
  62. ;***LP    PTBeep(ulFunc, ulParam) - Device Beep Service
  63. ;
  64. ;    PTBeep provides the primitive functions which is needed
  65. ;    in generating tone from the system speaker.
  66. ;
  67. ;    ENTRY
  68. ;        ulFunc  = beep services: BEEP_OFF, BEEP_ON, BEEP_FREQ
  69. ;        ulParam = parameter for the beep service
  70. ;            BEEP_OFF:  ulParam = 0
  71. ;            BEEP_ON:   ulParam = 0
  72. ;            BEEP_FREQ: ulParam = ulFreq (freq. of the beep)
  73. ;
  74. ;    EXIT
  75. ;        SUCCESS
  76. ;        (eax) = 0
  77. ;        FAILURE
  78. ;        (eax) = error code - ERROR_INVALID_FUNCTION
  79. ;
  80. ;    USES
  81. ;        None
  82. ;
  83. ;    CONTEXT
  84. ;        Task
  85. ;        Interrupt
  86. ;
  87. ;    PSEUDOCODE
  88. ;        rc = 0;
  89. ;        switch(usFunc) {
  90. ;        case BEEP_OFF:
  91. ;            PTBeepOff();
  92. ;            break;
  93. ;        case BEEP_ON:
  94. ;            PTBeepOn();
  95. ;            break;
  96. ;        case BEEP_FREQ:
  97. ;            PTBeepFreq(usParam);
  98. ;            break;
  99. ;        default:
  100. ;            rc = ERROR_INVALID_FUNCTION;
  101. ;        }
  102. ;        return rc;
  103.  
  104.  
  105.     ASSUME    CS:ClkCode,DS:NOTHING,ES:NOTHING,SS:NOTHING
  106. Procedure PTBeep,FAR
  107.  
  108.     .386p
  109.  
  110.     ?abase    = 8 + 2         ;%%% ret. addr. is 8 bytes, bp 2 bytes
  111.     ArgVar    ulParm,ULONG        ;BUGBUG Procedure, EndProc should be
  112.     ArgVar    ulFunc,ULONG        ; changed to support 16:32 type of
  113.                     ; procedure calling.
  114.  
  115.     EnterProc
  116.     SaveReg <bx>
  117.  
  118.     mov    ax,WORD PTR [ulFunc]    ;(ax)=ulFunc
  119.     mov    bx,WORD PTR [ulParm]    ;(bx)=ulParm
  120.  
  121.     cmp    ax,BeepMaxFunc        ;is it a valid function?
  122.     ja    pbe            ;NO, goto error exit
  123.  
  124.     push    si            ;save si
  125.     mov    si,ax            ;(si)=usFunc
  126.     shl    si,1            ;adjust si as word index
  127.     call    cs:BeepFuncTable[si]    ;process requested function
  128.     pop    si            ;restore si
  129.  
  130.     xor    eax,eax         ;(eax)=ERROR_NONE
  131.  
  132. pbx:    RestoreReg <bx>
  133.     ASSUME    DS:NOTHING
  134.  
  135.     LeaveProc
  136.  
  137.     retfd    ?aframe         ;%%%
  138.  
  139. pbe:    mov    eax,ERROR_INVALID_FUNCTION
  140.     jmp    short pbx
  141.  
  142.     CpuMode reset
  143.  
  144. EndProc PTBeep
  145.  
  146.  
  147. ;***LP    PTBeepOn() - Turn Speaker On
  148. ;
  149. ;    Turn the system speaker on by enabling it.
  150. ;
  151. ;    ENTRY
  152. ;        None
  153. ;
  154. ;    EXIT
  155. ;        None
  156. ;
  157. ;    USES
  158. ;        None
  159. ;
  160. ;    CONTEXT
  161. ;        Any
  162. ;
  163. ;    PSEUDOCODE
  164. ;        read SysB;
  165. ;        enable speaker bits;
  166. ;        write SysB;
  167.  
  168.     ASSUME    CS:ClkCode,DS:NOTHING,ES:NOTHING,SS:NOTHING
  169. Procedure PTBeepOn,NEAR
  170.  
  171.     push    ax            ;save ax
  172.  
  173.     in    al,PORT_SYSB        ;(al) = SYSB
  174.     IODelay
  175.     or    al,SYSB_SPKGATE+SYSB_SPKENABLE;turn on speaker enable bits
  176.     out    PORT_SYSB,al        ;enable speaker
  177.  
  178.     pop    ax            ;restore ax
  179.  
  180.     ret
  181.  
  182. EndProc PTBeepOn
  183.  
  184.  
  185. ;***LP    PTBeepOff() - Turn Speaker Off
  186. ;
  187. ;    Turn the system speaker off by disabling it.
  188. ;
  189. ;    ENTRY
  190. ;        None
  191. ;
  192. ;    EXIT
  193. ;        None
  194. ;
  195. ;    USES
  196. ;        None
  197. ;
  198. ;    CONTEXT
  199. ;        Any
  200. ;
  201. ;    PSEUDOCODE
  202. ;        read SysB;
  203. ;        disable speaker bits;
  204. ;        write SysB;
  205.  
  206.     ASSUME    CS:ClkCode,DS:NOTHING,ES:NOTHING,SS:NOTHING
  207. Procedure PTBeepOff,NEAR
  208.  
  209.     push    ax            ;save ax
  210.  
  211.     in    al,PORT_SYSB        ;(al) = SYSB
  212.     IODelay
  213.     and    al,NOT(SYSB_SPKGATE+SYSB_SPKENABLE);turn off speaker enable bits
  214.     out    PORT_SYSB,al        ;disable speaker
  215.  
  216.     pop    ax            ;restore ax
  217.  
  218.     ret
  219.  
  220. EndProc PTBeepOff
  221.  
  222.  
  223. ;***LP    PTBeepFreq(usFreq) - Set Beep Frequency
  224. ;
  225. ;    Set the speaker timer with the given frequency in Hz.
  226. ;
  227. ;    ENTRY
  228. ;        (bx) - usFreq = beep frequency in Hz
  229. ;
  230. ;    EXIT
  231. ;        None
  232. ;
  233. ;    USES
  234. ;        None
  235. ;
  236. ;    CONTEXT
  237. ;        Any
  238. ;
  239. ;    PSEUDOCODE
  240. ;        if (usFreq < BEEPFREQ_LO)
  241. ;        usFreq = BEEPFREQ_LO;
  242. ;        convert usFreq to usTicks;
  243. ;        program speaker timer with usTicks;
  244.  
  245.     ASSUME    CS:ClkCode,DS:NOTHING,ES:NOTHING,SS:NOTHING
  246. Procedure PTBeepFreq,NEAR
  247.  
  248.     SaveReg <ax,bx,dx>
  249.  
  250.     cmp    bx,BEEPFREQ_LO        ;below minimum frequency?
  251.     jae    pbf10            ;NO, continue
  252.  
  253.     mov    bx,BEEPFREQ_LO        ;set usFreq to minimum frequency
  254.  
  255. pbf10:    mov    al,SC_CNT2+RW_LSBMSB+CM_MODE3
  256.     out    PORT_CW,al        ;reset the byte index
  257.     mov    dx,TIMERFREQ_HI
  258.     mov    ax,TIMERFREQ_LO     ;(dx:ax) = TIMERFREQ (1.19MHz)
  259.     div    bx            ;(ax) = usTick in timer counts
  260.  
  261.     out    PORT_CNT2,al        ;program low byte of timer count
  262.     IODelay
  263.     xchg    al,ah            ;(al) = high byte of timer count
  264.     out    PORT_CNT2,al        ;program high byte of timer count
  265.  
  266.     RestoreReg <dx,bx,ax>
  267.  
  268.     ret
  269.  
  270. EndProc PTBeepFreq
  271.  
  272.  
  273. ;***LP    PTBeepOpen() - Get beep access
  274. ;
  275. ;    If vtimer has the speaker ownership, call vtimer to get
  276. ;    the speaker access.
  277. ;
  278. ;    ENTRY
  279. ;        None
  280. ;
  281. ;    EXIT
  282. ;        None
  283. ;
  284. ;    USES
  285. ;        All except ds,es
  286. ;
  287. ;    CONTEXT
  288. ;        Any
  289. ;
  290. ;    PSEUDOCODE
  291. ;        if vtimer has the speaker ownership
  292. ;        call vtimer to get it;
  293.  
  294.     ASSUME    CS:ClkCode,DS:NOTHING,ES:NOTHING,SS:NOTHING
  295. Procedure PTBeepOpen,NEAR
  296.  
  297.     SaveReg <ds,es>
  298.     mov    ds,cs:[selClkData]
  299.     ASSUME    DS:ClkData
  300.  
  301.     test    fsPTFlags,PTF_OWNT2    ;ptimer already has the ownership?
  302.     jnz    ptbox            ;YES, exit
  303.  
  304.     or    fsPTFlags,PTF_OWNT2
  305.     .386p
  306.     xor    eax,eax
  307.     push    DWORD PTR VTDCMD_PREEMPTT2;(TOS+8)=VTDCMD_PREEMPTT2
  308.     push    eax            ;(TOS+4)=0
  309.     push    eax            ;(TOS)=0
  310.  
  311.     ;Should ASSERTNONZERO(fpfnVTProc)
  312.     call    FWORD PTR [fpfnVTProc]
  313.     CpuMode reset
  314.  
  315. ptbox:    RestoreReg <es,ds>
  316.     ASSUME    DS:NOTHING
  317.  
  318.     ret
  319.  
  320. EndProc PTBeepOpen
  321.  
  322.  
  323. ;***LP    PTBeepClose() - Release beep access
  324. ;
  325. ;    If ptimer has the speaker ownership, call vtimer to release
  326. ;    the speaker.
  327. ;
  328. ;    ENTRY
  329. ;        None
  330. ;
  331. ;    EXIT
  332. ;        None
  333. ;
  334. ;    USES
  335. ;        All except ds,es
  336. ;
  337. ;    CONTEXT
  338. ;        Any
  339. ;
  340. ;    PSEUDOCODE
  341. ;        if ptimer has the speaker ownership and there is a vtimer
  342. ;        call vtimer to release ownership;
  343.  
  344.     ASSUME    CS:ClkCode,DS:NOTHING,ES:NOTHING,SS:NOTHING
  345. Procedure PTBeepClose,NEAR
  346.  
  347.     SaveReg <ds,es>
  348.     mov    ds,cs:[selClkData]
  349.     ASSUME    DS:ClkData
  350.  
  351.     test    fsPTFlags,PTF_OWNT2    ;ptimer has the ownership?
  352.     jz    ptbcx            ;NO, exit
  353.  
  354.     .386p
  355.     cmp    DWORD PTR fpfnVTProc,0    ;vtimer exist?
  356.     je    ptbcx            ;NO, exit
  357.  
  358.     and    fsPTFlags,NOT PTF_OWNT2
  359.     xor    eax,eax
  360.     push    DWORD PTR VTDCMD_RELEASET2;(TOS+8)=VTDCMD_RELEASET2
  361.     push    eax            ;(TOS+4)=0
  362.     push    eax            ;(TOS)=0
  363.  
  364.     call    FWORD PTR [fpfnVTProc]
  365.     CpuMode reset
  366.  
  367. ptbcx:    RestoreReg <es,ds>
  368.  
  369.     ret
  370.  
  371. EndProc PTBeepClose
  372.  
  373. ClkCode ENDS
  374.  
  375.  
  376.     END
  377.