SDL-mirror/test/nds-test-progs/general/source/main.c
Sam Lantinga 982b4b8c20 Updated Nintendo DS support
Frank Zago

This patch updates the DS port:
- do not use the now removed compat layer.
- integrate parts of libgl2D since I got permission from the author, and thus
removed an external dependancy,
- a few bugs fixes.

Now, the textures should be completely supported, except reading from them
which doesn't makes sense to have on the DS. Sound is still not supported.

If someone else wants to work on the missing pieces, feel free.
2012-02-12 21:04:01 -05:00

89 lines
2.3 KiB
C
Executable file

/*
* Really basic sample for the NDS.
*
* Fills a rectangle increasingly smaller of random color every time a
* button (a, b, x, y) is pressed.
*
* The behaviour whether SDL is compiled with HW support or not (see
* USE_HW_RENDERER in Makefile.ds).
*
* In framebuffer mode, the old rectangles stay because the screen has
* not been cleared.
*
* In accelerated mode, old the last rectangle is visible.
*
* No text is displayed.
*/
#include <SDL/SDL.h>
#if defined(NDS) || defined(__NDS__) || defined (__NDS)
#include <nds.h>
#include <fat.h>
#else
#define consoleDemoInit()
#define fatInitDefault()
#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
#endif
int main(void)
{
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Joystick *stick;
SDL_Event event;
SDL_Rect rect = { 0, 0, 256, 192 };
int i;
consoleDemoInit();
puts("Hello world! Initializing FAT...");
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
puts("# error initializing SDL");
puts(SDL_GetError());
return 1;
}
puts("* initialized SDL");
if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 &&
SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) {
exit(1);
}
stick = SDL_JoystickOpen(0);
if (stick == NULL) {
puts("# error opening joystick");
puts(SDL_GetError());
}
puts("* opened joystick");
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
while (1)
while (SDL_PollEvent(&event))
switch (event.type) {
case SDL_JOYBUTTONDOWN:
SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
if (rect.w > 8) {
rect.x += 4;
rect.y += 3;
rect.w -= 8;
rect.h -= 6;
}
/*
printf("button %d pressed at %d ticks\n",
event.jbutton.button, SDL_GetTicks());
*/
break;
case SDL_QUIT:
SDL_Quit();
return 0;
default:
break;
}
return 0;
}