Beispiel #1
0
static int
try_allocate(Parrot_Interp interpreter, IMC_Unit * unit)
{
    int x = 0;
    int color, colors[MAX_COLOR];
    int free_colors, t;
    SymReg ** graph = interference_graph;
    SymReg ** reglist = unit->reglist;

    while ((imcstack_depth(nodeStack) > 0) ) {
	x=imcstack_pop(nodeStack);

	for (t = 0; t < 4; t++) {
	    int typ = "INSP"[t];
	    memset(colors, 0, sizeof(colors));
	    if (reglist[x]->set == typ && reglist[x]->color == -1) {
		free_colors = map_colors(x, graph, colors, typ);
		if (free_colors > 0) {
		    for (color = 0; color < MAX_COLOR; color++) {
                        int c = (color + 16) % 32;
			if (!colors[c]) {
			    reglist[x]->color = c;

                            debug(interpreter, DEBUG_IMC,
                                    "#[%s] provisionally gets color [%d]"
                                     "(%d free colors, score %d)\n",
					reglist[x]->name, c,
                                        free_colors, reglist[x]->score);
			    break;
			}
		    }
		}

		if (reglist[x]->color == -1) {
                    debug(interpreter, DEBUG_IMC, "# no more colors free = %d\n", free_colors);

		    /* It has been impossible to assign a color
                     * to this node, return it so it gets spilled
                     */

		    restore_interference_graph(unit);
		    /* clean stack */
		    while ((imcstack_depth(nodeStack) > 0) )
			imcstack_pop(nodeStack);
		    return x;
		}
	    }
	}
    }

    return -1; /* we are totally finished */
}
Beispiel #2
0
main(int argc, char **argv)
{
    int colors;
    struct {
        long nplanes;
        long pbytes;
        long across;
        long down;
        long npics;
        long xsize;
        long ysize;
    } pdat;
    long pbytes; /* Bytes of data in a plane */
    int i, cnt;
    BitMapHeader bmhd;
    struct IFFHandle *iff;
    long camg = HIRES | LACE;
    int tiles = 0;
    char **planes;

    if (argc != 3) {
        fprintf(stderr, "Usage: %s source destination\n", argv[0]);
        exit(1);
    }

#if defined(_DCC) || defined(__GNUC__)
    IFFParseBase = OpenLibrary("iffparse.library", 0);
    if (!IFFParseBase) {
        error("unable to open iffparse.library");
        exit(1);
    }
#endif

    /* First, count the files in the file */
    if (fopen_text_file(argv[1], "r") != TRUE) {
        perror(argv[1]);
        return (1);
    }

    nplanes = 0;
    i = colorsinmap - 1; /*IFFScreen.Colors - 1; */
    while (i != 0) {
        nplanes++;
        i >>= 1;
    }

    planes = malloc(nplanes * sizeof(char *));
    if (planes == 0) {
        error("can not allocate planes pointer");
        exit(1);
    }

    while (read_text_tile(pixels) == TRUE)
        ++tiles;
    fclose_text_file();

    IFFScreen.Width = COLS * TILE_X;
    IFFScreen.Height = ROWS * TILE_Y;

    pbytes = (COLS * ROWS * TILE_X + 15) / 16 * 2 * TILE_Y;

    for (i = 0; i < nplanes; ++i) {
        planes[i] = calloc(1, pbytes);
        if (planes[i] == 0) {
            error("can not allocate planes pointer");
            exit(1);
        }
    }

    /* Now, process it */
    if (fopen_text_file(argv[1], "r") != TRUE) {
        perror(argv[1]);
        return (1);
    }

    iff = AllocIFF();
    if (!iff) {
        error("Can not allocate IFFHandle");
        return (1);
    }

    iff->iff_Stream = Open(argv[2], MODE_NEWFILE);
    if (!iff->iff_Stream) {
        error("Can not open output file");
        return (1);
    }

    InitIFFasDOS(iff);
    OpenIFF(iff, IFFF_WRITE);

    PushChunk(iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN);

    bmhd.w = IFFScreen.Width;
    bmhd.h = IFFScreen.Height;
    bmhd.x = 0;
    bmhd.y = 0;
    bmhd.nPlanes = nplanes;
    bmhd.masking = 0;
    bmhd.compression = 0;
    bmhd.reserved1 = 0;
    bmhd.transparentColor = 0;
    bmhd.xAspect = 100;
    bmhd.yAspect = 100;
    bmhd.pageWidth = TILE_X;
    bmhd.pageHeight = TILE_Y;

    PushChunk(iff, ID_BMAP, ID_BMHD, sizeof(bmhd));
    WriteChunkBytes(iff, &bmhd, sizeof(bmhd));
    PopChunk(iff);

    PushChunk(iff, ID_BMAP, ID_CAMG, sizeof(camg));
    WriteChunkBytes(iff, &camg, sizeof(camg));
    PopChunk(iff);

    /* We need to reorder the colors to get reasonable default pens but
     * we also need to know where some of the colors are - so go find out.
     */
    map_colors();

    cmap = malloc((colors = (1L << nplanes)) * sizeof(AmiColorMap));
    for (i = 0; i < colors; ++i) {
        cmap[colrmap[i]].r = ColorMap[CM_RED][i];
        cmap[colrmap[i]].g = ColorMap[CM_GREEN][i];
        cmap[colrmap[i]].b = ColorMap[CM_BLUE][i];
    }

    PushChunk(iff, ID_BMAP, ID_CMAP, IFFSIZE_UNKNOWN);
    for (i = 0; i < colors; ++i)
        WriteChunkBytes(iff, &cmap[i], 3);
    PopChunk(iff);

    cnt = 0;
    while (read_text_tile(pixels) == TRUE) {
        packwritebody(pixels, planes, cnt);
        if (cnt % 20 == 0)
            printf("%d..", cnt);
        ++cnt;
        fflush(stdout);
    }

    pdat.nplanes = nplanes;
    pdat.pbytes = pbytes;
    pdat.xsize = TILE_X;
    pdat.ysize = TILE_Y;
    pdat.across = COLS;
    pdat.down = ROWS;
    pdat.npics = cnt;

    PushChunk(iff, ID_BMAP, ID_PDAT, IFFSIZE_UNKNOWN);
    WriteChunkBytes(iff, &pdat, sizeof(pdat));
    PopChunk(iff);

    PushChunk(iff, ID_BMAP, ID_PLNE, IFFSIZE_UNKNOWN);
    for (i = 0; i < nplanes; ++i)
        WriteChunkBytes(iff, planes[i], pbytes);
    PopChunk(iff);

    CloseIFF(iff);
    Close(iff->iff_Stream);
    FreeIFF(iff);

    printf("\n%d tiles converted\n", cnt);

#if defined(_DCC) || defined(__GNUC__)
    CloseLibrary(IFFParseBase);
#endif
    exit(0);
}
Beispiel #3
0
static int
curses_init(const struct sessmgr_sw *sm)
{
    extern int Numrows, Numcols;

    if (!isatty(0))
	return 0;
    if (initted)
    {
#ifdef RAW_SESSMGR
	set_curterm(my_term);
#endif
	refresh();		/* bring curses back to life */
    }
    else
    {
	initscr();			/* be nice to trap errors... */
#ifdef COLOR_SUPPORT
	/*
	 * I assume the curses manpage tells the truth when it claims that
	 * colors are initialized to RGB defaults.  If not, I may need to set
	 * up the colors in question...
	 */
	if (has_colors() && start_color() != ERR && COLORS >= 8)
	{
	    color_pair_map = mallocw(COLOR_PAIRS * sizeof *color_pair_map);
	    memset(color_pair_map, -1, COLOR_PAIRS * sizeof *color_pair_map);
	    map_colors(COLOR_BLACK, COLOR_WHITE); /* default color pair */
            if(!MainColors) MainColors = LIGHTGRAY+(BLACK<<4); /* not high-intensity */
	}
        else MainColors = 0;  /* no colors available */
#endif
	my_term = cur_term;
	noecho();
	nonl();
	raw();
	keys = key_init();
	key_add(key_down, DNARROW);
	key_add(key_f1, -3);
	key_add(key_f2, -4);
	key_add(key_f3, -5);
	key_add(key_f4, -6);
	key_add(key_f5, -7);
	key_add(key_f6, -8);
	key_add(key_f7, -9);
	key_add(key_f8, -10);
	key_add(key_f9, -11);
#ifdef M_UNIX
	/* SCO botches it, as per usual */
	key_add(key_f0, -2);
#else
	key_add(key_f10, -2);
#endif
	key_add(key_left, LTARROW);
	key_add(key_right, RTARROW);
	key_add(key_up, UPARROW);
	key_add("\177", '\b');	/* so DEL behaves as BS */
	initted = 1;
    }
    Suspense = 0;
    Numrows = LINES;
    Numcols = COLS;
    return 1;
}