home *** CD-ROM | disk | FTP | other *** search
/ Software Collection (I) / TOOLS.iso / b04 / 25.img / ADLIB / ADLIBA.ASM / ADLIBA.ASM
Encoding:
Assembly Source File  |  1992-03-02  |  5.9 KB  |  243 lines

  1.         page    60, 132
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ;   adliba.asm
  5. ;
  6. ;   Copyright (c) 1991-1992 Microsoft Corporation.  All Rights Reserved.
  7. ;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10.         PMODE = 1
  11.  
  12.         .xlist
  13.         include cmacros.inc                   
  14.         .list
  15.  
  16.         ?PLM=1                          ; Pascal calling convention
  17.         ?WIN=0                          ; NO! Windows prolog/epilog code
  18.  
  19.  
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;
  22. ;   debug support
  23. ;
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25.  
  26. ifdef DEBUG
  27.     extrn OutputDebugStr:far          ; mmsystem
  28.     extrn _wDebugLevel:word           ; initc.c
  29. endif
  30.  
  31. D1 macro text
  32.     DOUT 1, < ",13,10,"ADLIB: &text&>
  33.     endm
  34. D2 macro text
  35.     DOUT 2, < &text&>
  36.     endm
  37. D3 macro text
  38.     DOUT 3, < &text&>
  39.     endm
  40. D4 macro text
  41.     DOUT 4, < &text&>
  42.     endm
  43.  
  44. DOUT macro level, text
  45.     local   string_buffer
  46.     local   wrong_level
  47.  
  48. ifdef DEBUG
  49.  
  50. _DATA segment
  51. string_buffer label byte
  52.     db      "&text&", 0
  53. _DATA ends
  54.  
  55.     cmp     [_wDebugLevel], level
  56.     jl      wrong_level
  57.     push    ds
  58.     push    DataOFFSET string_buffer
  59.     call    OutputDebugStr
  60. wrong_level:
  61. endif
  62.     endm
  63.  
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65. ;
  66. ;   assert macros
  67. ;
  68. ;   AssertF byte        -- fail iff byte==0
  69. ;   AssertT byte        -- fail iff byte!=0
  70. ;
  71. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72.  
  73. AssertF     macro exp
  74.     local   assert_ok
  75. ifdef DEBUG
  76.     push    ax
  77.     
  78.     mov     al, exp
  79.     or      al, al
  80.     jnz     assert_ok
  81.  
  82.     D1      <AssertF fail (&exp&)>
  83.     int     3
  84.  
  85. assert_ok:
  86.     pop     ax
  87. endif
  88.     endm
  89.  
  90. AssertT     macro exp
  91.     local   assert_ok
  92. ifdef DEBUG
  93.     push    ax
  94.     
  95.     mov     al, exp
  96.     or      al, al
  97.     jz      assert_ok
  98.  
  99.     D1      <AssertT fail (&exp&)>
  100.     int     3
  101.  
  102. assert_ok:
  103.     pop     ax
  104. endif
  105.     endm
  106.  
  107.  
  108. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  109. ;
  110. ;   data segment
  111. ;
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113.  
  114. sBegin Data
  115.  
  116.         externW <_wPort>                ; address of sound chip
  117.         externW <_wWriteDelay>          ; delay time for write
  118.  
  119. sEnd Data
  120.  
  121. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  122. ;
  123. ;   code segment
  124. ;
  125. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  126.  
  127. ifndef SEGNAME
  128.         SEGNAME equ <_TEXT>
  129. endif
  130.  
  131. createSeg %SEGNAME, CodeSeg, word, public, CODE
  132.  
  133. sBegin  CodeSeg
  134.  
  135.         assumes cs, CodeSeg
  136.         assumes ds, Data
  137.  
  138. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  139. ; @doc INTERNAL 
  140. ;
  141. ; @api BYTE | inport | Read a port.
  142. ;
  143. ; @parm WORD | port | The port to read.
  144. ;
  145. ; @rdesc Returns the port value read.
  146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147.  
  148.         assumes ds, Data
  149.         assumes es, nothing
  150.  
  151. cProc inport <FAR, PUBLIC> <>
  152. cBegin nogen
  153.  
  154.         mov     dx, [_wPort]
  155.         in      al, dx
  156.  
  157.         D4 <I:#AL>
  158.  
  159.         retf
  160.  
  161. cEnd nogen
  162.  
  163.  
  164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  165. ; @doc INTERNAL 
  166. ;
  167. ; @api void | SndOutput | This function writes data to the chip registers.
  168. ;
  169. ; @parm BYTE | bRegister | The address of the register to write.
  170. ;
  171. ; @parm BYTE | bData | The data value to write.
  172. ;
  173. ; @rdesc There is no return value.
  174. ;
  175. ; @comm Delay is included after each write.  Current implementation is less
  176. ;     than ideal - I'm currently investigating methods of calculating the
  177. ;     real number of cycles needed (which requires determining machine speed)
  178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  179.  
  180.         assumes ds, Data
  181.         assumes es, nothing
  182.  
  183. cProc SndOutput <FAR, PUBLIC> <>
  184.         ParmB   bRegister               ; register address
  185.         ParmB   bData                   ; value to write
  186. cBegin
  187.  
  188. ifdef DEBUG
  189.         mov     al, bRegister
  190.         mov     ah, bData
  191.         D4 <O:#AL,#AH>
  192. endif
  193.  
  194.         mov     dx, [_wPort]            ; get register select address of sound chip
  195.         mov     al, bRegister           ; register number to write to
  196.         out     dx, al
  197.  
  198. ;   A a minimum of 3.3 us delay is needed after selecting register:
  199.  
  200.         mov     cx, [_wWriteDelay]      ; 5/4/1 cycles
  201. @@:     dec     cx                      ; 2/2/1 cycles
  202.         jnz     @B                      ; 9/9/3 cycles (3/3/1 last time)
  203.  
  204.         inc     dx                      ; data write address of chip (2/2/1 cycles)
  205.         mov     al, bData               ; value to write (5/4/1 cycles)
  206.         out     dx, al
  207.  
  208. ;   A a minimum of 23 us delay is needed after writing a note:
  209.  
  210.         mov     ax, [_wWriteDelay]      ; 5/4/1 cycles
  211.         mov     bx, 7                   ; 2/2/1 cycles
  212.         mul     bx                      ; 21/9/13 cycles
  213. @@:     dec     ax                      ; 2/2/1 cycles
  214.         jnz     @B                      ; 9/9/3 cycles (3/3/1 last time)
  215.  
  216. cEnd
  217.  
  218.  
  219. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  220. ; @doc INTERNAL
  221. ;
  222. ; @asm WEP | This function is called when the DLL is unloaded.
  223. ;
  224. ; @parm WORD | UselessParm | This parameter has no meaning.
  225. ;
  226. ; @comm WARNING: This function is basically useless since you can't call any
  227. ;     kernel function that may cause the LoadModule() code to be reentered.
  228. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  229.  
  230.         assumes ds, nothing
  231.         assumes es, nothing
  232.  
  233. cProc WEP <FAR, PUBLIC, PASCAL>, <>
  234. ;       ParmW   wUselessParm
  235. cBegin nogen
  236.         mov     ax, 1
  237.         retf    2
  238. cEnd nogen
  239.  
  240. sEnd CodeSeg
  241.  
  242.         end
  243.