Ejemplo n.º 1
0
//
// This function is called to init the video driver for specific mode
//
static int config(uint32_t width, uint32_t height, uint32_t d_width,
                  uint32_t d_height, uint32_t flags, char *title,
                  uint32_t format) {
    int32_t req_w = width;// (d_width > 0 ? d_width : width);
    int32_t req_h = height;// (d_height > 0 ? d_height : height);
    uint16_t vid_mode = 0;
    int32_t req_bpp;

    uint32_t accflags;
    mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
           d_width, d_height, flags, title, format);
//Only RGB modes supported
    if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {
        assert(0);
        return -1;
    }
    req_bpp = IMGFMT_BGR_DEPTH(format);

    if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {
        assert(0);
        return-1;
    }

    if(!force_vm) {
        mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
        mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
        vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
        if(vid_mode==0)
            return 1;
        modeinfo=vga_getmodeinfo(vid_mode);
    } else { //force_vm
        vid_mode=force_vm;
        if(vga_hasmode(vid_mode) == 0) {
            mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable,
                   vid_mode,vga_getmodename(vid_mode));
            return 1; //error;
        }
        modeinfo=vga_getmodeinfo(vid_mode);
        if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ) {
            mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall,
                   vid_mode,vga_getmodename(vid_mode));
            return 1;
        }
    }
    mode_bpp=bpp_from_vminfo(modeinfo);

    mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_Vidmode,
           vid_mode,modeinfo->width,modeinfo->height,mode_bpp);

    if (vga_setmode(vid_mode) == -1) {
        mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_VgasetmodeFailed,vid_mode);
        uninit();
        return 1; // error
    }
    /* set 332 palette for 8 bpp */
    if(mode_bpp==8) {
        int i;
        for(i=0; i<256; i++)
            vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
    }
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    vga_init();
    
    if(argc>=2) {
        timescale=atoi(argv[1]);
        if(timescale<1)timescale=1;
    }

    VGAMODE = vga_getdefaultmode();
    if (VGAMODE == -1)
	VGAMODE = G320x200x256;	/* Default mode. */

    if (!vga_hasmode(VGAMODE)) {
	printf("Mode not available.\n");
	exit(-1);
    }
    VIRTUAL = 0;		/* No virtual screen. */
    if (vga_getmodeinfo(VGAMODE)->colors == 16 ||
	(vga_getmodeinfo(VGAMODE)->flags & IS_MODEX))
	/* These modes are supported indirectly by vgagl. */
	VIRTUAL = 1;

    if (VIRTUAL) {
	/* Create virtual screen. */
	gl_setcontextvgavirtual(VGAMODE);
	backscreen = gl_allocatecontext();
	gl_getcontext(backscreen);
    }
    vga_setmode(VGAMODE);
    gl_setcontextvga(VGAMODE);	/* Physical screen context. */
    physicalscreen = gl_allocatecontext();
    gl_getcontext(physicalscreen);
    if (COLORS == 256)
	gl_setrgbpalette();

	if(argc==3)sleep(2);

    test();

    /* Now do the same with clipping enabled. */
    gl_clearscreen(0);
    gl_setclippingwindow(WIDTH / 4, HEIGHT / 4, WIDTH - WIDTH / 4 - 1,
			 HEIGHT - HEIGHT / 4 - 1);

    test();

    gl_disableclipping();
    if (COLORS == 256)
	/* Show the logo if using 256 color mode. */
	logotest();

    getchar();

    if (VIRTUAL)
	gl_freecontext(backscreen);
    vga_setmode(TEXT);
    exit(0);
}
Ejemplo n.º 3
0
d_rasterdescription_t *d_raster_getmodes(int *nmodes)
{
    d_rasterdescription_t *modes;
    vga_modeinfo *minf;
    int i;

    modes = NULL;
    *nmodes = 0;

    for(i = 1; i < vga_lastmodenumber(); i++) {
        if(vga_hasmode(i) == 0) continue;

        (*nmodes)++;
        modes = d_memory_resize(modes, *nmodes*sizeof(d_rasterdescription_t));
        if(modes == NULL) {
            d_error_push("d_raster_getmodes: d_memory_resize failed.");
            return NULL;
        }
        
        minf = vga_getmodeinfo(i);
        modes[*nmodes-1].w = minf->width;
        modes[*nmodes-1].h = minf->height;
        modes[*nmodes-1].bpp = log2(minf->colors);
        modes[*nmodes-1].alpha = 0;
        if(modes[*nmodes-1].bpp == 8)
            modes[*nmodes-1].paletted = true;
        else
            modes[*nmodes-1].paletted = false;
        modes[*nmodes-1].cspace = RGB;
    }
    return modes;
}
Ejemplo n.º 4
0
static int
SVGA_open(PSD psd)
{
	int		mode;
	vga_modeinfo *	modeinfo;

	vga_init();
	//mode = G640x480x256;
	mode = G640x480x16;
	vga_setmode(mode);
	modeinfo = vga_getmodeinfo(mode);

	psd->xres = modeinfo->width;
	psd->yres = modeinfo->height;
	psd->linelen = modeinfo->linewidth;
	psd->planes = 1;
	psd->bpp = modeinfo->bytesperpixel;	// FIXME??
	psd->ncolors = modeinfo->colors;
	psd->flags = PSF_SCREEN;
	psd->addr = 0;		// FIXME

	/* note: must change psd->pixtype here for truecolor systems*/
	psd->pixtype = PF_PALETTE;
	return 1;
}
Ejemplo n.º 5
0
int ui_init(int *fd_keyboard, int *fd_mouse)
{
    int dac_shift, i, mouse_type, force_red;
    
    if (vga_init() == 0)
    {
        old_mode = vga_getcurrentmode();
        vga_setmode(G640x480x256);
        /*vga_setlinearaddressing();*/
        if (vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_FLAGS) & VGA_CLUT8)
        {
            vga_ext_set(VGA_EXT_SET, VGA_CLUT8);
            dac_shift = 0;
        }
        else
            dac_shift = 2;
        force_red = 0xFF;
        for (i = 0; i < 255; i++)
            vga_setpalette(i,
                           i >> dac_shift,
                           (i & force_red) >> dac_shift,
                           (i & force_red) >> dac_shift);
        vga_setpalette(UI_LO_COLOR, 127 >> dac_shift, 0, 0); /* Save dim    red for UI */
        vga_setpalette(UI_HI_COLOR, 255 >> dac_shift, 0, 0); /* Save bright red for UI */
        vga = vga_getmodeinfo(vga_getcurrentmode());
    }
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
void VID_InitModes(void)
{

int i;

	// get complete information on all modes

	num_modes = vga_lastmodenumber()+1;
	modes = malloc(num_modes * sizeof(vga_modeinfo));
	for (i=0 ; i<num_modes ; i++)
	{
		if (vga_hasmode(i))
			memcpy(&modes[i], vga_getmodeinfo(i), sizeof (vga_modeinfo));
		else
			modes[i].width = 0; // means not available
	}

	// filter for modes i don't support

	for (i=0 ; i<num_modes ; i++)
	{
		if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) 
			modes[i].width = 0;
	}

	for (i = 0; i < num_modes; i++)
		if (modes[i].width)
			ri.Con_Printf(PRINT_ALL, "mode %d: %d %d\n", modes[i].width, modes[i].height);

}
Ejemplo n.º 8
0
static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
 int badness,prev_badness;
 int bestmode,lastmode;
 int i;
 vga_modeinfo *vminfo;
