X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dos_sbtest;a=blobdiff_plain;f=src%2Fau_sb.c;h=2046f915d515403865417373ac5642d88d390469;hp=ab12b9e405f5d26aeaa9ab485949ee40c2fcf036;hb=d08178b30de9363c1fda1de3499f541faf520924;hpb=6d4de53a835a8258ba05c83a2af38f27a0e92d21 diff --git a/src/au_sb.c b/src/au_sb.c index ab12b9e..2046f91 100644 --- a/src/au_sb.c +++ b/src/au_sb.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "audio.h" #include "au_sb.h" #include "dma.h" @@ -169,18 +170,28 @@ void *sb_buffer(int *size) void sb_start(int rate, int nchan) { + int seg, pmsel; uint32_t addr; int size; _go32_dpmi_seginfo intr; - /* for now just use the are after boot2. it's only used by the second stage - * loader and the VBE init code, none of which should overlap with audio playback. - * It's not necessary to use low memory. We can use up to the first 16mb for this, - * so if this becomes an issue, I'll make a DMA buffer allocator over 1mb. - * start the buffer from the next 64k boundary. - */ - addr = ((uint32_t)low_mem_buffer + 0xffff) & 0xffff0000; - buffer = (void*)addr; + if(!buffer) { + __djgpp_nearptr_enable(); + + /* allocate a 64k-aligned 64k buffer in low memory */ + if((seg = __dpmi_allocate_dos_memory(65536 * 2 / 16, &pmsel)) <= 0) { + fprintf(stderr, "sb_start: failed to allocate DMA buffer\n"); + return; + } + + printf("allocated seg: %d, addr: %lx\n", seg, (unsigned long)seg << 4); + + addr = ((uint32_t)(seg << 4) + 0xffff) & 0xffff0000; + printf("aligned: %lx\n", (unsigned long)addr); + buffer = (void*)(addr - __djgpp_base_address); + } else { + addr = (uint32_t)buffer; + } xfer_mode = CMD_MODE_SIGNED; if(nchan > 1) {