Skip to content

Commit 9d2ab1e

Browse files
committed
Reduced memory usage + fixed a crash with the Reload Screen code
1 parent 578efc2 commit 9d2ab1e

File tree

8 files changed

+226
-21
lines changed

8 files changed

+226
-21
lines changed

ttyd-tools/rel/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ INCLUDES := include
5151

5252
MACHDEP = -mno-sdata -mgcn -DGEKKO -mcpu=750 -meabi -mhard-float
5353

54-
CFLAGS = -nostdlib -ffreestanding -ffunction-sections -fdata-sections -g -O3 -Wall -Werror $(MACHDEP) $(INCLUDE)
54+
CFLAGS = -nostdlib -ffreestanding -ffunction-sections -fdata-sections -g -Os -Wall -Werror $(MACHDEP) $(INCLUDE)
5555
CXXFLAGS = -fno-exceptions -fno-rtti -std=gnu++17 $(CFLAGS)
5656

5757
LDFLAGS = -r -e _prolog -u _prolog -u _epilog -u _unresolved -Wl,--gc-sections -nostdlib -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
@@ -182,7 +182,7 @@ $(OFILES_SOURCES) : $(HFILES)
182182
# REL linking
183183
%.rel: %.elf
184184
@echo output ... $(notdir $@)
185-
@$(ELF2REL) $< $(MAPFILE)
185+
@$(ELF2REL) $< -s $(MAPFILE)
186186

187187
%.gci: %.rel
188188
@echo packing ... $(notdir $@)

ttyd-tools/rel/include/ttyd.eu.lst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,44 @@
800800
// 801AB220:marioResetCamShiftRate
801801
// 801AB284:marioResetCamShift
802802

803+
// runtime.c
804+
8026849C:_savefpr_14
805+
802684A0:_savefpr_15
806+
802684A4:_savefpr_16
807+
802684A8:_savefpr_17
808+
802684AC:_savefpr_18
809+
802684B0:_savefpr_19
810+
802684B4:_savefpr_20
811+
802684B8:_savefpr_21
812+
802684BC:_savefpr_22
813+
802684C0:_savefpr_23
814+
802684C4:_savefpr_24
815+
802684C8:_savefpr_25
816+
802684CC:_savefpr_26
817+
802684D0:_savefpr_27
818+
802684D4:_savefpr_28
819+
802684D8:_savefpr_29
820+
802684DC:_savefpr_30
821+
802684E0:_savefpr_31
822+
80268534:_savegpr_14
823+
80268538:_savegpr_15
824+
8026853C:_savegpr_16
825+
80268540:_savegpr_17
826+
80268544:_savegpr_18
827+
80268548:_savegpr_19
828+
8026854C:_savegpr_20
829+
80268550:_savegpr_21
830+
80268554:_savegpr_22
831+
80268558:_savegpr_23
832+
8026855C:_savegpr_24
833+
80268560:_savegpr_25
834+
80268564:_savegpr_26
835+
80268568:_savegpr_27
836+
8026856C:_savegpr_28
837+
80268570:_savegpr_29
838+
80268574:_savegpr_30
839+
80268578:_savegpr_31
840+
803841
// printf.c
804842
8026DEAC:sprintf
805843
// unused:snprintf

ttyd-tools/rel/include/ttyd.jp.lst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,44 @@
797797
// 801A3578:marioResetCamShiftRate
798798
// 801A35DC:marioResetCamShift
799799

800+
// runtime.c
801+
8025E90C:_savefpr_14
802+
8025E910:_savefpr_15
803+
8025E914:_savefpr_16
804+
8025E918:_savefpr_17
805+
8025E91C:_savefpr_18
806+
8025E920:_savefpr_19
807+
8025E924:_savefpr_20
808+
8025E928:_savefpr_21
809+
8025E92C:_savefpr_22
810+
8025E930:_savefpr_23
811+
8025E934:_savefpr_24
812+
8025E938:_savefpr_25
813+
8025E93C:_savefpr_26
814+
8025E940:_savefpr_27
815+
8025E944:_savefpr_28
816+
8025E948:_savefpr_29
817+
8025E94C:_savefpr_30
818+
8025E950:_savefpr_31
819+
8025E9A4:_savegpr_14
820+
8025E9A8:_savegpr_15
821+
8025E9AC:_savegpr_16
822+
8025E9B0:_savegpr_17
823+
8025E9B4:_savegpr_18
824+
8025E9B8:_savegpr_19
825+
8025E9BC:_savegpr_20
826+
8025E9C0:_savegpr_21
827+
8025E9C4:_savegpr_22
828+
8025E9C8:_savegpr_23
829+
8025E9CC:_savegpr_24
830+
8025E9D0:_savegpr_25
831+
8025E9D4:_savegpr_26
832+
8025E9D8:_savegpr_27
833+
8025E9DC:_savegpr_28
834+
8025E9E0:_savegpr_29
835+
8025E9E4:_savegpr_30
836+
8025E9E8:_savegpr_31
837+
800838
// printf.c
801839
80264108:sprintf
802840
// unused:snprintf

