예제 #1
0
파일: draw.c 프로젝트: alannet/example
	int main(int argc, char *argv[])
	{
		
		int i;
		int oldmode;
		int mode = G320x200x256;
		int width, height, colors;

		//获得当前的模式
		oldmode = vga_getcurrentmode();

		//初始化
		vga_init();

		//判断是否支持该模式
		if(vga_hasmode(mode)) 
			vga_setmode(mode);
		else {
			printf("No such mode\n");
			exit(1);
		}
		//取得信息
		width = vga_getxdim();
		height = vga_getydim();
		colors = vga_getcolors();

		//绘图
		for(i=0; i<colors; i++){
			vga_setcolor(i);
			vga_drawline(0, i, width-1, i);
		}
			

		vga_setcolor(3);
		for(i=0; i<50; i++) vga_drawpixel(i*4, 20);

		vga_setcolor(4);
		vga_drawline(100, 100, 300, 200);

		vga_setcolor(5);
		vga_drawline(0, 0, width-1, 0);
		vga_drawline(0, height-1, width-1, height-1);
		vga_drawline(0, 0, 0, height-1);
		vga_drawline(width-1, 0, width-1, height-1);

		//等待按键
		while(!vga_getkey());

		//恢复原来的模式 
		vga_setmode(oldmode);

		return 0;
	}
예제 #2
0
void VID_SetPalette (byte *palette)
{
	static int	tmppal[256*3];
	int		*tp;
	int		i;

	if (!svgalib_inited)
		return;
	if (svgalib_backgrounded)
		return;

	memcpy(vid_current_palette, palette, sizeof(vid_current_palette));

	if (vga_getcolors() == 256)
	{
		tp = tmppal;
		for (i = 256 * 3; i; i--)
			*(tp++) = *(palette++) >> 2;

		if (vga_oktowrite())
			vga_setpalvec(0, 256, tmppal);
	}
예제 #3
0
/*
** SWimp_SetPalette
**
** System specific palette setting routine.  A NULL palette means
** to use the existing palette.  The palette is expected to be in
** a padded 4-byte xRGB format.
*/
void SWimp_SetPalette( const unsigned char *palette )
{
	static int tmppal[256*3];
	const unsigned char *pal;
	int *tp;
	int i;

    if ( !palette )
        palette = ( const unsigned char * ) sw_state.currentpalette;
 
	if (vga_getcolors() == 256)
	{
		tp = tmppal;
		pal = palette;

		for (i=0 ; i < 256 ; i++, pal += 4, tp += 3) {
			tp[0] = pal[0] >> 2;
			tp[1] = pal[1] >> 2;
			tp[2] = pal[2] >> 2;
		}

		if (vga_oktowrite())
			vga_setpalvec(0, 256, tmppal);
	}
예제 #4
0
void SvgalibScreen::initColorMap()
{
    const int numColors = vga_getcolors();
    if (numColors == 2 || numColors > 256) {
        screencols = 0;
        return; // not a palette based mode
    }

    if (numColors == 16) {
        if (grayscale) {
            for (int i = 0; i < 256; ++i) {
                const int c = i * 16 / 256;
                vga_setpalette(i, c, c, c);
            }
            screencols = 256; // XXX: takes advantage of optimization in alloc()
        } else { // read in EGA palette
            int r, g, b;
            for (int i = 0; i < 16; ++i) {
                vga_getpalette(i, &r, &g, &b);
                screenclut[i] = qRgb(r, g, b);
            }
            screencols = 16;
        }

        return;
    }

    Q_ASSERT(numColors == 256);

    if (grayscale) {
        for (int i = 0; i < 256; ++i) {
            const int c = i * 64 / 256;
            vga_setpalette(i, c, c, c);
        }
    } else {
        int i = 0;

#if 0
        // read in EGA palette
        while (i < 16) {
            int r, g, b;
            vga_getpalette(i, &r, &g, &b);
            screenclut[i] = qRgb(r, g, b);
            ++i;
        }
        screencols = 16;
#endif

        // 6 * 6 * 6 color cube
        for (int r = 0; r < 6; ++r) {
            for (int g = 0; g < 6; ++g) {
                for (int b = 0; b < 6; ++b) {
                    vga_setpalette(i, r * 64/6, g * 64/6, b * 64/6);
                    screenclut[i] = qRgb(r * 256/6, g * 256/6, b * 256/6);
                    ++i;
                }
            }
        }
        screencols = i;

        while (i < 256) {
            screenclut[i] = qRgb(0, 0, 0);
            ++i;
        }
    }
}
예제 #5
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();

}