/* Attempts to mmap sufficient memory for the specified video mode * over the memory pointed to by vdriver_fbuf, which must be * page-aligned. Returns TRUE if successful, else FALSE. */ boolean_t vgahost_mmap_linear_fbuf (const vga_mode_t *mode) { boolean_t success_p; success_p = FALSE; /* Default */ if (mode->phys_base_addr != 0) /* do we have a linear frame buffer? */ { if (!__djgpp_map_physical_memory (vdriver_fbuf, ((mode->height * mode->row_bytes + DPMI_PAGE_SIZE - 1) & ~(DPMI_PAGE_SIZE - 1)), mode->phys_base_addr)) { success_p = TRUE; } else if (mode->screen_selector != 0 && try_to_use_fat_ds_vga_hack_p) { /* We failed to mmap it the DPMI 1.0 way, so we'll see if we * can use the fat %ds hack. */ if (__djgpp_nearptr_enable ()) { unsigned long executor_base = 0, fbuf_base = 0; if (!__dpmi_get_segment_base_address (dos_pm_ds, &executor_base) && !__dpmi_get_segment_base_address (mode->screen_selector, &fbuf_base)) { vdriver_fbuf = (uint8 *) (fbuf_base - executor_base); actually_using_fat_ds_vga_hack_p = TRUE; success_p = TRUE; } } } } if (success_p) { /* Cool beans. Note that the screen is in our address space. */ vga_screen_selector = dos_pm_ds; } return success_p; }
static void _unlock_dpmi_data(void *addr, int size) { unsigned long baseaddr; __dpmi_meminfo mem; __dpmi_get_segment_base_address(_go32_my_ds(), &baseaddr); mem.address = baseaddr + (unsigned long)addr; mem.size = size; __dpmi_unlock_linear_region(&mem); }
int emm_init(void) { /* TODO: check EMM presence */ /* allocate 1 para for page map array */ rmseg = __dpmi_allocate_dos_memory(1, &rmsel); if (rmseg == -1) return -1; __dpmi_get_segment_base_address(rmsel, &rmaddr); return 0; }
void dpmi_lock_memory (void *start, unsigned long num_bytes) { unsigned long base = 0; /* Get the linear base address. */ if (__dpmi_get_segment_base_address (dos_pm_ds, &base) != -1) { __dpmi_meminfo mem; mem.handle = 0; /* Unused */ mem.size = num_bytes; mem.address = (unsigned long) ((char *) start + base); __dpmi_lock_linear_region (&mem); } }
int uip_vgamode(void) { int depth, rate; unsigned long screenbase; for (rate = 60; rate <= 70; rate += 10) { for (depth = 15; depth <= 16; depth++) { LOG_VERBOSE(("Trying mode 640x480 depth %d rate %d", depth, rate)); set_color_depth(depth); request_refresh_rate(rate); if ((set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 480 * 2) < 0)) { LOG_VERBOSE(("Mode not supported")); continue; } if (SCREEN_W != 640 || SCREEN_H != 480) { LOG_CRITICAL(("Screen not approriate for depth %d rate %d", depth, rate)); continue; } goto WHEE; } } LOG_CRITICAL(("Failed to find suitable mode")); return 1; WHEE: uip_vga = 1; if (uip_forceredshift != -1 && uip_forcegreenshift != -1 && uip_forceblueshift != -1) { uip_uipinfo->redshift = uip_forceredshift; uip_uipinfo->greenshift = uip_forcegreenshift; uip_uipinfo->blueshift = uip_forceblueshift; } else { uip_uipinfo->redshift = ui_topbit(makecol(255, 0, 0)) - 4; uip_uipinfo->greenshift = ui_topbit(makecol(0, 255, 0)) - 4; uip_uipinfo->blueshift = ui_topbit(makecol(0, 0, 255)) - 4; } if ((uip_bank0 = create_video_bitmap(640, 480)) == NULL || (uip_bank1 = create_video_bitmap(640, 480)) == NULL) { uip_textmode(); LOG_CRITICAL(("Failed to allocate memory pages")); return 1; } if (is_linear_bitmap(uip_bank0) == 0 || is_linear_bitmap(uip_bank1) == 0 || is_video_bitmap(uip_bank0) == 0 || is_video_bitmap(uip_bank1) == 0) { uip_textmode(); LOG_CRITICAL(("Allocated bitmaps not suitable or linear addressing mode " "not supported by hardware")); return 1; } /* don't you just hate MS platforms? */ __djgpp_nearptr_enable(); __dpmi_get_segment_base_address(uip_bank0->seg, &screenbase); uip_uipinfo->screenmem0 = (uint8 *)(screenbase + uip_bank0->line[0] - __djgpp_base_address); __dpmi_get_segment_base_address(uip_bank1->seg, &screenbase); uip_uipinfo->screenmem1 = (uint8 *)(screenbase + uip_bank1->line[0] - __djgpp_base_address); uip_uipinfo->linewidth = 2 * VIRTUAL_W; /* 16 bit */ uip_displaybank(0); /* set current to 0th bank */ uip_clearscreen(); /* clear bank */ ui_setupscreen(); /* setup bank */ uip_displaybank(-1); /* toggle bank */ uip_clearscreen(); /* clear bank */ ui_setupscreen(); /* setup bank */ if (install_keyboard() == -1) { uip_textmode(); LOG_CRITICAL(("Unable to initialise keyboard")); return 1; } if (uip_bank0->y_ofs != 0 || uip_bank1->y_ofs != 480) { uip_textmode(); LOG_CRITICAL(("sorry, I don't understand this video layout")); return 1; } keyboard_lowlevel_callback = uip_keyboardhandler; uip_keypoll = keyboard_needs_poll()? 1 : 0; return 0; }