Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

274 lines
6.9 KiB

  1. #include <windows.h>
  2. #include <mmsystem.h>
  3. #include <mmddk.h>
  4. #include "wvmapper.h"
  5. HINSTANCE g_hmodThis;
  6. WORD gwodOpenCount = 0 ;
  7. struct wod_tag gwod ;
  8. DWORD gDeviceAddress ;
  9. WORD gPinHandle ;
  10. LRESULT _loadds CALLBACK DriverProc (dwId, hDriver, wMsg, lParam1, lParam2 )
  11. DWORD dwId ;
  12. HDRVR hDriver ;
  13. WORD wMsg ;
  14. LPARAM lParam1 ;
  15. LPARAM lParam2 ;
  16. {
  17. switch ( wMsg ) {
  18. case DRV_OPEN:
  19. OutputDebugString ( "WVMAPPER :: DRV_OPEN\n" ) ;
  20. return ( OpenDevice() ) ;
  21. case DRV_CLOSE:
  22. OutputDebugString ( "WVMAPPER :: DRV_CLOSE\n" ) ;
  23. break ;
  24. case DRV_CONFIGURE:
  25. OutputDebugString ( "WVMAPPER :: DRV_CONFIGURE\n" ) ;
  26. break ;
  27. case DRV_DISABLE:
  28. OutputDebugString ( "WVMAPPER :: DRV_DISABLE\n" ) ;
  29. break ;
  30. case DRV_ENABLE:
  31. OutputDebugString ( "WVMAPPER :: DRV_ENABLE\n" ) ;
  32. break ;
  33. case DRV_FREE:
  34. OutputDebugString ( "WVMAPPER :: DRV_FREE\n" ) ;
  35. break ;
  36. case DRV_INSTALL:
  37. OutputDebugString ( "WVMAPPER :: DRV_INSTALL\n" ) ;
  38. break ;
  39. case DRV_LOAD:
  40. OutputDebugString ( "WVMAPPER :: DRV_LOAD\n" ) ;
  41. break ;
  42. case DRV_POWER:
  43. OutputDebugString ( "WVMAPPER :: DRV_POWER\n" ) ;
  44. break ;
  45. case DRV_QUERYCONFIGURE:
  46. OutputDebugString ( "WVMAPPER :: DRV_QUERYCONFIGURE\n" ) ;
  47. break ;
  48. case DRV_REMOVE:
  49. OutputDebugString ( "WVMAPPER :: DRV_REMOVE\n" ) ;
  50. break ;
  51. default:
  52. OutputDebugString ( "WVMAPPER :: DRV_OTHERS\n" ) ;
  53. }
  54. return (1L) ;
  55. }
  56. DWORD FAR PASCAL _loadds wodMessage (uDevId, uMsg, dwUser, dwParam1, dwParam2)
  57. UINT uDevId ;
  58. UINT uMsg ;
  59. DWORD dwUser ;
  60. DWORD dwParam1 ;
  61. DWORD dwParam2 ;
  62. {
  63. switch (uMsg) {
  64. case WODM_BREAKLOOP:
  65. OutputDebugString ( "WVMAPPER :: WODM_BREAKLOOP\n" ) ;
  66. return ( MMSYSERR_NOERROR ) ;
  67. case WODM_CLOSE:
  68. OutputDebugString ( "WVMAPPER :: WODM_CLOSE\n" ) ;
  69. return (wodmClose()) ;
  70. case WODM_GETDEVCAPS:
  71. OutputDebugString ( "WVMAPPER :: WODM_GETDEVCAPS\n" ) ;
  72. return (wodmGetDevCaps ( (LPWAVEOUTCAPS) dwParam1, dwParam2 ) ) ;
  73. case WODM_GETNUMDEVS:
  74. OutputDebugString ( "WVMAPPER :: WODM_GETNUMDEVS\n" ) ;
  75. return ( 1 ) ;
  76. case WODM_GETPOS:
  77. OutputDebugString ( "WVMAPPER :: WODM_GETPOS\n" ) ;
  78. return ( MMSYSERR_NOERROR ) ;
  79. case WODM_OPEN:
  80. OutputDebugString ( "WVMAPPER :: WODM_OPEN\n" ) ;
  81. return wodmOpen ( (LPWAVEOPENDESC) dwParam1, dwParam2 ) ;
  82. case WODM_PAUSE:
  83. OutputDebugString ( "WVMAPPER :: WODM_PAUSE\n" ) ;
  84. return ( MMSYSERR_NOERROR ) ;
  85. case WODM_RESET:
  86. OutputDebugString ( "WVMAPPER :: WODM_RESET\n" ) ;
  87. return ( MMSYSERR_NOERROR ) ;
  88. case WODM_RESTART:
  89. OutputDebugString ( "WVMAPPER :: WODM_RESTART\n" ) ;
  90. return ( MMSYSERR_NOERROR ) ;
  91. case WODM_WRITE:
  92. OutputDebugString ( "WVMAPPER :: WODM_WRITE\n" ) ;
  93. return ( wodmWrite ( (LPWAVEHDR)dwParam1, dwParam2) ) ;
  94. default:
  95. OutputDebugString ( "WVMAPPER :: WODM_OTHERS\n" ) ;
  96. return ( MMSYSERR_NOTSUPPORTED ) ;
  97. }
  98. return (TRUE) ;
  99. }
  100. DWORD FAR PASCAL _loadds widMessage (uDevId, uMsg, dwUser, dwParam1, dwParam2)
  101. UINT uDevId ;
  102. UINT uMsg ;
  103. DWORD dwUser ;
  104. DWORD dwParam1 ;
  105. DWORD dwParam2 ;
  106. {
  107. switch (uMsg) {
  108. case WIDM_CLOSE:
  109. OutputDebugString ( "WVMAPPER :: WIDM_CLOSE\n" ) ;
  110. return ( MMSYSERR_NOERROR ) ;
  111. case WIDM_GETDEVCAPS:
  112. OutputDebugString ( "WVMAPPER :: WIDM_GETDEVCAPS\n" ) ;
  113. return ( MMSYSERR_NOERROR ) ;
  114. case WIDM_GETNUMDEVS:
  115. OutputDebugString ( "WVMAPPER :: WIDM_GETNUMDEVS\n" ) ;
  116. return ( 1 ) ;
  117. case WIDM_GETPOS:
  118. OutputDebugString ( "WVMAPPER :: WIDM_GETPOS\n" ) ;
  119. return ( MMSYSERR_NOERROR ) ;
  120. case WIDM_OPEN:
  121. OutputDebugString ( "WVMAPPER :: WIDM_OPEN\n" ) ;
  122. return ( MMSYSERR_NOERROR ) ;
  123. case WIDM_RESET:
  124. OutputDebugString ( "WVMAPPER :: WIDM_RESET\n" ) ;
  125. return ( MMSYSERR_NOERROR ) ;
  126. default:
  127. OutputDebugString ( "WVMAPPER :: WIDM_OTHERS\n" ) ;
  128. return ( MMSYSERR_NOTSUPPORTED ) ;
  129. }
  130. return (TRUE) ;
  131. }
  132. BOOL FAR PASCAL LibMain(HANDLE hInstance, WORD wHeapSize, LPSTR lpszCmdLine)
  133. {
  134. g_hmodThis = hInstance;
  135. return(TRUE);
  136. }
  137. MMRESULT wodmGetDevCaps ( lpWaveOutCaps, dwSize )
  138. LPWAVEOUTCAPS lpWaveOutCaps ;
  139. DWORD dwSize ;
  140. {
  141. char *name = "WDM WaveOut Mapper" ;
  142. char far *tmp ;
  143. lpWaveOutCaps->wMid = 1 ;
  144. lpWaveOutCaps->wPid = 1 ;
  145. lpWaveOutCaps->vDriverVersion = 1 ;
  146. lpWaveOutCaps->dwFormats = WAVE_FORMAT_4S16 ;
  147. lpWaveOutCaps->wChannels = 2 ;
  148. lpWaveOutCaps->dwSupport = 0 ;
  149. tmp = &lpWaveOutCaps->szPname[0] ;
  150. while ( *name ) {
  151. *tmp++ = *name++ ;
  152. }
  153. *tmp = '\0' ;
  154. return ( MMSYSERR_NOERROR ) ;
  155. }
  156. MMRESULT wodmOpen ( lpWaveOpenDesc, Flags )
  157. LPWAVEOPENDESC lpWaveOpenDesc ;
  158. DWORD Flags ;
  159. {
  160. LPWAVEFORMAT lpWaveFormat ;
  161. if ( Flags & WAVE_FORMAT_QUERY ) {
  162. lpWaveFormat = lpWaveOpenDesc->lpFormat ;
  163. if ( (lpWaveFormat->wFormatTag != WAVE_FORMAT_PCM) ||
  164. (lpWaveFormat->nChannels != MIXER_CHANNELS) ||
  165. (lpWaveFormat->nSamplesPerSec != MIXER_SAMPLE_RATE) ||
  166. (lpWaveFormat->nBlockAlign != (MIXER_CHANNELS*MIXER_SAMPLE_SIZE)) )
  167. return ( WAVERR_BADFORMAT ) ;
  168. return ( MMSYSERR_NOERROR ) ;
  169. }
  170. if ( gwodOpenCount )
  171. return ( MMSYSERR_ALLOCATED ) ;
  172. gPinHandle = OpenPin((LPWAVEFORMAT)lpWaveOpenDesc->lpFormat) ;
  173. if ( !gPinHandle )
  174. return ( MMSYSERR_NOTENABLED ) ;
  175. gwodOpenCount++ ;
  176. gwod.hWave = lpWaveOpenDesc->hWave ;
  177. gwod.dwInstance = lpWaveOpenDesc->dwInstance ;
  178. gwod.dwCallBack = lpWaveOpenDesc->dwCallback ;
  179. gwod.dwFlags = Flags & (~WAVE_FORMAT_QUERY) ;
  180. wodCallBack ( WOM_OPEN, 0L, 0L ) ;
  181. return ( MMSYSERR_NOERROR) ;
  182. }
  183. MMRESULT wodmClose ()
  184. {
  185. if ( (gwodOpenCount != 1) ) {
  186. OutputDebugString ( "Wierd waveout open count -- %d" ) ;
  187. _asm int 3 ;
  188. }
  189. ClosePin ( gPinHandle ) ;
  190. gwodOpenCount-- ;
  191. wodCallBack ( WOM_CLOSE, 0L, 0L ) ;
  192. return (MMSYSERR_NOERROR) ;
  193. }
  194. MMRESULT wodmWrite ( lpWaveHdr, dwSize )
  195. LPWAVEHDR lpWaveHdr ;
  196. DWORD dwSize ;
  197. {
  198. lpWaveHdr->dwFlags |= WHDR_INQUEUE ;
  199. lpWaveHdr->dwFlags &= ~WHDR_DONE ;
  200. WritePin ( lpWaveHdr ) ;
  201. return ( MMSYSERR_NOERROR ) ;
  202. }
  203. VOID wodCallBack ( msg, dw1, dw2 )
  204. WORD msg ;
  205. DWORD dw1 ;
  206. DWORD dw2 ;
  207. {
  208. DriverCallback(
  209. gwod.dwCallBack, // user's callback DWORD
  210. HIWORD(gwod.dwFlags), // callback flags
  211. gwod.hWave, // handle to the wave device
  212. msg, // the message
  213. gwod.dwInstance, // user's instance data
  214. dw1, // first DWORD
  215. dw2 ) ; // second DWORD
  216. }
  217. WORD ClosePin ( PinHandle )
  218. WORD PinHandle;
  219. {
  220. WORD result ;
  221. _asm {
  222. mov ax, CLOSE_PIN
  223. mov bx, word ptr PinHandle
  224. call dword ptr [gDeviceAddress]
  225. mov result, ax
  226. }
  227. return (result) ;
  228. }
  229. LRESULT OpenDevice ()
  230. {
  231. _asm {
  232. xor ax, ax
  233. mov es, ax
  234. mov di, ax
  235. mov ax, 1684h
  236. mov bx, WVMAPPER_DEVICE_ID
  237. int 2fh
  238. mov word ptr [gDeviceAddress], di
  239. mov word ptr [gDeviceAddress+2], es
  240. }
  241. if ( gDeviceAddress )
  242. return ( 1L ) ;
  243. else
  244. return ( 0L ) ;
  245. }
  246. VOID PASCAL FAR _loadds WODCOMPLETEIO (lpWaveHdr)
  247. LPWAVEHDR lpWaveHdr ;
  248. {
  249. lpWaveHdr->dwFlags &= ~WHDR_INQUEUE ;
  250. lpWaveHdr->dwFlags |= WHDR_DONE ;
  251. wodCallBack ( WOM_DONE, (DWORD)lpWaveHdr, 0L) ;
  252. }