Skip to content

Commit 08144bf

Browse files
committed
Match linked_list.c
1 parent 37f13dc commit 08144bf

File tree

5 files changed

+142
-14
lines changed

5 files changed

+142
-14
lines changed

include/sys/linked_list.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef _SYS_LINKED_LIST_H
2+
#define _SYS_LINKED_LIST_H
3+
4+
#include "PR/ultratypes.h"
5+
6+
typedef struct {
7+
s16 count;
8+
s16 nextFieldOffset;
9+
void *head;
10+
} LinkedList;
11+
12+
// Pointer to the "next" field of a node
13+
#define LINKED_LIST_NEXT_FIELD(list, node) ((void**)((u32)node + list->nextFieldOffset))
14+
// Same as LINKED_LIST_NEXT_FIELD but the add operands are reversed... just exists for matching code
15+
#define LINKED_LIST_NEXT_FIELD2(list, node) ((void**)(list->nextFieldOffset + (u32)node))
16+
17+
LinkedList *linked_list_init(LinkedList *list, s16 nextFieldOffset);
18+
void linked_list_prepend(LinkedList *list, void *node);
19+
void linked_list_append(LinkedList *list, void *node);
20+
void linked_list_insert(LinkedList *list, void *after, void *node);
21+
void linked_list_remove(LinkedList *list, void *node);
22+
void linked_list_remove_fast(LinkedList *list, void *before, void *node);
23+
24+
#endif

splat.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ segments:
4242
- [0xBC10, c, generic_stack]
4343
- [0xBED0, c, segment_BED0]
4444
- [0xC4B0, c, bitstream]
45-
- [0xC660, c, C660]
45+
- [0xC660, c, linked_list]
4646
- [0xC840, c, dll]
4747
- [0xD280, c, fonts]
4848
- [0x10DF0, c, input]

src/C660.c

-13
This file was deleted.

src/linked_list.c

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "PR/ultratypes.h"
2+
#include "sys/linked_list.h"
3+
4+
LinkedList *linked_list_init(LinkedList *list, s16 nextFieldOffset) {
5+
list->head = NULL;
6+
list->nextFieldOffset = nextFieldOffset;
7+
8+
return list;
9+
}
10+
11+
void linked_list_prepend(LinkedList *list, void *node) {
12+
void *prevHead;
13+
14+
prevHead = list->head;
15+
list->head = node;
16+
17+
*LINKED_LIST_NEXT_FIELD(list, node) = prevHead;
18+
19+
list->count += 1;
20+
}
21+
22+
void linked_list_append(LinkedList *list, void *node) {
23+
void *next;
24+
void *last;
25+
26+
if (list->head == NULL) {
27+
list->head = node;
28+
} else {
29+
next = list->head;
30+
last = next;
31+
32+
while (next != NULL) {
33+
last = next;
34+
next = *LINKED_LIST_NEXT_FIELD2(list, last);
35+
}
36+
37+
*LINKED_LIST_NEXT_FIELD(list, last) = node;
38+
}
39+
40+
*LINKED_LIST_NEXT_FIELD(list, node) = NULL;
41+
42+
list->count += 1;
43+
}
44+
45+
void linked_list_insert(LinkedList *list, void *after, void *node) {
46+
void *next;
47+
48+
if (list->head == NULL) {
49+
list->head = node;
50+
} else {
51+
if (after == NULL) {
52+
// Prepend if after is null
53+
next = list->head;
54+
list->head = node;
55+
} else {
56+
// Insert between after and its next node
57+
next = *LINKED_LIST_NEXT_FIELD2(list, after);
58+
*LINKED_LIST_NEXT_FIELD(list, after) = node;
59+
}
60+
61+
*LINKED_LIST_NEXT_FIELD(list, node) = next;
62+
}
63+
64+
list->count += 1;
65+
}
66+
67+
void linked_list_remove(LinkedList *list, void *node) {
68+
void *before;
69+
void *curr;
70+
71+
if (node == list->head) {
72+
list->head = *LINKED_LIST_NEXT_FIELD(list, list->head);
73+
list->count -= 1;
74+
return;
75+
}
76+
77+
// Find the node before the one we want to remove
78+
curr = list->head;
79+
before = curr;
80+
81+
while (curr != NULL && curr != node) {
82+
before = curr;
83+
curr = *LINKED_LIST_NEXT_FIELD2(list, curr);
84+
}
85+
86+
if (curr != NULL) {
87+
void *next = *LINKED_LIST_NEXT_FIELD2(list, curr);
88+
89+
if (curr == list->head) {
90+
list->head = next;
91+
} else {
92+
*LINKED_LIST_NEXT_FIELD(list, before) = next;
93+
}
94+
95+
list->count -= 1;
96+
}
97+
}
98+
99+
void linked_list_remove_fast(LinkedList *list, void *before, void *node) {
100+
if (node != NULL) {
101+
void *next = *LINKED_LIST_NEXT_FIELD2(list, node);
102+
103+
if (node == list->head) {
104+
list->head = next;
105+
} else {
106+
*LINKED_LIST_NEXT_FIELD(list, before) = next;
107+
}
108+
109+
list->count -= 1;
110+
}
111+
}

symbol_addrs.txt

+6
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,12 @@ delayByteMirror = 0x8008c954; // size:0x1
985985
pointerIntArrayCounter = 0x800b1798; // size:0x2
986986
SHORT_ARRAY_800b17d0 = 0x800b17d0;
987987
gFramebufferEnd = 0x800bce08; // size:0x4
988+
linked_list_init = 0x8000BA60; // type:func
989+
linked_list_prepend = 0x8000BA80; // type:func
990+
linked_list_append = 0x8000BAA8; // type:func
991+
linked_list_insert = 0x8000BB08; // type:func
992+
linked_list_remove = 0x8000BB5C; // type:func
993+
linked_list_remove_fast = 0x8000BBF4; // type:func
988994
init_filesystem = 0x80037090; // type:func
989995
init_textures = 0x8003cc90; // type:func
990996
init_models = 0x80017c20; // type:func

0 commit comments

Comments
 (0)