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.
This commit is contained in:
parent
9514b6a286
commit
982b4b8c20
11 changed files with 613 additions and 99 deletions
|
@ -1,39 +1,34 @@
|
|||
|
||||
/*
|
||||
* 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 swiWaitForVBlank()
|
||||
#define consoleDemoInit()
|
||||
#define fatInitDefault()
|
||||
#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
|
||||
#endif
|
||||
void
|
||||
splash(SDL_Surface * screen, int s)
|
||||
{
|
||||
SDL_Surface *logo;
|
||||
SDL_Rect area = { 0, 0, 256, 192 };
|
||||
|
||||
logo = SDL_LoadBMP("sdl.bmp");
|
||||
if (!logo) {
|
||||
printf("Couldn't splash.\n");
|
||||
return;
|
||||
}
|
||||
/*logo->flags &= ~SDL_PREALLOC; */
|
||||
SDL_BlitSurface(logo, NULL, screen, &area);
|
||||
SDL_Flip(screen);
|
||||
while (s-- > 0) {
|
||||
int i = 60;
|
||||
while (--i)
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
int main(void)
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Joystick *stick;
|
||||
SDL_Event event;
|
||||
SDL_Rect rect = { 0, 0, 256, 192 };
|
||||
|
@ -41,48 +36,48 @@ main(void)
|
|||
|
||||
consoleDemoInit();
|
||||
puts("Hello world! Initializing FAT...");
|
||||
fatInitDefault();
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
puts("# error initializing SDL");
|
||||
puts(SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
puts("* initialized SDL");
|
||||
screen = SDL_SetVideoMode(256, 192, 15, SDL_SWSURFACE);
|
||||
if (!screen) {
|
||||
puts("# error setting video mode");
|
||||
puts(SDL_GetError());
|
||||
return 2;
|
||||
|
||||
if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 &&
|
||||
SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) {
|
||||
exit(1);
|
||||
}
|
||||
screen->flags &= ~SDL_PREALLOC;
|
||||
puts("* set video mode");
|
||||
|
||||
stick = SDL_JoystickOpen(0);
|
||||
if (stick == NULL) {
|
||||
puts("# error opening joystick");
|
||||
puts(SDL_GetError());
|
||||
// return 3;
|
||||
}
|
||||
puts("* opened joystick");
|
||||
|
||||
/*splash(screen, 3); */
|
||||
|
||||
SDL_FillRect(screen, &rect, RGB15(0, 0, 31) | 0x8000);
|
||||
SDL_Flip(screen);
|
||||
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_FillRect(screen, &rect, (u16) rand() | 0x8000);
|
||||
SDL_Flip(screen);
|
||||
|
||||
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());
|
||||
/*
|
||||
printf("button %d pressed at %d ticks\n",
|
||||
event.jbutton.button, SDL_GetTicks());
|
||||
*/
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
SDL_Quit();
|
||||
|
@ -90,7 +85,5 @@ main(void)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue