Commit 8924ca9

Nick committed on
Fix corrupted save bug
commit 8924ca9107261a1e96f64e58524bdd486d39d2ba parent 92d34c1
4 changed files +61−9
Modifiedconstants.pas +1−1
@@ -18,7 +18,7 @@ type
18 TRoutineIndex = 0..15; 18 TRoutineIndex = 0..15;
19 19
20 const 20 const
21 UGE_FORMAT_VERSION = 4; 21 UGE_FORMAT_VERSION = 5;
22 22
23 SYM_ROW = 'row'; 23 SYM_ROW = 'row';
24 SYM_TICK = 'tick'; 24 SYM_TICK = 'tick';
ModifiedhUGETracker.lpi +1−1
@@ -231,7 +231,7 @@
231 <IsPartOfProject Value="True"/> 231 <IsPartOfProject Value="True"/>
232 </Unit1> 232 </Unit1>
233 <Unit2> 233 <Unit2>
234 <Filename Value="Cpu\z80cpu.pas"/> 234 <Filename Value="CPU\z80cpu.pas"/>
235 <IsPartOfProject Value="True"/> 235 <IsPartOfProject Value="True"/>
236 <UnitName Value="Z80CPU"/> 236 <UnitName Value="Z80CPU"/>
237 </Unit2> 237 </Unit2>
Modifiedpostbuild.bat +1−1
@@ -4,7 +4,7 @@ for /f %%i in ('where rgbasm') do set rgbasm=%%i
4 for /f %%i in ('where rgblink') do set rgblink=%%i 4 for /f %%i in ('where rgblink') do set rgblink=%%i
5 for /f %%i in ('where rgbfix') do set rgbfix=%%i 5 for /f %%i in ('where rgbfix') do set rgbfix=%%i
6 6
7 set outdir=%1 7 set outdir=Release
8 8
9 :: Build halt.gb 9 :: Build halt.gb
10 %rgbasm% -o halt.o halt.asm 10 %rgbasm% -o halt.o halt.asm
Modifiedsong.pas +58−6
@@ -80,9 +80,11 @@ type
80 Routines: TRoutineBank; 80 Routines: TRoutineBank;
81 end; 81 end;
82 82
83 TSongV5 = TSongV4; // no structural differences
84
83 { TSong } 85 { TSong }
84 86
85 TSong = TSongV4; 87 TSong = TSongV5;
86 88
87 procedure WriteSongToStream(S: TStream; const ASong: TSong); 89 procedure WriteSongToStream(S: TStream; const ASong: TSong);
88 procedure ReadSongFromStream(S: TStream; out ASong: TSong); 90 procedure ReadSongFromStream(S: TStream; out ASong: TSong);
@@ -260,13 +262,55 @@ begin
260 ASong.Routines[I] := S.ReadAnsiString; 262 ASong.Routines[I] := S.ReadAnsiString;
261 end; 263 end;
262 264
265 procedure ReadSongFromStreamV5(S: TStream; out ASong: TSongV5);
266 var
267 i, n, PatKey: Integer;
268 pat: PPattern;
269 begin
270 // Read the fixed elements first
271 n := SizeOf(TSongV5)
272 - SizeOf(TPatternMap)
273 - SizeOf(TOrderMatrix)
274 - SizeOf(TRoutineBank);
275
276 S.Read(ASong, n);
277
278 // Create the patterns
279 ASong.Patterns := TPatternMap.Create;
280 // Read the pattern count
281 S.Read(n, SizeOf(Integer));
282 for i:=0 to n - 1 do begin
283 // Read pattern key
284 S.Read(PatKey, SizeOf(Integer));
285 // Allocate memory for each pattern ...
286 New(pat);
287 // and read the pattern content
288 S.Read(pat^, SizeOf(TPattern));
289 // Add the pattern to the list
290 ASong.Patterns.Add(PatKey, pat);
291 end;
292
293 // Read the OrderMatrix
294 for i := 0 to 3 do
295 begin
296 // Read length of each OrderMatrix array
297 S.Read(n, SizeOf(Integer));
298 // Allocate memory for it
299 SetLength(ASong.OrderMatrix[i], n);
300 // Read content of OrderMatrix array
301 S.Read(ASong.OrderMatrix[i, 0], n*SizeOf(Integer));
302 end;
303
304 for I := Low(TRoutineBank) to High(TRoutineBank) do
305 ASong.Routines[I] := S.ReadAnsiString;
306 end;
307
263 procedure WriteSongToStream(S: TStream; const ASong: TSong); 308 procedure WriteSongToStream(S: TStream; const ASong: TSong);
264 var 309 var
265 i, n: Integer; 310 i, n: Integer;
266 pPat: PPattern;
267 begin 311 begin
268 // Write the fixed record elements first 312 // Write the fixed record elements first
269 n := SizeOf(TSongV4) 313 n := SizeOf(TSongV5)
270 - SizeOf(TPatternMap) 314 - SizeOf(TPatternMap)
271 - SizeOf(TOrderMatrix) 315 - SizeOf(TOrderMatrix)
272 - SizeOf(TRoutineBank); 316 - SizeOf(TRoutineBank);
@@ -277,8 +321,8 @@ begin
277 // Write the patterns 321 // Write the patterns
278 for i := 0 to ASong.Patterns.Count-1 do 322 for i := 0 to ASong.Patterns.Count-1 do
279 begin 323 begin
280 pPat := ASong.Patterns[i]; 324 S.Write(ASong.Patterns.Keys[i], SizeOf(Integer));
281 S.Write(pPat^, SizeOf(pPat^)); 325 S.Write(ASong.Patterns.Data[i]^, SizeOf(TPattern));
282 end; 326 end;
283 327
284 // Write the OrderMatrix arrays 328 // Write the OrderMatrix arrays
@@ -300,6 +344,7 @@ var
300 SV1: TSongV1; 344 SV1: TSongV1;
301 SV2: TSongV2; 345 SV2: TSongV2;
302 SV3: TSongV3; 346 SV3: TSongV3;
347 SV4: TSongV4;
303 begin 348 begin
304 S.Read(Version, SizeOf(Integer)); 349 S.Read(Version, SizeOf(Integer));
305 S.Seek(0, soBeginning); 350 S.Seek(0, soBeginning);
@@ -316,7 +361,13 @@ begin
316 ReadSongFromStreamV3(S, SV3); 361 ReadSongFromStreamV3(S, SV3);
317 ASong := UpgradeSong(SV3); 362 ASong := UpgradeSong(SV3);
318 end; 363 end;
319 4: ReadSongFromStreamV4(S, ASong); 364 4: begin
365 ReadSongFromStreamV4(S, SV4);
366 ASong := UpgradeSong(SV4);
367 end;
368 5: begin
369 ReadSongFromStreamV5(S, ASong);
370 end;
320 end; 371 end;
321 end; 372 end;
322 373
@@ -602,6 +653,7 @@ end;
602 653
603 function UpgradeSong(S: TSongV4): TSong; 654 function UpgradeSong(S: TSongV4): TSong;
604 begin 655 begin
656 S.Version := 5;
605 Result := S; 657 Result := S;
606 end; 658 end;
607 659