-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
101 lines (88 loc) · 2.24 KB
/
Copy pathmain.cpp
File metadata and controls
101 lines (88 loc) · 2.24 KB
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
#include "main.h"
PSP_MODULE_INFO("mme", 0, 1, 1);
PSP_HEAP_SIZE_KB(-1024);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VFPU | PSP_THREAD_ATTR_USER);
static volatile u32* mem = nullptr;
#define meCounter (mem[0])
#define meStart (mem[1])
#define meExit (mem[2])
__attribute__((noinline, aligned(4)))
static void meLoop() {
do {
meDCacheWritebackInvalidAll();
} while(!mem || !meStart);
do {
meCounter++;
} while(!meExit);
}
extern char __start__me_section;
extern char __stop__me_section;
__attribute__((section("_me_section"), noinline, aligned(4)))
void meHandler() {
vrg(0xbc100040) = 0x02; // mem access (64mb)
vrg(0xbc100050) = 0x0f; // enable clocks: ME, AW bus RegA, RegB & Edram
asm volatile(
// clean status, disable interrupt
"mtc0 $0, $12\n"
"sync\n"
// save context
"addi $sp, $sp, -16\n"
"sw $k0, 0($sp)\n"
// setup meLoop
"la $k0, %0\n"
"mtc0 $k0, $14\n"
"sync\n"
// restore context
"lw $k0, 0($sp)\n"
"addi $sp, $sp, 16\n"
// exit to meLoop
"eret\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
:
: "i" (meLoop)
: "k0", "memory"
);
}
static int meInit() {
#define me_section_size (&__stop__me_section - &__start__me_section)
memcpy((void *)0xbfc00000, (void*)&__start__me_section, me_section_size);
meDCacheWritebackInvalidAll();
vrg(0xbc10004c) = 0b100;
vrg(0xbc10004c) = 0x0;
asm volatile("sync");
return 0;
}
void quit(const char* const str) {
pspDebugScreenClear();
pspDebugScreenPrintf(str);
sceKernelDelayThread(500000);
sceKernelExitGame();
}
int main() {
scePowerSetClockFrequency(333, 333, 166);
pspDebugScreenInit();
if (pspSdkLoadStartModule("ms0:/PSP/GAME/me/kcall.prx", PSP_MEMORY_PARTITION_KERNEL) < 0){
quit("Can't load the PRX, exiting...");
return 0;
}
mem = meGetUncached32(10);
kcall(&meInit);
meStart = true;
SceCtrlData ctl;
do {
sceCtrlPeekBufferPositive(&ctl, 1);
pspDebugScreenSetXY(0, 1);
pspDebugScreenPrintf("%u ", meCounter);
sceDisplayWaitVblankStart();
} while(!(ctl.Buttons & PSP_CTRL_HOME));
meExit = true;
meGetUncached32(0);
quit("Exiting...");
return 0;
}