author | Sam Lantinga <slouken@libsdl.org> |
Tue, 11 Dec 2012 12:01:30 -0800 | |
changeset 6741 | 9a7a2d663e75 |
parent 6285 | f12649068adb |
permissions | -rw-r--r-- |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
1 |
/* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
2 |
* Really basic sample for the NDS. |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
3 |
* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
4 |
* Fills a rectangle increasingly smaller of random color every time a |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
5 |
* button (a, b, x, y) is pressed. |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
6 |
* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
7 |
* The behaviour whether SDL is compiled with HW support or not (see |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
8 |
* USE_HW_RENDERER in Makefile.ds). |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
9 |
* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
10 |
* In framebuffer mode, the old rectangles stay because the screen has |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
11 |
* not been cleared. |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
12 |
* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
13 |
* In accelerated mode, old the last rectangle is visible. |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
14 |
* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
15 |
* No text is displayed. |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
16 |
*/ |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
17 |
|
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
#include <SDL/SDL.h> |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 |
#if defined(NDS) || defined(__NDS__) || defined (__NDS) |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
#include <nds.h> |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
#include <fat.h> |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
#else |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
#define consoleDemoInit() |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
#define fatInitDefault() |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3)) |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
#endif |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
27 |
|
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
28 |
int main(void) |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
{ |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
30 |
SDL_Window *window; |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
31 |
SDL_Renderer *renderer; |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
SDL_Joystick *stick; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
SDL_Event event; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
SDL_Rect rect = { 0, 0, 256, 192 }; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
int i; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
|
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
consoleDemoInit(); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
puts("Hello world! Initializing FAT..."); |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
39 |
|
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
40 |
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
puts("# error initializing SDL"); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
puts(SDL_GetError()); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
return 1; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
} |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
puts("* initialized SDL"); |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
46 |
|
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
47 |
if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 && |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
48 |
SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) { |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
49 |
exit(1); |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 |
} |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
51 |
|
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 |
stick = SDL_JoystickOpen(0); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 |
if (stick == NULL) { |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
puts("# error opening joystick"); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
puts(SDL_GetError()); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
} |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
puts("* opened joystick"); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
|
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
59 |
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
60 |
SDL_RenderFillRect(renderer, &rect); |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
61 |
SDL_RenderPresent(renderer); |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
|
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 |
while (1) |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
while (SDL_PollEvent(&event)) |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
switch (event.type) { |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
case SDL_JOYBUTTONDOWN: |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
67 |
|
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
68 |
SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE); |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
69 |
SDL_RenderFillRect(renderer, &rect); |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
70 |
SDL_RenderPresent(renderer); |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
if (rect.w > 8) { |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
rect.x += 4; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
rect.y += 3; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 |
rect.w -= 8; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
rect.h -= 6; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
} |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
77 |
/* |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
78 |
printf("button %d pressed at %d ticks\n", |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
79 |
event.jbutton.button, SDL_GetTicks()); |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
80 |
*/ |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
break; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
case SDL_QUIT: |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
SDL_Quit(); |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
return 0; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
default: |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
break; |
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
} |
6285
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
88 |
return 0; |
f12649068adb
Updated Nintendo DS support
Sam Lantinga <slouken@libsdl.org>
parents:
5270
diff
changeset
|
89 |
} |