NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
authorDarren Alton <dalton@stevens.edu>
Wed, 18 Feb 2009 00:33:31 +0000
changeset 3073c5280d33c32a
parent 3072 9da8f57ab92c
child 3074 caffd6a5555d
NDS compiles again, but may not yet work. Sprite support has been removed for the time being while it is re-worked.
Makefile.ds
src/video/nds/SDL_ndsrender.c
     1.1 --- a/Makefile.ds	Tue Feb 17 05:59:40 2009 +0000
     1.2 +++ b/Makefile.ds	Wed Feb 18 00:33:31 2009 +0000
     1.3 @@ -87,7 +87,9 @@
     1.4  src/video/SDL_blit_N.c \
     1.5  src/video/SDL_blit_slow.c \
     1.6  src/video/SDL_bmp.c \
     1.7 -src/video/SDL_fill.c \
     1.8 +src/video/SDL_drawline.c \
     1.9 +src/video/SDL_drawpoint.c \
    1.10 +src/video/SDL_fillrect.c \
    1.11  src/video/SDL_gamma.c \
    1.12  src/video/SDL_pixels.c \
    1.13  src/video/SDL_rect.c \
     2.1 --- a/src/video/nds/SDL_ndsrender.c	Tue Feb 17 05:59:40 2009 +0000
     2.2 +++ b/src/video/nds/SDL_ndsrender.c	Wed Feb 18 00:33:31 2009 +0000
     2.3 @@ -23,9 +23,9 @@
     2.4  #include <stdio.h>
     2.5  #include <stdlib.h>
     2.6  #include <nds.h>
     2.7 -#include <nds/arm9/video.h>
     2.8 -#include <nds/arm9/sprite.h>
     2.9 -#include <nds/arm9/trig_lut.h>
    2.10 +//#include <nds/arm9/video.h>
    2.11 +//#include <nds/arm9/sprite.h>
    2.12 +//#include <nds/arm9/trig_lut.h>
    2.13  
    2.14  #include "SDL_config.h"
    2.15  
    2.16 @@ -34,65 +34,6 @@
    2.17  #include "../SDL_yuv_sw_c.h"
    2.18  #include "../SDL_renderer_sw.h"
    2.19  
    2.20 -/* NDS sprite-related functions */
    2.21 -#define SPRITE_DMA_CHANNEL 3
    2.22 -#define SPRITE_ANGLE_MASK 0x01FF
    2.23 -
    2.24 -void
    2.25 -NDS_OAM_Update(tOAM * oam, int sub)
    2.26 -{
    2.27 -    DC_FlushAll();
    2.28 -    dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer,
    2.29 -                     sub ? OAM_SUB : OAM, SPRITE_COUNT * sizeof(SpriteEntry));
    2.30 -}
    2.31 -
    2.32 -void
    2.33 -NDS_OAM_RotateSprite(SpriteRotation * spriteRotation, u16 angle)
    2.34 -{
    2.35 -    s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4;
    2.36 -    s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4;
    2.37 -
    2.38 -    spriteRotation->hdx = c;
    2.39 -    spriteRotation->hdy = s;
    2.40 -    spriteRotation->vdx = -s;
    2.41 -    spriteRotation->vdy = c;
    2.42 -}
    2.43 -
    2.44 -void
    2.45 -NDS_OAM_Init(tOAM * oam, int sub)
    2.46 -{
    2.47 -    int i;
    2.48 -    for (i = 0; i < SPRITE_COUNT; i++) {
    2.49 -        oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED;
    2.50 -        oam->spriteBuffer[i].attribute[1] = 0;
    2.51 -        oam->spriteBuffer[i].attribute[2] = 0;
    2.52 -    }
    2.53 -    for (i = 0; i < MATRIX_COUNT; i++) {
    2.54 -        NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0);
    2.55 -    }
    2.56 -    swiWaitForVBlank();
    2.57 -    NDS_OAM_Update(oam, sub);
    2.58 -}
    2.59 -
    2.60 -void
    2.61 -NDS_OAM_HideSprite(SpriteEntry * spriteEntry)
    2.62 -{
    2.63 -    spriteEntry->isRotoscale = 0;
    2.64 -    spriteEntry->isHidden = 1;
    2.65 -}
    2.66 -
    2.67 -void
    2.68 -NDS_OAM_ShowSprite(SpriteEntry * spriteEntry, int affine, int double_bound)
    2.69 -{
    2.70 -    if (affine) {
    2.71 -        spriteEntry->isRotoscale = 1;
    2.72 -        spriteEntry->rsDouble = double_bound;
    2.73 -    } else {
    2.74 -        spriteEntry->isHidden = 0;
    2.75 -    }
    2.76 -}
    2.77 -
    2.78 -
    2.79  /* SDL NDS renderer implementation */
    2.80  
    2.81  static SDL_Renderer *NDS_CreateRenderer(SDL_Window * window, Uint32 flags);
    2.82 @@ -147,7 +88,7 @@
    2.83        SDL_PIXELFORMAT_INDEX8,
    2.84        SDL_PIXELFORMAT_ABGR1555,
    2.85        SDL_PIXELFORMAT_BGR555,
    2.86 -      },                        /* u32 texture_formats[20] */
    2.87 +     },                         /* u32 texture_formats[20] */
    2.88       (256),                     /* int max_texture_width */
    2.89       (256),                     /* int max_texture_height */
    2.90       }
    2.91 @@ -155,9 +96,8 @@
    2.92  
    2.93  typedef struct
    2.94  {
    2.95 -    bg_attribute *bg;           /* backgrounds */
    2.96 -    tOAM oam_copy;              /* sprites */
    2.97      u8 bg_taken[4];
    2.98 +    OamState *oam;
    2.99      int sub;
   2.100  } NDS_RenderData;
   2.101  
   2.102 @@ -165,12 +105,11 @@
   2.103  {
   2.104      enum
   2.105      { NDSTX_BG, NDSTX_SPR } type;       /* represented in a bg or sprite. */
   2.106 -    int hw_index;               /* sprite: index in the OAM. /  bg: 2 or 3. */
   2.107 -    struct
   2.108 -    {
   2.109 -        int hdx, hdy, vdx, vdy; /* affine transformation, used for scaling. */
   2.110 -        int pitch, bpp;         /* some useful info */
   2.111 -    } dim;
   2.112 +    int hw_index;               /* index of sprite in OAM or bg from libnds */
   2.113 +    int pitch, bpp;             /* useful information about the texture */
   2.114 +    struct { int x,y; } scale;  /* x/y stretch (24.8 fixed point) */
   2.115 +    struct { int x,y; } scroll; /* x/y offset */
   2.116 +    int rotate;                 /* -32768 to 32767, texture rotation */
   2.117      u16 *vram_pixels;           /* where the pixel data is stored (a pointer into VRAM) */
   2.118      u16 *vram_palette;          /* where the palette data is stored if it's indexed. */
   2.119      /*int size; */
   2.120 @@ -258,18 +197,11 @@
   2.121      renderer->info.max_texture_height =
   2.122          NDS_RenderDriver.info.max_texture_height;
   2.123  
   2.124 -    data->sub = 0;              /* TODO: this is hard-coded to the "main" screen.
   2.125 -                                   figure out how to detect whether to set it to
   2.126 -                                   "sub" screen.  window->id, perhaps? */
   2.127 -    if (!data->sub) {
   2.128 -        data->bg = &BACKGROUND;
   2.129 -    } else {
   2.130 -        data->bg = &BACKGROUND_SUB;
   2.131 -    }
   2.132 +    data->sub = 0;           /* TODO: this is hard-coded to the "main" screen.
   2.133 +                                figure out how to detect whether to set it to
   2.134 +                                "sub" screen.  window->id, perhaps? */
   2.135      data->bg_taken[2] = data->bg_taken[3] = 0;
   2.136  
   2.137 -    NDS_OAM_Init(&(data->oam_copy), data->sub); /* init sprites. */
   2.138 -
   2.139      return renderer;
   2.140  }
   2.141  
   2.142 @@ -308,8 +240,9 @@
   2.143         depending on which one it fits. */
   2.144      if (texture->w <= 64 && texture->h <= 64) {
   2.145          int whichspr = -1;
   2.146 -        printf("Tried to make a sprite.\n");
   2.147 +        printf("NDS_CreateTexture: Tried to make a sprite.\n");
   2.148          txdat->type = NDSTX_SPR;
   2.149 +#if 0
   2.150          for (i = 0; i < SPRITE_COUNT; ++i) {
   2.151              if (data->oam_copy.spriteBuffer[i].attribute[0] & ATTR0_DISABLED) {
   2.152                  whichspr = i;
   2.153 @@ -377,11 +310,13 @@
   2.154              txdat->dim.vdy = 0x100;
   2.155              txdat->dim.pitch = pitch;
   2.156              txdat->dim.bpp = bpp;
   2.157 -            txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);     /* FIXME: use tileIdx*boundary
   2.158 -                                                                                           to point to proper location */
   2.159 +            txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
   2.160 +            /* FIXME: use tileIdx*boundary
   2.161 +                      to point to proper location */
   2.162          } else {
   2.163              SDL_SetError("Out of NDS sprites.");
   2.164          }
   2.165 +#endif
   2.166      } else if (texture->w <= 256 && texture->h <= 256) {
   2.167          int whichbg = -1, base = 0;
   2.168          if (!data->bg_taken[2]) {
   2.169 @@ -398,27 +333,46 @@
   2.170                  return -1;
   2.171              }
   2.172  
   2.173 -            /* this is hard-coded to being 256x256 ABGR1555 for now. */
   2.174 -            data->bg->control[whichbg] = (bpp == 8) ?
   2.175 -                BG_BMP8_256x256 : BG_BMP16_256x256;
   2.176 +// hard-coded for 256x256 for now...
   2.177 +// TODO: a series of if-elseif-else's to find the closest but larger size.
   2.178 +            if(!data->sub) {
   2.179 +                if(bpp==8) {
   2.180 +                    txdat->hw_index = bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
   2.181 +                } else {
   2.182 +                    txdat->hw_index = bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
   2.183 +                }
   2.184 +            } else {
   2.185 +                if(bpp==8) {
   2.186 +                    txdat->hw_index = bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
   2.187 +                } else {
   2.188 +                    txdat->hw_index = bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
   2.189 +                }
   2.190 +            }
   2.191  
   2.192 -            data->bg->control[whichbg] |= BG_BMP_BASE(base);
   2.193 +/*   useful functions
   2.194 +        bgGetGfxPtr(bg3);            
   2.195 +		bgSetCenter(bg3, rcX, rcY);
   2.196 +		bgSetRotateScale(bg3, angle, scaleX, scaleY);
   2.197 +		bgSetScroll(bg3, scrollX, scrollY);
   2.198 +		bgUpdate(bg3);
   2.199 +*/
   2.200 +            txdat->type = NDSTX_BG;
   2.201 +            txdat->pitch = (texture->w)*(bpp/8);
   2.202 +            txdat->bpp = bpp;
   2.203 +            txdat->rotate = 0;
   2.204 +            txdat->scale.x = 0x100;
   2.205 +            txdat->scale.y = 0x100;
   2.206 +            txdat->scroll.x = 0;
   2.207 +            txdat->scroll.y = 0;
   2.208 +            txdat->vram_pixels = (u16*)bgGetGfxPtr(txdat->hw_index);
   2.209  
   2.210 -            data->bg->scroll[whichbg].x = 0;
   2.211 -            data->bg->scroll[whichbg].y = 0;
   2.212 +            bgSetCenter(txdat->hw_index, 0, 0);
   2.213 +            bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x,
   2.214 +                             txdat->scale.y);
   2.215 +            bgSetScroll(txdat->hw_index, txdat->scroll.x, txdat->scroll.y);
   2.216 +            bgUpdate(txdat->hw_index);
   2.217  
   2.218 -            txdat->type = NDSTX_BG;
   2.219 -            txdat->hw_index = whichbg;
   2.220 -            txdat->dim.hdx = 0x100;
   2.221 -            txdat->dim.hdy = 0;
   2.222 -            txdat->dim.vdx = 0;
   2.223 -            txdat->dim.vdy = 0x100;
   2.224 -            txdat->dim.pitch = 512;
   2.225 -            txdat->dim.bpp = bpp;
   2.226 -            txdat->vram_pixels = (u16 *) (data->sub ?
   2.227 -                                          BG_BMP_RAM_SUB(base) :
   2.228 -                                          BG_BMP_RAM(base));
   2.229 -
   2.230 +            data->bg_taken[whichbg] = 1;
   2.231              /*txdat->size = txdat->dim.pitch * texture->h; */
   2.232          } else {
   2.233              SDL_SetError("Out of NDS backgrounds.");
   2.234 @@ -440,7 +394,7 @@
   2.235  {
   2.236      NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   2.237      *pixels = txdat->vram_pixels;
   2.238 -    *pitch = txdat->dim.pitch;
   2.239 +    *pitch = txdat->pitch;
   2.240      return 0;
   2.241  }
   2.242  
   2.243 @@ -457,9 +411,9 @@
   2.244  
   2.245      src = (Uint8 *) pixels;
   2.246      dst =
   2.247 -        (Uint8 *) txdat->vram_pixels + rect->y * txdat->dim.pitch +
   2.248 -        rect->x * ((txdat->dim.bpp + 1) / 8);
   2.249 -    length = rect->w * ((txdat->dim.bpp + 1) / 8);
   2.250 +        (Uint8 *) txdat->vram_pixels + rect->y * txdat->pitch + rect->x *
   2.251 +        ((txdat->bpp + 1) / 8);
   2.252 +    length = rect->w * ((txdat->bpp + 1) / 8);
   2.253  
   2.254      if (rect->w == texture->w) {
   2.255          dmaCopy(src, dst, length * rect->h);
   2.256 @@ -467,7 +421,7 @@
   2.257          for (row = 0; row < rect->h; ++row) {
   2.258              dmaCopy(src, dst, length);
   2.259              src += pitch;
   2.260 -            dst += txdat->dim.pitch;
   2.261 +            dst += txdat->pitch;
   2.262          }
   2.263      }
   2.264  
   2.265 @@ -481,10 +435,9 @@
   2.266  {
   2.267      NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   2.268  
   2.269 -    *pixels = (void *) ((u8 *) txdat->vram_pixels + rect->y
   2.270 -                        * txdat->dim.pitch +
   2.271 -                        rect->x * ((txdat->dim.bpp + 1) / 8));
   2.272 -    *pitch = txdat->dim.pitch;
   2.273 +    *pixels = (void *) ((u8 *) txdat->vram_pixels + rect->y * txdat->pitch +
   2.274 +                        rect->x * ((txdat->bpp + 1) / 8));
   2.275 +    *pitch = txdat->pitch;
   2.276  
   2.277      return 0;
   2.278  }
   2.279 @@ -504,7 +457,8 @@
   2.280      u16 color;
   2.281      int i, j;
   2.282  
   2.283 -    color = RGB8(r, g, b);      /* <-- macro in libnds that makes an ARGB1555 pixel */
   2.284 +    printf("NDS_RenderFill: stub\n");
   2.285 +    color = RGB8(r, g, b);  /* macro in libnds that makes an ARGB1555 pixel */
   2.286      /* TODO: make a single-color sprite and stretch it.
   2.287         calculate the "HDX" width modifier of the sprite by:
   2.288         let S be the actual sprite's width (like, 32 pixels for example)
   2.289 @@ -525,35 +479,19 @@
   2.290      NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
   2.291      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   2.292      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   2.293 -    int i;
   2.294 -    int bpp = SDL_BYTESPERPIXEL(texture->format);
   2.295 -    int pitch = txdat->dim.pitch;
   2.296 +    int Bpp = SDL_BYTESPERPIXEL(texture->format);
   2.297  
   2.298      if (txdat->type == NDSTX_BG) {
   2.299 -        bg_rotation *bgrot = (txdat->hw_index == 2) ?
   2.300 -            &(data->bg->bg2_rotation) : &(data->bg->bg3_rotation);
   2.301 -        bgrot->xdx = txdat->dim.hdx;
   2.302 -        bgrot->xdy = txdat->dim.hdy;
   2.303 -        bgrot->ydx = txdat->dim.vdx;
   2.304 -        bgrot->ydy = txdat->dim.vdy;
   2.305 -        bgrot->centerX = 0;
   2.306 -        bgrot->centerY = 0;
   2.307 -
   2.308 -        data->bg->scroll[txdat->hw_index].x = dstrect->x;
   2.309 -        data->bg->scroll[txdat->hw_index].y = dstrect->y;
   2.310 +        txdat->scroll.x = dstrect->x;
   2.311 +        txdat->scroll.y = dstrect->y;
   2.312      } else {
   2.313          /* sprites not fully implemented yet */
   2.314 -        SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
   2.315 -        spr->posX = dstrect->x;
   2.316 -        spr->posY = dstrect->y;
   2.317 -        if (txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {
   2.318 -            SpriteRotation *sprot =
   2.319 -                &(data->oam_copy.matrixBuffer[txdat->hw_index]);
   2.320 -            sprot->hdx = txdat->dim.hdx;
   2.321 -            sprot->hdy = txdat->dim.hdy;
   2.322 -            sprot->vdx = txdat->dim.vdx;
   2.323 -            sprot->vdy = txdat->dim.vdy;
   2.324 -        }
   2.325 +        printf("NDS_RenderCopy: used sprite!\n");
   2.326 +//        SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
   2.327 +//        spr->posX = dstrect->x;
   2.328 +//        spr->posY = dstrect->y;
   2.329 +//        if (txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {          
   2.330 +//        }
   2.331      }
   2.332  
   2.333      return 0;
   2.334 @@ -568,7 +506,7 @@
   2.335      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   2.336  
   2.337      /* update sprites */
   2.338 -    NDS_OAM_Update(&(data->oam_copy), data->sub);
   2.339 +//    NDS_OAM_Update(&(data->oam_copy), data->sub);
   2.340      /* vsync for NDS */
   2.341      if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
   2.342          swiWaitForVBlank();