From 691af17bbd336ff641a7dffc2c9e3900b7eae939 Mon Sep 17 00:00:00 2001 From: Ziemas Date: Fri, 26 May 2023 23:55:10 +0200 Subject: [PATCH] overlord: Some cleanup (#2669) Started cleaning up some of the lower hanging fruit. --- game/overlord/jak2/iso.cpp | 15 +- game/overlord/jak2/iso.h | 8 +- game/overlord/jak2/iso_queue.cpp | 400 ++++++++++++------------------ game/overlord/jak2/spustreams.cpp | 124 ++------- game/overlord/jak2/vag.cpp | 16 +- game/sce/iop.h | 4 +- 6 files changed, 193 insertions(+), 374 deletions(-) diff --git a/game/overlord/jak2/iso.cpp b/game/overlord/jak2/iso.cpp index 1d2400d6d4..def4a1516b 100644 --- a/game/overlord/jak2/iso.cpp +++ b/game/overlord/jak2/iso.cpp @@ -224,18 +224,7 @@ void IsoQueueVagStream(VagCmd* cmd, int param_2) { } // copy data from the other command to us. - new_cmd->header.unk_0 = cmd->header.unk_0; - new_cmd->header.unk_4 = cmd->header.unk_4; - new_cmd->header.cmd_kind = cmd->header.cmd_kind; - new_cmd->header.status = cmd->header.status; - - new_cmd->header.mbx_to_reply = cmd->header.mbx_to_reply; - new_cmd->header.thread_id = cmd->header.thread_id; - new_cmd->header.unk_24 = cmd->header.unk_24; - new_cmd->header.callback_buffer = cmd->header.callback_buffer; - - new_cmd->header.callback = cmd->header.callback; - new_cmd->header.lse = cmd->header.lse; + new_cmd->header = cmd->header; new_cmd->file_record = cmd->file_record; new_cmd->vag_dir_entry = cmd->vag_dir_entry; @@ -472,7 +461,7 @@ u32 ISOThread() { if (iVar4 == 0) { iVar4 = (local_30->header).cmd_kind; (local_30->header).callback_buffer = (Buffer*)nullptr; - (local_30->header).unk_24 = 1; + (local_30->header).ready_for_data = 1; (local_30->header).callback = NullCallback; (local_30->header).lse = (LoadStackEntry*)nullptr; if (iVar4 - 0x100U < 3) { diff --git a/game/overlord/jak2/iso.h b/game/overlord/jak2/iso.h index 43a6cfeb86..2cd5c46ae0 100644 --- a/game/overlord/jak2/iso.h +++ b/game/overlord/jak2/iso.h @@ -4,6 +4,7 @@ #include "game/overlord/common/isocommon.h" #include "game/overlord/jak2/pages.h" +#include "game/sce/iop.h" namespace jak2 { void iso_init_globals(); @@ -81,13 +82,12 @@ extern IsoFs* isofs; extern LargeBuffer* SpLargeBuffer; struct CmdHeader { - int unk_0; - int unk_4; + iop::MsgPacket pkt; int cmd_kind; int status; int mbx_to_reply; int thread_id; - int unk_24; // 24 (init to 1) + int ready_for_data; // 24 (init to 1) Buffer* callback_buffer; // 28 int (*callback)(CmdHeader*, Buffer*); // 32 LoadStackEntry* lse; // 36 @@ -174,4 +174,4 @@ struct VagDir { extern VagDir gVagDir; extern s32 iso_mbx; -} // namespace jak2 \ No newline at end of file +} // namespace jak2 diff --git a/game/overlord/jak2/iso_queue.cpp b/game/overlord/jak2/iso_queue.cpp index a04cdf50bd..76cd212672 100644 --- a/game/overlord/jak2/iso_queue.cpp +++ b/game/overlord/jak2/iso_queue.cpp @@ -20,8 +20,10 @@ namespace jak2 { /// The data structure containing all memory pages. PageList* SpMemoryBuffers = nullptr; u8* ScratchPadMemory = nullptr; -constexpr int N_BUFFERS = 3 + 11; // ?? +constexpr int N_BUFFERS = 3; +constexpr int N_STR_BUFFERS = 8; static Buffer sBuffer[N_BUFFERS]; +static Buffer sStrBuffer[N_STR_BUFFERS]; static Buffer* sFreeBuffer = nullptr; static Buffer* sFreeStrBuffer = nullptr; u32 BuffersAlloc = 0; @@ -31,8 +33,8 @@ u32 NextBuffer = 0; u32 AllocdStrBuffersCount = 0; u32 NextStrBuffer = 0; int sSema = 0; -int vag_cmd_cnt = 0; -VagCmd vag_cmds[16]; +u32 vag_cmd_cnt = 0; +VagCmd vag_cmds[N_VAG_CMDS]; u32 vag_cmd_used = 0; u32 max_vag_cmd_cnt = 0; @@ -41,6 +43,7 @@ std::string gPriEntryNames[N_PRIORITIES][PRI_STACK_LENGTH]; // my addition for void ReturnMessage(CmdHeader* param_1); void FreeVAGCommand(VagCmd* param_1); +void FreeDataBuffer(u32* param_1, u32 param_2); void iso_queue_init_globals() { memset(sBuffer, 0, sizeof(sBuffer)); @@ -65,10 +68,8 @@ void InitBuffers() { SpMemoryBuffers = (PageList*)ScratchPadMemory; ScratchPadMemory += sizeof(PageList); InitPagedMemory(SpMemoryBuffers, 0x12, 0x8000); - Buffer* next_buffer = sBuffer; - for (int i = 0; i < 3; i++) { - next_buffer++; - sBuffer[i].next = next_buffer; + for (int i = 0; i < N_BUFFERS; i++) { + sBuffer[i].next = &sBuffer[i + 1]; sBuffer[i].decomp_buffer = nullptr; sBuffer[i].decompressed_size = 0; sBuffer[i].unk_12 = 0; @@ -81,30 +82,29 @@ void InitBuffers() { sBuffer[i].page = nullptr; sBuffer[i].unk_44 = 0; }; - sBuffer[2].next = nullptr; - - next_buffer = sBuffer + 4; + sBuffer[N_BUFFERS - 1].next = nullptr; sFreeBuffer = sBuffer; BuffersAlloc = 0; - for (int i = 0; i < 8; i++) { - sBuffer[i + 3].next = next_buffer; - next_buffer++; - sBuffer[i + 3].decomp_buffer = nullptr; - sBuffer[i + 3].decompressed_size = 0; - sBuffer[i + 3].unk_12 = 0; - sBuffer[i + 3].data_buffer_idx = -1; - sBuffer[i + 3].use_mode = 2; - sBuffer[i + 3].plist = SpMemoryBuffers; - sBuffer[i + 3].num_pages = 1; - sBuffer[i + 3].unk_32 = 2; - sBuffer[i + 3].free_pages = 0; - sBuffer[i + 3].page = nullptr; - sBuffer[i + 3].unk_44 = 0; + + for (int i = 0; i < N_STR_BUFFERS; i++) { + sStrBuffer[i].next = &sStrBuffer[i + 1]; + sStrBuffer[i].decomp_buffer = nullptr; + sStrBuffer[i].decompressed_size = 0; + sStrBuffer[i].unk_12 = 0; + sStrBuffer[i].data_buffer_idx = -1; + sStrBuffer[i].use_mode = 2; + sStrBuffer[i].plist = SpMemoryBuffers; + sStrBuffer[i].num_pages = 1; + sStrBuffer[i].unk_32 = 2; + sStrBuffer[i].free_pages = 0; + sStrBuffer[i].page = nullptr; + sStrBuffer[i].unk_44 = 0; }; - sBuffer[10].next = nullptr; - sFreeStrBuffer = sBuffer + 3; - StreamSRAM[0] = 0x5040; + sStrBuffer[N_STR_BUFFERS - 1].next = nullptr; + sFreeStrBuffer = sStrBuffer; StrBuffersAlloc = 0; + + StreamSRAM[0] = 0x5040; TrapSRAM[0] = 0x9040; snd_SRAMMarkUsed(0x5040, 0x4040); StreamSRAM[1] = 0x9080; @@ -326,110 +326,50 @@ LAB_00006a44: return pBVar7; } -void FreeBuffer(Buffer* param_1, int /*param_2*/) { - Buffer* pBVar1; - Page* pPVar2; - int iVar3; - u32 uVar4; +void FreeBuffer(Buffer* buf, int /*param_2*/) { // if (param_2 == 1) { // CpuSuspendIntr(local_18); //} - iVar3 = param_1->use_mode; - if (iVar3 == 1) { - if ((BuffersAlloc & 1 << (param_1->data_buffer_idx & 0x1fU)) != 0) { - pPVar2 = FreePagesList(param_1->plist, param_1->page); - pBVar1 = sFreeBuffer; - uVar4 = param_1->data_buffer_idx; - param_1->page = pPVar2; - param_1->data_buffer_idx = -1; - param_1->decompressed_size = 0; - param_1->unk_12 = 0; - sFreeBuffer = param_1; - param_1->use_mode = 0; - param_1->next = pBVar1; - BuffersAlloc = BuffersAlloc & ~(1 << (uVar4 & 0x1f)); - AllocdBuffersCount = AllocdBuffersCount + -1; + if (buf->use_mode == 1) { + if ((BuffersAlloc & 1 << (buf->data_buffer_idx & 0x1fU)) != 0) { + buf->page = FreePagesList(buf->plist, buf->page); + FreeDataBuffer(&BuffersAlloc, buf->data_buffer_idx); + buf->next = sFreeBuffer; + buf->decompressed_size = 0; + buf->unk_12 = 0; + sFreeBuffer = buf; + buf->use_mode = 0; + buf->data_buffer_idx = -1; + } + } else if (buf->use_mode == 2) { + if ((StrBuffersAlloc & 1 << (buf->data_buffer_idx & 0x1fU)) != 0) { + buf->page = FreePagesList(buf->plist, buf->page); + FreeDataBuffer(&StrBuffersAlloc, buf->data_buffer_idx); + buf->next = sFreeStrBuffer; + buf->decompressed_size = 0; + buf->unk_12 = 0; + sFreeStrBuffer = buf; + buf->use_mode = 0; + buf->data_buffer_idx = -1; } - } else if (((1 < iVar3) && (iVar3 == 2)) && - ((StrBuffersAlloc & 1 << (param_1->data_buffer_idx & 0x1fU)) != 0)) { - pPVar2 = FreePagesList(param_1->plist, param_1->page); - param_1->page = pPVar2; - param_1->decompressed_size = 0; - param_1->unk_12 = 0; - pBVar1 = param_1; - param_1->next = sFreeStrBuffer; - sFreeStrBuffer = pBVar1; - StrBuffersAlloc = StrBuffersAlloc & ~(1 << (param_1->data_buffer_idx & 0x1fU)); - AllocdStrBuffersCount = AllocdStrBuffersCount + -1; - param_1->data_buffer_idx = -1; - param_1->use_mode = 0; } // if (param_2 == 1) { // CpuResumeIntr(local_18[0]); //} } -void ReleaseMessage(CmdHeader* param_1, int param_2) { - Buffer* pBVar1; - int iVar2; - PriStackEntry* pPVar3; - int iVar4; - int iVar5; - PriStackEntry* pPVar6; +void ReleaseMessage(CmdHeader* cmd, int suspend_irq) { + while (cmd->callback_buffer != nullptr) { + auto cb_buf = cmd->callback_buffer; + cmd->callback_buffer = cb_buf->next; + FreeBuffer(cb_buf, suspend_irq); + } - pBVar1 = param_1->callback_buffer; - while (pBVar1 != (Buffer*)0x0) { - pBVar1 = param_1->callback_buffer; - param_1->callback_buffer = pBVar1->next; - FreeBuffer(pBVar1, param_2); - pBVar1 = param_1->callback_buffer; + if (cmd->lse != nullptr) { + isofs->close(cmd->lse); } - if (param_1->lse != (LoadStackEntry*)0x0) { - // (*(code*)isofs->close)(); - isofs->close(param_1->lse); - } - // if (param_2 == 1) { - // CpuSuspendIntr(local_18); - //} - iVar5 = 0; - pPVar6 = gPriStack; -LAB_00006d0c: - iVar4 = 0; - pPVar3 = pPVar6; - if (pPVar6->count < 1) - goto LAB_00006da0; - do { - if (pPVar3->entries[0] == param_1) - break; - iVar4 = iVar4 + 1; - pPVar3 = (PriStackEntry*)(pPVar3->entries + 1); - } while (iVar4 < pPVar6->count); - iVar2 = pPVar6->count + -1; - if (pPVar6->count <= iVar4) - goto LAB_00006da0; - pPVar6->count = iVar2; - if (iVar4 < iVar2) { - do { - iVar5 = iVar4 + 1; - pPVar6->entries[iVar4] = pPVar6->entries[iVar4 + 1]; - iVar4 = iVar5; - } while (iVar5 < pPVar6->count); - } - if (param_2 != 1) { - return; - } - goto LAB_00006dbc; -LAB_00006da0: - iVar5 = iVar5 + 1; - pPVar6 = pPVar6 + 1; - if (3 < iVar5) { - if (param_2 == 1) { - LAB_00006dbc:; - // CpuResumeIntr(local_18[0]); - } - return; - } - goto LAB_00006d0c; + + UnqueueMessage(cmd, suspend_irq); } void DisplayQueue() { @@ -466,88 +406,53 @@ int QueueMessage(CmdHeader* param_1, int param_2, const char* param_3, int param return uVar1; } -void UnqueueMessage(CmdHeader* param_1, int param_2) { - int iVar1; - PriStackEntry* pPVar2; - int iVar3; - PriStackEntry* pPVar4; - int iVar5; +void UnqueueMessage(CmdHeader* cmd, int suspend_irq) { + if (suspend_irq == 1) { + // CpuSuspendIntr(&stat); + } - if (param_2 == 1) { - // CpuSuspendIntr(local_18); - } - iVar5 = 0; - pPVar4 = gPriStack; -LAB_00007088: - iVar3 = 0; - pPVar2 = pPVar4; - if (pPVar4->count < 1) - goto LAB_0000711c; - do { - if (pPVar2->entries[0] == param_1) - break; - iVar3 = iVar3 + 1; - pPVar2 = (PriStackEntry*)(pPVar2->entries + 1); - } while (iVar3 < pPVar4->count); - iVar1 = pPVar4->count + -1; - if (pPVar4->count <= iVar3) - goto LAB_0000711c; - pPVar4->count = iVar1; - if (iVar3 < iVar1) { - do { - iVar5 = iVar3 + 1; - pPVar4->entries[iVar3] = pPVar4->entries[iVar3 + 1]; - iVar3 = iVar5; - } while (iVar5 < pPVar4->count); - } - if (param_2 != 1) { - return; - } - goto LAB_00007138; -LAB_0000711c: - iVar5 = iVar5 + 1; - pPVar4 = pPVar4 + 1; - if (3 < iVar5) { - if (param_2 == 1) { - LAB_00007138:; - // CpuResumeIntr(local_18[0]); + for (int pri = 0; pri < N_PRIORITIES; pri++) { + auto pse = &gPriStack[pri]; + + for (int idx = 0; idx < pse->count; idx++) { + if (pse->entries[idx] == cmd) { + pse->count--; + while (idx < pse->count) { + pse->entries[idx] = pse->entries[idx + 1]; + idx++; + } + + goto exit; + } } - return; } - goto LAB_00007088; + +exit: + if (suspend_irq == 1) { + // CpuResumeIntr(stat); + } } CmdHeader* GetMessage() { - CmdHeader* pCVar1; - int iVar2; - CmdHeader** ppCVar3; - PriStackEntry* iVar4; - int iVar5; + for (int pri = (N_PRIORITIES - 1); pri >= 0; pri--) { + auto pse = &gPriStack[pri]; + int idx = pse->count; - iVar5 = 3; - iVar4 = gPriStack + 3; - do { - iVar2 = iVar4->count + -1; - if (-1 < iVar2) { - ppCVar3 = iVar4->entries + iVar4->count + -1; - do { - pCVar1 = *ppCVar3; - if ((((pCVar1->lse != (LoadStackEntry*)0x0) && (pCVar1->status == -1)) && - (pCVar1->unk_24 != 0)) && - ((pCVar1->callback_buffer == (Buffer*)0x0 || - (pCVar1->callback_buffer->next == (Buffer*)0x0)))) { - return pCVar1; + for (idx = idx - 1; idx >= 0; idx--) { + auto cmd = pse->entries[idx]; + + if (cmd->lse && (u32)cmd->status == CMD_STATUS_IN_PROGRESS && cmd->ready_for_data) { + if (cmd->callback_buffer == nullptr) { + return cmd; } - iVar2 = iVar2 + -1; - ppCVar3 = ppCVar3 + -1; - } while (-1 < iVar2); + if (cmd->callback_buffer->next == nullptr) { + return cmd; + } + } } - iVar5 = iVar5 + -1; - iVar4 = iVar4 + -1; - if (iVar5 < 0) { - return (CmdHeader*)0x0; - } - } while (true); + } + + return nullptr; } void ProcessMessageData() { @@ -567,7 +472,7 @@ void ProcessMessageData() { ppCVar5 = iVar6->entries + iVar6->count + -1; do { pCVar2 = *ppCVar5; - if ((pCVar2 != (CmdHeader*)0x0) && (pCVar2->unk_24 != 0)) { + if ((pCVar2 != (CmdHeader*)0x0) && (pCVar2->ready_for_data != 0)) { iVar1 = pCVar2->status; if (iVar1 == -1) { pBVar3 = pCVar2->callback_buffer; @@ -618,80 +523,79 @@ void ReturnMessage(CmdHeader* param_1) { } VagCmd* GetVAGCommand() { - int iVar1; - u32 uVar2; - VagCmd* pRVar3; - - do { - while (vag_cmd_cnt == 0x1f) { + while (true) { + while (vag_cmd_cnt == 31) { DelayThread(100); } - do { - iVar1 = WaitSema(sSema); - uVar2 = 0; - pRVar3 = vag_cmds; - } while (iVar1 != 0); - do { - if (((int)vag_cmd_used >> (uVar2 & 0x1f) & 1U) == 0) { - vag_cmd_used = vag_cmd_used | 1 << (uVar2 & 0x1f); - vag_cmd_cnt = vag_cmd_cnt + 1; - if ((int)max_vag_cmd_cnt < vag_cmd_cnt) { + + while (WaitSema(sSema)) + ; + + for (int i = 0; i < 31; i++) { + // scan bits for free entry + if (((vag_cmd_used >> i) & 1) == 0) { + vag_cmd_used |= 1 << i; + + vag_cmd_cnt++; + if (max_vag_cmd_cnt < vag_cmd_cnt) { max_vag_cmd_cnt = vag_cmd_cnt; } + SignalSema(sSema); - return pRVar3; + return &vag_cmds[i]; } - uVar2 = uVar2 + 1; - pRVar3 = pRVar3 + 1; - } while ((int)uVar2 < 0x1f); - SignalSema(sSema); - } while (true); -} + } -void FreeVAGCommand(VagCmd* param_1) { - int iVar1; - u32 uVar2; - - // uVar2 = (param_1 + -0x17e50) * 0x781948b1 >> 2; - // kinda sus - uVar2 = (param_1 - vag_cmds) / sizeof(VagCmd); - if ((uVar2 < 0x1f) && (((int)vag_cmd_used >> (uVar2 & 0x1f) & 1U) != 0)) { - do { - iVar1 = WaitSema(sSema); - } while (iVar1 != 0); - vag_cmd_used = vag_cmd_used & ~(1 << (uVar2 & 0x1f)); - vag_cmd_cnt = vag_cmd_cnt + -1; SignalSema(sSema); } } -uint8_t* CheckForIsoPageBoundaryCrossing(Buffer* param_1) { - Page* new_page; - uint8_t* iVar1; - uint8_t* our_ptr; - uint8_t* page_end; +void FreeVAGCommand(VagCmd* cmd) { + u32 vag_idx; + + // get array index + vag_idx = (cmd - vag_cmds) / sizeof(VagCmd); + + if ((vag_idx < 0x1f) && ((vag_cmd_used >> vag_idx) & 1U) != 0) { + while (WaitSema(sSema)) + ; + + vag_cmd_used &= ~(1 << vag_idx); + --vag_cmd_cnt; + + SignalSema(sSema); + } +} + +u8* CheckForIsoPageBoundaryCrossing(Buffer* buf) { + Page* new_page; + u8* new_buffer; + u8* our_ptr; + u8* page_end; + + our_ptr = buf->decomp_buffer; + page_end = buf->page->ptr; - our_ptr = param_1->decomp_buffer; - page_end = (uint8_t*)param_1->page->ptr; if (page_end <= our_ptr) { - new_page = StepTopPage(param_1->plist, param_1->page); - param_1->page = new_page; - if (new_page != (Page*)0x0) { - iVar1 = new_page->buffer; - param_1->unk_12 = iVar1; - param_1->decomp_buffer = page_end + (iVar1 - (our_ptr + -1)); + new_page = StepTopPage(buf->plist, buf->page); + buf->page = new_page; + if (new_page != nullptr) { + new_buffer = new_page->buffer; + buf->unk_12 = new_buffer; + buf->decomp_buffer = page_end + (new_buffer - (our_ptr + -1)); } } - return param_1->decomp_buffer; + + return buf->decomp_buffer; } -void FreeDataBuffer(u32* param_1, u32 param_2) { +void FreeDataBuffer(u32* param_1, u32 buffer_idx) { if (param_1 == &BuffersAlloc) { - BuffersAlloc = BuffersAlloc & ~(1 << (param_2 & 0x1f)); - AllocdBuffersCount = AllocdBuffersCount + -1; + BuffersAlloc &= ~(1 << (buffer_idx & 0x1f)); + --AllocdBuffersCount; } else if (param_1 == &StrBuffersAlloc) { - AllocdStrBuffersCount = AllocdStrBuffersCount + -1; - StrBuffersAlloc = StrBuffersAlloc & ~(1 << (param_2 & 0x1f)); + StrBuffersAlloc &= ~(1 << (buffer_idx & 0x1f)); + --AllocdStrBuffersCount; } } diff --git a/game/overlord/jak2/spustreams.cpp b/game/overlord/jak2/spustreams.cpp index c95c8d44cd..87527ce327 100644 --- a/game/overlord/jak2/spustreams.cpp +++ b/game/overlord/jak2/spustreams.cpp @@ -15,6 +15,9 @@ using namespace iop; namespace jak2 { +void ProcessStreamData(); +void StopVagStream(VagCmd* cmd, int suspend_irq); + s32 StreamsThread = 0; void spusstreams_init_globals() { StreamsThread = 0; @@ -164,7 +167,7 @@ int ProcessVAGData(CmdHeader* param_1_in, Buffer* param_2) { param_1->spu_stream_dma_mem_addr + 0x2000, param_1, 0); if (iVar2 == 0) goto LAB_0000fecc; - (param_1->header).unk_24 = 0; + (param_1->header).ready_for_data = 0; goto LAB_0000fbdc; } if ((uVar3 & 1) != 0) { @@ -194,7 +197,7 @@ int ProcessVAGData(CmdHeader* param_1_in, Buffer* param_2) { param_1->spu_stream_dma_mem_addr + 0x2000, param_1, 0); if (iVar2 == 0) goto LAB_0000fecc; - (param_1->header).unk_24 = 0; + (param_1->header).ready_for_data = 0; goto LAB_0000fbdc; } iVar4 = param_1->xfer_size; @@ -223,7 +226,7 @@ int ProcessVAGData(CmdHeader* param_1_in, Buffer* param_2) { param_1, 0); if (iVar2 == 0) goto LAB_0000fecc; - (param_1->header).unk_24 = 0; + (param_1->header).ready_for_data = 0; iVar2 = 0x2000; if (pRVar7 != 0x0) { iVar2 = 0x4000; @@ -774,25 +777,25 @@ int CheckVAGStreamProgress(VagCmd* param_1) { pRVar4->unk_268 = 1; } } - (param_1->header).unk_24 = 0; + (param_1->header).ready_for_data = 0; // CpuResumeIntr(local_18[0]); uVar1 = 1; } } else { LAB_00010d58: uVar1 = 1; - if ((((param_1->sb_playing != '\0') && (uVar1 = 1, (param_1->header).unk_24 == 0)) && + if ((((param_1->sb_playing != '\0') && (uVar1 = 1, (param_1->header).ready_for_data == 0)) && param_1->safe_to_change_dma_fields) && (uVar1 = 1, param_1->unk_268 == 0)) { if (uVar3 < 0x2000) { uVar1 = 1; if ((param_1->num_processed_chunks & 1U) != 0) { - (param_1->header).unk_24 = 1; + (param_1->header).ready_for_data = 1; } } else { uVar1 = 1; if ((param_1->num_processed_chunks & 1U) == 0) { - (param_1->header).unk_24 = 1; + (param_1->header).ready_for_data = 1; } } } @@ -801,106 +804,27 @@ int CheckVAGStreamProgress(VagCmd* param_1) { } u32 CheckVagStreamsProgress() { - int iVar1; - VagCmd* pRVar2; - // int8_t* piVar3; - Buffer* pBVar4; - VagCmd* cmd; - int iVar5; - CmdHeader** ppCVar6; - VagStrListNode VStack200; - LfoListNode LStack96; - // undefined4 local_30 [2]; + while (true) { + ProcessStreamData(); - do { - if (gPriStack[3].count < 8) { - iVar5 = gPriStack[3].count + -1; - if (-1 < iVar5) { - ppCVar6 = gPriStack[3].entries + gPriStack[3].count + -1; - do { - pRVar2 = (VagCmd*)*ppCVar6; - if (pRVar2 != 0x0) { - if ((pRVar2->header).status == -1) { - if ((((pRVar2->header).unk_24 != 0) && - (pBVar4 = (pRVar2->header).callback_buffer, pBVar4 != (Buffer*)0x0)) && - ((pRVar2->header).callback == ProcessVAGData)) { - iVar1 = ProcessVAGData(&pRVar2->header, pBVar4); - (pRVar2->header).status = iVar1; - if ((pBVar4->decompressed_size == 0) && pRVar2->safe_to_change_dma_fields == 1) { - (pRVar2->header).callback_buffer = pBVar4->next; - FreeBuffer(pBVar4, 1); - } - if ((pRVar2->header).status == -1) - goto LAB_00010f30; - if (pRVar2->safe_to_change_dma_fields) { - ReleaseMessage((CmdHeader*)pRVar2, 1); - } - } - if ((pRVar2->header).status == -1) - goto LAB_00010f30; - } - ReleaseMessage((CmdHeader*)pRVar2, 1); - } - LAB_00010f30: - iVar5 = iVar5 + -1; - ppCVar6 = ppCVar6 + -1; - } while (-1 < iVar5); - } - } - pRVar2 = VagCmds; - iVar5 = 0; - // piVar3 = &VagCmds[0].byte9; - auto* cmd_iter = VagCmds; - do { - if (((cmd_iter->sb_playing != '\0') || - ((cmd_iter->byte4 != '\0' && (cmd_iter->byte6 != '\0')))) || - ((cmd_iter->header.unk_24 == 1 && (cmd_iter->id != 0)))) { - iVar1 = CheckVAGStreamProgress(pRVar2); - if (iVar1 == 0) { - if (cmd_iter->byte11 == '\0') { - // CpuSuspendIntr(local_30); - cmd = cmd_iter->stereo_sibling; - // piVar3[-8] = '\0'; - cmd_iter->sb_playing = 0; - if (cmd != 0x0) { - cmd->sb_playing = '\0'; - } - if (cmd_iter->unk_136 == 0) { - PauseVAG(pRVar2, 0); - // *piVar3 = '\x01'; - cmd_iter->byte9 = 1; - if (cmd != 0x0) { - PauseVAG(cmd, 0); - // *piVar3 = '\x01'; - cmd_iter->byte9 = 1; - } - } else { - PauseVAG(pRVar2, 0); - strncpy(VStack200.name, pRVar2->name, 0x30); - VStack200.id = cmd_iter->id; - RemoveVagStreamFromList(&VStack200, &PluginStreamsList); - RemoveVagStreamFromList(&VStack200, &EEPlayList); - LStack96.id = cmd_iter->id; - LStack96.plugin_id = cmd_iter->plugin_id; - RemoveLfoStreamFromList(&LStack96, &LfoList); - } - // CpuResumeIntr(local_30[0]); - } + for (auto& cmd : VagCmds) { + if (cmd.sb_playing || (cmd.byte4 && cmd.byte6) || + (cmd.header.ready_for_data == 1 && cmd.id)) { + if (CheckVAGStreamProgress(&cmd)) { + GetVAGStreamPos(&cmd); } else { - GetVAGStreamPos(pRVar2); + StopVagStream(&cmd, 1); } } - pRVar2 = pRVar2 + 1; - // piVar3 = piVar3 + 0x144; - cmd_iter++; - iVar5 = iVar5 + 1; - } while (iVar5 < 4); + }; + if (ActiveVagStreams < 1) { SleepThread(); } else { DelayThread(1000); } - } while (true); + }; + return 0; } @@ -976,7 +900,7 @@ u32 bswap(u32 param_1) { param_1 << 0x18; } -void ProcessStreamData(void) { +void ProcessStreamData() { int iVar1; VagCmd* pRVar2; Buffer* pBVar3; @@ -990,7 +914,7 @@ void ProcessStreamData(void) { pRVar2 = (VagCmd*)*ppCVar5; if (pRVar2 != 0x0) { if ((pRVar2->header).status == -1) { - if ((((pRVar2->header).unk_24 != 0) && + if ((((pRVar2->header).ready_for_data != 0) && (pBVar3 = (pRVar2->header).callback_buffer, pBVar3 != (Buffer*)0x0)) && ((pRVar2->header).callback == ProcessVAGData)) { iVar1 = ProcessVAGData(&pRVar2->header, pBVar3); diff --git a/game/overlord/jak2/vag.cpp b/game/overlord/jak2/vag.cpp index 3e56630aa3..3ed682e501 100644 --- a/game/overlord/jak2/vag.cpp +++ b/game/overlord/jak2/vag.cpp @@ -72,7 +72,7 @@ void InitVagCmds() { cmd.unk_264 = 0x4000; // puVar5[-7] = 0x4000; cmd.unk_268 = 0; // puVar5[-6] = 0; cmd.header.callback_buffer = nullptr; // puVar5[-0x42] = 0; - cmd.header.unk_24 = 1; // puVar5[-0x43] = 1; + cmd.header.ready_for_data = 1; // puVar5[-0x43] = 1; cmd.header.callback = NullCallback; // puVar5[-0x41] = NullCallback; cmd.header.lse = nullptr; // puVar5[-0x40] = 0; cmd.stereo_sibling = nullptr; // puVar5[-0x3d] = 0; @@ -233,7 +233,7 @@ void TerminateVAG(VagCmd* cmd, int param_2) { cmd->unk_256_pitch2 = 0; cmd->id = 0; cmd->plugin_id = 0; - (cmd->header).unk_24 = 0; + (cmd->header).ready_for_data = 0; cmd->unk_136 = 0; cmd->unk_140 = 0; cmd->pitch1 = 0; @@ -298,7 +298,7 @@ void TerminateVAG(VagCmd* cmd, int param_2) { cmd->unk_292 = 0; cmd->unk_296 = 0; (cmd->header).callback_buffer = (Buffer*)0x0; - (cmd->header).unk_24 = 0; + (cmd->header).ready_for_data = 0; (cmd->header).lse = (LoadStackEntry*)0x0; cmd->dma_iop_mem_ptr = (uint8_t*)0x0; cmd->dma_chan = -1; @@ -317,7 +317,7 @@ void TerminateVAG(VagCmd* cmd, int param_2) { VagCmdsPriCounter[pRVar4->priority] = VagCmdsPriCounter[pRVar4->priority] + -1; } iVar2 = 0x18; - piVar1 = &(pRVar4->header).unk_24; + piVar1 = &(pRVar4->header).ready_for_data; VagCmdsPriCounter[0] = VagCmdsPriCounter[0] + 1; for (auto& x : cmd->status_bytes) { x = 0; @@ -362,7 +362,7 @@ void TerminateVAG(VagCmd* cmd, int param_2) { pRVar4->unk_292 = 0; pRVar4->unk_296 = 0; (pRVar4->header).callback_buffer = (Buffer*)0x0; - (pRVar4->header).unk_24 = 0; + (pRVar4->header).ready_for_data = 0; (pRVar4->header).lse = (LoadStackEntry*)0x0; pRVar4->dma_iop_mem_ptr = (uint8_t*)0x0; pRVar4->dma_chan = -1; @@ -734,7 +734,7 @@ void InitVAGCmd(VagCmd* param_1, int param_2) { param_1->unk_260 = 0; param_1->unk_268 = 0; (param_1->header).callback_buffer = nullptr; - (param_1->header).unk_24 = 1; + (param_1->header).ready_for_data = 1; (param_1->header).lse = nullptr; param_1->stereo_sibling = nullptr; param_1->dma_iop_mem_ptr = nullptr; @@ -892,7 +892,7 @@ void FreeVagCmd(VagCmd* cmd, int /*param_2*/) { cmd->unk_292 = 0; cmd->unk_296 = 0; (cmd->header).callback_buffer = nullptr; - (cmd->header).unk_24 = 0; + (cmd->header).ready_for_data = 0; (cmd->header).lse = nullptr; cmd->dma_iop_mem_ptr = (uint8_t*)0x0; cmd->dma_chan = -1; @@ -966,7 +966,7 @@ void StopVAG(VagCmd* cmd, int /*param_2*/) { cmd->unk_256_pitch2 = 0; cmd->id = 0; cmd->plugin_id = 0; - (cmd->header).unk_24 = 0; + (cmd->header).ready_for_data = 0; cmd->unk_136 = 0; cmd->unk_140 = 0; cmd->pitch1 = 0; diff --git a/game/sce/iop.h b/game/sce/iop.h index 1aaa9183c8..165e8f7074 100644 --- a/game/sce/iop.h +++ b/game/sce/iop.h @@ -65,7 +65,9 @@ struct SysClock { }; struct MsgPacket { - u32 dummy = 0; + MsgPacket* next = nullptr; + u8 priority; + u8 dummy[3]; }; struct MbxParam {