Exemple #1
0
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 ();
}
Exemple #2
0
void I_FinishUpdate(void)
{
	static int		lasttic;
	int				tics;
	int				i;

	// draws little dots on the bottom of the screen, a simple fps meter
	if (devparm)
	{
		i = I_GetTime();
		tics = i - lasttic;
		lasttic = i;
		if (tics > 20)
			tics = 20;

		for (i = 0; i < tics * 2; i += 2)
			screens[0][(SCREENHEIGHT - 2) * SCREENWIDTH + i + 3] = 0xff;
		for (; i < 20 * 2; i += 2)
			screens[0][(SCREENHEIGHT - 2) * SCREENWIDTH + i + 3] = 0x0;
	}

	// blit frame
	memcpy(vga_getgraphmem(), screens[0], SCREENWIDTH * SCREENHEIGHT);

	// sleep a bit if there was no sound update
	if (!snd_updated)
	{
		I_WaitVBL(1);
	}
}
Exemple #3
0
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 ();
}
Exemple #4
0
//! [1]
bool SvgalibScreen::initDevice()
{
    if (vga_init() != 0) {
        qCritical("SvgalibScreen::initDevice(): unable to initialize svgalib");
        return false;
    }

    int mode = vga_getdefaultmode();
    if (vga_setmode(mode) == -1) {
        qCritical("SvgalibScreen::initialize(): unable to set graphics mode");
        return false;
    }

    if (gl_setcontextvga(mode) != 0) {
        qCritical("SvgalibScreen::initDevice(): unable to set vga context");
        return false;
    }
    context = gl_allocatecontext();
    gl_getcontext(context);

    vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
    if (modeinfo->flags & IS_LINEAR)
        QScreen::data = vga_getgraphmem();

    initColorMap();

    QScreenCursor::initSoftwareCursor();
    return true;
}
Exemple #5
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);
}
Exemple #6
0
void blit(void)
{
    gl_clearscreen(0x86);
    vga_imageblt(vga_getgraphmem(), 0, WIDTH - 128, HEIGHT - 128,
		 WIDTH * BYTESPERPIXEL);
/*      vga_bitblt(0, 100 * WIDTH * BYTESPERPIXEL, 50, 50, WIDTH * BYTESPERPIXEL);
   vga_fillblt(100 * BYTESPERPIXEL, 50, 50, WIDTH * BYTESPERPIXEL, 0x86);
 */
}
Exemple #7
0
/*
** SWimp_InitGraphics
**
** This initializes the software refresh's implementation specific
** graphics subsystem.  In the case of Windows it creates DIB or
** DDRAW surfaces.
**
** The necessary width and height parameters are grabbed from
** vid.width and vid.height.
*/
static qboolean SWimp_InitGraphics( qboolean fullscreen )
{
	int bsize, zsize, tsize;

	SWimp_Shutdown();

	current_mode = get_mode(vid.width, vid.height);

	if (current_mode < 0) {
		ri.Con_Printf (PRINT_ALL, "Mode %d %d not found\n", vid.width, vid.height);
		return false; // mode not found
	}

	// let the sound and input subsystems know about the new window
	ri.Vid_NewWindow (vid.width, vid.height);

	ri.Con_Printf (PRINT_ALL, "Setting VGAMode: %d\n", current_mode );

//	Cvar_SetValue ("vid_mode", (float)modenum);
	
	VGA_width = modes[current_mode].width;
	VGA_height = modes[current_mode].height;
	VGA_planar = modes[current_mode].bytesperpixel == 0;
	VGA_rowbytes = modes[current_mode].linewidth;

	vid.rowbytes = modes[current_mode].linewidth;

	if (VGA_planar) {
		VGA_bufferrowbytes = modes[current_mode].linewidth * 4;
		vid.rowbytes = modes[current_mode].linewidth*4;
	}

// get goin'

	vga_setmode(current_mode);

	VGA_pagebase = framebuffer_ptr = (char *) vga_getgraphmem();
//		if (vga_setlinearaddressing()>0)
//			framebuffer_ptr = (char *) vga_getgraphmem();
	if (!framebuffer_ptr)
		Sys_Error("This mode isn't hapnin'\n");

	vga_setpage(0);

	vid.buffer = malloc(vid.rowbytes * vid.height);
	if (!vid.buffer)
		Sys_Error("Unabled to alloc vid.buffer!\n");

	return true;
}
Exemple #8
0
short InitGraph(short mode=SVGA256_320x200)
{   if(fVGA) return 0;
    fVGA=1;
    SetVideoMode(mode);
    if(mode==SVGA256_320x200)
    {
        int j=0;
        for(long i=0; i<64000L; i+=320) s320[j++]=i;
        VideoMem = vga_getgraphmem();
    }
    else
        VideoMem = NULL;
    return 1;
}
Exemple #9
0
static int init_vidmode ()
{
	int err, i;

	fprintf (stderr, "svgalib: SVGAlib support by XoXus\n");

	err = vga_init ();
	if (err) {
		fprintf (stderr, "svgalib: can't initialize svgalib\n");
		return err_Unk;
	}
	err = vga_hasmode (G320x200x256);
	if (err == 0) {
		fprintf (stderr,
			"svgalib: video mode unavailable (320x200x256)\n");
		return err_Unk;
	}

	vga_setmode (G320x200x256);
	svgalib_framebuffer = vga_getgraphmem ();

	/* Set up EGA colors */
	for (i = 0; i < 32; i++) {
		vga_setpalette (i, palette[i * 3],
			palette[i * 3 + 1], palette[i * 3 + 2]);
	}

	/* Allocate framebuffer */
	video_buffer = (UINT8 *) malloc (320 * 200);
	if (!video_buffer) {
		fprintf (stderr, "svgalib: can't alloc framebuffer\n");
		deinit_vidmode ();
		return err_Unk;
	}

	/* XoXus: This is a semantics issue, but the keyboard init
	 *		probably shouldn't be done in 'init_vidmode'
	 */
	err = svgalib_key_init ();
	if (err != err_OK) {
		deinit_vidmode ();
		return err_Unk;
	}

	return err_OK;
}
/* 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());
}
Exemple #11
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 */
}
Exemple #12
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);
}
Exemple #13
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;
}
Exemple #14
0
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;
}