/* modex_exit: * Frees the magic bank switch buffer. */ static void modex_exit(BITMAP *b) { #ifdef ALLEGRO_DOS /* free conventional memory buffer */ if (_x_magic_buffer_addr) { __dpmi_free_dos_memory(magic_sel); magic_sel = 0; _x_magic_buffer_addr = 0; } #else /* free normal memory buffer */ if (_x_magic_buffer_addr) { _AL_FREE((void *)_x_magic_buffer_addr); _x_magic_buffer_addr = 0; } #endif _unset_vga_mode(); /* see modexsms.c */ _split_modex_screen_ptr = NULL; }
void dma_free(dma_buffer * buffer) { __dpmi_meminfo buff_info; if (!buffer) return; buff_info.address = buffer->physical; buff_info.size = buffer->size; __dpmi_unlock_linear_region(&buff_info); __dpmi_free_dos_memory(buffer->selector); free(buffer); if (--__buffer_count == 0) dma_finalize(); }
int set_clipboard_data(char *data, int size) { __dpmi_regs r; int seg, sel; int ret = TRUE; if (!clipboard_version) return FALSE; r.x.ax = 0x1701; __dpmi_int(0x2F, &r); if (!r.x.ax) return FALSE; r.x.ax = 0x1702; __dpmi_int(0x2F, &r); seg = __dpmi_allocate_dos_memory((size+15)>>4, &sel); if (seg < 0) { ret = FALSE; } else { dosmemput(data, size, seg*16); r.x.ax = 0x1703; r.x.dx = 1; r.x.es = seg; r.x.bx = 0; r.x.si = size>>16; r.x.cx = size&0xFFFF; __dpmi_int(0x2F, &r); if (!r.x.ax) ret = FALSE; __dpmi_free_dos_memory(sel); } r.x.ax = 0x1708; __dpmi_int(0x2F, &r); return ret; }
char *get_clipboard_data(int *size) { __dpmi_regs r; int seg, sel; void *ret = NULL; if (!clipboard_version) return FALSE; r.x.ax = 0x1701; __dpmi_int(0x2F, &r); if (!r.x.ax) return NULL; r.x.ax = 0x1704; r.x.dx = 1; __dpmi_int(0x2F, &r); *size = (r.x.dx<<16) | r.x.ax; if (*size > 0) { seg = __dpmi_allocate_dos_memory((*size+15)>>4, &sel); if (seg > 0) { r.x.ax = 0x1705; r.x.dx = 1; r.x.es = seg; r.x.bx = 0; __dpmi_int(0x2F, &r); if (r.x.ax) { ret = malloc(*size); if (ret) dosmemget(seg*16, *size, ret); } __dpmi_free_dos_memory(sel); } }
dma_buffer *dma_allocate(unsigned int channel, unsigned int size) { int parsize = (size + 15) >> 4; /* size in paragraphs */ int par = 0; /* Real-mode paragraph */ int selector = 0; /* Protected-mode selector */ int mask = channel <= 3 ? 0xfff : 0x1fff; /* Alignment mask in para. */ int allocsize = parsize; /* Allocated size in paragraphs */ int count; /* Try count */ int bound = 0; /* Nearest bound address */ int maxsize; /* Maximal possible block size */ dma_buffer *buffer = NULL; __dpmi_meminfo buff_info, struct_info; if (!dma_initialize()) return NULL; /* Loop until we'll get a properly aligned memory block */ for (count = 8; count; count--) { int resize = (selector != 0); /* Try first to resize (possibly previously) allocated block */ if (resize) { maxsize = (bound + parsize) - par; if (maxsize > parsize * 2) maxsize = parsize * 2; if (maxsize == allocsize) resize = 0; else { allocsize = maxsize; /* BUG WARNING: there is an error in dpmi.h DJGPP 2.01 library: the order of "selector" and "alloc size" should be reversed */ if (__dpmi_resize_dos_memory(allocsize, selector, &maxsize) != 0) resize = 0; } } if (!resize) { if (selector) __dpmi_free_dos_memory(selector), selector = 0; par = __dpmi_allocate_dos_memory(allocsize, &selector); } if ((par == 0) || (par == -1)) goto exit; /* If memory block contains a properly aligned portion, quit loop */ bound = (par + mask + 1) & ~mask; if (par + parsize <= bound) break; if (bound + parsize <= par + allocsize) { par = bound; break; } } if (!count) { __dpmi_free_dos_memory(selector); goto exit; } buffer = malloc(sizeof(dma_buffer)); buffer->linear = (void *)(__djgpp_conventional_base + bound * 16); buffer->physical = bound * 16; buffer->size = parsize * 16; buffer->selector = selector; buffer->channel = channel; buff_info.address = buffer->physical; buff_info.size = buffer->size; /* Don't pay attention to return code since under plain DOS it often returns error (at least under HIMEM/CWSDPMI and EMM386/DPMI) */ __dpmi_lock_linear_region(&buff_info); /* Lock the DMA buffer control structure as well */ struct_info.address = __djgpp_base_address + (unsigned long)buffer; struct_info.size = sizeof(dma_buffer); if (__dpmi_lock_linear_region(&struct_info)) { __dpmi_unlock_linear_region(&buff_info); __dpmi_free_dos_memory(selector); free(buffer); buffer = NULL; goto exit; } exit: if (buffer) __buffer_count++; else if (--__buffer_count == 0) dma_finalize(); return buffer; }
static bool dma_Free(DMA_HANDLE_t dma_handle) { if (__dpmi_free_dos_memory(dma_handle) == -1) return false; else return true; }