summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/libndsfpc/src/nds/dma.inc
blob: e00f2b9985b669f49e8343f45915f3056492dbbb (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
{$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);

function DMA_SRC(n: cint): pcuint32; inline;
function DMA_DEST(n: cint): pcuint32; inline;
function DMA_CR(n: cint): pcuint32; inline;
{$ifdef ARM9}
function DMA_FILL(n: cint): pcuint32; inline;
{$endif ARM9}


// 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_START_FIFO  = (7 shl 27);


  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}

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(value: cuint32; dest: pointer; size: cuint32); inline;
procedure dmaFillHalfWords(value: cuint16; dest: pointer; size: cuint32); inline;
function dmaBusy(channel: cuint8): cint; inline; 

{$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;

{$ifdef ARM9}
function DMA_FILL(n: cint): pcuint32; inline;
begin
  DMA_FILL := pcuint32($040000E0 + (n * 4));
end;
{$endif ARM9}

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(value: cuint32; dest: pointer; size: cuint32); inline;
begin
  {$ifdef ARM7}	         
    pcuint32($027FFE04)^ := value;	         
    DMA_SRC(3)^ := $027FFE04;	 
  {$else ARM7}
    DMA_FILL(3)^ := value;
//    pcuint32(DMA_SRC(3)^) := pcuint32(DMA_FILL(3));
    DMA_SRC(3)^ := cuint32(DMA_FILL(3));
  {$endif ARM7}
	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(value: cuint16; dest: pointer; size: cuint32); inline;
begin
  {$ifdef ARM7}
    pcuint32($027FFE04)^ := value;	         
    DMA_SRC(3)^ := $027FFE04;	 
  {$else ARM7}
    DMA_FILL(3)^ := value;
//    pcuint32(DMA_SRC(3)^) := pcuint32(DMA_FILL(3));
    DMA_SRC(3)^ := cuint32(DMA_FILL(3));
  {$endif ARM7}
	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}