Mercurial > sdl-ios-xcode
annotate test/nds-test-progs/general/source/main.c @ 2699:cf95a2fd3606 gsoc2008_nds
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 27 Aug 2008 13:44:02 +0000 |
parents | e1da92da346c |
children |
rev | line source |
---|---|
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
1 |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
2 #include <SDL/SDL.h> |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
3 #if defined(NDS) || defined(__NDS__) || defined (__NDS) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
4 #include <nds.h> |
2694
c1c7cb1b5a47
More sprite-work in the render driver, and some updates to the nds-test-progs.
Darren Alton <dalton@stevens.edu>
parents:
2692
diff
changeset
|
5 #include <fat.h> |
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
6 #else |
2698 | 7 #define swiWaitForVBlank() |
8 #define consoleDemoInit() | |
9 #define fatInitDefault() | |
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
10 #define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3)) |
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
11 #endif |
2698 | 12 void |
13 splash(SDL_Surface * screen, int s) | |
14 { | |
15 SDL_Surface *logo; | |
16 SDL_Rect area = { 0, 0, 256, 192 }; | |
2694
c1c7cb1b5a47
More sprite-work in the render driver, and some updates to the nds-test-progs.
Darren Alton <dalton@stevens.edu>
parents:
2692
diff
changeset
|
17 |
2698 | 18 logo = SDL_LoadBMP("sdl.bmp"); |
19 if (!logo) { | |
20 printf("Couldn't splash.\n"); | |
21 return; | |
22 } | |
23 /*logo->flags &= ~SDL_PREALLOC; */ | |
24 SDL_BlitSurface(logo, NULL, screen, &area); | |
25 SDL_Flip(screen); | |
26 while (s-- > 0) { | |
27 int i = 60; | |
28 while (--i) | |
29 swiWaitForVBlank(); | |
30 } | |
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
31 } |
2698 | 32 |
33 | |
34 int | |
35 main(void) | |
36 { | |
37 SDL_Surface *screen; | |
38 SDL_Joystick *stick; | |
39 SDL_Event event; | |
40 SDL_Rect rect = { 0, 0, 256, 192 }; | |
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
41 int i; |
2698 | 42 |
43 consoleDemoInit(); | |
44 puts("Hello world! Initializing FAT..."); | |
45 fatInitDefault(); | |
46 | |
47 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { | |
48 puts("# error initializing SDL"); | |
49 puts(SDL_GetError()); | |
50 return 1; | |
51 } | |
52 puts("* initialized SDL"); | |
53 screen = SDL_SetVideoMode(256, 192, 15, SDL_SWSURFACE); | |
54 if (!screen) { | |
55 puts("# error setting video mode"); | |
56 puts(SDL_GetError()); | |
57 return 2; | |
58 } | |
59 screen->flags &= ~SDL_PREALLOC; | |
60 puts("* set video mode"); | |
61 stick = SDL_JoystickOpen(0); | |
62 if (stick == NULL) { | |
63 puts("# error opening joystick"); | |
64 puts(SDL_GetError()); | |
65 // return 3; | |
66 } | |
67 puts("* opened joystick"); | |
2694
c1c7cb1b5a47
More sprite-work in the render driver, and some updates to the nds-test-progs.
Darren Alton <dalton@stevens.edu>
parents:
2692
diff
changeset
|
68 |
2698 | 69 /*splash(screen, 3); */ |
70 | |
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
71 SDL_FillRect(screen, &rect, RGB15(0, 0, 31) | 0x8000); |
2698 | 72 SDL_Flip(screen); |
73 | |
74 while (1) | |
75 while (SDL_PollEvent(&event)) | |
76 switch (event.type) { | |
77 case SDL_JOYBUTTONDOWN: | |
78 SDL_FillRect(screen, &rect, (u16) rand() | 0x8000); | |
79 SDL_Flip(screen); | |
80 if (rect.w > 8) { | |
81 rect.x += 4; | |
82 rect.y += 3; | |
83 rect.w -= 8; | |
84 rect.h -= 6; | |
85 } | |
86 printf("button %d pressed at %d ticks\n", | |
87 event.jbutton.which, SDL_GetTicks()); | |
88 break; | |
89 case SDL_QUIT: | |
90 SDL_Quit(); | |
91 return 0; | |
92 default: | |
93 break; | |
94 } | |
95 | |
2686
e9f27fe4f2a1
Existing testsprite programs made into NDS projects
Darren Alton <dalton@stevens.edu>
parents:
diff
changeset
|
96 return 0; |