예제 #1
0
//************************************************************************************************
// 	cMenu::Show()
//************************************************************************************************
EMenuValue cMenu::Show(int rc_fd)
{
    IMPORT_FRAMEBUFFER_VARS;
    
    STORE_PALETTE(&colormap);
    
    gl_fillbox(0, 0, p_xsize, p_ysize, TRANSP);
    Draw();
    //ShowOsd(True);
    int rccode;
    while( 1 )
    {
	cMenu::GetRCCode(rc_fd, rccode);
	if(!ProcessKey(rccode))
	    break;
	    
	if (m_RetValue != eMVNone)
	    break;
    }
    
    gl_fillbox(0, 0, p_xsize, p_ysize, TRANSP);
    STORE_PALETTE(NULL);
    SendFramebufferUpdateRequest(0, 0, p_xsize, p_ysize, False);
    
    return m_RetValue;
}
예제 #2
0
파일: main-lsl.c 프로젝트: AmyBSOD/ToME-SX
/*
 * Low-level graphics routine (assumes valid input)
 * Do a "special thing"
 */
static errr term_xtra_svgalib(int n, int v)
{
	switch (n)
	{
	case TERM_XTRA_EVENT:
		{
			/* Process some pending events */
			if (v) return (CheckEvents (FALSE));
			while (!CheckEvents (TRUE));
			return 0;
		}

	case TERM_XTRA_FLUSH:
		{
			/* Flush all pending events */
			/* Should discard all key presses but unimplemented */
			return 0;
		}

	case TERM_XTRA_CLEAR:
		{
			/* Clear the entire window */
			gl_fillbox (0, 0, 80 * CHAR_W, 25 * CHAR_H, 0);
			return 0;
		}

	case TERM_XTRA_DELAY:
		{
			/* Delay for some milliseconds */
			usleep(1000 * v);
			return 0;
		}
	}
	return 1;
}
예제 #3
0
파일: graphic.cpp 프로젝트: shihyu/progs
Graphic::Graphic()
{
#ifdef SVGALIB
  init_graph_mode();
  gl_fillbox(0,0,640,480, 200);
#endif
}
예제 #4
0
int GGI_vgagl_fillscreen(ggi_visual *vis)
{
	if (LIBGGICLIP_FULLSCREEN(vis)) {
		gl_clearscreen(LIBGGI_GC_FGCOLOR(vis));
	} else {
		gl_fillbox(LIBGGI_GC(vis)->cliptl.x, LIBGGI_GC(vis)->cliptl.y,
			   LIBGGI_GC(vis)->clipbr.x - LIBGGI_GC(vis)->cliptl.x,
			   LIBGGI_GC(vis)->clipbr.y - LIBGGI_GC(vis)->cliptl.y,
			   LIBGGI_GC_FGCOLOR(vis));
	}

	return 0;
}
예제 #5
0
//! [4]
void SvgalibScreen::solidFill(const QColor &color, const QRegion &reg)
{
    int c;
    if (depth() == 4 || depth() == 8)
        c = alloc(color.red(), color.green(), color.blue());
    else
        c = gl_rgbcolor(color.red(), color.green(), color.blue());

    const QVector<QRect> rects = (reg & region()).rects();
    for (int i = 0; i < rects.size(); ++i) {
        const QRect r = rects.at(i);
        gl_fillbox(r.left(), r.top(), r.width(), r.height(), c);
    }
}
예제 #6
0
void boxes(void)
{
    int x, y;
    for (x = 0; x <= VWIDTH - 8; x += 8)
	for (y = 0; y <= VHEIGHT - 8; y += 8) {
	    int r, g, b;
	    /* Draw red tiles. */
	    r = rand() & 255;
	    b = 0;
	    g = 0;
	    if ((rand() & 15) == 15) {	/* Add occasional */
		r = 0;		/* blue specks. */
		b = rand() & 127;
	    }
	    gl_fillbox(x, y, 7, 7, gl_rgbcolor(r, g, b));
	}
}
예제 #7
0
void sysdep_display_driver_clear_buffer(void)
{
  int line;
  switch(video_update_type)
  {
    case 0: /* linear */
      for (line=0; line<scaled_height; line++)
        memset(video_mem + line*video_modeinfo.linewidth, 0,
          scaled_width*video_modeinfo.bytesperpixel);
      break;
    case 1: /* gl bitmap equals framebuffer */
      gl_fillbox(startx, starty, scaled_width, scaled_height, 0);
      break;
    case 2: /* gl bitmap needs conversion before it can be blitted */
      memset(doublebuffer_buffer, 0,
        scaled_width * scaled_height * video_modeinfo.bytesperpixel);
      break;
  }
}
예제 #8
0
void x_bar(int xz, int yz, int xk, int yk)
{
#ifndef TXTDEBUG
#ifdef	GGI
 ggiSetGCForeground (ggiVis, ggi_getcolor (xg_fillc));
 ggiDrawBox (ggiVis, xz, yz, xk-xz+1, yk-yz+1);
#else
 unsigned char *palptr = xg_hipal + 3*xg_fillc;
 int r, g, b;

 r = ((int) (*palptr++)) << 2;
 g = ((int) (*palptr++)) << 2;
 b = ((int) (*palptr)) << 2;

 //printf ("box (%d): %d %d %d\n", xg_fillc, r, g, b);
 // rectangle filled with background color
 gl_fillbox(xz,yz,xk-xz+1,yk-yz+1,
   gl_rgbcolor(r,g,b));
#endif
#endif
}
예제 #9
0
파일: main-lsl.c 프로젝트: AmyBSOD/ToME-SX
/*
 * Low-level graphics routine (assumes valid input)
 * Erases a rectangular block of characters from (x,y) to (x+w,y+h)
 */
