Skip to content

Commit ad0da92

Browse files
committed
wip starting item support
We'll start with just the SW Sea chart, but this should be expanded in the future to eventually support any arbitrary item(s) the player chooses.
1 parent 30f5f42 commit ad0da92

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

base/code/main.asm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@
8383
mov r1, 0x7d
8484
ldr r0, [r0]
8585
pop pc
86+
87+
.thumb
88+
@set_starting_items:
89+
push lr
90+
91+
push r1 ; save r1, as it's used later on in the original code
92+
bl set_starting_items
93+
pop r1 ; restore r1
94+
95+
; These three instructions are the original instructions that the `bl` to this current
96+
; function replaced. They are needed to be able to return to the original code.
97+
mov r0, 0x3C
98+
mul r0, r1
99+
100+
pop pc
86101
.pool
87102
.endarea
88103

@@ -129,6 +144,16 @@
129144
.pool
130145
.endarea
131146

147+
.thumb
148+
.org 0x20ad20e
149+
.area 0x6, 0x00
150+
; hook into the function that sets the starting item flags
151+
bl @set_starting_items
152+
; original instruction, do not change
153+
b 0x20ad216
154+
.pool
155+
.endarea
156+
132157
.thumb
133158
.org 0x20ae1c2
134159
.area 0x6, 0x00
@@ -439,4 +464,5 @@
439464
.importobj "code/spawn_custom_freestanding_item.o"
440465
.importobj "code/custom_salvage_item.o"
441466
.importobj "code/extend_give_item_function.o"
467+
.importobj "code/set_starting_items.o"
442468
.close

base/code/set_starting_items.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
4+
typedef struct {
5+
uint8_t address;
6+
uint8_t bit;
7+
} ItemFlag;
8+
9+
// define array of ints
10+
ItemFlag starting_items[] = {
11+
// Oshus sword
12+
// {0x0, 0x1}, // TODO: enable this to support "Start with sword setting"
13+
14+
// SW Sea Chart
15+
{0x8, 0x2}, // TODO: make this dynamic when the starting island is randomized
16+
};
17+
18+
__attribute__((target("thumb"))) void set_starting_items(void) {
19+
uint8_t *base_address = (uint8_t *)(0x21BA604);
20+
21+
for (int i = 0; i < sizeof(starting_items) / sizeof(ItemFlag); i++) {
22+
uint8_t *flag = (uint8_t *)(starting_items[i].address + base_address);
23+
*flag |= starting_items[i].bit;
24+
}
25+
}

0 commit comments

Comments
 (0)