More work on the accelerated 2D video driver, beginnings of sprite-based rendering support. Also some initial work on an audio driver. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Sat, 19 Jul 2008 17:37:19 +0000
branchgsoc2008_nds
changeset 26804135aa9c5645
parent 2679 bc3e3e889f6d
child 2681 c15b6c758be5
More work on the accelerated 2D video driver, beginnings of sprite-based rendering support. Also some initial work on an audio driver.
Makefile.ds
include/SDL_config_nintendods.h
src/audio/SDL_audio.c
src/audio/nds/SDL_ndsaudio.c
src/audio/nds/SDL_ndsaudio.h
src/video/nds/SDL_ndsrender.c
src/video/nds/SDL_ndsvideo.c
     1.1 --- a/Makefile.ds	Sun Jul 13 04:28:54 2008 +0000
     1.2 +++ b/Makefile.ds	Sat Jul 19 17:37:19 2008 +0000
     1.3 @@ -31,6 +31,7 @@
     1.4  src/SDL_fatal.c \
     1.5  src/audio/disk/SDL_diskaudio.c \
     1.6  src/audio/dummy/SDL_dummyaudio.c \
     1.7 +src/audio/nds/SDL_ndsaudio.c \
     1.8  src/audio/SDL_audio.c \
     1.9  src/audio/SDL_audiocvt.c \
    1.10  src/audio/SDL_audiodev.c \
     2.1 --- a/include/SDL_config_nintendods.h	Sun Jul 13 04:28:54 2008 +0000
     2.2 +++ b/include/SDL_config_nintendods.h	Sat Jul 19 17:37:19 2008 +0000
     2.3 @@ -92,14 +92,15 @@
     2.4  #define LACKS_SYS_MMAN_H 1
     2.5  
     2.6  /* Enable various audio drivers */
     2.7 -#define SDL_AUDIO_DRIVER_DUMMY	1
     2.8 +#define SDL_AUDIO_DRIVER_NDS	1
     2.9 +/*#define SDL_AUDIO_DRIVER_DUMMY	1 TODO: uncomment this later*/
    2.10  
    2.11  /* DS doesn't have optical media */
    2.12  #define SDL_CDROM_DISABLED	1
    2.13  
    2.14  /* Enable various input drivers */
    2.15  #define SDL_JOYSTICK_NDS	1
    2.16 -/*#define SDL_JOYSTICK_DUMMY	1*/
    2.17 +/*#define SDL_JOYSTICK_DUMMY	1 TODO: uncomment this later*/
    2.18  
    2.19  /* DS has no dynamic linking afaik */
    2.20  #define SDL_LOADSO_DISABLED	1
    2.21 @@ -113,6 +114,6 @@
    2.22  
    2.23  /* Enable various video drivers */
    2.24  #define SDL_VIDEO_DRIVER_NDS	1
    2.25 -#define SDL_VIDEO_DRIVER_DUMMY	1
    2.26 +/*#define SDL_VIDEO_DRIVER_DUMMY	1 TODO: uncomment this later*/
    2.27  
    2.28  #endif /* _SDL_config_nintendods_h */
     3.1 --- a/src/audio/SDL_audio.c	Sun Jul 13 04:28:54 2008 +0000
     3.2 +++ b/src/audio/SDL_audio.c	Sat Jul 19 17:37:19 2008 +0000
     3.3 @@ -70,6 +70,7 @@
     3.4  extern AudioBootStrap DCAUD_bootstrap;
     3.5  extern AudioBootStrap MMEAUDIO_bootstrap;
     3.6  extern AudioBootStrap DART_bootstrap;
     3.7 +extern AudioBootStrap NDSAUD_bootstrap;
     3.8  
     3.9  
    3.10  /* Available audio drivers */
    3.11 @@ -145,6 +146,9 @@
    3.12  #if SDL_AUDIO_DRIVER_DART
    3.13      &DART_bootstrap,
    3.14  #endif
    3.15 +#if SDL_AUDIO_DRIVER_NDS
    3.16 +    &NDSAUD_bootstrap,
    3.17 +#endif
    3.18      NULL
    3.19  };
    3.20  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/audio/nds/SDL_ndsaudio.c	Sat Jul 19 17:37:19 2008 +0000
     4.3 @@ -0,0 +1,92 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2006 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +
    4.25 +    This file written by Ryan C. Gordon (icculus@icculus.org)
    4.26 +*/
    4.27 +#include "SDL_config.h"
    4.28 +
    4.29 +/* Output audio to NDS */
    4.30 +
    4.31 +#include <nds.h>
    4.32 +
    4.33 +#include "SDL_audio.h"
    4.34 +#include "../SDL_audio_c.h"
    4.35 +#include "SDL_ndsaudio.h"
    4.36 +
    4.37 +static int
    4.38 +NDSAUD_OpenDevice(_THIS, const char *devname, int iscapture)
    4.39 +{
    4.40 +    return 1;                   /* always succeeds. */
    4.41 +}
    4.42 +
    4.43 +static void
    4.44 +NDSAUD_PlayDevice(_THIS)
    4.45 +{
    4.46 +    TransferSoundData* sound = SDL_malloc(sizeof(TransferSoundData));
    4.47 +    if(!sound) {
    4.48 +        SDL_OutOfMemory();
    4.49 +    }
    4.50 +    sound->data = NULL;  /* pointer to raw audio data */
    4.51 +    sound->len = 0;      /* size of raw data pointed to above */
    4.52 +    sound->rate = 22050; /* sample rate = 22050Hz */
    4.53 +    sound->vol = 127;    /* volume [0..127] for [min..max] */
    4.54 +    sound->pan = 64;     /* balance [0..127] for [left..right] */
    4.55 +    sound->format = 0;   /* 0 for 16-bit, 1 for 8-bit */
    4.56 +    /* stub */
    4.57 +}
    4.58 +
    4.59 +
    4.60 +static Uint8 *
    4.61 +NDSAUD_GetDeviceBuf(_THIS)
    4.62 +{
    4.63 +    /* stub */
    4.64 +}
    4.65 +
    4.66 +static void
    4.67 +NDSAUD_WaitDevice(_THIS)
    4.68 +{
    4.69 +    /* stub */
    4.70 +}
    4.71 +
    4.72 +static void
    4.73 +NDSAUD_CloseDevice(_THIS)
    4.74 +{
    4.75 +    /* stub */
    4.76 +}
    4.77 +
    4.78 +static int
    4.79 +NDSAUD_Init(SDL_AudioDriverImpl * impl)
    4.80 +{
    4.81 +    /* Set the function pointers */
    4.82 +    impl->OpenDevice = NDSAUD_OpenDevice;
    4.83 +    impl->PlayDevice = NDSAUD_PlayDevice;
    4.84 +    impl->WaitDevice = NDSAUD_WaitDevice;
    4.85 +    impl->GetDeviceBuf = NDSAUD_GetDeviceBuf;
    4.86 +    impl->CloseDevice = NDSAUD_CloseDevice;
    4.87 +    impl->OnlyHasDefaultOutputDevice = 1;
    4.88 +    return 1;
    4.89 +}
    4.90 +
    4.91 +AudioBootStrap NDSAUD_bootstrap = {
    4.92 +    "nds", "SDL NDS audio driver", NDSAUD_Init, 1
    4.93 +};
    4.94 +
    4.95 +/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/audio/nds/SDL_ndsaudio.h	Sat Jul 19 17:37:19 2008 +0000
     5.3 @@ -0,0 +1,42 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#ifndef _SDL_ndsaudio_h
    5.28 +#define _SDL_ndsaudio_h
    5.29 +
    5.30 +#include "../SDL_sysaudio.h"
    5.31 +
    5.32 +/* Hidden "this" pointer for the audio functions */
    5.33 +#define _THIS	SDL_AudioDevice *this
    5.34 +
    5.35 +struct SDL_PrivateAudioData
    5.36 +{
    5.37 +    /* The file descriptor for the audio device */
    5.38 +    Uint8 *mixbuf;
    5.39 +    Uint32 mixlen;
    5.40 +    Uint32 write_delay;
    5.41 +    Uint32 initial_calls;
    5.42 +};
    5.43 +
    5.44 +#endif /* _SDL_ndsaudio_h */
    5.45 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/nds/SDL_ndsrender.c	Sun Jul 13 04:28:54 2008 +0000
     6.2 +++ b/src/video/nds/SDL_ndsrender.c	Sat Jul 19 17:37:19 2008 +0000
     6.3 @@ -159,6 +159,7 @@
     6.4  /*  Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
     6.5      Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
     6.6  */
     6.7 +printf("+NDS_CreateRenderer\n");
     6.8  
     6.9      /* hard coded this to BGR555 for now */
    6.10      if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
    6.11 @@ -220,6 +221,7 @@
    6.12      data->bg_taken[2] = data->bg_taken[3] = 0;
    6.13      data->sub = 0;
    6.14  
    6.15 +printf("-NDS_CreateRenderer\n");
    6.16      return renderer;
    6.17  }
    6.18  
    6.19 @@ -228,6 +230,7 @@
    6.20  {
    6.21      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
    6.22      /* stub. TODO: figure out what needs to be done, if anything. */
    6.23 +printf("!NDS_ActivateRenderer\n");
    6.24      return 0;
    6.25  }
    6.26  
    6.27 @@ -236,6 +239,7 @@
    6.28  {
    6.29      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
    6.30      /* stub. TODO: figure out what needs to be done */
    6.31 +printf("!NDS_DisplayModeChanged\n");
    6.32      return 0;
    6.33  }
    6.34  
    6.35 @@ -244,6 +248,7 @@
    6.36  {
    6.37      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
    6.38      NDS_TextureData *txdat = NULL;
    6.39 +printf("+NDS_CreateTexture\n");
    6.40      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    6.41          SDL_SetError("Unsupported texture format");
    6.42          return -1;
    6.43 @@ -301,6 +306,7 @@
    6.44          }
    6.45      }
    6.46  
    6.47 +printf("-NDS_CreateTexture\n");
    6.48      if (!texture->driverdata) {
    6.49          return -1;
    6.50      }
    6.51 @@ -311,6 +317,7 @@
    6.52  NDS_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
    6.53                        void **pixels, int *pitch)
    6.54  {
    6.55 +printf("+NDS_QueryTexturePixels\n");
    6.56      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    6.57          SDL_SetError("Unsupported texture format");
    6.58          return -1;
    6.59 @@ -319,6 +326,7 @@
    6.60  
    6.61          *pixels = txdat->vram;
    6.62          *pitch = txdat->dim.pitch;
    6.63 +printf("-NDS_QueryTexturePixels\n");
    6.64          return 0;
    6.65      }
    6.66  }
    6.67 @@ -327,12 +335,14 @@
    6.68  NDS_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
    6.69                       const SDL_Color * colors, int firstcolor, int ncolors)
    6.70  {
    6.71 +printf("+NDS_SetTexturePalette\n");
    6.72      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    6.73          SDL_SetError("YUV textures don't have a palette");
    6.74          return -1;
    6.75      } else {
    6.76          NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
    6.77          /* TODO: mess with 8-bit modes and/or 16-color palette modes */
    6.78 +printf("-NDS_SetTexturePalette\n");
    6.79          return 0;
    6.80      }
    6.81  }
    6.82 @@ -341,11 +351,13 @@
    6.83  NDS_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
    6.84                       SDL_Color * colors, int firstcolor, int ncolors)
    6.85  {
    6.86 +printf("+NDS_GetTexturePalette\n");
    6.87      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    6.88          SDL_SetError("YUV textures don't have a palette");
    6.89          return -1;
    6.90      } else {
    6.91          NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
    6.92 +printf("-NDS_GetTexturePalette\n");
    6.93          /* TODO: mess with 8-bit modes and/or 16-color palette modes */
    6.94          return 0;
    6.95      }
    6.96 @@ -354,6 +366,7 @@
    6.97  static int
    6.98  NDS_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
    6.99  {
   6.100 +printf("!NDS_SetTextureColorMod\n");
   6.101      /* stub. TODO: figure out what needs to be done, if anything */
   6.102      return 0;
   6.103  }
   6.104 @@ -361,6 +374,7 @@
   6.105  static int
   6.106  NDS_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
   6.107  {
   6.108 +printf("!NDS_SetTextureAlphaMod\n");
   6.109      /* stub. TODO: figure out what needs to be done, if anything */
   6.110      return 0;
   6.111  }
   6.112 @@ -368,6 +382,7 @@
   6.113  static int
   6.114  NDS_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
   6.115  {
   6.116 +printf("!NDS_SetTextureBlendMode\n");
   6.117      /* stub. TODO: figure out what needs to be done, if anything */
   6.118      return 0;
   6.119  }
   6.120 @@ -375,6 +390,7 @@
   6.121  static int
   6.122  NDS_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
   6.123  {
   6.124 +printf("!NDS_SetTextureScaleMode\n");
   6.125      /* stub. TODO: figure out what needs to be done.
   6.126         (NDS hardware scaling is nearest neighbor.) */
   6.127      return 0;
   6.128 @@ -384,6 +400,7 @@
   6.129  NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   6.130                   const SDL_Rect * rect, const void *pixels, int pitch)
   6.131  {
   6.132 +printf("+NDS_UpdateTexture\n");
   6.133      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.134          SDL_SetError("Unsupported texture format");
   6.135          return -1;
   6.136 @@ -403,6 +420,7 @@
   6.137              src += pitch;
   6.138              dst += txdat->dim.pitch;
   6.139          }
   6.140 +printf("-NDS_UpdateTexture\n");
   6.141          return 0;
   6.142      }
   6.143  }
   6.144 @@ -412,6 +430,7 @@
   6.145                 const SDL_Rect * rect, int markDirty, void **pixels,
   6.146                 int *pitch)
   6.147  {
   6.148 +printf("+NDS_LockTexture\n");
   6.149      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.150          SDL_SetError("Unsupported texture format");
   6.151          return -1;
   6.152 @@ -421,6 +440,7 @@
   6.153          *pixels = (void *) ((u8 *)txdat->vram + rect->y * txdat->dim.pitch
   6.154                              + rect->x * (txdat->dim.bpp/8));
   6.155          *pitch = txdat->dim.pitch;
   6.156 +printf("-NDS_LockTexture\n");
   6.157          return 0;
   6.158      }
   6.159  }
   6.160 @@ -431,12 +451,14 @@
   6.161      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.162          SDL_SetError("Unsupported texture format");
   6.163      }
   6.164 +printf("!NDS_UnlockTexture\n");
   6.165  }
   6.166  
   6.167  static void
   6.168  NDS_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   6.169                  int numrects, const SDL_Rect * rects)
   6.170  { /* stub */
   6.171 +printf("!NDS_DirtyTexture\n");
   6.172  }
   6.173  
   6.174  static int
   6.175 @@ -448,6 +470,7 @@
   6.176      u16 color;
   6.177      int i, j;
   6.178  
   6.179 +printf("+NDS_RenderFill\n");
   6.180      /* TODO: make a single-color sprite and stretch it.
   6.181      color = RGB15(r>>3,g>>3,b>>3);
   6.182      for (i = real_rect.x; i < real_rect.x+real_rect.w; ++i) {
   6.183 @@ -456,6 +479,7 @@
   6.184                  0x8000 | color;
   6.185          }
   6.186      }*/
   6.187 +printf("-NDS_RenderFill\n");
   6.188      return 0;
   6.189  }
   6.190  
   6.191 @@ -467,6 +491,7 @@
   6.192      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   6.193      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   6.194  
   6.195 +printf("+NDS_RenderCopy\n");
   6.196  #if 0
   6.197      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.198          SDL_Surface *target = data->screens[data->current_screen];
   6.199 @@ -485,6 +510,7 @@
   6.200          return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
   6.201      }
   6.202  #endif
   6.203 +printf("-NDS_RenderCopy\n");
   6.204      return 0;
   6.205  }
   6.206  
   6.207 @@ -495,21 +521,25 @@
   6.208      NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
   6.209      /* Send the data to the display TODO */
   6.210  
   6.211 +printf("+NDS_RenderPresent\n");
   6.212      /* Update the flipping chain, if any */
   6.213      if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
   6.214          swiWaitForVBlank();
   6.215      }
   6.216 +printf("-NDS_RenderPresent\n");
   6.217  }
   6.218  
   6.219  static void
   6.220  NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   6.221  {
   6.222 +printf("+NDS_DestroyTexture\n");
   6.223      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   6.224          SDL_SetError("Unsupported texture format");
   6.225      } else {
   6.226          /* free anything else allocated for texture */
   6.227          SDL_free(texture->driverdata);
   6.228      }
   6.229 +printf("-NDS_DestroyTexture\n");
   6.230  }
   6.231  
   6.232  static void
   6.233 @@ -520,6 +550,7 @@
   6.234      SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);*/
   6.235      int i;
   6.236  
   6.237 +printf("+NDS_DestroyRenderer\n");
   6.238      if (data) {
   6.239          /* TODO: free anything relevant. */
   6.240          /*for (i = 0; i < SDL_arraysize(data->texture); ++i) {
   6.241 @@ -539,6 +570,7 @@
   6.242          SDL_free(data);
   6.243      }
   6.244      SDL_free(renderer);
   6.245 +printf("-NDS_DestroyRenderer\n");
   6.246  }
   6.247  
   6.248  /* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/nds/SDL_ndsvideo.c	Sun Jul 13 04:28:54 2008 +0000
     7.2 +++ b/src/video/nds/SDL_ndsvideo.c	Sat Jul 19 17:37:19 2008 +0000
     7.3 @@ -21,16 +21,8 @@
     7.4  */
     7.5  #include "SDL_config.h"
     7.6  
     7.7 -/* Dummy SDL video driver implementation; this is just enough to make an
     7.8 - *  SDL-based application THINK it's got a working video driver, for
     7.9 - *  applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
    7.10 - *  and also for use as a collection of stubs when porting SDL to a new
    7.11 - *  platform for which you haven't yet written a valid video driver.
    7.12 - *
    7.13 - * This is also a great way to determine bottlenecks: if you think that SDL
    7.14 - *  is a performance problem for a given platform, enable this driver, and
    7.15 - *  then see if your application runs faster without video overhead.
    7.16 - *
    7.17 +/* SDL Nintendo DS video driver implementation
    7.18 + * based on dummy driver:
    7.19   * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
    7.20   *  of this was cut-and-pasted from Stephane Peter's work in the AAlib
    7.21   *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
    7.22 @@ -39,6 +31,9 @@
    7.23  #include <stdio.h>
    7.24  #include <stdlib.h>
    7.25  #include <nds.h>
    7.26 +#include <nds/arm9/sprite.h>
    7.27 +#include <nds/arm9/trig_lut.h>
    7.28 +#include <nds/arm9/video.h>
    7.29  
    7.30  #include "SDL_video.h"
    7.31  #include "SDL_mouse.h"
    7.32 @@ -57,12 +52,71 @@
    7.33  static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
    7.34  static void NDS_VideoQuit(_THIS);
    7.35  
    7.36 -/* DUMMY driver bootstrap functions */
    7.37 +/* NDS sprite-related functions */
    7.38  
    7.39 +#define SPRITE_DMA_CHANNEL 3
    7.40 +#define SPRITE_ANGLE_MASK 0x01FF
    7.41 +
    7.42 +void
    7.43 +NDS_OAM_Update(tOAM *oam)
    7.44 +{
    7.45 +    DC_FlushAll();
    7.46 +    dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer, OAM,
    7.47 +                     SPRITE_COUNT * sizeof(SpriteEntry));
    7.48 +}
    7.49 +
    7.50 +void
    7.51 +NDS_OAM_RotateSprite(SpriteRotation *spriteRotation, u16 angle)
    7.52 +{
    7.53 +    s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4;
    7.54 +    s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4;
    7.55 +
    7.56 +    spriteRotation->hdx = c;
    7.57 +    spriteRotation->hdy = s;
    7.58 +    spriteRotation->vdx = -s;
    7.59 +    spriteRotation->vdy = c;
    7.60 +}
    7.61 +
    7.62 +void
    7.63 +NDS_OAM_Init(tOAM *oam)
    7.64 +{
    7.65 +    int i;
    7.66 +    for(i = 0; i < SPRITE_COUNT; i++) {
    7.67 +        oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED;
    7.68 +        oam->spriteBuffer[i].attribute[1] = 0;
    7.69 +        oam->spriteBuffer[i].attribute[2] = 0;
    7.70 +    }
    7.71 +    for(i = 0; i < MATRIX_COUNT; i++) {
    7.72 +        NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0);
    7.73 +    }
    7.74 +    swiWaitForVBlank();
    7.75 +    NDS_OAM_Update(oam);
    7.76 +}
    7.77 +
    7.78 +void
    7.79 +NDS_OAM_HideSprite(SpriteEntry *spriteEntry)
    7.80 +{
    7.81 +    spriteEntry->isRotoscale = 0;
    7.82 +    spriteEntry->isHidden = 1;
    7.83 +}
    7.84 +
    7.85 +void
    7.86 +NDS_OAM_ShowSprite(SpriteEntry *spriteEntry, int affine, int double_bound)
    7.87 +{
    7.88 +    if (affine) {
    7.89 +        spriteEntry->isRotoscale = 1;
    7.90 +        spriteEntry->rsDouble = double_bound;
    7.91 +    } else {
    7.92 +        spriteEntry->isHidden = 0;
    7.93 +    }
    7.94 +}
    7.95 +
    7.96 +
    7.97 +/* SDL NDS driver bootstrap functions */
    7.98  static int
    7.99  NDS_Available(void)
   7.100  {
   7.101 -    const char *envr = SDL_getenv("SDL_VIDEODRIVER");
   7.102 +    /*const char *envr = SDL_getenv("SDL_VIDEODRIVER");*/
   7.103      /*printf("NDS_Available()\n"); */
   7.104      return (1);
   7.105  }
   7.106 @@ -79,6 +133,7 @@
   7.107      SDL_VideoDevice *device;
   7.108      /*printf("NDS_CreateDevice(%d)\n", devindex); */
   7.109  
   7.110 +printf("+NDS_CreateDevice\n");
   7.111      /* Initialize all variables that we clean on shutdown */
   7.112      device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
   7.113      if (!device) {
   7.114 @@ -99,6 +154,7 @@
   7.115  
   7.116      device->free = NDS_DeleteDevice;
   7.117  
   7.118 +printf("-NDS_CreateDevice\n");
   7.119      return device;
   7.120  }
   7.121  
   7.122 @@ -113,7 +169,8 @@
   7.123      SDL_DisplayMode mode;
   7.124      int i;
   7.125  
   7.126 -    /* simple 256x192x15x60 for now */
   7.127 +printf("+NDS_VideoInit\n");
   7.128 +    /* simple 256x192x16x60 for now */
   7.129      mode.w = 256;
   7.130      mode.h = 192;
   7.131      mode.format = SDL_PIXELFORMAT_ABGR1555;
   7.132 @@ -129,49 +186,41 @@
   7.133      SDL_AddDisplayMode(0, &mode);
   7.134  
   7.135      /* hackish stuff to get things up and running for now, and for a console */
   7.136 -    powerON(POWER_ALL);
   7.137     irqInit();
   7.138 +    powerON(POWER_ALL_2D);
   7.139     irqInit();
   7.140      irqEnable(IRQ_VBLANK);
   7.141      NDS_SetDisplayMode(_this, &mode);
   7.142 +printf("-NDS_VideoInit\n");
   7.143      return 0;
   7.144  }
   7.145  
   7.146  static int
   7.147  NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   7.148  {
   7.149 +printf("+NDS_SetDisplayMode\n");
   7.150      /* right now this function is just hard-coded for 256x192 ABGR1555 */
   7.151      videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);       /* display on main core */
   7.152      videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);    /* debug text on sub */
   7.153 -    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD,
   7.154 -                     VRAM_C_SUB_BG, VRAM_D_LCD);
   7.155 -
   7.156 +    vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
   7.157 +                     VRAM_C_SUB_BG_0x06200000,  VRAM_C_SUB_BG_0x06220000);
   7.158 +    vramSetBankE(VRAM_E_MAIN_SPRITE);
   7.159      /* set up console for debug text 'n stuff */
   7.160      SUB_BG0_CR = BG_MAP_BASE(31);
   7.161      BG_PALETTE_SUB[255] = RGB15(31, 31, 31);
   7.162 +   /* debugging purposes, uncomment this later.  then remove it & add 2screen.
   7.163      consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31),
   7.164 -                       (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);
   7.165 -
   7.166 -#if 0
   7.167 -/* we should be using this as a texture for rendering, not as a framebuffer */
   7.168 -    /* maps well to the 256x192 screen anyway.  note: need VRAM_B for bigger */
   7.169 -    BACKGROUND.control[3] = BG_BMP16_256x256;
   7.170 -    /* affine transformation matrix.  nothing too fancy here */
   7.171 -    BG3_XDX = 0x100;
   7.172 -    BG3_XDY = 0;
   7.173 -    BG3_YDX = 0;
   7.174 -    BG3_YDY = 0x100;
   7.175 -    /* x/y position */
   7.176 -    BG3_CX = 0;
   7.177 -    BG3_CY = 0;
   7.178 -#endif
   7.179 +                       (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);*/
   7.180 +printf("-NDS_SetDisplayMode\n");
   7.181      return 0;
   7.182  }
   7.183  
   7.184  void
   7.185  NDS_VideoQuit(_THIS)
   7.186  {
   7.187 +printf("+NDS_VideoQuit\n");
   7.188      videoSetMode(DISPLAY_SCREEN_OFF);
   7.189      videoSetModeSub(DISPLAY_SCREEN_OFF);
   7.190      vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
   7.191 +printf("-NDS_VideoQuit\n");
   7.192  }
   7.193  
   7.194  /* vi: set ts=4 sw=4 expandtab: */