static errr term_wipe_svgalib(int x, int y, int n)
{
	gl_fillbox(x * CHAR_W, y * CHAR_H, n * CHAR_W, CHAR_H, 0);
	return (0);
}
예제 #10
0
파일: main-lsl.c 프로젝트: AmyBSOD/ToME-SX
/*
 * Low-level graphics routine (assumes valid input)
 * Draws a "cursor" at (x,y)
 */
static errr term_curs_svgalib(int x, int y)
{
	gl_fillbox(x * CHAR_W, y * CHAR_H, CHAR_W, CHAR_H, 15);
	return (0);
}
예제 #11
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());
}
void main(void)
{
    struct timeval timeout;
    fd_set inputs;
    char bitmap[16 * 16 * 4];	/* big enough for 10x10 bitmap in any mode */
    int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5;
    char loop = 1, drawcursor = 1;
#ifdef USE_RAWKEYBOARD
    char space_pressed = 0;
#endif

    puts("This is a demo showing the abilities of the new vga_waitevent() function\n"
	 "If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n"
	 "to bailout if in doubt.\n"
	 "Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n"
    "cursor color. Left button to draw. Right button or 'Q' to bailout.\n"
	 "The cursor goes on/off every half second by usage of a timeout passed to\n"
	 "vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n"
	 "asynchronously and is displayed by the frontend.");
#ifdef USE_RAWKEYBOARD
    puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n"
	 "render the console unusable. (but shouldn't).");
#endif
    fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout);
    fflush(stdout);
    getchar();
    fflush(stdin);		/* clear I/O buffer */

    pipe(pipefd);
    if (fork() == 0) {		/* fork off b4 touching graphix to avoid side effects */
	close(pipefd[0]);	/* Important: close reading side, else it remains     */
	/* opened by child when parent exits and we don't get */
	/* a SIGPIPE!                                         */
	child(pipefd[1]);
    }
    vga_init();
    vgamode = vga_getdefaultmode();
    if (vgamode == -1)
	vgamode = G320x200x256;

    if (!vga_hasmode(vgamode)) {
	printf("Mode not available.\n");
	exit(-1);
    }
    /* Enable automatic mouse setup at mode set. */
    vga_setmousesupport(1);
    vga_setmode(vgamode);
    /* Disable wrapping (default). */
    /* mouse_setwrap(MOUSE_NOWRAP); */
    gl_setcontextvga(vgamode);
    gl_enableclipping();

    /* There might be some scrap data in the serial buffer
       from the mouse. It will make vga_waitevent block
       because it thinks the mouse wants to send data but
       then no mouse packet arrives. */
    color = newcolor();
    x = 0;
    y = 0;
    gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED);
    gl_setfont(8, 8, gl_font8x8);
    gl_setfontcolors(0, newcolor());

#ifdef USE_RAWKEYBOARD
    if (keyboard_init()) {
	printf("Could not initialize keyboard.\n");
	exit(1);
    }