ttyd-tools/rel/include/ttyd.us.lst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,44 @@
800800
// 801A9544:marioResetCamShiftRate
801801
// 801A95A8:marioResetCamShift
802802

803+
// runtime.c
804+
802648BC:_savefpr_14
805+
802648C0:_savefpr_15
806+
802648C4:_savefpr_16
807+
802648C8:_savefpr_17
808+
802648CC:_savefpr_18
809+
802648D0:_savefpr_19
810+
802648D4:_savefpr_20
811+
802648D8:_savefpr_21
812+
802648DC:_savefpr_22
813+
802648E0:_savefpr_23
814+
802648E4:_savefpr_24
815+
802648E8:_savefpr_25
816+
802648EC:_savefpr_26
817+
802648F0:_savefpr_27
818+
802648F4:_savefpr_28
819+
802648F8:_savefpr_29
820+
802648FC:_savefpr_30
821+
80264900:_savefpr_31
822+
80264954:_savegpr_14
823+
80264958:_savegpr_15
824+
8026495C:_savegpr_16
825+
80264960:_savegpr_17
826+
80264964:_savegpr_18
827+
80264968:_savegpr_19
828+
8026496C:_savegpr_20
829+
80264970:_savegpr_21
830+
80264974:_savegpr_22
831+
80264978:_savegpr_23
832+
8026497C:_savegpr_24
833+
80264980:_savegpr_25
834+
80264984:_savegpr_26
835+
80264988:_savegpr_27
836+
8026498C:_savegpr_28
837+
80264990:_savegpr_29
838+
80264994:_savegpr_30
839+
80264998:_savegpr_31
840+
803841
// printf.c
804842
8026A0B8:sprintf
805843
// unused:snprintf

