Fixes to the NDS sprite2 test. Illustrates partially working texture-as-sprite functionality.
authorDarren Alton <dalton@stevens.edu>
Sat, 06 Sep 2008 04:31:34 +0000
changeset 2750e3affc66d963
parent 2749 1c5f440a60fe
child 2751 3411fb673d4b
Fixes to the NDS sprite2 test. Illustrates partially working texture-as-sprite functionality.
src/haptic/nds/SDL_syshaptic.c
src/joystick/nds/SDL_sysjoystick.c
src/video/nds/SDL_ndsevents.c
test/nds-test-progs/sprite2/icon.bmp
test/nds-test-progs/sprite2/source/testsprite2.c
     1.1 --- a/src/haptic/nds/SDL_syshaptic.c	Sat Sep 06 00:10:16 2008 +0000
     1.2 +++ b/src/haptic/nds/SDL_syshaptic.c	Sat Sep 06 04:31:34 2008 +0000
     1.3 @@ -43,36 +43,35 @@
     1.4  } NDS_HapticData;
     1.5  
     1.6  
     1.7 -
     1.8 -void NDS_EZF_OpenNorWrite()
     1.9 -{
    1.10 -    GBA_BUS[0x0FF0000] = 0xD200;
    1.11 -    GBA_BUS[0x0000000] = 0x1500;
    1.12 -    GBA_BUS[0x0010000] = 0xD200;
    1.13 -    GBA_BUS[0x0020000] = 0x1500;
    1.14 -    GBA_BUS[0x0E20000] = 0x1500;
    1.15 -    GBA_BUS[0x0FE0000] = 0x1500;
    1.16 -}
    1.17 -
    1.18 -
    1.19 -void NDS_EZF_CloseNorWrite()
    1.20 -{
    1.21 -    GBA_BUS[0x0FF0000] = 0xD200;
    1.22 -    GBA_BUS[0x0000000] = 0x1500;
    1.23 -    GBA_BUS[0x0010000] = 0xD200;
    1.24 -    GBA_BUS[0x0020000] = 0x1500;
    1.25 -    GBA_BUS[0x0E20000] = 0xD200;
    1.26 -    GBA_BUS[0x0FE0000] = 0x1500;
    1.27 -}
    1.28 +
    1.29 void
    1.30 +NDS_EZF_OpenNorWrite() 
    1.31 +{
    1.32 +    
    1.33 GBA_BUS[0x0FF0000] = 0xD200;
    1.34 +    
    1.35 GBA_BUS[0x0000000] = 0x1500;
    1.36 +    
    1.37 GBA_BUS[0x0010000] = 0xD200;
    1.38 +    
    1.39 GBA_BUS[0x0020000] = 0x1500;
    1.40 +    
    1.41 GBA_BUS[0x0E20000] = 0x1500;
    1.42 +    
    1.43 GBA_BUS[0x0FE0000] = 0x1500;
    1.44 +
    1.45 } 
    1.46 
    1.47 
    1.48 void
    1.49  
    1.50 -void NDS_EZF_ChipReset()
    1.51 -{
    1.52 -    GBA_BUS[0x0000] = 0x00F0 ;
    1.53 -    GBA_BUS[0x1000] = 0x00F0 ;
    1.54 -}
    1.55 -uint32 NDS_EZF_IsPresent()
    1.56 -{
    1.57 -    vuint16 id1,id2;
    1.58 +NDS_EZF_CloseNorWrite() 
    1.59 +{
    1.60 +    
    1.61 GBA_BUS[0x0FF0000] = 0xD200;
    1.62 +    
    1.63 GBA_BUS[0x0000000] = 0x1500;
    1.64 +    
    1.65 GBA_BUS[0x0010000] = 0xD200;
    1.66 +    
    1.67 GBA_BUS[0x0020000] = 0x1500;
    1.68 +    
    1.69 GBA_BUS[0x0E20000] = 0xD200;
    1.70 +    
    1.71 GBA_BUS[0x0FE0000] = 0x1500;
    1.72 +
    1.73 }
    1.74 +
    1.75 +void
    1.76 +NDS_EZF_ChipReset()
    1.77 +{
    1.78 +    
    1.79 GBA_BUS[0x0000] = 0x00F0;
    1.80 +    
    1.81 GBA_BUS[0x1000] = 0x00F0;
    1.82 +} 
    1.83 uint32 NDS_EZF_IsPresent() 
    1.84 +{
    1.85 +    
    1.86 vuint16 id1, id2;
    1.87  
    1.88      NDS_EZF_OpenNorWrite();
    1.89  
    1.90 @@ -82,41 +81,35 @@
    1.91      GBA_BUS[0x1555] = 0x00AA;
    1.92      GBA_BUS[0x12AA] = 0x0055;
    1.93      GBA_BUS[0x1555] = 0x0090;
    1.94 -
    1.95 -    id1 = GBA_BUS[0x0001];
    1.96 -    id2 = GBA_BUS[0x1001];
    1.97 -
    1.98 -    if((id1!=0x227E)|| (id2!=0x227E)) {
    1.99 -        NDS_EZF_CloseNorWrite();
   1.100 -        return 0;
   1.101 -    }
   1.102 -
   1.103 -    id1 = GBA_BUS[0x000E];
   1.104 -    id2 = GBA_BUS[0x100E];
   1.105 +    
   1.106 id1 = GBA_BUS[0x0001];
   1.107 +    
   1.108 id2 = GBA_BUS[0x1001];
   1.109 +    
   1.110 if ((id1 != 0x227E) || (id2 != 0x227E)) {
   1.111 +        NDS_EZF_CloseNorWrite();
   1.112 +        
   1.113 return 0;
   1.114 +    }
   1.115 +    
   1.116 
   1.117 id1 = GBA_BUS[0x000E];
   1.118 +    
   1.119 id2 = GBA_BUS[0x100E];
   1.120  
   1.121      NDS_EZF_CloseNorWrite();
   1.122 -
   1.123 -    if(id1==0x2218 && id2==0x2218) {
   1.124 -        return 1;
   1.125 +    
   1.126 if (id1 == 0x2218 && id2 == 0x2218) {
   1.127 +        
   1.128 return 1;
   1.129      }
   1.130 -
   1.131 -    return 0;
   1.132 -}
   1.133 -
   1.134 -void NDS_EZF_SetShake(u8 pos)
   1.135 +    
   1.136 return 0;
   1.137 +
   1.138 }
   1.139 +
   1.140 void
   1.141 +NDS_EZF_SetShake(u8 pos) 
   1.142  {
   1.143 -    u16 data = ((pos%3)|0x00F0);
   1.144 -
   1.145 -    GBA_BUS[0x0FF0000] = 0xD200;
   1.146 -    GBA_BUS[0x0000000] = 0x1500;
   1.147 -    GBA_BUS[0x0010000] = 0xD200;
   1.148 -    GBA_BUS[0x0020000] = 0x1500;
   1.149 -    GBA_BUS[0x0F10000] = data;
   1.150 -    GBA_BUS[0x0FE0000] = 0x1500;
   1.151 +    u16 data = ((pos % 3) | 0x00F0);
   1.152 +    
   1.153 GBA_BUS[0x0FF0000] = 0xD200;
   1.154 +    
   1.155 GBA_BUS[0x0000000] = 0x1500;
   1.156 +    
   1.157 GBA_BUS[0x0010000] = 0xD200;
   1.158 +    
   1.159 GBA_BUS[0x0020000] = 0x1500;
   1.160 +    
   1.161 GBA_BUS[0x0F10000] = data;
   1.162 +    
   1.163 GBA_BUS[0x0FE0000] = 0x1500;
   1.164  
   1.165 -    GBA_BUS[0] = 0x0000; /* write any value for vibration. */
   1.166 -    GBA_BUS[0] = 0x0002;
   1.167 -}
   1.168 +    GBA_BUS[0] = 0x0000;        /* write any value for vibration. */
   1.169 +    GBA_BUS[0] = 0x0002;
   1.170 +
   1.171 }
   1.172  
   1.173  static int
   1.174  SDL_SYS_LogicError(void)
   1.175 @@ -130,11 +123,11 @@
   1.176  SDL_SYS_HapticInit(void)
   1.177  {
   1.178      int ret = 0;
   1.179 -    if(isRumbleInserted()) {
   1.180 +    if (isRumbleInserted()) {
   1.181          /* official rumble pak is present. */
   1.182          ret = 1;
   1.183          printf("debug: haptic present: nintendo\n");
   1.184 -    } else if(NDS_EZF_IsPresent()) {
   1.185 +    } else if (NDS_EZF_IsPresent()) {
   1.186          /* ezflash 3-in-1 pak is present. */
   1.187          ret = 1;
   1.188          printf("debug: haptic present: ezf3in1\n");
   1.189 @@ -150,11 +143,14 @@
   1.190  const char *
   1.191  SDL_SYS_HapticName(int index)
   1.192  {
   1.193 -    if(nds_haptic) {
   1.194 -        switch(nds_haptic->hwdata->type) {
   1.195 -            case OFFICIAL: return "Nintendo DS Rumble Pak";
   1.196 -            case EZF3IN1: return "EZFlash 3-in-1 Rumble";
   1.197 -            default: return NULL;
   1.198 +    if (nds_haptic) {
   1.199 +        switch (nds_haptic->hwdata->type) {
   1.200 +        case OFFICIAL:
   1.201 +            return "Nintendo DS Rumble Pak";
   1.202 +        case EZF3IN1:
   1.203 +            return "EZFlash 3-in-1 Rumble";
   1.204 +        default:
   1.205 +            return NULL;
   1.206          }
   1.207      }
   1.208      return NULL;
   1.209 @@ -164,12 +160,12 @@
   1.210  int
   1.211  SDL_SYS_HapticOpen(SDL_Haptic * haptic)
   1.212  {
   1.213 -    if(!haptic) {
   1.214 +    if (!haptic) {
   1.215          return -1;
   1.216      }
   1.217  
   1.218      haptic->hwdata = SDL_malloc(sizeof(NDS_HapticData));
   1.219 -    if(!haptic->hwdata) {
   1.220 +    if (!haptic->hwdata) {
   1.221          SDL_OutOfMemory();
   1.222          return -1;
   1.223      }
   1.224 @@ -179,10 +175,10 @@
   1.225  
   1.226      /* determine what is here, if anything */
   1.227      haptic->hwdata->type = NONE;
   1.228 -    if(isRumbleInserted()) {
   1.229 +    if (isRumbleInserted()) {
   1.230          /* official rumble pak is present. */
   1.231          haptic->hwdata->type = OFFICIAL;
   1.232 -    } else if(NDS_EZF_IsPresent()) {
   1.233 +    } else if (NDS_EZF_IsPresent()) {
   1.234          /* ezflash 3-in-1 pak is present. */
   1.235          haptic->hwdata->type = EZF3IN1;
   1.236          NDS_EZF_ChipReset();
   1.237 @@ -213,7 +209,7 @@
   1.238  int
   1.239  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
   1.240  {
   1.241 -    /*SDL_SYS_LogicError();*/
   1.242 +    /*SDL_SYS_LogicError(); */
   1.243      return -1;
   1.244  }
   1.245  
     2.1 --- a/src/joystick/nds/SDL_sysjoystick.c	Sat Sep 06 00:10:16 2008 +0000
     2.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Sat Sep 06 04:31:34 2008 +0000
     2.3 @@ -44,7 +44,8 @@
     2.4  int
     2.5  SDL_SYS_JoystickInit(void)
     2.6  {
     2.7 -    SDL_numjoysticks = 1;
     2.8     return (1);
     2.9 +    SDL_numjoysticks = 1;
    2.10 +    
    2.11 return (1);
    2.12  }
    2.13  
    2.14  /* Function to get the device-dependent name of a joystick */
    2.15 @@ -78,14 +79,14 @@
    2.16   * but instead should call SDL_PrivateJoystick*() to deliver events
    2.17   * and update joystick device state.
    2.18   */
    2.19 -void
    2.20 +    void
    2.21  SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    2.22  {
    2.23      u32 keysd, keysu;
    2.24      int magnitude = 16384;
    2.25      
    2.26 -    /*scanKeys(); - this is done in PumpEvents, because touch uses it too */
    2.27 -    keysd = keysDown();
    2.28 +        /*scanKeys(); - this is done in PumpEvents, because touch uses it too */ 
    2.29 +        keysd = keysDown();
    2.30      keysu = keysUp();
    2.31  
    2.32      if ((keysd & KEY_UP)) {
    2.33 @@ -100,58 +101,58 @@
    2.34      if ((keysd & KEY_RIGHT)) {
    2.35          SDL_PrivateJoystickAxis(joystick, 0, magnitude);
    2.36      }
    2.37 -
    2.38     if ((keysu & (KEY_UP | KEY_DOWN))) {
    2.39 +    
    2.40 if ((keysu & (KEY_UP | KEY_DOWN))) {
    2.41          SDL_PrivateJoystickAxis(joystick, 1, 0);
    2.42      }
    2.43 -
    2.44     if ((keysu & (KEY_LEFT | KEY_RIGHT))) {
    2.45 +    
    2.46 if ((keysu & (KEY_LEFT | KEY_RIGHT))) {
    2.47          SDL_PrivateJoystickAxis(joystick, 0, 0);
    2.48      }
    2.49 -    
    2.50     if ((keysd & KEY_A)) {
    2.51 +    
    2.52 if ((keysd & KEY_A)) {
    2.53          SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
    2.54      }
    2.55 -    
    2.56     if ((keysd & KEY_B)) {
    2.57 +    
    2.58 if ((keysd & KEY_B)) {
    2.59          SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED);
    2.60      }
    2.61 -    
    2.62     if ((keysd & KEY_X)) {
    2.63 +    
    2.64 if ((keysd & KEY_X)) {
    2.65          SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED);
    2.66      }
    2.67 -    
    2.68     if ((keysd & KEY_Y)) {
    2.69 +    
    2.70 if ((keysd & KEY_Y)) {
    2.71          SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED);
    2.72      }
    2.73 -    
    2.74     if ((keysd & KEY_L)) {
    2.75 +    
    2.76 if ((keysd & KEY_L)) {
    2.77          SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED);
    2.78      }
    2.79 -    
    2.80     if ((keysd & KEY_R)) {
    2.81 +    
    2.82 if ((keysd & KEY_R)) {
    2.83          SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED);
    2.84      }
    2.85 -    
    2.86     if ((keysd & KEY_SELECT)) {
    2.87 +    
    2.88 if ((keysd & KEY_SELECT)) {
    2.89          SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED);
    2.90      }
    2.91 -    
    2.92     if ((keysd & KEY_START)) {
    2.93 +    
    2.94 if ((keysd & KEY_START)) {
    2.95          SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED);
    2.96      }
    2.97 -    
    2.98     if ((keysu & KEY_A)) {
    2.99 +    
   2.100 if ((keysu & KEY_A)) {
   2.101          SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
   2.102      }
   2.103 -    
   2.104     if ((keysu & KEY_B)) {
   2.105 +    
   2.106 if ((keysu & KEY_B)) {
   2.107          SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED);
   2.108      }
   2.109 -    
   2.110     if ((keysu & KEY_X)) {
   2.111 +    
   2.112 if ((keysu & KEY_X)) {
   2.113          SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED);
   2.114      }
   2.115 -    
   2.116     if ((keysu & KEY_Y)) {
   2.117 +    
   2.118 if ((keysu & KEY_Y)) {
   2.119          SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED);
   2.120      }
   2.121 -    
   2.122     if ((keysu & KEY_L)) {
   2.123 +    
   2.124 if ((keysu & KEY_L)) {
   2.125          SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED);
   2.126      }
   2.127 -    
   2.128     if ((keysu & KEY_R)) {
   2.129 +    
   2.130 if ((keysu & KEY_R)) {
   2.131          SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED);
   2.132      }
   2.133 -    
   2.134     if ((keysu & KEY_SELECT)) {
   2.135 +    
   2.136 if ((keysu & KEY_SELECT)) {
   2.137          SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED);
   2.138      }
   2.139 -    
   2.140     if ((keysu & KEY_START)) {
   2.141 +    
   2.142 if ((keysu & KEY_START)) {
   2.143          SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED);
   2.144      }
   2.145  
   2.146 }
   2.147 @@ -169,4 +170,3 @@
   2.148  }
   2.149  
   2.150  #endif /* SDL_JOYSTICK_NDS */
   2.151 -
     3.1 --- a/src/video/nds/SDL_ndsevents.c	Sat Sep 06 00:10:16 2008 +0000
     3.2 +++ b/src/video/nds/SDL_ndsevents.c	Sat Sep 06 04:31:34 2008 +0000
     3.3 @@ -47,8 +47,8 @@
     3.4      }
     3.5      if (keysHeld() & KEY_TOUCH) {
     3.6          touchPosition t = touchReadXY();
     3.7 -        SDL_SendMouseMotion(0, 0, t.px, t.py, 1); /* last arg is pressure,
     3.8 -                                                     hardcoded 1 for now */
     3.9 +        SDL_SendMouseMotion(0, 0, t.px, t.py, 1);       /* last arg is pressure,
    3.10 +                                                           hardcoded 1 for now */
    3.11      }
    3.12  }
    3.13  
     4.1 Binary file test/nds-test-progs/sprite2/icon.bmp has changed
     5.1 --- a/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Sep 06 00:10:16 2008 +0000
     5.2 +++ b/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Sep 06 04:31:34 2008 +0000
     5.3 @@ -7,8 +7,6 @@
     5.4  #include <fat.h>
     5.5  #include "common.h"
     5.6  
     5.7 -#include "icon_bmp_bin.h"
     5.8 -
     5.9  #define NUM_SPRITES	10
    5.10  #define MAX_SPEED 	1
    5.11  
    5.12 @@ -184,66 +182,7 @@
    5.13      if (!state) {
    5.14          return 1;
    5.15      }
    5.16 -    for (i = 1; i < argc;) {
    5.17 -        int consumed;
    5.18  
    5.19 -        consumed = CommonArg(state, i);
    5.20 -        if (consumed == 0) {
    5.21 -            consumed = -1;
    5.22 -            if (SDL_strcasecmp(argv[i], "--blend") == 0) {
    5.23 -                if (argv[i + 1]) {
    5.24 -                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
    5.25 -                        blendMode = SDL_TEXTUREBLENDMODE_NONE;
    5.26 -                        consumed = 2;
    5.27 -                    } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
    5.28 -                        blendMode = SDL_TEXTUREBLENDMODE_MASK;
    5.29 -                        consumed = 2;
    5.30 -                    } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
    5.31 -                        blendMode = SDL_TEXTUREBLENDMODE_BLEND;
    5.32 -                        consumed = 2;
    5.33 -                    } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
    5.34 -                        blendMode = SDL_TEXTUREBLENDMODE_ADD;
    5.35 -                        consumed = 2;
    5.36 -                    } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
    5.37 -                        blendMode = SDL_TEXTUREBLENDMODE_MOD;
    5.38 -                        consumed = 2;
    5.39 -                    }
    5.40 -                }
    5.41 -            } else if (SDL_strcasecmp(argv[i], "--scale") == 0) {
    5.42 -                if (argv[i + 1]) {
    5.43 -                    if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
    5.44 -                        scaleMode = SDL_TEXTURESCALEMODE_NONE;
    5.45 -                        consumed = 2;
    5.46 -                    } else if (SDL_strcasecmp(argv[i + 1], "fast") == 0) {
    5.47 -                        scaleMode = SDL_TEXTURESCALEMODE_FAST;
    5.48 -                        consumed = 2;
    5.49 -                    } else if (SDL_strcasecmp(argv[i + 1], "slow") == 0) {
    5.50 -                        scaleMode = SDL_TEXTURESCALEMODE_SLOW;
    5.51 -                        consumed = 2;
    5.52 -                    } else if (SDL_strcasecmp(argv[i + 1], "best") == 0) {
    5.53 -                        scaleMode = SDL_TEXTURESCALEMODE_BEST;
    5.54 -                        consumed = 2;
    5.55 -                    }
    5.56 -                }
    5.57 -            } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
    5.58 -                cycle_color = SDL_TRUE;
    5.59 -                consumed = 1;
    5.60 -            } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
    5.61 -                cycle_alpha = SDL_TRUE;
    5.62 -                consumed = 1;
    5.63 -            } else if (SDL_isdigit(*argv[i])) {
    5.64 -                num_sprites = SDL_atoi(argv[i]);
    5.65 -                consumed = 1;
    5.66 -            }
    5.67 -        }
    5.68 -        if (consumed < 0) {
    5.69 -            fprintf(stderr,
    5.70 -                    "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n",
    5.71 -                    argv[0], CommonUsage(state));
    5.72 -            quit(1);
    5.73 -        }
    5.74 -        i += consumed;
    5.75 -    }
    5.76      if (!CommonInit(state)) {
    5.77          quit(2);
    5.78      }
    5.79 @@ -259,8 +198,9 @@
    5.80          SDL_SelectRenderer(state->windows[i]);
    5.81          SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
    5.82      }
    5.83 -    if (LoadSprite2(icon_bmp_bin, icon_bmp_bin_size) < 0) {
    5.84 -        printf("errored.\n");
    5.85 +    if (LoadSprite("icon.bmp") < 0) {
    5.86 +        printf("\nerrored.\n");
    5.87 +        while (1);
    5.88          quit(2);
    5.89      }
    5.90