示例#1
0
文件: svga.c 项目: Pa0l0ne/Amiga360
static int enter_graphics_mode (int which)
{
    int oldmode = current_vgamode;
    vga_setmode (TEXT);
    if (vga_setmode (which) < 0) {
	sleep(1);
	vga_setmode (TEXT);
	write_log ("SVGAlib doesn't like my video mode (%d). Giving up.\n", which);
	return 0;
    }
    current_vgamode = which;

    linear_mem = 0;
    if ((modeinfo.flags & CAPABLE_LINEAR) && ! currprefs.svga_no_linear) {
	int val = vga_setlinearaddressing ();
	int new_ul = val != -1 ? !need_dither : 0;
	if (using_linear == -1)
	    using_linear = new_ul;
	else
	    if (using_linear != new_ul) {
		leave_graphics_mode ();
		write_log ("SVGAlib feeling not sure about linear modes???\n");
		abort ();
	    }
	if (val != -1) {
	    linear_mem = (char *)vga_getgraphmem ();
	    write_log ("Using linear addressing: %p.\n", linear_mem);
	}
    }

    return post_enter_graphics ();
}
示例#2
0
文件: svga.c 项目: Pa0l0ne/Amiga360
static int enter_graphics_mode_picasso (int which)
{
    int oldmode = current_vgamode;
    if (which == oldmode)
	return 1;

    vga_setmode (TEXT);
    if (vga_setmode (which) < 0) {
	sleep (1);
	vga_setmode (TEXT);
	write_log ("SVGAlib doesn't like my video mode (%d). Giving up.\n", which);
	exit (1);
    }
    current_vgamode = which;

    linear_mem = 0;
    if ((modeinfo.flags & CAPABLE_LINEAR) && ! currprefs.svga_no_linear) {
	int val = vga_setlinearaddressing ();
	if (val != -1) {
	    linear_mem = (char *)vga_getgraphmem ();
	    write_log ("Using linear addressing: %p.\n", linear_mem);
	}
    }

    keyboard_close ();
    mouse_close ();
    return post_enter_graphics ();
}
示例#3
0
void VL_Startup()
{
	myint mode;
	
	vga_init(); /* TODO: maybe move into main or such? */
	
	if (MS_CheckParm("x2")) {
		mode = G640x400x256;
		vwidth = 640;
		vheight = 400;
	} else {
		mode = G320x200x256;
		vwidth = 320;
		vheight = 200;
	}

	if (gfxbuf == NULL) 
		gfxbuf = malloc(vwidth * vheight * 1);
		
	if (vga_hasmode(mode) == 0) 
		Quit("vga_hasmode failed!");
			
	if (vga_setmode(mode) != 0)
		Quit("vga_setmode failed!");
		
	if ((mode != G320x200x256) && (vga_setlinearaddressing() == -1))
		Quit("vga_setlinearaddressing failed!");
		
 	graphmem = vga_getgraphmem();
 	
 	keyboard_init();
	keyboard_seteventhandler(keyboard_handlerx);
}
示例#4
0
void S9xGraphicsMode ()
{
    if (text_mode)
    {
	screen_width = modes [mode].width;
	screen_height = modes [mode].height;
	int ret = vga_setmode (modes [mode].mode);

	if (ret < 0)
	{
	    fprintf (stderr, "Unable to switch to requested screen mode/resolution:\n");
	    S9xExit ();
	}

	if (vga_setlinearaddressing () < 0)
	{
	    if (info->flags & EXT_INFO_AVAILABLE)
		video_page_size = info->aperture_size;
	    else
		video_page_size = 64 * 1024;
	}
	else
	    video_page_size = ~0;

	if (modes [mode].mode == G320x200x256 && screen_width == 256)
	{
	    iopl(3);
	    outRegArray (scr256x256, sizeof (scr256x256) / sizeof (Register));
	    screen_pitch = screen_width;
	}
    
	gl_setcontextvga (modes [mode].mode);
	if (keyboard_init ())
	{
	    fprintf (stdout, "Keyboard initialisation failed.\n");
	    S9xExit ();
	}
        keyboard_seteventhandler(&_S9xSVGAKeyboardHandler);
	text_mode = FALSE;
	if (DeltaScreen)
	    memset (DeltaScreen, 0xff, GFX.Pitch * IMAGE_HEIGHT);
    }
}
示例#5
0
void configure(void)
{
    int allowed[GLASTMODE + 1];

    for (;;) {
	int i;
	int m;
	for (i = G320x200x16; i <= GLASTMODE; i++) {
	    allowed[i] = 0;
	    if (vga_hasmode(i)) {
		printf("%2d  %s\n", i, vga_getmodename(i));
		allowed[i] = 1;
	    }
	}

	printf("\nWhich mode? ");
	scanf("%d", &m);
	getchar();
	printf("\n");
	if (m >= G320x200x16 && m <= GLASTMODE) {
	    VGAMODE = m;
	    if (vga_getmodeinfo(m)->bytesperpixel >= 1)
		USEGL = 1;
	    else
		USEGL = 0;
	    break;
	}
    }

    vga_setmode(VGAMODE);
#ifdef LINEAR_ADDRESSING
    vga_setlinearaddressing();
#endif
    if (USEGL) {
	gl_setcontextvga(VGAMODE);
	physicalscreen = gl_allocatecontext();
	gl_getcontext(physicalscreen);
    }
}
示例#6
0
/* This name doesn't really cover this function, since it also sets up mouse
   and keyboard. This is done over here, since on most display targets the
   mouse and keyboard can't be setup before the display has. */
