-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
166 lines (138 loc) · 4.23 KB
/
main.c
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
/*
Hello World example made by Aurelio Mannara for libctru
This code was modified for the last time on: 12/12/2014 21:00 UTC+1
*/
#include <3ds.h>
#include <stdio.h>
#include <memory.h>
#include <inttypes.h>
static void pause(u32 key) {
// Main loop
while (aptMainLoop())
{
svcSleepThread(1000000);
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown() | hidKeysDownRepeat();
if (key) {
if (kDown & key) break; // break in order to return to hbmenu
} else {
if (kDown != 0) break;
}
// Flush and swap framebuffers
gfxFlushBuffers();
gfxSwapBuffers();
//Wait for VBlank
gspWaitForVBlank();
}
}
#define BUF_COUNT (0x10000)
static u32 src[BUF_COUNT];
static u32 dst[BUF_COUNT];
static void clearDst(void) {
memset(dst, 0, sizeof(dst));
svcInvalidateProcessDataCache(CUR_PROCESS_HANDLE, (u32)dst, sizeof(dst));
}
static void testAndPrintResult(void) {
for (u32 i = 0; i < BUF_COUNT; ++i) {
src[i] = i;
}
svcInvalidateProcessDataCache(CUR_PROCESS_HANDLE, (u32)src, sizeof(src));
clearDst();
printf("src = { 0x%"PRIu32", 0x%"PRIu32", 0x%"PRIu32", 0x%"PRIu32", ... }\n", src[0], src[1], src[2], src[3]);
#define PITCH_FACTOR (2)
u32 burstSize = 0x10;
u32 transferSize = 0x100;
u32 pitch = transferSize * PITCH_FACTOR;
DmaConfig cfg = {
.channelId = -1,
.flags = DMACFG_WAIT_AVAILABLE | DMACFG_USE_SRC_CONFIG | DMACFG_USE_DST_CONFIG,
.srcCfg = {
.deviceId = -1,
.allowedAlignments = 15,
.burstSize = burstSize,
.burstStride = burstSize,
.transferSize = transferSize,
.transferStride = pitch,
},
.dstCfg = {
.deviceId = -1,
.allowedAlignments = 15,
.burstSize = burstSize,
.burstStride = burstSize,
.transferSize = transferSize,
.transferStride = transferSize,
},
};
printf(
"dma from src to dst with\n"
"transferSize = 0x%"PRIx32"\n"
"srcCfg.transferStride = 0x%"PRIx32"\n"
"dstCfg.transferStride = 0x%"PRIx32"\n", (u32)cfg.srcCfg.transferSize, (u32)cfg.srcCfg.transferStride, (u32)cfg.dstCfg.transferStride);
pause(0);
Handle hdma;
svcStartInterProcessDma(&hdma, CUR_PROCESS_HANDLE, (u32)dst, CUR_PROCESS_HANDLE, (u32)src, BUF_COUNT / PITCH_FACTOR, &cfg);
svcWaitSynchronization(hdma, -1);
svcCloseHandle(hdma);
printf("checking src at src[i * srcCfg.transferStride]\n");
printf(" for dst at dst[i * dstCfg.transferStride]\n");
printf("they should be equal\n");
pause(0);
for (u32 i = 1; i <= 0x10; ++i) {
u32 srcIdx = i * cfg.srcCfg.transferStride;
printf("src[0x%"PRIx32"] = 0x%"PRIx32" expected\n",
srcIdx,
src[srcIdx]
);
u32 dstIdx = i * cfg.dstCfg.transferStride;
printf("dst[0x%"PRIx32"] = 0x%"PRIx32" got\n",
dstIdx,
dst[dstIdx]
);
pause(0);
}
// switched case
clearDst();
printf("switching dstCfg. and srcCfg.transferStride\n");
cfg.srcCfg.transferStride = transferSize;
cfg.dstCfg.transferStride = pitch;
pause(0);
printf(
"dma from src to dst with\n"
"transferSize = 0x%"PRIx32"\n"
"srcCfg.transferStride = 0x%"PRIx32"\n"
"dstCfg.transferStride = 0x%"PRIx32"\n", (u32)cfg.srcCfg.transferSize, (u32)cfg.srcCfg.transferStride, (u32)cfg.dstCfg.transferStride);
pause(0);
svcStartInterProcessDma(&hdma, CUR_PROCESS_HANDLE, (u32)dst, CUR_PROCESS_HANDLE, (u32)src, BUF_COUNT / PITCH_FACTOR, &cfg);
svcWaitSynchronization(hdma, -1);
svcCloseHandle(hdma);
printf("checking src at src[i * dstCfg.transferStride]\n");
printf(" for dst at dst[i * srcCfg.transferStride]\n");
printf("they should be NOT equal\n");
pause(0);
for (u32 i = 1; i <= 0x10; ++i) {
u32 srcIdx = i * cfg.dstCfg.transferStride;
printf("src[0x%"PRIx32"] = 0x%"PRIx32" expected\n",
srcIdx,
src[srcIdx]
);
u32 dstIdx = i * cfg.srcCfg.transferStride;
printf("dst[0x%"PRIx32"] = 0x%"PRIx32" got\n",
dstIdx,
dst[dstIdx]
);
pause(0);
}
}
int main(int argc, char **argv)
{
gfxInitDefault();
//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
consoleInit(GFX_TOP, NULL);
testAndPrintResult();
printf("Press Start to exit.");
pause(KEY_START);
gfxExit();
return 0;
}