@@ -152,6 +152,7 @@ bool loadIT(FILE *f, uint32_t filesize)
152
152
bool oldFormat = (itHdr .cmwt < 0x200 );
153
153
bool songUsesInstruments = !!(itHdr .flags & 4 );
154
154
bool oldEffects = !!(itHdr .flags & 16 );
155
+ bool compatGxx = !!(itHdr .flags & 32 );
155
156
156
157
// read order list
157
158
for (int32_t i = 0 ; i < MAX_ORDERS ; i ++ )
@@ -664,16 +665,21 @@ bool loadIT(FILE *f, uint32_t filesize)
664
665
songTmp .numChannels = MIN ((numChannels + 1 ) & ~1 , MAX_CHANNELS );
665
666
666
667
// convert pattern data
667
-
668
+
669
+ uint8_t lastInstr [MAX_CHANNELS ], lastGInstr [MAX_CHANNELS ];
668
670
uint8_t lastDxy [MAX_CHANNELS ], lastExy [MAX_CHANNELS ], lastFxy [MAX_CHANNELS ];
669
671
uint8_t lastJxy [MAX_CHANNELS ], lastKxy [MAX_CHANNELS ], lastLxy [MAX_CHANNELS ];
672
+ uint8_t lastOxx [MAX_CHANNELS ];
670
673
674
+ memset (lastInstr , 0 , sizeof (lastInstr ));
675
+ memset (lastGInstr , 0 , sizeof (lastGInstr ));
671
676
memset (lastDxy , 0 , sizeof (lastDxy ));
672
677
memset (lastExy , 0 , sizeof (lastExy ));
673
678
memset (lastFxy , 0 , sizeof (lastFxy ));
674
679
memset (lastJxy , 0 , sizeof (lastJxy ));
675
680
memset (lastKxy , 0 , sizeof (lastKxy ));
676
681
memset (lastLxy , 0 , sizeof (lastLxy ));
682
+ memset (lastOxx , 0 , sizeof (lastOxx ));
677
683
678
684
for (int32_t i = 0 ; i < songTmp .pattNum ; i ++ )
679
685
{
@@ -685,6 +691,9 @@ bool loadIT(FILE *f, uint32_t filesize)
685
691
{
686
692
for (int32_t ch = 0 ; ch < songTmp .numChannels ; ch ++ , p ++ )
687
693
{
694
+ if (p -> instr > 0 )
695
+ lastInstr [ch ] = p -> instr ;
696
+
688
697
// effect
689
698
if (p -> efx != 0 )
690
699
{
@@ -803,7 +812,15 @@ bool loadIT(FILE *f, uint32_t filesize)
803
812
}
804
813
break ;
805
814
806
- case 'G' : p -> efx = 3 ; break ; // tone portamento
815
+ case 'G' : // tone portamento
816
+ {
817
+ p -> efx = 3 ;
818
+
819
+ // remove illegal slides (this is not quite right, but good enough)
820
+ if (!compatGxx && p -> instr != 0 && p -> instr != lastGInstr [ch ])
821
+ p -> efx = p -> efxData = 0 ;
822
+ }
823
+ break ;
807
824
808
825
case 'H' : // vibrato
809
826
{
@@ -912,7 +929,46 @@ bool loadIT(FILE *f, uint32_t filesize)
912
929
}
913
930
break ;
914
931
915
- case 'O' : p -> efx = 0x9 ; break ; // set sample offset
932
+ case 'O' : // set sample offset
933
+ {
934
+ p -> efx = 0x9 ;
935
+
936
+ if (p -> efxData > 0 )
937
+ lastOxx [ch ] = p -> efxData ;
938
+
939
+ // handle cases where the sample offset is after the end of the sample
940
+ if (lastInstr [ch ] > 0 && lastOxx [ch ] > 0 && p -> note > 0 && p -> note <= 96 )
941
+ {
942
+ instr_t * ins = instrTmp [lastInstr [ch ]];
943
+ if (ins != NULL )
944
+ {
945
+ const uint8_t sample = ins -> note2SampleLUT [p -> note - 1 ];
946
+ if (sample < MAX_SMP_PER_INST )
947
+ {
948
+ sample_t * s = & ins -> smp [sample ];
949
+ if (s -> length > 0 )
950
+ {
951
+ const bool loopEnabled = (GET_LOOPTYPE (s -> flags ) != LOOP_DISABLED );
952
+ const uint32_t sampleEnd = loopEnabled ? s -> loopStart + s -> loopLength : s -> length ;
953
+
954
+ if (lastOxx [ch ]* 256UL >= sampleEnd )
955
+ {
956
+ if (oldEffects )
957
+ {
958
+ if (loopEnabled )
959
+ p -> efxData = (uint8_t )(sampleEnd >> 8 );
960
+ }
961
+ else
962
+ {
963
+ p -> efx = p -> efxData = 0 ;
964
+ }
965
+ }
966
+ }
967
+ }
968
+ }
969
+ }
970
+ }
971
+ break ;
916
972
917
973
case 'P' : // panning slide
918
974
{
@@ -1044,6 +1100,9 @@ bool loadIT(FILE *f, uint32_t filesize)
1044
1100
p -> efxData = 0 ;
1045
1101
}
1046
1102
1103
+ if (p -> instr != 0 && p -> efx != 0x3 )
1104
+ lastGInstr [ch ] = p -> instr ;
1105
+
1047
1106
// volume column
1048
1107
if (p -> vol > 0 )
1049
1108
{
0 commit comments