Commit 6f4d3ba

Nick Faro committed on
Fix reading order count from symbol table
commit 6f4d3bafb9878e1685641bd4fe407e976fb3bf33 parent 2aca8fd
6 changed files +35−11
Modifiedsrc/codegen.pas +3−3
@@ -366,7 +366,7 @@ begin
366 'order4, duty_instruments, wave_instruments, noise_instruments, NULL, waves};', 366 'order4, duty_instruments, wave_instruments, noise_instruments, NULL, waves};',
367 [DescriptorName, 367 [DescriptorName,
368 Song.TicksPerRow[0], Song.TicksPerRow[1], Song.TicksPerRow[2], Song.TicksPerRow[3], 368 Song.TicksPerRow[0], Song.TicksPerRow[1], Song.TicksPerRow[2], Song.TicksPerRow[3],
369 OrderCount(Song) 369 OrderCount(Song)*2
370 ])); 370 ]));
371 371
372 AssignFile(F, Filename); 372 AssignFile(F, Filename);
@@ -586,7 +586,7 @@ begin
586 +IntToStr(Song.TicksPerRow[1])+', ' 586 +IntToStr(Song.TicksPerRow[1])+', '
587 +IntToStr(Song.TicksPerRow[2])+', ' 587 +IntToStr(Song.TicksPerRow[2])+', '
588 +IntToStr(Song.TicksPerRow[3])); 588 +IntToStr(Song.TicksPerRow[3]));
589 OutSL.Add('dw '+IntToStr(OrderCount(Song))); 589 OutSL.Add('dw '+IntToStr(OrderCount(Song)*2));
590 OutSL.Add('dw order1, order2, order3, order4'); 590 OutSL.Add('dw order1, order2, order3, order4');
591 OutSL.Add('dw duty_instruments, wave_instruments, noise_instruments'); 591 OutSL.Add('dw duty_instruments, wave_instruments, noise_instruments');
592 OutSL.Add('dw routines'); 592 OutSL.Add('dw routines');
@@ -808,7 +808,7 @@ begin
808 if Assemble(Filename + '_song.obj', 808 if Assemble(Filename + '_song.obj',
809 ConcatPaths([RuntimeDir, 'hUGEDriver', 'song.asm']), 809 ConcatPaths([RuntimeDir, 'hUGEDriver', 'song.asm']),
810 ['SONG_DESCRIPTOR=song', 810 ['SONG_DESCRIPTOR=song',
811 'ORDER_COUNT='+IntToStr(OrderCount(Song)), 811 'ORDER_COUNT='+IntToStr(OrderCount(Song)*2),
812 'TICKS0='+IntToStr(Song.TicksPerRow[0]), 812 'TICKS0='+IntToStr(Song.TicksPerRow[0]),
813 'TICKS1='+IntToStr(Song.TicksPerRow[1]), 813 'TICKS1='+IntToStr(Song.TicksPerRow[1]),
814 'TICKS2='+IntToStr(Song.TicksPerRow[2]), 814 'TICKS2='+IntToStr(Song.TicksPerRow[2]),
Modifiedsrc/constants.pas +1−1
@@ -28,10 +28,10 @@ const
28 SYM_NEXT_ORDER = 'next_order'; 28 SYM_NEXT_ORDER = 'next_order';
29 SYM_ROW_BREAK = 'row_break'; 29 SYM_ROW_BREAK = 'row_break';
30 SYM_TICKS_PER_ROW = 'ticks_per_row'; 30 SYM_TICKS_PER_ROW = 'ticks_per_row';
31 SYM_ORDER_COUNT = 'order_cnt';
32 SYM_LOOP_ORDER = 'loop_order'; 31 SYM_LOOP_ORDER = 'loop_order';
33 SYM_SINGLE_STEPPING = 'single_stepping'; 32 SYM_SINGLE_STEPPING = 'single_stepping';
34 SYM_SINGLE_STEP_STOPPED = 'single_step_stopped'; 33 SYM_SINGLE_STEP_STOPPED = 'single_step_stopped';
34 SYM_SONG_DESCRIPTOR = 'song_descriptor';
35 35
36 SYM_HALT_INSTR = 'instrument'; 36 SYM_HALT_INSTR = 'instrument';
37 SYM_HALT_PERIOD = 'channel_period'; 37 SYM_HALT_PERIOD = 'channel_period';
Modifiedsrc/rendertowave.pas +2−2
@@ -274,7 +274,7 @@ begin
274 FCCallback := @OrderCheckCallback; 274 FCCallback := @OrderCheckCallback;
275 FDCallback := nil; 275 FDCallback := nil;
276 276
277 SetLength(SeenPatterns, PeekSymbol(SYM_ORDER_COUNT) div 2); 277 SetLength(SeenPatterns, PeekSymbol(SYM_SONG_DESCRIPTOR, 4) div 2);
278 StartOfSong := -1; 278 StartOfSong := -1;
279 CurrentPattern := -1; 279 CurrentPattern := -1;
280 280
@@ -299,7 +299,7 @@ begin
299 FCCallback := @OrderCheckCallback; 299 FCCallback := @OrderCheckCallback;
300 FDCallback := nil; 300 FDCallback := nil;
301 301
302 SetLength(SeenPatterns, PeekSymbol(SYM_ORDER_COUNT) div 2); 302 SetLength(SeenPatterns, PeekSymbol(SYM_SONG_DESCRIPTOR, 4) div 2);
303 StartOfSong := -1; 303 StartOfSong := -1;
304 CurrentPattern := -1; 304 CurrentPattern := -1;
305 StartPattern := FromPositionLowerSpinEdit.Value; 305 StartPattern := FromPositionLowerSpinEdit.Value;
Modifiedsrc/song.pas +25−1
@@ -143,6 +143,8 @@ function UpgradeSong(S: TSongV4): TSong; overload;
143 function UpgradeSong(S: TSongV6): TSong; overload; 143 function UpgradeSong(S: TSongV6): TSong; overload;
144 144
145 function OptimizeSong(const S: TSong): TSong; 145 function OptimizeSong(const S: TSong): TSong;
146 function PatternIsUsed(Idx: Integer; const Song: TSong): Boolean;
147 function OrderCount(const Song: TSong): Integer;
146 148
147 implementation 149 implementation
148 150
@@ -941,5 +943,27 @@ begin
941 end; 943 end;
942 end; 944 end;
943 945
944 end. 946 <<<<<<< HEAD
947 =======
948 function PatternIsUsed(Idx: Integer; const Song: TSong): Boolean;
949 var
950 I, J: Integer;
951 begin
952 for I := Low(Song.OrderMatrix) to High(Song.OrderMatrix) do
953 for J := Low(Song.OrderMatrix[I]) to High(Song.OrderMatrix[I])-1 do
954 if Song.OrderMatrix[I, J] = Idx then Exit(True);
955
956 Result := False;
957 end;
945 958
959 function OrderCount(const Song: TSong): Integer;
960 var
961 OrderMatrix: TOrderMatrix;
962 begin
963 OrderMatrix := Song.OrderMatrix;
964 Result := MaxIntValue([High(OrderMatrix[0]), High(OrderMatrix[1]),
965 High(OrderMatrix[2]), High(OrderMatrix[3])]);
966 end;
967
968 >>>>>>> 71f550f (Fix reading order count from symbol table)
969 end.
Modifiedsrc/symparser.pas +3−3
@@ -13,7 +13,7 @@ type
13 function SymbolAddress(Symbol: String): Integer; 13 function SymbolAddress(Symbol: String): Integer;
14 function WordPeekSymbol(Symbol: String): Integer; 14 function WordPeekSymbol(Symbol: String): Integer;
15 procedure WordPokeSymbol(Symbol: String; Value: Word); 15 procedure WordPokeSymbol(Symbol: String; Value: Word);
16 function PeekSymbol(Symbol: String): Integer; 16 function PeekSymbol(Symbol: String; Offset: Integer = 0): Integer;
17 procedure PokeSymbol(Symbol: String; Value: Byte); 17 procedure PokeSymbol(Symbol: String; Value: Byte);
18 procedure WriteBufferToSymbol(Symbol: String; const Buffer; Count: Integer); 18 procedure WriteBufferToSymbol(Symbol: String; const Buffer; Count: Integer);
19 procedure WriteBufferToAddress(Address: Integer; const Buffer; Count: Integer); 19 procedure WriteBufferToAddress(Address: Integer; const Buffer; Count: Integer);
@@ -132,14 +132,14 @@ begin
132 end; 132 end;
133 end; 133 end;
134 134
135 function PeekSymbol(Symbol: String): Integer; 135 function PeekSymbol(Symbol: String; Offset: Integer = 0): Integer;
136 begin 136 begin
137 if SymbolTable.IndexOf(Symbol) = -1 then begin 137 if SymbolTable.IndexOf(Symbol) = -1 then begin
138 DebugLn(['[WARNING] Attempting to peek unloaded symbol: ', symbol]); 138 DebugLn(['[WARNING] Attempting to peek unloaded symbol: ', symbol]);
139 Exit(0); 139 Exit(0);
140 end; 140 end;
141 141
142 Result := speekb(SymbolTable.KeyData[Symbol]); 142 Result := speekb(SymbolTable.KeyData[Symbol]+Offset);
143 end; 143 end;
144 144
145 procedure PokeSymbol(Symbol: String; Value: Byte); 145 procedure PokeSymbol(Symbol: String; Value: Byte);
Modifiedsrc/vgm.pas +1−1
@@ -136,7 +136,7 @@ begin
136 enablesound; 136 enablesound;
137 load(ConcatPaths([CacheDir, 'render/preview.gb'])); 137 load(ConcatPaths([CacheDir, 'render/preview.gb']));
138 138
139 SetLength(SeenOrders, PeekSymbol(SYM_ORDER_COUNT) div 2); 139 SetLength(SeenOrders, PeekSymbol(SYM_SONG_DESCRIPTOR, 4) div 2);
140 StartOfSong := -1; 140 StartOfSong := -1;
141 141
142 WritingVGM := True; 142 WritingVGM := True;