gba_sprites.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. (*
  2. gba_sprites.pas 18/06/2006 4.28.18
  3. ------------------------------------------------------------------------------
  4. This lib is a raw porting of libgba library for gba (you can find it at
  5. http://www.devkitpro.org).
  6. As this is a direct port from c, I'm pretty sure that something could not work
  7. as you expect. I am even more sure that this code could be written better, so
  8. if you think that I have made some mistakes or you have some better
  9. implemented functions, let me know [francky74 (at) gmail (dot) com]
  10. Enjoy!
  11. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  12. (http://www.freepascal.org)
  13. Copyright (C) 2006 Francesco Lombardi
  14. This library is free software; you can redistribute it and/or
  15. modify it under the terms of the GNU Lesser General Public
  16. License as published by the Free Software Foundation; either
  17. version 2.1 of the License, or (at your option) any later version.
  18. This library is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. Lesser General Public License for more details.
  22. You should have received a copy of the GNU Lesser General Public
  23. License along with this library; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  25. ------------------------------------------------------------------------------
  26. *)
  27. unit gba_sprites;
  28. {$i def.inc}
  29. interface
  30. uses
  31. gba_types, gba_regs;
  32. const
  33. OAM : POBJATTR = pointer($07000000);
  34. OBJ_BASE_ADR = pointer($06010000);
  35. BITMAP_OBJ_BASE_ADR = pointer($06014000);
  36. OBJ_ROT_SCALE_ON = (1 shl 8);
  37. OBJ_DISABLE = (1 shl 9);
  38. OBJ_DOUBLE = (1 shl 9);
  39. OBJ_MOSAIC = (1 shl 12);
  40. OBJ_256_COLOR = (1 shl 13);
  41. OBJ_16_COLOR = (0 shl 13);
  42. OBJ_HFLIP = (1 shl 12);
  43. OBJ_VFLIP = (1 shl 13);
  44. type
  45. SPRITE_SHAPES = (
  46. SQUARE,
  47. WIDE,
  48. TALL
  49. );
  50. TSpriteShapes = SPRITE_SHAPES;
  51. SPRITE_SIZECODE = (
  52. Sprite_8x8,
  53. Sprite_16x16,
  54. Sprite_32x32,
  55. Sprite_64x64,
  56. Sprite_16x8,
  57. Sprite_32x8,
  58. Sprite_32x16,
  59. Sprite_64x32,
  60. Sprite_8x16,
  61. Sprite_8x32,
  62. Sprite_16x32,
  63. Sprite_32x64
  64. );
  65. TSpriteSizeCode = SPRITE_SIZECODE;
  66. function ObjY(m: integer): integer; inline;
  67. function ObjMode(m: integer): integer; inline;
  68. function ObjShape(m: integer): integer; inline;
  69. function ObjX(m: integer): integer; inline;
  70. function ObjRotScale(m: integer): integer; inline;
  71. function ObjSize(m: integer): integer; inline;
  72. function ObjChar(m: integer): integer; inline;
  73. function ObjPriority(m: integer): integer; inline;
  74. function ObjPalette(m: integer): integer; inline;
  75. {$define ObjTranslucent := ObjMode(1)}
  76. {$define ObjObjWindow := ObjMode(2)}
  77. {$define ObjSquare := ObjShape(0)}
  78. {$define ObjWide := ObjShape(1)}
  79. {$define ObjTall := ObjShape(2)}
  80. implementation
  81. function ObjY(m: integer): integer; inline;
  82. begin
  83. ObjY := ((m) and $00ff);
  84. end;
  85. function ObjMode(m: integer): integer; inline;
  86. begin
  87. ObjMode := ((m) shl 10);
  88. end;
  89. function ObjShape(m: integer): integer; inline;
  90. begin
  91. ObjShape := ((m) shl 14);
  92. end;
  93. function ObjX(m: integer): integer; inline;
  94. begin
  95. ObjX := ((m) and $01ff);
  96. end;
  97. function ObjRotScale(m: integer): integer; inline;
  98. begin
  99. ObjRotScale := ((m) shl 9);
  100. end;
  101. function ObjSize(m: integer): integer; inline;
  102. begin
  103. ObjSize := ((m) shl 14);
  104. end;
  105. function ObjChar(m: integer): integer; inline;
  106. begin
  107. ObjChar := ((m) and $03ff);
  108. end;
  109. function ObjPriority(m: integer): integer; inline;
  110. begin
  111. ObjPriority := ((m) shl 10);
  112. end;
  113. function ObjPalette(m: integer): integer; inline;
  114. begin
  115. ObjPalette := ((m) shl 12);
  116. end;
  117. end.