Exemple #1
0
static void testcase2(const char *desc)
{
	int err;
	ggi_visual_t vis;
	ggi_mode mode;


	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	err = ggiCheckSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode);

	err = ggiSetMode(vis, &mode);
	if (err != GGI_OK) {
		printfailure("ggiSetMode: expected return value: GGI_OK\n"
					"actual return value: %i\n", err);
		return;
	}

	ggiClose(vis);
	ggiExit();

	printsuccess();
	return;
}
Exemple #2
0
int gr_init(int mode)
{
	int retcode;
 	// Only do this function once!
	if (gr_installed==1)
		return -1;
	MALLOC(grd_curscreen,grs_screen, 1);
	memset(grd_curscreen, 0, sizeof(grs_screen));
	
	ggiInit();
	screenvis = ggiOpen(NULL);

	if ((retcode=gr_set_mode(mode)))
		return retcode;
	
	grd_curscreen->sc_canvas.cv_color = 0;
	grd_curscreen->sc_canvas.cv_drawmode = 0;
	grd_curscreen->sc_canvas.cv_font = NULL;
	grd_curscreen->sc_canvas.cv_font_fg_color = 0;
	grd_curscreen->sc_canvas.cv_font_bg_color = 0;
	gr_set_current_canvas( &grd_curscreen->sc_canvas );

	gr_installed = 1;
	atexit(gr_close);
	return 0;
}
Exemple #3
0
static void testcase7(const char *desc)
{
	int err;
	ggi_visual_t vis;
	ggi_mode mode;

	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	/* sync mode enables mansync if used */

	/* Get the default mode */
	err = ggiCheckGraphMode (vis, 640, 480, GGI_AUTO, GGI_AUTO,
				GT_AUTO, &mode);
	if (err != GGI_OK) {
		printfailure("ggiCheckGraphMode: #1: No 640x480 mode available\n");
		ggiClose(vis);
		ggiExit();
		return;
	}

	err = ggiSetMode(vis, &mode);
	if (err != GGI_OK) {
		printfailure("ggiSetMode() #1: failed although ggiCheckGraphMode() was OK!\n");
		ggiClose(vis);
		ggiExit();
		return;
	}


	err = ggiCheckGraphMode(vis, 320, 200, GGI_AUTO, GGI_AUTO,
				GT_AUTO, &mode);
	if (err != GGI_OK) {
		printfailure("ggiCheckGraphMode: #2: No 320x200 mode available\n");
		ggiClose(vis);
		ggiExit();
		return;
	}

	err = ggiSetMode(vis, &mode);
	if (err != GGI_OK) {
		printfailure("ggiSetMode() #2: resetting a mode failed although ggiCheckGraphMode() was OK!\n");
		ggiClose(vis);
		ggiExit();
		return;
	}


	ggiClose(vis);
	ggiExit();

	printsuccess();
	return;
}
Exemple #4
0
static void testcase5(const char *desc)
{
	int err;
	ggi_visual_t vis;
	ggi_mode sug_mode, final_mode;
	int visible_w, visible_h;

	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	ggiSetFlags(vis, GGIFLAG_ASYNC);

	/* Get the default mode */
	err = ggiCheckGraphMode (vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO,
				GT_AUTO, &sug_mode);
	if (err != GGI_OK) {
		printfailure("ggiCheckGraphMode: No graphic mode available\n");
		ggiClose(vis);
		ggiExit();
		return;
	}

	visible_w = sug_mode.visible.x;
	visible_h = sug_mode.visible.y;

	err = ggiCheckGraphMode(vis, visible_w, visible_h, visible_w, visible_h*2,
				GT_AUTO, &final_mode);
	if (!err) {
		/* actually print an info output */
		printassert(0 == 1, "Info: Applications may assume now,"
				" panning via ggiSetOrigin() is available\n");

		/* Note, Applications have no other way to figure out if
		 * ggiSetOrigin() is available or not
		 */
	} else {
		final_mode = sug_mode;
	}

	err = ggiSetMode(vis, &final_mode);
	if (err) {
		printfailure("ggiSetMode() failed although ggiCheckGraphMode() was OK!\n");
		ggiClose(vis);
		ggiExit();
	}

	ggiClose(vis);
	ggiExit();

	printsuccess();
	return;
}
Exemple #5
0
static void testcase1(const char *desc)
{
	ggi_visual_t vis;
	ggi_color green, back;
	int err;

	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	err = ggiSetGraphMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_8BIT);
	if(err < 0) {
		printassert(0, "Palettized mode not available.\n");
		printsuccess();
		ggiClose(vis);
		ggiExit();
		return;
	}

	green.r = 100;
	green.g = 40000;
	green.b = 4000;
	err = ggiSetPalette(vis, GGI_PALETTE_DONTCARE, 1, &green);
	if (err < 0) {
		printfailure("Unable to install colormap with one entry.\n");
		ggiClose(vis);
		ggiExit();
		return;
	}

	printassert(err == (int)ggiMapColor(vis, &green),
		"ggiMapColor inconsistent with retval of ggiSetPalette.\n");

	ggiUnmapPixel(vis, err, &back);
	if(green.r != back.r || green.g != back.g || green.b != back.b) {
		printfailure("Unexpected color from ggiUnmapPixel.\n");
		ggiClose(vis);
		ggiExit();
		return;
	}

	ggiSetGCForeground(vis, err);
	ggiDrawBox(vis, 0, 0, 3000, 3000);
	ggiFlush(vis);

	/* You should see a green square, how to test this? */
	ggUSleep(5000000);
	printsuccess();

	ggiClose(vis);
	ggiExit();
}
Exemple #6
0
static void handle_connection(void)
{
	TeleUser *u;

	static int numcon=0;


	u = malloc(sizeof(TeleUser));

	numcon++;

	fprintf(stderr, "Connection %d received.\n", numcon);


	if (user != NULL) {
		fprintf(stderr, "Connection refused.\n");

		/* tserver_refuse() ??? */

		if (tserver_open(&serv, u) == 0) {
			tserver_close(u);
		}
		return;
	}

	if (NULL == target_name)
	  vis = ggiOpen(NULL);
	else
	  vis = ggiOpen(target_name, NULL);

	if (vis == NULL) {
		fprintf(stderr, "teleserver: Couldn't open GGI visual.\n");
		ggiExit();
		exit(2);
	}

	if (tserver_open(&serv, u) < 0) {
		fprintf(stderr, "tserver_open < 0\n");
		ggiClose(vis);
		return;
	}

	user = u;
}
Exemple #7
0
static int GGI_Available(void)
{
	ggi_visual_t *vis;

	vis = NULL;
	if (ggiInit() == 0) {
		vis = ggiOpen(NULL);
		if (vis != NULL) {
			ggiClose(vis);
		}
	}
	return (vis != NULL);
}
Exemple #8
0
static int preinit(const char *arg)
{
    if (ggiInit() != 0) {
        mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] unable to initialize GGI\n");
        return (-1);
    }
