Skip to content

Commit 546f423

Browse files
committed
dldi acceleration patching works in no$gba for some homebrew
1 parent 50eaf52 commit 546f423

File tree

4 files changed

+72
-25
lines changed

4 files changed

+72
-25
lines changed

bootloader/source/hook.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,34 @@ static const u32 homebrewSigPatched[5] = {
7878
0xEA000000, // b got_handler
7979
0x037C0010 // DCD 0x037C0010
8080
};
81-
81+
8282
// accelerator patch for IPC_SYNC
8383
static const u32 homebrewAccelSig[4] = {
84-
0x2201B510 , // .
84+
0x2401B510 , // .
8585
// MOVS R4, #1
8686
0xD0064220 , // .
8787
// .
8888
0x881A4B10 , // ...
8989
0x430A2108 , // ...
9090
};
9191

92-
93-
94-
static const u32 homebrewAccelSigPatched[4] = {
92+
/*static const u32 homebrewAccelSigPatched[4] = {
9593
0x2201B510 , // .
9694
// MOVS R4, #1
9795
0x43180423 , // LSLS R3, R4, #0x10 // IRQ IPC SYNC
9896
// ORRS R0, R3 // ENABLE THE BIT
9997
0x881A4B10 , // ...
10098
0x430A2108 , // ...
101-
};
99+
}; */
100+
101+
static const u32 homebrewAccelSigPatched[4] = {
102+
0x47104A00 , // LDR R2, =0x037C0014
103+
// BX R2
104+
0x037C0020 , //
105+
//
106+
0x881A4B10 , // ...
107+
0x430A2108 , // ...
108+
};
102109

103110
static const int MAX_HANDLER_SIZE = 50;
104111

sdengine/source/sdmmcEngine.c

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,34 +173,62 @@ static u32* restoreInterruptHandlerHomebrew (u32* addr, u32 size) {
173173
return addr;
174174
}
175175

176-
void myIrqHandler(void) {
177-
//dbg_printf("myIrqHandler\n");
178-
//REG_IE |= IRQ_IPC_SYNC;
176+
//---------------------------------------------------------------------------------
177+
void SyncHandler(void) {
178+
//---------------------------------------------------------------------------------
179+
nocashMessage("SyncHandler");
180+
runSdMmcEngineCheck();
181+
}
179182

180-
/*if(!initialized) {
183+
//---------------------------------------------------------------------------------
184+
void checkIRQ_IPC_SYNC() {
185+
//---------------------------------------------------------------------------------
186+
if(!initialized) {
181187
nocashMessage("!initialized");
182-
u32* current=irqHandler+4;
188+
u32* current=irqHandler+1;
183189

184-
while(*current!=IRQ_IPC_SYNC && *current) {
185-
current+=8;
190+
while(*current!=IRQ_IPC_SYNC && *current!=0) {
191+
current+=2;
186192
}
193+
if(current==IRQ_IPC_SYNC) {
194+
nocashMessage("IRQ_IPC_SYNC slot found");
195+
} else {
196+
nocashMessage("empty irqtable slot found");
197+
}
187198

188-
nocashMessage("empty irqtable slot found");
189-
190-
*((IntFn*)current-4) = runSdMmcEngineCheck;
199+
*((IntFn*)current-1) = SyncHandler;
191200
*current = IRQ_IPC_SYNC;
192201

193202
nocashMessage("IRQ_IPC_SYNC setted");
194-
195-
REG_IPC_SYNC |= IPC_SYNC_IRQ_ENABLE;
196-
REG_IE |= IRQ_IPC_SYNC;
197-
198-
nocashMessage("IRQ_IPC_SYNC enabled");
199-
// restore the irq Handler for better compatibility
200-
// restoreInterruptHandlerHomebrew(irqSig-8,24);
203+
201204
initialized = true;
202-
}*/
205+
}
206+
}
207+
208+
209+
void myIrqHandler(void) {
210+
//dbg_printf("myIrqHandler\n");
211+
212+
checkIRQ_IPC_SYNC();
203213
runSdMmcEngineCheck();
204214
}
205215

216+
void myIrqEnable(u32 irq) {
217+
dbg_printf("myIrqEnable\n");
218+
int oldIME = enterCriticalSection();
219+
if (irq & IRQ_VBLANK)
220+
REG_DISPSTAT |= DISP_VBLANK_IRQ ;
221+
if (irq & IRQ_HBLANK)
222+
REG_DISPSTAT |= DISP_HBLANK_IRQ ;
223+
if (irq & IRQ_VCOUNT)
224+
REG_DISPSTAT |= DISP_YTRIGGER_IRQ;
225+
226+
irq |= IRQ_IPC_SYNC;
227+
REG_IPC_SYNC |= IPC_SYNC_IRQ_ENABLE;
228+
nocashMessage("IRQ_IPC_SYNC enabled");
229+
230+
REG_IE |= irq;
231+
leaveCriticalSection(oldIME);
232+
}
233+
206234

sdengine/source/sdmmcEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern "C" {
2525

2626
void myIrqHandler(void);
2727

28+
void myIrqEnable(u32 irq);
29+
2830
void runSdMmcEngineCheck (void);
2931

3032

sdengine/source/sdmmc_engine_header.s

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ irqSig:
2626
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
2727

2828
sdmmc_engine_start:
29+
sdmmc_engine_irqHandler:
2930
ldr r1, =irqHandler @ user IRQ handler address
3031
cmp r1, #0
3132
bne call_handler
3233
bx lr
3334

35+
sdmmc_engine_irqEnable:
36+
push {lr}
37+
push {r1-r12}
38+
ldr r3, =myIrqEnable
39+
bl _blx_r3_stub @ jump to myIrqEnable
40+
pop {r1-r12}
41+
pop {lr}
42+
bx lr
43+
3444
call_handler:
3545
push {lr}
3646
adr lr, code_handler_start
@@ -41,7 +51,7 @@ call_handler:
4151
code_handler_start:
4252
push {r0-r12}
4353
ldr r3, =myIrqHandler
44-
bl _blx_r3_stub @ jump to user code
54+
bl _blx_r3_stub @ jump to myIrqHandler
4555

4656
@ exit after return
4757
b exit

0 commit comments

Comments
 (0)