gba_dma.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. (*
  2. gba_dma.pas 18/06/2006 4.18.32
  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_dma;
  28. {$i def.inc}
  29. interface
  30. uses
  31. gba_types, gba_regs;
  32. const
  33. DMA_SHIFT = 16;
  34. // destination control
  35. _DMA_DST_INC = ($0000 shl DMA_SHIFT);
  36. DMA_DST_DEC = ($0020 shl DMA_SHIFT);
  37. DMA_DST_FIX = ($0040 shl DMA_SHIFT);
  38. DMA_DST_RESET = ($0060 shl DMA_SHIFT);
  39. // source control
  40. _DMA_SRC_INC = ($0000 shl DMA_SHIFT);
  41. DMA_SRC_DEC = ($0080 shl DMA_SHIFT);
  42. DMA_SRC_FIX = ($0100 shl DMA_SHIFT);
  43. DMA_SRC_RESET = ($0180 shl DMA_SHIFT);
  44. DMA_REPEAT = ($0200 shl DMA_SHIFT);
  45. // chunks
  46. _DMA_16 = ($0000 shl DMA_SHIFT);
  47. DMA_32 = ($0400 shl DMA_SHIFT);
  48. // timing
  49. _DMA_AT_NOW = ($0000 shl DMA_SHIFT);
  50. DMA_AT_VBLANK = ($1000 shl DMA_SHIFT);
  51. DMA_AT_HBLANK = ($2000 shl DMA_SHIFT);
  52. DMA_AT_FIFO = ($3000 shl DMA_SHIFT); // for sound ( DMA 1 & 2)
  53. DMA_AT_REFRESH = ($3000 shl DMA_SHIFT); // for video ( DMA 3)
  54. DMA_IRQ = ($4000 shl DMA_SHIFT);
  55. DMA_ON = ($8000 shl DMA_SHIFT);
  56. // I want it NOW!
  57. DMA_NOW = DMA_ON or _DMA_AT_NOW;
  58. DMA_16NOW = DMA_NOW or _DMA_16;
  59. DMA_32NOW = DMA_NOW or DMA_32;
  60. // copies
  61. DMA_CPY16 = DMA_NOW or _DMA_16;
  62. DMA_CPY32 = DMA_NOW or DMA_32;
  63. // fills
  64. DMA_FILL16 = DMA_NOW or DMA_SRC_FIX or _DMA_16;
  65. DMA_FILL32 = DMA_NOW or DMA_SRC_FIX or DMA_32;
  66. DMA_TRANSFER_ON = (1 shl 15);
  67. DMA_TRANSFER_OFF = (0 shl 15);
  68. DMA_INTR_ON = (1 shl 14);
  69. DMA_INTR_OFF = (0 shl 14);
  70. DMA_TIMING_NOW = (0 shl 12);
  71. DMA_TIMING_VBLANK = (1 shl 12);
  72. DMA_TIMING_HBLANK = (2 shl 12);
  73. DMA_TIMING_FIFO = (3 shl 12);
  74. DMA_TIMING_DRAWLINE = (3 shl 12);
  75. DMA_ROM_REQUEST = (1 shl 11);
  76. DMA_SIZE_16 = (0 shl 10);
  77. DMA_SIZE_32 = (1 shl 10);
  78. DMA_REPEAT_ON = (1 shl 9);
  79. DMA_REPEAT_OFF = (0 shl 9);
  80. DMA_SAD_INC = (0 shl 7);
  81. DMA_SAD_DEC = (1 shl 7);
  82. DMA_SAD_FIX = (2 shl 7);
  83. DMA_DAD_INC = (0 shl 5);
  84. DMA_DAD_DEC = (1 shl 5);
  85. DMA_DAD_FIX = (2 shl 5);
  86. DMA_DAD_RESET = (3 shl 5);
  87. procedure DMA0Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  88. procedure DMA1Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  89. procedure DMA2Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  90. procedure DMA3Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  91. implementation
  92. procedure DMA0Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  93. begin
  94. REG_DM0SAD^ := dword(sad);
  95. REG_DM0DAD^ := dword(dad);
  96. REG_DM0CNT^ := size or mode;
  97. end;
  98. procedure DMA1Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  99. begin
  100. REG_DM1SAD^ := dword(sad);
  101. REG_DM1DAD^ := dword(dad);
  102. REG_DM1CNT^ := size or mode;
  103. end;
  104. procedure DMA2Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  105. begin
  106. REG_DM2SAD^ := dword(sad);
  107. REG_DM2DAD^ := dword(dad);
  108. REG_DM2CNT^ := size or mode;
  109. end;
  110. procedure DMA3Copy(sad: pword; dad: pword; size: dword; mode: dword); inline;
  111. begin
  112. REG_DM3SAD^ := dword(sad);
  113. REG_DM3DAD^ := dword(dad);
  114. REG_DM3CNT^ := size or mode;
  115. end;
  116. end.