Skip to content

Commit

Permalink
Update loader codes to enable interrupts when CARD functions will run
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephiles committed Jan 29, 2023
1 parent 8151a64 commit b1cc84a
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 72 deletions.
12 changes: 6 additions & 6 deletions Binaries/BinaryData.ts

Large diffs are not rendered by default.

Binary file modified Binaries/bin/Main_EU_V1.bin
Binary file not shown.
Binary file modified Binaries/bin/Main_EU_V2.bin
Binary file not shown.
Binary file modified Binaries/bin/Main_JP_V1.bin
Binary file not shown.
Binary file modified Binaries/bin/Main_JP_V2.bin
Binary file not shown.
Binary file modified Binaries/bin/Main_US_V1.bin
Binary file not shown.
Binary file modified Binaries/bin/Main_US_V2.bin
Binary file not shown.
Binary file modified OriginalVersion/bin/Main_EU_V1.bin
Binary file not shown.
Binary file modified OriginalVersion/bin/Main_EU_V2.bin
Binary file not shown.
Binary file modified OriginalVersion/bin/Main_JP_V1.bin
Binary file not shown.
Binary file modified OriginalVersion/bin/Main_JP_V2.bin
Binary file not shown.
Binary file modified OriginalVersion/bin/Main_US_V1.bin
Binary file not shown.
Binary file modified OriginalVersion/bin/Main_US_V2.bin
Binary file not shown.
30 changes: 21 additions & 9 deletions OriginalVersion/source/Main_EU_V1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.set do_alloc,0x802CFF28
.set do_free,0x802D05AC
.set OSDisableInterrupts,0x8033E4F4
.set OSEnableInterrupts,0x8033E508
.set OSRestoreInterrupts,0x8033E51C
.set OSLink,0x8033F310
.set OSUnlink,0x8033F5A8
Expand All @@ -42,6 +43,12 @@
.set CARDRead,0x803596FC

__start:
# Enable interrupts for safety
lis r12,OSEnableInterrupts@h
ori r12,r12,OSEnableInterrupts@l
mtlr r12
blrl

# Hook __OSReboot
lis r3,__OSReboot@h
ori r3,r3,__OSReboot@l
Expand Down Expand Up @@ -237,6 +244,12 @@ gPayload:
# Original code created by PistonMiner and Zephiles for Paper Mario: The Thousand-Year Door
# Code ported to Twilight Princess by Zephiles

# Interrupts are required to be enabled for CARD functions to work properly
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r26,r3 # enable

# Initialize static values used for addresses
lis r31,0x8000

