Skip to content

Commit

Permalink
Fix detection of highest waveform
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperDisk committed Dec 29, 2024
1 parent c4fa072 commit 0623f3f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/codegen.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function FindUsedStuff(const Song: TSong): TUsedStuff;
I, J: Integer;
Pat: PPattern;
Cell: TCell;
Instr: TInstrument;
InstValue: Integer;
Highest: ^Integer;
Waveform: Integer;
Expand All @@ -57,6 +58,17 @@ function FindUsedStuff(const Song: TSong): TUsedStuff;
Result.HighestNoiseInst := -1;
Result.HighestWaveform := -1;

for Instr in Song.Instruments.Wave do begin
if not Instr.SubpatternEnabled then Continue;

for Cell in Instr.Subpattern do
if Cell.EffectCode = $9 then begin
Waveform := Cell.EffectParams.Value;
if Waveform > Result.HighestWaveform then
Result.HighestWaveform := Waveform;
end;
end;

for I := Low(Song.OrderMatrix) to High(Song.OrderMatrix) do begin
case I of
0, 1: Highest := @Result.HighestDutyInst;
Expand All @@ -71,6 +83,12 @@ function FindUsedStuff(const Song: TSong): TUsedStuff;

Pat := Song.Patterns.KeyData[Song.OrderMatrix[I, J]];
for Cell in Pat^ do begin
if (Cell.EffectCode = $9) and (I = 2) then begin // waveforms on wave channel
Waveform := Cell.EffectParams.Value;
if Waveform > Result.HighestWaveform then
Result.HighestWaveform := Waveform;
end;

if Cell.Instrument = 0 then Continue;

if InRange(Cell.Instrument, 0, 15) then
Expand Down

0 comments on commit 0623f3f

Please sign in to comment.