Skip to content

Commit

Permalink
wip starting item support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mike8699 committed Sep 16, 2024
1 parent 30f5f42 commit ad0da92
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions base/code/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
mov r1, 0x7d
ldr r0, [r0]
pop pc

.thumb
@set_starting_items:
push lr

push r1 ; save r1, as it's used later on in the original code
bl set_starting_items
pop r1 ; restore r1

; These three instructions are the original instructions that the `bl` to this current
; function replaced. They are needed to be able to return to the original code.
mov r0, 0x3C
mul r0, r1

pop pc
.pool
.endarea

Expand Down Expand Up @@ -129,6 +144,16 @@
.pool
.endarea

.thumb
.org 0x20ad20e
.area 0x6, 0x00
; hook into the function that sets the starting item flags
bl @set_starting_items
; original instruction, do not change
b 0x20ad216
.pool
.endarea

.thumb
.org 0x20ae1c2
.area 0x6, 0x00
Expand Down Expand Up @@ -439,4 +464,5 @@
.importobj "code/spawn_custom_freestanding_item.o"
.importobj "code/custom_salvage_item.o"
.importobj "code/extend_give_item_function.o"
.importobj "code/set_starting_items.o"
.close
25 changes: 25 additions & 0 deletions base/code/set_starting_items.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdbool.h>
#include <stdint.h>

typedef struct {
uint8_t address;
uint8_t bit;
} ItemFlag;

// define array of ints
ItemFlag starting_items[] = {
// Oshus sword
// {0x0, 0x1}, // TODO: enable this to support "Start with sword setting"

// SW Sea Chart
{0x8, 0x2}, // TODO: make this dynamic when the starting island is randomized
};

__attribute__((target("thumb"))) void set_starting_items(void) {
uint8_t *base_address = (uint8_t *)(0x21BA604);

for (int i = 0; i < sizeof(starting_items) / sizeof(ItemFlag); i++) {
uint8_t *flag = (uint8_t *)(starting_items[i].address + base_address);
*flag |= starting_items[i].bit;
}
}

0 comments on commit ad0da92

Please sign in to comment.