Skip to content

Commit ce4626e

Browse files
committed
Fix #1570
1 parent c014769 commit ce4626e

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

retail/bootloader/source/arm7/hook_arm9.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define b_overlaysCached BIT(6)
2020
#define b_cacheFlushFlag BIT(7)
2121
#define b_cardReadFix BIT(8)
22+
#define b_bypassExceptionHandler BIT(9)
2223
#define b_softResetMb BIT(13)
2324

2425

@@ -242,6 +243,9 @@ int hookNdsRetailArm9(
242243
if (patchOffsetCache.resetMb) {
243244
ce9->valueBits |= b_softResetMb;
244245
}
246+
if (strncmp(romTid, "AZE", 3) == 0) { // Zelda: Phantom Hourglass
247+
ce9->valueBits |= b_bypassExceptionHandler;
248+
}
245249
ce9->mainScreen = mainScreen;
246250
ce9->s2FlashcardId = s2FlashcardId;
247251
ce9->overlaysSrc = (ndsHeader->arm9overlaySource > ndsHeader->arm7romOffset) ? (ndsHeader->arm9romOffset + ndsHeader->arm9binarySize) : ndsHeader->arm9overlaySource;

retail/bootloaderi/source/arm7/hook_arm9.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define b_softResetMb BIT(13)
2828
#define b_cloneboot BIT(14)
2929
#define b_isDlp BIT(15)
30+
#define b_bypassExceptionHandler BIT(16)
3031

3132

3233
static const int MAX_HANDLER_LEN = 50;
@@ -333,6 +334,9 @@ int hookNdsRetailArm9(
333334
if (strncmp(romTid, "HND", 3) == 0) {
334335
ce9->valueBits |= b_isDlp;
335336
}
337+
if (strncmp(romTid, "AZE", 3) == 0) { // Zelda: Phantom Hourglass
338+
ce9->valueBits |= b_bypassExceptionHandler;
339+
}
336340
ce9->mainScreen = mainScreen;
337341
ce9->overlaysSrc = (ndsHeader->arm9overlaySource > ndsHeader->arm7romOffset) ? (ndsHeader->arm9romOffset + ndsHeader->arm9binarySize) : ndsHeader->arm9overlaySource;
338342
ce9->overlaysSize = overlaysSize;

retail/cardengine/arm9/source/exception.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "locations.h"
55
#include "cardengine_header_arm9.h"
66

7+
#define bypassExceptionHandler BIT(9)
8+
79
#define EXCEPTION_VECTOR_SDK1 (*(VoidFn *)(0x27FFD9C))
810

911
extern cardengineArm9* volatile ce9;
@@ -27,10 +29,10 @@ void userException() {
2729
//---------------------------------------------------------------------------------
2830
void setExceptionHandler2() {
2931
//---------------------------------------------------------------------------------
30-
if (EXCEPTION_VECTOR_SDK1 == enterException && *exceptionC == userException) return;
32+
if (EXCEPTION_VECTOR_SDK1 == ((ce9->valueBits & bypassExceptionHandler) ? 0 : enterException) && *exceptionC == userException) return;
3133

3234
exceptionStack = (u32)EXCEPTION_STACK_LOCATION;
33-
EXCEPTION_VECTOR_SDK1 = enterException;
35+
EXCEPTION_VECTOR_SDK1 = (ce9->valueBits & bypassExceptionHandler) ? 0 : enterException;
3436
*exceptionC = userException;
3537
}
3638

retail/cardenginei/arm9/source/exception.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "cardengine_header_arm9.h"
66

77
#define dsiBios BIT(11)
8+
#define bypassExceptionHandler BIT(16)
89

910
#define EXCEPTION_VECTOR_SDK1 (*(VoidFn *)(0x27FFD9C))
1011

@@ -31,12 +32,12 @@ void userException() {
3132
void setExceptionHandler2() {
3233
//---------------------------------------------------------------------------------
3334
#ifdef TWLSDK
34-
if (EXCEPTION_VECTOR == enterException && *exceptionC == userException) return;
35+
if (EXCEPTION_VECTOR == ((ce9->valueBits & bypassExceptionHandler) ? 0 : enterException) && *exceptionC == userException) return;
3536
#else
3637
if (!(ce9->valueBits & dsiBios)) {
37-
if (EXCEPTION_VECTOR_SDK1 == enterException && *exceptionC == userException) return;
38+
if (EXCEPTION_VECTOR_SDK1 == ((ce9->valueBits & bypassExceptionHandler) ? 0 : enterException) && *exceptionC == userException) return;
3839
} else {
39-
if (EXCEPTION_VECTOR == enterException && *exceptionC == userException) return;
40+
if (EXCEPTION_VECTOR == ((ce9->valueBits & bypassExceptionHandler) ? 0 : enterException) && *exceptionC == userException) return;
4041
}
4142
#endif
4243

@@ -47,13 +48,13 @@ void setExceptionHandler2() {
4748
#endif
4849
#ifdef TWLSDK
4950
exceptionStack = (u32)EXCEPTION_STACK_LOCATION_SDK5;
50-
EXCEPTION_VECTOR = enterException;
51+
EXCEPTION_VECTOR = (ce9->valueBits & bypassExceptionHandler) ? 0 : enterException;
5152
#else
5253
exceptionStack = (u32)EXCEPTION_STACK_LOCATION;
5354
if (!(ce9->valueBits & dsiBios)) {
54-
EXCEPTION_VECTOR_SDK1 = enterException;
55+
EXCEPTION_VECTOR_SDK1 = (ce9->valueBits & bypassExceptionHandler) ? 0 : enterException;
5556
} else {
56-
EXCEPTION_VECTOR = enterException;
57+
EXCEPTION_VECTOR = (ce9->valueBits & bypassExceptionHandler) ? 0 : enterException;
5758
}
5859
#endif
5960
*exceptionC = userException;

retail/cardenginei/arm9_dsiware/source/exception.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "locations.h"
55
#include "cardengine_header_arm9.h"
66

7+
#define bypassExceptionHandler BIT(16)
8+
79
extern cardengineArm9* volatile ce9;
810

911
extern u32 exceptionAddr;
@@ -26,10 +28,10 @@ void userException() {
2628
//---------------------------------------------------------------------------------
2729
void setExceptionHandler2() {
2830
//---------------------------------------------------------------------------------
29-
if (EXCEPTION_VECTOR == enterException && *exceptionC == userException) return;
31+
if (EXCEPTION_VECTOR == ((ce9->valueBits & bypassExceptionHandler) ? 0 : enterException) && *exceptionC == userException) return;
3032

3133
exceptionStack = (u32)EXCEPTION_STACK_LOCATION_SDK5;
32-
EXCEPTION_VECTOR = enterException;
34+
EXCEPTION_VECTOR = (ce9->valueBits & bypassExceptionHandler) ? 0 : enterException;
3335
*exceptionC = userException;
3436
}
3537

retail/common/include/cardengine_header_arm9.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ typedef struct cardengineArm9 {
101101
13: softResetMb
102102
14: cloneboot
103103
15: isDlp
104+
16: bypassExceptionHandler
104105
*/
105106
s32 mainScreen;
106107
u32 consoleModel;
@@ -218,6 +219,9 @@ typedef struct cardengineArm9 {
218219
4: enableExceptionHandler
219220
5: isSdk5
220221
6: overlaysCached
222+
7: cacheFlushFlag
223+
8: cardReadFix
224+
9: bypassExceptionHandler
221225
13: softResetMb
222226
*/
223227
s32 mainScreen;

0 commit comments

Comments
 (0)