xref: /reactos/drivers/multimedia/audio/sound/sound.c (revision 8a978a17)
1 /*
2  * COPYRIGHT:        See COPYING in the top level directory
3  * PROJECT:          ReactOS kernel
4  * FILE:             mkernel/modules/sound/sound.c
5  * PURPOSE:          SoundBlaster 16 Driver
6  * PROGRAMMER:       Snatched from David Welch (welch@mcmail.com)
7  *		     Modified for Soundblaster by Robert Bergkvist (fragdance@hotmail.com)
8  * UPDATE HISTORY:
9  *              ??/??/??: Created
10  *
11  */
12 
13 /* FUNCTIONS **************************************************************/
14 
15 #include <ntddk.h>
16 #include <string.h>
17 #include <devices.h>
18 #include "sb16.h"
19 #include "dsp.h"
20 #include "mixer.h"
21 #include "wave.h"
22 
23 #define NDEBUG
24 #include <debug.h>
25 
26 SB16 sb16;
27 sb_status sb16_getenvironment(void);
28 
29 #if 0
30 static NTSTATUS NTAPI Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
31 /*
32  * FUNCTION: Handles user mode requests
33  * ARGUMENTS:
34  *           DeviceObject = Device for request
35  *           Irp = I/O request packet describing request
36  * RETURNS: Success or failure
37  */
38 {
39    PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
40    NTSTATUS status;
41 
42    switch (Stack->MajorFunction)
43      {
44       case IRP_MJ_CREATE:
45       	DPRINT1("(SoundBlaster 16 Driver WaveOut) Creating\n");
46  	reset_dsp(sb16.base);
47        	status = STATUS_SUCCESS;
48 	break;
49 
50      case IRP_MJ_CLOSE:
51 	status = STATUS_SUCCESS;
52 	break;
53 
54       case IRP_MJ_WRITE:
55         DPRINT1("(SoundBlaster 16 Driver) Writing %d bytes\n",Stack->Parameters.Write.Length);
56         sb16_play((WAVE_HDR*)Irp->UserBuffer);
57 	status = STATUS_SUCCESS;
58 	break;
59 
60       default:
61         status = STATUS_NOT_IMPLEMENTED;
62 	break;
63      	}
64 
65    Irp->IoStatus.Status = status;
66    Irp->IoStatus.Information = 0;
67 
68    IoCompleteRequest(Irp, IO_NO_INCREMENT);
69    return(status);
70 }
71 
72 NTSTATUS ModuleEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
73 /*
74  * FUNCTION: Called by the system to initialize the driver
75  * ARGUMENTS:
76  *           DriverObject = object describing this driver
77  *           RegistryPath = path to our configuration entries
78  * RETURNS: Success or failure
79  */
80 {
81 #if 0
82 	PDEVICE_OBJECT DeviceObject;
83 	NTSTATUS ret;
84 
85 	DPRINT1("SoundBlaster 16 Driver 0.0.1\n");
86   	if(sb16_getenvironment()!=SB_TRUE)
87   	{
88   		DPRINT1("Soundblaster 16 not found\n");
89 	  	return 0;
90 	}
91 	ret = IoCreateDevice(DriverObject,0,L"\\Device\\WaveOut",FILE_DEVICE_WAVE_OUT,0,FALSE,&DeviceObject);
92 	if (ret!=STATUS_SUCCESS)
93 		return(ret);
94 
95 	DeviceObject->Flags=0;
96 	DriverObject->MajorFunction[IRP_MJ_CLOSE] = Dispatch;
97 	DriverObject->MajorFunction[IRP_MJ_CREATE] =Dispatch;
98 	DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch;
99 	DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch;
100 	DriverObject->DriverUnload = NULL;
101 #endif
102 	return(STATUS_SUCCESS);
103 }
104 #endif
105 
106 sb_status sb16_getenvironment(void)
107 {
108 	if(detect_dsp(&sb16)!=SB_TRUE)
109 	{
110 		DPRINT1("Detect DSP failed!!!\n");
111 		return SB_FALSE;
112 	}
113 	DPRINT1("DSP base address 0x%x\n",sb16.base);
114 	get_irq(&sb16);
115 	DPRINT1("IRQ: %d\n",sb16.irq);
116 	get_dma(&sb16);
117 	DPRINT1("DMA8: 0x%x DMA16: 0x%x\n",sb16.dma8,sb16.dma16);
118 	return SB_TRUE;
119 }
120 
121