Skip to content

Commit

Permalink
Merge pull request #19530 from hrydgard/even-more-misc-fixes
Browse files Browse the repository at this point in the history
Even more misc fixes: Beaterator, sharp bilinear, remove back button
  • Loading branch information
hrydgard authored Oct 16, 2024
2 parents e52c1e3 + cc32950 commit ae640f8
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 94 deletions.
12 changes: 6 additions & 6 deletions Core/Debugger/SymbolMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ u32 SymbolMap::GetNextSymbolAddress(u32 address, SymbolType symmask) {

std::string SymbolMap::GetDescription(unsigned int address) {
std::lock_guard<std::recursive_mutex> guard(lock_);
const char* labelName = NULL;
const char *labelName = nullptr;

u32 funcStart = GetFunctionStart(address);
if (funcStart != INVALID_ADDRESS) {
Expand All @@ -414,11 +414,11 @@ std::string SymbolMap::GetDescription(unsigned int address) {
labelName = GetLabelName(dataStart);
}

if (labelName != NULL)
if (labelName)
return labelName;

char descriptionTemp[256];
sprintf(descriptionTemp, "(%08x)", address);
char descriptionTemp[32];
snprintf(descriptionTemp, sizeof(descriptionTemp), "(%08x)", address);
return descriptionTemp;
}

Expand All @@ -435,7 +435,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
entry.address = it->first;
entry.size = GetFunctionSize(entry.address);
const char* name = GetLabelName(entry.address);
if (name != NULL)
if (name)
entry.name = name;
result.push_back(entry);
}
Expand All @@ -448,7 +448,7 @@ std::vector<SymbolEntry> SymbolMap::GetAllSymbols(SymbolType symmask) {
entry.address = it->first;
entry.size = GetDataSize(entry.address);
const char* name = GetLabelName(entry.address);
if (name != NULL)
if (name)
entry.name = name;
result.push_back(entry);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceKernelEventFlag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class EventFlag : public KernelObject {
const char *GetTypeName() override { return GetStaticTypeName(); }
static const char *GetStaticTypeName() { return "EventFlag"; }
void GetQuickInfo(char *ptr, int size) override {
sprintf(ptr, "init=%08x cur=%08x numwait=%i",
snprintf(ptr, size, "init=%08x cur=%08x numwait=%i",
nef.initPattern,
nef.currentPattern,
nef.numWaitThreads);
Expand Down
8 changes: 3 additions & 5 deletions Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,8 @@ class PSPModule : public KernelObject {
const char *GetName() override { return nm.name; }
const char *GetTypeName() override { return GetStaticTypeName(); }
static const char *GetStaticTypeName() { return "Module"; }
void GetQuickInfo(char *ptr, int size) override
{
// ignore size
sprintf(ptr, "%sname=%s gp=%08x entry=%08x",
void GetQuickInfo(char *ptr, int size) override {
snprintf(ptr, size, "%sname=%s gp=%08x entry=%08x",
isFake ? "faked " : "",
nm.name,
nm.gp_value,
Expand Down Expand Up @@ -394,7 +392,7 @@ class PSPModule : public KernelObject {

// Add the symbol to the symbol map for debugging.
char temp[256];
sprintf(temp,"zz_%s", GetFuncName(func.moduleName, func.nid));
snprintf(temp, sizeof(temp), "zz_%s", GetFuncName(func.moduleName, func.nid));
g_symbolMap->AddFunction(temp,func.stubAddr,8);

// Keep track and actually hook it up if possible.
Expand Down
8 changes: 4 additions & 4 deletions Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PSPCallback : public KernelObject {
static const char *GetStaticTypeName() { return "CallBack"; }

void GetQuickInfo(char *ptr, int size) override {
sprintf(ptr, "thread=%i, argument= %08x",
snprintf(ptr, size, "thread=%i, argument= %08x",
//hackAddress,
nc.threadId,
nc.commonArgument);
Expand Down Expand Up @@ -378,7 +378,7 @@ class PSPThread : public KernelObject {
const char *GetTypeName() override { return GetStaticTypeName(); }
static const char *GetStaticTypeName() { return "Thread"; }
void GetQuickInfo(char *ptr, int size) override {
sprintf(ptr, "pc= %08x sp= %08x %s %s %s %s %s %s (wt=%i wid=%i wv= %08x )",
snprintf(ptr, size, "pc= %08x sp= %08x %s %s %s %s %s %s (wt=%i wid=%i wv= %08x )",
context.pc, context.r[MIPS_REG_SP],
(nt.status & THREADSTATUS_RUNNING) ? "RUN" : "",
(nt.status & THREADSTATUS_READY) ? "READY" : "",
Expand Down Expand Up @@ -1699,7 +1699,7 @@ static void __ReportThreadQueueEmpty() {
idleThread0->GetQuickInfo(idleDescription0, sizeof(idleDescription0));
idleStatus0 = idleThread0->nt.status;
} else {
sprintf(idleDescription0, "DELETED");
truncate_cpy(idleDescription0, "DELETED");
}

char idleDescription1[256];
Expand All @@ -1708,7 +1708,7 @@ static void __ReportThreadQueueEmpty() {
idleThread1->GetQuickInfo(idleDescription1, sizeof(idleDescription1));
idleStatus1 = idleThread1->nt.status;
} else {
sprintf(idleDescription1, "DELETED");
truncate_cpy(idleDescription1, "DELETED");
}

ERROR_LOG_REPORT_ONCE(threadqueueempty, Log::sceKernel, "Failed to reschedule: out of threads on queue (%d, %d)", idleStatus0, idleStatus1);
Expand Down
91 changes: 35 additions & 56 deletions Core/HLE/sceUsbMic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void __MicBlockingResume(u64 userdata, int cyclesLate) {
CoreTiming::ScheduleEvent(usToCycles(waitTimeus), eventMicBlockingResume, userdata);
}
} else {
for (u32 i = 0; i < waitingThread.needSize; i++) {
for (int i = 0; i < waitingThread.needSize; i++) {
if (Memory::IsValidAddress(waitingThread.addr + i)) {
Memory::Write_U8(i & 0xFF, waitingThread.addr + i);
}
Expand Down Expand Up @@ -159,40 +159,20 @@ void __UsbMicDoState(PointerWrap &p) {
}
}

QueueBuf::QueueBuf(u32 size) : available(0), end(0), capacity(size) {
QueueBuf::QueueBuf(int size) : available(0), end(0), capacity(size) {
buf_ = new u8[size];
}

QueueBuf::~QueueBuf() {
delete[] buf_;
}

QueueBuf::QueueBuf(const QueueBuf &buf) {
buf_ = new u8[buf.capacity];
memcpy(buf_, buf.buf_, buf.capacity);
available = buf.available;
end = buf.end;
capacity = buf.capacity;
}

QueueBuf& QueueBuf::operator=(const QueueBuf &buf) {
if (capacity < buf.capacity) {
resize(buf.capacity);
}
std::unique_lock<std::mutex> lock(mutex);
memcpy(buf_, buf.buf_, buf.capacity);
available = buf.available;
end = buf.end;
lock.unlock();
return *this;
}

u32 QueueBuf::push(u8 *buf, u32 size) {
u32 addedSize = 0;
int QueueBuf::push(const u8 *buf, int size) {
int addedSize = 0;
// This will overwrite the old data if the size prepare to add more than remaining size.
std::unique_lock<std::recursive_mutex> lock(mutex);
if (size > capacity)
resize(size);
// This will overwrite the old data if the size prepare to add more than remaining size.
std::unique_lock<std::mutex> lock(mutex);
while (end + size > capacity) {
memcpy(buf_ + end, buf + addedSize, capacity - end);
addedSize += capacity - end;
Expand All @@ -207,29 +187,33 @@ u32 QueueBuf::push(u8 *buf, u32 size) {
return addedSize;
}

u32 QueueBuf::pop(u8 *buf, u32 size) {
u32 ret = 0;
int QueueBuf::pop(u8 *buf, int size) {
if (size == 0) {
return 0;
}
int ret = 0;
std::unique_lock<std::recursive_mutex> lock(mutex);
if (getAvailableSize() < size)
size = getAvailableSize();
ret = size;

std::unique_lock<std::mutex> lock(mutex);
if (getStartPos() + size <= capacity) {
memcpy(buf, buf_ + getStartPos(), size);
int startPos = getStartPos();
if (startPos + size <= capacity) {
memcpy(buf, buf_ + startPos, size);
} else {
memcpy(buf, buf_ + getStartPos(), capacity - getStartPos());
memcpy(buf + capacity - getStartPos(), buf_, size - (capacity - getStartPos()));
memcpy(buf, buf_ + startPos, capacity - startPos);
memcpy(buf + capacity - startPos, buf_, size - (capacity - startPos));
}
available -= size;
lock.unlock();
return ret;
}

void QueueBuf::resize(u32 newSize) {
void QueueBuf::resize(int newSize) {
if (capacity >= newSize) {
return;
}
u32 availableSize = getAvailableSize();
int availableSize = getAvailableSize();
u8 *oldbuf = buf_;

buf_ = new u8[newSize];
Expand All @@ -241,21 +225,17 @@ void QueueBuf::resize(u32 newSize) {
}

void QueueBuf::flush() {
std::unique_lock<std::mutex> lock(mutex);
std::unique_lock<std::recursive_mutex> lock(mutex);
available = 0;
end = 0;
lock.unlock();
}

u32 QueueBuf::getAvailableSize() {
return available;
}

u32 QueueBuf::getRemainingSize() {
int QueueBuf::getRemainingSize() const {
return capacity - getAvailableSize();
}

u32 QueueBuf::getStartPos() {
int QueueBuf::getStartPos() const {
return end >= available ? end - available : capacity - available + end;
}

Expand Down Expand Up @@ -293,7 +273,7 @@ static int sceUsbMicInput(u32 maxSamples, u32 sampleRate, u32 bufAddr) {
return -1;
}

ERROR_LOG(Log::HLE, "UNTEST sceUsbMicInput: maxSamples: %d, samplerate: %d, bufAddr: %08x", maxSamples, sampleRate, bufAddr);
WARN_LOG(Log::HLE, "UNTEST sceUsbMicInput: maxSamples: %d, samplerate: %d, bufAddr: %08x", maxSamples, sampleRate, bufAddr);
if (maxSamples <= 0 || (maxSamples & 0x3F) != 0) {
return SCE_USBMIC_ERROR_INVALID_MAX_SAMPLES;
}
Expand All @@ -304,6 +284,7 @@ static int sceUsbMicInput(u32 maxSamples, u32 sampleRate, u32 bufAddr) {

return __MicInput(maxSamples, sampleRate, bufAddr, USBMIC, false);
}

static int sceUsbMicGetInputLength() {
int ret = Microphone::getReadMicDataLength() / 2;
ERROR_LOG(Log::HLE, "UNTEST sceUsbMicGetInputLength(ret: %d)", ret);
Expand All @@ -317,7 +298,8 @@ static int sceUsbMicInputInit(int unknown1, int inputVolume, int unknown2) {

static int sceUsbMicWaitInputEnd() {
ERROR_LOG(Log::HLE, "UNIMPL sceUsbMicWaitInputEnd");
return 0;
// Hack: Just task switch so other threads get to do work. Helps Beaterator (although recording does not appear to work correctly).
return hleDelayResult(0, "MicWait", 100);
}

int Microphone::startMic(void *param) {
Expand Down Expand Up @@ -364,24 +346,24 @@ bool Microphone::isNeedInput() {
return ::isNeedInput;
}

u32 Microphone::numNeedSamples() {
int Microphone::numNeedSamples() {
return ::numNeedSamples;
}

u32 Microphone::availableAudioBufSize() {
int Microphone::availableAudioBufSize() {
return audioBuf->getAvailableSize();
}

u32 Microphone::getReadMicDataLength() {
int Microphone::getReadMicDataLength() {
return ::readMicDataLength;
}

int Microphone::addAudioData(u8 *buf, u32 size) {
int Microphone::addAudioData(u8 *buf, int size) {
if (!audioBuf)
return 0;
audioBuf->push(buf, size);

u32 addSize = std::min(audioBuf->getAvailableSize(), numNeedSamples() * 2 - getReadMicDataLength());
int addSize = std::min(audioBuf->getAvailableSize(), numNeedSamples() * 2 - getReadMicDataLength());
if (Memory::IsValidRange(curTargetAddr + readMicDataLength, addSize)) {
getAudioData(Memory::GetPointerWriteUnchecked(curTargetAddr + readMicDataLength), addSize);
NotifyMemInfo(MemBlockFlags::WRITE, curTargetAddr + readMicDataLength, addSize, "MicAddAudioData");
Expand All @@ -391,10 +373,9 @@ int Microphone::addAudioData(u8 *buf, u32 size) {
return size;
}

u32 Microphone::getAudioData(u8 *buf, u32 size) {
int Microphone::getAudioData(u8 *buf, int size) {
if(audioBuf)
return audioBuf->pop(buf, size);

return 0;
}

Expand Down Expand Up @@ -423,7 +404,7 @@ u32 __MicInput(u32 maxSamples, u32 sampleRate, u32 bufAddr, MICTYPE type, bool b
curSampleRate = sampleRate;
curChannels = 1;
curTargetAddr = bufAddr;
u32 size = maxSamples << 1;
int size = maxSamples << 1;
if (!audioBuf) {
audioBuf = new QueueBuf(size);
} else {
Expand Down Expand Up @@ -460,8 +441,7 @@ u32 __MicInput(u32 maxSamples, u32 sampleRate, u32 bufAddr, MICTYPE type, bool b
return type == CAMERAMIC ? size : maxSamples;
}

const HLEFunction sceUsbMic[] =
{
const HLEFunction sceUsbMic[] = {
{0x06128E42, &WrapI_V<sceUsbMicPollInputEnd>, "sceUsbMicPollInputEnd", 'i', "" },
{0x2E6DCDCD, &WrapI_UUU<sceUsbMicInputBlocking>, "sceUsbMicInputBlocking", 'i', "xxx" },
{0x45310F07, &WrapI_U<sceUsbMicInputInitEx>, "sceUsbMicInputInitEx", 'i', "x" },
Expand All @@ -471,7 +451,6 @@ const HLEFunction sceUsbMic[] =
{0xF899001C, &WrapI_V<sceUsbMicWaitInputEnd>, "sceUsbMicWaitInputEnd", 'i', "" },
};

void Register_sceUsbMic()
{
void Register_sceUsbMic() {
RegisterModule("sceUsbMic", ARRAY_SIZE(sceUsbMic), sceUsbMic);
}
Loading

0 comments on commit ae640f8

Please sign in to comment.