From: XXguille AT XXiies DOT XXes (Guillermo Rodriguez Garcia) Newsgroups: comp.os.msdos.djgpp Subject: Re: Allocate dos memory Date: Sun, 25 Apr 1999 23:58:01 GMT Organization: Telefonica Transmision de Datos Lines: 59 Message-ID: <3725abcb.2835404@noticias.iies.es> References: <371fcde7 DOT 5102505 AT news DOT enter DOT net> NNTP-Posting-Host: 194.224.30.195 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Forte Agent 1.5/32.451 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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 :-)