Skip to content

Commit 72509b1

Browse files
committed
label some asm functions
1 parent d07c416 commit 72509b1

File tree

14 files changed

+75
-67
lines changed

14 files changed

+75
-67
lines changed

asm/src/code_08000F10.s

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,43 @@ CheckBits: @ 0x08000F10
1010
ldr r3, _08000F50 @ =ram_CheckBits
1111
bx r3
1212

13-
thumb_func_start sub_08000F14
14-
sub_08000F14: @ 0x08000F14
13+
// sum 3 drop probability vectors
14+
thumb_func_start SumDropProbabilities
15+
SumDropProbabilities: @ 0x08000F14
1516
push {r4, r5, r6}
16-
movs r4, #0x1e
17+
movs r4, #30 // vector addition for 16 shorts in reverse
1718
_08000F18:
18-
ldrsh r5, [r1, r4]
19-
ldrsh r6, [r2, r4]
20-
adds r5, r5, r6
21-
ldrsh r6, [r3, r4]
22-
adds r5, r5, r6
23-
strh r5, [r0, r4]
19+
ldrsh r5, [r1, r4] // row 1
20+
ldrsh r6, [r2, r4] // + row 2
21+
adds r5, r6
22+
ldrsh r6, [r3, r4] // + row 3
23+
adds r5, r6
24+
strh r5, [r0, r4] // store in output
2425
subs r4, #2
2526
bpl _08000F18
2627
pop {r4, r5, r6}
2728
bx lr
2829

29-
thumb_func_start sub_08000F2C
30-
sub_08000F2C: @ 0x08000F2C
30+
// sum 3 drop probabilities, clamp to 0, return scalar sum
31+
thumb_func_start SumDropProbabilities2
32+
SumDropProbabilities2: @ 0x08000F2C
3133
push {r4, r5, r6, r7}
32-
movs r4, #0x1e
33-
movs r7, #0
34+
movs r4, #30
35+
movs r7, #0 // sum
3436
_08000F32:
35-
ldrsh r5, [r1, r4]
36-
ldrsh r6, [r2, r4]
37-
adds r5, r5, r6
38-
ldrsh r6, [r3, r4]
39-
adds r5, r5, r6
40-
bpl _08000F40
37+
ldrsh r5, [r1, r4] // row 1
38+
ldrsh r6, [r2, r4] // + row 2
39+
adds r5, r6
40+
ldrsh r6, [r3, r4] // + row 3
41+
adds r5, r6
42+
bpl positive_drop_chance // clamp to 0
4143
movs r5, #0
42-
_08000F40:
43-
strh r5, [r0, r4]
44-
adds r7, r7, r5
44+
positive_drop_chance:
45+
strh r5, [r0, r4] // store in output
46+
adds r7, r5
4547
subs r4, #2
4648
bpl _08000F32
47-
adds r0, r7, #0
49+
adds r0, r7, #0 // return sum
4850
pop {r4, r5, r6, r7}
4951
bx lr
5052
.align 2, 0

include/entity.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include "color.h"
77
#include "sprite.h"
88

9-
#define MAX_ENTITIES 71
9+
#define MAX_ENTITIES 72
10+
#define MAX_MANAGERS 32
11+
#define MAX_AUX_PLAYER_ENTITIES 7
1012

