/*
 * DANG_BEGIN_MODULE
 *
 *
 * DANG_END_MODULE
 *
 * DANG_BEGIN_CHANGELOG
 *
 * $Date: $
 * $Source: $
 * $Revision: $
 * $State: $
 *
 * $Log: $
 *
 * DANG_END_CHANGELOG
 */

#include "dosemu.h"
#include "env/setup.h"

extern struct video_system Video_X;

Boolean env_X_detect(void)
{
  if (config.X)
    return TRUE;
  return FALSE;
}

void env_X_phase0_init(void)
{
}

void env_X_phase1_init(void)
{
  v_printf("VID: Video set to Video_X\n");
  Video = &Video_X;

  Video->init();

  /* allocate screen buffer for non-console video compare speedup */
  prev_screen = (ushort *)malloc(co * MAX_LINES * 2);
  if (prev_screen==NULL) {
    error("could not malloc prev_screen\n");
    leavedos(99);
  }
  v_printf("SCREEN saves at: %p of %d size\n", prev_screen, co * li * 2);
/* 
 * DANG_BEGIN_REMARK
 * Here the sleeping lion will be awoken and eat much of CPU time !!!
 *
 * The result of setting VM86_SCREEN_BITMAP (at state of Linux 1.1.56):
 *   Each vm86 call will set 32 pages of video mem RD-only
 *    (there may be 1000000 per second)
 *   Write access to RD-only page results in page-fault (mm/memory.c),
 *   which will set a bit in current->screen_bitmap and calls do_wp_page()
 *   which does __get_free_page(GFP_KERNEL) but frees it immediatly, 
 *   because copy-on-write is not neccessary and sets RD/WR for the page.
 *   (this could happen 32000000 per second, if the CPU were fast enough)
 * It would be better to get the DIRTY-bit directly from the page table,
 * isn't it?  A special syscall in emumodule could do this.
 * DANG_END_REMARK
 */
#if CONFIG_VIDEO_CHECK_DIRTY
  if (!config_dualmon) {
    vm86s.flags |= VM86_SCREEN_BITMAP;
  }
#endif
  clear_screen(video_page, 7);
}

void env_X_phase1_reset(void)
{
}

void env_X_term(void)
{
}
