sb16: continue trying to add a driver

This commit is contained in:
2026-05-09 15:21:07 +03:00
parent 59b775457d
commit 312c543510
+42 -1
View File
@@ -49,11 +49,13 @@ int sb16_get_irq()
return irq;
}
void* buffer;
void* sb16_allocate_buf()
{
const size_t size = 64*1024;//64 KB
void* buffer = malloc(size);
buffer = malloc(size);
return get_physaddr(buffer);
}
@@ -66,6 +68,42 @@ void sb16_get_version(int* major, int* minor)
*minor = inb(DSP_READ);
}
void sb16_program_dma()
{
const int transfer_mode = 0x48;
const int channel = 1;
const int page_number = 0;//page that contains sound data
int buffer_pos = (uint32_t)buffer & 0xffff;
int count = 0;
outb(0x0A, 0x4 + channel);//0x4 + channel number (1 in this case)
outb(0x0C, 1);//flip flop
outb(0x0B, transfer_mode + channel);
outb(0x83, page_number);
//set the position
outb(0x02, (buffer_pos) & 0xFF);
outb(0x02, (buffer_pos >> 8) & 0xFF);
//set the count
outb(0x03, (count - 1) & 0xFF);
outb(0x03, ((count - 1) >> 8) & 0xFF);
outb(0x0A, 1);
}
void sb16_program()
{
const int samples_count = 0;
outb(DSP_WRITE, 0x40);//time constant
outb(DSP_WRITE, 165);//10989 Hz
outb(DSP_WRITE, 0xC0);//8-bit sound
outb(DSP_WRITE, 0x00);//mono unsigned
outb(DSP_WRITE, (samples_count - 1) & 0xFF);
outb(DSP_WRITE, ((samples_count - 1) >> 8) & 0xFF);
}
void sb16_init()
{
int status = sb16_dsp_reset();
@@ -80,4 +118,7 @@ void sb16_init()
printf("sb16 version: %X.%X\n", major, minor);
outb(DSP_WRITE, 0xD1);//enable speaker
sb16_program_dma();
sb16_program();
}