Expand Down Expand Up @@ -367,19 +380,15 @@ mr r28,r3
# Disable interrupts to make sure other REL files do not try to be linked while this one is being linked
bl (OSDisableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r26,r3 # enable

# Link the functions in the REL
mr r3,r27 # Pointer to the Module
mr r4,r28 # Pointer to the BSS Area
bl (OSLink - LOADER_LOWMEM_LOCATION + __start)
cmpwi r3,1 # Check if something went wrong
bne- unlinkRel

# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Store the BSS Area and the Module
stw r28,0x42DC(r31) # Pointer to the BSS Area
Expand All @@ -404,9 +413,8 @@ unlinkRel:
mr r3,r27 # Pointer to the Module
bl (OSUnlink - LOADER_LOWMEM_LOCATION + __start)

# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Free the BSS Area and the File Buffer
mr r4,r28 # Pointer to the BSS Area
Expand Down Expand Up @@ -435,6 +443,10 @@ mtlr r30
blrl

exit:
# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Restore the overwritten instruction
lis r3,OVERWRITTEN_INSTRUCTION_VALUE

Expand Down
30 changes: 21 additions & 9 deletions OriginalVersion/source/Main_EU_V2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.set do_free,0x802D05AC
.set do_resize,0x802D0778
.set OSDisableInterrupts,0x8033E4F4
.set OSEnableInterrupts,0x8033E508
.set OSRestoreInterrupts,0x8033E51C
.set OSLinkFixed,0x8033F334
.set OSUnlink,0x8033F5A8
Expand All @@ -43,6 +44,12 @@
.set CARDRead,0x803596FC

__start:
# Enable interrupts for safety
lis r12,OSEnableInterrupts@h
ori r12,r12,OSEnableInterrupts@l
mtlr r12
blrl

# Hook __OSReboot
lis r3,__OSReboot@h
ori r3,r3,__OSReboot@l
Expand Down Expand Up @@ -238,6 +245,12 @@ gPayload:
# Original code created by PistonMiner and Zephiles for Paper Mario: The Thousand-Year Door
# Code ported to Twilight Princess by Zephiles

# Interrupts are required to be enabled for CARD functions to work properly
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r24,r3 # enable

# Initialize static values used for addresses
lis r31,0x8000

Expand Down Expand Up @@ -396,9 +409,6 @@ bne- freeCurrentMemoryArea
# Disable interrupts to make sure other REL files do not try to be linked while this one is being linked
bl (OSDisableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r25,r3 # enable

# Get the address of the BSS Area
add r28,r27,r26

Expand All @@ -409,9 +419,8 @@ bl (OSLinkFixed - LOADER_LOWMEM_LOCATION + __start)
cmpwi r3,1 # Check if something went wrong
bne- unlinkRel

# Restore interrupts
mr r3,r25 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Add the BSS Area Size to the adjusted fixed REL size
add r5,r26,r21
Expand Down Expand Up @@ -445,9 +454,8 @@ unlinkRel:
mr r3,r27 # Pointer to the Module
bl (OSUnlink - LOADER_LOWMEM_LOCATION + __start)

# Restore interrupts
mr r3,r25 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

freeCurrentMemoryArea:
mr r4,r27 # Pointer to the File Buffer or the 0x400 Bytes Buffer
Expand All @@ -472,6 +480,10 @@ mtlr r30
blrl

exit:
# Restore interrupts
mr r3,r24 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Restore the overwritten instruction
lis r3,OVERWRITTEN_INSTRUCTION_VALUE

Expand Down
30 changes: 21 additions & 9 deletions OriginalVersion/source/Main_JP_V1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.set do_alloc,0x802D15C4
.set do_free,0x802D1C48
.set OSDisableInterrupts,0x8033FB90
.set OSEnableInterrupts,0x8033FBA4
.set OSRestoreInterrupts,0x8033FBB8
.set OSLink,0x803409AC
.set OSUnlink,0x80340C44
Expand All @@ -42,6 +43,12 @@
.set CARDRead,0x8035AD68

__start:
# Enable interrupts for safety
lis r12,OSEnableInterrupts@h
ori r12,r12,OSEnableInterrupts@l
mtlr r12
blrl

# Hook __OSReboot
lis r3,__OSReboot@h
ori r3,r3,__OSReboot@l
Expand Down Expand Up @@ -237,6 +244,12 @@ gPayload:
# Original code created by PistonMiner and Zephiles for Paper Mario: The Thousand-Year Door
# Code ported to Twilight Princess by Zephiles

# Interrupts are required to be enabled for CARD functions to work properly
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r26,r3 # enable

# Initialize static values used for addresses
lis r31,0x8000

Expand Down Expand Up @@ -367,19 +380,15 @@ mr r28,r3
# Disable interrupts to make sure other REL files do not try to be linked while this one is being linked
bl (OSDisableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r26,r3 # enable

# Link the functions in the REL
mr r3,r27 # Pointer to the Module
mr r4,r28 # Pointer to the BSS Area
bl (OSLink - LOADER_LOWMEM_LOCATION + __start)
cmpwi r3,1 # Check if something went wrong
bne- unlinkRel

# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Store the BSS Area and the Module
stw r28,0x42DC(r31) # Pointer to the BSS Area
Expand All @@ -404,9 +413,8 @@ unlinkRel:
mr r3,r27 # Pointer to the Module
bl (OSUnlink - LOADER_LOWMEM_LOCATION + __start)

# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Free the BSS Area and the File Buffer
mr r4,r28 # Pointer to the BSS Area
Expand Down Expand Up @@ -435,6 +443,10 @@ mtlr r30
blrl

exit:
# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Restore the overwritten instruction
lis r3,OVERWRITTEN_INSTRUCTION_VALUE

Expand Down
30 changes: 21 additions & 9 deletions OriginalVersion/source/Main_JP_V2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.set do_free,0x802D1C48
.set do_resize,0x802D1E14
.set OSDisableInterrupts,0x8033FB90
.set OSEnableInterrupts,0x8033FBA4
.set OSRestoreInterrupts,0x8033FBB8
.set OSLinkFixed,0x803409D0
.set OSUnlink,0x80340C44
Expand All @@ -43,6 +44,12 @@
.set CARDRead,0x8035AD68

__start:
# Enable interrupts for safety
lis r12,OSEnableInterrupts@h
ori r12,r12,OSEnableInterrupts@l
mtlr r12
blrl

# Hook __OSReboot
lis r3,__OSReboot@h
ori r3,r3,__OSReboot@l
Expand Down Expand Up @@ -238,6 +245,12 @@ gPayload:
# Original code created by PistonMiner and Zephiles for Paper Mario: The Thousand-Year Door
# Code ported to Twilight Princess by Zephiles

# Interrupts are required to be enabled for CARD functions to work properly
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r24,r3 # enable

# Initialize static values used for addresses
lis r31,0x8000

Expand Down Expand Up @@ -396,9 +409,6 @@ bne- freeCurrentMemoryArea
# Disable interrupts to make sure other REL files do not try to be linked while this one is being linked
bl (OSDisableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r25,r3 # enable

# Get the address of the BSS Area
add r28,r27,r26

Expand All @@ -409,9 +419,8 @@ bl (OSLinkFixed - LOADER_LOWMEM_LOCATION + __start)
cmpwi r3,1 # Check if something went wrong
bne- unlinkRel

# Restore interrupts
mr r3,r25 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Add the BSS Area Size to the adjusted fixed REL size
add r5,r26,r21
Expand Down Expand Up @@ -445,9 +454,8 @@ unlinkRel:
mr r3,r27 # Pointer to the Module
bl (OSUnlink - LOADER_LOWMEM_LOCATION + __start)

# Restore interrupts
mr r3,r25 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

freeCurrentMemoryArea:
mr r4,r27 # Pointer to the File Buffer or the 0x400 Bytes Buffer
Expand All @@ -472,6 +480,10 @@ mtlr r30
blrl

exit:
# Restore interrupts
mr r3,r24 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Restore the overwritten instruction
lis r3,OVERWRITTEN_INSTRUCTION_VALUE

Expand Down
30 changes: 21 additions & 9 deletions OriginalVersion/source/Main_US_V1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
.set do_alloc,0x802CF128
.set do_free,0x802CF7AC
.set OSDisableInterrupts,0x8033D6F4
.set OSEnableInterrupts,0x8033D708
.set OSRestoreInterrupts,0x8033D71C
.set OSLink,0x8033E510
.set OSUnlink,0x8033E7A8
Expand All @@ -42,6 +43,12 @@
.set CARDRead,0x803588CC

__start:
# Enable interrupts for safety
lis r12,OSEnableInterrupts@h
ori r12,r12,OSEnableInterrupts@l
mtlr r12
blrl

# Hook __OSReboot
lis r3,__OSReboot@h
ori r3,r3,__OSReboot@l
Expand Down Expand Up @@ -237,6 +244,12 @@ gPayload:
# Original code created by PistonMiner and Zephiles for Paper Mario: The Thousand-Year Door
# Code ported to Twilight Princess by Zephiles

# Interrupts are required to be enabled for CARD functions to work properly
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r26,r3 # enable

# Initialize static values used for addresses
lis r31,0x8000

Expand Down Expand Up @@ -367,19 +380,15 @@ mr r28,r3
# Disable interrupts to make sure other REL files do not try to be linked while this one is being linked
bl (OSDisableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Backup the returned value to be used for later
mr r26,r3 # enable

# Link the functions in the REL
mr r3,r27 # Pointer to the Module
mr r4,r28 # Pointer to the BSS Area
bl (OSLink - LOADER_LOWMEM_LOCATION + __start)
cmpwi r3,1 # Check if something went wrong
bne- unlinkRel

# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Store the BSS Area and the Module
stw r28,0x42DC(r31) # Pointer to the BSS Area
Expand All @@ -404,9 +413,8 @@ unlinkRel:
mr r3,r27 # Pointer to the Module
bl (OSUnlink - LOADER_LOWMEM_LOCATION + __start)

# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)
# Re-enable interrupts
bl (OSEnableInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Free the BSS Area and the File Buffer
mr r4,r28 # Pointer to the BSS Area
Expand Down Expand Up @@ -435,6 +443,10 @@ mtlr r30
blrl

exit:
# Restore interrupts
mr r3,r26 # enable
bl (OSRestoreInterrupts - LOADER_LOWMEM_LOCATION + __start)

# Restore the overwritten instruction
lis r3,OVERWRITTEN_INSTRUCTION_VALUE

Expand Down
Loading

0 comments on commit b1cc84a

Please sign in to comment.