#endif

    while (loop) {
	gl_getbox(x, y, 10, 10, bitmap);
	if (drawcursor) {
	    gl_hline(x, y, x + cursorsize, color);
	    gl_hline(x, y + cursorsize, x + cursorsize, color);
	    gl_line(x, y, x, y + cursorsize, color);
	    gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color);
	}
	FD_ZERO(&inputs);
	FD_SET(pipefd[0], &inputs);
	timeout.tv_sec = 0;
	timeout.tv_usec = 500000;	/* 0.5 second time out */
	event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT,
			      &inputs, NULL, NULL, &timeout);
	gl_putbox(x, y, 10, 10, bitmap);
	if (timeout.tv_sec || timeout.tv_usec) {
	    /* No timeout. An actual event occured. Reset to visible
	       cursor. Note:
	       This is actually a bug as the cursor will get visible on time
	       updates. However, it's better this way for demo/test
	       purposes. */
	    drawcursor = 1;
	} else {
	    drawcursor ^= 1;
	}
	if (FD_ISSET(pipefd[0], &inputs))
	    process_input(pipefd[0]);
	if (event & VGA_MOUSEEVENT) {
	    x = mouse_getx();
	    y = mouse_gety();
	    button = mouse_getbutton();
	    if (button & MOUSE_LEFTBUTTON)
		gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color);
	    if (button & MOUSE_RIGHTBUTTON)
		loop = 0;
	}
	if (event & VGA_KEYEVENT) {
#ifdef USE_RAWKEYBOARD
	    if (keyboard_keypressed(SCANCODE_1))
		cursorsize = 0;
	    if (keyboard_keypressed(SCANCODE_2))
		cursorsize = 1;
	    if (keyboard_keypressed(SCANCODE_3))
		cursorsize = 2;
	    if (keyboard_keypressed(SCANCODE_4))
		cursorsize = 3;
	    if (keyboard_keypressed(SCANCODE_5))
		cursorsize = 4;
	    if (keyboard_keypressed(SCANCODE_6))
		cursorsize = 5;
	    if (keyboard_keypressed(SCANCODE_7))
		cursorsize = 6;
	    if (keyboard_keypressed(SCANCODE_8))
		cursorsize = 7;
	    if (keyboard_keypressed(SCANCODE_9))
		cursorsize = 8;
	    if (keyboard_keypressed(SCANCODE_0))
		cursorsize = 9;
	    if (keyboard_keypressed(SCANCODE_Q))
		loop = 0;
	    if (keyboard_keypressed(SCANCODE_SPACE)) {
		if (!space_pressed) {
		    color = newcolor();
		    space_pressed = 1;
		}
	    } else {
		space_pressed = 0;
	    }
#else
	    switch (vga_getch()) {
	    case '1':
		cursorsize = 0;
		break;
	    case '2':
		cursorsize = 1;
		break;
	    case '3':
		cursorsize = 2;
		break;
	    case '4':
		cursorsize = 3;
		break;
	    case '5':
		cursorsize = 4;
		break;
	    case '6':
		cursorsize = 5;
		break;
	    case '7':
		cursorsize = 6;
		break;
	    case '8':
		cursorsize = 7;
		break;
	    case '9':
		cursorsize = 8;
		break;
	    case '0':
		cursorsize = 9;
		break;
	    case ' ':
		color = newcolor();
		break;
	    case 'q':
	    case 'Q':
		loop = 0;
		break;
	    default:
		ping();
		break;
	    }
#endif
	}
    }

#ifdef USE_RAWKEYBOARD
    keyboard_close();		/* Don't forget this! */
#endif
    vga_setmode(TEXT);
    exit(0);
}
예제 #13
0
void test(void)
{
    int i, j;
    unsigned char *bitmap;
    GraphicsContext *savedcontext;

    if (VIRTUAL)
	gl_setcontext(backscreen);

    gl_clearscreen(0);
    for (i = 0; i < 5; i++) {
	gl_clearscreen(0);
	for (j = 0; j < 20000; j++)
	    gl_setpixel(random() % WIDTH, random() % HEIGHT,
			random() % COLORS);
    }

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    gl_clearscreen(0);
    for (i = 0; i < 5000; i++) {
	int x, y;
	x = random() % (WIDTH - 1);
	y = random() % (HEIGHT - 1);
	gl_fillbox(x, y, random() % (WIDTH - x), random()
		   % (HEIGHT - y), random() % COLORS);
    }

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    gl_clearscreen(0);
    for (i = 0; i < 4000; i++)
	gl_line(random() % WIDTH, random() % HEIGHT,
		random() % WIDTH, random() % HEIGHT,
		random() % COLORS);

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    /* Create bitmap. */
    bitmap = malloc(64 * 64 * BYTESPERPIXEL);
    /* Create temporary graphics context to create bitmap in. */
    savedcontext = gl_allocatecontext();
    gl_getcontext(savedcontext);
    gl_setcontextvirtual(64, 64, BYTESPERPIXEL, BITSPERPIXEL, bitmap);
    /* The rgb functions can be used to create nice bitmaps easily for */
    /* hicolor/truecolor modes. The 256 color 'emulated' truecolor */
    /* looks less impressive. */
    for (i = 0; i < 32; i++)
	for (j = 0; j < 32; j++) {
	    int c;
	    c = 255 - (i + j) * 4;
	    gl_setpixelrgb(31 - i, 31 - j, c, 0, 0);
	    gl_setpixelrgb(32 + i, 31 - j, c, c, 0);
	    gl_setpixelrgb(31 - i, 32 + j, c, 0, c);
	    gl_setpixelrgb(32 + i, 32 + j, c, c, c);
	}
    /* Restore previous context. */
    gl_setcontext(savedcontext);

    gl_clearscreen(0);
    for (i = 0; i < 4000; i++) {
	int x, y;
	x = random() % (WIDTH - 64 + 1);
	y = random() % (HEIGHT - 64 + 1);
	gl_putbox(x, y, 64, 64, bitmap);
    }

    free(bitmap);

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);
}
예제 #14
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);
}