In every library that would benefit from initialization, one could use this macro code rather than explicitly doing so for each library.
For example, in an included file:setLibraryInitRoutine initFoo
Another file:setLibraryInitRoutine initBar
Then, somewhere suitable in the main calling code (somewhere after reset): executeLibraryInitRoutines
Code: Select all
.ifndef _INIT_LIB_H_
_INIT_LIB_H_ = 1
.scope initialize
initCounter .set 0
.endscope
.macro setLibraryInitRoutine proc
initialize::initCounter .set initialize::initCounter + 1 ; first entry starts at 1
initialize::.ident(.sprintf("%s%d","_Library_Init_List_", initialize::initCounter)) = proc
.endmacro
.macro executeLibraryInitRoutines
.if .not initialize::initCounter
.exitmacro ; if none, do nothing
.endif
.repeat initialize::initCounter, I
jsr initialize::.ident(.sprintf("%s%d","_Library_Init_List_", I+1))
.endrepeat
.endmacro
.endif