diff --git a/Common/ConsoleListener.cpp b/Common/ConsoleListener.cpp index 7bff1714d0..56ba1d8631 100644 --- a/Common/ConsoleListener.cpp +++ b/Common/ConsoleListener.cpp @@ -37,7 +37,6 @@ const int LOG_PENDING_MAX = 120 * 10000; const int LOG_LATENCY_DELAY_MS = 20; const int LOG_SHUTDOWN_DELAY_MS = 250; const int LOG_MAX_DISPLAY_LINES = 4000; -const int LOG_MAX_LINE_LENGTH = 480; #endif ConsoleListener::ConsoleListener() @@ -270,7 +269,7 @@ void ConsoleListener::LogWriterThread() const int count = logRemotePos - logPendingReadPos; memcpy(logLocal + start, logPending + logPendingReadPos, count); - logPendingReadPos = count; + logPendingReadPos += count; LeaveCriticalSection(&criticalSection); // Double check. @@ -315,42 +314,51 @@ void ConsoleListener::SendToThread(LogTypes::LOG_LEVELS Level, const char *Text) return; size_t Len = strlen(Text); + if (Len > LOG_PENDING_MAX) + Len = LOG_PENDING_MAX - 16; char ColorAttr[16] = ""; + int ColorLen = 0; if (bUseColor) { // Not ANSI, since the console doesn't support it, but ANSI-like. snprintf(ColorAttr, 16, "\033%d", Level); // For now, rather than properly support it. _dbg_assert_msg_(COMMON, strlen(ColorAttr) == 2, "Console logging doesn't support > 9 levels."); - Len += strlen(ColorAttr); + ColorLen = strlen(ColorAttr); } EnterCriticalSection(&criticalSection); u32 logWritePos = Common::AtomicLoad(logPendingWritePos); u32 prevLogWritePos = logWritePos; - if (logWritePos + Len >= LOG_PENDING_MAX) + if (logWritePos + ColorLen + Len >= LOG_PENDING_MAX) { - // One line shouldn't be this long... - char temp[LOG_MAX_LINE_LENGTH]; - snprintf(temp, LOG_MAX_LINE_LENGTH, "%s%s", ColorAttr, Text); + for (u32 i = 0; i < ColorLen; ++i) + logPending[(logWritePos + i) % LOG_PENDING_MAX] = ColorAttr[i]; + logWritePos += ColorLen; + if (logWritePos >= LOG_PENDING_MAX) + logWritePos -= LOG_PENDING_MAX; int start = 0; - if (logWritePos < LOG_PENDING_MAX) + if (logWritePos < LOG_PENDING_MAX && logWritePos + Len >= LOG_PENDING_MAX) { const int count = LOG_PENDING_MAX - logWritePos; - memcpy(logPending + logWritePos, temp, count); + memcpy(logPending + logWritePos, Text, count); start = count; logWritePos = 0; } const int count = Len - start; - memcpy(logPending + logWritePos, temp + start, count); - logWritePos += count; + if (count > 0) + { + memcpy(logPending + logWritePos, Text + start, count); + logWritePos += count; + } } else { - snprintf(logPending + logWritePos, LOG_PENDING_MAX - logWritePos, "%s%s", ColorAttr, Text); - logWritePos += Len; + memcpy(logPending + logWritePos, ColorAttr, ColorLen); + memcpy(logPending + logWritePos + ColorLen, Text, Len); + logWritePos += ColorLen + Len; } // Oops, we passed the read pos. diff --git a/Common/x64Emitter.cpp b/Common/x64Emitter.cpp index a423f03762..516dfa5fb6 100644 --- a/Common/x64Emitter.cpp +++ b/Common/x64Emitter.cpp @@ -163,7 +163,7 @@ void OpArg::WriteRex(XEmitter *emit, int opBits, int bits, int customOp) const _dbg_assert_(DYNA_REC, (indexReg & 8) == 0); _dbg_assert_(DYNA_REC, (offsetOrBaseReg & 8) == 0); _dbg_assert_(DYNA_REC, opBits != 8 || (customOp & 0x10c) != 4 || customOp == -1); - _dbg_assert_(DYNA_REC, bits != 8 || (offsetOrBaseReg & 0x10c) != 4); + _dbg_assert_(DYNA_REC, scale == SCALE_ATREG || bits != 8 || (offsetOrBaseReg & 0x10c) != 4); #endif } diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index 9080c47727..428482e36f 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -108,6 +108,7 @@ void __AudioShutdown() u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) { + u32 ret = 0; section.lock(); if (chan.sampleAddress == 0) return SCE_ERROR_AUDIO_NOT_OUTPUT; @@ -146,6 +147,8 @@ u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) for (u32 i = 0; i < totalSamples; i++) chan.sampleQueue.push((s16)Memory::Read_U16(chan.sampleAddress + sizeof(s16) * i)); } + + ret = chan.sampleCount; } else if (chan.format == PSP_AUDIO_FORMAT_MONO) { @@ -156,9 +159,11 @@ u32 __AudioEnqueue(AudioChannel &chan, int chanNum, bool blocking) chan.sampleQueue.push(sample); chan.sampleQueue.push(sample); } + + ret = chan.sampleCount; } section.unlock(); - return 0; + return ret; } // Mix samples from the various audio channels into a single sample queue. @@ -205,7 +210,7 @@ void __AudioUpdate() SceUID waitingThread = chans[i].waitingThread; chans[i].waitingThread = 0; // DEBUG_LOG(HLE, "Woke thread %i for some buffer filling", waitingThread); - __KernelResumeThreadFromWait(waitingThread); + __KernelResumeThreadFromWait(waitingThread, chans[i].sampleCount); } } } diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index f42e7b9acb..761f057004 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -34,17 +34,68 @@ #define PSP_MODE_AT_3_PLUS 0x00001000 #define PSP_MODE_AT_3 0x00001001 -struct Atrac { +const u32 ATRAC_MAX_SAMPLES = 1024; +struct Atrac { + Atrac() : decodePos(0), buffer(0), bufferSize(0), loopNum(0) {} + void DoState(PointerWrap &p) { + p.Do(decodePos); + p.Do(buffer); + p.Do(bufferSize); + p.Do(loopNum); + p.DoMarker("Atrac"); + } + + u32 decodePos; + u32 buffer; + u32 bufferSize; + int loopNum; }; -Atrac globalAtrac; +std::map atracMap; + +void __AtracInit() +{ +} + +void __AtracDoState(PointerWrap &p) { + int n = (int) atracMap.size(); + p.Do(n); + if (p.mode == p.MODE_READ) { + for (auto it = atracMap.begin(), end = atracMap.end(); it != end; ++it) { + delete it->second; + } + atracMap.clear(); + + for (int i = 0; i < n; ++i) { + int key; + p.Do(key); + Atrac *atrac = new Atrac; + atrac->DoState(p); + atracMap[key] = atrac; + } + } else { + for (auto it = atracMap.begin(), end = atracMap.end(); it != end; ++it) { + p.Do(it->first); + it->second->DoState(p); + } + } + + p.DoMarker("sceAtrac"); +} + +void __AtracShutdown() +{ + for (auto it = atracMap.begin(), end = atracMap.end(); it != end; ++it) { + delete it->second; + } + atracMap.clear(); +} // Temporary workaround to prevent excessive logging making games very slow. // This is just the default cycle / 10, so about 1/10 second. const u64 atracLogTickFrequency = 22200; -static bool atracShouldLogUnimpl(u64 &lastTicks) -{ +static bool atracShouldLogUnimpl(u64 &lastTicks) { u64 ticks = CoreTiming::GetTicks(); bool result = ticks - lastTicks >= atracLogTickFrequency; lastTicks = ticks; @@ -56,12 +107,23 @@ static bool atracShouldLogUnimpl(u64 &lastTicks) #define ERROR_LOG_LIMITED(t, ...) { static u64 limited__lastTicks = 0; if (atracShouldLogUnimpl(limited__lastTicks)) ERROR_LOG(t, __VA_ARGS__); } //#define ERROR_LOG_LIMITED(t, ...) { ERROR_LOG(t, __VA_ARGS__); } -// TODO: Properly. Atrac *getAtrac(int atracID) { - if (atracID == 1) { - return &globalAtrac; - } else { - return 0; + if (atracMap.find(atracID) == atracMap.end()) { + return NULL; + } + return atracMap[atracID]; +} + +int createAtrac(Atrac *atrac) { + int id = (int) atracMap.size(); + atracMap[id] = atrac; + return id; +} + +void deleteAtrac(int atracID) { + if (atracMap.find(atracID) != atracMap.end()) { + delete atracMap[atracID]; + atracMap.erase(atracID); } } @@ -78,7 +140,7 @@ int getCodecType(int addr) { u32 sceAtracGetAtracID(int codecType) { ERROR_LOG_LIMITED(HLE, "FAKE sceAtracGetAtracID(%i)", codecType); - return 1; + return createAtrac(new Atrac); } u32 sceAtracAddStreamData(int atracID, u32 bytesToAdd) @@ -95,14 +157,56 @@ u32 sceAtracAddStreamData(int atracID, u32 bytesToAdd) u32 sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishFlagAddr, u32 remainAddr) { ERROR_LOG_LIMITED(HLE, "FAKE sceAtracDecodeData(%i, %08x, %08x, %08x, %08x)", atracID, outAddr, numSamplesAddr, finishFlagAddr, remainAddr); - Memory::Write_U16(0, outAddr); // Write a single 16-bit stereo - Memory::Write_U16(0, outAddr + 2); + Atrac *atrac = getAtrac(atracID); - Memory::Write_U32(1, numSamplesAddr); - Memory::Write_U32(1, finishFlagAddr); // Lie that decoding is finished - Memory::Write_U32(0, remainAddr); // Lie that decoding is finished + u32 ret = 0; + if (atrac != NULL) { + // We already passed the end - return an error (many games check for this.) + if (atrac->decodePos >= atrac->bufferSize && atrac->loopNum == 0) { + Memory::Write_U32(0, numSamplesAddr); + Memory::Write_U32(1, finishFlagAddr); + Memory::Write_U32(0, remainAddr); - return 0; + ret = ATRAC_ERROR_ALL_DATA_DECODED; + } else { + // TODO: This isn't at all right, but at least it makes the music "last" some time. + u32 numSamples = (atrac->bufferSize - atrac->decodePos) / (sizeof(s16) * 2); + if (numSamples > ATRAC_MAX_SAMPLES) { + numSamples = ATRAC_MAX_SAMPLES; + } + + // Should we loop? + if (numSamples == 0 && atrac->loopNum != 0) { + // Restart. + atrac->decodePos = 0; + if (atrac->loopNum > 0) + atrac->loopNum--; + numSamples = ATRAC_MAX_SAMPLES; + } + + Memory::Memset(outAddr, 0, numSamples * sizeof(s16) * 2); + Memory::Write_U32(numSamples, numSamplesAddr); + atrac->decodePos += ATRAC_MAX_SAMPLES; + + if (numSamples == 0) { + Memory::Write_U32(1, finishFlagAddr); + Memory::Write_U32(-1, remainAddr); + } else { + Memory::Write_U32(0, finishFlagAddr); + Memory::Write_U32(-1, remainAddr); + } + } + // TODO: Can probably remove this after we validate no wrong ids? + } else { + Memory::Write_U16(0, outAddr); // Write a single 16-bit stereo + Memory::Write_U16(0, outAddr + 2); + + Memory::Write_U32(1, numSamplesAddr); + Memory::Write_U32(1, finishFlagAddr); // Lie that decoding is finished + Memory::Write_U32(-1, remainAddr); // Lie that decoding is finished + } + + return ret; } u32 sceAtracEndEntry() @@ -116,10 +220,17 @@ u32 sceAtracGetBufferInfoForReseting(int atracID, int sample, u32 bufferInfoAddr ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracGetBufferInfoForReseting(%i, %i, %08x)",atracID, sample, bufferInfoAddr); Atrac *atrac = getAtrac(atracID); if (!atrac) { + // TODO: Write the right stuff instead. + Memory::Memset(bufferInfoAddr, 0, 32); //return -1; + } else { + Memory::Write_U32(atrac->buffer, bufferInfoAddr); + Memory::Write_U32(atrac->bufferSize, bufferInfoAddr + 4); + Memory::Write_U32(0, bufferInfoAddr + 8); + Memory::Write_U32(0, bufferInfoAddr + 12); + // TODO: Write the right stuff instead. + Memory::Memset(bufferInfoAddr + 16, 0, 16); } - // TODO: Write the right stuff instead. - Memory::Memset(bufferInfoAddr, 0, 32); return 0; } @@ -177,7 +288,7 @@ u32 sceAtracGetMaxSample(int atracID, u32 maxSamplesAddr) //return -1; } if (Memory::IsValidAddress(maxSamplesAddr)) - Memory::Write_U32(1024, maxSamplesAddr); + Memory::Write_U32(ATRAC_MAX_SAMPLES, maxSamplesAddr); return 0; } @@ -188,7 +299,7 @@ u32 sceAtracGetNextDecodePosition(int atracID, u32 outposAddr) if (!atrac) { //return -1; } - Memory::Write_U32(1, outposAddr); // outpos + Memory::Write_U32(atrac != NULL ? atrac->decodePos : 0, outposAddr); // outpos return 0; } @@ -198,19 +309,29 @@ u32 sceAtracGetNextSample(int atracID, u32 outNAddr) Atrac *atrac = getAtrac(atracID); if (!atrac) { //return -1; + Memory::Write_U32(1, outNAddr); + } else { + if (atrac->decodePos >= atrac->bufferSize) { + Memory::Write_U32(0, outNAddr); + } else { + // TODO: This is not correct. + u32 numSamples = (atrac->bufferSize - atrac->decodePos) / (sizeof(s16) * 2); + Memory::Write_U32(numSamples, outNAddr); + } } - Memory::Write_U32(0, outNAddr); return 0; } -u32 sceAtracGetRemainFrame(int atracID, u32 outposAddr) +u32 sceAtracGetRemainFrame(int atracID, u32 remainAddr) { - ERROR_LOG_LIMITED(HLE, "sceAtracGetRemainFrame(%i, %08x)", atracID, outposAddr); + ERROR_LOG_LIMITED(HLE, "sceAtracGetRemainFrame(%i, %08x)", atracID, remainAddr); Atrac *atrac = getAtrac(atracID); if (!atrac) { //return -1; + Memory::Write_U32(12, remainAddr); // outpos + } else { + Memory::Write_U32(-1, remainAddr); } - Memory::Write_U32(12, outposAddr); // outpos return 0; } @@ -246,7 +367,7 @@ u32 sceAtracGetStreamDataInfo(int atracID, u32 writePointerAddr, u32 availableBy if (!atrac) { //return -1; } - Memory::Write_U32(0, readOffsetAddr); + Memory::Write_U32(atrac ? atrac->buffer : 0, readOffsetAddr); Memory::Write_U32(0, availableBytesAddr); Memory::Write_U32(0, writePointerAddr); return 0; @@ -255,6 +376,7 @@ u32 sceAtracGetStreamDataInfo(int atracID, u32 writePointerAddr, u32 availableBy u32 sceAtracReleaseAtracID(int atracID) { ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracReleaseAtracID(%i)", atracID); + deleteAtrac(atracID); return 0; } @@ -264,6 +386,9 @@ u32 sceAtracResetPlayPosition(int atracID, int sample, int bytesWrittenFirstBuf, Atrac *atrac = getAtrac(atracID); if (!atrac) { //return -1; + } else { + // TODO: Not sure what this means? + atrac->decodePos = sample; } return 0; } @@ -287,6 +412,11 @@ u32 sceAtracSetSecondBuffer(int atracID, u32 secondBuffer, u32 secondBufferSize) u32 sceAtracSetData(int atracID, u32 buffer, u32 bufferSize) { ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracSetData(%i, %08x, %08x)", atracID, buffer, bufferSize); + Atrac *atrac = getAtrac(atracID); + if (atrac != NULL) { + atrac->buffer = buffer; + atrac->bufferSize = bufferSize; + } return 0; } @@ -294,14 +424,22 @@ int sceAtracSetDataAndGetID(u32 buffer, u32 bufferSize) { ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracSetDataAndGetID(%08x, %08x)", buffer, bufferSize); int codecType = getCodecType(buffer); - return 1; + + Atrac *atrac = new Atrac(); + atrac->buffer = buffer; + atrac->bufferSize = bufferSize; + return createAtrac(atrac); } int sceAtracSetHalfwayBufferAndGetID(int atracID, u32 halfBuffer, u32 readSize, u32 halfBufferSize) { ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracSetHalfwayBufferAndGetID(%i, %08x, %08x, %08x)", atracID, halfBuffer, readSize, halfBufferSize); int codecType = getCodecType(halfBuffer); - return 1; + + Atrac *atrac = new Atrac(); + atrac->buffer = halfBuffer; + atrac->bufferSize = halfBufferSize; + return createAtrac(atrac); } u32 sceAtracStartEntry() @@ -313,6 +451,10 @@ u32 sceAtracStartEntry() u32 sceAtracSetLoopNum(int atracID, int loopNum) { ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracSetLoopNum(%i, %i)", atracID, loopNum); + Atrac *atrac = getAtrac(atracID); + if (atrac) { + atrac->loopNum = loopNum; + } return 0; } @@ -354,7 +496,11 @@ int sceAtracSetAA3DataAndGetID(u32 buffer, int bufferSize, int fileSize, u32 met { ERROR_LOG_LIMITED(HLE, "UNIMPL sceAtracSetAA3DataAndGetID(%08x, %i, %i, %08x)", buffer, bufferSize, fileSize, metadataSizeAddr); int codecType = getCodecType(buffer); - return 1; + + Atrac *atrac = new Atrac(); + atrac->buffer = buffer; + atrac->bufferSize = bufferSize; + return createAtrac(atrac); } const HLEFunction sceAtrac3plus[] = diff --git a/Core/HLE/sceAtrac.h b/Core/HLE/sceAtrac.h index 9da361beae..04cba8bd89 100644 --- a/Core/HLE/sceAtrac.h +++ b/Core/HLE/sceAtrac.h @@ -17,4 +17,9 @@ #pragma once +#include "../Common/ChunkFile.h" + void Register_sceAtrac3plus(); +void __AtracInit(); +void __AtracDoState(PointerWrap &p); +void __AtracShutdown(); \ No newline at end of file diff --git a/Core/HLE/sceAudio.cpp b/Core/HLE/sceAudio.cpp index 80b9d9c35f..00fa063cc3 100644 --- a/Core/HLE/sceAudio.cpp +++ b/Core/HLE/sceAudio.cpp @@ -130,19 +130,16 @@ int sceAudioGetChannelRestLength(u32 chan) { return (int)chans[chan].sampleQueue.size() / 2; } -static int GetFreeChannel() { - for (int i = 0; i < PSP_AUDIO_CHANNEL_MAX ; i++) +static u32 GetFreeChannel() { + for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX ; i++) if (!chans[i].reserved) return i; return -1; } u32 sceAudioChReserve(u32 chan, u32 sampleCount, u32 format) { - if (chan == (u32)-1) { + if (chan == (u32)-1) { chan = GetFreeChannel(); - } else { - ERROR_LOG(HLE,"sceAudioChReserve - reserve channel failed"); - return SCE_ERROR_AUDIO_NO_CHANNELS_AVAILABLE; } if (chan >= PSP_AUDIO_CHANNEL_MAX) { ERROR_LOG(HLE ,"sceAudioChReserve(%08x, %08x, %08x) - bad channel", chan, sampleCount, format); @@ -152,8 +149,9 @@ u32 sceAudioChReserve(u32 chan, u32 sampleCount, u32 format) { ERROR_LOG(HLE, "sceAudioChReserve(%08x, %08x, %08x) - invalid format", chan, sampleCount, format); return SCE_ERROR_AUDIO_INVALID_FORMAT; } - if (chans[chan].reserved) { - WARN_LOG(HLE, "WARNING: Reserving already reserved channel."); + if (chans[chan].reserved) { + ERROR_LOG(HLE,"sceAudioChReserve - reserve channel failed"); + return SCE_ERROR_AUDIO_NO_CHANNELS_AVAILABLE; } DEBUG_LOG(HLE, "sceAudioChReserve(%08x, %08x, %08x)", chan, sampleCount, format); diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index ca8571be2b..75d40d8f35 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -31,6 +31,7 @@ #include "__sceAudio.h" +#include "sceAtrac.h" #include "sceAudio.h" #include "sceCtrl.h" #include "sceDisplay.h" @@ -93,6 +94,7 @@ void __KernelInit() __IoInit(); __AudioInit(); __SasInit(); + __AtracInit(); __DisplayInit(); __GeInit(); __PowerInit(); @@ -134,6 +136,7 @@ void __KernelShutdown() __GeShutdown(); __SasShutdown(); __DisplayShutdown(); + __AtracShutdown(); __AudioShutdown(); __IoShutdown(); __KernelMutexShutdown(); @@ -164,6 +167,7 @@ void __KernelDoState(PointerWrap &p) __KernelSemaDoState(p); __KernelTimeDoState(p); + __AtracDoState(p); __AudioDoState(p); __CtrlDoState(p); __DisplayDoState(p); diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index c51bd05622..8a7f1e6ad5 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -845,7 +845,87 @@ u32 sceMpegAvcDecodeStopYCbCr(u32 mpeg, u32 bufferAddr, u32 statusAddr) int sceMpegAvcDecodeYCbCr(u32 mpeg, u32 auAddr, u32 bufferAddr, u32 initAddr) { - ERROR_LOG(HLE, "UNIMPL sceMpegAvcDecodeYCbCr(%08x, %08x, %08x, %08x)", mpeg, auAddr, bufferAddr, initAddr); + MpegContext *ctx = getMpegCtx(mpeg); + if (!ctx) { + WARN_LOG(HLE, "sceMpegAvcDecodeYCbCr(%08x, %08x, %d, %08x, %08x): bad mpeg handle", mpeg, auAddr, bufferAddr, initAddr); + return 0; + } + + if (!Memory::IsValidAddress(auAddr) || !Memory::IsValidAddress(bufferAddr) || !Memory::IsValidAddress(initAddr)) { + ERROR_LOG(HLE, "sceMpegAvcDecodeYCbCr: bad addresses"); + return 0; + } + + SceMpegAu avcAu; + avcAu.read(auAddr); + + SceMpegRingBuffer ringbuffer; + Memory::ReadStruct(ctx->mpegRingbufferAddr, &ringbuffer); + + if (ringbuffer.packetsRead == 0) { + // empty! + return MPEG_AVC_DECODE_ERROR_FATAL; + } + + u32 buffer = Memory::Read_U32(bufferAddr); + u32 init = Memory::Read_U32(initAddr); + DEBUG_LOG(HLE, "*buffer = %08x, *init = %08x", buffer, init); + + int packetsInRingBuffer = ringbuffer.packets - ringbuffer.packetsFree; + int processedPackets = ringbuffer.packetsRead - packetsInRingBuffer; + int processedSize = processedPackets * ringbuffer.packetSize; + + int packetsConsumed = 3; + if (ctx->mpegStreamSize > 0 && ctx->mpegLastTimestamp > 0) { + // Try a better approximation of the packets consumed based on the timestamp + int processedSizeBasedOnTimestamp = (int) ((((float) avcAu.pts) / ctx->mpegLastTimestamp) * ctx->mpegStreamSize); + if (processedSizeBasedOnTimestamp < processedSize) { + packetsConsumed = 0; + } else { + packetsConsumed = (processedSizeBasedOnTimestamp - processedSize) / ringbuffer.packetSize; + if (packetsConsumed > 10) { + packetsConsumed = 10; + } + } + DEBUG_LOG(HLE, "sceMpegAvcDecodeYCbCr consumed %d %d/%d %d", processedSizeBasedOnTimestamp, processedSize, ctx->mpegStreamSize, packetsConsumed); + } + + if (ctx->mediaengine->stepVideo()) { + // TODO: Write it somewhere or buffer it or something? + packetsConsumed += ctx->mediaengine->readLength() / ringbuffer.packetSize; + + // Consuming all the remaining packets? + if (ringbuffer.packetsFree + packetsConsumed >= ringbuffer.packets) { + // Having not yet reached the last timestamp? + if (ctx->mpegLastTimestamp > 0 && avcAu.pts < ctx->mpegLastTimestamp) { + // Do not yet consume all the remaining packets. + packetsConsumed = 0; + } + } + ctx->mediaengine->setReadLength(ctx->mediaengine->readLength() - packetsConsumed * ringbuffer.packetSize); + } else { + // Consume all remaining packets + packetsConsumed = ringbuffer.packets - ringbuffer.packetsFree; + } + ctx->avc.avcFrameStatus = 1; + ctx->videoFrameCount++; + + // Update the ringbuffer with the consumed packets + if (ringbuffer.packetsFree < ringbuffer.packets && packetsConsumed > 0) { + ringbuffer.packetsFree = std::min(ringbuffer.packets, ringbuffer.packetsFree + packetsConsumed); + DEBUG_LOG(HLE, "sceMpegAvcDecodeYCbCr consumed %d packets, remaining %d packets", packetsConsumed, ringbuffer.packets - ringbuffer.packetsFree); + } + + ctx->avc.avcDecodeResult = MPEG_AVC_DECODE_SUCCESS; + + // Flush structs back to memory + avcAu.write(auAddr); + Memory::WriteStruct(ctx->mpegRingbufferAddr, &ringbuffer); + + Memory::Write_U32(ctx->avc.avcFrameStatus, initAddr); // 1 = showing, 0 = not showing + + DEBUG_LOG(HLE, "UNIMPL sceMpegAvcDecodeYCbCr(%08x, %08x, %08x, %08x)", mpeg, auAddr, bufferAddr, initAddr); + return 0; } @@ -1201,6 +1281,8 @@ u32 sceMpegAvcCopyYCbCr(u32 mpeg, u32 sourceAddr, u32 YCbCrAddr) u32 sceMpegAtracDecode(u32 mpeg, u32 auAddr, u32 bufferAddr, int init) { ERROR_LOG(HLE, "UNIMPL sceMpegAtracDecode(%08x, %08x, %08x, %i)", mpeg, auAddr, bufferAddr, init); + if (Memory::IsValidAddress(bufferAddr)) + Memory::Memset(bufferAddr, 0, MPEG_ATRAC_ES_OUTPUT_SIZE); return 0; } diff --git a/Core/HLE/scePower.cpp b/Core/HLE/scePower.cpp index 2113355baf..920e8a8dc5 100644 --- a/Core/HLE/scePower.cpp +++ b/Core/HLE/scePower.cpp @@ -246,6 +246,11 @@ u32 scePowerGetBusClockFrequencyInt() { return freq; } +// a85880d0, unknown name +u32 IsPSPNonFat() { + return 0; // Fat PSP! +} + static const HLEFunction scePower[] = { {0x04B7766E,&WrapI_II,"scePowerRegisterCallback"}, {0x2B51FE2F,0,"scePower_2B51FE2F"}, @@ -295,8 +300,8 @@ static const HLEFunction scePower[] = { {0x34f9c463,WrapU_V,"scePowerGetPllClockFrequencyInt"}, {0xea382a27,0,"scePowerGetPllClockFrequencyFloat"}, {0xebd177d6,WrapV_UUU,"scePower_driver_EBD177D6"}, //TODO: used in a few places, jpcsp says is the same as scePowerSetClockFrequency - {0x469989ad,0,"scePower_469989ad"}, - {0xa85880d0,0,"scePower_a85880d0"}, + {0x469989ad,WrapV_UUU,"scePower_469989ad"}, // This is also the same as SetClockFrequency + {0xa85880d0,WrapU_V,"scePower_a85880d0_IsPSPNonFat"}, }; //890129c in tyshooter looks bogus diff --git a/Core/HLE/sceUtility.cpp b/Core/HLE/sceUtility.cpp index 50f571ac03..8a1fa235c2 100644 --- a/Core/HLE/sceUtility.cpp +++ b/Core/HLE/sceUtility.cpp @@ -226,6 +226,7 @@ int sceUtilityGamedataInstallGetStatus() #define PSP_SYSTEMPARAM_ID_INT_DAYLIGHTSAVINGS 7 #define PSP_SYSTEMPARAM_ID_INT_LANGUAGE 8 #define PSP_SYSTEMPARAM_ID_INT_BUTTON_PREFERENCE 9 +#define PSP_SYSTEMPARAM_ID_INT_LOCK_PARENTAL_LEVEL 10 /** * Return values for the SystemParam functions @@ -321,6 +322,9 @@ u32 sceUtilityGetSystemParamInt(u32 id, u32 destaddr) case PSP_SYSTEMPARAM_ID_INT_BUTTON_PREFERENCE: param = PSP_SYSTEMPARAM_BUTTON_CROSS; break; + case PSP_SYSTEMPARAM_ID_INT_LOCK_PARENTAL_LEVEL: + param = 0; + break; default: return PSP_SYSTEMPARAM_RETVAL_FAIL; } diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index ea43814e50..e5dc819007 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -39,14 +39,17 @@ void VagDecoder::Start(u32 data, int vagSize, bool loopEnabled) { read_ = data; curSample = 28; curBlock_ = -1; - s_1 = 0.0; // per block? - s_2 = 0.0; + s_1 = 0; // per block? + s_2 = 0; } void VagDecoder::DecodeBlock(u8 *&readp) { int predict_nr = *readp++; int shift_factor = predict_nr & 0xf; predict_nr >>= 4; + if (predict_nr >= sizeof(f) / sizeof(s8)) { + predict_nr = 0; + } int flags = *readp++; if (flags == 7) { end_ = true; @@ -55,8 +58,10 @@ void VagDecoder::DecodeBlock(u8 *&readp) { else if (flags == 6) { loopStartBlock_ = curBlock_; } - else if (flags == 3 && loopEnabled_) { - loopAtNextBlock_ = true; + else if (flags == 3) { + if (loopEnabled_) { + loopAtNextBlock_ = true; + } } for (int i = 0; i < 28; i += 2) { int d = *readp++; @@ -66,7 +71,7 @@ void VagDecoder::DecodeBlock(u8 *&readp) { samples[i + 1] = s >> shift_factor; } for (int i = 0; i < 28; i++) { - samples[i] = samples[i] + ((s_1 * f[predict_nr][0] + s_2 * f[predict_nr][1]) >> 6); + samples[i] = (int) (samples[i] + ((s_1 * f[predict_nr][0] + s_2 * f[predict_nr][1]) >> 6)); s_2 = s_1; s_1 = samples[i]; } diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index a6ff8df0d7..cc79d0bc10 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -73,8 +73,6 @@ enum VoiceType { // VAG is a Sony ADPCM audio compression format, which goes all the way back to the PSX. // It compresses 28 16-bit samples into a block of 16 bytes. -// TODO: Get rid of the doubles, making sure it does not impact sound quality. -// Doubles are pretty fast on Android devices these days though. class VagDecoder { public: VagDecoder() : data_(0), read_(0) {} diff --git a/Core/MIPS/ARM/ArmCompBranch.cpp b/Core/MIPS/ARM/ArmCompBranch.cpp index 512ab96886..f3b149c6c7 100644 --- a/Core/MIPS/ARM/ArmCompBranch.cpp +++ b/Core/MIPS/ARM/ArmCompBranch.cpp @@ -422,4 +422,11 @@ void Jit::Comp_Syscall(u32 op) js.compiling = false; } +void Jit::Comp_Break(u32 op) +{ + Comp_Generic(op); + WriteSyscallExit(); + js.compiling = false; +} + } // namespace Mipscomp diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h index a3d44f5637..1172050eaa 100644 --- a/Core/MIPS/ARM/ArmJit.h +++ b/Core/MIPS/ARM/ArmJit.h @@ -89,6 +89,7 @@ public: void Comp_Jump(u32 op); void Comp_JumpReg(u32 op); void Comp_Syscall(u32 op); + void Comp_Break(u32 op); void Comp_IType(u32 op); void Comp_RType3(u32 op); diff --git a/Core/MIPS/MIPSInt.cpp b/Core/MIPS/MIPSInt.cpp index 195a77391e..91f576560b 100644 --- a/Core/MIPS/MIPSInt.cpp +++ b/Core/MIPS/MIPSInt.cpp @@ -179,7 +179,7 @@ namespace MIPSInt void Int_Break(u32 op) { - DEBUG_LOG(CPU, "BREAK!"); + ERROR_LOG(CPU, "BREAK!"); coreState = CORE_STEPPING; PC += 4; } diff --git a/Core/MIPS/MIPSTables.cpp b/Core/MIPS/MIPSTables.cpp index 190ee0022d..45d8329412 100644 --- a/Core/MIPS/MIPSTables.cpp +++ b/Core/MIPS/MIPSTables.cpp @@ -183,7 +183,7 @@ const MIPSInstruction tableSpecial[64] = /// 000000 ...... ...... .......... xxx INSTR("movz", &Jit::Comp_RType3, Dis_RType3, Int_RType3, OUT_RD|IN_RS|IN_RT), INSTR("movn", &Jit::Comp_RType3, Dis_RType3, Int_RType3, OUT_RD|IN_RS|IN_RT), INSTR("syscall", &Jit::Comp_Syscall, Dis_Syscall, Int_Syscall,0), - INSTR("break", &Jit::Comp_Generic, Dis_Generic, Int_Break, 0), + INSTR("break", &Jit::Comp_Break, Dis_Generic, Int_Break, 0), {-2}, INSTR("sync", &Jit::Comp_Generic, Dis_Generic, Int_Sync, 0), diff --git a/Core/MIPS/x86/CompBranch.cpp b/Core/MIPS/x86/CompBranch.cpp index 3d07edc3b7..65b2d3a47a 100644 --- a/Core/MIPS/x86/CompBranch.cpp +++ b/Core/MIPS/x86/CompBranch.cpp @@ -506,4 +506,11 @@ void Jit::Comp_Syscall(u32 op) js.compiling = false; } +void Jit::Comp_Break(u32 op) +{ + Comp_Generic(op); + WriteSyscallExit(); + js.compiling = false; +} + } // namespace Mipscomp diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h index 82d530ca4e..4adf9b7f24 100644 --- a/Core/MIPS/x86/Jit.h +++ b/Core/MIPS/x86/Jit.h @@ -122,6 +122,7 @@ public: void Comp_Jump(u32 op); void Comp_JumpReg(u32 op); void Comp_Syscall(u32 op); + void Comp_Break(u32 op); void Comp_IType(u32 op); void Comp_RType3(u32 op); diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index 5ebc5d3ade..54c6b50bff 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -60,7 +60,7 @@ static const int flushOnChangedBeforeCommandList[] = { GE_CMD_FOG1, GE_CMD_FOG2, GE_CMD_FOGCOLOR, - GE_CMD_LMODE, + GE_CMD_SHADEMODE, GE_CMD_REVERSENORMAL, GE_CMD_MATERIALUPDATE, GE_CMD_MATERIALEMISSIVE, @@ -71,7 +71,7 @@ static const int flushOnChangedBeforeCommandList[] = { GE_CMD_MATERIALSPECULARCOEF, GE_CMD_AMBIENTCOLOR, GE_CMD_AMBIENTALPHA, - GE_CMD_COLORMODEL, + GE_CMD_LIGHTMODE, GE_CMD_LIGHTTYPE0, GE_CMD_LIGHTTYPE1, GE_CMD_LIGHTTYPE2, GE_CMD_LIGHTTYPE3, GE_CMD_LX0,GE_CMD_LY0,GE_CMD_LZ0, GE_CMD_LX1,GE_CMD_LY1,GE_CMD_LZ1, @@ -316,17 +316,14 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { // Handle control and drawing commands here directly. The others we delegate. switch (cmd) { case GE_CMD_BASE: - //DEBUG_LOG(G3D,"DL BASE: %06x", data & 0xFFFFFF); break; case GE_CMD_VADDR: /// <<8???? gstate_c.vertexAddr = ((gstate.base & 0x00FF0000) << 8)|data; - //DEBUG_LOG(G3D,"DL VADDR: %06x", gstate_c.vertexAddr); break; case GE_CMD_IADDR: gstate_c.indexAddr = ((gstate.base & 0x00FF0000) << 8)|data; - //DEBUG_LOG(G3D,"DL IADDR: %06x", gstate_c.indexAddr); break; case GE_CMD_PRIM: @@ -390,23 +387,24 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { case GE_CMD_JUMP: { - u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0x0FFFFFFF; + u32 target = gstate_c.getJumpAddress(data); if (Memory::IsValidAddress(target)) { currentList->pc = target - 4; // pc will be increased after we return, counteract that } else { - ERROR_LOG(G3D, "JUMP to illegal address %08x - ignoring??", target); + ERROR_LOG(G3D, "JUMP to illegal address %08x - ignoring! data=%06x", target, data); } } break; case GE_CMD_CALL: { + // Saint Seiya needs correct support for relative calls. u32 retval = currentList->pc + 4; - u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0xFFFFFFF; + u32 target = gstate_c.getJumpAddress(data); if (stackptr == ARRAY_SIZE(stack)) { ERROR_LOG(G3D, "CALL: Stack full!"); } else if (!Memory::IsValidAddress(target)) { - ERROR_LOG(G3D, "CALL to illegal address %08x - ignoring??", target); + ERROR_LOG(G3D, "CALL to illegal address %08x - ignoring! data=%06x", target, data); } else { stack[stackptr++] = retval; currentList->pc = target - 4; // pc will be increased after we return, counteract that @@ -420,6 +418,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { ERROR_LOG(G3D, "RET: Stack empty!"); } else { u32 target = (currentList->pc & 0xF0000000) | (stack[--stackptr] & 0x0FFFFFFF); + //target = (target + gstate_c.originAddr) & 0xFFFFFFF; currentList->pc = target - 4; if (!Memory::IsValidAddress(currentList->pc)) { ERROR_LOG(G3D, "Invalid DL PC %08x on return", currentList->pc); @@ -429,6 +428,16 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { } break; + case GE_CMD_OFFSETADDR: + gstate_c.offsetAddr = data << 8; + // ??? + break; + + case GE_CMD_ORIGIN: + gstate_c.offsetAddr = currentList->pc; + break; + + case GE_CMD_SIGNAL: { // Processed in GE_END. Has data. @@ -497,10 +506,6 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { // bounding box test. Let's do nothing. break; - case GE_CMD_ORIGIN: - gstate.offsetAddr = currentList->pc & 0xFFFFFF; - break; - case GE_CMD_VERTEXTYPE: if (diff & GE_VTYPE_THROUGH) { // Throughmode changed, let's make the proj matrix dirty. @@ -509,10 +514,6 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { // This sets through-mode or not, as well. break; - case GE_CMD_OFFSETADDR: - // offsetAddr = data<<8; - break; - case GE_CMD_REGION1: { int x1 = data & 0x3ff; @@ -813,7 +814,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) { case GE_CMD_CULL: break; - case GE_CMD_LMODE: + case GE_CMD_SHADEMODE: break; case GE_CMD_PATCHDIVISION: diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 09330c3b1b..f129aa26b3 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -328,11 +328,12 @@ void FramebufferManager::SetRenderFrameBuffer() { textureCache_->NotifyFramebuffer(vfb->fb_address, vfb->fbo); #ifdef USING_GLES2 - // Tiled renderers benefit IMMENSELY from clearing an FBO before rendering - // to it. Let's hope this doesn't break too many things... - // It did, will have to find a better solution like clearing only if this is - // the first time the buffer is bound on this frame. - // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + // Some tiled mobile GPUs benefit IMMENSELY from clearing an FBO before rendering + // to it. This broke stuff before, so now it only clears on the first use of an + // FBO in a frame. This means that some games won't be able to avoid the on-some-GPUs + // performance-crushing framebuffer reloads from RAM, but we'll have to live with that. + if (vfb->last_frame_used != gpuStats.numFrames) + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); #endif glstate.viewport.set(0, 0, vfb->renderWidth, vfb->renderHeight); currentRenderVfb_ = vfb; diff --git a/GPU/GPUState.cpp b/GPU/GPUState.cpp index cfd3f23fc7..75474fcb6f 100644 --- a/GPU/GPUState.cpp +++ b/GPU/GPUState.cpp @@ -31,6 +31,7 @@ GPUStatistics gpuStats; void InitGfxState() { memset(&gstate, 0, sizeof(gstate)); + memset(&gstate_c, 0, sizeof(gstate_c)); for (int i = 0; i < 256; i++) { gstate.cmdmem[i] = i << 24; } diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 19cda92bf0..a65d477971 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -221,6 +221,7 @@ struct GPUgstate int getNumBoneWeights() const { return 1 + ((vertType & GE_VTYPE_WEIGHTCOUNT_MASK) >> GE_VTYPE_WEIGHTCOUNT_SHIFT); } + // Real data in the context ends here }; @@ -231,6 +232,8 @@ struct GPUStateCache u32 vertexAddr; u32 indexAddr; + u32 offsetAddr; + bool textureChanged; float uScale,vScale,zScale; @@ -247,6 +250,9 @@ struct GPUStateCache float vpWidth; float vpHeight; + + + u32 getJumpAddress(u32 data) const; }; // TODO: Implement support for these. @@ -322,3 +328,8 @@ extern GPUgstate gstate; extern GPUStateCache gstate_c; extern GPUInterface *gpu; extern GPUStatistics gpuStats; + +inline u32 GPUStateCache::getJumpAddress(u32 data) const { + u32 baseExtended = ((gstate.base & 0x0F0000) << 8) | (data & 0xFFFFFF); + return (gstate_c.offsetAddr + baseExtended) & 0x0FFFFFFF; +} diff --git a/GPU/GeDisasm.cpp b/GPU/GeDisasm.cpp index 1ef05ca609..79dbd2ddfe 100644 --- a/GPU/GeDisasm.cpp +++ b/GPU/GeDisasm.cpp @@ -85,7 +85,7 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer) { case GE_CMD_CALL: { u32 retval = pc + 4; - u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0xFFFFFFF; + u32 target = gstate_c.getJumpAddress(op & 0xFFFFFF); sprintf(buffer, "CMD CALL - %08x to %08x, ret=%08x", pc, target, retval); } break; @@ -444,6 +444,14 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer) { sprintf(buffer, "Material specular coef: %f", getFloat24(data)); break; + case GE_CMD_SHADEMODE: + sprintf(buffer, "Shade: %06x (%s)", data, data ? "gouraud" : "flat"); + break; + + case GE_CMD_LIGHTMODE: + sprintf(buffer, "Lightmode: %06x (%s)", data, data ? "separate spec" : "single color"); + break; + case GE_CMD_LIGHTTYPE0: case GE_CMD_LIGHTTYPE1: case GE_CMD_LIGHTTYPE2: @@ -534,10 +542,6 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer) { sprintf(buffer, "cull: %06x", data); break; - case GE_CMD_LMODE: - sprintf(buffer, "Shade mode: %06x", data); - break; - case GE_CMD_PATCHDIVISION: { int patch_div_s = data & 0xFF; diff --git a/GPU/Null/NullGpu.cpp b/GPU/Null/NullGpu.cpp index ed9e56ac29..7276fe6093 100644 --- a/GPU/Null/NullGpu.cpp +++ b/GPU/Null/NullGpu.cpp @@ -169,6 +169,7 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) case GE_CMD_ORIGIN: gstate.offsetAddr = currentList->pc & 0xFFFFFF; + gstate_c.offsetAddr = currentList->pc; break; case GE_CMD_VERTEXTYPE: @@ -565,7 +566,7 @@ void NullGPU::ExecuteOp(u32 op, u32 diff) DEBUG_LOG(G3D,"DL cull: %06x", data); break; - case GE_CMD_LMODE: + case GE_CMD_LIGHTMODE: DEBUG_LOG(G3D,"DL Shade mode: %06x", data); break; diff --git a/GPU/ge_constants.h b/GPU/ge_constants.h index 35bc75b8ca..78a90fe26c 100644 --- a/GPU/ge_constants.h +++ b/GPU/ge_constants.h @@ -91,7 +91,7 @@ enum GECommand GE_CMD_TEXOFFSETV=0x4B, GE_CMD_OFFSETX=0x4C, GE_CMD_OFFSETY=0x4D, - GE_CMD_LMODE=0x50, + GE_CMD_SHADEMODE=0x50, // flat or gouraud GE_CMD_REVERSENORMAL=0x51, GE_CMD_MATERIALUPDATE=0x53, GE_CMD_MATERIALEMISSIVE, //not sure about these but this makes sense @@ -102,7 +102,7 @@ enum GECommand GE_CMD_MATERIALSPECULARCOEF=0x5B, GE_CMD_AMBIENTCOLOR, GE_CMD_AMBIENTALPHA, - GE_CMD_COLORMODEL=0x5E, + GE_CMD_LIGHTMODE=0x5E, GE_CMD_LIGHTTYPE0=0x5F, GE_CMD_LIGHTTYPE1=0x60, GE_CMD_LIGHTTYPE2=0x61, diff --git a/Qt/EmuThread.cpp b/Qt/EmuThread.cpp index f41e170287..4ffd52b3a7 100644 --- a/Qt/EmuThread.cpp +++ b/Qt/EmuThread.cpp @@ -33,7 +33,10 @@ void EmuThread_Stop() { // DSound_UpdateSound(); Core_Stop(); - glWindow->stop_rendering(); + if(glWindow) + { + glWindow->stop_rendering(); + } host->UpdateUI(); } @@ -156,8 +159,8 @@ void EmuThread::run() { msleep(frameTime-time); } + timer.start(); } - timer.start(); fbo_unbind(); diff --git a/Qt/mainwindow.cpp b/Qt/mainwindow.cpp index bdec903dbd..4456555cbc 100644 --- a/Qt/mainwindow.cpp +++ b/Qt/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "Core/MIPS/MIPSDebugInterface.h" #include "Core/SaveState.h" @@ -13,6 +14,8 @@ #include "Core/Config.h" #include "ConsoleListener.h" #include "base/display.h" +#include "GPU/GPUInterface.h" +#include "GPU/GPUState.h" #include "QtHost.h" #include "EmuThread.h" @@ -45,8 +48,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), nextState(CORE_POWERDOWN), - dialogDisasm(0), - g_bFullScreen(false) + dialogDisasm(0) { ui->setupUi(this); qApp->installEventFilter(this); @@ -208,7 +210,11 @@ void MainWindow::BrowseAndBoot(void) { QString filename = QFileDialog::getOpenFileName(NULL, "Load File", g_Config.currentDirectory.c_str(), "PSP ROMs (*.pbp *.elf *.iso *.cso *.prx)"); if (QFile::exists(filename)) + { + QFileInfo info(filename); + g_Config.currentDirectory = info.absolutePath().toStdString(); EmuThread_Start(filename, w); + } } void MainWindow::Boot() @@ -297,9 +303,8 @@ void MainWindow::SetZoom(float zoom) { setFixedSize(sizeHint()); resize(sizeHint()); - PSP_CoreParameter().pixelWidth = (int) (480 * zoom); - PSP_CoreParameter().pixelHeight = (int) (272 * zoom); - //GL_Resized(); + PSP_CoreParameter().pixelWidth = pixel_xres; + PSP_CoreParameter().pixelHeight = pixel_yres; } void MainWindow::on_action_FileLoad_triggered() @@ -580,16 +585,36 @@ void MainWindow::on_action_OptionsIgnoreIllegalReadsWrites_triggered() void MainWindow::on_action_OptionsFullScreen_triggered() { - // TODO - if(g_bFullScreen) { - //_ViewNormal(hWnd); - SetZoom(1); //restore window to original size + if(isFullScreen()) { + showNormal(); + ui->menubar->setVisible(true); + ui->statusbar->setVisible(true); + SetZoom(g_Config.iWindowZoom); } else { - /*int cx = ::GetSystemMetrics(SM_CXSCREEN); - float screenfactor = cx / 480.0f; - SetZoom(screenfactor); - _ViewFullScreen(hWnd);*/ + ui->menubar->setVisible(false); + ui->statusbar->setVisible(false); + + // Remove constraint + w->setMinimumSize(0, 0); + w->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + ui->centralwidget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + + showFullScreen(); + + int width = (int) QApplication::desktop()->screenGeometry().width(); + int height = (int) QApplication::desktop()->screenGeometry().height(); + PSP_CoreParameter().pixelWidth = width; + PSP_CoreParameter().pixelHeight = height; + PSP_CoreParameter().renderWidth = width; + PSP_CoreParameter().renderHeight = height; + PSP_CoreParameter().outputWidth = width; + PSP_CoreParameter().outputHeight = height; + pixel_xres = width; + pixel_yres = height; + if (gpu) + gpu->Resized(); } } @@ -642,6 +667,12 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::keyPressEvent(QKeyEvent *e) { + if(isFullScreen() && e->key() == Qt::Key_F12) + { + on_action_OptionsFullScreen_triggered(); + return; + } + for (int b = 0; b < 14; b++) { if (e->key() == buttonMappings[b]) { diff --git a/Qt/mainwindow.ui b/Qt/mainwindow.ui index 6c5cce3893..eda55d0f63 100644 --- a/Qt/mainwindow.ui +++ b/Qt/mainwindow.ui @@ -324,9 +324,6 @@ - - false - &Toggle Full Screen @@ -407,7 +404,7 @@ Screen &2x - Ctrl+Shift+2 + Ctrl+2 @@ -418,7 +415,7 @@ Screen &3x - Ctrl+Shift+3 + Ctrl+3 @@ -429,7 +426,7 @@ Screen &4x - Ctrl+Shift+3 + Ctrl+4 diff --git a/pspautotests b/pspautotests index 3870083f15..4f047eb8c7 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 3870083f15c69aa47a159fda148a8df3db6891e4 +Subproject commit 4f047eb8c76c6388a63a87ec72e98c64670152d5