diff --git a/tools/rom/build.c b/tools/rom/build.c index 662b00b7..0e9e47f6 100644 --- a/tools/rom/build.c +++ b/tools/rom/build.c @@ -438,6 +438,7 @@ bool WriteFnt(FILE *fpRom, size_t *pAddress, FileTree *pRoot, size_t firstFileId size_t tableStart = address; if (!WriteFntSubtable(pRoot, &ctx)) return false; + ctx.table[0].parentId = ctx.tableSize; size_t tableLength = ctx.tableSize * sizeof(FntEntry); for (size_t i = 0; i < ctx.tableSize; ++i) { diff --git a/tools/rom/files.h b/tools/rom/files.h index f59eddcb..7af4cbdc 100644 --- a/tools/rom/files.h +++ b/tools/rom/files.h @@ -137,10 +137,18 @@ bool FreeFileTree(FileTree *pTree) { int CompareFileTree(const void *a, const void *b) { FileTree *treeA = (FileTree*) a; FileTree *treeB = (FileTree*) b; + + // Files before directories + bool dirA = treeA->entry == NULL || treeA->entry->isSubdir; + bool dirB = treeB->entry == NULL || treeB->entry->isSubdir; + if (dirA && !dirB) return 1; + if (!dirA && dirB) return -1; + size_t lenA = treeA->entry->length; size_t lenB = treeB->entry->length; size_t minSize = (lenA < lenB) ? lenA : lenB; + // Alphabetic name order const char *nameA = treeA->entry->name; const char *nameB = treeB->entry->name; for (size_t i = 0; i < minSize; ++i) { @@ -148,6 +156,8 @@ int CompareFileTree(const void *a, const void *b) { const char chB = tolower(nameB[i]); if (chA != chB) return chA - chB; } + + // Shortest name first if (lenA < lenB) return -1; if (lenA > lenB) return 1; return 0;