dma.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. (*
  2. $Id: dma.inc 25 2007-12-10 21:06:46Z p4p3r0 $
  3. ------------------------------------------------------------------------------
  4. Copyright (C) 2005
  5. Jason Rogers (dovoto)
  6. Dave Murphy (WinterMute)
  7. This software is provided 'as-is', without any express or implied
  8. warranty. In no event will the authors be held liable for any
  9. damages arising from the use of this software.
  10. Permission is granted to anyone to use this software for any
  11. purpose, including commercial applications, and to alter it and
  12. redistribute it freely, subject to the following restrictions:
  13. 1. The origin of this software must not be misrepresented; you
  14. must not claim that you wrote the original software. If you use
  15. this software in a product, an acknowledgment in the product
  16. documentation would be appreciated but is not required.
  17. 2. Altered source versions must be plainly marked as such, and
  18. must not be misrepresented as being the original software.
  19. 3. This notice may not be removed or altered from any source
  20. distribution.
  21. ------------------------------------------------------------------------------
  22. Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  23. (http://www.freepascal.org)
  24. Copyright (C) 2006 Francesco Lombardi
  25. Check http://sourceforge.net/projects/libndsfpc for updates
  26. ------------------------------------------------------------------------------
  27. $Log$
  28. *)
  29. {$ifdef NDS_INTERFACE}
  30. const
  31. DMA0_SRC : pcuint32 = pointer($040000B0);
  32. DMA0_DEST : pcuint32 = pointer($040000B4);
  33. DMA0_CR : pcuint32 = pointer($040000B8);
  34. DMA1_SRC : pcuint32 = pointer($040000BC);
  35. DMA1_DEST : pcuint32 = pointer($040000C0);
  36. DMA1_CR : pcuint32 = pointer($040000C4);
  37. DMA2_SRC : pcuint32 = pointer($040000C8);
  38. DMA2_DEST : pcuint32 = pointer($040000CC);
  39. DMA2_CR : pcuint32 = pointer($040000D0);
  40. DMA3_SRC : pcuint32 = pointer($040000D4);
  41. DMA3_DEST : pcuint32 = pointer($040000D8);
  42. DMA3_CR : pcuint32 = pointer($040000DC);
  43. {$endif NDS_INTERFACE}
  44. {$ifdef NDS_IMPLEMENTATION}
  45. function DMA_SRC(n: cint): pcuint32; inline;
  46. begin
  47. DMA_SRC := pcuint32($040000B0 + (n * 12));
  48. end;
  49. function DMA_DEST(n: cint): pcuint32; inline;
  50. begin
  51. DMA_DEST := pcuint32($040000B4 + (n * 12));
  52. end;
  53. function DMA_CR(n: cint): pcuint32; inline;
  54. begin
  55. DMA_CR := pcuint32($040000B8 + (n * 12));
  56. end;
  57. {$endif NDS_IMPLEMENTATION}
  58. {$ifdef NDS_INTERFACE}
  59. // DMA control register contents
  60. // The defaults are 16-bit, increment source/dest addresses, no irq
  61. const
  62. DMA_ENABLE = (1 shl 31); //BIT(31);
  63. DMA_BUSY = (1 shl 31); //BIT(31);
  64. DMA_IRQ_REQ = (1 shl 30); //BIT(30);
  65. DMA_START_NOW = 0;
  66. DMA_START_CARD = (5 shl 27);
  67. {$ifdef ARM7}
  68. DMA_START_VBL = (1 shl 27); //BIT(27);
  69. {$endif ARM7}
  70. {$ifdef ARM9}
  71. DMA_START_HBL = (1 shl 28); //BIT(28);
  72. DMA_START_VBL = (1 shl 27); //BIT(27);
  73. DMA_START_FIFO = (7 shl 27);
  74. DMA_DISP_FIFO = (4 shl 27);
  75. {$endif ARM9}
  76. DMA_16_BIT = 0;
  77. DMA_32_BIT = (1 shl 26); //BIT(26);
  78. DMA_REPEAT = (1 shl 25); //BIT(25);
  79. DMA_SRC_INC = (0);
  80. DMA_SRC_DEC = (1 shl 23); //BIT(23);
  81. DMA_SRC_FIX = (1 shl 24); //BIT(24);
  82. DMA_DST_INC = (0);
  83. DMA_DST_DEC = (1 shl 21); //BIT(21);
  84. DMA_DST_FIX = (1 shl 22); //BIT(22);
  85. DMA_DST_RESET = (3 shl 21);
  86. DMA_COPY_WORDS = (DMA_ENABLE or DMA_32_BIT or DMA_START_NOW);
  87. DMA_COPY_HALFWORDS = (DMA_ENABLE or DMA_16_BIT or DMA_START_NOW);
  88. {$ifdef ARM9}
  89. DMA_FIFO = (DMA_ENABLE or DMA_32_BIT or DMA_DST_FIX or DMA_START_FIFO);
  90. {$endif ARM9}
  91. {$endif NDS_INTERFACE}
  92. {$ifdef NDS_IMPLEMENTATION}
  93. procedure dmaCopyWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  94. begin
  95. DMA_SRC(channel)^ := cuint32(src);
  96. DMA_DEST(channel)^ := cuint32(dest);
  97. DMA_CR(channel)^ := DMA_COPY_WORDS or (size shr 2);
  98. while (DMA_CR(channel)^ and DMA_BUSY) <> 0 do;
  99. end;
  100. procedure dmaCopyHalfWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  101. begin
  102. DMA_SRC(channel)^ := cuint32(src);
  103. DMA_DEST(channel)^ := cuint32(dest);
  104. DMA_CR(channel)^ := DMA_COPY_HALFWORDS or (size shr 1);
  105. while (DMA_CR(channel)^ and DMA_BUSY) <> 0 do;
  106. end;
  107. procedure dmaCopy(const source: pointer; dest: pointer; size: cuint32); inline;
  108. begin
  109. DMA_SRC(3)^ := cuint32(source);
  110. DMA_DEST(3)^ := cuint32(dest);
  111. DMA_CR(3)^ := DMA_COPY_HALFWORDS or (size shr 1);
  112. while (DMA_CR(3)^ and DMA_BUSY <> 0) do;
  113. end;
  114. procedure dmaCopyWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  115. begin
  116. DMA_SRC(channel)^ := cuint32(src);
  117. DMA_DEST(channel)^ := cuint32(dest);
  118. DMA_CR(channel)^ := DMA_COPY_WORDS or (size shr 2);
  119. end;
  120. procedure dmaCopyHalfWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  121. begin
  122. DMA_SRC(channel)^ := cuint32(src);
  123. DMA_DEST(channel)^ := cuint32(dest);
  124. DMA_CR(channel)^ := DMA_COPY_HALFWORDS or (size shr 1);
  125. end;
  126. procedure dmaCopyAsynch(const source: pointer; dest: pointer; size: cuint32); inline;
  127. begin
  128. DMA_SRC(3)^ := cuint32(source);
  129. DMA_DEST(3)^ := cuint32(dest);
  130. DMA_CR(3)^ := DMA_COPY_HALFWORDS or (size shr 1);
  131. end;
  132. procedure dmaFillWords(const src: pointer; dest: pointer; size: cuint32); inline;
  133. begin
  134. DMA_SRC(3)^ := cuint32(src);
  135. DMA_DEST(3)^ := cuint32(dest);
  136. DMA_CR(3)^ := DMA_SRC_FIX or DMA_COPY_WORDS or (size shr 2);
  137. while (DMA_CR(3)^ and DMA_BUSY) <> 0 do;
  138. end;
  139. procedure dmaFillHalfWords(const src: pointer; dest: pointer; size: cuint32); inline;
  140. begin
  141. DMA_SRC(3)^ := cuint32(src);
  142. DMA_DEST(3)^ := cuint32(dest);
  143. DMA_CR(3)^ := DMA_SRC_FIX or DMA_COPY_HALFWORDS or (size shr 1);
  144. while (DMA_CR(3)^ and DMA_BUSY) <> 0 do;
  145. end;
  146. function dmaBusy(channel: cuint8): cint; inline;
  147. begin
  148. dmaBusy := (DMA_CR(channel)^ and DMA_BUSY) shr 31;
  149. end;
  150. {$endif NDS_IMPLEMENTATION}
  151. {$ifdef NDS_INTERFACE}
  152. function DMA_SRC(n: cint): pcuint32; inline;
  153. function DMA_DEST(n: cint): pcuint32; inline;
  154. function DMA_CR(n: cint): pcuint32; inline;
  155. procedure dmaCopyWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  156. procedure dmaCopyHalfWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  157. procedure dmaCopy(const source: pointer; dest: pointer; size: cuint32); inline;
  158. procedure dmaCopyWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  159. procedure dmaCopyHalfWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
  160. procedure dmaCopyAsynch(const source: pointer; dest: pointer; size: cuint32); inline;
  161. procedure dmaFillWords(const src: pointer; dest: pointer; size: cuint32); inline;
  162. procedure dmaFillHalfWords(const src: pointer; dest: pointer; size: cuint32); inline;
  163. function dmaBusy(channel: cuint8): cint; inline;
  164. {$endif NDS_INTERFACE}