#ifdef HAVE_GGIWMH
    if (ggiWmhInit() < 0) {
        mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] unable to initialize libggiwmh\n");
        return (-1);
    }
#endif

    if (arg) {
        int i = 0;
        ggi_conf.driver = strdup(arg);
        while (ggi_conf.driver[i] != '\0') {
            if (ggi_conf.driver[i] == '.')
                ggi_conf.driver[i] = ',';
            i++;
        }
    } else {
        ggi_conf.driver = NULL;
    }

    ggi_conf.vis = ggiOpen(ggi_conf.driver);
    if (ggi_conf.vis == NULL) {
        mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] unable to open '%s' output\n",
               (ggi_conf.driver == NULL) ? "default" : ggi_conf.driver);
        ggiExit();
        return (-1);
    }
    ggi_conf.drawvis = ggi_conf.vis;


#ifdef HAVE_GGIWMH
    ggiWmhAttach(ggi_conf.vis);
#endif


    mp_msg(MSGT_VO, MSGL_V, "[ggi] using '%s' output\n",
          (ggi_conf.driver == NULL) ? "default" : ggi_conf.driver);

    return 0;
}
Exemple #9
0
static void testcase8(const char *desc)
{
	int err;
	ggi_visual_t vis;
	ggi_mode mode;

	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	mode.virt.x = mode.virt.y = GGI_AUTO;
	mode.visible.x = mode.visible.y = GGI_AUTO;
	mode.frames = GGI_AUTO;
	mode.graphtype = GT_AUTO;
	mode.dpp.x = mode.dpp.y = 1;
        mode.size.x = -19493;
        mode.size.y = 31831;

	/* Get the default mode */
	ggiCheckMode(vis, &mode);

	err = ggiSetMode(vis, &mode);
	if (err != GGI_OK) {
		printfailure("ggiSetMode() failed even though ggiCheckMode() was called!\n");
		ggiClose(vis);
		ggiExit();
		return;
	}

	ggiClose(vis);
	ggiExit();

	printsuccess();
	return;
}
Exemple #10
0
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)
{
    ggi_mode mode = {
        1,                      /* frames */
        {width, height},        /* visible */
        {GGI_AUTO, GGI_AUTO},   /* virt */
        {GGI_AUTO, GGI_AUTO},   /* size */
        GT_AUTO,                /* graphtype */
        {GGI_AUTO, GGI_AUTO}    /* dots per pixel */
    };


    set_graphtype(format, &mode);

#if 0
    printf("[ggi] mode: ");
    ggiPrintMode(&mode);
    printf("\n");
#endif

    ggiCheckMode(ggi_conf.vis, &mode);

    if (ggiSetMode(ggi_conf.vis, &mode) < 0) {
        mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to set display mode\n");
        return (-1);
    }
    if (ggiGetMode(ggi_conf.vis, &mode) < 0) {
        mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to get display mode\n");
        return (-1);
    }
    if ((mode.graphtype == GT_INVALID)
       || (mode.graphtype == GT_AUTO))
    {
        mp_msg(MSGT_VO, MSGL_ERR, "[ggi] not supported depth/bpp\n");
        return (-1);
    }

#if 0
    printf("[ggi] mode: ");
    ggiPrintMode(&mode);
    printf("\n");
#endif


#ifdef HAVE_GGIWMH
    ggiWmhSetTitle(ggi_conf.vis, title);
    if (vo_ontop) window_ontop();
#endif

    ggiSetFlags(ggi_conf.vis, GGIFLAG_ASYNC);

    if (GT_SCHEME(mode.graphtype) == GT_PALETTE)
        ggiSetColorfulPalette(ggi_conf.vis);

    if (GT_SCHEME(mode.graphtype) != GT_TRUECOLOR) {
        ggi_mode drawmode;

        ggi_conf.drawvis = ggiOpen("display-memory", NULL);
        if (ggi_conf.drawvis == NULL) {
            mp_msg(MSGT_VO, MSGL_ERR,
                   "[ggi] unable to get backbuffer for conversion\n");
            return -1;
        }
        memcpy(&drawmode, &mode, sizeof(ggi_mode));
        drawmode.graphtype = GT_32BIT;
        drawmode.size.x = GGI_AUTO;
        drawmode.size.y = GGI_AUTO;
        ggiCheckMode(ggi_conf.drawvis, &drawmode);
        if (ggiSetMode(ggi_conf.drawvis, &drawmode) < 0) {
            mp_msg(MSGT_VO, MSGL_ERR,
                   "[ggi] unable to set backbuffer mode\n");
            return -1;
        }
        mode.graphtype = drawmode.graphtype;

        ggiSetFlags(ggi_conf.drawvis, GGIFLAG_ASYNC);
    }
    vo_depthonscreen = GT_DEPTH(mode.graphtype);
    vo_screenwidth = mode.virt.x;
    vo_screenheight = mode.virt.y;

    vo_dwidth = width;
    vo_dheight = height;
    vo_dbpp = GT_SIZE(mode.graphtype);


    /* calculate top, left corner */
    vo_dx = (vo_screenwidth - vo_dwidth) / 2;
    vo_dy = (vo_screenheight - vo_dheight) / 2;


    ggi_conf.srcwidth = width;
    ggi_conf.srcheight = height;
    ggi_conf.srcformat = format;

    ggi_conf.voflags = flags;

    if (IMGFMT_IS_RGB(ggi_conf.srcformat)) {
        ggi_conf.srcdepth = IMGFMT_RGB_DEPTH(ggi_conf.srcformat);
    } else if (IMGFMT_IS_BGR(ggi_conf.srcformat)) {
        ggi_conf.srcdepth = IMGFMT_BGR_DEPTH(ggi_conf.srcformat);
    } else {
        mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] Unknown image format: %s\n",
               vo_format_name(ggi_conf.srcformat));
        return (-1);
    }

    mp_msg(MSGT_VO, MSGL_INFO, "[ggi] input: %dx%dx%d, output: %dx%dx%d\n",
           ggi_conf.srcwidth, ggi_conf.srcheight, ggi_conf.srcdepth,
           mode.virt.x, mode.virt.y, vo_dbpp);

    ggi_conf.srcbpp = (ggi_conf.srcdepth + 7) / 8;

    ggi_conf.flushregion.x1 = vo_dx;
    ggi_conf.flushregion.y1 = vo_dy;
    ggi_conf.flushregion.x2 = vo_dwidth;
    ggi_conf.flushregion.y2 = vo_dheight;

    return (0);
}
Exemple #11
0
static int GGIopen_palemu(struct ggi_visual *vis, struct ggi_dlhandle *dlh,
		   const char *args, void *argptr, uint32_t *dlret)
{
	ggi_palemu_priv *priv;
	gg_option options[PALEMU_NUM_OPTS];
	char target[1024];
	int err = GGI_ENOMEM;
	struct gg_api *api;
	struct gg_observer *obs = NULL;

	DPRINT("display-palemu: GGIopen start.\n");

	/* handle arguments */
	memcpy(options, palemu_optlist, sizeof(options));
	if (args) {
		args = ggParseOptions(args, options, PALEMU_NUM_OPTS);

		if (args == NULL) {
			fprintf(stderr,
				"display-palemu: error in arguments.\n");
			return GGI_EARGINVAL;
		}
	}
	if (getenv("GGI_PALEMU_OPTIONS") != NULL) {
		if (ggParseOptions(getenv("GGI_PALEMU_OPTIONS"), options,
				   PALEMU_NUM_OPTS) == NULL) {
			fprintf(stderr, "display-palemu: error in ""$GGI_PALEMU_OPTIONS.\n");
			return GGI_EARGINVAL;
		}
	}

	/* Find out the parent target. */
	while (args && *args && isspace((uint8_t)*args)) {
		args++;
	}

	*target = '\0';
	if (args) {
		if (ggParseTarget(args, target, 1024) == NULL) {
			return GGI_EARGINVAL;
		}
	}
	if (*target == '\0') {
		strcpy(target, "auto");
	}

	LIBGGI_GC(vis) = malloc(sizeof(ggi_gc));
	if (LIBGGI_GC(vis) == NULL) {
		return GGI_ENOMEM;
	}
	LIBGGI_PRIVATE(vis) = priv = malloc(sizeof(*priv));
	if (priv == NULL) {
		goto out_freegc;
	}
	priv->flush_lock = ggLockCreate();
	if (priv->flush_lock == NULL) {
		goto out_freepriv;
	}
	priv->opmansync = malloc(sizeof(_ggi_opmansync));
	if (priv->opmansync == NULL) {
		goto out_freelock;
	}

	priv->flags  = 0;
	priv->fb_ptr = NULL;
	priv->target = PALEMU_TARGET;

	DPRINT("display-palemu: parent mode is '%s'\n",
		  options[OPT_PARENT].result);
	ggiParseMode(options[OPT_PARENT].result, &priv->parent_defmode);

	DPRINT("display-palemu: opening target: %s\n", target);
	priv->parent = ggNewStem(NULL);
	if (priv->parent == NULL) {
		fprintf(stderr,
			"display-palemu: Failed to create stem for target: '%s'\n",
			target);
		err = GGI_ENODEVICE;
		goto out_freeopmansync;
	}
	/* FIXME! Should iterate over the apis attached to vis->instance.stem
	 * instead of only looking for ggi and gii.
	 */
	if (ggiAttach(priv->parent) < 0) {
		ggDelStem(priv->parent);
		priv->parent = NULL;
		fprintf(stderr,
			"display-palemu: Failed to attach ggi to stem for target: '%s'\n",
			target);
		err = GGI_ENODEVICE;
		goto out_freeopmansync;
	}
	if ((api = ggGetAPIByName("gii")) != NULL) {
		/* FIXME! This should probably be done in pseudo-stubs-gii */
		if (STEM_HAS_API(vis->instance.stem, api)) {
			if (ggAttach(api, priv->parent) < 0) {
				ggDelStem(priv->parent);
				priv->parent = NULL;
				fprintf(stderr,
					"display-palemu: Failed to attach gii to stem for target: '%s'\n",
					target);
				err = GGI_ENODEVICE;
				goto out_freeopmansync;
			}
			obs = ggObserve(GG_STEM_API_CHANNEL(priv->parent, api),
			    transfer_gii_src, vis->instance.stem);
		}
	}
	if (ggiOpen(priv->parent, target, NULL) < 0) {
		if (obs) {
			ggDelObserver(obs);
			obs = NULL;
		}
		fprintf(stderr,
			"display-palemu: Failed to open target: '%s'\n",
			target);
		ggDelStem(priv->parent);
		priv->parent = NULL;
		err = GGI_ENODEVICE;
		goto out_freeopmansync;
	}
	if (obs) {
		ggDelObserver(obs);
		obs = NULL;
	}

	ggiSetFlags(priv->parent, GGIFLAG_ASYNC);

	/* Setup mansync */
	MANSYNC_open(vis, priv);
	if (priv->mod_mansync == NULL) {
		fprintf(stderr,
			"display-palemu: Cannot load helper-mansync!\n");
		GGIclose_palemu(vis, dlh);
		return err;
	}

	MANSYNC_init(vis);
	if (!(LIBGGI_FLAGS(vis) & GGIFLAG_ASYNC)) {
		MANSYNC_start(vis);
	}

	/* Has mode management */
	vis->opdisplay->getmode = GGI_palemu_getmode;
	vis->opdisplay->setmode = GGI_palemu_setmode;
	vis->opdisplay->checkmode = GGI_palemu_checkmode;
	vis->opdisplay->getapi = GGI_palemu_getapi;
	vis->opdisplay->flush = GGI_palemu_flush;
	vis->opdisplay->setflags = GGI_palemu_setflags;

	DPRINT("display-palemu: GGIopen succeeded.\n");

	*dlret = GGI_DL_OPDISPLAY;
	return 0;

  out_freelock:
	ggLockDestroy(priv->flush_lock);
  out_freeopmansync:
	free(priv->opmansync);
  out_freepriv:
	free(priv);
  out_freegc:
	free(LIBGGI_GC(vis));

	return err;
}
Exemple #12
0
static int GGIopen_monotext(struct ggi_visual *vis, struct ggi_dlhandle *dlh,
				const char *args, void *argptr, uint32_t *dlret)
{
	ggi_palemu_priv *priv;
	gg_option options[MONOTEXT_NUM_OPTS];
	char target[1024];
	struct gg_api *api;
	struct gg_observer *obs = NULL;
	int val;
	int err = 0;

	DPRINT("display-monotext: GGIopen start.\n");

	memcpy(options, monotext_optlist, sizeof(options));
	if (args) {
		args = ggParseOptions(args, options, MONOTEXT_NUM_OPTS);
		if (args == NULL) {
			fprintf(stderr,
				"display-monotext: error in arguments\n");
			return GGI_EARGINVAL;
		}
	}

	/* open the parent visual */
	DPRINT("display-monotext: opening target: %s\n", args);

	if (args != NULL) {
		if (ggParseTarget(args, target, sizeof(target)) == NULL) {
			/* error occured */
			return GGI_EARGINVAL;
		}
	}

	/* Find out the parent target */
	while (args && *args && isspace((uint8_t)*args)) {
		args++;
	}

	*target = '\0';
	if (args) {
		if (ggParseTarget(args, target, sizeof(target)) == NULL) {
			return GGI_EARGINVAL;
		}
	}

	if (*target == '\0') {
		strcpy(target, "auto");
	}

	LIBGGI_GC(vis) = malloc(sizeof(ggi_gc));
	if (LIBGGI_GC(vis) == NULL) {
		err = GGI_ENOMEM;
		goto err0;
	}
	LIBGGI_PRIVATE(vis) = priv = malloc(sizeof(ggi_palemu_priv));
	if (priv == NULL) {
		err = GGI_ENOMEM;
		goto err1;
	}

	priv->flush_lock = ggLockCreate();
	if (priv->flush_lock == NULL) {
		err = GGI_ENOMEM;
		goto err2;
	}
	priv->opmansync = malloc(sizeof(_ggi_opmansync));
	if (priv->opmansync == NULL) {
		err = GGI_ENOMEM;
		goto err3;
	}

	priv->flags = 0;
	priv->fb_ptr = NULL;
	priv->target = MONOTEXT_TARGET;


	DPRINT("display-monotext: opening target: %s\n", target);
	priv->parent = ggNewStem(NULL);
	if (priv->parent == NULL) {
		fprintf(stderr,
			"display-monotext: Failed to create stem for target: %s\n",
			target);
		err = GGI_ENODEVICE;
		goto err3;
	}

	/* XXX Should iterate over the apis attached to vis->instance.stem
	 * instead of only looking for ggi and gii.
	 */
	if (ggiAttach(priv->parent) < 0) {
		ggDelStem(priv->parent);
		priv->parent = NULL;
		fprintf(stderr,
			"display-monotext: Failed to attach ggi to stem for target: %s\n",
			target);
		err = GGI_ENODEVICE;
		goto err4;
	}

	api = ggGetAPIByName("gii");
	if (api != NULL) {
		/* XXX This should probably be done in pseudo-stubs-gii */
		if (STEM_HAS_API(vis->instance.stem, api)) {
			if (ggAttach(api, priv->parent) < 0) {
				ggDelStem(priv->parent);
				priv->parent = NULL;
				fprintf(stderr,
					"Failed to attach gii to stem for target: %s\n",
					target);
				err = GGI_ENODEVICE;
				goto err4;
			}
			obs = ggObserve(GG_STEM_API_CHANNEL(priv->parent, api),
					transfer_gii_src, vis->instance.stem);
		}
	}

	if (ggiOpen(priv->parent, target, NULL) < 0) {
		if (obs) {
			ggDelObserver(obs);
			obs = NULL;
		}
		fprintf(stderr,
			"display-monotext: Failed to open target: '%s'\n",
			target);
		ggDelStem(priv->parent);
		priv->parent = NULL;
		err = GGI_ENODEVICE;
		goto err4;
	}
	if (obs) {
		ggDelObserver(obs);
		obs = NULL;
	}

	ggiSetFlags(priv->parent, GGIFLAG_ASYNC);


	/* set defaults */
	priv->parent_defmode.graphtype = GT_TEXT16;
	priv->flags = 0;
	priv->squish.x = priv->squish.y = 1;

	val = strtol(options[OPT_A].result, NULL, 0);	
	if (val != 0) {
		priv->accuracy.x = priv->accuracy.y = val;
	} else {
		priv->accuracy.x = strtol(options[OPT_X].result, NULL, 0);
		priv->accuracy.y = strtol(options[OPT_Y].result, NULL, 0);
	}

	/* Setup mansync */
	MANSYNC_open(vis, priv);
	if (priv->mod_mansync == NULL) {
		fprintf(stderr,
			"display-monotext: Cannot load helper-mansync!\n");
		GGIclose_monotext(vis, dlh);
		goto err4;
	}

	MANSYNC_init(vis);
	if (!(LIBGGI_FLAGS(vis) & GGIFLAG_ASYNC)) {
		MANSYNC_start(vis);
	}

	/* Has mode management */
	vis->opdisplay->getmode   = GGI_palemu_getmode;
	vis->opdisplay->setmode   = GGI_palemu_setmode;
	vis->opdisplay->checkmode = GGI_monotext_checkmode;
	vis->opdisplay->getapi    = GGI_palemu_getapi;
	vis->opdisplay->flush     = GGI_palemu_flush;
	vis->opdisplay->setflags  = GGI_palemu_setflags;

	DPRINT("display-monotext: GGIopen succeeded.\n");

	*dlret = GGI_DL_OPDISPLAY;
	return 0;

err4:
	free(priv->opmansync);
err3:
	ggLockDestroy(priv->flush_lock);
err2:
	free(priv);
err1:
	free(LIBGGI_GC(vis));
err0:
	return err;
}
Exemple #13
0
static void testcase1(const char *desc)
{
	int ret;
	ggi_visual_t vis;
	ggi_mode mode;
	ggi_pixel pixel_color;
	ggi_color color_color;

#if 0
	unsigned int j, size;
	const ggi_directbuffer *dbuf = NULL;
#endif


	color_color.r = 0x0000;
	color_color.g = 0xffff;
	color_color.b = 0xffff;

	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;


	vis = ggNewStem(libggi, NULL);
	if (vis == NULL) {
		printfailure("Couldn't create stem for %s", DISPLAYSTR);
		return;
	}

	ret = ggiOpen(vis, DISPLAYSTR, NULL);
	if (ret != 0) {
		printfailure("Couldn't open %s", DISPLAYSTR);
		return;
	}

#if 0
	/* Here, XGGI would switch to async mode,
	 * if there were a place to hook in ggiFlush()
	 */
	ggiSetFlags(vis, GGIFLAG_ASYNC);
#endif

	/* Now check, if mansync is actually running
	 * - note, we are in sync mode here.
	 */

	/* stop mansync. If it runs as it should,
	 * we don't fail with an assertion here */
	ret = MANSYNC_stop(STEM_API_DATA(vis, libggi, struct ggi_visual*));
	if (ret != 0) {
		printfailure("BUG: mansync not running - forgot to call "
			"MANSYNC_start(vis) right after MANSYNC_init(vis)?\n");
		goto exit_testcase;
	}

	/* now restart it */
	ret = MANSYNC_start(STEM_API_DATA(vis, libggi, struct ggi_visual*));
	if (ret != 0) {
		printfailure("BUG: mansync couldn't be relaunched\n");
		goto exit_testcase;
	}

	ggiParseMode("", &mode);
	ggiCheckMode(vis, &mode);

	ret = ggiSetMode(vis, &mode);
	if (ret != GGI_OK) {
		printfailure("expected return value: \"%i\"\n"
			"actual return value: \"%i\"\n",
			GGI_OK, ret);
		goto exit_testcase;
	}

	/* Disable directbuffer as this is not required to
	 * perform the test
	 */

#if 0
	ret = -1;
	size = GT_SIZE(mode.graphtype);
	for (j = 0;
		(dbuf = ggiDBGetBuffer(vis, j)) != NULL;
	     j++)
	{
		if ((dbuf->type & GGI_DB_SIMPLE_PLB)
		    && ((8*dbuf->buffer.plb.stride) % size) == 0)
		{
			/* found */
			ret = GGI_OK;
			break;
		}
	}

	if (ret != GGI_OK) {
		printfailure("This mode and target has no suitable DirectBuffer\n");
		goto exit_testcase;
	}

	if (ggiResourceAcquire(dbuf->resource,
			GGI_ACTYPE_WRITE | GGI_ACTYPE_READ)
	   != 0)
	{
		printfailure("Unable to acquire DirectBuffer\n");
		goto exit_testcase;
	}
#endif

	/* ... and now draw something.
	 */
	pixel_color = ggiMapColor(vis, &color_color);
	ggiSetGCForeground(vis, pixel_color);
	ggiFillscreen(vis);

#if 0
	ggiResourceRelease(dbuf->resource);
#endif


exit_testcase:
	ggDelStem(vis);

	printsuccess();
	return;
}
void Init()
{
	GLfloat h=(GLfloat)3/4;
	GLfloat pos[4]={5,5,-20,0};
	GLfloat specular[4]={.4,.4,.4,1};
	GLfloat diffuse[4]={.3,.3,.3,1};
	GLfloat ambient[4]={.2,.2,.2,1};

	int err;

	if (ggiInit()<0)
	{
		printf("ggiInit() failed\n");
		exit(1);
	}
	ctx=GGIMesaCreateContext();
	if (ctx==NULL)
	{
		printf("Can't create Context!\n");
		exit(1);
	}

	vis=ggiOpen(NULL);
	vis_mem=ggiOpen("display-memory",NULL);
	if (vis==NULL || vis_mem==NULL)
	{
		printf("Can't open ggi_visuals!\n");
		exit(1);
	}	
	err=ggiSetGraphMode(vis,screen_x,screen_y,screen_x,screen_y,bpp);
	err+=ggiSetGraphMode(vis_mem,screen_x,screen_y,screen_x,screen_y,bpp);
	if (err)
	{
		printf("Can't set %ix%i\n",screen_x,screen_y);
		exit(1);
	}

	if (GGIMesaSetVisual(ctx,vis_mem,GL_TRUE,GL_FALSE)<0)
	{
		printf("GGIMesaSetVisual() failed!\n");
		exit(1);
	}

	GGIMesaMakeCurrent(ctx);

	glViewport(0,0,screen_x,screen_y);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1,1,-h,h,1,50);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0,0,-9);
	glShadeModel(GL_FLAT);

	glFrontFace(GL_CW);
	glEnable(GL_CULL_FACE);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	
	glLightfv(GL_LIGHT0,GL_POSITION,pos);
	
	glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
	glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
	glLightfv(GL_LIGHT0,GL_SPECULAR,specular);

	#ifdef ZBUFFER
		glEnable(GL_DEPTH_TEST);
	#endif
}
Exemple #15
0
/* Set the default mode and do all the work. We might want to split 
 * that later ...
 */
