コード例 #1
0
ファイル: w_system.c プロジェクト: j13s/devil
void ws_setdriver(const char *name) {
    GrSetDriver( (char *)name );
}
コード例 #2
0
ファイル: modetest.c プロジェクト: nidheeshdas/Algosim
int main(void)
{
	static int firstgr = 1;
	GrEvent ev;

	GrSetDriver(NULL);
	if(GrCurrentVideoDriver() == NULL) {
	    printf("No graphics driver found\n");
	    exit(1);
	}
	for( ; ; ) {
	    int  i,w,h,px,py;
	    char m1[41];
	    nmodes = (int)(collectmodes(GrCurrentVideoDriver(),grmodes) - grmodes);
	    if(nmodes == 0) {
		printf("No graphics modes found\n");
		exit(1);
	    }
	    qsort(grmodes,nmodes,sizeof(grmodes[0]),vmcmp);
	    printf(
		"Graphics driver: \"%s\"\n"
		"  graphics defaults: %dx%d %ld colors\n"
		"  text defaults: %dx%d %ld colors\n\n",
		GrCurrentVideoDriver()->name,
		GrDriverInfo->defgw,
		GrDriverInfo->defgh,
		(long)GrDriverInfo->defgc,
		GrDriverInfo->deftw,
		GrDriverInfo->defth,
		(long)GrDriverInfo->deftc
	    );
	    PrintModes();
	    printf("\nEnter choice #, or anything else to quit> ");
	    fflush(stdout);
	    if(!fgets(m1,40,stdin) || 
	    (sscanf(m1,"%d",&i) != 1) || (i < 1) || (i > nmodes)) {
		exit(0);
	    }
	    if(firstgr) {
		printf(
                    "When in graphics mode, press any key to return to menu.\n"
		    "Now press <CR> to continue..."
		);
		fflush(stdout);
		fgets(m1,40,stdin);
		firstgr = 0;
	    }
	    i--;
	    GrSetMode(
		GR_width_height_bpp_graphics,
		grmodes[i].w,
		grmodes[i].h,
		grmodes[i].bpp
	    );
	    if(grmodes[i].bpp<15) {
		w = GrScreenX() >> 1;
		h = GrScreenY() >> 1;
		px = w + 5;
		py = h + 5;
		w -= 10;
		h -= 10;
		drawing(
		    5,5,w,h,
		    GrBlack(),
		    GrWhite()
		);
		drawing(
		    px,5,w,h,
		    GrAllocColor(255,0,0),
		    GrAllocColor(0,255,0)
		);
		drawing(
		    5,py,w,h,
		    GrAllocColor(0,0,255),
		    GrAllocColor(255,255,0)
		);
		drawing(
		    px,py,w,h,
		    GrAllocColor(255,0,255),
		    GrAllocColor(0,255,255)
		);
	    } else {
コード例 #3
0
ファイル: setmode.c プロジェクト: nidheeshdas/Algosim
int GrSetMode(GrGraphicsMode which,...)
{
    int  w,h,pl,vw,vh;
    int  t,noclear,res;
    GrColor c;
    va_list ap;
    GRX_ENTER();
    pl = 0;
    vw = 0;
    vh = 0;
    t = FALSE;
    noclear = FALSE;
    c = 0;
    res = FALSE;
    DBGPRINTF(DBG_SETMD,("Mode: %d\n",(int)which));
    if(DRVINFO->vdriver == NULL) {
        GrSetDriver(NULL);
        if(DRVINFO->vdriver == NULL) {
            res = errhdlr("could not find suitable video driver");
            goto done;
        }
    }
    va_start(ap,which);
    switch(which) {
    case GR_NC_default_text:
        noclear = TRUE;
    case GR_default_text:
        w = DRVINFO->deftw;
        h = DRVINFO->defth;
        c = DRVINFO->deftc;
        t = TRUE;
        break;
    case GR_NC_320_200_graphics:
        noclear = TRUE;
    case GR_320_200_graphics:
        w = 320;
        h = 200;
        c = DRVINFO->defgc;
        break;
    case GR_NC_default_graphics:
        noclear = TRUE;
    case GR_default_graphics:
        w = DRVINFO->defgw;
        h = DRVINFO->defgh;
        c = DRVINFO->defgc;
        break;
    case GR_NC_width_height_graphics:
        noclear = TRUE;
    case GR_width_height_graphics:
        w = va_arg(ap,int);
        h = va_arg(ap,int);
        c = DRVINFO->defgc;
        break;
    case GR_NC_biggest_graphics:
        noclear = TRUE;
    case GR_biggest_graphics:
        w = DRVINFO->biggw;
        h = DRVINFO->biggh;
        pl = 32;
        break;
    case GR_NC_width_height_color_graphics:
        noclear = TRUE;
    case GR_width_height_color_graphics:
        w = va_arg(ap,int);
        h = va_arg(ap,int);
        c = va_arg(ap,GrColor);
        break;
    case GR_NC_width_height_bpp_graphics:
        noclear = TRUE;
    case GR_width_height_bpp_graphics:
        w  = va_arg(ap,int);
        h  = va_arg(ap,int);
        pl = va_arg(ap,int);
        break;
    case GR_NC_custom_graphics:
        noclear = TRUE;
    case GR_custom_graphics:
        w  = va_arg(ap,int);
        h  = va_arg(ap,int);
        c  = va_arg(ap,GrColor);
        vw = va_arg(ap,int);
        vh = va_arg(ap,int);
        break;
    case GR_NC_custom_bpp_graphics:
        noclear = TRUE;
    case GR_custom_bpp_graphics:
        w  = va_arg(ap,int);
        h  = va_arg(ap,int);
        pl = va_arg(ap,int);
        vw = va_arg(ap,int);
        vh = va_arg(ap,int);
        break;
    default:
        va_end(ap);
        res = errhdlr("unknown video mode");
        goto done;
    }
    va_end(ap);
    if (c)
        for(pl = 1; (pl < 32) && ((1UL << pl) < (GrColor)c); pl++) ;
    for( ; ; ) {
        GrContext     cxt;
        GrFrameDriver fdr;
        GrVideoMode  *mdp,vmd;
        mdp = (DRVINFO->vdriver->selectmode)(DRVINFO->vdriver,w,h,pl,t,NULL);
        if(!mdp) {
            res = errhdlr("could not find suitable video mode");
            goto done;
        }
        sttcopy(&vmd,mdp);
        if((t || buildframedriver(&vmd,&fdr)) &&
                (*vmd.extinfo->setup)(&vmd,noclear) &&
                (t || buildcontext(&vmd,&fdr,&cxt))) {
            if((!t) &&
                    ((vw > vmd.width) || (vh > vmd.height)) &&
                    (vmd.extinfo->setvsize != NULL) &&
                    (vmd.extinfo->scroll   != NULL)) {
                int ww = vmd.width  = imax(vw,vmd.width);
                int hh = vmd.height = imax(vh,vmd.height);
                if(!(*vmd.extinfo->setvsize)(&vmd,ww,hh,&vmd) ||
                        !buildcontext(&vmd,&fdr,&cxt)) {
                    sttcopy(&vmd,mdp);
                    buildcontext(&vmd,&fdr,&cxt);
                    (*vmd.extinfo->setup)(&vmd,noclear);
                }
            }
//		DBGPRINTF(DBG_SETMD,("GrMouseUnInit ...\n"));
//		GrMouseUnInit();
//		DBGPRINTF(DBG_SETMD,("GrMouseUnInit done\n"));
            DRVINFO->setbank    = (void (*)(int    ))_GrDummyFunction;
            DRVINFO->setrwbanks = (void (*)(int,int))_GrDummyFunction;
            DRVINFO->curbank    = (-1);
            DRVINFO->splitbanks = FALSE;
            if(!t) {
                if(vmd.extinfo->setbank) {
                    DRVINFO->setbank = vmd.extinfo->setbank;
                }
                if(vmd.extinfo->setrwbanks) {
                    DRVINFO->setrwbanks = vmd.extinfo->setrwbanks;
                    DRVINFO->splitbanks = TRUE;
                }
                if(umul32(vmd.lineoffset,vmd.height) <= 0x10000L) {
                    DRVINFO->splitbanks = TRUE;
                }
            }
            else {
                sttzero(&cxt);
                sttcopy(&fdr,&DRVINFO->tdriver);
                cxt.gc_driver = &DRVINFO->tdriver;
            }
            sttcopy(&CXTINFO->current,&cxt);
            sttcopy(&CXTINFO->screen, &cxt);
            sttcopy(&DRVINFO->fdriver,&fdr);
            sttcopy(&DRVINFO->sdriver,&fdr);
            sttcopy(&DRVINFO->actmode,&vmd);
            DRVINFO->curmode = mdp;
            DRVINFO->mcode   = which;
            DRVINFO->vposx   = 0;
            DRVINFO->vposy   = 0;
            DBGPRINTF(DBG_SETMD,("GrResetColors ...\n"));
            if ( !_GrResetColors() ) {
                res = errhdlr("could not set color mode");
                goto done;
            }
            DBGPRINTF(DBG_SETMD,("GrResetColors done\n"));
            if(fdr.init) {
                DBGPRINTF(DBG_SETMD,("fdr.init ...\n"));
                (*fdr.init)(&DRVINFO->actmode);
                DBGPRINTF(DBG_SETMD,("fdr.init done\n"));
            }
            if(DRVINFO->mdsethook) {
                DBGPRINTF(DBG_SETMD,("mdsethook ...\n"));
                (*DRVINFO->mdsethook)();
                DBGPRINTF(DBG_SETMD,("mdsethook done\n"));
            }
            DBGPRINTF(DBG_SETMD,("GrSetMode complete\n"));
            res = TRUE;
            goto done;
        }
        mdp->present = FALSE;
    }
done:
    GRX_RETURN(res);
}