int sysdep_display_driver_open(int reopen)
{
	int i;
	int best_mode = -1;
	int depth, score, best_score = 0;
	vga_modeinfo *my_modeinfo;
	unsigned char *video_start;
	static int firsttime = 1;
	
	if (reopen)
	{
	  sysdep_display_effect_close();
          if (doublebuffer_buffer)
          {
                  free(doublebuffer_buffer);
                  doublebuffer_buffer = NULL;
          }
	}

	/* Find a suitable mode, also determine the max size of the display */
	sysdep_display_properties.max_width  = 0;
	sysdep_display_properties.max_height = 0;

	for (i=1; (my_modeinfo=vga_getmodeinfo(i)); i++)
	{
		if (!vga_hasmode(i))
			continue;
			
		switch(my_modeinfo->colors)
		{
		  case 32768:
		    depth = 15;
		    break;
		  case 65536:
		    depth = 16;
		    break;
		  case 16777216:
		    depth = 24;
		    break;
		  default:
		    continue;
		}
		score = mode_match(my_modeinfo->width, my_modeinfo->height,
		  my_modeinfo->linewidth/my_modeinfo->bytesperpixel,
		  depth, my_modeinfo->bytesperpixel*8);
		if (score > best_score)
		{
			best_score = score;
			best_mode = i;
			video_modeinfo = *my_modeinfo;
		}
		/* also determine the max size of the display */
		if (my_modeinfo->width  > sysdep_display_properties.max_width)
		  sysdep_display_properties.max_width  = my_modeinfo->width;
		if (my_modeinfo->height > sysdep_display_properties.max_height)
		  sysdep_display_properties.max_height = my_modeinfo->height;

                if (firsttime)
		  fprintf(stderr, "SVGAlib: Info: Found videomode %dx%dx%d\n",
		    my_modeinfo->width, my_modeinfo->height, (depth==24)?
                    my_modeinfo->bytesperpixel*8:depth);
	}
	firsttime = 0;

	if (best_score == 0)
	{
		fprintf(stderr, "SVGAlib: Couldn't find a suitable mode\n");
		return 1;
	}

	mode_set_aspect_ratio((double)(video_modeinfo.width)/video_modeinfo.height);
        scaled_width = ((sysdep_display_params.width+3)&~3) * 
          sysdep_display_params.widthscale;
        scaled_height = sysdep_display_params.yarbsize? sysdep_display_params.yarbsize:
          sysdep_display_params.height * sysdep_display_params.heightscale;
	startx = ((video_modeinfo.width  - scaled_width ) / 2) & ~3;
	starty =  (video_modeinfo.height - scaled_height) / 2;

	fprintf(stderr, "Using video mode %dx%dx%d, starting at %dx%d\n",
			video_modeinfo.width, video_modeinfo.height, video_modeinfo.colors,
			startx, starty);

	/* fill the sysdep_display_properties struct */
	memset(&sysdep_display_properties.palette_info, 0, sizeof(struct
	  sysdep_palette_info));
	switch(video_modeinfo.colors)
	{
	  case 32768:
	    sysdep_display_properties.palette_info.red_mask   = 0x001F;
            sysdep_display_properties.palette_info.green_mask = 0x03E0;
            sysdep_display_properties.palette_info.blue_mask  = 0xEC00;
            sysdep_display_properties.palette_info.depth      = 15;
            break;
          case 65536:
            sysdep_display_properties.palette_info.red_mask   = 0xF800;
            sysdep_display_properties.palette_info.green_mask = 0x07E0;
            sysdep_display_properties.palette_info.blue_mask  = 0x001F;
            sysdep_display_properties.palette_info.depth      = 16;
            break;
          case 16777216:
            sysdep_display_properties.palette_info.red_mask   = 0xFF0000;
            sysdep_display_properties.palette_info.green_mask = 0x00FF00;
            sysdep_display_properties.palette_info.blue_mask  = 0x0000FF;
            sysdep_display_properties.palette_info.depth      = 24;
            break;
	}
        sysdep_display_properties.palette_info.bpp = 
              video_modeinfo.bytesperpixel*8;
	sysdep_display_properties.vector_renderer = NULL;

	if(best_mode != video_mode)
	{
	  vga_setmode(best_mode);
	  video_mode = best_mode;
        }

	/* do we have a linear framebuffer ? */
	i = video_modeinfo.width * video_modeinfo.height *
          video_modeinfo.bytesperpixel;
	if ((video_modeinfo.flags & IS_LINEAR) ||
	    (use_linear && (video_modeinfo.flags && CAPABLE_LINEAR) &&
             vga_setlinearaddressing() >= i))
	{
          video_mem  = vga_getgraphmem();
          video_mem += startx * video_modeinfo.bytesperpixel;
          video_mem += starty * video_modeinfo.linewidth;
          video_update_type=0;
          sysdep_display_properties.mode_info[0] |= SYSDEP_DISPLAY_DIRECT_FB;
          fprintf(stderr, "SVGAlib: Info: Using a linear framebuffer to speed up\n");
	}
	else /* use gl funcs todo the updating */
	{
	  gl_setcontextvga(best_mode);
          /* do we need to blit to a doublebuffer buffer because using
             effects, scaling etc. */
	  if (!sysdep_display_blit_dest_bitmap_equals_src_bitmap())
	  {
	    doublebuffer_buffer = malloc(scaled_width*scaled_height*
	      video_modeinfo.bytesperpixel);
            if (!doublebuffer_buffer)
            {
                    fprintf(stderr, "SVGAlib: Error: Couldn't allocate doublebuffer buffer\n");
                    return 1;
            }
	    video_update_type=2;
          }
	  else
	    video_update_type=1;
	    
          sysdep_display_properties.mode_info[0] &= ~SYSDEP_DISPLAY_DIRECT_FB;
	}

	/* clear the unused area of the screen */
        switch(video_update_type)
        {
          case 0: /* linear */
            video_start = vga_getgraphmem();

            /* top */
            memset(video_start, 0, starty*video_modeinfo.linewidth);
            /* left and right */
            for (i=starty; i<(scaled_height+starty); i++)
            {
              /* left */
              memset(video_start + i*video_modeinfo.linewidth, 0,
                startx * video_modeinfo.bytesperpixel);
              /* right */
              memset(video_start + i*video_modeinfo.linewidth +
                (startx + scaled_width) * video_modeinfo.bytesperpixel,
                0, (video_modeinfo.width - (startx + scaled_width)) *
                video_modeinfo.bytesperpixel);
	    }
	    /* bottom */
	    memset(video_start + (starty + scaled_height) *
	      video_modeinfo.linewidth, 0,
	      (video_modeinfo.height - (starty + scaled_height)) *
	      video_modeinfo.linewidth);
            break;
          case 1: /* gl bitmap equals framebuffer */
          case 2: /* gl bitmap needs conversion before it can be blitted */
            /* top */
            gl_fillbox(0, 0, video_modeinfo.width, starty, 0);
            /* left */
            gl_fillbox(0, starty, startx, scaled_height, 0);
            /* right */
            gl_fillbox(startx + scaled_width, starty,
               video_modeinfo.width - (startx + scaled_width),
               scaled_height, 0);
            /* bottom */
            gl_fillbox(0, starty + scaled_height, video_modeinfo.width,
               video_modeinfo.height - (starty + scaled_height), 0);
            break;
        }

	/* init input */
	if (!reopen)
	{
	  if(svga_input_open(NULL, NULL))
	    return 1;
        }

        /* get a blit function */
        return !(blit_func=sysdep_display_effect_open());
}
示例#7
0
static void screen(int mode)
{
  int bpp,bott,endp,linlen,i,j,bii,col,p;
  vga_modeinfo *minf;
  unsigned char *vbuf;
  int mem;
  
  if(mode == 0)
    {
      printf("Usage:lineart [mode mode ...]\n\nwhere mode is an integer.\n");
      return;
    }
  if(! vga_hasmode(mode)) {
    printf("Invalid mode %d\n",mode);
    return;
  }
  vga_setmode(mode);
  minf = vga_getmodeinfo(mode);
  if(! (minf->flags & CAPABLE_LINEAR)){
    vga_setmode(TEXT);
    printf("The mode %d is not capable of linear\n",mode);
    return;
  }
  vga_setpage(0);
  if(vga_setlinearaddressing() == -1) {
    vga_setmode(TEXT);
    printf("Could not set linear addressing for mode %d\n",mode);
    return;
  }
  bpp = minf->bytesperpixel;
  linlen = minf->width*bpp;
  bott = linlen*17;            /* pointer 17 pixels wide. */
  endp = linlen*minf->height;
  mem = minf->linewidth*minf->height;

  /* Do random pixels */
  vbuf = vga_getgraphmem();
  printf("Memory mapped to %08x. Mode = %d.\n",(int) vbuf,mode);
  memset(vbuf,0,mem);    /* Clear out 2 megabytes of memory, */
  for(i = 0;i < 100000;i++)
    {
      p = rand() % mem-2;
      *(vbuf + p) = rand() & 0xff;
      if(bpp > 1)
	*(vbuf + p + 1) = rand() & 0xff;
      if(bpp == 3) 
	*(vbuf + p + 2) = rand() & 0xff;
    }

  /* Place marker at top left and bottem right. */
  for(i = 0;i < 44;i += bpp) {
    *(vbuf + i) = 0x60;
    *(vbuf + bott + i) = 0x60;
    *(vbuf + endp - i) = 0x60;
    bii = endp -1 -bott;
    *(vbuf + bii -i) = 0x60;
    if(bpp > 1) {
      *(vbuf + i + 1) = 0x60;
      *(vbuf + i + 1 + bott) = 0x60;
      *(vbuf - i - 1 + endp) = 0x60;
      *(vbuf - i - 1 + bii) = 0x60;
    }
    if(bpp == 3) {
            *(vbuf + i + 2) = 0x60;
	    *(vbuf + i + 2 + bott) = 0x60;
	    *(vbuf - i - 2 + endp) = 0x60;
	    *(vbuf - i - 2 + bii) = 0x60;
    }
    col = (i == 0 || i >= 42)? 0x60:0;
    for(j = 1;j < 17;j++) {
      *(vbuf + i + linlen*j) = col;
      *(vbuf - i + endp -1 - linlen*j) = col;
      if(bpp > 1) {
	*(vbuf + i + 1 + linlen*j) = col;
	*(vbuf - i - 2 + endp - linlen*j) = col;
      }
      if(bpp == 3) {
	*(vbuf + i + 2 + linlen*j) = col;
	*(vbuf - i - 3 + endp - linlen*j) = col;
      }
    }
  }
  for(i = 5;i < 12;i += bpp)
    for(j = 4;j < 12;j++) {
            *(vbuf + i + linlen*j) = 0x3f;
	    *(vbuf + endp - i - bpp - linlen*j) = 0x3f;
    }
  getchar();   /* Wait for a key punch */
}
示例#8
0
SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
				int width, int height, int bpp, Uint32 flags)
{
	int mode;
	int vgamode;
	vga_modeinfo *modeinfo;
	int screenpage_len;

	/* Try to set the requested linear video mode */
	bpp = (bpp+7)/8-1;
	for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
		if ( (SDL_modelist[bpp][mode]->w == width) &&
		     (SDL_modelist[bpp][mode]->h == height) ) {
			break;
		}
	}
	if ( SDL_modelist[bpp][mode] == NULL ) {
		SDL_SetError("Couldn't find requested mode in list");
		return(NULL);
	}
	vga_setmode(SDL_vgamode[bpp][mode]);
	vga_setpage(0);

	vgamode=SDL_vgamode[bpp][mode];
	if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) {
		SDL_SetError("Unable to set linear addressing");
		return(NULL);
	}
	modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]);

	/* Update hardware acceleration info */
	SVGA_UpdateVideoInfo(this);

	/* Allocate the new pixel format for the screen */
	bpp = (bpp+1)*8;
	if ( (bpp == 16) && (modeinfo->colors == 32768) ) {
		bpp = 15;
	}
	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
		return(NULL);
	}

	/* Set up the new mode framebuffer */
	current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
	if ( bpp == 8 ) {
		/* FIXME: What about DirectColor? */
		current->flags |= SDL_HWPALETTE;
	}
	current->w = width;
	current->h = height;
	current->pitch = modeinfo->linewidth;
	current->pixels = vga_getgraphmem();

	/* set double-buffering */
	if ( flags & SDL_DOUBLEBUF )
	{
	    /* length of one screen page in bytes */
	    screenpage_len=current->h*modeinfo->linewidth;

	    /* if start address should be aligned */
	    if ( modeinfo->linewidth_unit )
	    {
		if ( screenpage_len % modeinfo->linewidth_unit )    
		{
		    screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit );
		}
	    }

	    /* if we heve enough videomemory =  ak je dost videopamete  */
	    if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) )
	    {
		current->flags |= SDL_DOUBLEBUF;
		flip_page = 0;
		flip_offset[0] = 0;
		flip_offset[1] = screenpage_len;
		flip_address[0] = vga_getgraphmem();
		flip_address[1] = flip_address[0]+screenpage_len;
		SVGA_FlipHWSurface(this,current);
	    }
	} 

	/* Set the blit function */
	this->UpdateRects = SVGA_DirectUpdate;

	/* Set up the mouse handler again (buggy SVGAlib 1.40) */
	mouse_seteventhandler(SVGA_mousecallback);

	/* We're done */
	return(current);
}
示例#9
0
int main(int argc, char *argv[])
{
    int i,j;

    if (!(argc == 2 && strcmp(argv[1], "--force") == 0))
	if (!(vga_getmodeinfo(vga_getdefaultmode())->flags & CAPABLE_LINEAR)) {
	    printf("Linear addressing not supported for this chipset.\n");
	    exit(1);
	}
    vga_init();
    vga_setmode(vga_getdefaultmode());
    vga_setpage(0);
#ifdef USE_LINEAR_ADDRESSING
    if (vga_setlinearaddressing() == -1) {
	vga_setmode(TEXT);
	printf("Could not set linear addressing.\n");
	exit(-1);
    }
#endif

    /* Should not mess with bank register after this. */

    vbuf = vga_getgraphmem();
    printf("vbuf mapped at %08lx.\n", (unsigned long) vbuf);

    getchar();

#ifdef USE_LINEAR_ADDRESSING
    memset(vbuf, 0x88, 640 * 480);
    sleep(1);

    memset(vbuf, 0, 640 * 480);
    for (i = 0; i < 100000; i++)
	*(vbuf + (rand() & 0xfffff)) = rand();
#endif

#if 0
    if (vga_getcurrentchipset() == CIRRUS)
		/* Show the bandwidth of the extended write modes of the */
		/* Cirrus chip. */
		by8test();
#endif

    getchar();
    for(i = 0;i < 44;i++){
      *(vbuf + i) = 0x1c;
      *(vbuf + 640*17 + i) = 0x1c;
      *(vbuf + 640*480 - i) = 0x1c;
      *(vbuf + 640*480 - 1 - 640*17 - i) = 0x1c;
      for(j = 1;j < 17;j++){
	*(vbuf + 640*j + i) = (i == 0 || i == 43)? 0x1c:0;
	*(vbuf + 640*480 - 1 - 640*j - i) = (i == 0 || i == 43)? 0x1c:0;
      }
    }
    for(i = 3;i < 10;i++)
      for(j = 4;j < 10;j++){
	*(vbuf + i + 640*j) = 0x3f;
	*(vbuf + 640*480 -1 -640*j - i) = 0x3f;
      }
    getchar();
    vga_setmode(TEXT);
    return 0;
}
示例#10
0
文件: gr.c 项目: Ringdingcoder/d1x
int gr_set_mode(u_int32_t mode)
{
	unsigned int w, h;
	char vgamode[16];
	vga_modeinfo *modeinfo;
	int modenum, rowsize;
	void *framebuffer;
	
#ifdef NOGRAPH
	return 0;
#endif
	if (mode<=0)
		return 0;

	w=SM_W(mode);
	h=SM_H(mode);

	gr_palette_clear();

	sprintf(vgamode, "G%dx%dx256", w, h);
	modenum = vga_getmodenumber(vgamode);	
	vga_setmode(modenum);
#ifdef SVGALIB_INPUT
	mouse_seteventhandler(mouse_handler);
#endif
	modeinfo = vga_getmodeinfo(modenum);

	if (modeinfo->flags & CAPABLE_LINEAR)
	{
		usebuffer = 0;

		vga_setlinearaddressing();

		// Set up physical screen only
		gl_setcontextvga(modenum);
		physicalscreen = gl_allocatecontext();
		gl_getcontext(physicalscreen);
		screenbuffer = physicalscreen;

		framebuffer = physicalscreen->vbuf;
		rowsize = physicalscreen->bytewidth;
	}
	else
	{
		usebuffer = 1;

		// Set up the physical screen
		gl_setcontextvga(modenum);
		physicalscreen = gl_allocatecontext();
		gl_getcontext(physicalscreen);

		// Set up the virtual screen
		gl_setcontextvgavirtual(modenum);
		screenbuffer = gl_allocatecontext();
		gl_getcontext(screenbuffer);

		framebuffer = screenbuffer->vbuf;
		rowsize = screenbuffer->bytewidth;
	}

	memset(grd_curscreen, 0, sizeof(grs_screen));
	grd_curscreen->sc_mode = mode;
	grd_curscreen->sc_w = w;
	grd_curscreen->sc_h = h;
	grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
	grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
	grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
	grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
	grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
	grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = rowsize;
	grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR;
	grd_curscreen->sc_canvas.cv_bitmap.bm_data = framebuffer;
	gr_set_current_canvas(NULL);
	
	gamefont_choose_game_font(w,h);
	
	return 0;
}
示例#11
0
文件: ifr_sgraph.c 项目: clemej/ifrac
int graph_init_video(void)
{
  int 	rc = 0;
	int   screen_colours;
	vga_modeinfo *vminfo;
	
	if (tcgetpgrp(STDIN_FILENO) != getpid())
	{	fprintf(stderr, "Sorry, this application cannot start in background\n");
		return 0;
	}

	pltf = PLTF_SVGA;

  /*-----------------------------------------------------------*/     
	/* Checking libvga version, 1.4.0 and prior will return (-1) */
	/* Currently you need IOPERM for 1.9.x to run as a non-priv  */
	/* user, however set IOPERM upsets upsets previous versions  */
  /*-----------------------------------------------------------*/     
  if (vga_setmode(-1) >= 0x1900)	setenv("IOPERM", "1", 0);  

	rc = vga_init();
	if (rc != 0)
	{ fprintf(stderr, "Can't initialise SVGA library. \n"
     		    "Possible solution: log as root, and enter:\n"
		    "\tchown 0 ifrac\n"
		    "\tchmod 4755 ifrac\n");
	  return 0;
	}	

#ifdef SVGALIB_BACKGROUND_SUPPORT
  set_background_routines();
#else
	run_background = 0;
#endif

	if (!set_video_mode())
	{  fprintf(stderr, "Sorry, unable to set video mode. \n");
      	   return 0;		
	}

	vminfo = vga_getmodeinfo(vga_getcurrentmode());
	
	WndWidth = ScrWidth = vminfo->width;
	WndHeight = ScrHeight = vminfo->height;

	screen_colours = vminfo->colors;
	if (screen_colours < 16)
	{	fprintf (stderr,
		   "This application requires at least 16-colour mode\n");
		return 0;
	}	 

	ScrDepth = 0;
	while((screen_colours>>=1) != 0) ScrDepth++;

	if (ScrDepth <= 8)
	{  BytesPerPixel = 1;
	   stored_colours = 1;
	}
	else
	{  BytesPerPixel = vminfo->bytesperpixel;
	   stored_colours = 0;
	}
	
	scan_line_width = vminfo->linewidth;
	screen_size = scan_line_width * ScrHeight;

	if (ScrDepth < 8) 
		DirVideo = 0;
	else {
		vga_setpage(screen_page=0);

		if (DirVideo == 2 && (vminfo->flags & CAPABLE_LINEAR)) 
			lbuf_len = vga_setlinearaddressing();
	
		if (DirVideo > 0) 
			lbuf_addr = vga_getgraphmem();
	}
	
	return  1;
}