Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align files to 32 KiB #10

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/gcmasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,19 @@ struct Directory {
}
};

size_t allocate_image_offset(size_t offset, size_t size) {
return (offset + size + 0xFF) & 0xFFFFFF00;
size_t align(size_t offset, size_t alignment) {
return (offset + alignment - 1) & ~(alignment - 1);
}

size_t allocate_image_offsets(Directory& dir, size_t min_offset) {
for (auto& it : dir.directories) {
min_offset = allocate_image_offsets(*it.second, min_offset);
}
for (auto& it : dir.files) {
it.second->image_offset = min_offset;
min_offset = allocate_image_offset(min_offset, it.second->size);
// Streaming audio files in particular must be 32 KiB aligned, but we don't
// attempt to detect those so we align everything to 32 KiB.
it.second->image_offset = align(min_offset, 0x8000);
min_offset = it.second->image_offset + it.second->size;
}
return min_offset;
}
Expand Down Expand Up @@ -251,11 +253,10 @@ void compile_image(
}

size_t apploader_offset = 0x2440;
size_t default_dol_offset = (apploader_offset + apploader_bin->size + 0xFF) & 0xFFFFFF00;
size_t file_data_start_offset = (default_dol_offset + default_dol->size + 0xFF) & 0xFFFFFF00;
size_t default_dol_offset = align(apploader_offset + apploader_bin->size, 0x100);
size_t file_data_start_offset = align(default_dol_offset + default_dol->size, 0x100);

size_t fst_offset = (allocate_image_offsets(root_dir, file_data_start_offset) + 0xFF) & 0xFFFFFF00;
fst_offset = (fst_offset + 0xFF) & 0xFFFFFF00;
size_t fst_offset = align(allocate_image_offsets(root_dir, file_data_start_offset), 0x100);

auto fst = generate_fst(root_dir);

Expand Down
Loading