Existing testsprite programs made into NDS projects gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Wed, 13 Aug 2008 00:49:03 +0000
branchgsoc2008_nds
changeset 2686e9f27fe4f2a1
parent 2685 2190b873ff00
child 2687 5166b19b6808
Existing testsprite programs made into NDS projects
test/nds-test-progs/general/Makefile
test/nds-test-progs/general/source/main.c
test/nds-test-progs/sprite/Makefile
test/nds-test-progs/sprite/source/common.c
test/nds-test-progs/sprite/source/common.h
test/nds-test-progs/sprite/source/testsprite.c
test/nds-test-progs/sprite2/Makefile
test/nds-test-progs/sprite2/source/common.c
test/nds-test-progs/sprite2/source/common.h
test/nds-test-progs/sprite2/source/testsprite2.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/nds-test-progs/general/Makefile	Wed Aug 13 00:49:03 2008 +0000
     1.3 @@ -0,0 +1,132 @@
     1.4 +#---------------------------------------------------------------------------------
     1.5 +.SUFFIXES:
     1.6 +#---------------------------------------------------------------------------------
     1.7 +
     1.8 +ifeq ($(strip $(DEVKITARM)),)
     1.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
    1.10 +endif
    1.11 +
    1.12 +include $(DEVKITARM)/ds_rules
    1.13 +
    1.14 +#---------------------------------------------------------------------------------
    1.15 +# TARGET is the name of the output
    1.16 +# BUILD is the directory where object files & intermediate files will be placed
    1.17 +# SOURCES is a list of directories containing source code
    1.18 +# INCLUDES is a list of directories containing extra header files
    1.19 +#---------------------------------------------------------------------------------
    1.20 +TARGET		:=	$(shell basename $(CURDIR))
    1.21 +BUILD		:=	build
    1.22 +SOURCES		:=	source
    1.23 +DATA		:=	data  
    1.24 +INCLUDES	:=	include
    1.25 +
    1.26 +#---------------------------------------------------------------------------------
    1.27 +# options for code generation
    1.28 +#---------------------------------------------------------------------------------
    1.29 +ARCH	:=	-mthumb -mthumb-interwork
    1.30 +
    1.31 +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
    1.32 +# *insists* it has a FPU or VFP, and it won't take no for an answer!
    1.33 +CFLAGS	:=	-save-temps -g -Wall -O0\
    1.34 + 			-mcpu=arm9tdmi -mtune=arm9tdmi \
    1.35 +			$(ARCH)
    1.36 +
    1.37 +CFLAGS	+=	$(INCLUDE) -DARM9 -D__NDS__
    1.38 +CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
    1.39 +
    1.40 +ASFLAGS	:=	-g $(ARCH)
    1.41 +LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
    1.42 +
    1.43 +#---------------------------------------------------------------------------------
    1.44 +# any extra libraries we wish to link with the project
    1.45 +#---------------------------------------------------------------------------------
    1.46 +LIBS	:= -lSDL -lfat -lnds9
    1.47 + 
    1.48 + 
    1.49 +#---------------------------------------------------------------------------------
    1.50 +# list of directories containing libraries, this must be the top level containing
    1.51 +# include and lib
    1.52 +#---------------------------------------------------------------------------------
    1.53 +LIBDIRS	:=	$(LIBNDS)
    1.54 + 
    1.55 +#---------------------------------------------------------------------------------
    1.56 +# no real need to edit anything past this point unless you need to add additional
    1.57 +# rules for different file extensions
    1.58 +#---------------------------------------------------------------------------------
    1.59 +ifneq ($(BUILD),$(notdir $(CURDIR)))
    1.60 +#---------------------------------------------------------------------------------
    1.61 + 
    1.62 +export OUTPUT	:=	$(CURDIR)/$(TARGET)
    1.63 + 
    1.64 +export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
    1.65 +					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
    1.66 +
    1.67 +export DEPSDIR	:=	$(CURDIR)/$(BUILD)
    1.68 +
    1.69 +CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
    1.70 +CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
    1.71 +SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
    1.72 +BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
    1.73 + 
    1.74 +#---------------------------------------------------------------------------------
    1.75 +# use CXX for linking C++ projects, CC for standard C
    1.76 +#---------------------------------------------------------------------------------
    1.77 +ifeq ($(strip $(CPPFILES)),)
    1.78 +#---------------------------------------------------------------------------------
    1.79 +	export LD	:=	$(CC)
    1.80 +#---------------------------------------------------------------------------------
    1.81 +else
    1.82 +#---------------------------------------------------------------------------------
    1.83 +	export LD	:=	$(CXX)
    1.84 +#---------------------------------------------------------------------------------
    1.85 +endif
    1.86 +#---------------------------------------------------------------------------------
    1.87 +
    1.88 +export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
    1.89 +					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
    1.90 + 
    1.91 +export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
    1.92 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    1.93 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    1.94 +					-I$(CURDIR)/$(BUILD)
    1.95 + 
    1.96 +export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
    1.97 + 
    1.98 +.PHONY: $(BUILD) clean
    1.99 + 
   1.100 +#---------------------------------------------------------------------------------
   1.101 +$(BUILD):
   1.102 +	@[ -d $@ ] || mkdir -p $@
   1.103 +	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
   1.104 + 
   1.105 +#---------------------------------------------------------------------------------
   1.106 +clean:
   1.107 +	@echo clean ...
   1.108 +	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba 
   1.109 + 
   1.110 + 
   1.111 +#---------------------------------------------------------------------------------
   1.112 +else
   1.113 + 
   1.114 +DEPENDS	:=	$(OFILES:.o=.d)
   1.115 + 
   1.116 +#---------------------------------------------------------------------------------
   1.117 +# main targets
   1.118 +#---------------------------------------------------------------------------------
   1.119 +$(OUTPUT).ds.gba	: 	$(OUTPUT).nds
   1.120 +$(OUTPUT).nds	: 	$(OUTPUT).arm9
   1.121 +$(OUTPUT).arm9	:	$(OUTPUT).elf
   1.122 +$(OUTPUT).elf	:	$(OFILES)
   1.123 + 
   1.124 +#---------------------------------------------------------------------------------
   1.125 +%.pcx.o	:	%.pcx
   1.126 +#---------------------------------------------------------------------------------
   1.127 +	@echo $(notdir $<)
   1.128 +	@$(bin2o)
   1.129 + 
   1.130 + 
   1.131 +-include $(DEPENDS)
   1.132 + 
   1.133 +#---------------------------------------------------------------------------------------
   1.134 +endif
   1.135 +#---------------------------------------------------------------------------------------
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/nds-test-progs/general/source/main.c	Wed Aug 13 00:49:03 2008 +0000
     2.3 @@ -0,0 +1,77 @@
     2.4 +
     2.5 +#include <SDL/SDL.h>
     2.6 +#if defined(NDS) || defined(__NDS__) || defined (__NDS)
     2.7 +#include <nds.h>
     2.8 +#else
     2.9 +#define swiWaitForVBlank() 
    2.10 +#define consoleDemoInit() 
    2.11 +#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
    2.12 +#endif
    2.13 +
    2.14 +void delay(int s) {
    2.15 +	while(s-- > 0) {
    2.16 +		int i = 60;
    2.17 +		while(--i) swiWaitForVBlank();
    2.18 +	}
    2.19 +}
    2.20 +
    2.21 +int main(void) {
    2.22 +	SDL_Surface *screen;
    2.23 +	SDL_Joystick *stick;
    2.24 +	SDL_Event event;
    2.25 +	SDL_Rect rect = {8,8,240,176};
    2.26 +
    2.27 +	consoleDemoInit();
    2.28 +	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) {
    2.29 +		puts("# error initializing SDL");
    2.30 +		puts(SDL_GetError());
    2.31 +		return 1;
    2.32 +	}
    2.33 +	puts("* initialized SDL\n"); delay(1);
    2.34 +
    2.35 +	screen = SDL_SetVideoMode(256, 192, 16, SDL_SWSURFACE);
    2.36 +	if(!screen) {
    2.37 +		puts("# error setting video mode");
    2.38 +		puts(SDL_GetError());
    2.39 +		return 2;
    2.40 +	}
    2.41 +	puts("* set video mode\n"); delay(1);
    2.42 +
    2.43 +	stick = SDL_JoystickOpen(0);
    2.44 +	if(stick == NULL) {
    2.45 +		puts("# error opening joystick");
    2.46 +		puts(SDL_GetError());
    2.47 +//		return 3;
    2.48 +	}
    2.49 +	puts("* opened joystick"); delay(1);
    2.50 +	SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000);
    2.51 +	SDL_Flip(screen);
    2.52 +
    2.53 +	while(1)
    2.54 +	while(SDL_PollEvent(&event))
    2.55 +	switch(event.type) {
    2.56 +		case SDL_JOYBUTTONDOWN:
    2.57 +		switch(event.jbutton.which) {
    2.58 +			case 0:
    2.59 +			SDL_FillRect(screen, &rect, RGB15(31,0,0)|0x8000);
    2.60 +			break;
    2.61 +			case 1:
    2.62 +			SDL_FillRect(screen, &rect, RGB15(0,31,0)|0x8000);
    2.63 +			break;
    2.64 +			case 2:
    2.65 +			SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000);
    2.66 +			break;
    2.67 +			case 3:
    2.68 +			SDL_FillRect(screen, &rect, RGB15(0,0,0)|0x8000);
    2.69 +			break;
    2.70 +			default: break;
    2.71 +		}
    2.72 +		printf("joy_%d\n", event.jbutton.which);
    2.73 +		SDL_Flip(screen);
    2.74 +		break;
    2.75 +		case SDL_QUIT: SDL_Quit(); return 0;
    2.76 +		default: break;
    2.77 +	}
    2.78 +
    2.79 +	return 0;
    2.80 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/nds-test-progs/sprite/Makefile	Wed Aug 13 00:49:03 2008 +0000
     3.3 @@ -0,0 +1,132 @@
     3.4 +#---------------------------------------------------------------------------------
     3.5 +.SUFFIXES:
     3.6 +#---------------------------------------------------------------------------------
     3.7 +
     3.8 +ifeq ($(strip $(DEVKITARM)),)
     3.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
    3.10 +endif
    3.11 +
    3.12 +include $(DEVKITARM)/ds_rules
    3.13 +
    3.14 +#---------------------------------------------------------------------------------
    3.15 +# TARGET is the name of the output
    3.16 +# BUILD is the directory where object files & intermediate files will be placed
    3.17 +# SOURCES is a list of directories containing source code
    3.18 +# INCLUDES is a list of directories containing extra header files
    3.19 +#---------------------------------------------------------------------------------
    3.20 +TARGET		:=	$(shell basename $(CURDIR))
    3.21 +BUILD		:=	build
    3.22 +SOURCES		:=	source
    3.23 +DATA		:=	data  
    3.24 +INCLUDES	:=	include
    3.25 +
    3.26 +#---------------------------------------------------------------------------------
    3.27 +# options for code generation
    3.28 +#---------------------------------------------------------------------------------
    3.29 +ARCH	:=	-mthumb -mthumb-interwork
    3.30 +
    3.31 +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
    3.32 +# *insists* it has a FPU or VFP, and it won't take no for an answer!
    3.33 +CFLAGS	:=	-save-temps -g -Wall -O0\
    3.34 + 			-mcpu=arm9tdmi -mtune=arm9tdmi \
    3.35 +			$(ARCH)
    3.36 +
    3.37 +CFLAGS	+=	$(INCLUDE) -DARM9 -D__NDS__
    3.38 +CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
    3.39 +
    3.40 +ASFLAGS	:=	-g $(ARCH)
    3.41 +LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
    3.42 +
    3.43 +#---------------------------------------------------------------------------------
    3.44 +# any extra libraries we wish to link with the project
    3.45 +#---------------------------------------------------------------------------------
    3.46 +LIBS	:= -lSDL -lfat -lnds9
    3.47 + 
    3.48 + 
    3.49 +#---------------------------------------------------------------------------------
    3.50 +# list of directories containing libraries, this must be the top level containing
    3.51 +# include and lib
    3.52 +#---------------------------------------------------------------------------------
    3.53 +LIBDIRS	:=	$(LIBNDS)
    3.54 + 
    3.55 +#---------------------------------------------------------------------------------
    3.56 +# no real need to edit anything past this point unless you need to add additional
    3.57 +# rules for different file extensions
    3.58 +#---------------------------------------------------------------------------------
    3.59 +ifneq ($(BUILD),$(notdir $(CURDIR)))
    3.60 +#---------------------------------------------------------------------------------
    3.61 + 
    3.62 +export OUTPUT	:=	$(CURDIR)/$(TARGET)
    3.63 + 
    3.64 +export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
    3.65 +					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
    3.66 +
    3.67 +export DEPSDIR	:=	$(CURDIR)/$(BUILD)
    3.68 +
    3.69 +CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
    3.70 +CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
    3.71 +SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
    3.72 +BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
    3.73 + 
    3.74 +#---------------------------------------------------------------------------------
    3.75 +# use CXX for linking C++ projects, CC for standard C
    3.76 +#---------------------------------------------------------------------------------
    3.77 +ifeq ($(strip $(CPPFILES)),)
    3.78 +#---------------------------------------------------------------------------------
    3.79 +	export LD	:=	$(CC)
    3.80 +#---------------------------------------------------------------------------------
    3.81 +else
    3.82 +#---------------------------------------------------------------------------------
    3.83 +	export LD	:=	$(CXX)
    3.84 +#---------------------------------------------------------------------------------
    3.85 +endif
    3.86 +#---------------------------------------------------------------------------------
    3.87 +
    3.88 +export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
    3.89 +					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
    3.90 + 
    3.91 +export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
    3.92 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    3.93 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    3.94 +					-I$(CURDIR)/$(BUILD)
    3.95 + 
    3.96 +export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
    3.97 + 
    3.98 +.PHONY: $(BUILD) clean
    3.99 + 
   3.100 +#---------------------------------------------------------------------------------
   3.101 +$(BUILD):
   3.102 +	@[ -d $@ ] || mkdir -p $@
   3.103 +	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
   3.104 + 
   3.105 +#---------------------------------------------------------------------------------
   3.106 +clean:
   3.107 +	@echo clean ...
   3.108 +	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba 
   3.109 + 
   3.110 + 
   3.111 +#---------------------------------------------------------------------------------
   3.112 +else
   3.113 + 
   3.114 +DEPENDS	:=	$(OFILES:.o=.d)
   3.115 + 
   3.116 +#---------------------------------------------------------------------------------
   3.117 +# main targets
   3.118 +#---------------------------------------------------------------------------------
   3.119 +$(OUTPUT).ds.gba	: 	$(OUTPUT).nds
   3.120 +$(OUTPUT).nds	: 	$(OUTPUT).arm9
   3.121 +$(OUTPUT).arm9	:	$(OUTPUT).elf
   3.122 +$(OUTPUT).elf	:	$(OFILES)
   3.123 + 
   3.124 +#---------------------------------------------------------------------------------
   3.125 +%.pcx.o	:	%.pcx
   3.126 +#---------------------------------------------------------------------------------
   3.127 +	@echo $(notdir $<)
   3.128 +	@$(bin2o)
   3.129 + 
   3.130 + 
   3.131 +-include $(DEPENDS)
   3.132 + 
   3.133 +#---------------------------------------------------------------------------------------
   3.134 +endif
   3.135 +#---------------------------------------------------------------------------------------
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/nds-test-progs/sprite/source/common.c	Wed Aug 13 00:49:03 2008 +0000
     4.3 @@ -0,0 +1,965 @@
     4.4 +
     4.5 +/* A simple test program framework */
     4.6 +
     4.7 +#include <stdio.h>
     4.8 +
     4.9 +#include "common.h"
    4.10 +
    4.11 +#define VIDEO_USAGE \
    4.12 +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
    4.13 +
    4.14 +#define AUDIO_USAGE \
    4.15 +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    4.16 +
    4.17 +CommonState *
    4.18 +CommonCreateState(char **argv, Uint32 flags)
    4.19 +{
    4.20 +    CommonState *state = SDL_calloc(1, sizeof(*state));
    4.21 +    if (!state) {
    4.22 +        SDL_OutOfMemory();
    4.23 +        return NULL;
    4.24 +    }
    4.25 +
    4.26 +    /* Initialize some defaults */
    4.27 +    state->argv = argv;
    4.28 +    state->flags = flags;
    4.29 +    state->window_title = argv[0];
    4.30 +    state->window_flags = SDL_WINDOW_SHOWN;
    4.31 +    state->window_x = SDL_WINDOWPOS_UNDEFINED;
    4.32 +    state->window_y = SDL_WINDOWPOS_UNDEFINED;
    4.33 +    state->window_w = 256;
    4.34 +    state->window_h = 192;
    4.35 +    state->num_windows = 1;
    4.36 +    state->audiospec.freq = 22050;
    4.37 +    state->audiospec.format = AUDIO_S16;
    4.38 +    state->audiospec.channels = 2;
    4.39 +    state->audiospec.samples = 2048;
    4.40 +    return state;
    4.41 +}
    4.42 +
    4.43 +int
    4.44 +CommonArg(CommonState * state, int index)
    4.45 +{
    4.46 +    char **argv = state->argv;
    4.47 +
    4.48 +    if (SDL_strcasecmp(argv[index], "--video") == 0) {
    4.49 +        ++index;
    4.50 +        if (!argv[index]) {
    4.51 +            return -1;
    4.52 +        }
    4.53 +        state->videodriver = argv[index];
    4.54 +        return 2;
    4.55 +    }
    4.56 +    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
    4.57 +        ++index;
    4.58 +        if (!argv[index]) {
    4.59 +            return -1;
    4.60 +        }
    4.61 +        state->renderdriver = argv[index];
    4.62 +        return 2;
    4.63 +    }
    4.64 +    if (SDL_strcasecmp(argv[index], "--info") == 0) {
    4.65 +        ++index;
    4.66 +        if (!argv[index]) {
    4.67 +            return -1;
    4.68 +        }
    4.69 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
    4.70 +            state->verbose |=
    4.71 +                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
    4.72 +                 VERBOSE_EVENT);
    4.73 +            return 2;
    4.74 +        }
    4.75 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
    4.76 +            state->verbose |= VERBOSE_VIDEO;
    4.77 +            return 2;
    4.78 +        }
    4.79 +        if (SDL_strcasecmp(argv[index], "modes") == 0) {
    4.80 +            state->verbose |= VERBOSE_MODES;
    4.81 +            return 2;
    4.82 +        }
    4.83 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
    4.84 +            state->verbose |= VERBOSE_RENDER;
    4.85 +            return 2;
    4.86 +        }
    4.87 +        if (SDL_strcasecmp(argv[index], "event") == 0) {
    4.88 +            state->verbose |= VERBOSE_EVENT;
    4.89 +            return 2;
    4.90 +        }
    4.91 +        return -1;
    4.92 +    }
    4.93 +    if (SDL_strcasecmp(argv[index], "--display") == 0) {
    4.94 +        ++index;
    4.95 +        if (!argv[index]) {
    4.96 +            return -1;
    4.97 +        }
    4.98 +        state->display = SDL_atoi(argv[index]);
    4.99 +        return 2;
   4.100 +    }
   4.101 +    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
   4.102 +        state->window_flags |= SDL_WINDOW_FULLSCREEN;
   4.103 +        state->num_windows = 1;
   4.104 +        return 1;
   4.105 +    }
   4.106 +    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
   4.107 +        ++index;
   4.108 +        if (!argv[index] || !SDL_isdigit(*argv[index])) {
   4.109 +            return -1;
   4.110 +        }
   4.111 +        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
   4.112 +            state->num_windows = SDL_atoi(argv[index]);
   4.113 +        }
   4.114 +        return 2;
   4.115 +    }
   4.116 +    if (SDL_strcasecmp(argv[index], "--title") == 0) {
   4.117 +        ++index;
   4.118 +        if (!argv[index]) {
   4.119 +            return -1;
   4.120 +        }
   4.121 +        state->window_title = argv[index];
   4.122 +        return 2;
   4.123 +    }
   4.124 +    if (SDL_strcasecmp(argv[index], "--center") == 0) {
   4.125 +        state->window_x = SDL_WINDOWPOS_CENTERED;
   4.126 +        state->window_y = SDL_WINDOWPOS_CENTERED;
   4.127 +        return 1;
   4.128 +    }
   4.129 +    if (SDL_strcasecmp(argv[index], "--position") == 0) {
   4.130 +        char *x, *y;
   4.131 +        ++index;
   4.132 +        if (!argv[index]) {
   4.133 +            return -1;
   4.134 +        }
   4.135 +        x = argv[index];
   4.136 +        y = argv[index];
   4.137 +        while (*y && *y != ',') {
   4.138 +            ++y;
   4.139 +        }
   4.140 +        if (!*y) {
   4.141 +            return -1;
   4.142 +        }
   4.143 +        *y++ = '\0';
   4.144 +        state->window_x = SDL_atoi(x);
   4.145 +        state->window_y = SDL_atoi(y);
   4.146 +        return 2;
   4.147 +    }
   4.148 +    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
   4.149 +        char *w, *h;
   4.150 +        ++index;
   4.151 +        if (!argv[index]) {
   4.152 +            return -1;
   4.153 +        }
   4.154 +        w = argv[index];
   4.155 +        h = argv[index];
   4.156 +        while (*h && *h != 'x') {
   4.157 +            ++h;
   4.158 +        }
   4.159 +        if (!*h) {
   4.160 +            return -1;
   4.161 +        }
   4.162 +        *h++ = '\0';
   4.163 +        state->window_w = SDL_atoi(w);
   4.164 +        state->window_h = SDL_atoi(h);
   4.165 +        return 2;
   4.166 +    }
   4.167 +    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
   4.168 +        ++index;
   4.169 +        if (!argv[index]) {
   4.170 +            return -1;
   4.171 +        }
   4.172 +        state->depth = SDL_atoi(argv[index]);
   4.173 +        return 2;
   4.174 +    }
   4.175 +    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
   4.176 +        ++index;
   4.177 +        if (!argv[index]) {
   4.178 +            return -1;
   4.179 +        }
   4.180 +        state->refresh_rate = SDL_atoi(argv[index]);
   4.181 +        return 2;
   4.182 +    }
   4.183 +    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
   4.184 +        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
   4.185 +        return 1;
   4.186 +    }
   4.187 +    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
   4.188 +        state->window_flags |= SDL_WINDOW_BORDERLESS;
   4.189 +        return 1;
   4.190 +    }
   4.191 +    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
   4.192 +        state->window_flags |= SDL_WINDOW_RESIZABLE;
   4.193 +        return 1;
   4.194 +    }
   4.195 +    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
   4.196 +        state->window_flags |= SDL_WINDOW_MINIMIZED;
   4.197 +        return 1;
   4.198 +    }
   4.199 +    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
   4.200 +        state->window_flags |= SDL_WINDOW_MAXIMIZED;
   4.201 +        return 1;
   4.202 +    }
   4.203 +    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
   4.204 +        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
   4.205 +        return 1;
   4.206 +    }
   4.207 +    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
   4.208 +        ++index;
   4.209 +        if (!argv[index]) {
   4.210 +            return -1;
   4.211 +        }
   4.212 +        state->audiospec.freq = SDL_atoi(argv[index]);
   4.213 +        return 2;
   4.214 +    }
   4.215 +    if (SDL_strcasecmp(argv[index], "--format") == 0) {
   4.216 +        ++index;
   4.217 +        if (!argv[index]) {
   4.218 +            return -1;
   4.219 +        }
   4.220 +        if (SDL_strcasecmp(argv[index], "U8") == 0) {
   4.221 +            state->audiospec.format = AUDIO_U8;
   4.222 +            return 2;
   4.223 +        }
   4.224 +        if (SDL_strcasecmp(argv[index], "S8") == 0) {
   4.225 +            state->audiospec.format = AUDIO_S8;
   4.226 +            return 2;
   4.227 +        }
   4.228 +        if (SDL_strcasecmp(argv[index], "U16") == 0) {
   4.229 +            state->audiospec.format = AUDIO_U16;
   4.230 +            return 2;
   4.231 +        }
   4.232 +        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
   4.233 +            state->audiospec.format = AUDIO_U16LSB;
   4.234 +            return 2;
   4.235 +        }
   4.236 +        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
   4.237 +            state->audiospec.format = AUDIO_U16MSB;
   4.238 +            return 2;
   4.239 +        }
   4.240 +        if (SDL_strcasecmp(argv[index], "S16") == 0) {
   4.241 +            state->audiospec.format = AUDIO_S16;
   4.242 +            return 2;
   4.243 +        }
   4.244 +        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
   4.245 +            state->audiospec.format = AUDIO_S16LSB;
   4.246 +            return 2;
   4.247 +        }
   4.248 +        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
   4.249 +            state->audiospec.format = AUDIO_S16MSB;
   4.250 +            return 2;
   4.251 +        }
   4.252 +        return -1;
   4.253 +    }
   4.254 +    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
   4.255 +        ++index;
   4.256 +        if (!argv[index]) {
   4.257 +            return -1;
   4.258 +        }
   4.259 +        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
   4.260 +        return 2;
   4.261 +    }
   4.262 +    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
   4.263 +        ++index;
   4.264 +        if (!argv[index]) {
   4.265 +            return -1;
   4.266 +        }
   4.267 +        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
   4.268 +        return 2;
   4.269 +    }
   4.270 +    if ((SDL_strcasecmp(argv[index], "-h") == 0)
   4.271 +        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
   4.272 +        /* Print the usage message */
   4.273 +        return -1;
   4.274 +    }
   4.275 +    return 0;
   4.276 +}
   4.277 +
   4.278 +const char *
   4.279 +CommonUsage(CommonState * state)
   4.280 +{
   4.281 +    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
   4.282 +    case SDL_INIT_VIDEO:
   4.283 +        return VIDEO_USAGE;
   4.284 +    case SDL_INIT_AUDIO:
   4.285 +        return AUDIO_USAGE;
   4.286 +    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
   4.287 +        return VIDEO_USAGE " " AUDIO_USAGE;
   4.288 +    default:
   4.289 +        return "";
   4.290 +    }
   4.291 +}
   4.292 +
   4.293 +static void
   4.294 +PrintRendererFlag(Uint32 flag)
   4.295 +{
   4.296 +    switch (flag) {
   4.297 +    case SDL_RENDERER_SINGLEBUFFER:
   4.298 +        fprintf(stderr, "SingleBuffer");
   4.299 +        break;
   4.300 +    case SDL_RENDERER_PRESENTCOPY:
   4.301 +        fprintf(stderr, "PresentCopy");
   4.302 +        break;
   4.303 +    case SDL_RENDERER_PRESENTFLIP2:
   4.304 +        fprintf(stderr, "PresentFlip2");
   4.305 +        break;
   4.306 +    case SDL_RENDERER_PRESENTFLIP3:
   4.307 +        fprintf(stderr, "PresentFlip3");
   4.308 +        break;
   4.309 +    case SDL_RENDERER_PRESENTDISCARD:
   4.310 +        fprintf(stderr, "PresentDiscard");
   4.311 +        break;
   4.312 +    case SDL_RENDERER_PRESENTVSYNC:
   4.313 +        fprintf(stderr, "PresentVSync");
   4.314 +        break;
   4.315 +    case SDL_RENDERER_ACCELERATED:
   4.316 +        fprintf(stderr, "Accelerated");
   4.317 +        break;
   4.318 +    default:
   4.319 +        fprintf(stderr, "0x%8.8x", flag);
   4.320 +        break;
   4.321 +    }
   4.322 +}
   4.323 +
   4.324 +static void
   4.325 +PrintBlendMode(Uint32 flag)
   4.326 +{
   4.327 +    switch (flag) {
   4.328 +    case SDL_TEXTUREBLENDMODE_NONE:
   4.329 +        fprintf(stderr, "None");
   4.330 +        break;
   4.331 +    case SDL_TEXTUREBLENDMODE_MASK:
   4.332 +        fprintf(stderr, "Mask");
   4.333 +        break;
   4.334 +    case SDL_TEXTUREBLENDMODE_BLEND:
   4.335 +        fprintf(stderr, "Blend");
   4.336 +        break;
   4.337 +    case SDL_TEXTUREBLENDMODE_ADD:
   4.338 +        fprintf(stderr, "Add");
   4.339 +        break;
   4.340 +    case SDL_TEXTUREBLENDMODE_MOD:
   4.341 +        fprintf(stderr, "Mod");
   4.342 +        break;
   4.343 +    default:
   4.344 +        fprintf(stderr, "0x%8.8x", flag);
   4.345 +        break;
   4.346 +    }
   4.347 +}
   4.348 +
   4.349 +static void
   4.350 +PrintScaleMode(Uint32 flag)
   4.351 +{
   4.352 +    switch (flag) {
   4.353 +    case SDL_TEXTURESCALEMODE_NONE:
   4.354 +        fprintf(stderr, "None");
   4.355 +        break;
   4.356 +    case SDL_TEXTURESCALEMODE_FAST:
   4.357 +        fprintf(stderr, "Fast");
   4.358 +        break;
   4.359 +    case SDL_TEXTURESCALEMODE_SLOW:
   4.360 +        fprintf(stderr, "Slow");
   4.361 +        break;
   4.362 +    case SDL_TEXTURESCALEMODE_BEST:
   4.363 +        fprintf(stderr, "Best");
   4.364 +        break;
   4.365 +    default:
   4.366 +        fprintf(stderr, "0x%8.8x", flag);
   4.367 +        break;
   4.368 +    }
   4.369 +}
   4.370 +
   4.371 +static void
   4.372 +PrintPixelFormat(Uint32 format)
   4.373 +{
   4.374 +    switch (format) {
   4.375 +    case SDL_PIXELFORMAT_UNKNOWN:
   4.376 +        fprintf(stderr, "Unknwon");
   4.377 +        break;
   4.378 +    case SDL_PIXELFORMAT_INDEX1LSB:
   4.379 +        fprintf(stderr, "Index1LSB");
   4.380 +        break;
   4.381 +    case SDL_PIXELFORMAT_INDEX1MSB:
   4.382 +        fprintf(stderr, "Index1MSB");
   4.383 +        break;
   4.384 +    case SDL_PIXELFORMAT_INDEX4LSB:
   4.385 +        fprintf(stderr, "Index4LSB");
   4.386 +        break;
   4.387 +    case SDL_PIXELFORMAT_INDEX4MSB:
   4.388 +        fprintf(stderr, "Index4MSB");
   4.389 +        break;
   4.390 +    case SDL_PIXELFORMAT_INDEX8:
   4.391 +        fprintf(stderr, "Index8");
   4.392 +        break;
   4.393 +    case SDL_PIXELFORMAT_RGB332:
   4.394 +        fprintf(stderr, "RGB332");
   4.395 +        break;
   4.396 +    case SDL_PIXELFORMAT_RGB444:
   4.397 +        fprintf(stderr, "RGB444");
   4.398 +        break;
   4.399 +    case SDL_PIXELFORMAT_RGB555:
   4.400 +        fprintf(stderr, "RGB555");
   4.401 +        break;
   4.402 +    case SDL_PIXELFORMAT_ARGB4444:
   4.403 +        fprintf(stderr, "ARGB4444");
   4.404 +        break;
   4.405 +    case SDL_PIXELFORMAT_ARGB1555:
   4.406 +        fprintf(stderr, "ARGB1555");
   4.407 +        break;
   4.408 +    case SDL_PIXELFORMAT_RGB565:
   4.409 +        fprintf(stderr, "RGB565");
   4.410 +        break;
   4.411 +    case SDL_PIXELFORMAT_RGB24:
   4.412 +        fprintf(stderr, "RGB24");
   4.413 +        break;
   4.414 +    case SDL_PIXELFORMAT_BGR24:
   4.415 +        fprintf(stderr, "BGR24");
   4.416 +        break;
   4.417 +    case SDL_PIXELFORMAT_RGB888:
   4.418 +        fprintf(stderr, "RGB888");
   4.419 +        break;
   4.420 +    case SDL_PIXELFORMAT_BGR888:
   4.421 +        fprintf(stderr, "BGR888");
   4.422 +        break;
   4.423 +    case SDL_PIXELFORMAT_ARGB8888:
   4.424 +        fprintf(stderr, "ARGB8888");
   4.425 +        break;
   4.426 +    case SDL_PIXELFORMAT_RGBA8888:
   4.427 +        fprintf(stderr, "RGBA8888");
   4.428 +        break;
   4.429 +    case SDL_PIXELFORMAT_ABGR8888:
   4.430 +        fprintf(stderr, "ABGR8888");
   4.431 +        break;
   4.432 +    case SDL_PIXELFORMAT_BGRA8888:
   4.433 +        fprintf(stderr, "BGRA8888");
   4.434 +        break;
   4.435 +    case SDL_PIXELFORMAT_ARGB2101010:
   4.436 +        fprintf(stderr, "ARGB2101010");
   4.437 +        break;
   4.438 +    case SDL_PIXELFORMAT_YV12:
   4.439 +        fprintf(stderr, "YV12");
   4.440 +        break;
   4.441 +    case SDL_PIXELFORMAT_IYUV:
   4.442 +        fprintf(stderr, "IYUV");
   4.443 +        break;
   4.444 +    case SDL_PIXELFORMAT_YUY2:
   4.445 +        fprintf(stderr, "YUY2");
   4.446 +        break;
   4.447 +    case SDL_PIXELFORMAT_UYVY:
   4.448 +        fprintf(stderr, "UYVY");
   4.449 +        break;
   4.450 +    case SDL_PIXELFORMAT_YVYU:
   4.451 +        fprintf(stderr, "YVYU");
   4.452 +        break;
   4.453 +    case SDL_PIXELFORMAT_ABGR1555:
   4.454 +        fprintf(stderr, "ABGR1555");
   4.455 +        break;
   4.456 +    case SDL_PIXELFORMAT_BGR555:
   4.457 +        fprintf(stderr, "BGR555");
   4.458 +        break;
   4.459 +    default:
   4.460 +        fprintf(stderr, "0x%8.8x", format);
   4.461 +        break;
   4.462 +    }
   4.463 +}
   4.464 +
   4.465 +static void
   4.466 +PrintRenderer(SDL_RendererInfo * info)
   4.467 +{
   4.468 +    int i, count;
   4.469 +
   4.470 +    fprintf(stderr, "  Renderer %s:\n", info->name);
   4.471 +
   4.472 +    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
   4.473 +    fprintf(stderr, " (");
   4.474 +    count = 0;
   4.475 +    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
   4.476 +        Uint32 flag = (1 << i);
   4.477 +        if (info->flags & flag) {
   4.478 +            if (count > 0) {
   4.479 +                fprintf(stderr, " | ");
   4.480 +            }
   4.481 +            PrintRendererFlag(flag);
   4.482 +            ++count;
   4.483 +        }
   4.484 +    }
   4.485 +    fprintf(stderr, ")\n");
   4.486 +
   4.487 +    fprintf(stderr, "    Blend: 0x%8.8X", info->blend_modes);
   4.488 +    fprintf(stderr, " (");
   4.489 +    count = 0;
   4.490 +    for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) {
   4.491 +        Uint32 flag = (1 << i);
   4.492 +        if (info->blend_modes & flag) {
   4.493 +            if (count > 0) {
   4.494 +                fprintf(stderr, " | ");
   4.495 +            }
   4.496 +            PrintBlendMode(flag);
   4.497 +            ++count;
   4.498 +        }
   4.499 +    }
   4.500 +    fprintf(stderr, ")\n");
   4.501 +
   4.502 +    fprintf(stderr, "    Scale: 0x%8.8X", info->scale_modes);
   4.503 +    fprintf(stderr, " (");
   4.504 +    count = 0;
   4.505 +    for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) {
   4.506 +        Uint32 flag = (1 << i);
   4.507 +        if (info->scale_modes & flag) {
   4.508 +            if (count > 0) {
   4.509 +                fprintf(stderr, " | ");
   4.510 +            }
   4.511 +            PrintScaleMode(flag);
   4.512 +            ++count;
   4.513 +        }
   4.514 +    }
   4.515 +    fprintf(stderr, ")\n");
   4.516 +
   4.517 +    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
   4.518 +    for (i = 0; i < (int) info->num_texture_formats; ++i) {
   4.519 +        if (i > 0) {
   4.520 +            fprintf(stderr, ", ");
   4.521 +        }
   4.522 +        PrintPixelFormat(info->texture_formats[i]);
   4.523 +    }
   4.524 +    fprintf(stderr, "\n");
   4.525 +
   4.526 +    if (info->max_texture_width || info->max_texture_height) {
   4.527 +        fprintf(stderr, "    Max Texture Size: %dx%d\n",
   4.528 +                info->max_texture_width, info->max_texture_height);
   4.529 +    }
   4.530 +}
   4.531 +
   4.532 +SDL_bool
   4.533 +CommonInit(CommonState * state)
   4.534 +{
   4.535 +    int i, j, m, n;
   4.536 +    SDL_DisplayMode fullscreen_mode;
   4.537 +
   4.538 +    if (state->flags & SDL_INIT_VIDEO) {
   4.539 +        if (state->verbose & VERBOSE_VIDEO) {
   4.540 +            n = SDL_GetNumVideoDrivers();
   4.541 +            if (n == 0) {
   4.542 +                fprintf(stderr, "No built-in video drivers\n");
   4.543 +            } else {
   4.544 +                fprintf(stderr, "Built-in video drivers:");
   4.545 +                for (i = 0; i < n; ++i) {
   4.546 +                    if (i > 0) {
   4.547 +                        fprintf(stderr, ",");
   4.548 +                    }
   4.549 +                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
   4.550 +                }
   4.551 +                fprintf(stderr, "\n");
   4.552 +            }
   4.553 +        }
   4.554 +        if (SDL_VideoInit(state->videodriver, 0) < 0) {
   4.555 +            fprintf(stderr, "Couldn't initialize video driver: %s\n",
   4.556 +                    SDL_GetError());
   4.557 +            return SDL_FALSE;
   4.558 +        }
   4.559 +        if (state->verbose & VERBOSE_VIDEO) {
   4.560 +            fprintf(stderr, "Video driver: %s\n",
   4.561 +                    SDL_GetCurrentVideoDriver());
   4.562 +        }
   4.563 +
   4.564 +        if (state->verbose & VERBOSE_MODES) {
   4.565 +            SDL_DisplayMode mode;
   4.566 +            int bpp;
   4.567 +            Uint32 Rmask, Gmask, Bmask, Amask;
   4.568 +
   4.569 +            n = SDL_GetNumVideoDisplays();
   4.570 +            fprintf(stderr, "Number of displays: %d\n", n);
   4.571 +            for (i = 0; i < n; ++i) {
   4.572 +                fprintf(stderr, "Display %d:\n", i);
   4.573 +                SDL_SelectVideoDisplay(i);
   4.574 +
   4.575 +                SDL_GetDesktopDisplayMode(&mode);
   4.576 +                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
   4.577 +                                           &Bmask, &Amask);
   4.578 +                fprintf(stderr,
   4.579 +                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
   4.580 +                        mode.w, mode.h, mode.refresh_rate, bpp);
   4.581 +                if (Rmask || Gmask || Bmask) {
   4.582 +                    fprintf(stderr, "      Red Mask = 0x%.8x\n", Rmask);
   4.583 +                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
   4.584 +                    fprintf(stderr, "      Blue Mask = 0x%.8x\n", Bmask);
   4.585 +                    if (Amask)
   4.586 +                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
   4.587 +                }
   4.588 +
   4.589 +                /* Print available fullscreen video modes */
   4.590 +                m = SDL_GetNumDisplayModes();
   4.591 +                if (m == 0) {
   4.592 +                    fprintf(stderr, "No available fullscreen video modes\n");
   4.593 +                } else {
   4.594 +                    fprintf(stderr, "  Fullscreen video modes:\n");
   4.595 +                    for (j = 0; j < m; ++j) {
   4.596 +                        SDL_GetDisplayMode(j, &mode);
   4.597 +                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
   4.598 +                                                   &Gmask, &Bmask, &Amask);
   4.599 +                        fprintf(stderr,
   4.600 +                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
   4.601 +                                j, mode.w, mode.h, mode.refresh_rate, bpp);
   4.602 +                        if (Rmask || Gmask || Bmask) {
   4.603 +                            fprintf(stderr, "        Red Mask = 0x%.8x\n",
   4.604 +                                    Rmask);
   4.605 +                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
   4.606 +                                    Gmask);
   4.607 +                            fprintf(stderr, "        Blue Mask = 0x%.8x\n",
   4.608 +                                    Bmask);
   4.609 +                            if (Amask)
   4.610 +                                fprintf(stderr,
   4.611 +                                        "        Alpha Mask = 0x%.8x\n",
   4.612 +                                        Amask);
   4.613 +                        }
   4.614 +                    }
   4.615 +                }
   4.616 +            }
   4.617 +        }
   4.618 +
   4.619 +        SDL_SelectVideoDisplay(state->display);
   4.620 +        if (state->verbose & VERBOSE_RENDER) {
   4.621 +            SDL_RendererInfo info;
   4.622 +
   4.623 +            n = SDL_GetNumRenderDrivers();
   4.624 +            if (n == 0) {
   4.625 +                fprintf(stderr, "No built-in render drivers\n");
   4.626 +            } else {
   4.627 +                fprintf(stderr, "Built-in render drivers:\n");
   4.628 +                for (i = 0; i < n; ++i) {
   4.629 +                    SDL_GetRenderDriverInfo(i, &info);
   4.630 +                    PrintRenderer(&info);
   4.631 +                }
   4.632 +            }
   4.633 +        }
   4.634 +
   4.635 +        switch (state->depth) {
   4.636 +        case 8:
   4.637 +            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
   4.638 +            break;
   4.639 +        case 15:
   4.640 +            fullscreen_mode.format = SDL_PIXELFORMAT_BGR555;
   4.641 +            break;
   4.642 +        case 16:
   4.643 +        default:
   4.644 +            fullscreen_mode.format = SDL_PIXELFORMAT_ABGR1555;
   4.645 +            break;
   4.646 +/* NDS       default:
   4.647 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
   4.648 +            break;*/
   4.649 +        }
   4.650 +        fullscreen_mode.w = state->window_w;
   4.651 +        fullscreen_mode.h = state->window_h;
   4.652 +        fullscreen_mode.refresh_rate = state->refresh_rate;
   4.653 +        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
   4.654 +
   4.655 +        state->windows =
   4.656 +            (SDL_WindowID *) SDL_malloc(state->num_windows *
   4.657 +                                        sizeof(*state->windows));
   4.658 +        if (!state->windows) {
   4.659 +            fprintf(stderr, "Out of memory!\n");
   4.660 +            return SDL_FALSE;
   4.661 +        }
   4.662 +        for (i = 0; i < state->num_windows; ++i) {
   4.663 +            char title[1024];
   4.664 +
   4.665 +            if (state->num_windows > 1) {
   4.666 +                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
   4.667 +                             state->window_title, i + 1);
   4.668 +            } else {
   4.669 +                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
   4.670 +            }
   4.671 +            state->windows[i] =
   4.672 +                SDL_CreateWindow(title, state->window_x, state->window_y,
   4.673 +                                 state->window_w, state->window_h,
   4.674 +                                 state->window_flags);
   4.675 +            if (!state->windows[i]) {
   4.676 +                fprintf(stderr, "Couldn't create window: %s\n",
   4.677 +                        SDL_GetError());
   4.678 +                return SDL_FALSE;
   4.679 +            }
   4.680 +
   4.681 +            if (!state->skip_renderer
   4.682 +                && (state->renderdriver
   4.683 +                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
   4.684 +                m = -1;
   4.685 +                if (state->renderdriver) {
   4.686 +                    SDL_RendererInfo info;
   4.687 +                    n = SDL_GetNumRenderDrivers();
   4.688 +                    for (j = 0; j < n; ++j) {
   4.689 +                        SDL_GetRenderDriverInfo(j, &info);
   4.690 +                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
   4.691 +                            0) {
   4.692 +                            m = j;
   4.693 +                            break;
   4.694 +                        }
   4.695 +                    }
   4.696 +                    if (m == n) {
   4.697 +                        fprintf(stderr,
   4.698 +                                "Couldn't find render driver named %s",
   4.699 +                                state->renderdriver);
   4.700 +                        return SDL_FALSE;
   4.701 +                    }
   4.702 +                }
   4.703 +                if (SDL_CreateRenderer
   4.704 +                    (state->windows[i], m, state->render_flags) < 0) {
   4.705 +                    fprintf(stderr, "Couldn't create renderer: %s\n",
   4.706 +                            SDL_GetError());
   4.707 +                    return SDL_FALSE;
   4.708 +                }
   4.709 +                if (state->verbose & VERBOSE_RENDER) {
   4.710 +                    SDL_RendererInfo info;
   4.711 +
   4.712 +                    fprintf(stderr, "Current renderer:\n");
   4.713 +                    SDL_GetRendererInfo(&info);
   4.714 +                    PrintRenderer(&info);
   4.715 +                }
   4.716 +            }
   4.717 +        }
   4.718 +        SDL_SelectRenderer(state->windows[0]);
   4.719 +    }
   4.720 +
   4.721 +    if (state->flags & SDL_INIT_AUDIO) {
   4.722 +        if (state->verbose & VERBOSE_AUDIO) {
   4.723 +            n = SDL_GetNumAudioDrivers();
   4.724 +            if (n == 0) {
   4.725 +                fprintf(stderr, "No built-in audio drivers\n");
   4.726 +            } else {
   4.727 +                fprintf(stderr, "Built-in audio drivers:");
   4.728 +                for (i = 0; i < n; ++i) {
   4.729 +                    if (i > 0) {
   4.730 +                        fprintf(stderr, ",");
   4.731 +                    }
   4.732 +                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
   4.733 +                }
   4.734 +                fprintf(stderr, "\n");
   4.735 +            }
   4.736 +        }
   4.737 +        if (SDL_AudioInit(state->audiodriver) < 0) {
   4.738 +            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
   4.739 +                    SDL_GetError());
   4.740 +            return SDL_FALSE;
   4.741 +        }
   4.742 +        if (state->verbose & VERBOSE_VIDEO) {
   4.743 +            fprintf(stderr, "Audio driver: %s\n",
   4.744 +                    SDL_GetCurrentAudioDriver());
   4.745 +        }
   4.746 +
   4.747 +        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
   4.748 +            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   4.749 +            return SDL_FALSE;
   4.750 +        }
   4.751 +    }
   4.752 +
   4.753 +    return SDL_TRUE;
   4.754 +}
   4.755 +
   4.756 +static void
   4.757 +PrintEvent(SDL_Event * event)
   4.758 +{
   4.759 +    fprintf(stderr, "SDL EVENT: ");
   4.760 +    switch (event->type) {
   4.761 +    case SDL_WINDOWEVENT:
   4.762 +        switch (event->window.event) {
   4.763 +        case SDL_WINDOWEVENT_SHOWN:
   4.764 +            fprintf(stderr, "Window %d shown", event->window.windowID);
   4.765 +            break;
   4.766 +        case SDL_WINDOWEVENT_HIDDEN:
   4.767 +            fprintf(stderr, "Window %d hidden", event->window.windowID);
   4.768 +            break;
   4.769 +        case SDL_WINDOWEVENT_EXPOSED:
   4.770 +            fprintf(stderr, "Window %d exposed", event->window.windowID);
   4.771 +            break;
   4.772 +        case SDL_WINDOWEVENT_MOVED:
   4.773 +            fprintf(stderr, "Window %d moved to %d,%d",
   4.774 +                    event->window.windowID, event->window.data1,
   4.775 +                    event->window.data2);
   4.776 +            break;
   4.777 +        case SDL_WINDOWEVENT_RESIZED:
   4.778 +            fprintf(stderr, "Window %d resized to %dx%d",
   4.779 +                    event->window.windowID, event->window.data1,
   4.780 +                    event->window.data2);
   4.781 +            break;
   4.782 +        case SDL_WINDOWEVENT_MINIMIZED:
   4.783 +            fprintf(stderr, "Window %d minimized", event->window.windowID);
   4.784 +            break;
   4.785 +        case SDL_WINDOWEVENT_MAXIMIZED:
   4.786 +            fprintf(stderr, "Window %d maximized", event->window.windowID);
   4.787 +            break;
   4.788 +        case SDL_WINDOWEVENT_RESTORED:
   4.789 +            fprintf(stderr, "Window %d restored", event->window.windowID);
   4.790 +            break;
   4.791 +        case SDL_WINDOWEVENT_ENTER:
   4.792 +            fprintf(stderr, "Mouse entered window %d",
   4.793 +                    event->window.windowID);
   4.794 +            break;
   4.795 +        case SDL_WINDOWEVENT_LEAVE:
   4.796 +            fprintf(stderr, "Mouse left window %d", event->window.windowID);
   4.797 +            break;
   4.798 +        case SDL_WINDOWEVENT_FOCUS_GAINED:
   4.799 +            fprintf(stderr, "Window %d gained keyboard focus",
   4.800 +                    event->window.windowID);
   4.801 +            break;
   4.802 +        case SDL_WINDOWEVENT_FOCUS_LOST:
   4.803 +            fprintf(stderr, "Window %d lost keyboard focus",
   4.804 +                    event->window.windowID);
   4.805 +            break;
   4.806 +        case SDL_WINDOWEVENT_CLOSE:
   4.807 +            fprintf(stderr, "Window %d closed", event->window.windowID);
   4.808 +            break;
   4.809 +        default:
   4.810 +            fprintf(stderr, "Window %d got unknown event %d",
   4.811 +                    event->window.windowID, event->window.event);
   4.812 +            break;
   4.813 +        }
   4.814 +        break;
   4.815 +    case SDL_KEYDOWN:
   4.816 +        fprintf(stderr,
   4.817 +                "Keyboard %d: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   4.818 +                event->key.which, event->key.windowID,
   4.819 +                event->key.keysym.scancode,
   4.820 +                SDL_GetScancodeName(event->key.keysym.scancode),
   4.821 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   4.822 +        break;
   4.823 +    case SDL_KEYUP:
   4.824 +        fprintf(stderr,
   4.825 +                "Keyboard %d: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   4.826 +                event->key.which, event->key.windowID,
   4.827 +                event->key.keysym.scancode,
   4.828 +                SDL_GetScancodeName(event->key.keysym.scancode),
   4.829 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   4.830 +        break;
   4.831 +    case SDL_TEXTINPUT:
   4.832 +        fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d",
   4.833 +                event->text.which, event->text.text, event->text.windowID);
   4.834 +        break;
   4.835 +    case SDL_MOUSEMOTION:
   4.836 +        fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d",
   4.837 +                event->motion.which, event->motion.x, event->motion.y,
   4.838 +                event->motion.xrel, event->motion.yrel,
   4.839 +                event->motion.windowID);
   4.840 +        break;
   4.841 +    case SDL_MOUSEBUTTONDOWN:
   4.842 +        fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d",
   4.843 +                event->button.which, event->button.button, event->button.x,
   4.844 +                event->button.y, event->button.windowID);
   4.845 +        break;
   4.846 +    case SDL_MOUSEBUTTONUP:
   4.847 +        fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d",
   4.848 +                event->button.which, event->button.button, event->button.x,
   4.849 +                event->button.y, event->button.windowID);
   4.850 +        break;
   4.851 +    case SDL_MOUSEWHEEL:
   4.852 +        fprintf(stderr,
   4.853 +                "Mouse %d: wheel scrolled %d in x and %d in y in window %d",
   4.854 +                event->wheel.which, event->wheel.x, event->wheel.y,
   4.855 +                event->wheel.windowID);
   4.856 +        break;
   4.857 +    case SDL_JOYBALLMOTION:
   4.858 +        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
   4.859 +                event->jball.which, event->jball.ball, event->jball.xrel,
   4.860 +                event->jball.yrel);
   4.861 +        break;
   4.862 +    case SDL_JOYHATMOTION:
   4.863 +        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
   4.864 +                event->jhat.hat);
   4.865 +        switch (event->jhat.value) {
   4.866 +        case SDL_HAT_CENTERED:
   4.867 +            fprintf(stderr, "CENTER");
   4.868 +            break;
   4.869 +        case SDL_HAT_UP:
   4.870 +            fprintf(stderr, "UP");
   4.871 +            break;
   4.872 +        case SDL_HAT_RIGHTUP:
   4.873 +            fprintf(stderr, "RIGHTUP");
   4.874 +            break;
   4.875 +        case SDL_HAT_RIGHT:
   4.876 +            fprintf(stderr, "RIGHT");
   4.877 +            break;
   4.878 +        case SDL_HAT_RIGHTDOWN:
   4.879 +            fprintf(stderr, "RIGHTDOWN");
   4.880 +            break;
   4.881 +        case SDL_HAT_DOWN:
   4.882 +            fprintf(stderr, "DOWN");
   4.883 +            break;
   4.884 +        case SDL_HAT_LEFTDOWN:
   4.885 +            fprintf(stderr, "LEFTDOWN");
   4.886 +            break;
   4.887 +        case SDL_HAT_LEFT:
   4.888 +            fprintf(stderr, "LEFT");
   4.889 +            break;
   4.890 +        case SDL_HAT_LEFTUP:
   4.891 +            fprintf(stderr, "LEFTUP");
   4.892 +            break;
   4.893 +        default:
   4.894 +            fprintf(stderr, "UNKNOWN");
   4.895 +            break;
   4.896 +        }
   4.897 +        break;
   4.898 +    case SDL_JOYBUTTONDOWN:
   4.899 +        fprintf(stderr, "Joystick %d: button %d pressed",
   4.900 +                event->jbutton.which, event->jbutton.button);
   4.901 +        break;
   4.902 +    case SDL_JOYBUTTONUP:
   4.903 +        fprintf(stderr, "Joystick %d: button %d released",
   4.904 +                event->jbutton.which, event->jbutton.button);
   4.905 +        break;
   4.906 +    case SDL_QUIT:
   4.907 +        fprintf(stderr, "Quit requested");
   4.908 +        break;
   4.909 +    case SDL_USEREVENT:
   4.910 +        fprintf(stderr, "User event %d", event->user.code);
   4.911 +        break;
   4.912 +    default:
   4.913 +        fprintf(stderr, "Unknown event %d", event->type);
   4.914 +        break;
   4.915 +    }
   4.916 +    fprintf(stderr, "\n");
   4.917 +}
   4.918 +
   4.919 +void
   4.920 +CommonEvent(CommonState * state, SDL_Event * event, int *done)
   4.921 +{
   4.922 +    if (state->verbose & VERBOSE_EVENT) {
   4.923 +        PrintEvent(event);
   4.924 +    }
   4.925 +
   4.926 +    switch (event->type) {
   4.927 +    case SDL_WINDOWEVENT:
   4.928 +        switch (event->window.event) {
   4.929 +        case SDL_WINDOWEVENT_CLOSE:
   4.930 +            *done = 1;
   4.931 +            break;
   4.932 +        }
   4.933 +        break;
   4.934 +    case SDL_KEYDOWN:
   4.935 +        switch (event->key.keysym.sym) {
   4.936 +            /* Add hotkeys here */
   4.937 +        case SDLK_g:
   4.938 +            if (event->key.keysym.mod & KMOD_CTRL) {
   4.939 +                /* Ctrl-G toggle grab */
   4.940 +            }
   4.941 +            break;
   4.942 +        case SDLK_ESCAPE:
   4.943 +            *done = 1;
   4.944 +            break;
   4.945 +        default:
   4.946 +            break;
   4.947 +        }
   4.948 +        break;
   4.949 +    case SDL_QUIT:
   4.950 +        *done = 1;
   4.951 +        break;
   4.952 +    }
   4.953 +}
   4.954 +
   4.955 +void
   4.956 +CommonQuit(CommonState * state)
   4.957 +{
   4.958 +    if (state->flags & SDL_INIT_VIDEO) {
   4.959 +        SDL_VideoQuit();
   4.960 +    }
   4.961 +    if (state->flags & SDL_INIT_AUDIO) {
   4.962 +        SDL_AudioQuit();
   4.963 +    }
   4.964 +    if (state->windows) {
   4.965 +        SDL_free(state->windows);
   4.966 +    }
   4.967 +    SDL_free(state);
   4.968 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/nds-test-progs/sprite/source/common.h	Wed Aug 13 00:49:03 2008 +0000
     5.3 @@ -0,0 +1,48 @@
     5.4 +
     5.5 +/* A simple test program framework */
     5.6 +
     5.7 +#include <SDL/SDL.h>
     5.8 +
     5.9 +#define VERBOSE_VIDEO   0x00000001
    5.10 +#define VERBOSE_MODES   0x00000002
    5.11 +#define VERBOSE_RENDER  0x00000004
    5.12 +#define VERBOSE_EVENT   0x00000008
    5.13 +#define VERBOSE_AUDIO   0x00000010
    5.14 +
    5.15 +typedef struct
    5.16 +{
    5.17 +    /* SDL init flags */
    5.18 +    char **argv;
    5.19 +    Uint32 flags;
    5.20 +    Uint32 verbose;
    5.21 +
    5.22 +    /* Video info */
    5.23 +    const char *videodriver;
    5.24 +    int display;
    5.25 +    const char *window_title;
    5.26 +    Uint32 window_flags;
    5.27 +    int window_x;
    5.28 +    int window_y;
    5.29 +    int window_w;
    5.30 +    int window_h;
    5.31 +    int depth;
    5.32 +    int refresh_rate;
    5.33 +    int num_windows;
    5.34 +    SDL_WindowID *windows;
    5.35 +
    5.36 +    /* Renderer info */
    5.37 +    const char *renderdriver;
    5.38 +    Uint32 render_flags;
    5.39 +    SDL_bool skip_renderer;
    5.40 +
    5.41 +    /* Audio info */
    5.42 +    const char *audiodriver;
    5.43 +    SDL_AudioSpec audiospec;
    5.44 +} CommonState;
    5.45 +
    5.46 +extern CommonState *CommonCreateState(char **argv, Uint32 flags);
    5.47 +extern int CommonArg(CommonState * state, int index);
    5.48 +extern const char *CommonUsage(CommonState * state);
    5.49 +extern SDL_bool CommonInit(CommonState * state);
    5.50 +extern void CommonEvent(CommonState * state, SDL_Event * event, int *done);
    5.51 +extern void CommonQuit(CommonState * state);
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/nds-test-progs/sprite/source/testsprite.c	Wed Aug 13 00:49:03 2008 +0000
     6.3 @@ -0,0 +1,319 @@
     6.4 +/* Simple program:  Move N sprites around on the screen as fast as possible */
     6.5 +
     6.6 +#include <stdlib.h>
     6.7 +#include <stdio.h>
     6.8 +#include <time.h>
     6.9 +#include <math.h>
    6.10 +
    6.11 +#include "SDL.h"
    6.12 +
    6.13 +#define NUM_SPRITES	100
    6.14 +#define MAX_SPEED 	1
    6.15 +
    6.16 +SDL_Surface *sprite;
    6.17 +int numsprites;
    6.18 +SDL_Rect *sprite_rects;
    6.19 +SDL_Rect *positions;
    6.20 +SDL_Rect *velocities;
    6.21 +int sprites_visible;
    6.22 +int debug_flip;
    6.23 +Uint16 sprite_w, sprite_h;
    6.24 +
    6.25 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    6.26 +static void
    6.27 +quit(int rc)
    6.28 +{
    6.29 +    SDL_Quit();
    6.30 +    exit(rc);
    6.31 +}
    6.32 +
    6.33 +int
    6.34 +LoadSprite(char *file)
    6.35 +{
    6.36 +    SDL_Surface *temp;
    6.37 +
    6.38 +    /* Load the sprite image */
    6.39 +    sprite = SDL_LoadBMP(file);
    6.40 +    if (sprite == NULL) {
    6.41 +        fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
    6.42 +        return (-1);
    6.43 +    }
    6.44 +
    6.45 +    /* Set transparent pixel as the pixel at (0,0) */
    6.46 +    if (sprite->format->palette) {
    6.47 +        SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
    6.48 +                        *(Uint8 *) sprite->pixels);
    6.49 +    }
    6.50 +
    6.51 +    /* Convert sprite to video format */
    6.52 +    temp = SDL_DisplayFormat(sprite);
    6.53 +    SDL_FreeSurface(sprite);
    6.54 +    if (temp == NULL) {
    6.55 +        fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError());
    6.56 +        return (-1);
    6.57 +    }
    6.58 +    sprite = temp;
    6.59 +
    6.60 +    /* We're ready to roll. :) */
    6.61 +    return (0);
    6.62 +}
    6.63 +
    6.64 +void
    6.65 +MoveSprites(SDL_Surface * screen, Uint32 background)
    6.66 +{
    6.67 +    int i, nupdates;
    6.68 +    SDL_Rect area, *position, *velocity;
    6.69 +
    6.70 +    nupdates = 0;
    6.71 +    /* Erase all the sprites if necessary */
    6.72 +    if (sprites_visible) {
    6.73 +        SDL_FillRect(screen, NULL, background);
    6.74 +    }
    6.75 +
    6.76 +    /* Move the sprite, bounce at the wall, and draw */
    6.77 +    for (i = 0; i < numsprites; ++i) {
    6.78 +        position = &positions[i];
    6.79 +        velocity = &velocities[i];
    6.80 +        position->x += velocity->x;
    6.81 +        if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) {
    6.82 +            velocity->x = -velocity->x;
    6.83 +            position->x += velocity->x;
    6.84 +        }
    6.85 +        position->y += velocity->y;
    6.86 +        if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) {
    6.87 +            velocity->y = -velocity->y;
    6.88 +            position->y += velocity->y;
    6.89 +        }
    6.90 +
    6.91 +        /* Blit the sprite onto the screen */
    6.92 +        area = *position;
    6.93 +        SDL_BlitSurface(sprite, NULL, screen, &area);
    6.94 +        sprite_rects[nupdates++] = area;
    6.95 +    }
    6.96 +
    6.97 +    if (debug_flip) {
    6.98 +        if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
    6.99 +            static int t = 0;
   6.100 +
   6.101 +            Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0);
   6.102 +            SDL_Rect r;
   6.103 +            r.x =
   6.104 +                (sin((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20);
   6.105 +            r.y = 0;
   6.106 +            r.w = 20;
   6.107 +            r.h = screen->h;
   6.108 +
   6.109 +            SDL_FillRect(screen, &r, color);
   6.110 +            t += 2;
   6.111 +        }
   6.112 +    }
   6.113 +
   6.114 +    /* Update the screen! */
   6.115 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   6.116 +        SDL_Flip(screen);
   6.117 +    } else {
   6.118 +        SDL_UpdateRects(screen, nupdates, sprite_rects);
   6.119 +    }
   6.120 +    sprites_visible = 1;
   6.121 +}
   6.122 +
   6.123 +/* This is a way of telling whether or not to use hardware surfaces */
   6.124 +Uint32
   6.125 +FastestFlags(Uint32 flags, int width, int height, int bpp)
   6.126 +{
   6.127 +    const SDL_VideoInfo *info;
   6.128 +
   6.129 +    /* Hardware acceleration is only used in fullscreen mode */
   6.130 +    flags |= SDL_FULLSCREEN;
   6.131 +
   6.132 +    /* Check for various video capabilities */
   6.133 +    info = SDL_GetVideoInfo();
   6.134 +    if (info->blit_hw_CC && info->blit_fill) {
   6.135 +        /* We use accelerated colorkeying and color filling */
   6.136 +        flags |= SDL_HWSURFACE;
   6.137 +    }
   6.138 +    /* If we have enough video memory, and will use accelerated
   6.139 +       blits directly to it, then use page flipping.
   6.140 +     */
   6.141 +    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   6.142 +        /* Direct hardware blitting without double-buffering
   6.143 +           causes really bad flickering.
   6.144 +         */
   6.145 +        if (info->video_mem * 1024 > (height * width * bpp / 8)) {
   6.146 +            flags |= SDL_DOUBLEBUF;
   6.147 +        } else {
   6.148 +            flags &= ~SDL_HWSURFACE;
   6.149 +        }
   6.150 +    }
   6.151 +
   6.152 +    /* Return the flags */
   6.153 +    return (flags);
   6.154 +}
   6.155 +
   6.156 +int
   6.157 +main(int argc, char *argv[])
   6.158 +{
   6.159 +    SDL_Surface *screen;
   6.160 +    Uint8 *mem;
   6.161 +    int width, height;
   6.162 +    Uint8 video_bpp;
   6.163 +    Uint32 videoflags;
   6.164 +    Uint32 background;
   6.165 +    int i, done;
   6.166 +    SDL_Event event;
   6.167 +    Uint32 then, now, frames;
   6.168 +
   6.169 +    /* Initialize SDL */
   6.170 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   6.171 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   6.172 +        return (1);
   6.173 +    }
   6.174 +
   6.175 +    numsprites = NUM_SPRITES;
   6.176 +    videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
   6.177 +    width = 640;
   6.178 +    height = 480;
   6.179 +    video_bpp = 8;
   6.180 +    debug_flip = 0;
   6.181 +    while (argc > 1) {
   6.182 +        --argc;
   6.183 +        if (strcmp(argv[argc - 1], "-width") == 0) {
   6.184 +            width = atoi(argv[argc]);
   6.185 +            --argc;
   6.186 +        } else if (strcmp(argv[argc - 1], "-height") == 0) {
   6.187 +            height = atoi(argv[argc]);
   6.188 +            --argc;
   6.189 +        } else if (strcmp(argv[argc - 1], "-bpp") == 0) {
   6.190 +            video_bpp = atoi(argv[argc]);
   6.191 +            videoflags &= ~SDL_ANYFORMAT;
   6.192 +            --argc;
   6.193 +        } else if (strcmp(argv[argc], "-fast") == 0) {
   6.194 +            videoflags = FastestFlags(videoflags, width, height, video_bpp);
   6.195 +        } else if (strcmp(argv[argc], "-hw") == 0) {
   6.196 +            videoflags ^= SDL_HWSURFACE;
   6.197 +        } else if (strcmp(argv[argc], "-flip") == 0) {
   6.198 +            videoflags ^= SDL_DOUBLEBUF;
   6.199 +        } else if (strcmp(argv[argc], "-debugflip") == 0) {
   6.200 +            debug_flip ^= 1;
   6.201 +        } else if (strcmp(argv[argc], "-fullscreen") == 0) {
   6.202 +            videoflags ^= SDL_FULLSCREEN;
   6.203 +        } else if (isdigit(argv[argc][0])) {
   6.204 +            numsprites = atoi(argv[argc]);
   6.205 +        } else {
   6.206 +            fprintf(stderr,
   6.207 +                    "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
   6.208 +                    argv[0]);
   6.209 +            quit(1);
   6.210 +        }
   6.211 +    }
   6.212 +
   6.213 +    /* Set video mode */
   6.214 +    screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
   6.215 +    if (!screen) {
   6.216 +        fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
   6.217 +                width, height, SDL_GetError());
   6.218 +        quit(2);
   6.219 +    }
   6.220 +
   6.221 +    /* Load the sprite */
   6.222 +    if (LoadSprite("icon.bmp") < 0) {
   6.223 +        quit(1);
   6.224 +    }
   6.225 +
   6.226 +    /* Allocate memory for the sprite info */
   6.227 +    mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
   6.228 +    if (mem == NULL) {
   6.229 +        SDL_FreeSurface(sprite);
   6.230 +        fprintf(stderr, "Out of memory!\n");
   6.231 +        quit(2);
   6.232 +    }
   6.233 +    sprite_rects = (SDL_Rect *) mem;
   6.234 +    positions = sprite_rects;
   6.235 +    sprite_rects += numsprites;
   6.236 +    velocities = sprite_rects;
   6.237 +    sprite_rects += numsprites;
   6.238 +    sprite_w = sprite->w;
   6.239 +    sprite_h = sprite->h;
   6.240 +    srand(time(NULL));
   6.241 +    for (i = 0; i < numsprites; ++i) {
   6.242 +        positions[i].x = rand() % (screen->w - sprite_w);
   6.243 +        positions[i].y = rand() % (screen->h - sprite_h);
   6.244 +        positions[i].w = sprite->w;
   6.245 +        positions[i].h = sprite->h;
   6.246 +        velocities[i].x = 0;
   6.247 +        velocities[i].y = 0;
   6.248 +        while (!velocities[i].x && !velocities[i].y) {
   6.249 +            velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
   6.250 +            velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
   6.251 +        }
   6.252 +    }
   6.253 +    background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
   6.254 +
   6.255 +    /* Print out information about our surfaces */
   6.256 +    printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel);
   6.257 +    if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   6.258 +        printf("Screen is in video memory\n");
   6.259 +    } else {
   6.260 +        printf("Screen is in system memory\n");
   6.261 +    }
   6.262 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   6.263 +        printf("Screen has double-buffering enabled\n");
   6.264 +    }
   6.265 +    if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   6.266 +        printf("Sprite is in video memory\n");
   6.267 +    } else {
   6.268 +        printf("Sprite is in system memory\n");
   6.269 +    }
   6.270 +    /* Run a sample blit to trigger blit acceleration */
   6.271 +    {
   6.272 +        SDL_Rect dst;
   6.273 +        dst.x = 0;
   6.274 +        dst.y = 0;
   6.275 +        dst.w = sprite->w;
   6.276 +        dst.h = sprite->h;
   6.277 +        SDL_BlitSurface(sprite, NULL, screen, &dst);
   6.278 +        SDL_FillRect(screen, &dst, background);
   6.279 +    }
   6.280 +    if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   6.281 +        printf("Sprite blit uses hardware acceleration\n");
   6.282 +    }
   6.283 +    if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
   6.284 +        printf("Sprite blit uses RLE acceleration\n");
   6.285 +    }
   6.286 +
   6.287 +    /* Loop, blitting sprites and waiting for a keystroke */
   6.288 +    frames = 0;
   6.289 +    then = SDL_GetTicks();
   6.290 +    done = 0;
   6.291 +    sprites_visible = 0;
   6.292 +    while (!done) {
   6.293 +        /* Check for events */
   6.294 +        ++frames;
   6.295 +        while (SDL_PollEvent(&event)) {
   6.296 +            switch (event.type) {
   6.297 +            case SDL_MOUSEBUTTONDOWN:
   6.298 +                SDL_WarpMouse(screen->w / 2, screen->h / 2);
   6.299 +                break;
   6.300 +            case SDL_KEYDOWN:
   6.301 +                /* Any keypress quits the app... */
   6.302 +            case SDL_QUIT:
   6.303 +                done = 1;
   6.304 +                break;
   6.305 +            default:
   6.306 +                break;
   6.307 +            }
   6.308 +        }
   6.309 +        MoveSprites(screen, background);
   6.310 +    }
   6.311 +    SDL_FreeSurface(sprite);
   6.312 +    free(mem);
   6.313 +
   6.314 +    /* Print out some timing information */
   6.315 +    now = SDL_GetTicks();
   6.316 +    if (now > then) {
   6.317 +        printf("%2.2f frames per second\n",
   6.318 +               ((double) frames * 1000) / (now - then));
   6.319 +    }
   6.320 +    SDL_Quit();
   6.321 +    return (0);
   6.322 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/nds-test-progs/sprite2/Makefile	Wed Aug 13 00:49:03 2008 +0000
     7.3 @@ -0,0 +1,132 @@
     7.4 +#---------------------------------------------------------------------------------
     7.5 +.SUFFIXES:
     7.6 +#---------------------------------------------------------------------------------
     7.7 +
     7.8 +ifeq ($(strip $(DEVKITARM)),)
     7.9 +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
    7.10 +endif
    7.11 +
    7.12 +include $(DEVKITARM)/ds_rules
    7.13 +
    7.14 +#---------------------------------------------------------------------------------
    7.15 +# TARGET is the name of the output
    7.16 +# BUILD is the directory where object files & intermediate files will be placed
    7.17 +# SOURCES is a list of directories containing source code
    7.18 +# INCLUDES is a list of directories containing extra header files
    7.19 +#---------------------------------------------------------------------------------
    7.20 +TARGET		:=	$(shell basename $(CURDIR))
    7.21 +BUILD		:=	build
    7.22 +SOURCES		:=	source
    7.23 +DATA		:=	data  
    7.24 +INCLUDES	:=	include
    7.25 +
    7.26 +#---------------------------------------------------------------------------------
    7.27 +# options for code generation
    7.28 +#---------------------------------------------------------------------------------
    7.29 +ARCH	:=	-mthumb -mthumb-interwork
    7.30 +
    7.31 +# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
    7.32 +# *insists* it has a FPU or VFP, and it won't take no for an answer!
    7.33 +CFLAGS	:=	-save-temps -g -Wall -O0\
    7.34 + 			-mcpu=arm9tdmi -mtune=arm9tdmi \
    7.35 +			$(ARCH)
    7.36 +
    7.37 +CFLAGS	+=	$(INCLUDE) -DARM9 -D__NDS__
    7.38 +CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -fno-exceptions -fno-rtti
    7.39 +
    7.40 +ASFLAGS	:=	-g $(ARCH)
    7.41 +LDFLAGS	=	-specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
    7.42 +
    7.43 +#---------------------------------------------------------------------------------
    7.44 +# any extra libraries we wish to link with the project
    7.45 +#---------------------------------------------------------------------------------
    7.46 +LIBS	:= -lSDL -lfat -lnds9
    7.47 + 
    7.48 + 
    7.49 +#---------------------------------------------------------------------------------
    7.50 +# list of directories containing libraries, this must be the top level containing
    7.51 +# include and lib
    7.52 +#---------------------------------------------------------------------------------
    7.53 +LIBDIRS	:=	$(LIBNDS)
    7.54 + 
    7.55 +#---------------------------------------------------------------------------------
    7.56 +# no real need to edit anything past this point unless you need to add additional
    7.57 +# rules for different file extensions
    7.58 +#---------------------------------------------------------------------------------
    7.59 +ifneq ($(BUILD),$(notdir $(CURDIR)))
    7.60 +#---------------------------------------------------------------------------------
    7.61 + 
    7.62 +export OUTPUT	:=	$(CURDIR)/$(TARGET)
    7.63 + 
    7.64 +export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
    7.65 +					$(foreach dir,$(DATA),$(CURDIR)/$(dir))
    7.66 +
    7.67 +export DEPSDIR	:=	$(CURDIR)/$(BUILD)
    7.68 +
    7.69 +CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
    7.70 +CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
    7.71 +SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
    7.72 +BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
    7.73 + 
    7.74 +#---------------------------------------------------------------------------------
    7.75 +# use CXX for linking C++ projects, CC for standard C
    7.76 +#---------------------------------------------------------------------------------
    7.77 +ifeq ($(strip $(CPPFILES)),)
    7.78 +#---------------------------------------------------------------------------------
    7.79 +	export LD	:=	$(CC)
    7.80 +#---------------------------------------------------------------------------------
    7.81 +else
    7.82 +#---------------------------------------------------------------------------------
    7.83 +	export LD	:=	$(CXX)
    7.84 +#---------------------------------------------------------------------------------
    7.85 +endif
    7.86 +#---------------------------------------------------------------------------------
    7.87 +
    7.88 +export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
    7.89 +					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
    7.90 + 
    7.91 +export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
    7.92 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    7.93 +					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
    7.94 +					-I$(CURDIR)/$(BUILD)
    7.95 + 
    7.96 +export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)
    7.97 + 
    7.98 +.PHONY: $(BUILD) clean
    7.99 + 
   7.100 +#---------------------------------------------------------------------------------
   7.101 +$(BUILD):
   7.102 +	@[ -d $@ ] || mkdir -p $@
   7.103 +	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
   7.104 + 
   7.105 +#---------------------------------------------------------------------------------
   7.106 +clean:
   7.107 +	@echo clean ...
   7.108 +	@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba 
   7.109 + 
   7.110 + 
   7.111 +#---------------------------------------------------------------------------------
   7.112 +else
   7.113 + 
   7.114 +DEPENDS	:=	$(OFILES:.o=.d)
   7.115 + 
   7.116 +#---------------------------------------------------------------------------------
   7.117 +# main targets
   7.118 +#---------------------------------------------------------------------------------
   7.119 +$(OUTPUT).ds.gba	: 	$(OUTPUT).nds
   7.120 +$(OUTPUT).nds	: 	$(OUTPUT).arm9
   7.121 +$(OUTPUT).arm9	:	$(OUTPUT).elf
   7.122 +$(OUTPUT).elf	:	$(OFILES)
   7.123 + 
   7.124 +#---------------------------------------------------------------------------------
   7.125 +%.pcx.o	:	%.pcx
   7.126 +#---------------------------------------------------------------------------------
   7.127 +	@echo $(notdir $<)
   7.128 +	@$(bin2o)
   7.129 + 
   7.130 + 
   7.131 +-include $(DEPENDS)
   7.132 + 
   7.133 +#---------------------------------------------------------------------------------------
   7.134 +endif
   7.135 +#---------------------------------------------------------------------------------------
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/nds-test-progs/sprite2/source/common.c	Wed Aug 13 00:49:03 2008 +0000
     8.3 @@ -0,0 +1,965 @@
     8.4 +
     8.5 +/* A simple test program framework */
     8.6 +
     8.7 +#include <stdio.h>
     8.8 +
     8.9 +#include "common.h"
    8.10 +
    8.11 +#define VIDEO_USAGE \
    8.12 +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
    8.13 +
    8.14 +#define AUDIO_USAGE \
    8.15 +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    8.16 +
    8.17 +CommonState *
    8.18 +CommonCreateState(char **argv, Uint32 flags)
    8.19 +{
    8.20 +    CommonState *state = SDL_calloc(1, sizeof(*state));
    8.21 +    if (!state) {
    8.22 +        SDL_OutOfMemory();
    8.23 +        return NULL;
    8.24 +    }
    8.25 +
    8.26 +    /* Initialize some defaults */
    8.27 +    state->argv = argv;
    8.28 +    state->flags = flags;
    8.29 +    state->window_title = argv[0];
    8.30 +    state->window_flags = SDL_WINDOW_SHOWN;
    8.31 +    state->window_x = SDL_WINDOWPOS_UNDEFINED;
    8.32 +    state->window_y = SDL_WINDOWPOS_UNDEFINED;
    8.33 +    state->window_w = 256;
    8.34 +    state->window_h = 192;
    8.35 +    state->num_windows = 1;
    8.36 +    state->audiospec.freq = 22050;
    8.37 +    state->audiospec.format = AUDIO_S16;
    8.38 +    state->audiospec.channels = 2;
    8.39 +    state->audiospec.samples = 2048;
    8.40 +    return state;
    8.41 +}
    8.42 +
    8.43 +int
    8.44 +CommonArg(CommonState * state, int index)
    8.45 +{
    8.46 +    char **argv = state->argv;
    8.47 +
    8.48 +    if (SDL_strcasecmp(argv[index], "--video") == 0) {
    8.49 +        ++index;
    8.50 +        if (!argv[index]) {
    8.51 +            return -1;
    8.52 +        }
    8.53 +        state->videodriver = argv[index];
    8.54 +        return 2;
    8.55 +    }
    8.56 +    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
    8.57 +        ++index;
    8.58 +        if (!argv[index]) {
    8.59 +            return -1;
    8.60 +        }
    8.61 +        state->renderdriver = argv[index];
    8.62 +        return 2;
    8.63 +    }
    8.64 +    if (SDL_strcasecmp(argv[index], "--info") == 0) {
    8.65 +        ++index;
    8.66 +        if (!argv[index]) {
    8.67 +            return -1;
    8.68 +        }
    8.69 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
    8.70 +            state->verbose |=
    8.71 +                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
    8.72 +                 VERBOSE_EVENT);
    8.73 +            return 2;
    8.74 +        }
    8.75 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
    8.76 +            state->verbose |= VERBOSE_VIDEO;
    8.77 +            return 2;
    8.78 +        }
    8.79 +        if (SDL_strcasecmp(argv[index], "modes") == 0) {
    8.80 +            state->verbose |= VERBOSE_MODES;
    8.81 +            return 2;
    8.82 +        }
    8.83 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
    8.84 +            state->verbose |= VERBOSE_RENDER;
    8.85 +            return 2;
    8.86 +        }
    8.87 +        if (SDL_strcasecmp(argv[index], "event") == 0) {
    8.88 +            state->verbose |= VERBOSE_EVENT;
    8.89 +            return 2;
    8.90 +        }
    8.91 +        return -1;
    8.92 +    }
    8.93 +    if (SDL_strcasecmp(argv[index], "--display") == 0) {
    8.94 +        ++index;
    8.95 +        if (!argv[index]) {
    8.96 +            return -1;
    8.97 +        }
    8.98 +        state->display = SDL_atoi(argv[index]);
    8.99 +        return 2;
   8.100 +    }
   8.101 +    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
   8.102 +        state->window_flags |= SDL_WINDOW_FULLSCREEN;
   8.103 +        state->num_windows = 1;
   8.104 +        return 1;
   8.105 +    }
   8.106 +    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
   8.107 +        ++index;
   8.108 +        if (!argv[index] || !SDL_isdigit(*argv[index])) {
   8.109 +            return -1;
   8.110 +        }
   8.111 +        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
   8.112 +            state->num_windows = SDL_atoi(argv[index]);
   8.113 +        }
   8.114 +        return 2;
   8.115 +    }
   8.116 +    if (SDL_strcasecmp(argv[index], "--title") == 0) {
   8.117 +        ++index;
   8.118 +        if (!argv[index]) {
   8.119 +            return -1;
   8.120 +        }
   8.121 +        state->window_title = argv[index];
   8.122 +        return 2;
   8.123 +    }
   8.124 +    if (SDL_strcasecmp(argv[index], "--center") == 0) {
   8.125 +        state->window_x = SDL_WINDOWPOS_CENTERED;
   8.126 +        state->window_y = SDL_WINDOWPOS_CENTERED;
   8.127 +        return 1;
   8.128 +    }
   8.129 +    if (SDL_strcasecmp(argv[index], "--position") == 0) {
   8.130 +        char *x, *y;
   8.131 +        ++index;
   8.132 +        if (!argv[index]) {
   8.133 +            return -1;
   8.134 +        }
   8.135 +        x = argv[index];
   8.136 +        y = argv[index];
   8.137 +        while (*y && *y != ',') {
   8.138 +            ++y;
   8.139 +        }
   8.140 +        if (!*y) {
   8.141 +            return -1;
   8.142 +        }
   8.143 +        *y++ = '\0';
   8.144 +        state->window_x = SDL_atoi(x);
   8.145 +        state->window_y = SDL_atoi(y);
   8.146 +        return 2;
   8.147 +    }
   8.148 +    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
   8.149 +        char *w, *h;
   8.150 +        ++index;
   8.151 +        if (!argv[index]) {
   8.152 +            return -1;
   8.153 +        }
   8.154 +        w = argv[index];
   8.155 +        h = argv[index];
   8.156 +        while (*h && *h != 'x') {
   8.157 +            ++h;
   8.158 +        }
   8.159 +        if (!*h) {
   8.160 +            return -1;
   8.161 +        }
   8.162 +        *h++ = '\0';
   8.163 +        state->window_w = SDL_atoi(w);
   8.164 +        state->window_h = SDL_atoi(h);
   8.165 +        return 2;
   8.166 +    }
   8.167 +    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
   8.168 +        ++index;
   8.169 +        if (!argv[index]) {
   8.170 +            return -1;
   8.171 +        }
   8.172 +        state->depth = SDL_atoi(argv[index]);
   8.173 +        return 2;
   8.174 +    }
   8.175 +    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
   8.176 +        ++index;
   8.177 +        if (!argv[index]) {
   8.178 +            return -1;
   8.179 +        }
   8.180 +        state->refresh_rate = SDL_atoi(argv[index]);
   8.181 +        return 2;
   8.182 +    }
   8.183 +    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
   8.184 +        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
   8.185 +        return 1;
   8.186 +    }
   8.187 +    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
   8.188 +        state->window_flags |= SDL_WINDOW_BORDERLESS;
   8.189 +        return 1;
   8.190 +    }
   8.191 +    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
   8.192 +        state->window_flags |= SDL_WINDOW_RESIZABLE;
   8.193 +        return 1;
   8.194 +    }
   8.195 +    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
   8.196 +        state->window_flags |= SDL_WINDOW_MINIMIZED;
   8.197 +        return 1;
   8.198 +    }
   8.199 +    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
   8.200 +        state->window_flags |= SDL_WINDOW_MAXIMIZED;
   8.201 +        return 1;
   8.202 +    }
   8.203 +    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
   8.204 +        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
   8.205 +        return 1;
   8.206 +    }
   8.207 +    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
   8.208 +        ++index;
   8.209 +        if (!argv[index]) {
   8.210 +            return -1;
   8.211 +        }
   8.212 +        state->audiospec.freq = SDL_atoi(argv[index]);
   8.213 +        return 2;
   8.214 +    }
   8.215 +    if (SDL_strcasecmp(argv[index], "--format") == 0) {
   8.216 +        ++index;
   8.217 +        if (!argv[index]) {
   8.218 +            return -1;
   8.219 +        }
   8.220 +        if (SDL_strcasecmp(argv[index], "U8") == 0) {
   8.221 +            state->audiospec.format = AUDIO_U8;
   8.222 +            return 2;
   8.223 +        }
   8.224 +        if (SDL_strcasecmp(argv[index], "S8") == 0) {
   8.225 +            state->audiospec.format = AUDIO_S8;
   8.226 +            return 2;
   8.227 +        }
   8.228 +        if (SDL_strcasecmp(argv[index], "U16") == 0) {
   8.229 +            state->audiospec.format = AUDIO_U16;
   8.230 +            return 2;
   8.231 +        }
   8.232 +        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
   8.233 +            state->audiospec.format = AUDIO_U16LSB;
   8.234 +            return 2;
   8.235 +        }
   8.236 +        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
   8.237 +            state->audiospec.format = AUDIO_U16MSB;
   8.238 +            return 2;
   8.239 +        }
   8.240 +        if (SDL_strcasecmp(argv[index], "S16") == 0) {
   8.241 +            state->audiospec.format = AUDIO_S16;
   8.242 +            return 2;
   8.243 +        }
   8.244 +        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
   8.245 +            state->audiospec.format = AUDIO_S16LSB;
   8.246 +            return 2;
   8.247 +        }
   8.248 +        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
   8.249 +            state->audiospec.format = AUDIO_S16MSB;
   8.250 +            return 2;
   8.251 +        }
   8.252 +        return -1;
   8.253 +    }
   8.254 +    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
   8.255 +        ++index;
   8.256 +        if (!argv[index]) {
   8.257 +            return -1;
   8.258 +        }
   8.259 +        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
   8.260 +        return 2;
   8.261 +    }
   8.262 +    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
   8.263 +        ++index;
   8.264 +        if (!argv[index]) {
   8.265 +            return -1;
   8.266 +        }
   8.267 +        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
   8.268 +        return 2;
   8.269 +    }
   8.270 +    if ((SDL_strcasecmp(argv[index], "-h") == 0)
   8.271 +        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
   8.272 +        /* Print the usage message */
   8.273 +        return -1;
   8.274 +    }
   8.275 +    return 0;
   8.276 +}
   8.277 +
   8.278 +const char *
   8.279 +CommonUsage(CommonState * state)
   8.280 +{
   8.281 +    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
   8.282 +    case SDL_INIT_VIDEO:
   8.283 +        return VIDEO_USAGE;
   8.284 +    case SDL_INIT_AUDIO:
   8.285 +        return AUDIO_USAGE;
   8.286 +    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
   8.287 +        return VIDEO_USAGE " " AUDIO_USAGE;
   8.288 +    default:
   8.289 +        return "";
   8.290 +    }
   8.291 +}
   8.292 +
   8.293 +static void
   8.294 +PrintRendererFlag(Uint32 flag)
   8.295 +{
   8.296 +    switch (flag) {
   8.297 +    case SDL_RENDERER_SINGLEBUFFER:
   8.298 +        fprintf(stderr, "SingleBuffer");
   8.299 +        break;
   8.300 +    case SDL_RENDERER_PRESENTCOPY:
   8.301 +        fprintf(stderr, "PresentCopy");
   8.302 +        break;
   8.303 +    case SDL_RENDERER_PRESENTFLIP2:
   8.304 +        fprintf(stderr, "PresentFlip2");
   8.305 +        break;
   8.306 +    case SDL_RENDERER_PRESENTFLIP3:
   8.307 +        fprintf(stderr, "PresentFlip3");
   8.308 +        break;
   8.309 +    case SDL_RENDERER_PRESENTDISCARD:
   8.310 +        fprintf(stderr, "PresentDiscard");
   8.311 +        break;
   8.312 +    case SDL_RENDERER_PRESENTVSYNC:
   8.313 +        fprintf(stderr, "PresentVSync");
   8.314 +        break;
   8.315 +    case SDL_RENDERER_ACCELERATED:
   8.316 +        fprintf(stderr, "Accelerated");
   8.317 +        break;
   8.318 +    default:
   8.319 +        fprintf(stderr, "0x%8.8x", flag);
   8.320 +        break;
   8.321 +    }
   8.322 +}
   8.323 +
   8.324 +static void
   8.325 +PrintBlendMode(Uint32 flag)
   8.326 +{
   8.327 +    switch (flag) {
   8.328 +    case SDL_TEXTUREBLENDMODE_NONE:
   8.329 +        fprintf(stderr, "None");
   8.330 +        break;
   8.331 +    case SDL_TEXTUREBLENDMODE_MASK:
   8.332 +        fprintf(stderr, "Mask");
   8.333 +        break;
   8.334 +    case SDL_TEXTUREBLENDMODE_BLEND:
   8.335 +        fprintf(stderr, "Blend");
   8.336 +        break;
   8.337 +    case SDL_TEXTUREBLENDMODE_ADD:
   8.338 +        fprintf(stderr, "Add");
   8.339 +        break;
   8.340 +    case SDL_TEXTUREBLENDMODE_MOD:
   8.341 +        fprintf(stderr, "Mod");
   8.342 +        break;
   8.343 +    default:
   8.344 +        fprintf(stderr, "0x%8.8x", flag);
   8.345 +        break;
   8.346 +    }
   8.347 +}
   8.348 +
   8.349 +static void
   8.350 +PrintScaleMode(Uint32 flag)
   8.351 +{
   8.352 +    switch (flag) {
   8.353 +    case SDL_TEXTURESCALEMODE_NONE:
   8.354 +        fprintf(stderr, "None");
   8.355 +        break;
   8.356 +    case SDL_TEXTURESCALEMODE_FAST:
   8.357 +        fprintf(stderr, "Fast");
   8.358 +        break;
   8.359 +    case SDL_TEXTURESCALEMODE_SLOW:
   8.360 +        fprintf(stderr, "Slow");
   8.361 +        break;
   8.362 +    case SDL_TEXTURESCALEMODE_BEST:
   8.363 +        fprintf(stderr, "Best");
   8.364 +        break;
   8.365 +    default:
   8.366 +        fprintf(stderr, "0x%8.8x", flag);
   8.367 +        break;
   8.368 +    }
   8.369 +}
   8.370 +
   8.371 +static void
   8.372 +PrintPixelFormat(Uint32 format)
   8.373 +{
   8.374 +    switch (format) {
   8.375 +    case SDL_PIXELFORMAT_UNKNOWN:
   8.376 +        fprintf(stderr, "Unknwon");
   8.377 +        break;
   8.378 +    case SDL_PIXELFORMAT_INDEX1LSB:
   8.379 +        fprintf(stderr, "Index1LSB");
   8.380 +        break;
   8.381 +    case SDL_PIXELFORMAT_INDEX1MSB:
   8.382 +        fprintf(stderr, "Index1MSB");
   8.383 +        break;
   8.384 +    case SDL_PIXELFORMAT_INDEX4LSB:
   8.385 +        fprintf(stderr, "Index4LSB");
   8.386 +        break;
   8.387 +    case SDL_PIXELFORMAT_INDEX4MSB:
   8.388 +        fprintf(stderr, "Index4MSB");
   8.389 +        break;
   8.390 +    case SDL_PIXELFORMAT_INDEX8:
   8.391 +        fprintf(stderr, "Index8");
   8.392 +        break;
   8.393 +    case SDL_PIXELFORMAT_RGB332:
   8.394 +        fprintf(stderr, "RGB332");
   8.395 +        break;
   8.396 +    case SDL_PIXELFORMAT_RGB444:
   8.397 +        fprintf(stderr, "RGB444");
   8.398 +        break;
   8.399 +    case SDL_PIXELFORMAT_RGB555:
   8.400 +        fprintf(stderr, "RGB555");
   8.401 +        break;
   8.402 +    case SDL_PIXELFORMAT_ARGB4444:
   8.403 +        fprintf(stderr, "ARGB4444");
   8.404 +        break;
   8.405 +    case SDL_PIXELFORMAT_ARGB1555:
   8.406 +        fprintf(stderr, "ARGB1555");
   8.407 +        break;
   8.408 +    case SDL_PIXELFORMAT_RGB565:
   8.409 +        fprintf(stderr, "RGB565");
   8.410 +        break;
   8.411 +    case SDL_PIXELFORMAT_RGB24:
   8.412 +        fprintf(stderr, "RGB24");
   8.413 +        break;
   8.414 +    case SDL_PIXELFORMAT_BGR24:
   8.415 +        fprintf(stderr, "BGR24");
   8.416 +        break;
   8.417 +    case SDL_PIXELFORMAT_RGB888:
   8.418 +        fprintf(stderr, "RGB888");
   8.419 +        break;
   8.420 +    case SDL_PIXELFORMAT_BGR888:
   8.421 +        fprintf(stderr, "BGR888");
   8.422 +        break;
   8.423 +    case SDL_PIXELFORMAT_ARGB8888:
   8.424 +        fprintf(stderr, "ARGB8888");
   8.425 +        break;
   8.426 +    case SDL_PIXELFORMAT_RGBA8888:
   8.427 +        fprintf(stderr, "RGBA8888");
   8.428 +        break;
   8.429 +    case SDL_PIXELFORMAT_ABGR8888:
   8.430 +        fprintf(stderr, "ABGR8888");
   8.431 +        break;
   8.432 +    case SDL_PIXELFORMAT_BGRA8888:
   8.433 +        fprintf(stderr, "BGRA8888");
   8.434 +        break;
   8.435 +    case SDL_PIXELFORMAT_ARGB2101010:
   8.436 +        fprintf(stderr, "ARGB2101010");
   8.437 +        break;
   8.438 +    case SDL_PIXELFORMAT_YV12:
   8.439 +        fprintf(stderr, "YV12");
   8.440 +        break;
   8.441 +    case SDL_PIXELFORMAT_IYUV:
   8.442 +        fprintf(stderr, "IYUV");
   8.443 +        break;
   8.444 +    case SDL_PIXELFORMAT_YUY2:
   8.445 +        fprintf(stderr, "YUY2");
   8.446 +        break;
   8.447 +    case SDL_PIXELFORMAT_UYVY:
   8.448 +        fprintf(stderr, "UYVY");
   8.449 +        break;
   8.450 +    case SDL_PIXELFORMAT_YVYU:
   8.451 +        fprintf(stderr, "YVYU");
   8.452 +        break;
   8.453 +    case SDL_PIXELFORMAT_ABGR1555:
   8.454 +        fprintf(stderr, "ABGR1555");
   8.455 +        break;
   8.456 +    case SDL_PIXELFORMAT_BGR555:
   8.457 +        fprintf(stderr, "BGR555");
   8.458 +        break;
   8.459 +    default:
   8.460 +        fprintf(stderr, "0x%8.8x", format);
   8.461 +        break;
   8.462 +    }
   8.463 +}
   8.464 +
   8.465 +static void
   8.466 +PrintRenderer(SDL_RendererInfo * info)
   8.467 +{
   8.468 +    int i, count;
   8.469 +
   8.470 +    fprintf(stderr, "  Renderer %s:\n", info->name);
   8.471 +
   8.472 +    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
   8.473 +    fprintf(stderr, " (");
   8.474 +    count = 0;
   8.475 +    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
   8.476 +        Uint32 flag = (1 << i);
   8.477 +        if (info->flags & flag) {
   8.478 +            if (count > 0) {
   8.479 +                fprintf(stderr, " | ");
   8.480 +            }
   8.481 +            PrintRendererFlag(flag);
   8.482 +            ++count;
   8.483 +        }
   8.484 +    }
   8.485 +    fprintf(stderr, ")\n");
   8.486 +
   8.487 +    fprintf(stderr, "    Blend: 0x%8.8X", info->blend_modes);
   8.488 +    fprintf(stderr, " (");
   8.489 +    count = 0;
   8.490 +    for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) {
   8.491 +        Uint32 flag = (1 << i);
   8.492 +        if (info->blend_modes & flag) {
   8.493 +            if (count > 0) {
   8.494 +                fprintf(stderr, " | ");
   8.495 +            }
   8.496 +            PrintBlendMode(flag);
   8.497 +            ++count;
   8.498 +        }
   8.499 +    }
   8.500 +    fprintf(stderr, ")\n");
   8.501 +
   8.502 +    fprintf(stderr, "    Scale: 0x%8.8X", info->scale_modes);
   8.503 +    fprintf(stderr, " (");
   8.504 +    count = 0;
   8.505 +    for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) {
   8.506 +        Uint32 flag = (1 << i);
   8.507 +        if (info->scale_modes & flag) {
   8.508 +            if (count > 0) {
   8.509 +                fprintf(stderr, " | ");
   8.510 +            }
   8.511 +            PrintScaleMode(flag);
   8.512 +            ++count;
   8.513 +        }
   8.514 +    }
   8.515 +    fprintf(stderr, ")\n");
   8.516 +
   8.517 +    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
   8.518 +    for (i = 0; i < (int) info->num_texture_formats; ++i) {
   8.519 +        if (i > 0) {
   8.520 +            fprintf(stderr, ", ");
   8.521 +        }
   8.522 +        PrintPixelFormat(info->texture_formats[i]);
   8.523 +    }
   8.524 +    fprintf(stderr, "\n");
   8.525 +
   8.526 +    if (info->max_texture_width || info->max_texture_height) {
   8.527 +        fprintf(stderr, "    Max Texture Size: %dx%d\n",
   8.528 +                info->max_texture_width, info->max_texture_height);
   8.529 +    }
   8.530 +}
   8.531 +
   8.532 +SDL_bool
   8.533 +CommonInit(CommonState * state)
   8.534 +{
   8.535 +    int i, j, m, n;
   8.536 +    SDL_DisplayMode fullscreen_mode;
   8.537 +
   8.538 +    if (state->flags & SDL_INIT_VIDEO) {
   8.539 +        if (state->verbose & VERBOSE_VIDEO) {
   8.540 +            n = SDL_GetNumVideoDrivers();
   8.541 +            if (n == 0) {
   8.542 +                fprintf(stderr, "No built-in video drivers\n");
   8.543 +            } else {
   8.544 +                fprintf(stderr, "Built-in video drivers:");
   8.545 +                for (i = 0; i < n; ++i) {
   8.546 +                    if (i > 0) {
   8.547 +                        fprintf(stderr, ",");
   8.548 +                    }
   8.549 +                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
   8.550 +                }
   8.551 +                fprintf(stderr, "\n");
   8.552 +            }
   8.553 +        }
   8.554 +        if (SDL_VideoInit(state->videodriver, 0) < 0) {
   8.555 +            fprintf(stderr, "Couldn't initialize video driver: %s\n",
   8.556 +                    SDL_GetError());
   8.557 +            return SDL_FALSE;
   8.558 +        }
   8.559 +        if (state->verbose & VERBOSE_VIDEO) {
   8.560 +            fprintf(stderr, "Video driver: %s\n",
   8.561 +                    SDL_GetCurrentVideoDriver());
   8.562 +        }
   8.563 +
   8.564 +        if (state->verbose & VERBOSE_MODES) {
   8.565 +            SDL_DisplayMode mode;
   8.566 +            int bpp;
   8.567 +            Uint32 Rmask, Gmask, Bmask, Amask;
   8.568 +
   8.569 +            n = SDL_GetNumVideoDisplays();
   8.570 +            fprintf(stderr, "Number of displays: %d\n", n);
   8.571 +            for (i = 0; i < n; ++i) {
   8.572 +                fprintf(stderr, "Display %d:\n", i);
   8.573 +                SDL_SelectVideoDisplay(i);
   8.574 +
   8.575 +                SDL_GetDesktopDisplayMode(&mode);
   8.576 +                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
   8.577 +                                           &Bmask, &Amask);
   8.578 +                fprintf(stderr,
   8.579 +                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
   8.580 +                        mode.w, mode.h, mode.refresh_rate, bpp);
   8.581 +                if (Rmask || Gmask || Bmask) {
   8.582 +                    fprintf(stderr, "      Red Mask = 0x%.8x\n", Rmask);
   8.583 +                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
   8.584 +                    fprintf(stderr, "      Blue Mask = 0x%.8x\n", Bmask);
   8.585 +                    if (Amask)
   8.586 +                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
   8.587 +                }
   8.588 +
   8.589 +                /* Print available fullscreen video modes */
   8.590 +                m = SDL_GetNumDisplayModes();
   8.591 +                if (m == 0) {
   8.592 +                    fprintf(stderr, "No available fullscreen video modes\n");
   8.593 +                } else {
   8.594 +                    fprintf(stderr, "  Fullscreen video modes:\n");
   8.595 +                    for (j = 0; j < m; ++j) {
   8.596 +                        SDL_GetDisplayMode(j, &mode);
   8.597 +                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
   8.598 +                                                   &Gmask, &Bmask, &Amask);
   8.599 +                        fprintf(stderr,
   8.600 +                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
   8.601 +                                j, mode.w, mode.h, mode.refresh_rate, bpp);
   8.602 +                        if (Rmask || Gmask || Bmask) {
   8.603 +                            fprintf(stderr, "        Red Mask = 0x%.8x\n",
   8.604 +                                    Rmask);
   8.605 +                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
   8.606 +                                    Gmask);
   8.607 +                            fprintf(stderr, "        Blue Mask = 0x%.8x\n",
   8.608 +                                    Bmask);
   8.609 +                            if (Amask)
   8.610 +                                fprintf(stderr,
   8.611 +                                        "        Alpha Mask = 0x%.8x\n",
   8.612 +                                        Amask);
   8.613 +                        }
   8.614 +                    }
   8.615 +                }
   8.616 +            }
   8.617 +        }
   8.618 +
   8.619 +        SDL_SelectVideoDisplay(state->display);
   8.620 +        if (state->verbose & VERBOSE_RENDER) {
   8.621 +            SDL_RendererInfo info;
   8.622 +
   8.623 +            n = SDL_GetNumRenderDrivers();
   8.624 +            if (n == 0) {
   8.625 +                fprintf(stderr, "No built-in render drivers\n");
   8.626 +            } else {
   8.627 +                fprintf(stderr, "Built-in render drivers:\n");
   8.628 +                for (i = 0; i < n; ++i) {
   8.629 +                    SDL_GetRenderDriverInfo(i, &info);
   8.630 +                    PrintRenderer(&info);
   8.631 +                }
   8.632 +            }
   8.633 +        }
   8.634 +
   8.635 +        switch (state->depth) {
   8.636 +        case 8:
   8.637 +            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
   8.638 +            break;
   8.639 +        case 15:
   8.640 +            fullscreen_mode.format = SDL_PIXELFORMAT_BGR555;
   8.641 +            break;
   8.642 +        case 16:
   8.643 +        default:
   8.644 +            fullscreen_mode.format = SDL_PIXELFORMAT_ABGR1555;
   8.645 +            break;
   8.646 +/* NDS       default:
   8.647 +            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
   8.648 +            break;*/
   8.649 +        }
   8.650 +        fullscreen_mode.w = state->window_w;
   8.651 +        fullscreen_mode.h = state->window_h;
   8.652 +        fullscreen_mode.refresh_rate = state->refresh_rate;
   8.653 +        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
   8.654 +
   8.655 +        state->windows =
   8.656 +            (SDL_WindowID *) SDL_malloc(state->num_windows *
   8.657 +                                        sizeof(*state->windows));
   8.658 +        if (!state->windows) {
   8.659 +            fprintf(stderr, "Out of memory!\n");
   8.660 +            return SDL_FALSE;
   8.661 +        }
   8.662 +        for (i = 0; i < state->num_windows; ++i) {
   8.663 +            char title[1024];
   8.664 +
   8.665 +            if (state->num_windows > 1) {
   8.666 +                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
   8.667 +                             state->window_title, i + 1);
   8.668 +            } else {
   8.669 +                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
   8.670 +            }
   8.671 +            state->windows[i] =
   8.672 +                SDL_CreateWindow(title, state->window_x, state->window_y,
   8.673 +                                 state->window_w, state->window_h,
   8.674 +                                 state->window_flags);
   8.675 +            if (!state->windows[i]) {
   8.676 +                fprintf(stderr, "Couldn't create window: %s\n",
   8.677 +                        SDL_GetError());
   8.678 +                return SDL_FALSE;
   8.679 +            }
   8.680 +
   8.681 +            if (!state->skip_renderer
   8.682 +                && (state->renderdriver
   8.683 +                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
   8.684 +                m = -1;
   8.685 +                if (state->renderdriver) {
   8.686 +                    SDL_RendererInfo info;
   8.687 +                    n = SDL_GetNumRenderDrivers();
   8.688 +                    for (j = 0; j < n; ++j) {
   8.689 +                        SDL_GetRenderDriverInfo(j, &info);
   8.690 +                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
   8.691 +                            0) {
   8.692 +                            m = j;
   8.693 +                            break;
   8.694 +                        }
   8.695 +                    }
   8.696 +                    if (m == n) {
   8.697 +                        fprintf(stderr,
   8.698 +                                "Couldn't find render driver named %s",
   8.699 +                                state->renderdriver);
   8.700 +                        return SDL_FALSE;
   8.701 +                    }
   8.702 +                }
   8.703 +                if (SDL_CreateRenderer
   8.704 +                    (state->windows[i], m, state->render_flags) < 0) {
   8.705 +                    fprintf(stderr, "Couldn't create renderer: %s\n",
   8.706 +                            SDL_GetError());
   8.707 +                    return SDL_FALSE;
   8.708 +                }
   8.709 +                if (state->verbose & VERBOSE_RENDER) {
   8.710 +                    SDL_RendererInfo info;
   8.711 +
   8.712 +                    fprintf(stderr, "Current renderer:\n");
   8.713 +                    SDL_GetRendererInfo(&info);
   8.714 +                    PrintRenderer(&info);
   8.715 +                }
   8.716 +            }
   8.717 +        }
   8.718 +        SDL_SelectRenderer(state->windows[0]);
   8.719 +    }
   8.720 +
   8.721 +    if (state->flags & SDL_INIT_AUDIO) {
   8.722 +        if (state->verbose & VERBOSE_AUDIO) {
   8.723 +            n = SDL_GetNumAudioDrivers();
   8.724 +            if (n == 0) {
   8.725 +                fprintf(stderr, "No built-in audio drivers\n");
   8.726 +            } else {
   8.727 +                fprintf(stderr, "Built-in audio drivers:");
   8.728 +                for (i = 0; i < n; ++i) {
   8.729 +                    if (i > 0) {
   8.730 +                        fprintf(stderr, ",");
   8.731 +                    }
   8.732 +                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
   8.733 +                }
   8.734 +                fprintf(stderr, "\n");
   8.735 +            }
   8.736 +        }
   8.737 +        if (SDL_AudioInit(state->audiodriver) < 0) {
   8.738 +            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
   8.739 +                    SDL_GetError());
   8.740 +            return SDL_FALSE;
   8.741 +        }
   8.742 +        if (state->verbose & VERBOSE_VIDEO) {
   8.743 +            fprintf(stderr, "Audio driver: %s\n",
   8.744 +                    SDL_GetCurrentAudioDriver());
   8.745 +        }
   8.746 +
   8.747 +        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
   8.748 +            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   8.749 +            return SDL_FALSE;
   8.750 +        }
   8.751 +    }
   8.752 +
   8.753 +    return SDL_TRUE;
   8.754 +}
   8.755 +
   8.756 +static void
   8.757 +PrintEvent(SDL_Event * event)
   8.758 +{
   8.759 +    fprintf(stderr, "SDL EVENT: ");
   8.760 +    switch (event->type) {
   8.761 +    case SDL_WINDOWEVENT:
   8.762 +        switch (event->window.event) {
   8.763 +        case SDL_WINDOWEVENT_SHOWN:
   8.764 +            fprintf(stderr, "Window %d shown", event->window.windowID);
   8.765 +            break;
   8.766 +        case SDL_WINDOWEVENT_HIDDEN:
   8.767 +            fprintf(stderr, "Window %d hidden", event->window.windowID);
   8.768 +            break;
   8.769 +        case SDL_WINDOWEVENT_EXPOSED:
   8.770 +            fprintf(stderr, "Window %d exposed", event->window.windowID);
   8.771 +            break;
   8.772 +        case SDL_WINDOWEVENT_MOVED:
   8.773 +            fprintf(stderr, "Window %d moved to %d,%d",
   8.774 +                    event->window.windowID, event->window.data1,
   8.775 +                    event->window.data2);
   8.776 +            break;
   8.777 +        case SDL_WINDOWEVENT_RESIZED:
   8.778 +            fprintf(stderr, "Window %d resized to %dx%d",
   8.779 +                    event->window.windowID, event->window.data1,
   8.780 +                    event->window.data2);
   8.781 +            break;
   8.782 +        case SDL_WINDOWEVENT_MINIMIZED:
   8.783 +            fprintf(stderr, "Window %d minimized", event->window.windowID);
   8.784 +            break;
   8.785 +        case SDL_WINDOWEVENT_MAXIMIZED:
   8.786 +            fprintf(stderr, "Window %d maximized", event->window.windowID);
   8.787 +            break;
   8.788 +        case SDL_WINDOWEVENT_RESTORED:
   8.789 +            fprintf(stderr, "Window %d restored", event->window.windowID);
   8.790 +            break;
   8.791 +        case SDL_WINDOWEVENT_ENTER:
   8.792 +            fprintf(stderr, "Mouse entered window %d",
   8.793 +                    event->window.windowID);
   8.794 +            break;
   8.795 +        case SDL_WINDOWEVENT_LEAVE:
   8.796 +            fprintf(stderr, "Mouse left window %d", event->window.windowID);
   8.797 +            break;
   8.798 +        case SDL_WINDOWEVENT_FOCUS_GAINED:
   8.799 +            fprintf(stderr, "Window %d gained keyboard focus",
   8.800 +                    event->window.windowID);
   8.801 +            break;
   8.802 +        case SDL_WINDOWEVENT_FOCUS_LOST:
   8.803 +            fprintf(stderr, "Window %d lost keyboard focus",
   8.804 +                    event->window.windowID);
   8.805 +            break;
   8.806 +        case SDL_WINDOWEVENT_CLOSE:
   8.807 +            fprintf(stderr, "Window %d closed", event->window.windowID);
   8.808 +            break;
   8.809 +        default:
   8.810 +            fprintf(stderr, "Window %d got unknown event %d",
   8.811 +                    event->window.windowID, event->window.event);
   8.812 +            break;
   8.813 +        }
   8.814 +        break;
   8.815 +    case SDL_KEYDOWN:
   8.816 +        fprintf(stderr,
   8.817 +                "Keyboard %d: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   8.818 +                event->key.which, event->key.windowID,
   8.819 +                event->key.keysym.scancode,
   8.820 +                SDL_GetScancodeName(event->key.keysym.scancode),
   8.821 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   8.822 +        break;
   8.823 +    case SDL_KEYUP:
   8.824 +        fprintf(stderr,
   8.825 +                "Keyboard %d: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   8.826 +                event->key.which, event->key.windowID,
   8.827 +                event->key.keysym.scancode,
   8.828 +                SDL_GetScancodeName(event->key.keysym.scancode),
   8.829 +                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   8.830 +        break;
   8.831 +    case SDL_TEXTINPUT:
   8.832 +        fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d",
   8.833 +                event->text.which, event->text.text, event->text.windowID);
   8.834 +        break;
   8.835 +    case SDL_MOUSEMOTION:
   8.836 +        fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d",
   8.837 +                event->motion.which, event->motion.x, event->motion.y,
   8.838 +                event->motion.xrel, event->motion.yrel,
   8.839 +                event->motion.windowID);
   8.840 +        break;
   8.841 +    case SDL_MOUSEBUTTONDOWN:
   8.842 +        fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d",
   8.843 +                event->button.which, event->button.button, event->button.x,
   8.844 +                event->button.y, event->button.windowID);
   8.845 +        break;
   8.846 +    case SDL_MOUSEBUTTONUP:
   8.847 +        fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d",
   8.848 +                event->button.which, event->button.button, event->button.x,
   8.849 +                event->button.y, event->button.windowID);
   8.850 +        break;
   8.851 +    case SDL_MOUSEWHEEL:
   8.852 +        fprintf(stderr,
   8.853 +                "Mouse %d: wheel scrolled %d in x and %d in y in window %d",
   8.854 +                event->wheel.which, event->wheel.x, event->wheel.y,
   8.855 +                event->wheel.windowID);
   8.856 +        break;
   8.857 +    case SDL_JOYBALLMOTION:
   8.858 +        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
   8.859 +                event->jball.which, event->jball.ball, event->jball.xrel,
   8.860 +                event->jball.yrel);
   8.861 +        break;
   8.862 +    case SDL_JOYHATMOTION:
   8.863 +        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
   8.864 +                event->jhat.hat);
   8.865 +        switch (event->jhat.value) {
   8.866 +        case SDL_HAT_CENTERED:
   8.867 +            fprintf(stderr, "CENTER");
   8.868 +            break;
   8.869 +        case SDL_HAT_UP:
   8.870 +            fprintf(stderr, "UP");
   8.871 +            break;
   8.872 +        case SDL_HAT_RIGHTUP:
   8.873 +            fprintf(stderr, "RIGHTUP");
   8.874 +            break;
   8.875 +        case SDL_HAT_RIGHT:
   8.876 +            fprintf(stderr, "RIGHT");
   8.877 +            break;
   8.878 +        case SDL_HAT_RIGHTDOWN:
   8.879 +            fprintf(stderr, "RIGHTDOWN");
   8.880 +            break;
   8.881 +        case SDL_HAT_DOWN:
   8.882 +            fprintf(stderr, "DOWN");
   8.883 +            break;
   8.884 +        case SDL_HAT_LEFTDOWN:
   8.885 +            fprintf(stderr, "LEFTDOWN");
   8.886 +            break;
   8.887 +        case SDL_HAT_LEFT:
   8.888 +            fprintf(stderr, "LEFT");
   8.889 +            break;
   8.890 +        case SDL_HAT_LEFTUP:
   8.891 +            fprintf(stderr, "LEFTUP");
   8.892 +            break;
   8.893 +        default:
   8.894 +            fprintf(stderr, "UNKNOWN");
   8.895 +            break;
   8.896 +        }
   8.897 +        break;
   8.898 +    case SDL_JOYBUTTONDOWN:
   8.899 +        fprintf(stderr, "Joystick %d: button %d pressed",
   8.900 +                event->jbutton.which, event->jbutton.button);
   8.901 +        break;
   8.902 +    case SDL_JOYBUTTONUP:
   8.903 +        fprintf(stderr, "Joystick %d: button %d released",
   8.904 +                event->jbutton.which, event->jbutton.button);
   8.905 +        break;
   8.906 +    case SDL_QUIT:
   8.907 +        fprintf(stderr, "Quit requested");
   8.908 +        break;
   8.909 +    case SDL_USEREVENT:
   8.910 +        fprintf(stderr, "User event %d", event->user.code);
   8.911 +        break;
   8.912 +    default:
   8.913 +        fprintf(stderr, "Unknown event %d", event->type);
   8.914 +        break;
   8.915 +    }
   8.916 +    fprintf(stderr, "\n");
   8.917 +}
   8.918 +
   8.919 +void
   8.920 +CommonEvent(CommonState * state, SDL_Event * event, int *done)
   8.921 +{
   8.922 +    if (state->verbose & VERBOSE_EVENT) {
   8.923 +        PrintEvent(event);
   8.924 +    }
   8.925 +
   8.926 +    switch (event->type) {
   8.927 +    case SDL_WINDOWEVENT:
   8.928 +        switch (event->window.event) {
   8.929 +        case SDL_WINDOWEVENT_CLOSE:
   8.930 +            *done = 1;
   8.931 +            break;
   8.932 +        }
   8.933 +        break;
   8.934 +    case SDL_KEYDOWN:
   8.935 +        switch (event->key.keysym.sym) {
   8.936 +            /* Add hotkeys here */
   8.937 +        case SDLK_g:
   8.938 +            if (event->key.keysym.mod & KMOD_CTRL) {
   8.939 +                /* Ctrl-G toggle grab */
   8.940 +            }
   8.941 +            break;
   8.942 +        case SDLK_ESCAPE:
   8.943 +            *done = 1;
   8.944 +            break;
   8.945 +        default:
   8.946 +            break;
   8.947 +        }
   8.948 +        break;
   8.949 +    case SDL_QUIT:
   8.950 +        *done = 1;
   8.951 +        break;
   8.952 +    }
   8.953 +}
   8.954 +
   8.955 +void
   8.956 +CommonQuit(CommonState * state)
   8.957 +{
   8.958 +    if (state->flags & SDL_INIT_VIDEO) {
   8.959 +        SDL_VideoQuit();
   8.960 +    }
   8.961 +    if (state->flags & SDL_INIT_AUDIO) {
   8.962 +        SDL_AudioQuit();
   8.963 +    }
   8.964 +    if (state->windows) {
   8.965 +        SDL_free(state->windows);
   8.966 +    }
   8.967 +    SDL_free(state);
   8.968 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/nds-test-progs/sprite2/source/common.h	Wed Aug 13 00:49:03 2008 +0000
     9.3 @@ -0,0 +1,48 @@
     9.4 +
     9.5 +/* A simple test program framework */
     9.6 +
     9.7 +#include <SDL/SDL.h>
     9.8 +
     9.9 +#define VERBOSE_VIDEO   0x00000001
    9.10 +#define VERBOSE_MODES   0x00000002
    9.11 +#define VERBOSE_RENDER  0x00000004
    9.12 +#define VERBOSE_EVENT   0x00000008
    9.13 +#define VERBOSE_AUDIO   0x00000010
    9.14 +
    9.15 +typedef struct
    9.16 +{
    9.17 +    /* SDL init flags */
    9.18 +    char **argv;
    9.19 +    Uint32 flags;
    9.20 +    Uint32 verbose;
    9.21 +
    9.22 +    /* Video info */
    9.23 +    const char *videodriver;
    9.24 +    int display;
    9.25 +    const char *window_title;
    9.26 +    Uint32 window_flags;
    9.27 +    int window_x;
    9.28 +    int window_y;
    9.29 +    int window_w;
    9.30 +    int window_h;
    9.31 +    int depth;
    9.32 +    int refresh_rate;
    9.33 +    int num_windows;
    9.34 +    SDL_WindowID *windows;
    9.35 +
    9.36 +    /* Renderer info */
    9.37 +    const char *renderdriver;
    9.38 +    Uint32 render_flags;
    9.39 +    SDL_bool skip_renderer;
    9.40 +
    9.41 +    /* Audio info */
    9.42 +    const char *audiodriver;
    9.43 +    SDL_AudioSpec audiospec;
    9.44 +} CommonState;
    9.45 +
    9.46 +extern CommonState *CommonCreateState(char **argv, Uint32 flags);
    9.47 +extern int CommonArg(CommonState * state, int index);
    9.48 +extern const char *CommonUsage(CommonState * state);
    9.49 +extern SDL_bool CommonInit(CommonState * state);
    9.50 +extern void CommonEvent(CommonState * state, SDL_Event * event, int *done);
    9.51 +extern void CommonQuit(CommonState * state);
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/nds-test-progs/sprite2/source/testsprite2.c	Wed Aug 13 00:49:03 2008 +0000
    10.3 @@ -0,0 +1,302 @@
    10.4 +/* Simple program:  Move N sprites around on the screen as fast as possible */
    10.5 +
    10.6 +#include <stdlib.h>
    10.7 +#include <stdio.h>
    10.8 +#include <time.h>
    10.9 +#include <nds.h>
   10.10 +#include "common.h"
   10.11 +
   10.12 +#define NUM_SPRITES	100
   10.13 +#define MAX_SPEED 	1
   10.14 +
   10.15 +static CommonState *state;
   10.16 +static int num_sprites;
   10.17 +static SDL_TextureID *sprites;
   10.18 +static SDL_bool cycle_color;
   10.19 +static SDL_bool cycle_alpha;
   10.20 +static int cycle_direction = 1;
   10.21 +static int current_alpha = 0;
   10.22 +static int current_color = 0;
   10.23 +static SDL_Rect *positions;
   10.24 +static SDL_Rect *velocities;
   10.25 +static int sprite_w, sprite_h;
   10.26 +static SDL_TextureBlendMode blendMode = SDL_TEXTUREBLENDMODE_MASK;
   10.27 +static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE;
   10.28 +
   10.29 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
   10.30 +static void
   10.31 +quit(int rc)
   10.32 +{
   10.33 +    if (sprites) {
   10.34 +        SDL_free(sprites);
   10.35 +    }
   10.36 +    if (positions) {
   10.37 +        SDL_free(positions);
   10.38 +    }
   10.39 +    if (velocities) {
   10.40 +        SDL_free(velocities);
   10.41 +    }
   10.42 +    CommonQuit(state);
   10.43 +    exit(rc);
   10.44 +}
   10.45 +
   10.46 +int
   10.47 +LoadSprite(char *file)
   10.48 +{
   10.49 +    int i;
   10.50 +    SDL_Surface *temp;
   10.51 +
   10.52 +    /* Load the sprite image */
   10.53 +    temp = SDL_LoadBMP(file);
   10.54 +    if (temp == NULL) {
   10.55 +        fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
   10.56 +        return (-1);
   10.57 +    }
   10.58 +    sprite_w = temp->w;
   10.59 +    sprite_h = temp->h;
   10.60 +
   10.61 +    /* Set transparent pixel as the pixel at (0,0) */
   10.62 +    if (temp->format->palette) {
   10.63 +        SDL_SetColorKey(temp, SDL_SRCCOLORKEY, *(Uint8 *) temp->pixels);
   10.64 +    }
   10.65 +
   10.66 +    /* Create textures from the image */
   10.67 +    for (i = 0; i < state->num_windows; ++i) {
   10.68 +        SDL_SelectRenderer(state->windows[i]);
   10.69 +        sprites[i] = SDL_CreateTextureFromSurface(0, temp);
   10.70 +        if (!sprites[i]) {
   10.71 +            fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
   10.72 +            SDL_FreeSurface(temp);
   10.73 +            return (-1);
   10.74 +        }
   10.75 +        SDL_SetTextureBlendMode(sprites[i], blendMode);
   10.76 +        SDL_SetTextureScaleMode(sprites[i], scaleMode);
   10.77 +    }
   10.78 +    SDL_FreeSurface(temp);
   10.79 +
   10.80 +    /* We're ready to roll. :) */
   10.81 +    return (0);
   10.82 +}
   10.83 +
   10.84 +void
   10.85 +MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
   10.86 +{
   10.87 +    int i, n;
   10.88 +    int window_w, window_h;
   10.89 +    SDL_Rect area, *position, *velocity;
   10.90 +
   10.91 +    SDL_SelectRenderer(window);
   10.92 +
   10.93 +    /* Query the sizes */
   10.94 +    SDL_GetWindowSize(window, &window_w, &window_h);
   10.95 +
   10.96 +    /* Cycle the color and alpha, if desired */
   10.97 +    if (cycle_color) {
   10.98 +        current_color += cycle_direction;
   10.99 +        if (current_color < 0) {
  10.100 +            current_color = 0;
  10.101 +            cycle_direction = -cycle_direction;
  10.102 +        }
  10.103 +        if (current_color > 255) {
  10.104 +            current_color = 255;
  10.105 +            cycle_direction = -cycle_direction;
  10.106 +        }
  10.107 +        SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
  10.108 +                               (Uint8) current_color);
  10.109 +    }
  10.110 +    if (cycle_alpha) {
  10.111 +        current_alpha += cycle_direction;
  10.112 +        if (current_alpha < 0) {
  10.113 +            current_alpha = 0;
  10.114 +            cycle_direction = -cycle_direction;
  10.115 +        }
  10.116 +        if (current_alpha > 255) {
  10.117 +            current_alpha = 255;
  10.118 +            cycle_direction = -cycle_direction;
  10.119 +        }
  10.120 +        SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
  10.121 +    }
  10.122 +
  10.123 +    /* Move the sprite, bounce at the wall, and draw */
  10.124 +    n = 0;
  10.125 +    SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
  10.126 +    for (i = 0; i < num_sprites; ++i) {
  10.127 +        position = &positions[i];
  10.128 +        velocity = &velocities[i];
  10.129 +        position->x += velocity->x;
  10.130 +        if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
  10.131 +            velocity->x = -velocity->x;
  10.132 +            position->x += velocity->x;
  10.133 +        }
  10.134 +        position->y += velocity->y;
  10.135 +        if ((position->y < 0) || (position->y >= (window_h - sprite_w))) {
  10.136 +            velocity->y = -velocity->y;
  10.137 +            position->y += velocity->y;
  10.138 +        }
  10.139 +
  10.140 +        /* Blit the sprite onto the screen */
  10.141 +        SDL_RenderCopy(sprite, NULL, position);
  10.142 +    }
  10.143 +
  10.144 +    /* Update the screen! */
  10.145 +    SDL_RenderPresent();
  10.146 +}
  10.147 +
  10.148 +int
  10.149 +main(int argc, char *argv[])
  10.150 +{
  10.151 +    int i, done;
  10.152 +    SDL_Event event;
  10.153 +    Uint32 then, now, frames;
  10.154 +
  10.155 +    /* Initialize parameters */
  10.156 +    num_sprites = NUM_SPRITES;
  10.157 +
  10.158 +    /* Initialize test framework */
  10.159 +    state = CommonCreateState(argv, SDL_INIT_VIDEO);
  10.160 +    if (!state) {
  10.161 +        return 1;
  10.162 +    }
  10.163 +    for (i = 1; i < argc;) {
  10.164 +        int consumed;
  10.165 +
  10.166 +        consumed = CommonArg(state, i);
  10.167 +        if (consumed == 0) {
  10.168 +            consumed = -1;
  10.169 +            if (SDL_strcasecmp(argv[i], "--blend") == 0) {
  10.170 +                if (argv[i + 1]) {
  10.171 +                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
  10.172 +                        blendMode = SDL_TEXTUREBLENDMODE_NONE;
  10.173 +                        consumed = 2;
  10.174 +                    } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
  10.175 +                        blendMode = SDL_TEXTUREBLENDMODE_MASK;
  10.176 +                        consumed = 2;
  10.177 +                    } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
  10.178 +                        blendMode = SDL_TEXTUREBLENDMODE_BLEND;
  10.179 +                        consumed = 2;
  10.180 +                    } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
  10.181 +                        blendMode = SDL_TEXTUREBLENDMODE_ADD;
  10.182 +                        consumed = 2;
  10.183 +                    } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
  10.184 +                        blendMode = SDL_TEXTUREBLENDMODE_MOD;
  10.185 +                        consumed = 2;
  10.186 +                    }
  10.187 +                }
  10.188 +            } else if (SDL_strcasecmp(argv[i], "--scale") == 0) {
  10.189 +                if (argv[i + 1]) {
  10.190 +                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
  10.191 +                        scaleMode = SDL_TEXTURESCALEMODE_NONE;
  10.192 +                        consumed = 2;
  10.193 +                    } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) {
  10.194 +                        scaleMode = SDL_TEXTURESCALEMODE_FAST;
  10.195 +                        consumed = 2;
  10.196 +                    } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) {
  10.197 +                        scaleMode = SDL_TEXTURESCALEMODE_SLOW;
  10.198 +                        consumed = 2;
  10.199 +                    } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) {
  10.200 +                        scaleMode = SDL_TEXTURESCALEMODE_BEST;
  10.201 +                        consumed = 2;
  10.202 +                    }
  10.203 +                }
  10.204 +            } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
  10.205 +                cycle_color = SDL_TRUE;
  10.206 +                consumed = 1;
  10.207 +            } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
  10.208 +                cycle_alpha = SDL_TRUE;
  10.209 +                consumed = 1;
  10.210 +            } else if (SDL_isdigit(*argv[i])) {
  10.211 +                num_sprites = SDL_atoi(argv[i]);
  10.212 +                consumed = 1;
  10.213 +            }
  10.214 +        }
  10.215 +        if (consumed < 0) {
  10.216 +            fprintf(stderr,
  10.217 +                    "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n",
  10.218 +                    argv[0], CommonUsage(state));
  10.219 +            quit(1);
  10.220 +        }
  10.221 +        i += consumed;
  10.222 +    }
  10.223 +    if (!CommonInit(state)) {
  10.224 +        quit(2);
  10.225 +    }
  10.226 +
  10.227 +    /* Create the windows, initialize the renderers, and load the textures */
  10.228 +    sprites =
  10.229 +        (SDL_TextureID *) SDL_malloc(state->num_windows * sizeof(*sprites));
  10.230 +    if (!sprites) {
  10.231 +        fprintf(stderr, "Out of memory!\n");
  10.232 +        quit(2);
  10.233 +    }
  10.234 +    for (i = 0; i < state->num_windows; ++i) {
  10.235 +        SDL_SelectRenderer(state->windows[i]);
  10.236 +        SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
  10.237 +    }
  10.238 +    if (LoadSprite("icon.bmp") < 0) {
  10.239 +        quit(2);
  10.240 +    }
  10.241 +
  10.242 +    /* Allocate memory for the sprite info */
  10.243 +    positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
  10.244 +    velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
  10.245 +    if (!positions || !velocities) {
  10.246 +        fprintf(stderr, "Out of memory!\n");
  10.247 +        quit(2);
  10.248 +    }
  10.249 +    srand(time(NULL));
  10.250 +    if (scaleMode != SDL_TEXTURESCALEMODE_NONE) {
  10.251 +        sprite_w += sprite_w / 2;
  10.252 +        sprite_h += sprite_h / 2;
  10.253 +    }
  10.254 +    for (i = 0; i < num_sprites; ++i) {
  10.255 +        positions[i].x = rand() % (state->window_w - sprite_w);
  10.256 +        positions[i].y = rand() % (state->window_h - sprite_h);
  10.257 +        positions[i].w = sprite_w;
  10.258 +        positions[i].h = sprite_h;
  10.259 +        velocities[i].x = 0;
  10.260 +        velocities[i].y = 0;
  10.261 +        while (!velocities[i].x && !velocities[i].y) {
  10.262 +            velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
  10.263 +            velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
  10.264 +        }
  10.265 +    }
  10.266 +
  10.267 +    /* Main render loop */
  10.268 +    frames = 0;
  10.269 +    then = SDL_GetTicks();
  10.270 +    done = 0;
  10.271 +    while (!done) {
  10.272 +        /* Check for events */
  10.273 +        ++frames;
  10.274 +        while (SDL_PollEvent(&event)) {
  10.275 +            CommonEvent(state, &event, &done);
  10.276 +            switch (event.type) {
  10.277 +            case SDL_WINDOWEVENT:
  10.278 +                switch (event.window.event) {
  10.279 +                case SDL_WINDOWEVENT_EXPOSED:
  10.280 +                    SDL_SelectRenderer(event.window.windowID);
  10.281 +                    SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
  10.282 +                    break;
  10.283 +                }
  10.284 +                break;
  10.285 +            default:
  10.286 +                break;
  10.287 +            }
  10.288 +        }
  10.289 +        for (i = 0; i < state->num_windows; ++i) {
  10.290 +            MoveSprites(state->windows[i], sprites[i]);
  10.291 +        }
  10.292 +    }
  10.293 +
  10.294 +    /* Print out some timing information */
  10.295 +    now = SDL_GetTicks();
  10.296 +    if (now > then) {
  10.297 +        printf("%2.2f frames per second\n",
  10.298 +               ((double) frames * 1000) / (now - then));
  10.299 +    }
  10.300 +
  10.301 +    quit(0);
  10.302 +    return 0;
  10.303 +}
  10.304 +
  10.305 +/* vi: set ts=4 sw=4 expandtab: */