1113
/** Kinds of Entity's supported by the game. */
1214
typedef enum {
@@ -38,6 +40,8 @@ typedef enum {
3840
typedef enum {
3941
ENT_DID_INIT = 0x1, /**< Graphics and other data loaded. */
4042
ENT_SCRIPTED = 0x2, /**< Execute in a scripted environment. */
43+
ENT_UNUSED1 = 0x4, /**< Unused delete flag. */
44+
ENT_UNUSED2 = 0x8, /**< Unused delete flag. */
4145
ENT_DELETED = 0x10, /**< Queue deletion next frame. */
4246
ENT_PERSIST = 0x20, /**< Persist between rooms. */
4347
ENT_COLLIDE = 0x80, /**< Collide with other Entity's. */
@@ -238,6 +242,15 @@ typedef struct LinkedList {
238242
Entity* first;
239243
} LinkedList;
240244

245+
/**
246+
* LinkedList's which point to allocate Entities.
247+
* These work together with Entity.prev and Entity.next fields
248+
* to allow the iteration of all Entity's.
249+
*/
250+
extern LinkedList gEntityLists[9];
251+
extern Entity gAuxPlayerEntities[MAX_AUX_PLAYER_ENTITIES];
252+
extern Entity gEntities[MAX_ENTITIES];
253+
241254
typedef void(EntityAction)(Entity*);
242255
typedef void (*EntityActionPtr)(Entity*);
243256
typedef void (*const* EntityActionArray)(Entity*);
@@ -283,7 +296,7 @@ Entity* CreateEnemy(u32 id, u32 type);
283296
Entity* CreateNPC(u32 id, u32 type, u32 type2);
284297
Entity* CreateObject(u32 id, u32 type, u32 type2);
285298
Entity* CreateObjectWithParent(Entity* parent, u32 id, u32 type, u32 type2);
286-
Entity* CreateItemGetEntity(void);
299+
Entity* CreateAuxPlayerEntity(void);
287300
Entity* CreateFx(Entity* parent, u32 type, u32 type2);
288301
/// @}
289302

@@ -484,14 +497,6 @@ void ClearEventPriority(void);
484497

485498
void sub_0805E958(void);
486499

487-
/**
488-
* LinkedList's which point to allocate Entities.
489-
* These work together with Entity.prev and Entity.next fields
490-
* to allow the iteration of all Entity's.
491-
*/
492-
extern LinkedList gEntityLists[9];
493-
extern Entity gItemGetEntities[7];
494-
495500
typedef struct {
496501
u8 unk_0;
497502
u8 unk_1;

include/structures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static_assert(sizeof(gActiveItems) == 0x70);
192192

193193
typedef struct {
194194
u8 event_priority; // system requested priority
195-
u8 ent_priority; // entity requested priority
195+
u8 ent_priority; // entity requested priority
196196
u8 queued_priority;
197197
u8 queued_priority_reset;
198198
Entity* requester;

linker.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ SECTIONS {
132132
. = 0x000010A0; gRoomTransition = .;
133133
. = 0x00001150; gRand = .;
134134
. = 0x00001160; gPlayerEntity = .;
135-
. = 0x000011E8; gItemGetEntities = .;
136-
. = 0x000015A0; gUnk_030015A0 = .;
135+
. = 0x000011E8; gAuxPlayerEntities = .;
136+
. = 0x000015A0; gEntities = .;
137137
. = 0x00003BE0; gCarriedEntity = .;
138138
. = 0x00003C70; gUnk_03003C70 = .;
139139
. = 0x00003D70; gEntityLists = .;

src/enemy/acroBandits.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void AcroBandit_Type0Action5(Entity* this) {
240240

241241
GetNextFrame(this);
242242
if (this->frame & ANIM_DONE) {
243-
if (gEntCount < MAX_ENTITIES - 4) {
243+
if (gEntCount < MAX_ENTITIES - 5) {
244244
u32 tmp = Random();
245245
tmp &= 3;
246246

src/enemy/fireballGuy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void FireballGuy_Action2(Entity* this) {
8181

8282
/* Can we create enough new entities? */
8383
count = typeEntityCount[this->type];
84-
if (MAX_ENTITIES + 1 - count <= gEntCount)
84+
if (MAX_ENTITIES - count <= gEntCount)
8585
return;
8686

8787
/* Create 2-5 new MiniFireballGuy */

src/enemy/slime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void sub_080450A8(Entity* this) {
105105

106106
/* Can we create enough new entities? */
107107
count = typeEntityCount[this->type];
108-
if (MAX_ENTITIES + 1 - count <= gEntCount)
108+
if (MAX_ENTITIES - count <= gEntCount)
109109
return;
110110

111111
/* Create 2-4 new MiniSlime */

src/entity.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include "npc.h"
77
#include "manager/diggingCaveEntranceManager.h"
88

9+
typedef struct Temp {
10+
void* prev;
11+
void* next;
12+
u8 _0[0x38];
13+
} Temp;
14+
915
extern u8 gUpdateVisibleTiles;
1016
extern Manager gUnk_02033290;
1117
void UpdatePlayerInput(void);
@@ -241,8 +247,6 @@ void EraseAllEntities(void) {
241247
gOAMControls.unk[1].unk6 = 1;
242248
}
243249

244-
extern Entity gUnk_030015A0[0x48];
245-
246250
Entity* GetEmptyEntity() {
247251
u8 flags_ip;
248252
Entity* end;
@@ -253,9 +257,9 @@ Entity* GetEmptyEntity() {
253257
LinkedList* listPtr;
254258
LinkedList* endListPtr;
255259

256-
if (gEntCount <= 0x46) {
257-
currentEnt = gUnk_030015A0;
258-
end = currentEnt + ARRAY_COUNT(gUnk_030015A0);
260+
if (gEntCount < MAX_ENTITIES - 1) {
261+
currentEnt = gEntities;
262+
end = currentEnt + ARRAY_COUNT(gEntities);
259263

260264
do {
261265
if (currentEnt->prev == 0) {
@@ -267,7 +271,8 @@ Entity* GetEmptyEntity() {
267271
currentEnt = &gPlayerEntity;
268272

269273
do {
270-
if ((s32)currentEnt->prev < 0 && (currentEnt->flags & 0xc) && currentEnt != gUpdateContext.current_entity) {
274+
if ((s32)currentEnt->prev < 0 && (currentEnt->flags & (ENT_UNUSED1 | ENT_UNUSED2)) &&
275+
currentEnt != gUpdateContext.current_entity) {
271276
ClearDeletedEntity(currentEnt);
272277
return currentEnt;
273278
}
@@ -282,9 +287,10 @@ Entity* GetEmptyEntity() {
282287
currentEnt = listPtr->first;
283288
nextList = listPtr + 1;
284289
while ((u32)currentEnt != (u32)listPtr) {
285-
if (currentEnt->kind != MANAGER && flags_ip < (currentEnt->flags & 0x1c) &&
290+
if (currentEnt->kind != MANAGER &&
291+
flags_ip < (currentEnt->flags & (ENT_UNUSED1 | ENT_UNUSED2 | ENT_DELETED)) &&
286292
gUpdateContext.current_entity != currentEnt) {
287-
flags_ip = currentEnt->flags & 0x1c;
293+
flags_ip = currentEnt->flags & (ENT_UNUSED1 | ENT_UNUSED2 | ENT_DELETED);
288294
rv = currentEnt;
289295
}
290296
currentEnt = currentEnt->next;
@@ -301,16 +307,16 @@ Entity* GetEmptyEntity() {
301307
return rv;
302308
}
303309

304-
extern Entity gItemGetEntities[7];
310+
extern Entity gAuxPlayerEntities[7];
305311

306-
Entity* CreateItemGetEntity(void) {
307-
Entity* ent = gItemGetEntities;
312+
Entity* CreateAuxPlayerEntity(void) {
313+
Entity* ent = gAuxPlayerEntities;
308314

309315
do {
310316
if (ent->prev == NULL) {
311317
return ent;
312318
}
313-
} while (++ent < &gItemGetEntities[7]);
319+
} while (++ent < &gAuxPlayerEntities[7]);
314320

315321
return NULL;
316322
}
@@ -407,12 +413,6 @@ void DeleteAllEntities(void) {
407413
}
408414
}
409415

410-
typedef struct Temp {
411-
void* prev;
412-
void* next;
413-
u8 _0[0x38];
414-
} Temp;
415-
416416
// fix this
417417
Manager* GetEmptyManager(void) {
418418
Temp* it;

src/itemUtils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ void EnableRandomDrops(void) {
403403
gRoomVars.randomDropsDisabled = FALSE;
404404
}
405405

406-
extern void sub_08000F14(s16*, const s16*, const s16*, const s16*);
407-
extern u32 sub_08000F2C(s16*, const s16*, const s16*, const s16*);
406+
extern void SumDropProbabilities(s16*, const s16*, const s16*, const s16*);
407+
extern u32 SumDropProbabilities2(s16*, const s16*, const s16*, const s16*);
408408
u32 CreateItemDrop(Entity* arg0, u32 itemId, u32 itemParameter);
409409
u32 CreateRandomItemDrop(Entity* arg0, u32 arg1) {
410410
extern const u8 gUnk_080FE1B4[] /* = {
@@ -459,7 +459,7 @@ u32 CreateRandomItemDrop(Entity* arg0, u32 arg1) {
459459
#endif
460460
}
461461
// vector addition, s0 = ptr4 + ptr2 + ptr3
462-
sub_08000F14(droptable.a, ptr4->a, ptr2->a, ptr3->a);
462+
SumDropProbabilities(droptable.a, ptr4->a, ptr2->a, ptr3->a);
463463
if (gSave.stats.health <= 8) {
464464
droptable.s.hearts += 5;
465465
}
@@ -486,7 +486,7 @@ u32 CreateRandomItemDrop(Entity* arg0, u32 arg1) {
486486
// vector addition, s0 = s0 + ptr2 + ptr3
487487
// resulting values are clamped to be >= 0
488488
// returns sum over s0
489-
summOdds = sub_08000F2C(droptable.a, droptable.a, ptr2->a, ptr3->a);
489+
summOdds = SumDropProbabilities2(droptable.a, droptable.a, ptr2->a, ptr3->a);
490490
rand = Random();
491491
item = (rand >> 0x18);
492492
item &= 0xF;

src/object/gentariCurtain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void sub_080921BC(GentariCurtainEntity* this) {
9696
GenericEntity* pEVar1;
9797
GenericEntity* end;
9898

99-
pEVar1 = (GenericEntity*)gItemGetEntities;
99+
pEVar1 = (GenericEntity*)gAuxPlayerEntities;
100100
end = pEVar1 + 0x4f;
101101

102102
do {

src/objectUtils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const s8 gUnk_08126EEC[] = {
3131
};
3232

3333
Entity* CreateLinkAnimation(Entity* parent, u32 type, u32 type2) {
34-
Entity* e = CreateItemGetEntity();
34+
Entity* e = CreateAuxPlayerEntity();
3535
if (e != NULL) {
3636
LinkAnimationEntity* this = (LinkAnimationEntity*)e;
3737
e->id = LINK_ANIMATION;

src/playerItemUtils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static Entity* GiveItemWithCutscene(u32 item, u32 type2, u32 delay) {
3636
item = ITEM_RUPEE50;
3737
type2 = 0;
3838
}
39-
e = CreateItemGetEntity();
39+
e = CreateAuxPlayerEntity();
4040
if (e != NULL) {
4141
e->type = item;
4242
e->type2 = type2;

src/playerUtils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ Entity* CreatePlayerItemWithParent(ItemBehavior* this, u32 id) {
462462
}
463463

464464
void* CreateItemGetPlayerItemWithParent(ItemBehavior* this) {
465-
GenericEntity* playerItem = (GenericEntity*)CreateItemGetEntity();
465+
GenericEntity* playerItem = (GenericEntity*)CreateAuxPlayerEntity();
466466
if (playerItem != NULL) {
467467
playerItem->base.id = gItemDefinitions[this->behaviorId].playerItemId;
468468
playerItem->base.kind = PLAYER_ITEM;
@@ -501,7 +501,7 @@ Entity* CreatePlayerItem(u32 id, u32 type, u32 type2, u32 unk) {
501501
Entity* sub_08077CF8(u32 id, u32 type, u32 type2, u32 unk) {
502502
GenericEntity* ent;
503503

504-
ent = (GenericEntity*)CreateItemGetEntity();
504+
ent = (GenericEntity*)CreateAuxPlayerEntity();
505505
if (ent != NULL) {
506506
ent->base.flags = ENT_COLLIDE;
507507
ent->base.kind = PLAYER_ITEM;

src/ui.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ void ButtonUIElement_Action1(UIElement* element) {
626626

627627
MAX_MOVEMENT = (!element->type2) ? 4 : 8;
628628

629-
if (element->type2 == 0 && (((gUnk_0200AF00.unk_1 >> element->type) & 1) || (gMessage.state & MESSAGE_ACTIVE) != 0)) {
629+
if (element->type2 == 0 &&
630+
(((gUnk_0200AF00.unk_1 >> element->type) & 1) || (gMessage.state & MESSAGE_ACTIVE) != 0)) {
630631
y = (s16)gUnk_0200AF00.buttonY[element->type] - 0x28;
631632
} else {
632633
y = (s16)gUnk_0200AF00.buttonY[element->type];

0 commit comments

Comments
 (0)