static int setup_mode(void)
{
	int i;
	ggi_color col;
	const ggi_directbuffer *buf;
	ggi_mode gmode;

	if ((visual=ggNewStem(NULL)) == NULL) {
		fprintf(stderr,
			"unable to create stem, exiting.\n");
		return -1;
	}

	if (ggiAttach(visual) < 0) {
		fprintf(stderr,
			"unable to attach ggi api, exiting.\n");
		return -1;
	}

	if (ggiOpen(visual, NULL) < 0) {
		fprintf(stderr,
			"unable to open default visual, exiting.\n");
		return -1;
	}

	ggiCheckSimpleMode(visual, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO,
			   &gmode);
	if (ggiSetMode(visual, &gmode) == 0) {
		printf("Graph mode %dx%d (%dx%d virt)\n",
		       gmode.visible.x, gmode.visible.y,
		       gmode.virt.x, gmode.virt.y);
	} else {
		fprintf(stderr, "Unable to set any mode at all!\n");
		ggiClose(visual);
		return -1;
	}

	col.r = 0xFFFF;
	col.g = 0xFFFF;
	col.b = 0xFFFF;
	printf("white = 0x%"PRIx32"\n", ggiMapColor(visual, &col));

	col.r = 0x0000;
	col.g = 0x0000;
	col.b = 0x0000;
	printf("black = 0x%"PRIx32"\n", ggiMapColor(visual, &col));

	printf("Pixelformat for Get/Put buffers:\n");
	print_pixfmt(ggiGetPixelFormat(visual));

	for (i = 0; ; i++) {
		int acquired = 0;

		buf = ggiDBGetBuffer(visual, i);
		if (buf == NULL) break;

		printf("DirectBuffer (frame #%d):\n", buf->frame);
		if (ggiResourceMustAcquire(buf->resource)) {
			switch (db_doacquire(buf)) {
			case 2:
				printf("Acquired DirectBuffer read/write\n");
				acquired = 1;
				break;
			case 1:
				printf("Acquired DirectBuffer for writing\n");
				acquired = 1;
				break;
			case 0:
				printf("Acquired DirectBuffer for read-only\n");
				acquired = 1;
				break;
			default:
				printf("DirectBuffer can not be Acquired!\n");
				break;
			}
		} else {
			printf("Does not need to be acquired\n");
		}

		printf("Mapped at read:%p, write:%p (paged %u)\n",
		       buf->read, buf->write, buf->page_size);
		switch (buf->layout) {
			case blPixelLinearBuffer: 
				printf("Layout: Linear Pixel Buffer\n");
				printf("Stride=%d\n", buf->buffer.plb.stride);
				printf("Pixelformat:\n");
				print_pixfmt(buf->buffer.plb.pixelformat);
				break;
			default: 
				printf("Layout: Unknown\n");
				break;	/* Skip it. Don't know it. */
		}
		if (acquired) ggiResourceRelease(buf->resource);
	}

	return 0;
}
Exemple #16
0
int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
	ggi_mode mode =
	{
		1,
		{ GGI_AUTO, GGI_AUTO },
		{ GGI_AUTO, GGI_AUTO },
		{ 0, 0 },
		GT_AUTO,
		{ GGI_AUTO, GGI_AUTO }
	};	
	struct private_hwdata *priv;
	ggi_color pal[256], map[256];
	const ggi_directbuffer *db;
	int err, num_bufs;
	ggi_pixel white, black;
	
	priv = SDL_malloc(sizeof(struct private_hwdata));
	if (priv == NULL)
	{
		SDL_SetError("Unhandled GGI mode type!\n");
		GGI_VideoQuit(NULL);
	}
	
	if (ggiInit() != 0)
	{
		SDL_SetError("Unable to initialize GGI!\n");
		GGI_VideoQuit(NULL);
	}
	
	VIS = ggiOpen(NULL);
	if (VIS == NULL)
	{
		SDL_SetError("Unable to open default GGI visual!\n");
		ggiExit();
		GGI_VideoQuit(NULL);
	}
	
	ggiSetFlags(VIS, GGIFLAG_ASYNC);
	
	/* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */
	ggiCheckMode(VIS, &mode);
	
	/* At this point we should have a valid mode - try to set it */
	err = ggiSetMode(VIS, &mode);
	
	/* If we couldn't set _any_ modes, something is very wrong */
	if (err)
	{
		SDL_SetError("Can't set a mode!\n");
		ggiClose(VIS);
		ggiExit();
		GGI_VideoQuit(NULL);
	}

	/* Determine the current screen size */
	this->info.current_w = mode.virt.x;
	this->info.current_h = mode.virt.y;

	/* Set a palette for palletized modes */
	if (GT_SCHEME(mode.graphtype) == GT_PALETTE)
	{
		ggiSetColorfulPalette(VIS);
		ggiGetPalette(VIS, 0, 1 << vformat->BitsPerPixel, pal);
	}
	
	/* Now we try to get the DirectBuffer info, which determines whether
	 * SDL can access hardware surfaces directly. */
	
	num_bufs = ggiDBGetNumBuffers(VIS);

	if (num_bufs > 0)
	{
		db = ggiDBGetBuffer(VIS, 0); /* Only handle one DB for now */
		
		vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth;
		
		vformat->Rmask = db->buffer.plb.pixelformat->red_mask;
		vformat->Gmask = db->buffer.plb.pixelformat->green_mask;
		vformat->Bmask = db->buffer.plb.pixelformat->blue_mask;
		
		/* Fill in our hardware acceleration capabilities */
	
		this->info.wm_available = 0;
		this->info.hw_available = 1;
		this->info.video_mem = db->buffer.plb.stride * mode.virt.y;
	}

	video_mode.x = 0;
	video_mode.y = 0;
	video_mode.w = mode.virt.x;
	video_mode.h = mode.virt.y;
	SDL_modelist[((vformat->BitsPerPixel + 7) / 8) - 1] = &video_mode;

	/* We're done! */
	return(0);
}
Exemple #17
0
int
main(int argc, char *argv[])
{
	int i;
	long binit, a_binit;
	long prev, curr;
	long aprev, acurr;

	fill_info();

	binit = get_size();
	a_binit = _get_ggi_alloced();
	if (ggiInit() != 0)
		err("first ggiInit() failed!\n");

	prev = get_size();
	aprev = _get_ggi_alloced();
	for (i=2; i <= 80; i++) {
		putchar('.');
		fflush(stdout);
		ggiExit();
		if (ggiInit() != 0)
			err("ggiInit() number %d failed\n", i);
	}
	curr = get_size();
	acurr = _get_ggi_alloced();
	inform_mem("\nggiInit()\n", prev, curr, aprev, acurr);

	if ((vis = ggiOpen(NULL)) == NULL)
		err("first ggiOpen() failed!\n");

	prev = get_size();
	aprev = _get_ggi_alloced();
	for (i=2; i < 20; i++) {
		putchar('.');
		fflush(stdout);
		ggiClose(vis);
		if ((vis = ggiOpen(NULL)) == NULL)
			err("ggiOpen() number %d failed\n", i);
	}
	curr = get_size();
	acurr = _get_ggi_alloced();
	inform_mem("\nggiOpen()\n", prev, curr, aprev, acurr);

	prev = get_size();
	aprev = _get_ggi_alloced();
	for (i=2; i < 20; i++) {
		putchar('.');
		fflush(stdout);
		ggiCheckSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO,
				   NULL);
	}
	curr = get_size();
	acurr = _get_ggi_alloced();
	inform_mem("\nggiCheckSimpleMode()\n", prev, curr, aprev, acurr);

	ggiSetFlags(vis, GGIFLAG_ASYNC);

	if (ggiSetSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO) != 0) {
		err("Unable to set default mode!\n");
	}
	prev = get_size();
	aprev = _get_ggi_alloced();
	for (i=2; i < 20; i++) {
		putchar('.');
		fflush(stdout);
		if (ggiSetSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO)
		    != 0) {
			err("Unable to set default mode %d!\n", i);
		}
	}
	curr = get_size();
	acurr = _get_ggi_alloced();
	inform_mem("\nggiSetSimpleMode()\n", prev, curr, aprev, acurr);

	ggiExit();

	curr = get_size();
	acurr = _get_ggi_alloced();
	inform_mem("\nggiExit()\n", binit, curr, a_binit, acurr);

	return 0;
}
Exemple #18
0
static void testcase4(const char *desc)
{
	int err;
	ggi_visual_t vis;
	ggi_mode mode;
	ggi_coord size;

	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	err = ggiCheckSimpleMode(
		vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode);
	printassert(err == GGI_OK, "ggiCheckSimpleMode: can't find a mode\n");
	if(err != GGI_OK) {
		ggiClose(vis);
		ggiExit();
		printsuccess();
		return;
	}

	printassert(mode.size.x != GGI_AUTO && mode.size.y != GGI_AUTO,
		"physical size is apparently not supported\n");
	if(mode.size.x == GGI_AUTO || mode.size.y == GGI_AUTO) {
		ggiClose(vis);
		ggiExit();
		printsuccess();
		return;
	}

	/* Clear out all but the physical size */
	mode.frames    = GGI_AUTO;
	mode.visible.x = GGI_AUTO;
	mode.visible.y = GGI_AUTO;
	mode.virt.x    = GGI_AUTO;
	mode.virt.y    = GGI_AUTO;
	mode.graphtype = GT_AUTO;
	mode.dpp.x     = GGI_AUTO;
	mode.dpp.y     = GGI_AUTO;

	size = mode.size;

	/* This mode should be there */
	err = ggiCheckMode(vis, &mode);
	ggiClose(vis);
	ggiExit();

	if (err != GGI_OK) {
		printfailure("ggiCheckMode: expected return value: GGI_OK\n"
					"actual return value: %i\n", err);
		return;
	}

	if (mode.size.x != size.x) {
		printfailure(
			"ggiCheckMode: size.x: expected return value: %i\n"
					"actual return value: %i\n",
			size.x, mode.size.x);
		return;
	}

	if (mode.size.y != size.y) {
		printfailure(
			"ggiCheckMode: size.y: expected return value: %i\n"
					"actual return value: %i\n",
			size.y, mode.size.y);
		return;
	}

	printsuccess();
}
Exemple #19
0
static void testcase1(const char *desc)
{
	int err;
	ggi_visual_t vis;
	ggi_mode mode;


	printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc);
	if (dontrun) return;

	err = ggiInit();
	printassert(err == GGI_OK, "ggiInit failed with %i\n", err);

	vis = ggiOpen(NULL);
	printassert(vis != NULL, "ggiOpen() failed\n");

	err = ggiCheckSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode);
	if (err == GGI_OK) {
		if (mode.visible.x == GGI_AUTO) {
			printfailure("visible.x: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.visible.y == GGI_AUTO) {
			printfailure("visible.y: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.virt.x == GGI_AUTO) {
			printfailure("virt.x: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.virt.y == GGI_AUTO) {
			printfailure("virt.y: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.size.x == GGI_AUTO) {
			printfailure("size.x: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.size.y == GGI_AUTO) {
			printfailure("size.y: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.frames == GGI_AUTO) {
			printfailure("frames: expected return value: != GGI_AUTO\n"
					"actual return value: GGI_AUTO\n");
			return;
		}
		if (mode.graphtype == GT_AUTO) {
			printfailure("graphtype: expected return value: != GT_AUTO\n"
					"actual return value: GT_AUTO\n");
			return;
		}
	}


	ggiClose(vis);
	ggiExit();

	printsuccess();
	return;
}
Exemple #20
0
int main(int argc, const char *argv[])
{
	ggi_visual_t vis;
	ggi_mode mode;
	int i, j, cx, cy, c;
	char buf[80];

	/* Set up the random number generator */
	srandom((unsigned)time(NULL));

	/* Initialize LibGGI */
	if (giiInit() < 0) {
		fprintf(stderr, "Cannot initialize LibGII!\n");
		return 1;
	}

	if (ggiInit() < 0) {
		fprintf(stderr, "Cannot initialize LibGGI!\n");
		giiExit();
		return 1;
	}

	vis = ggNewStem(NULL);
	if (!vis) {
		fprintf(stderr, "Cannot open create stem!\n");
		ggiExit();
		giiExit();
		return 1;
	}

	if (giiAttach(vis) < 0) {
		fprintf(stderr, "Cannot attach LibGII!\n");
		ggDelStem(vis);
		ggiExit();
		giiExit();
		return 1;
	}

	if (ggiAttach(vis) < 0) {
		fprintf(stderr, "Cannot attach LibGGI!\n");
		ggDelStem(vis);
		ggiExit();
		giiExit();
		return 1;
	}

	/* Open default visual */
	if (ggiOpen(vis, NULL) < 0) {
		fprintf(stderr, "Cannot open default visual!\n");
		ggDelStem(vis);
		ggiExit();
		giiExit();
		return 1;
	}

	/* Set visual to async mode (drawing not immediate) */
	ggiSetFlags(vis, GGIFLAG_ASYNC);

	/* Set default mode, but with multiple buffering */
	if (argc > 1) {
		ggiParseMode(argv[1], &mode);
	} else {
		ggiParseMode("", &mode);
		if (mode.frames < 2) mode.frames = 2;
	}

	if (ggiSetMode(vis, &mode)) {
		fprintf(stderr, "Cannot set mode!\n");
		ggDelStem(vis);
		ggiExit();
		giiExit();
		return 1;
	}

	ggiGetCharSize(vis, &cx, &cy);

	/* Setup palette */
	if (GT_SCHEME(mode.graphtype) == GT_PALETTE) {
		ggiSetColorfulPalette(vis);
	}

	/* Write something into each frame */
	for (i = 0; i < mode.frames; i++) {

		if (ggiSetWriteFrame(vis, i)) {
			fprintf(stderr, "Cannot set write frame!\n");
			ggDelStem(vis);
			ggiExit();
			giiExit();
			return 1;
		}

		ggiSetGCBackground(vis, ggiMapColor(vis, &white));
		ggiSetGCForeground(vis, ggiMapColor(vis, &white));
		ggiFillscreen(vis);
	}

	/* Clip a small border so that clipping can be verified. */
	ggiSetGCClipping(vis, 5, 5, mode.virt.x - 5, mode.virt.y - 5);

	/* Write something into each frame */
	for (i = 0; i < mode.frames; i++) {

		ggiSetWriteFrame(vis, i);

		ggiSetGCBackground(vis, ggiMapColor(vis, &black));
		ggiSetGCForeground(vis, ggiMapColor(vis, &black));
		ggiFillscreen(vis);

		snprintf(buf, sizeof(buf), "Hello World #%d!", i);

		for (j = 0; j < mode.virt.y; j += cy) {

			ggi_color col;

			int x = random() % mode.virt.x;

			int h = (random() & 0x7fff) + 0x8000;
			int l = (random() & 0x7fff);

			/* Use different colors for different frames */
			col.r = ((i + 1) & 1) ? h : l;
			col.g = ((i + 1) & 2) ? h : l;
			col.b = ((i + 1) & 4) ? h : l;

			ggiSetGCForeground(vis, ggiMapColor(vis, &col));
			ggiPuts(vis, x, j, buf);
		}
		/* Flush commands before proceeding to the next frame */
		ggiFlush(vis);
	}

	/* Cycle through frames */
	i = 0;
	j = 0;
	do {
		if (ggiSetDisplayFrame(vis, i)) {
			ggPanic("Cannot set display frame!\n");
		}

		/* Wait */
		c = GIIK_VOID;
		do {
			struct timeval tv = { 0, 0 };
			int key;

			/* Flush command before waiting for input */
			ggiFlush(vis);

			key = giiEventPoll(vis, emKeyPress, &tv);
			if (key & emKeyPress)
				c = giiGetc(vis);
			ggUSleep(50000);
			animate(vis, &mode, j);
			j++;
		} while (c == GIIK_VOID || GII_KTYP(c) == GII_KT_MOD);

		i = (i + 1) % mode.frames;

	} while (c != 'q' && c != 'Q' && c != 'x' && c != 'X' &&
		 c != GIIUC_Escape);

	ggiClose(vis);

	ggDelStem(vis);
	ggiExit();
	giiExit();
	return 0;
}
void graphicsinit(char *svgamode) //initialization of graphics, mode according to X_LOPIF
{
const short cur[32] =
	 { 0x9FFF, 0x0FFF, 0x07FF, 0x83FF, 0xC1FF, 0xE0FF, 0xF067, 0xF003,
	   0xF001, 0xF000, 0xF800, 0xF800, 0xF800, 0xFC00, 0xFC00, 0xFC00,
	   0x0000, 0x6000, 0x7000, 0x3800, 0x1C00, 0x0E00, 0x0700, 0x0018,
	   0x07EC, 0x07EE, 0x001E, 0x03EE, 0x03EE, 0x001E, 0x00EC, 0x0002 };


  xg_256=MM_Hic; //set Hicolor flag...
  initpalette();
  x_settextjusty(0,2);	// always write text from upper left corner

#ifdef GGI
// printf("Initializing GGI visual target.\n");
 ggiVis = ggiOpen (NULL);
 ggiGetMode (ggiVis, &origMode);
 ggiSetSimpleMode (ggiVis, 800, 600, 1, GT_16BIT);
 SVGAx=799;
 SVGAy=599;
 ggiAddFlags(ggiVis,GGIFLAG_ASYNC);
#else
 strupr(svgamode);
// printf("Console switched to graphics mode.\n");
 if(strstr(svgamode,".I"))
 {
  vga_setmode(G640x480x64K);
  gl_setcontextvga(G640x480x64K);
  SVGAx=639;
  SVGAy=479;
 }
 else
 if(strstr(svgamode,".K"))
 {
  vga_setmode(G1024x768x64K);
  gl_setcontextvga(G1024x768x64K);
  SVGAx=1023;
  SVGAy=767;
 }
 else
 if(strstr(svgamode,".L"))
 {
  vga_setmode(G1280x1024x64K);
  gl_setcontextvga(G1280x1024x64K);
  SVGAx=1279;
  SVGAy=1023;
 }
 if(strstr(svgamode,".M"))
 {
  vga_setmode(G1600x1200x64K);
  gl_setcontextvga(G1600x1200x64K);
  SVGAx=1599;
  SVGAy=1199;
 }
 {
  vga_setmode(G800x600x64K);
  gl_setcontextvga(G800x600x64K);
  SVGAx=799;
  SVGAy=599;
 }
 vga_runinbackground(1);
 vga_oktowrite();
 gl_setwritemode(FONT_COMPRESSED|WRITEMODE_MASKED);
 gl_setfontcolors(0,vga_white());
 //gl_setfont(8,8,gl_font8x8);
 gl_setrgbpalette();
 gl_enableclipping();
#endif
 x_defcurs( (short *)cur, (short *)&cur[16], 15); //mouse kursor
}