-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinram.cpp
196 lines (175 loc) · 3.72 KB
/
inram.cpp
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
#include "inram.h"
#include "hard.h"
//#pragma arm section rodata="_inram"
extern u32 gl_currentpage ;
extern EZ4_CARTTYPE g_EZ4CardType;
void SetRampage(u16 page)
{
*(vu16 *)0x9fe0000 = 0xd200;
*(vu16 *)0x8000000 = 0x1500;
*(vu16 *)0x8020000 = 0xd200;
*(vu16 *)0x8040000 = 0x1500;
*(vu16 *)0x9c00000 = page;
*(vu16 *)0x9fc0000 = 0x1500;
}
void SetRompage(u16 page)
{
*(vu16 *)0x9fe0000 = 0xd200;
*(vu16 *)0x8000000 = 0x1500;
*(vu16 *)0x8020000 = 0xd200;
*(vu16 *)0x8040000 = 0x1500;
*(vu16 *)0x9880000 = page;
*(vu16 *)0x9fc0000 = 0x1500;
}
void HardRest()
{
__asm
{
mov r3, #0x04000208
mov r2, #0
str r2, [r3, #0]
mov r3, #0x03007FFA
mov r2, #0xFD
str r2, [r3, #0]
swi 0x1
mov r6, #0x30007F00
str r5, [r6]
mov r6, #0x03007FFA
mov r7, #0x0
str r7, [r6, #0]
swi 0
}
}
void SoftRest()
{
__asm
{
swi 0x26
}
}
void SetRompageWithSoftReset(u16 page)
{
SetRompage(page);
SoftRest();
}
void SetRompageWithHardReset(u16 page)
{
SetRompage(page);
HardRest();
}
void inramresetexec()
{
SetRompage(0x0);
*(u16*)(0x8000000) = 0xFF ;
*(u16*)(0x8000000+0x100) = 0xFF ;
*(u16*)(0x8000000+0x200) = 0xFF ;
*(u16*)(0x8000000+0x300) = 0xFF ;
*(u16*)(0x8800000) = 0xFF ;
*(u16*)(0x8800000+0x100) = 0xFF ;
*(u16*)(0x8800000+0x200) = 0xFF ;
*(u16*)(0x8800000+0x300) = 0xFF ;
SetRompage(gl_currentpage) ;
}
void minireset(u16 page)
{
SetRompage(page);
__asm
{
mov r3, #0x03007FFA
mov r2, #0x0
strh r2, [r3, #0]
mov r0, 0xFC
swi 0x1
swi 0
}
}
void ldErase()
{
u16 i ;
u32 eraseAdd = 0x83E0000;//0x08200000 ;
*(vu16 *)REG_IME = 0 ; // Set IME
*(vu16*)(eraseAdd) = 0x50 ;
*(vu16*)(eraseAdd) = 0xFF ;
*(vu16*)(eraseAdd) = 0x20 ;
*(vu16*)(eraseAdd) = 0xD0 ;
while( (*(vu16*)(eraseAdd)) != 0x80);
*(vu16*)(eraseAdd) = 0xFF ;
*(vu16 *)REG_IME = 1 ; // Set IME
/*
for(i=0;i<32;i++)
{
*(u16*)(eraseAdd+i*0x8000) = 0x20 ;
*(u16*)(eraseAdd+i*0x8000) = 0xd0 ;
while( (*(u16*)(eraseAdd+i*0x8000)) != 0x80);
}
*/
// *(u16*)(0x08200000) = 0xFF ;
}
void ldRead(u8* buf,u32 size)
{
register u32 ss;
u8 *pSave=(u8*)0x0E000000;
SetRampage(0xA0);
for(ss=0;ss<size;ss++)
{
buf[ss] = pSave[ss] ;
}
SetRampage(0x00);
/*
u32 eraseAdd = 0x83E0000;//0x08200000 ;
u32 i;
*(vu16 *)REG_IME = 0 ; // Set IME
*(vu16*)(eraseAdd) = 0x50 ;
*(vu16*)(eraseAdd) = 0xFF ;
for(i=0;i<size;i+=2)
*((u16 *)(buf+i)) = *(vu16*)(eraseAdd+i);
*(vu16 *)REG_IME = 1 ;
*/
}
void ldWrite(u32 address,u8*buf,u32 size)
{
register u32 ss;
u8 *pSave=(u8*)0x0E000000;
SetRampage(0xA0);
for(ss=0;ss<size;ss++)
{
pSave[ss] = buf[ss];
}
SetRampage(0x00);
/*
vu16* pWord = (vu16 *)buf ;
u32 wsize = size/2 ;
u32 ss = 0,e=0;
for(ss=0;ss<wsize;ss+=128)
{
*(vu16*)(address+(ss<<1)) = 0x41;
for(e=0;e<128;e++)
{
*(vu16 *)(address+(ss<<1)+e*2) = pWord[ss+e];
}
*(vu16*)(address+(ss<<1)) = 0x0e;
*(vu16*)(address+(ss<<1)) = 0xd0;
while((*(vu16*)(address+(ss<<1)) != 0x80));
*(vu16*)(address+(ss<<1)) = 0xFF;
}
*(vu16*)(0x83E0000) = 0xFF ;
*/
}
void IsSingleCard()
{
u32 address = 0x8000000;
vu16 id1,id2;
*(u16*)(address+0xAAA) = 0xF0 ;
*(u16*)(address+0xAAA) = 0xAA ;
*(u16*)(address+0x554) = 0x55 ;
*(u16*)(address+0xAAA) = 0x90 ;
id1 = *(vu16*)(address+2);
id2 = *(vu16*)(address+0xE*2);
if(id1==0x227E && id2==0x2202)
{
*(u16*)(address+0xAAA) = 0xAA ;
*(u16*)(address+0x554) = 0x55 ;
*(u16*)(address+0xAAA) = 0xF0 ;
g_EZ4CardType = EZ4_1Chip;
}
}