diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index 67d71a69e7..d4cc48f096 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -1507,15 +1507,6 @@ void PostPutAction::run(MipsCall &call) { // Program signals that it has written data to the ringbuffer and gets a callback ? static u32 sceMpegRingbufferPut(u32 ringbufferAddr, int numPackets, int available) { - // Generally, program will call sceMpegRingbufferAvailableSize() before this func. - // Still need to check available? - - numPackets = std::min(numPackets, available); - if (numPackets <= 0) { - DEBUG_LOG(ME, "sceMpegRingbufferPut(%08x, %i, %i): no packets to enqueue", ringbufferAddr, numPackets, available); - return 0; - } - auto ringbuffer = PSPPointer::Create(ringbufferAddr); if (!ringbuffer.IsValid()) { // Would have crashed before, TODO test behavior. @@ -1523,6 +1514,15 @@ static u32 sceMpegRingbufferPut(u32 ringbufferAddr, int numPackets, int availabl return -1; } + numPackets = std::min(numPackets, available); + // Generally, program will call sceMpegRingbufferAvailableSize() before this func. + // Seems still need to check actual available, Patapon 3 for example. + numPackets = std::min(numPackets, ringbuffer->packets - ringbuffer->packetsAvail); + if (numPackets <= 0) { + DEBUG_LOG(ME, "sceMpegRingbufferPut(%08x, %i, %i): no packets to enqueue", ringbufferAddr, numPackets, available); + return 0; + } + MpegContext *ctx = getMpegCtx(ringbuffer->mpeg); if (!ctx) { WARN_LOG(ME, "sceMpegRingbufferPut(%08x, %i, %i): bad mpeg handle %08x", ringbufferAddr, numPackets, available, ringbuffer->mpeg);