Skip to content

Commit ff4409d

Browse files
committed
Check memory size when adding frames in..
...bankswitching NSFs - Use same channel count method in calculating frame list sizes
1 parent 15dfe00 commit ff4409d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Source/Compiler.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,7 @@ bool CCompiler::CollectLabelsBankswitched(CMap<CStringA, LPCSTR, int, int> &labe
17411741
unsigned int Track = 0;
17421742

17431743
// The switchable area is $B000-$C000
1744+
// !! !! TODO: refactor this!!!
17441745
for (CChunk *pChunk : m_vChunks) {
17451746
int Size = pChunk->CountDataSize();
17461747

@@ -1753,6 +1754,11 @@ bool CCompiler::CollectLabelsBankswitched(CMap<CStringA, LPCSTR, int, int> &labe
17531754
}
17541755
// fall through
17551756
case CHUNK_FRAME:
1757+
// Make sure frame does not exceed memory area
1758+
if (Offset + DriverSizeAndNSFDRV + Size > FixedBankMaxSize + PatternSwitchBankMaxSize) {
1759+
Offset = FixedBankMaxSize - DriverSizeAndNSFDRV;
1760+
++Bank;
1761+
}
17561762
labelMap[pChunk->GetLabel()] = Offset;
17571763
pChunk->SetBank(Bank < FixedBankPages ? ((Offset + DriverSizeAndNSFDRV) >> 12) : Bank);
17581764
Offset += Size;
@@ -2018,8 +2024,9 @@ void CCompiler::AddBankswitching()
20182024

20192025
// Frame lists sizes has changed
20202026
const int TrackCount = m_pDocument->GetTrackCount();
2027+
int Channels = m_pDocument->GetAvailableChannels(); // use same channel count method from UpdateFrameBanks()
20212028
for (int i = 0; i < TrackCount; ++i) {
2022-
m_iTrackFrameSize[i] += m_pDocument->GetChannelCount() * m_pDocument->GetFrameCount(i);
2029+
m_iTrackFrameSize[i] += Channels * m_pDocument->GetFrameCount(i);
20232030
}
20242031

20252032
// Data size has changed

0 commit comments

Comments
 (0)