Mail Archives: djgpp/1999/04/28/07:49:57
El día Fri, 23 Apr 1999 01:48:10 GMT, tdu AT enter DOT net (Tim Updegrove)
escribió:
>I'm still trying to allocate memory and get a physical address for a
>DMA controller.  As a temporary approach to my physical address
>problem, I've tried to use __dpmi_allocate_dos_memory.  The below
>piece of code works but I have several questions:
Here you have a function which allocates DOS memory suitable for DMA
transfers, ensuring that the block doesn't cross a page boundary; it
is based in Allegro, but for 16 bit DMA it supports blocks up to 128
KB (I think Allegro's was limited to 64 KB). On success, it fills
*paddr with the physical address of the block to use, and *psel with
the selector (needed to free the block) and returns 0. On error, it
returns -1.
You don't need to manually lock this memory.
Hope this helps.
=== Begin ===
int dma_alloc(unsigned size, int *paddr, int *psel)
{
    int seg;
    if (size > 131072) return -1;
    seg = __dpmi_allocate_dos_memory((2 * size + 15) >> 4, psel);
    if (seg == -1)
    {
        *paddr = 0;
        *psel  = 0;
        return -1;
    }
    *paddr = seg << 4;
    if (size <= 65536)
    {
        if ((*paddr >> 16) != ((*paddr + size) >> 16))
            *paddr = (*paddr + size) & 0xFFFF0000;
    }
    else
    {
        if ((*paddr >> 17) != ((*paddr + size) >> 17))
            *paddr = (*paddr + size) & 0xFFFE0000;
    }
    return 0;
}
=== End ===
Regards,
GUILLE
----
Guillermo Rodriguez Garcia
XXguille AT XXiies DOT XXes (ya sabes :-)
- Raw text -