mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
5e987cc0e2
Fixes #2545 Fixes #2546 Fixes #2547 Fixes #2548 Fixes #2549 Fixes #2550 Fixes #2551 Fixes #2552 Fixes #2553 Fixes #2554 Fixes #2555 Fixes #2556 Fixes #2557 Fixes #2558 Fixes #2559 Fixes #2560 Fixes #2561 Fixes #2562 Fixes #2563 Fixes #2564 Fixes #2565 Fixes #2567 Fixes #2566 Fixes #2568 Fixes #2569 Fixes #2570 Fixes #2522 Fixes #2571 --------- Co-authored-by: water <awaterford111445@gmail.com> Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com> Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
128 lines
3.1 KiB
C++
128 lines
3.1 KiB
C++
#include "list.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include "common/util/Assert.h"
|
|
|
|
#include "game/sce/iop.h"
|
|
|
|
using namespace iop;
|
|
namespace jak2 {
|
|
|
|
bool InitList(List* head, u32 elt_count, int elt_size) {
|
|
ListNode* buf_ptr;
|
|
int iVar1;
|
|
ListNode** ppLVar2;
|
|
u32 elt_idx;
|
|
SemaParam local_20;
|
|
|
|
head->elt_count = elt_count;
|
|
buf_ptr = (ListNode*)AllocSysMemory(0, elt_count * elt_size, 0);
|
|
head->buffer = (u8*)buf_ptr;
|
|
if (!buf_ptr) {
|
|
printf("IOP: ======================================================================\n");
|
|
printf("IOP: list InitList: no memory for list %s\n", head->name);
|
|
printf("IOP: ======================================================================\n");
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
elt_idx = 0;
|
|
head->next = buf_ptr;
|
|
// suspicious pointer math ahead.
|
|
if (elt_count != 0) {
|
|
ppLVar2 = &buf_ptr->prev;
|
|
do {
|
|
ppLVar2[1] = (ListNode*)0x0;
|
|
if (elt_idx < elt_count - 1) {
|
|
buf_ptr->next = (ListNode*)((u8*)&buf_ptr->next + elt_size);
|
|
} else {
|
|
buf_ptr->next = (ListNode*)0x0;
|
|
}
|
|
if (elt_idx == 0) {
|
|
*ppLVar2 = (ListNode*)0x0;
|
|
} else {
|
|
*ppLVar2 = (ListNode*)((u8*)buf_ptr - elt_size);
|
|
}
|
|
ppLVar2 = (ListNode**)((u8*)ppLVar2 + elt_size);
|
|
elt_idx = elt_idx + 1;
|
|
buf_ptr = (ListNode*)((u8*)&buf_ptr->next + elt_size);
|
|
} while (elt_idx < elt_count);
|
|
}
|
|
head->maybe_any_in_use = 0;
|
|
head->unk2_init0 = 0;
|
|
local_20.attr = 1;
|
|
local_20.init_count = 1;
|
|
local_20.max_count = 1;
|
|
local_20.option = 0;
|
|
iVar1 = CreateSema(&local_20);
|
|
head->sema = iVar1;
|
|
if (iVar1 < 0) {
|
|
printf("IOP: ======================================================================\n");
|
|
printf("IOP: list InitList: can\'t create semaphore for list %s\n", head->name);
|
|
printf("IOP: ======================================================================\n");
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
return head->buffer != (void*)0x0;
|
|
}
|
|
|
|
ListNode* AddToCircularList(List* param_1) {
|
|
int iVar1;
|
|
ListNode* pLVar2;
|
|
|
|
iVar1 = param_1->elt_count;
|
|
pLVar2 = param_1->next;
|
|
while (iVar1 != 0) {
|
|
iVar1 = iVar1 + -1;
|
|
if (pLVar2->in_use != 1)
|
|
goto LAB_00011c14;
|
|
pLVar2 = pLVar2->next;
|
|
}
|
|
if (pLVar2->in_use == 1) {
|
|
pLVar2 = param_1->next->next;
|
|
param_1->next = pLVar2;
|
|
pLVar2 = pLVar2->prev;
|
|
}
|
|
LAB_00011c14:
|
|
param_1->maybe_any_in_use = 1;
|
|
pLVar2->in_use = 1;
|
|
return pLVar2;
|
|
}
|
|
|
|
void MakeCircularList(List* lst) {
|
|
ListNode* pLVar1;
|
|
ListNode* pLVar2;
|
|
int iVar3;
|
|
ListNode* pLVar4;
|
|
|
|
pLVar4 = lst->next;
|
|
iVar3 = lst->elt_count;
|
|
pLVar1 = pLVar4->next;
|
|
pLVar2 = pLVar4;
|
|
while (true) {
|
|
if (pLVar1 == (ListNode*)0x0) {
|
|
if (iVar3 != 0) {
|
|
pLVar2->next = pLVar4;
|
|
pLVar4->prev = pLVar2;
|
|
}
|
|
return;
|
|
}
|
|
if (iVar3 == 0)
|
|
break;
|
|
pLVar2 = pLVar2->next;
|
|
pLVar1 = pLVar2->next;
|
|
iVar3 = iVar3 + -1;
|
|
}
|
|
}
|
|
|
|
void BreakCircularList(List* param_1) {
|
|
ListNode* pLVar1;
|
|
ListNode* pLVar2;
|
|
|
|
pLVar2 = param_1->next;
|
|
pLVar1 = pLVar2->prev;
|
|
if (pLVar1) {
|
|
pLVar1->next = nullptr;
|
|
pLVar2->prev = nullptr;
|
|
}
|
|
}
|
|
} // namespace jak2
|