SGDK
SGDK copied to clipboard
Every sound driver is always linked in
I have found that my ROMs always contain every sound driver. After analyzing the symbols and tracing their usage, I found this chain of calls is responsible:
_start_entry() => internal_reset() => Z80_init() => Z80_loadDriver().
And because Z80_loadDriver() and Z80_unloadDriver() reference all SGDK drivers, all drivers and their table data are always linked into every ROM, whether you use them or not.
I can't think of a reason I wouldn't know what driver I had loaded. Even if I might need more than one in different parts of my game, I would have enough state to keep track of what was loaded.
So I propose we deprecate and remove Z80_loadDriver(), Z80_unloadDriver(), and Z80_getLoadedDriver(). Games should call the load and unload methods of their drivers directly.
When I tried these changes locally, I found that I was able to strip 33552 bytes from "int main() { return 0; }". I eliminated 1380 more bytes by decoupling XGM2_doVBlankFadeProcess() from src/sys.c via a callback.