ttyd-tools/rel/include/ttyd/mario.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ extern "C" {
157157
// marioBgmodeOn
158158
// marioBgmodeChk
159159
// marioSetMutekiTime
160-
void marioKeyOn();
161-
void marioKeyOff();
160+
int8_t marioKeyOn();
161+
int8_t marioKeyOff();
162162
// marioCtrlOn2
163163
// marioCtrlOff2
164164
// marioCtrlOn

ttyd-tools/rel/source/codes/ReloadScreenC.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,34 @@ void Mod::reloadScreen()
2828

2929
if ((NextSeq >= Game) && (NextSeq <= MapChange))
3030
{
31-
// Not in the pause menu
32-
// A separate address for NextBero is needed, as the original value will be cleared during the reloading process
33-
// The game will crash if NextMap is used directly in seqSetSeq, so a separate address must be used instead
31+
uint32_t Seq = ttyd::seqdrv::seqGetSeq();
32+
uint32_t Battle = static_cast<uint32_t>(ttyd::seqdrv::SeqIndex::kBattle);
3433

35-
ttyd::string::strcpy(NewBero, NextBero);
36-
ttyd::string::strcpy(NewMap, NextMap);
37-
ttyd::seqdrv::seqSetSeq(ttyd::seqdrv::SeqIndex::kMapChange, NewMap, NewBero);
38-
39-
uint32_t SystemLevel = ttyd::mariost::marioStGetSystemLevel();
40-
if (SystemLevel != 0)
34+
// Reloading the room with the Seq set to Battle will cause the game to crash, so don't allow it
35+
if (Seq != Battle)
4136
{
42-
if (SystemLevel == 15)
37+
// Not in the pause menu
38+
// A separate address for NextBero is needed, as the original value will be cleared during the reloading process
39+
// The game will crash if NextMap is used directly in seqSetSeq, so a separate address must be used instead
40+
41+
ttyd::string::strcpy(NewBero, NextBero);
42+
ttyd::string::strcpy(NewMap, NextMap);
43+
ttyd::seqdrv::seqSetSeq(ttyd::seqdrv::SeqIndex::kMapChange, NewMap, NewBero);
44+
45+
uint32_t SystemLevel = ttyd::mariost::marioStGetSystemLevel();
46+
if (SystemLevel != 0)
4347
{
44-
// Currently in pause menu, so re-enable the camera
45-
ttyd::camdrv::camDispOn(4);
48+
if (SystemLevel == 15)
49+
{
50+
// Currently in pause menu, so re-enable the camera
51+
ttyd::camdrv::camDispOn(4);
52+
}
53+
54+
// Enable sound effects, set the default camera id for Mario, and give back control to the player
55+
ttyd::pmario_sound::psndClearFlag(0x80);
56+
ttyd::mario_cam::marioSetCamId(4);
57+
ttyd::mariost::marioStSystemLevel(0);
4658
}
47-
48-
// Enable sound effects, set the default camera id for Mario, and give back control to the player
49-
ttyd::pmario_sound::psndClearFlag(0x80);
50-
ttyd::mario_cam::marioSetCamId(4);
51-
ttyd::mariost::marioStSystemLevel(0);
5259
}
5360
}
5461
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.global _restfpr_14_x
2+
.global _restfpr_15_x
3+
.global _restfpr_16_x
4+
.global _restfpr_17_x
5+
.global _restfpr_18_x
6+
.global _restfpr_19_x
7+
.global _restfpr_20_x
8+
.global _restfpr_21_x
9+
.global _restfpr_22_x
10+
.global _restfpr_23_x
11+
.global _restfpr_24_x
12+
.global _restfpr_25_x
13+
.global _restfpr_26_x
14+
.global _restfpr_27_x
15+
.global _restfpr_28_x
16+
.global _restfpr_29_x
17+
.global _restfpr_30_x
18+
.global _restfpr_31_x
19+
20+
_restfpr_14_x: lfd %f14,-0x90(%r11)
21+
_restfpr_15_x: lfd %f15,-0x88(%r11)
22+
_restfpr_16_x: lfd %f16,-0x80(%r11)
23+
_restfpr_17_x: lfd %f17,-0x78(%r11)
24+
_restfpr_18_x: lfd %f18,-0x70(%r11)
25+
_restfpr_19_x: lfd %f19,-0x68(%r11)
26+
_restfpr_20_x: lfd %f20,-0x60(%r11)
27+
_restfpr_21_x: lfd %f21,-0x58(%r11)
28+
_restfpr_22_x: lfd %f22,-0x50(%r11)
29+
_restfpr_23_x: lfd %f23,-0x48(%r11)
30+
_restfpr_24_x: lfd %f24,-0x40(%r11)
31+
_restfpr_25_x: lfd %f25,-0x38(%r11)
32+
_restfpr_26_x: lfd %f26,-0x30(%r11)
33+
_restfpr_27_x: lfd %f27,-0x28(%r11)
34+
_restfpr_28_x: lfd %f28,-0x20(%r11)
35+
_restfpr_29_x: lfd %f29,-0x18(%r11)
36+
_restfpr_30_x: lfd %f30,-0x10(%r11)
37+
_restfpr_31_x:
38+
lwz %r0,0x4(%r11)
39+
lfd %f31,-0x8(%r11)
40+
mtlr %r0
41+
mr %sp,%r11
42+
blr
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.global _restgpr_14_x
2+
.global _restgpr_15_x
3+
.global _restgpr_16_x
4+
.global _restgpr_17_x
5+
.global _restgpr_18_x
6+
.global _restgpr_19_x
7+
.global _restgpr_20_x
8+
.global _restgpr_21_x
9+
.global _restgpr_22_x
10+
.global _restgpr_23_x
11+
.global _restgpr_24_x
12+
.global _restgpr_25_x
13+
.global _restgpr_26_x
14+
.global _restgpr_27_x
15+
.global _restgpr_28_x
16+
.global _restgpr_29_x
17+
.global _restgpr_30_x
18+
.global _restgpr_31_x
19+
20+
_restgpr_14_x: lwz %r14,-0x48(%r11)
21+
_restgpr_15_x: lwz %r15,-0x44(%r11)
22+
_restgpr_16_x: lwz %r16,-0x40(%r11)
23+
_restgpr_17_x: lwz %r17,-0x3C(%r11)
24+
_restgpr_18_x: lwz %r18,-0x38(%r11)
25+
_restgpr_19_x: lwz %r19,-0x34(%r11)
26+
_restgpr_20_x: lwz %r20,-0x30(%r11)
27+
_restgpr_21_x: lwz %r21,-0x2C(%r11)
28+
_restgpr_22_x: lwz %r22,-0x28(%r11)
29+
_restgpr_23_x: lwz %r23,-0x24(%r11)
30+
_restgpr_24_x: lwz %r24,-0x20(%r11)
31+
_restgpr_25_x: lwz %r25,-0x1C(%r11)
32+
_restgpr_26_x: lwz %r26,-0x18(%r11)
33+
_restgpr_27_x: lwz %r27,-0x14(%r11)
34+
_restgpr_28_x: lwz %r28,-0x10(%r11)
35+
_restgpr_29_x: lwz %r29,-0xC(%r11)
36+
_restgpr_30_x: lwz %r30,-0x8(%r11)
37+
_restgpr_31_x:
38+
lwz %r0,0x4(%r11)
39+
lwz %r31,-0x4(%r11)
40+
mtlr %r0
41+
mr %sp,%r11
42+
blr

0 commit comments

Comments
 (0)