//int best aspect mode // best linear mode // best normal mode (no modeX)

  prev_badness = 0;//take care of special case below
  bestmode = 0; //0 is the TEXT mode
  lastmode = vga_lastmodenumber();
  for(i=1;i<=lastmode;i++){
    vminfo = vga_getmodeinfo(i);
    if( vminfo == NULL ) continue;
    if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
      mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
    if( vga_hasmode(i) == 0 ) continue;
    if( req_bpp != bpp_from_vminfo(vminfo) )continue;
    if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
    badness=(vminfo->width * vminfo->height) - (req_h * req_w);
    //put here aspect calculations
    if(squarepix) 
      if( vminfo->width*3 != vminfo->height*4 ) continue;

    if( bestmode==0 || prev_badness >= badness ){//modeX etc...
      prev_badness=badness;
      bestmode=i;
      if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
        mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
    }
  }
  return bestmode;
}
Ejemplo n.º 9
0
void gfx_set_picasso_modeinfo (uae_u32 w, uae_u32 h, uae_u32 depth, int rgbfmt)
{
    vga_modeinfo *info;
    int i, mode;

    for (i = 0; i < MAX_SCREEN_MODES; i++)
	if (x_size_table[i] == w && y_size_table[i] == h)
	    break;
    printf ("::: %d %d %d, %d\n", w, h, depth, i);
    if (i == MAX_SCREEN_MODES)
	abort ();
    mode = (depth == 8 ? vga_mode_table[i][0]
	    : depth == 16 ? vga_mode_table[i][2]
	    : depth == 32 ? vga_mode_table[i][5]
	    : -1);
    printf ("::: %d\n", mode);
    if (mode == -1)
	abort ();

    info = vga_getmodeinfo (mode);
    printf ("::: %d\n", info->linewidth);
    picasso_vgamode = mode;
    picasso_vidinfo.width = w;
    picasso_vidinfo.height = h;
    picasso_vidinfo.depth = depth;
    picasso_vidinfo.pixbytes = depth>>3;
    picasso_vidinfo.rowbytes = info->linewidth;
    picasso_vidinfo.rgbformat = (depth == 8 ? RGBFB_CHUNKY
				 : depth == 16 ? RGBFB_R5G6B5PC
				 : RGBFB_B8G8R8A8);
    if (screen_is_picasso)
	set_window_for_picasso ();
}
Ejemplo n.º 10
0
static void SVGA_UpdateVideoInfo(_THIS)
{
	vga_modeinfo *modeinfo;

	this->info.wm_available = 0;
	this->info.hw_available = 1;
	modeinfo = vga_getmodeinfo(vga_getcurrentmode());
	this->info.video_mem = modeinfo->memory;
	/* FIXME: Add hardware accelerated blit information */
#ifdef SVGALIB_DEBUG
	printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not ");
#endif
}
Ejemplo n.º 11
0
void
find_mode( int exact )
{
  vga_modeinfo *inf;
  int i, j, w, h;

  for( i = 0; i <= vga_lastmodenumber(); i++ ) {
    if( vga_hasmode( i ) ) {
      inf = vga_getmodeinfo( i );
      if( inf->colors >= 16 && !( inf->flags & IS_MODEX ) &&
    	    inf->width >= 320 && inf->height >= 240 &&
		inf->width <= 1280 && inf->height <= 1024 ) {
	/* try exact match */
	for( j = 0; j < 3; j++ ) {
	  w = DISPLAY_ASPECT_WIDTH * ( j + 1 );
	  h = DISPLAY_SCREEN_HEIGHT * ( j + 1 );
	  if( exact == 0 && inf->width == w && inf->height == h &&
	    ( modes[j].n == -1 ||
		( ( modes[j].width != w || modes[j].height != h ||
		    modes[j].depth != 16 ) && (
			inf->colors == 65536 || 
			    inf->colors > modes[j].colors ) ) ) ) {
	    set_mode( j, i, inf );
	  }

	  if( exact == 1 && inf->width >= w && inf->height >= h &&
		inf->width < w * 5 / 4 && inf->height < h * 5 / 4 &&
	    ( modes[j].n == -1 ||
		( ( modes[j].width > inf->width ||
			     modes[j].height > inf->height ||
		    modes[j].depth != 16 ) && (
			inf->colors == 65536 || 
			    inf->colors > modes[j].colors ) ) ) ) {
	    set_mode( j, i, inf );
	  }

	  if( exact == -1 && inf->width <= w && inf->height <= h &&
		inf->width > w * 3 / 4 && inf->height > h * 3 / 4 &&
	    ( modes[j].n == -1 ||
		( ( modes[j].width < inf->width ||
			     modes[j].height < inf->height ||
		    modes[j].depth != 16 ) && (
			inf->colors == 65536 || 
			    inf->colors > modes[j].colors ) ) ) ) {
	    set_mode( j, i, inf );
	  }
	}
      }
    }
  }
}
Ejemplo n.º 12
0
static int SVGA_AddMode(_THIS, int mode, int actually_add, int force)
{
	vga_modeinfo *modeinfo;

	modeinfo = vga_getmodeinfo(mode);
	if ( force || ( modeinfo->flags & CAPABLE_LINEAR ) ) {
		int i, j;

		i = modeinfo->bytesperpixel-1;
		if ( actually_add ) {
			SDL_Rect saved_rect[2];
			int      saved_mode[2];
			int b;

			/* Add the mode, sorted largest to smallest */
			b = 0;
			j = 0;
			while ( (SDL_modelist[i][j]->w > modeinfo->width) ||
			        (SDL_modelist[i][j]->h > modeinfo->height) ) {
				++j;
			}
			/* Skip modes that are already in our list */
			if ( (SDL_modelist[i][j]->w == modeinfo->width) &&
			     (SDL_modelist[i][j]->h == modeinfo->height) ) {
				return(0);
			}
			/* Insert the new mode */
			saved_rect[b] = *SDL_modelist[i][j];
			saved_mode[b] = SDL_vgamode[i][j];
			SDL_modelist[i][j]->w = modeinfo->width;
			SDL_modelist[i][j]->h = modeinfo->height;
			SDL_vgamode[i][j] = mode;
			/* Everybody scoot down! */
			if ( saved_rect[b].w && saved_rect[b].h ) {
			    for ( ++j; SDL_modelist[i][j]->w; ++j ) {
				saved_rect[!b] = *SDL_modelist[i][j];
				saved_mode[!b] = SDL_vgamode[i][j];
				*SDL_modelist[i][j] = saved_rect[b];
				SDL_vgamode[i][j] = saved_mode[b];
				b = !b;
			    }
			    *SDL_modelist[i][j] = saved_rect[b];
			    SDL_vgamode[i][j] = saved_mode[b];
			}
		} else {
			++SDL_nummodes[i];
		}
	}
	return( force || ( modeinfo->flags & CAPABLE_LINEAR ) );
}
Ejemplo n.º 13
0
void SetVideoMode(short mode)
{   _mode_ = mode;
    vga_init ();
    if (!(vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_SET) & (1 << VGA_EXT_PAGE_OFFSET))) {
        puts("You need at least svgalib 1.2.10 to run this program!\n");
        exit(1);
    }
    if (!vga_hasmode (_mode_)) {
        fprintf (stderr, "Mode not available.\n");
        exit (-1);
    }
    vga_setmode (_mode_);
    _ginfo_ = vga_getmodeinfo (_mode_);
    dX = _ginfo_->width;
    dY = _ginfo_->height;
}
Ejemplo n.º 14
0
//! [0]
bool SvgalibScreen::connect(const QString &displaySpec)
{
    int mode = vga_getdefaultmode();
    if (mode <= 0) {
        qCritical("SvgalibScreen::connect(): invalid vga mode");
        return false;
    }

    vga_modeinfo *modeinfo = vga_getmodeinfo(mode);

    QScreen::lstep = modeinfo->linewidth;
    QScreen::dw = QScreen::w = modeinfo->width;
    QScreen::dh = QScreen::h = modeinfo->height;
    QScreen::d = getModeDepth(modeinfo);
    QScreen::size = QScreen::lstep * dh;
    QScreen::data = 0;

    switch (depth()) {
    case 32:
        setPixelFormat(QImage::Format_ARGB32_Premultiplied);
        break;
    case 24:
        setPixelFormat(QImage::Format_RGB888);
        break;
    case 16:
        setPixelFormat(QImage::Format_RGB16);
        break;
    case 15:
        setPixelFormat(QImage::Format_RGB555);
        break;
    default:
        break;
    }

    const int dpi = 72;
    QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
    QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);

    const QStringList args = displaySpec.split(QLatin1Char(':'),
                                               QString::SkipEmptyParts);
    grayscale = args.contains(QLatin1String("grayscale"), Qt::CaseInsensitive);

    return true;
}
Ejemplo n.º 15
0
bool d_raster_setmode(d_rasterdescription_t mode)
{
    vga_modeinfo *minf;
    int i, ret;

    if(mode.cspace == grayscale) {
        d_error_push(__FUNCTION__": grayscale modes are not supported "
                     "with this driver.");
        return failure;
    }

    for(i = 1; i < vga_lastmodenumber(); i++) {
        if(vga_hasmode(i) == 0) continue;
        
        minf = vga_getmodeinfo(i);
        if(minf->width         == mode.w   &&
           minf->height        == mode.h   &&
           minf->colors        == 1<<mode.bpp) {
            
            ret = vga_setmode(i);
            if(ret != 0) {
                d_error_push(__FUNCTION__": vga_setmode failed.");
                return failure;
            }

            raster_curmode = mode;
            
            if(raster_vbuf != NULL)
                d_memory_delete(raster_vbuf);

            raster_vbuf = d_memory_new((mode.w*mode.h*mode.bpp+7)/8);
            if(raster_vbuf == NULL) {
                d_error_push(__FUNCTION__": memory allocation failed for "
                             "raster_vbuf.");
                return failure;
            }

            return success;
        }
    }
    d_error_push(__FUNCTION__": no such mode available.");
    return failure;
}
Ejemplo n.º 16
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);
    }
}
Ejemplo n.º 17
0
static void VID_InitModes (void)
{
	int	i;

/* get complete information on all modes */
	num_modes = vga_lastmodenumber() + 1;
	modes = (vga_modeinfo *) Z_Malloc(num_modes * sizeof(vga_modeinfo), Z_MAINZONE);
	for (i = 0; i < num_modes; i++)
	{
		if (vga_hasmode(i))
			memcpy(&modes[i], vga_getmodeinfo(i), sizeof(vga_modeinfo));
		else
			modes[i].width = 0;	/* means not available */
	}

/* filter for modes i don't support */
	for (i = 0; i < num_modes; i++)
	{
		if (modes[i].bytesperpixel != 1 && modes[i].colors != 256)
			modes[i].width = 0;
	}
}
Ejemplo n.º 18
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);
}
Ejemplo n.º 19
0
int graphics_init (void)
{
    int i;
    need_dither = 0;
    screen_is_picasso = 0;

    if (!select_mode_from_prefs ())
	return 0;

    bitdepth = mode_bitdepth[currprefs.color_mode][0];
    bit_unit = mode_bitdepth[currprefs.color_mode][1];
    need_dither = mode_bitdepth[currprefs.color_mode][2];

    modeinfo = *vga_getmodeinfo (vgamode);

    gfxvidinfo.pixbytes = modeinfo.bytesperpixel;
    if (!need_dither) {
	if (modeinfo.bytesperpixel == 0) {
	    printf("Got a bogus value from SVGAlib...\n");
	    gfxvidinfo.pixbytes = 1;
	}
    } else {
	gfxvidinfo.pixbytes = 2;
    }

    using_linear = -1;

    if (!enter_graphics_mode (vgamode))
	return 0;

    sleep(2);
    gfxvidinfo.maxblocklines = 0;

    gfxvidinfo.width = modeinfo.width;
    gfxvidinfo.height = modeinfo.height;

    if (linear_mem != NULL && !need_dither) {
	gfxvidinfo.bufmem = linear_mem;
	gfxvidinfo.rowbytes = modeinfo.linewidth;
    } else {
	gfxvidinfo.rowbytes = (modeinfo.width * gfxvidinfo.pixbytes + 3) & ~3;
#if 1
	gfxvidinfo.bufmem = malloc (gfxvidinfo.rowbytes);
	gfxvidinfo.linemem = gfxvidinfo.bufmem;
	memset (gfxvidinfo.bufmem, 0, gfxvidinfo.rowbytes);
#else
	gfxvidinfo.bufmem = malloc(gfxvidinfo.rowbytes * modeinfo.height);
	memset (gfxvidinfo.bufmem, 0, gfxvidinfo.rowbytes * modeinfo.height);
#endif
	gfxvidinfo.emergmem = 0;
    }
    printf ("rowbytes %d\n", gfxvidinfo.rowbytes);
    init_colors ();
    buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
    for(i = 0; i < 256; i++)
	keystate[i] = 0;

    lastmx = lastmy = 0;
    newmousecounters = 0;

    return 1;
}
Ejemplo n.º 20
0
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;
}
Ejemplo n.º 21
0
void S9xInitDisplay (int /*argc*/, char ** /*argv*/)
{
    if (vga_init() < 0)
    {
	fprintf (stdout, "Unable to initialise vga.\n");
	S9xExit ();
    }
    S9xTextMode ();

    if (mode < 0)
    {
	if (Settings.SixteenBit)
	    mode = 6;
	else
	    mode = 2;
    }
    info = vga_getmodeinfo (modes [mode].mode);
    if (info->flags & IS_MODEX)
	planar = 1;

    if (info->flags & CAPABLE_LINEAR)
	video_page_size = ~0;
    else
    if (info->flags & EXT_INFO_AVAILABLE)
	video_page_size = info->aperture_size;
    else
	video_page_size = 64 * 1024;

    if (!screen_pitch)
	screen_pitch = info->linewidth;
	
    if (info->bytesperpixel > 1)
    {
	Settings.Transparency = TRUE;
	Settings.SixteenBit = TRUE;
    }
    else
    {
	Settings.Transparency = FALSE;
	Settings.SixteenBit = FALSE;
    }

    if (info->width >= 512 && info->height >= 578)
	Settings.SupportHiRes = TRUE;

    if (!Settings.SixteenBit || info->width < 512 || info->height < 240)
	interpolation = FALSE;

    if (interpolation)
    {
	GFX.Pitch = (IMAGE_WIDTH + 2) * 2;
	GFX.Screen = (uint8 *) malloc (GFX.Pitch * IMAGE_HEIGHT);
	GFX.SubScreen = (uint8 *) malloc (GFX.Pitch * IMAGE_HEIGHT);
	DeltaScreen = (uint8 *) malloc (GFX.Pitch * IMAGE_HEIGHT);
	GFX.ZBuffer = (uint8 *) malloc ((GFX.Pitch >> 1) * IMAGE_HEIGHT);
	GFX.SubZBuffer = (uint8 *) malloc ((GFX.Pitch >> 1) * IMAGE_HEIGHT);

	if (!GFX.Screen || !GFX.SubScreen || !DeltaScreen || 
	    !GFX.ZBuffer || !GFX.SubZBuffer)
	{
	    fprintf (stdout, "Cannot allocate screen buffer.\n");
	    S9xExit ();
	}
    }
    else
    if (Settings.SixteenBit)
Ejemplo n.º 22
0
void main(void)
{
    int vgamode, color, leftpressed;
    int x, y;
    vga_init();
    vgamode = vga_getdefaultmode();
    if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1))
        vgamode = G320x200x256;

    if (!vga_hasmode(vgamode)) {
        printf("Mode not available.\n");
        exit(1);
    }
    printf("\nWARNING: This program will set the keyboard to RAW mode.\n"
           "The keyboard routines in svgalib have not been tested\n"
           "very much. There may be no recovery if something goes\n"
           "wrong.\n\n"
           "Press ctrl-c now to bail out, enter to continue.\n"
           "In the test itself, use 'q' or Escape to quit.\n"
           "It will also terminate after 60 seconds.\n"
           "Use any cursor keys to move, keypad 0 or enter to change color.\n");

    getchar();

    vga_setmode(vgamode);
    gl_setcontextvga(vgamode);
    gl_enableclipping();

    signal(SIGALRM, timeout);

    /* This installs the default handler, which is good enough for most */
    /* purposes. */
    if (keyboard_init()) {
        printf("Could not initialize keyboard.\n");
        exit(1);
    }
    /* Translate to 4 keypad cursor keys, and unify enter key. */
    keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER |
                           TRANSLATE_DIAGONAL);
    /* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't...
       but might not do what you expect.. */

    alarm(60);			/* Terminate after 60 seconds for safety. */

    x = WIDTH / 2;
    y = HEIGHT / 2;
    color = newcolor();
    leftpressed = 0;
    for (;;) {
        /* Draw moving box. */
        gl_fillbox(x, y, 5, 5, color);

        /* Draw key status bar at top of screen. */
        gl_putbox(0, 0, 128, 1, keyboard_getstate());

        /* Wait about 1/100th of a second. */
        /* Note that use of this function makes things less */
        /* smooth because of timer latency. */
        usleep(10000);

        keyboard_update();

        /* Move. */
        if (keyboard_keypressed(SCANCODE_CURSORLEFT))
            x--;
        if (keyboard_keypressed(SCANCODE_CURSORRIGHT))
            x++;
        if (keyboard_keypressed(SCANCODE_CURSORUP))
            y--;
        if (keyboard_keypressed(SCANCODE_CURSORDOWN))
            y++;

        /* Boundary checks. */
        if (x < 0)
            x = 0;
        if (x >= WIDTH)
            x = WIDTH - 1;
        if (y < 1)
            y = 1;
        if (y >= HEIGHT)
            y = HEIGHT - 1;

        /* Check for color change. */
        if (keyboard_keypressed(SCANCODE_KEYPAD0) ||
                keyboard_keypressed(SCANCODE_ENTER)) {
            if (!leftpressed) {
                color = newcolor();
                leftpressed = 1;
            }
        } else
            leftpressed = 0;

        if (keyboard_keypressed(SCANCODE_Q) ||
                keyboard_keypressed(SCANCODE_ESCAPE))
            break;
    }

    keyboard_close();		/* Don't forget this! */
    vga_setmode(TEXT);
    exit(0);
}
Ejemplo n.º 23
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());
}
Ejemplo n.º 24
0
int main(int argc, char *argv[])
{
    int mode, mode2;
    int i, high;

    vga_init();			/* Initialize. */

    mode = -1;
    mode2= -1;

    if(argc==2) {
        mode = atoi(argv[1]);
    } else if(argc==3) {
        mode = atoi(argv[1]);
        mode2= atoi(argv[2]);
    }


    if (mode == -1) {
        printf("Choose one of the following video modes: \n");

        high = 0;
        for (i = 1; i <= vga_lastmodenumber(); i++)
            if (vga_hasmode(i)) {
                vga_modeinfo *info;
                char expl[100];
                const char *cols = NULL;

                *expl = '\0';
                info = vga_getmodeinfo(i);
                switch (info->colors) {
                case 2:
                    cols = "2";
                    strcpy(expl, "1 bitplane, monochrome");
                    break;
                case 16:
                    cols = "16";
                    strcpy(expl, "4 bitplanes");
                    break;
                case 256:
                    if (i == G320x200x256)
                        strcpy(expl, "packed-pixel");
                    else if (i == G320x240x256
                             || i == G320x400x256
                             || i == G360x480x256)
                        strcpy(expl, "Mode X");
                    else
                        strcpy(expl,
                               "packed-pixel, banked");
                    break;
                case 1 << 15:
                    cols = "32K";
                    strcpy(expl, "5-5-5 RGB, blue at LSB, banked");
                    break;
                case 1 << 16:
                    cols = "64K";
                    strcpy(expl, "5-6-5 RGB, blue at LSB, banked");
                    break;
                case 1 << 24:
                    cols = "16M";
                    if (info->bytesperpixel == 3) {
                        if (info->flags & RGB_MISORDERED)
                            strcpy(expl, "8-8-8 BGR, red byte first, banked");
                        else
                            strcpy(expl, "8-8-8 RGB, blue byte first, banked");
                    } else if (info->flags & RGB_MISORDERED)
                        strcpy(expl, "8-8-8 RGBX, 32-bit pixels, X byte first, banked");
                    else
                        strcpy(expl, "8-8-8 XRGB, 32-bit pixels, blue byte first, banked");
                    break;
                }
                if (info->flags & IS_INTERLACED) {
                    if (*expl != '\0')
                        strcat(expl, ", ");
                    strcat(expl, "interlaced");
                }
                if (info->flags & IS_DYNAMICMODE) {
                    if (*expl != '\0')
                        strcat(expl, ", ");
                    strcat(expl, "dynamically loaded");
                }
                high = i;
                printf("%5d: %dx%d, ",
                       i, info->width, info->height);
                if (cols == NULL)
                    printf("%d", info->colors);
                else
                    printf("%s", cols);
                printf(" colors ");
                if (*expl != '\0')
                    printf("(%s)", expl);
                printf("\n");
            }
        printf("Enter mode number (1-%d): ", high);
        scanf("%d", &mode);
        getchar();
        printf("\n");

        if (mode < 1 || mode > GLASTMODE) {
            printf("Error: Mode number out of range \n");
            exit(-1);
        }
    }
    if (vga_hasmode(mode)) {
        testmode(mode);
        if(mode2!=-1 && vga_hasmode(mode2)) {
            testmode(mode2);
        }
    } else {
        printf("Error: Video mode not supported by driver\n");
        exit(-1);
    }

    vga_setmode(TEXT);

    return 0;
}
Ejemplo n.º 25
0
static void testmode(int mode)
{
    int xmax, ymax, i, x, y, yw, ys, c;
    vga_modeinfo *modeinfo;

    vga_setmode(mode);

    modeinfo = vga_getmodeinfo(mode);

    printf("Width: %d  Height: %d  Colors: %d\n",
           modeinfo->width,
           modeinfo->height,
           modeinfo->colors);
    printf("DisplayStartRange: %xh  Maxpixels: %d  Blit: %s\n",
           modeinfo->startaddressrange,
           modeinfo->maxpixels,
           modeinfo->haveblit ? "YES" : "NO");

#ifdef TEST_MODEX
    if (modeinfo->colors == 256)
        printf("Switching to ModeX ... %s\n",
               (vga_setmodeX()? "done" : "failed"));
#endif

    vga_screenoff();

    xmax = vga_getxdim() - 1;
    ymax = vga_getydim() - 1;

    vga_setcolor(vga_white());
    vga_drawline(0, 0, xmax, 0);
    vga_drawline(xmax, 0, xmax, ymax);
    vga_drawline(xmax, ymax, 0, ymax);
    vga_drawline(0, ymax, 0, 0);

    /* Draw crosses */
    for (i = 0; i <= 15; i++) {
        vga_setegacolor(i);
        vga_drawline(10 + i * 5, 10, 89 + i * 5, 89);
    }
    for (i = 0; i <= 15; i++) {
        vga_setegacolor(i);
        vga_drawline(89 + i * 5, 10, 10 + i * 5, 89);
    }

    vga_screenon();

    ys = 100;
    yw = (ymax - 100) / 4;
    switch (vga_getcolors()) {
    case 256:
        /* Draw horizontal color bands using palette */
        for (i = 0; i < 60; ++i) {
            c = (i * 64) / 60;
            vga_setpalette(i + 16, c, c, c);
            vga_setpalette(i + 16 + 60, c, 0, 0);
            vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
            vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
        }
        line[0] = line[xmax] = 15;
        line[1] = line[xmax - 1] = 0;
        for (x = 2; x < xmax - 1; ++x)
            line[x] = (((x - 2) * 60) / (xmax - 3)) + 16;
        for (y = ys; y < ys + yw; ++y)	/* gray */
            vga_drawscanline(y, line);
        for (x = 2; x < xmax - 1; ++x)
            line[x] += 60;
        ys += yw;
        for (y = ys; y < ys + yw; ++y)	/* red */
            vga_drawscanline(y, line);
        for (x = 2; x < xmax - 1; ++x)
            line[x] += 60;
        ys += yw;
        for (y = ys; y < ys + yw; ++y)	/* green */
            vga_drawscanline(y, line);
        for (x = 2; x < xmax - 1; ++x)
            line[x] += 60;
        ys += yw;
        for (y = ys; y < ys + yw; ++y)	/* blue */
            vga_drawscanline(y, line);
        break;

    case 1 << 15:
    case 1 << 16:
    case 1 << 24:
        /* Draw horizontal color bands in RGB */
        for (x = 2; x < xmax - 1; ++x) {
            c = ((x - 2) * 255) / (xmax - 4);
            y = ys;
            vga_setrgbcolor(c, c, c);
            vga_drawline(x, y, x, y + yw - 1);
            y += yw;
            vga_setrgbcolor(c, 0, 0);
            vga_drawline(x, y, x, y + yw - 1);
            y += yw;
            vga_setrgbcolor(0, c, 0);
            vga_drawline(x, y, x, y + yw - 1);
            y += yw;
            vga_setrgbcolor(0, 0, c);
            vga_drawline(x, y, x, y + yw - 1);
        }
        drawSquares(xmax, ymax);
        break;
    default:
        /* Draw vertical color bars */
        if (vga_getcolors() == 16) {
            for (i = 0; i < xmax - 1; i++)
                line[i] = (i + 2) % 16;
            line[0] = line[xmax] = 15;
            line[1] = line[xmax - 1] = 0;
        }
        if (vga_getcolors() == 2) {
            for (i = 0; i <= xmax; i++)
                line[i] = 0x11;
            line[0] = 0x91;
        }
        for (i = 100; i < ymax - 1; i++)
            vga_drawscanline(i, line);
        break;

    }

    if (getchar() == 'd')
        vga_dumpregs();

}
Ejemplo n.º 26
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 */
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
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;
}