summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/src/nds/dma.inc
blob: 4118bb78f86b6b8b404d8613ef3fbb4e0ed37268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
(*
  $Id: dma.inc 25 2007-12-10 21:06:46Z p4p3r0 $
  ------------------------------------------------------------------------------
  	Copyright (C) 2005
  		Jason Rogers (dovoto)
  		Dave Murphy (WinterMute)
  	
  	This software is provided 'as-is', without any express or implied
  	warranty.  In no event will the authors be held liable for any
  	damages arising from the use of this software.
  	
  	Permission is granted to anyone to use this software for any
  	purpose, including commercial applications, and to alter it and
  	redistribute it freely, subject to the following restrictions:
  	
  	1.	The origin of this software must not be misrepresented; you
  		must not claim that you wrote the original software. If you use
  		this software in a product, an acknowledgment in the product
  		documentation would be appreciated but is not required.
  	
  	2.	Altered source versions must be plainly marked as such, and
  		must not be misrepresented as being the original software.
  	
  	3.	This notice may not be removed or altered from any source
  		distribution.
  ------------------------------------------------------------------------------
    
    
  Conversion by Legolas (http://itaprogaming.free.fr) for freepascal compiler
  (http://www.freepascal.org)
   
  Copyright (C) 2006  Francesco Lombardi
  Check http://sourceforge.net/projects/libndsfpc for updates
   
  ------------------------------------------------------------------------------

  $Log$

*)



{$ifdef NDS_INTERFACE}
const
  DMA0_SRC       : pcuint32 = pointer($040000B0);
  DMA0_DEST      : pcuint32 = pointer($040000B4);
  DMA0_CR        : pcuint32 = pointer($040000B8);

  DMA1_SRC       : pcuint32 = pointer($040000BC);
  DMA1_DEST      : pcuint32 = pointer($040000C0);
  DMA1_CR        : pcuint32 = pointer($040000C4);

  DMA2_SRC       : pcuint32 = pointer($040000C8);
  DMA2_DEST      : pcuint32 = pointer($040000CC);
  DMA2_CR        : pcuint32 = pointer($040000D0);

  DMA3_SRC       : pcuint32 = pointer($040000D4);
  DMA3_DEST      : pcuint32 = pointer($040000D8);
  DMA3_CR        : pcuint32 = pointer($040000DC);
{$endif NDS_INTERFACE}

{$ifdef NDS_IMPLEMENTATION}
function DMA_SRC(n: cint): pcuint32; inline;
begin
  DMA_SRC := pcuint32($040000B0 + (n * 12));
end;

function DMA_DEST(n: cint): pcuint32; inline;
begin
  DMA_DEST := pcuint32($040000B4 + (n * 12));
end;

function DMA_CR(n: cint): pcuint32; inline;
begin
  DMA_CR := pcuint32($040000B8 + (n * 12));
end;
{$endif NDS_IMPLEMENTATION}

{$ifdef NDS_INTERFACE}
// DMA control register contents
// The defaults are 16-bit, increment source/dest addresses, no irq
const
  DMA_ENABLE   = (1 shl 31); //BIT(31);
  DMA_BUSY     = (1 shl 31); //BIT(31);
  DMA_IRQ_REQ  = (1 shl 30); //BIT(30);

  DMA_START_NOW   = 0;
  DMA_START_CARD  = (5 shl 27);

{$ifdef ARM7}
  DMA_START_VBL = (1 shl 27); //BIT(27);
{$endif ARM7}

{$ifdef ARM9}
  DMA_START_HBL  = (1 shl 28); //BIT(28);
  DMA_START_VBL  = (1 shl 27); //BIT(27);
  DMA_START_FIFO  = (7 shl 27);
  DMA_DISP_FIFO   = (4 shl 27);
{$endif ARM9}

  DMA_16_BIT      = 0; 
  DMA_32_BIT      = (1 shl 26); //BIT(26);

  DMA_REPEAT      = (1 shl 25); //BIT(25);

  DMA_SRC_INC     = (0); 
  DMA_SRC_DEC     = (1 shl 23); //BIT(23);
  DMA_SRC_FIX     = (1 shl 24); //BIT(24); 

  DMA_DST_INC     = (0); 
  DMA_DST_DEC     = (1 shl 21); //BIT(21); 
  DMA_DST_FIX     = (1 shl 22); //BIT(22);
  DMA_DST_RESET   = (3 shl 21); 

  DMA_COPY_WORDS      = (DMA_ENABLE or DMA_32_BIT or DMA_START_NOW); 
  DMA_COPY_HALFWORDS  = (DMA_ENABLE or DMA_16_BIT or DMA_START_NOW); 
{$ifdef ARM9}
  DMA_FIFO            = (DMA_ENABLE or DMA_32_BIT or DMA_DST_FIX or DMA_START_FIFO); 
{$endif ARM9}
{$endif NDS_INTERFACE}


{$ifdef NDS_IMPLEMENTATION}

procedure dmaCopyWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline; 
begin
	DMA_SRC(channel)^ := cuint32(src);
	DMA_DEST(channel)^ := cuint32(dest);
	DMA_CR(channel)^ := DMA_COPY_WORDS or (size shr 2);
	while (DMA_CR(channel)^ and DMA_BUSY) <> 0 do;
end;

procedure dmaCopyHalfWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
begin
	DMA_SRC(channel)^ := cuint32(src);
	DMA_DEST(channel)^ := cuint32(dest);
	DMA_CR(channel)^ := DMA_COPY_HALFWORDS or (size shr 1);
	while (DMA_CR(channel)^ and DMA_BUSY) <> 0 do;
end;

procedure dmaCopy(const source: pointer; dest: pointer; size: cuint32); inline;
begin
	DMA_SRC(3)^ := cuint32(source);
	DMA_DEST(3)^ := cuint32(dest);
	DMA_CR(3)^ := DMA_COPY_HALFWORDS or (size shr 1);
	while (DMA_CR(3)^ and DMA_BUSY <> 0) do;
end;

procedure dmaCopyWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline; 
begin
	DMA_SRC(channel)^ := cuint32(src);
	DMA_DEST(channel)^ := cuint32(dest);
	DMA_CR(channel)^ := DMA_COPY_WORDS or (size shr 2);
end;

procedure dmaCopyHalfWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
begin
	DMA_SRC(channel)^ := cuint32(src);
	DMA_DEST(channel)^ := cuint32(dest);
	DMA_CR(channel)^ := DMA_COPY_HALFWORDS or (size shr 1);
end;

procedure dmaCopyAsynch(const source: pointer; dest: pointer; size: cuint32); inline;
begin
	DMA_SRC(3)^ := cuint32(source);
	DMA_DEST(3)^ := cuint32(dest);
	DMA_CR(3)^ := DMA_COPY_HALFWORDS or (size shr 1);
end;

procedure dmaFillWords(const src: pointer; dest: pointer; size: cuint32); inline;
begin
	DMA_SRC(3)^ := cuint32(src);
	DMA_DEST(3)^ := cuint32(dest);
	DMA_CR(3)^ := DMA_SRC_FIX or DMA_COPY_WORDS or (size shr 2);
	while (DMA_CR(3)^ and DMA_BUSY) <> 0 do;
end;

procedure dmaFillHalfWords(const src: pointer; dest: pointer; size: cuint32); inline;
begin
	DMA_SRC(3)^ := cuint32(src);
	DMA_DEST(3)^ := cuint32(dest);
	DMA_CR(3)^ := DMA_SRC_FIX or DMA_COPY_HALFWORDS or (size shr 1);
	while (DMA_CR(3)^ and DMA_BUSY) <> 0 do;
end;

function dmaBusy(channel: cuint8): cint; inline; 
begin
	dmaBusy := (DMA_CR(channel)^ and DMA_BUSY) shr 31;
end;
{$endif NDS_IMPLEMENTATION}


{$ifdef NDS_INTERFACE}
function DMA_SRC(n: cint): pcuint32; inline;
function DMA_DEST(n: cint): pcuint32; inline;
function DMA_CR(n: cint): pcuint32; inline;
procedure dmaCopyWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline; 
procedure dmaCopyHalfWords(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
procedure dmaCopy(const source: pointer; dest: pointer; size: cuint32); inline;
procedure dmaCopyWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline; 
procedure dmaCopyHalfWordsAsynch(channel: cuint8; const src: pointer; dest: pointer; size: cuint32); inline;
procedure dmaCopyAsynch(const source: pointer; dest: pointer; size: cuint32); inline;
procedure dmaFillWords(const src: pointer; dest: pointer; size: cuint32); inline;
procedure dmaFillHalfWords(const src: pointer; dest: pointer; size: cuint32); inline;
function dmaBusy(channel: cuint8): cint; inline; 
{$endif NDS_INTERFACE}