Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
More sprite-work in the render driver, and some updates to the nds-te…
Browse files Browse the repository at this point in the history
…st-progs.
  • Loading branch information
Darren Alton committed Aug 16, 2008
1 parent f388900 commit eee4eee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
14 changes: 12 additions & 2 deletions src/video/nds/SDL_ndsrender.c
Expand Up @@ -341,10 +341,22 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
sprent->objMode = OBJMODE_BITMAP;
sprent->posX = 0; sprent->posY = 0;
sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */

/* the first 32 sprites get transformation matrices.
first come, first served */
if(whichspr < MATRIX_COUNT) {
sprent->isRotoscale = 1;
sprent->rsMatrixIdx = whichspr;
}

sprent->objShape = OBJSHAPE_SQUARE;
if(texture->w/2 >= texture->h) {
sprent->objShape = OBJSHAPE_WIDE;
} else if(texture->h/2 >= texture->w) {
sprent->objShape = OBJSHAPE_TALL;
}
} else {
SDL_SetError("Out of NDS sprites.");
}
} else if(texture->w <= 256 && texture->h <= 256) {
int whichbg = -1, base = 0;
Expand Down Expand Up @@ -385,15 +397,13 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
/*txdat->size = txdat->dim.pitch * texture->h;*/
} else {
SDL_SetError("Out of NDS backgrounds.");
printf("ran out.\n");
}
} else {
SDL_SetError("Texture too big for NDS hardware.");
}

TRACE("-NDS_CreateTexture\n");
if (!texture->driverdata) {
SDL_SetError("Couldn't create NDS render driver data.");
return -1;
}

Expand Down
23 changes: 20 additions & 3 deletions test/nds-test-progs/general/source/main.c
Expand Up @@ -2,13 +2,26 @@
#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 delay(int s) {
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();
Expand All @@ -22,7 +35,8 @@ int main(void) {
SDL_Rect rect = {8,8,240,176};
int i;

consoleDemoInit();
consoleDemoInit(); puts("Hello world! Initializing FAT...");
fatInitDefault();
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) {
puts("# error initializing SDL");
puts(SDL_GetError());
Expand All @@ -44,6 +58,9 @@ int main(void) {
// return 3;
}
puts("* opened joystick");

/*splash(screen, 3);*/

SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000);
SDL_Flip(screen);

Expand All @@ -66,7 +83,7 @@ int main(void) {
break;
default: break;
}
printf("joy_%d\n", event.jbutton.which);
printf("joy_%d, at %d\n", event.jbutton.which, SDL_GetTicks());
SDL_Flip(screen);
break;
case SDL_QUIT: SDL_Quit(); return 0;
Expand Down
34 changes: 15 additions & 19 deletions test/nds-test-progs/sprite/source/testsprite.c
Expand Up @@ -7,7 +7,7 @@
#include <fat.h>
#include <SDL/SDL.h>

#define NUM_SPRITES 100
#define NUM_SPRITES 10
#define MAX_SPEED 1

SDL_Surface *sprite;
Expand Down Expand Up @@ -162,18 +162,21 @@ main(int argc, char *argv[])
int i, done;
SDL_Event event;
Uint32 then, now, frames;

consoleDemoInit(); puts("Hello world! Initializing FAT...");
fatInitDefault();
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
puts("* initialized SDL");

numsprites = NUM_SPRITES;
videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
width = 640;
height = 480;
video_bpp = 8;
videoflags = SDL_SWSURFACE /*| SDL_ANYFORMAT*/;
width = 256;
height = 192;
video_bpp = 15;
debug_flip = 0;
while (argc > 1) {
--argc;
Expand Down Expand Up @@ -214,11 +217,14 @@ main(int argc, char *argv[])
width, height, SDL_GetError());
quit(2);
}
screen->flags &= ~SDL_PREALLOC;
puts("* set video mode");

/* Load the sprite */
if (LoadSprite("icon.bmp") < 0) {
quit(1);
}
puts("* loaded sprite");

/* Allocate memory for the sprite info */
mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
Expand Down Expand Up @@ -286,25 +292,15 @@ main(int argc, char *argv[])
then = SDL_GetTicks();
done = 0;
sprites_visible = 0;
puts("hello!");
while (!done) {
/* Check for events */
++frames;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
SDL_WarpMouse(screen->w / 2, screen->h / 2);
break;
case SDL_KEYDOWN:
/* Any keypress quits the app... */
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
printf(".");
swiWaitForVBlank();
MoveSprites(screen, background);
}
puts("goodbye!");
SDL_FreeSurface(sprite);
free(mem);

Expand Down
5 changes: 4 additions & 1 deletion test/nds-test-progs/sprite2/source/testsprite2.c
Expand Up @@ -7,7 +7,7 @@
#include <fat.h>
#include "common.h"

#define NUM_SPRITES 100
#define NUM_SPRITES 10
#define MAX_SPEED 1

static CommonState *state;
Expand Down Expand Up @@ -149,7 +149,10 @@ main(int argc, char *argv[])
int i, done;
SDL_Event event;
Uint32 then, now, frames;

consoleDemoInit(); puts("Hello world! Initializing FAT...");
fatInitDefault();

/* Initialize parameters */
num_sprites = NUM_SPRITES;

Expand Down

0 comments on commit eee4eee

Please sign in to comment.