From 7c7145d1c5a04a87c3f0b0d759bd4cf839bf353d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 19 Dec 2020 01:16:12 +1000 Subject: [PATCH] MDEC: Handle invalid commands Fixes panic in Formula 1. --- src/core/mdec.cpp | 20 +++++++++++++++++--- src/core/mdec.h | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/core/mdec.cpp b/src/core/mdec.cpp index 1091bbddb..5625f80ac 100644 --- a/src/core/mdec.cpp +++ b/src/core/mdec.cpp @@ -270,9 +270,9 @@ void MDEC::Execute() break; default: - Panic("Unknown command"); - num_words = 0; - new_state = State::Idle; + Log_DevPrintf("Invalid MDEC command 0x%08X", cw.bits); + num_words = cw.parameter_word_count.GetValue(); + new_state = State::NoCommand; break; } @@ -334,6 +334,20 @@ void MDEC::Execute() continue; } + case State::NoCommand: + { + // can potentially have a large amount of halfwords, so eat them as we go + const u32 words_to_consume = std::min(m_remaining_halfwords, m_data_in_fifo.GetSize()); + m_data_in_fifo.Remove(words_to_consume); + m_remaining_halfwords -= words_to_consume; + if (m_remaining_halfwords == 0) + goto finished; + + m_state = State::Idle; + UpdateStatus(); + continue; + } + default: UnreachableCode(); return; diff --git a/src/core/mdec.h b/src/core/mdec.h index 89d3eafe2..14b20d7fc 100644 --- a/src/core/mdec.h +++ b/src/core/mdec.h @@ -56,7 +56,8 @@ private: DecodingMacroblock, WritingMacroblock, SetIqTable, - SetScaleTable + SetScaleTable, + NoCommand }; union StatusRegister