test/threadwin.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
     1.1 --- a/test/threadwin.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/test/threadwin.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -15,323 +15,327 @@
     1.4  static int visible = 1;
     1.5  
     1.6  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.7 -static void quit(int rc)
     1.8 +static void
     1.9 +quit (int rc)
    1.10  {
    1.11 -	SDL_Quit();
    1.12 -	exit(rc);
    1.13 +    SDL_Quit ();
    1.14 +    exit (rc);
    1.15  }
    1.16  
    1.17 -SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
    1.18 +SDL_Surface *
    1.19 +LoadIconSurface (char *file, Uint8 ** maskp)
    1.20  {
    1.21 -	SDL_Surface *icon;
    1.22 -	Uint8       *pixels;
    1.23 -	Uint8       *mask;
    1.24 -	int          mlen, i;
    1.25 +    SDL_Surface *icon;
    1.26 +    Uint8 *pixels;
    1.27 +    Uint8 *mask;
    1.28 +    int mlen, i;
    1.29  
    1.30 -	*maskp = NULL;
    1.31 +    *maskp = NULL;
    1.32  
    1.33 -	/* Load the icon surface */
    1.34 -	icon = SDL_LoadBMP(file);
    1.35 -	if ( icon == NULL ) {
    1.36 -		fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
    1.37 -		return(NULL);
    1.38 -	}
    1.39 +    /* Load the icon surface */
    1.40 +    icon = SDL_LoadBMP (file);
    1.41 +    if (icon == NULL) {
    1.42 +        fprintf (stderr, "Couldn't load %s: %s\n", file, SDL_GetError ());
    1.43 +        return (NULL);
    1.44 +    }
    1.45  
    1.46 -	/* Check width and height */
    1.47 -	if ( (icon->w%8) != 0 ) {
    1.48 -		fprintf(stderr, "Icon width must be a multiple of 8!\n");
    1.49 -		SDL_FreeSurface(icon);
    1.50 -		return(NULL);
    1.51 -	}
    1.52 -	if ( icon->format->palette == NULL ) {
    1.53 -		fprintf(stderr, "Icon must have a palette!\n");
    1.54 -		SDL_FreeSurface(icon);
    1.55 -		return(NULL);
    1.56 -	}
    1.57 +    /* Check width and height */
    1.58 +    if ((icon->w % 8) != 0) {
    1.59 +        fprintf (stderr, "Icon width must be a multiple of 8!\n");
    1.60 +        SDL_FreeSurface (icon);
    1.61 +        return (NULL);
    1.62 +    }
    1.63 +    if (icon->format->palette == NULL) {
    1.64 +        fprintf (stderr, "Icon must have a palette!\n");
    1.65 +        SDL_FreeSurface (icon);
    1.66 +        return (NULL);
    1.67 +    }
    1.68  
    1.69 -	/* Set the colorkey */
    1.70 -	SDL_SetColorKey(icon, SDL_SRCCOLORKEY, *((Uint8 *)icon->pixels));
    1.71 +    /* Set the colorkey */
    1.72 +    SDL_SetColorKey (icon, SDL_SRCCOLORKEY, *((Uint8 *) icon->pixels));
    1.73  
    1.74 -	/* Create the mask */
    1.75 -	pixels = (Uint8 *)icon->pixels;
    1.76 -	printf("Transparent pixel: (%d,%d,%d)\n",
    1.77 -				icon->format->palette->colors[*pixels].r,
    1.78 -				icon->format->palette->colors[*pixels].g,
    1.79 -				icon->format->palette->colors[*pixels].b);
    1.80 -	mlen = icon->w*icon->h;
    1.81 -	mask = (Uint8 *)malloc(mlen/8);
    1.82 -	if ( mask == NULL ) {
    1.83 -		fprintf(stderr, "Out of memory!\n");
    1.84 -		SDL_FreeSurface(icon);
    1.85 -		return(NULL);
    1.86 -	}
    1.87 -	memset(mask, 0, mlen/8);
    1.88 -	for ( i=0; i<mlen; ) {
    1.89 -		if ( pixels[i] != *pixels )
    1.90 -			mask[i/8] |= 0x01;
    1.91 -		++i;
    1.92 -		if ( (i%8) != 0 )
    1.93 -			mask[i/8] <<= 1;
    1.94 -	}
    1.95 -	*maskp = mask;
    1.96 -	return(icon);
    1.97 +    /* Create the mask */
    1.98 +    pixels = (Uint8 *) icon->pixels;
    1.99 +    printf ("Transparent pixel: (%d,%d,%d)\n",
   1.100 +            icon->format->palette->colors[*pixels].r,
   1.101 +            icon->format->palette->colors[*pixels].g,
   1.102 +            icon->format->palette->colors[*pixels].b);
   1.103 +    mlen = icon->w * icon->h;
   1.104 +    mask = (Uint8 *) malloc (mlen / 8);
   1.105 +    if (mask == NULL) {
   1.106 +        fprintf (stderr, "Out of memory!\n");
   1.107 +        SDL_FreeSurface (icon);
   1.108 +        return (NULL);
   1.109 +    }
   1.110 +    memset (mask, 0, mlen / 8);
   1.111 +    for (i = 0; i < mlen;) {
   1.112 +        if (pixels[i] != *pixels)
   1.113 +            mask[i / 8] |= 0x01;
   1.114 +        ++i;
   1.115 +        if ((i % 8) != 0)
   1.116 +            mask[i / 8] <<= 1;
   1.117 +    }
   1.118 +    *maskp = mask;
   1.119 +    return (icon);
   1.120  }
   1.121  
   1.122 -int SDLCALL FilterEvents(const SDL_Event *event)
   1.123 +int SDLCALL
   1.124 +FilterEvents (const SDL_Event * event)
   1.125  {
   1.126 -	static int reallyquit = 0;
   1.127 +    static int reallyquit = 0;
   1.128  
   1.129 -	switch (event->type) {
   1.130 +    switch (event->type) {
   1.131  
   1.132 -		case SDL_ACTIVEEVENT:
   1.133 -			/* See what happened */
   1.134 -			printf("App %s ",
   1.135 -				event->active.gain ? "gained" : "lost");
   1.136 -			if ( event->active.state & SDL_APPACTIVE )
   1.137 -				printf("active ");
   1.138 -			if ( event->active.state & SDL_APPMOUSEFOCUS )
   1.139 -				printf("mouse ");
   1.140 -			if ( event->active.state & SDL_APPINPUTFOCUS )
   1.141 -				printf("input ");
   1.142 -			printf("focus\n");
   1.143 +    case SDL_ACTIVEEVENT:
   1.144 +        /* See what happened */
   1.145 +        printf ("App %s ", event->active.gain ? "gained" : "lost");
   1.146 +        if (event->active.state & SDL_APPACTIVE)
   1.147 +            printf ("active ");
   1.148 +        if (event->active.state & SDL_APPMOUSEFOCUS)
   1.149 +            printf ("mouse ");
   1.150 +        if (event->active.state & SDL_APPINPUTFOCUS)
   1.151 +            printf ("input ");
   1.152 +        printf ("focus\n");
   1.153  
   1.154 -			/* See if we are iconified or restored */
   1.155 -			if ( event->active.state & SDL_APPACTIVE ) {
   1.156 -				printf("App has been %s\n",
   1.157 -					event->active.gain ?
   1.158 -						 "restored" : "iconified");
   1.159 -			}
   1.160 -			return(0);
   1.161 +        /* See if we are iconified or restored */
   1.162 +        if (event->active.state & SDL_APPACTIVE) {
   1.163 +            printf ("App has been %s\n",
   1.164 +                    event->active.gain ? "restored" : "iconified");
   1.165 +        }
   1.166 +        return (0);
   1.167  
   1.168 -		/* This is important!  Queue it if we want to quit. */
   1.169 -		case SDL_QUIT:
   1.170 -			if ( ! reallyquit ) {
   1.171 -				reallyquit = 1;
   1.172 -				printf("Quit requested\n");
   1.173 -				return(0);
   1.174 -			}
   1.175 -			printf("Quit demanded\n");
   1.176 -			return(1);
   1.177 +        /* This is important!  Queue it if we want to quit. */
   1.178 +    case SDL_QUIT:
   1.179 +        if (!reallyquit) {
   1.180 +            reallyquit = 1;
   1.181 +            printf ("Quit requested\n");
   1.182 +            return (0);
   1.183 +        }
   1.184 +        printf ("Quit demanded\n");
   1.185 +        return (1);
   1.186  
   1.187 -		/* Mouse and keyboard events go to threads */
   1.188 -		case SDL_MOUSEMOTION:
   1.189 -		case SDL_MOUSEBUTTONDOWN:
   1.190 -		case SDL_MOUSEBUTTONUP:
   1.191 -		case SDL_KEYDOWN:
   1.192 -		case SDL_KEYUP:
   1.193 -			return(1);
   1.194 +        /* Mouse and keyboard events go to threads */
   1.195 +    case SDL_MOUSEMOTION:
   1.196 +    case SDL_MOUSEBUTTONDOWN:
   1.197 +    case SDL_MOUSEBUTTONUP:
   1.198 +    case SDL_KEYDOWN:
   1.199 +    case SDL_KEYUP:
   1.200 +        return (1);
   1.201  
   1.202 -		/* Drop all other events */
   1.203 -		default:
   1.204 -			return(0);
   1.205 -	}
   1.206 +        /* Drop all other events */
   1.207 +    default:
   1.208 +        return (0);
   1.209 +    }
   1.210  }
   1.211  
   1.212 -int SDLCALL HandleMouse(void *unused)
   1.213 +int SDLCALL
   1.214 +HandleMouse (void *unused)
   1.215  {
   1.216 -	SDL_Event events[10];
   1.217 -	int i, found;
   1.218 -	Uint32 mask;
   1.219 +    SDL_Event events[10];
   1.220 +    int i, found;
   1.221 +    Uint32 mask;
   1.222  
   1.223 -	/* Handle mouse events here */
   1.224 -	mask = (SDL_MOUSEMOTIONMASK|SDL_MOUSEBUTTONDOWNMASK|SDL_MOUSEBUTTONUPMASK);
   1.225 -	while ( ! done ) {
   1.226 -		found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask);
   1.227 -		for ( i=0; i<found; ++i ) {
   1.228 -			switch(events[i].type) {
   1.229 -				/* We want to toggle visibility on buttonpress */
   1.230 -				case SDL_MOUSEBUTTONDOWN:
   1.231 -				case SDL_MOUSEBUTTONUP:
   1.232 -					if ( events[i].button.state == SDL_PRESSED ) {
   1.233 -						visible = !visible;
   1.234 -						SDL_ShowCursor(visible);
   1.235 -					}
   1.236 -					printf("Mouse button %d has been %s\n",
   1.237 -						events[i].button.button,
   1.238 -						(events[i].button.state == SDL_PRESSED) ?
   1.239 -						"pressed" : "released");
   1.240 -					break;
   1.241 -				/* Show relative mouse motion */
   1.242 -				case SDL_MOUSEMOTION:
   1.243 -					printf("Mouse relative motion: {%d,%d}\n",
   1.244 -							events[i].motion.xrel, events[i].motion.yrel);
   1.245 -					break;
   1.246 -			}
   1.247 -		}
   1.248 -		/* Give up some CPU to allow events to arrive */
   1.249 -		SDL_Delay(20);
   1.250 -	}
   1.251 -	return(0);
   1.252 +    /* Handle mouse events here */
   1.253 +    mask =
   1.254 +        (SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK |
   1.255 +         SDL_MOUSEBUTTONUPMASK);
   1.256 +    while (!done) {
   1.257 +        found = SDL_PeepEvents (events, 10, SDL_GETEVENT, mask);
   1.258 +        for (i = 0; i < found; ++i) {
   1.259 +            switch (events[i].type) {
   1.260 +                /* We want to toggle visibility on buttonpress */
   1.261 +            case SDL_MOUSEBUTTONDOWN:
   1.262 +            case SDL_MOUSEBUTTONUP:
   1.263 +                if (events[i].button.state == SDL_PRESSED) {
   1.264 +                    visible = !visible;
   1.265 +                    SDL_ShowCursor (visible);
   1.266 +                }
   1.267 +                printf ("Mouse button %d has been %s\n",
   1.268 +                        events[i].button.button,
   1.269 +                        (events[i].button.state == SDL_PRESSED) ?
   1.270 +                        "pressed" : "released");
   1.271 +                break;
   1.272 +                /* Show relative mouse motion */
   1.273 +            case SDL_MOUSEMOTION:
   1.274 +                printf ("Mouse relative motion: {%d,%d}\n",
   1.275 +                        events[i].motion.xrel, events[i].motion.yrel);
   1.276 +                break;
   1.277 +            }
   1.278 +        }
   1.279 +        /* Give up some CPU to allow events to arrive */
   1.280 +        SDL_Delay (20);
   1.281 +    }
   1.282 +    return (0);
   1.283  }
   1.284  
   1.285 -int SDLCALL HandleKeyboard(void *unused)
   1.286 +int SDLCALL
   1.287 +HandleKeyboard (void *unused)
   1.288  {
   1.289 -	SDL_Event events[10];
   1.290 -	int i, found;
   1.291 -	Uint32 mask;
   1.292 +    SDL_Event events[10];
   1.293 +    int i, found;
   1.294 +    Uint32 mask;
   1.295  
   1.296 -	/* Handle mouse events here */
   1.297 -	mask = (SDL_KEYDOWNMASK|SDL_KEYUPMASK);
   1.298 -	while ( ! done ) {
   1.299 -		found = SDL_PeepEvents(events, 10, SDL_GETEVENT, mask);
   1.300 -		for ( i=0; i<found; ++i ) {
   1.301 -			switch(events[i].type) {
   1.302 -			    /* We want to toggle visibility on buttonpress */
   1.303 -			    case SDL_KEYDOWN:
   1.304 -			    case SDL_KEYUP:
   1.305 -			    	printf("Key '%c' has been %s\n",
   1.306 -						events[i].key.keysym.unicode,
   1.307 -					(events[i].key.state == SDL_PRESSED) ?
   1.308 -						"pressed" : "released");
   1.309 +    /* Handle mouse events here */
   1.310 +    mask = (SDL_KEYDOWNMASK | SDL_KEYUPMASK);
   1.311 +    while (!done) {
   1.312 +        found = SDL_PeepEvents (events, 10, SDL_GETEVENT, mask);
   1.313 +        for (i = 0; i < found; ++i) {
   1.314 +            switch (events[i].type) {
   1.315 +                /* We want to toggle visibility on buttonpress */
   1.316 +            case SDL_KEYDOWN:
   1.317 +            case SDL_KEYUP:
   1.318 +                printf ("Key '%c' has been %s\n",
   1.319 +                        events[i].key.keysym.unicode,
   1.320 +                        (events[i].key.state == SDL_PRESSED) ?
   1.321 +                        "pressed" : "released");
   1.322  
   1.323 -			    	/* Allow hitting <ESC> to quit the app */
   1.324 -			    	if ( events[i].key.keysym.sym == SDLK_ESCAPE ) {
   1.325 -			    		done = 1;
   1.326 -			    	}
   1.327 +                /* Allow hitting <ESC> to quit the app */
   1.328 +                if (events[i].key.keysym.sym == SDLK_ESCAPE) {
   1.329 +                    done = 1;
   1.330 +                }
   1.331  
   1.332 -					/* skip events now that aren't KEYUPs... */
   1.333 -					if (events[i].key.state == SDL_PRESSED)
   1.334 -						break;
   1.335 +                /* skip events now that aren't KEYUPs... */
   1.336 +                if (events[i].key.state == SDL_PRESSED)
   1.337 +                    break;
   1.338  
   1.339 -			    	if ( events[i].key.keysym.sym == SDLK_f ) {
   1.340 -						int rc = 0;
   1.341 -						printf("attempting to toggle fullscreen...\n");
   1.342 -						rc = SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
   1.343 -                        printf("SDL_WM_ToggleFullScreen returned %d.\n", rc);
   1.344 -			    	}
   1.345 +                if (events[i].key.keysym.sym == SDLK_f) {
   1.346 +                    int rc = 0;
   1.347 +                    printf ("attempting to toggle fullscreen...\n");
   1.348 +                    rc = SDL_WM_ToggleFullScreen (SDL_GetVideoSurface ());
   1.349 +                    printf ("SDL_WM_ToggleFullScreen returned %d.\n", rc);
   1.350 +                }
   1.351  
   1.352 -			    	if ( events[i].key.keysym.sym == SDLK_g ) {
   1.353 -						SDL_GrabMode m;
   1.354 -						m = SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON ?
   1.355 -								SDL_GRAB_OFF : SDL_GRAB_ON;
   1.356 -						printf("attempting to toggle input grab to %s...\n",
   1.357 -                                m == SDL_GRAB_ON ? "ON" : "OFF");
   1.358 -                        SDL_WM_GrabInput(m);
   1.359 -						printf("attempt finished.\n");
   1.360 -			    	}
   1.361 +                if (events[i].key.keysym.sym == SDLK_g) {
   1.362 +                    SDL_GrabMode m;
   1.363 +                    m = SDL_WM_GrabInput (SDL_GRAB_QUERY) ==
   1.364 +                        SDL_GRAB_ON ? SDL_GRAB_OFF : SDL_GRAB_ON;
   1.365 +                    printf
   1.366 +                        ("attempting to toggle input grab to %s...\n",
   1.367 +                         m == SDL_GRAB_ON ? "ON" : "OFF");
   1.368 +                    SDL_WM_GrabInput (m);
   1.369 +                    printf ("attempt finished.\n");
   1.370 +                }
   1.371  
   1.372 -			    	break;
   1.373 -			}
   1.374 -		}
   1.375 -		/* Give up some CPU to allow events to arrive */
   1.376 -		SDL_Delay(20);
   1.377 -	}
   1.378 -	return(0);
   1.379 +                break;
   1.380 +            }
   1.381 +        }
   1.382 +        /* Give up some CPU to allow events to arrive */
   1.383 +        SDL_Delay (20);
   1.384 +    }
   1.385 +    return (0);
   1.386  }
   1.387  
   1.388 -int main(int argc, char *argv[])
   1.389 +int
   1.390 +main (int argc, char *argv[])
   1.391  {
   1.392 -	SDL_Surface *screen;
   1.393 -	SDL_Surface *icon;
   1.394 -	Uint8 *icon_mask;
   1.395 -	int i, parsed;
   1.396 -	Uint8 *buffer;
   1.397 -	SDL_Color palette[256];
   1.398 -	Uint32 init_flags;
   1.399 -	Uint8  video_bpp;
   1.400 -	Uint32 video_flags;
   1.401 -	SDL_Thread *mouse_thread;
   1.402 -	SDL_Thread *keybd_thread;
   1.403 +    SDL_Surface *screen;
   1.404 +    SDL_Surface *icon;
   1.405 +    Uint8 *icon_mask;
   1.406 +    int i, parsed;
   1.407 +    Uint8 *buffer;
   1.408 +    SDL_Color palette[256];
   1.409 +    Uint32 init_flags;
   1.410 +    Uint8 video_bpp;
   1.411 +    Uint32 video_flags;
   1.412 +    SDL_Thread *mouse_thread;
   1.413 +    SDL_Thread *keybd_thread;
   1.414  
   1.415 -	/* Set the options, based on command line arguments */
   1.416 -	init_flags = SDL_INIT_VIDEO;
   1.417 -	video_bpp = 8;
   1.418 -	video_flags = SDL_SWSURFACE;
   1.419 -	parsed = 1;
   1.420 -	while ( parsed ) {
   1.421 -		/* If the threaded option is enabled, and the SDL library hasn't
   1.422 -		   been compiled with threaded events enabled, then the mouse and
   1.423 -		   keyboard won't respond.
   1.424 -		 */
   1.425 -		if ( (argc >= 2) && (strcmp(argv[1], "-threaded") == 0) ) {
   1.426 -			init_flags |= SDL_INIT_EVENTTHREAD;
   1.427 -			argc -= 1;
   1.428 -			argv += 1;
   1.429 -			printf("Running with threaded events\n");
   1.430 -		} else
   1.431 -		if ( (argc >= 2) && (strcmp(argv[1], "-fullscreen") == 0) ) {
   1.432 -			video_flags |= SDL_FULLSCREEN;
   1.433 -			argc -= 1;
   1.434 -			argv += 1;
   1.435 -		} else
   1.436 -		if ( (argc >= 3) && (strcmp(argv[1], "-bpp") == 0) ) {
   1.437 -			video_bpp = atoi(argv[2]);
   1.438 -			argc -= 2;
   1.439 -			argv += 2;
   1.440 -		} else {
   1.441 -			parsed = 0;
   1.442 -		}
   1.443 -	}
   1.444 +    /* Set the options, based on command line arguments */
   1.445 +    init_flags = SDL_INIT_VIDEO;
   1.446 +    video_bpp = 8;
   1.447 +    video_flags = SDL_SWSURFACE;
   1.448 +    parsed = 1;
   1.449 +    while (parsed) {
   1.450 +        /* If the threaded option is enabled, and the SDL library hasn't
   1.451 +           been compiled with threaded events enabled, then the mouse and
   1.452 +           keyboard won't respond.
   1.453 +         */
   1.454 +        if ((argc >= 2) && (strcmp (argv[1], "-threaded") == 0)) {
   1.455 +            init_flags |= SDL_INIT_EVENTTHREAD;
   1.456 +            argc -= 1;
   1.457 +            argv += 1;
   1.458 +            printf ("Running with threaded events\n");
   1.459 +        } else if ((argc >= 2) && (strcmp (argv[1], "-fullscreen") == 0)) {
   1.460 +            video_flags |= SDL_FULLSCREEN;
   1.461 +            argc -= 1;
   1.462 +            argv += 1;
   1.463 +        } else if ((argc >= 3) && (strcmp (argv[1], "-bpp") == 0)) {
   1.464 +            video_bpp = atoi (argv[2]);
   1.465 +            argc -= 2;
   1.466 +            argv += 2;
   1.467 +        } else {
   1.468 +            parsed = 0;
   1.469 +        }
   1.470 +    }
   1.471  
   1.472 -	/* Initialize SDL with the requested flags */
   1.473 -	if ( SDL_Init(init_flags) < 0 ) {
   1.474 -		fprintf(stderr,
   1.475 -			"Couldn't initialize SDL: %s\n", SDL_GetError());
   1.476 -		return(1);
   1.477 -	}
   1.478 +    /* Initialize SDL with the requested flags */
   1.479 +    if (SDL_Init (init_flags) < 0) {
   1.480 +        fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ());
   1.481 +        return (1);
   1.482 +    }
   1.483 +
   1.484 +    /* Set the icon -- this must be done before the first mode set */
   1.485 +    icon = LoadIconSurface ("icon.bmp", &icon_mask);
   1.486 +    if (icon != NULL) {
   1.487 +        SDL_WM_SetIcon (icon, icon_mask);
   1.488 +    }
   1.489 +    if (icon_mask != NULL)
   1.490 +        free (icon_mask);
   1.491  
   1.492 -	/* Set the icon -- this must be done before the first mode set */
   1.493 -	icon = LoadIconSurface("icon.bmp", &icon_mask);
   1.494 -	if ( icon != NULL ) {
   1.495 -		SDL_WM_SetIcon(icon, icon_mask);
   1.496 -	}
   1.497 -	if ( icon_mask != NULL )
   1.498 -		free(icon_mask);
   1.499 +    /* Initialize the display */
   1.500 +    screen = SDL_SetVideoMode (640, 480, video_bpp, video_flags);
   1.501 +    if (screen == NULL) {
   1.502 +        fprintf (stderr, "Couldn't set 640x480x%d video mode: %s\n",
   1.503 +                 video_bpp, SDL_GetError ());
   1.504 +        quit (1);
   1.505 +    }
   1.506 +    printf ("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
   1.507 +            "fullscreen" : "windowed");
   1.508  
   1.509 -	/* Initialize the display */
   1.510 -	screen = SDL_SetVideoMode(640, 480, video_bpp, video_flags);
   1.511 -	if (  screen == NULL ) {
   1.512 -		fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
   1.513 -						video_bpp, SDL_GetError());
   1.514 -		quit(1);
   1.515 -	}
   1.516 -	printf("Running in %s mode\n", screen->flags & SDL_FULLSCREEN ?
   1.517 -						"fullscreen" : "windowed");
   1.518 +    /* Enable printable characters */
   1.519 +    SDL_EnableUNICODE (1);
   1.520  
   1.521 -	/* Enable printable characters */
   1.522 -	SDL_EnableUNICODE(1);
   1.523 +    /* Set an event filter that discards everything but QUIT */
   1.524 +    SDL_SetEventFilter (FilterEvents);
   1.525  
   1.526 -	/* Set an event filter that discards everything but QUIT */
   1.527 -	SDL_SetEventFilter(FilterEvents);
   1.528 -
   1.529 -	/* Create the event handling threads */
   1.530 -	mouse_thread = SDL_CreateThread(HandleMouse, NULL);
   1.531 -	keybd_thread = SDL_CreateThread(HandleKeyboard, NULL);
   1.532 +    /* Create the event handling threads */
   1.533 +    mouse_thread = SDL_CreateThread (HandleMouse, NULL);
   1.534 +    keybd_thread = SDL_CreateThread (HandleKeyboard, NULL);
   1.535  
   1.536 -	/* Set the surface pixels and refresh! */
   1.537 -	for ( i=0; i<256; ++i ) {
   1.538 -		palette[i].r = 255-i;
   1.539 -		palette[i].g = 255-i;
   1.540 -		palette[i].b = 255-i;
   1.541 -	}
   1.542 -	SDL_SetColors(screen, palette, 0, 256);
   1.543 -	if ( SDL_LockSurface(screen) < 0 ) {
   1.544 -		fprintf(stderr, "Couldn't lock display surface: %s\n",
   1.545 -							SDL_GetError());
   1.546 -		quit(2);
   1.547 -	}
   1.548 -	buffer = (Uint8 *)screen->pixels;
   1.549 -	for ( i=0; i<screen->h; ++i ) {
   1.550 -		memset(buffer,(i*255)/screen->h,
   1.551 -				screen->w*screen->format->BytesPerPixel);
   1.552 -		buffer += screen->pitch;
   1.553 -	}
   1.554 -	SDL_UnlockSurface(screen);
   1.555 -	SDL_UpdateRect(screen, 0, 0, 0, 0);
   1.556 +    /* Set the surface pixels and refresh! */
   1.557 +    for (i = 0; i < 256; ++i) {
   1.558 +        palette[i].r = 255 - i;
   1.559 +        palette[i].g = 255 - i;
   1.560 +        palette[i].b = 255 - i;
   1.561 +    }
   1.562 +    SDL_SetColors (screen, palette, 0, 256);
   1.563 +    if (SDL_LockSurface (screen) < 0) {
   1.564 +        fprintf (stderr, "Couldn't lock display surface: %s\n",
   1.565 +                 SDL_GetError ());
   1.566 +        quit (2);
   1.567 +    }
   1.568 +    buffer = (Uint8 *) screen->pixels;
   1.569 +    for (i = 0; i < screen->h; ++i) {
   1.570 +        memset (buffer, (i * 255) / screen->h,
   1.571 +                screen->w * screen->format->BytesPerPixel);
   1.572 +        buffer += screen->pitch;
   1.573 +    }
   1.574 +    SDL_UnlockSurface (screen);
   1.575 +    SDL_UpdateRect (screen, 0, 0, 0, 0);
   1.576  
   1.577 -	/* Loop, waiting for QUIT */
   1.578 -	while ( ! done ) {
   1.579 -		if ( ! (init_flags & SDL_INIT_EVENTTHREAD) ) {
   1.580 -			SDL_PumpEvents(); /* Needed when event thread is off */
   1.581 -		}
   1.582 -		if ( SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_QUITMASK) ) {
   1.583 -			done = 1;
   1.584 -		}
   1.585 -		/* Give up some CPU so the events can accumulate */
   1.586 -		SDL_Delay(20);
   1.587 -	}
   1.588 -	SDL_WaitThread(mouse_thread, NULL);
   1.589 -	SDL_WaitThread(keybd_thread, NULL);
   1.590 -	SDL_Quit();
   1.591 -	return(0);
   1.592 +    /* Loop, waiting for QUIT */
   1.593 +    while (!done) {
   1.594 +        if (!(init_flags & SDL_INIT_EVENTTHREAD)) {
   1.595 +            SDL_PumpEvents ();  /* Needed when event thread is off */
   1.596 +        }
   1.597 +        if (SDL_PeepEvents (NULL, 0, SDL_PEEKEVENT, SDL_QUITMASK)) {
   1.598 +            done = 1;
   1.599 +        }
   1.600 +        /* Give up some CPU so the events can accumulate */
   1.601 +        SDL_Delay (20);
   1.602 +    }
   1.603 +    SDL_WaitThread (mouse_thread, NULL);
   1.604 +    SDL_WaitThread (keybd_thread, NULL);
   1.605 +    SDL_Quit ();
   1.606 +    return (0);
   1.607  }