Mercurial > sdl-ios-xcode
comparison test/nds-test-progs/general/source/main.c @ 2686:e9f27fe4f2a1 gsoc2008_nds
Existing testsprite programs made into NDS projects
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Wed, 13 Aug 2008 00:49:03 +0000 |
parents | |
children | 87cfb5fde5db |
comparison
equal
deleted
inserted
replaced
2685:2190b873ff00 | 2686:e9f27fe4f2a1 |
---|---|
1 | |
2 #include <SDL/SDL.h> | |
3 #if defined(NDS) || defined(__NDS__) || defined (__NDS) | |
4 #include <nds.h> | |
5 #else | |
6 #define swiWaitForVBlank() | |
7 #define consoleDemoInit() | |
8 #define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3)) | |
9 #endif | |
10 | |
11 void delay(int s) { | |
12 while(s-- > 0) { | |
13 int i = 60; | |
14 while(--i) swiWaitForVBlank(); | |
15 } | |
16 } | |
17 | |
18 int main(void) { | |
19 SDL_Surface *screen; | |
20 SDL_Joystick *stick; | |
21 SDL_Event event; | |
22 SDL_Rect rect = {8,8,240,176}; | |
23 | |
24 consoleDemoInit(); | |
25 if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) { | |
26 puts("# error initializing SDL"); | |
27 puts(SDL_GetError()); | |
28 return 1; | |
29 } | |
30 puts("* initialized SDL\n"); delay(1); | |
31 | |
32 screen = SDL_SetVideoMode(256, 192, 16, SDL_SWSURFACE); | |
33 if(!screen) { | |
34 puts("# error setting video mode"); | |
35 puts(SDL_GetError()); | |
36 return 2; | |
37 } | |
38 puts("* set video mode\n"); delay(1); | |
39 | |
40 stick = SDL_JoystickOpen(0); | |
41 if(stick == NULL) { | |
42 puts("# error opening joystick"); | |
43 puts(SDL_GetError()); | |
44 // return 3; | |
45 } | |
46 puts("* opened joystick"); delay(1); | |
47 SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000); | |
48 SDL_Flip(screen); | |
49 | |
50 while(1) | |
51 while(SDL_PollEvent(&event)) | |
52 switch(event.type) { | |
53 case SDL_JOYBUTTONDOWN: | |
54 switch(event.jbutton.which) { | |
55 case 0: | |
56 SDL_FillRect(screen, &rect, RGB15(31,0,0)|0x8000); | |
57 break; | |
58 case 1: | |
59 SDL_FillRect(screen, &rect, RGB15(0,31,0)|0x8000); | |
60 break; | |
61 case 2: | |
62 SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000); | |
63 break; | |
64 case 3: | |
65 SDL_FillRect(screen, &rect, RGB15(0,0,0)|0x8000); | |
66 break; | |
67 default: break; | |
68 } | |
69 printf("joy_%d\n", event.jbutton.which); | |
70 SDL_Flip(screen); | |
71 break; | |
72 case SDL_QUIT: SDL_Quit(); return 0; | |
73 default: break; | |
74 } | |
75 | |
76 return 0; | |
77 } |