Skip to content

Commit aa5a1f3

Browse files
author
Niko
committed
easier to read this code
1 parent 6237899 commit aa5a1f3

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

decompile/General/LOAD/LOAD_44_TenStages.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -214,40 +214,13 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH
214214

215215
// RAM optimization, dont do this OG code
216216
#if 0
217-
218217
// OG game
219218
DECOMP_MainInit_PrimMem(gGT);
220219
DECOMP_MainInit_OTMem(gGT);
221-
222220
#else
223-
224-
// first allocate OT for RaceFlag
221+
// Reversed order, for RAM optimizations
225222
DECOMP_MainInit_OTMem(gGT);
226-
227-
228-
// use HighMem for RaceFlag, dont use MEMPACK_AllocHighMem,
229-
// then later this allocation is extended to remainder of heap,
230-
// this will always be LESS than OG game allocation, so it wont
231-
// impact any intended loading screens
232-
#ifndef REBUILD_PC
233-
234-
int backup = (int)sdata->mempack[0].firstFreeByte;
235-
236-
sdata->mempack[0].firstFreeByte =
237-
(void*)((int)sdata->mempack[0].lastFreeByte
238-
- 0xA000 // primMem needed
239-
- (0x2200*2)); // ghost HighMem
240-
241-
DECOMP_MainInit_PrimMem(gGT, 0xA000);
242-
sdata->mempack[0].firstFreeByte = (void*)backup;
243-
244-
// use low-end addressing for PC port
245-
#else
246-
247-
DECOMP_MainInit_PrimMem(gGT, 0xA000);
248-
249-
#endif
250-
223+
DECOMP_MainInit_PrimMem(gGT, 0xA000);
251224
#endif
252225

253226
// RAM Optimization, NEVER do this here,

decompile/General/MAIN/MainInit_02_PrimMem.c

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,34 @@ void DECOMP_MainInit_PrimMem(struct GameTracker* gGT, int force)
77
int GetOriginalSize(struct GameTracker* gGT);
88
int size = GetOriginalSize(gGT);
99

10+
int backup = 0;
11+
12+
// On PS1
13+
// Stage 0 allocates PrimMem to HighMem,
14+
// Stage 8 allocates PrimMem to fill rest of RAM
15+
#ifndef REBUILD_PC
16+
17+
// optimization,
18+
// LOAD_TenStages: Stage 0,
19+
// allocate HighMem for checkered flag
20+
if(force != 0)
21+
{
22+
size = force/2;
23+
24+
backup = (int)sdata->mempack[0].firstFreeByte;
25+
26+
sdata->mempack[0].firstFreeByte =
27+
(void*)((int)sdata->mempack[0].lastFreeByte
28+
- 0xA000 // primMem needed
29+
- (0x2200*2)); // ghost HighMem
30+
}
31+
1032
// optimization,
11-
// use all remaining heap for primMem,
12-
// LOAD_TenStages:Stage8
13-
if(force == 0)
33+
// LOAD_TenStages: Stage 8,
34+
// allocate all remaining RAM
35+
else
1436
{
15-
// gGT->levelID is set cause Stage8
37+
// gGT->levelID is set cause Stage 8
1638
// is past all the level load+callback
1739
if (gGT->levelID <= CITADEL_CITY)
1840
{
@@ -46,25 +68,45 @@ void DECOMP_MainInit_PrimMem(struct GameTracker* gGT, int force)
4668
size = newSize;
4769
}
4870
}
71+
72+
// On PC
73+
// Stage 0 allocates all 24-bit RAM to primitives,
74+
// Stage 8 does nothing,
75+
// The rest of LOAD_TenStages can use
76+
// 32-bit addresses above 24-bit max
77+
#else
4978

5079
// optimization,
51-
// steal OT mem during loading screen,
52-
// LOAD_TenStages:Stage0
80+
// LOAD_TenStages: Stage 0
81+
if(force != 0)
82+
{
83+
// allocate rest of 24-bit range
84+
size = 0x1000000 - (int)sdata->mempack[0].firstFreeByte;
85+
size /= 2;
86+
size -= 0x100;
87+
}
88+
89+
// optimization,
90+
// LOAD_TenStages: Stage 8,
5391
else
54-
size = force/2;
92+
{
93+
return;
94+
}
5595

56-
#ifdef REBUILD_PC
57-
// only allocate early-stage
58-
if(force == 0) return;
59-
60-
// allocate rest of 24-bit range
61-
size = 0x1000000 - (int)sdata->mempack[0].firstFreeByte;
62-
size /= 2;
63-
size -= 0x100;
6496
#endif
6597

6698
DECOMP_MainDB_PrimMem(&gGT->db[0].primMem, size);
6799
DECOMP_MainDB_PrimMem(&gGT->db[1].primMem, size);
100+
101+
#ifndef REBUILD_PC
102+
// Stage 0:
103+
// restore firstFreeByte for the rest
104+
// of the LOAD_TenStages loading system
105+
if(backup != 0)
106+
{
107+
sdata->mempack[0].firstFreeByte = (void*)backup;
108+
}
109+
#endif
68110
}
69111

70112
int GetOriginalSize(struct GameTracker* gGT)

0 commit comments

Comments
 (0)