comparison test/nds-test-progs/general/source/main.c @ 2735:204be4fc2726

Final merge of Google Summer of Code 2008 work... Port SDL 1.3 to the Nintendo DS by Darren Alton, mentored by Sam Lantinga
author Sam Lantinga <slouken@libsdl.org>
date Wed, 27 Aug 2008 15:10:03 +0000
parents
children 7aba0406c273
comparison
equal deleted inserted replaced
2734:dd25eabe441c 2735:204be4fc2726
1
2 #include <SDL/SDL.h>
3 #if defined(NDS) || defined(__NDS__) || defined (__NDS)
4 #include <nds.h>
5 #include <fat.h>
6 #else
7 #define swiWaitForVBlank()
8 #define consoleDemoInit()
9 #define fatInitDefault()
10 #define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
11 #endif
12 void
13 splash(SDL_Surface * screen, int s)
14 {
15 SDL_Surface *logo;
16 SDL_Rect area = { 0, 0, 256, 192 };
17
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 }
31 }
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 };
41 int i;
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");
68
69 /*splash(screen, 3); */
70
71 SDL_FillRect(screen, &rect, RGB15(0, 0, 31) | 0x8000);
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
96 return 0;
97
98 }
99
100