@@ -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
70112int GetOriginalSize (struct GameTracker * gGT )
0 commit comments