sprite.inc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. (*
  2. $Id: sprite.inc 25 2007-12-10 21:06:46Z p4p3r0 $
  3. ------------------------------------------------------------------------------
  4. sprite.h -- definitions for DS sprites
  5. Copyright (C) 2007
  6. Liran Nuna (LiraNuna)
  7. Dave Murphy (WinterMute)
  8. This software is provided 'as-is', without any express or implied
  9. warranty. In no event will the authors be held liable for any
  10. damages arising from the use of this software.
  11. Permission is granted to anyone to use this software for any
  12. purpose, including commercial applications, and to alter it and
  13. redistribute it freely, subject to the following restrictions:
  14. 1. The origin of this software must not be misrepresented; you
  15. must not claim that you wrote the original software. If you use
  16. this software in a product, an acknowledgment in the product
  17. documentation would be appreciated but is not required.
  18. 2. Altered source versions must be plainly marked as such, and
  19. must not be misrepresented as being the original software.
  20. 3. This notice may not be removed or altered from any source
  21. distribution.
  22. ------------------------------------------------------------------------------
  23. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  24. (http://www.freepascal.org)
  25. Copyright (C) 2006 Francesco Lombardi
  26. Check http://sourceforge.net/projects/libndsfpc for updates
  27. ------------------------------------------------------------------------------
  28. $Log$
  29. *)
  30. {$ifndef ARM9}
  31. {$error Sprites are only available on the ARM9}
  32. {$endif ARM9}
  33. // Sprite control defines
  34. {$ifdef NDS_INTERFACE}
  35. // Attribute 0 consists of 8 bits of Y plus the following flags:
  36. const
  37. ATTR0_NORMAL = (0 shl 8);
  38. ATTR0_ROTSCALE = (1 shl 8);
  39. ATTR0_DISABLED = (2 shl 8);
  40. ATTR0_ROTSCALE_DOUBLE = (3 shl 8);
  41. ATTR0_TYPE_NORMAL = (0 shl 10);
  42. ATTR0_TYPE_BLENDED = (1 shl 10);
  43. ATTR0_TYPE_WINDOWED = (2 shl 10);
  44. ATTR0_BMP = (3 shl 10);
  45. ATTR0_MOSAIC = (1 shl 12);
  46. ATTR0_COLOR_16 = (0 shl 13); //16 color in tile mode...16 bit in bitmap mode
  47. ATTR0_COLOR_256 = (1 shl 13);
  48. ATTR0_SQUARE = (0 shl 14);
  49. ATTR0_WIDE = (1 shl 14);
  50. ATTR0_TALL = (2 shl 14);
  51. {$endif NDS_INTERFACE}
  52. {$ifdef NDS_IMPLEMENTATION}
  53. function OBJ_Y(m: cint): cint; inline;
  54. begin
  55. OBJ_Y := ((m) and $00ff);
  56. end;
  57. function ATTR1_ROTDATA(n: cint): cint; inline;
  58. begin
  59. ATTR1_ROTDATA := ((n) shl 9) // note: overlaps with flip flags
  60. end;
  61. {$endif NDS_IMPLEMENTATION}
  62. {$ifdef NDS_INTERFACE}
  63. const
  64. ATTR1_FLIP_X = (1 shl 12);
  65. ATTR1_FLIP_Y = (1 shl 13);
  66. ATTR1_SIZE_8 = (0 shl 14);
  67. ATTR1_SIZE_16 = (1 shl 14);
  68. ATTR1_SIZE_32 = (2 shl 14);
  69. ATTR1_SIZE_64 = (3 shl 14);
  70. {$endif NDS_INTERFACE}
  71. {$ifdef NDS_IMPLEMENTATION}
  72. function OBJ_X(m: cint): cint; inline;
  73. begin
  74. OBJ_X := ((m) and $01ff);
  75. end;
  76. // Atribute 2 consists of the following:
  77. function ATTR2_PRIORITY(n: cint): cint; inline;
  78. begin
  79. ATTR2_PRIORITY := ((n) shl 10);
  80. end;
  81. function ATTR2_PALETTE(n: cint): cint; inline;
  82. begin
  83. ATTR2_PALETTE := ((n) shl 12);
  84. end;
  85. function ATTR2_ALPHA(n: cint): cint; inline;
  86. begin
  87. ATTR2_ALPHA := ((n) shl 12);
  88. end;
  89. {$endif NDS_IMPLEMENTATION}
  90. {$ifdef NDS_INTERFACE}
  91. type
  92. TObjMode = (OBJMODE_NORMAL, OBJMODE_BLENDED, OBJMODE_WINDOWED, OBJMODE_BITMAP);
  93. TObjShape = (OBJSHAPE_SQUARE, OBJSHAPE_WIDE, OBJSHAPE_TALL, OBJSHAPE_FORBIDDEN);
  94. TObjSize = (OBJSIZE_8, OBJSIZE_16, OBJSIZE_32, OBJSIZE_64);
  95. TObjColMode = (OBJCOLOR_16, OBJCOLOR_256);
  96. TObjPriority = (OBJPRIORITY_0, OBJPRIORITY_1, OBJPRIORITY_2, OBJPRIORITY_3);
  97. sSpriteEntry = packed record
  98. case integer of
  99. 0: (st1: packed record
  100. st1: bitpacked record
  101. posY: 0..8;
  102. case integer of
  103. 0: (st1: bitpacked record
  104. __padding1: 0..1;
  105. isHidden: 0..1;
  106. __padding2: 0..6;
  107. end;
  108. );
  109. 1: (st2: bitpacked record
  110. isRotoscale: 0..1;
  111. rsDouble: 0..1;
  112. objMode: 0..2;
  113. isMosaic: 0..1;
  114. colMode: 0..1;
  115. objShape: 0..2;
  116. end;
  117. );
  118. end;
  119. st2: bitpacked record
  120. tileIdx: 0..10;
  121. objPriority: 0..2;
  122. objPal: 0..4;
  123. end;
  124. attribute3: cuint16;
  125. case integer of
  126. 0: (st1: bitpacked record
  127. posX: 0..9;
  128. __padding1: 0..7;
  129. end;
  130. );
  131. 1: (st2: bitpacked record
  132. __padding1: 0..8;
  133. case integer of
  134. 0: (st1: bitpacked record
  135. __padding1: 0..4;
  136. hFlip: 0..1;
  137. vFlip: 0..1;
  138. __padding2: 0..2;
  139. end;
  140. );
  141. 1: (st2: bitpacked record
  142. __padding1: 0..1;
  143. rsMatrixIdx: 0..5;
  144. objSize: 0..2;
  145. end;
  146. );
  147. end;
  148. );
  149. end;
  150. );
  151. 1: (st: packed record
  152. attribute: array [0..2] of cuint16;
  153. filler: cuint16;
  154. end;
  155. );
  156. end;
  157. SpriteEntry = sSpriteEntry;
  158. TSpriteEntry = sSpriteEntry;
  159. PSpriteEntry = ^sSpriteEntry;
  160. sSpriteRotation = record
  161. filler1: array [0..2] of cuint16;
  162. hdx: cint16;
  163. filler2: array [0..2] of cuint16;
  164. hdy: cint16;
  165. filler3: array [0..2] of cuint16;
  166. vdx: cint16;
  167. filler4: array [0..2] of cuint16;
  168. vdy: cint16;
  169. end;
  170. SpriteRotation = sSpriteRotation;
  171. TSpriteRotation = sSpriteRotation;
  172. pSpriteRotation = ^sSpriteRotation;
  173. const
  174. SPRITE_COUNT = 128;
  175. MATRIX_COUNT = 32;
  176. type
  177. TOAM = record
  178. case integer of
  179. 0: (spriteBuffer: array [0..SPRITE_COUNT-1] of TSpriteEntry;);
  180. 1: (matrixBuffer: array [0..MATRIX_COUNT-1] of TSpriteRotation;);
  181. end;
  182. {$endif NDS_INTERFACE}
  183. {$ifdef NDS_INTERFACE}
  184. function OBJ_Y(m: cint): cint; inline;
  185. function ATTR1_ROTDATA(n: cint): cint; inline;
  186. function OBJ_X(m: cint): cint; inline;
  187. function ATTR2_PRIORITY(n: cint): cint; inline;
  188. function ATTR2_PALETTE(n: cint): cint; inline;
  189. function ATTR2_ALPHA(n: cint): cint; inline;
  190. {$endif NDS_INTERFACE}