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
|
#include "NdevExi2A/exi2.h"
#include <revolution/os.h>
#define IS_TRUE(x) ((x) != FALSE)
#define IS_FALSE(x) !IS_TRUE(x)
#define ROUND_UP(x, align) (((x) + (align)-1) & (-(align)))
BOOL __EXI2Select() {
u32 regs = __EXIRegs[10];
regs &= 0x405;
regs |= 0xC0;
__EXIRegs[10] = regs;
return TRUE;
}
BOOL __EXI2Deselect() {
u32 regs = __EXIRegs[10];
__EXIRegs[10] = regs & 0x405;
return TRUE;
}
BOOL __EXI2Sync() {
while (__EXIRegs[13] & 0x1) {
}
return TRUE;
}
BOOL __EXI2Imm(u32* param_0, int width, int param_2) {
int i1; // r31
int i2; // r30
u32 var_r29;
u8* var_r28;
u32 var_r25;
if (param_2 != 0) {
var_r29 = 0;
for (i1 = 0; i1 < width; i1++) {
var_r29 |= ((u8*)param_0)[i1] << ((3 - i1) << 3);
}
__EXIRegs[14] = var_r29;
}
__EXIRegs[13] = 0x1 | (param_2 << 2) | ((width - 1) << 4);
__EXI2Sync();
if (param_2 == 0) {
var_r28 = (u8*)param_0;
var_r25 = __EXIRegs[14];
for (i2 = 0; i2 < width; i2++) {
*var_r28 = var_r25 >> ((3 - i2) << 3);
var_r28++;
}
}
return 1;
}
void __DBEXIInit() {
u8 sp08;
__OSMaskInterrupts(0x18000);
while ((__EXIRegs[13] & 0x1) == 0x1) {
};
__EXIRegs[10] = 0;
sp08 = 0xD4;
__DBEXIWriteReg(0xB4000000, &sp08, 1);
}
BOOL __DBEXIReadReg(u32 param_0, void* dst, u32 param_2) {
int is_failed = FALSE;
u32 val = 0;
is_failed |= IS_FALSE(__EXI2Select());
is_failed |= IS_FALSE(__EXI2Imm(¶m_0, 4, 1));
is_failed |= IS_FALSE(__EXI2Sync());
is_failed |= IS_FALSE(__EXI2Imm(&val, 4, 0));
is_failed |= IS_FALSE(__EXI2Sync());
is_failed |= IS_FALSE(__EXI2Deselect());
switch (param_2) {
case 1:
*(u8*)dst = val >> 24;
break;
case 2:
*(u16*)dst = (val >> 24) | ((val >> 8) & 0xff00);
break;
default:
*(u32*)dst = __EXISwap32(val);
break;
}
return IS_FALSE(is_failed);
}
BOOL __DBEXIWriteReg(u32 param_0, void* src, u32 width) {
int is_failed = FALSE;
u32 val;
switch (width) {
case 1:
val = (*(u8*)src & 0xFF) << 24;
break;
case 2:
val = ((*(u16*)src & 0xFF) << 24) | ((*(u16*)src & 0xff00) << 8);
break;
default:
val = __EXISwap32(*(u32*)src);
break;
}
is_failed |= IS_FALSE(__EXI2Select());
is_failed |= IS_FALSE(__EXI2Imm(¶m_0, 4, 1));
is_failed |= IS_FALSE(__EXI2Sync());
is_failed |= IS_FALSE(__EXI2Imm(&val, 4, 1));
is_failed |= IS_FALSE(__EXI2Sync());
is_failed |= IS_FALSE(__EXI2Deselect());
return IS_FALSE(is_failed);
}
BOOL __DBEXIReadRam(u32 param_0, void* dst, int count) {
int is_failed = FALSE;
u32 cur_val;
u32* cursor = (u32*)dst;
is_failed |= IS_FALSE(__EXI2Select());
is_failed |= IS_FALSE(__EXI2Imm(¶m_0, 4, 1));
is_failed |= IS_FALSE(__EXI2Sync());
while (count > 0) {
is_failed |= IS_FALSE(__EXI2Imm(&cur_val, 4, 0));
is_failed |= IS_FALSE(__EXI2Sync());
*cursor++ = cur_val;
count -= 4;
}
is_failed |= IS_FALSE(__EXI2Deselect());
return IS_FALSE(is_failed);
}
BOOL __DBEXIWriteRam(u32 param_0, void* src, int count) {
int is_failed = FALSE;
u32 cur_val;
u32* cursor = (u32*)src;
is_failed |= IS_FALSE(__EXI2Select());
is_failed |= IS_FALSE(__EXI2Imm(¶m_0, 4, 1));
is_failed |= IS_FALSE(__EXI2Sync());
while (count > 0) {
cur_val = *cursor++;
is_failed |= IS_FALSE(__EXI2Imm(&cur_val, 4, 1));
is_failed |= IS_FALSE(__EXI2Sync());
count -= 4;
}
is_failed |= IS_FALSE(__EXI2Deselect());
return IS_FALSE(is_failed);
}
u32 __EXISwap32(u32 v) {
return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);
}
|