2 ; Ullrich von Bassewitz, 20.11.2000
4 ; CC65 runtime: Support for calling module constructors/destructors
6 ; The condes routine must be called with the table address in a/x and the
7 ; size of the table (which must not be zero!) in y. The current implementation
8 ; limits the table size to 254 bytes (127 vectors) but this shouldn't be
9 ; problem for now and may be changed later.
11 ; libinit and libdone call condes with the predefined module constructor and
12 ; destructor tables, they must be called from the platform specific startup
16 .export initlib, donelib, condes
18 .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
19 .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
23 ; --------------------------------------------------------------------------
24 ; Initialize library modules
30 ldy #<(__CONSTRUCTOR_COUNT__*2)
32 lda #<__CONSTRUCTOR_TABLE__
33 ldx #>__CONSTRUCTOR_TABLE__
40 ; --------------------------------------------------------------------------
41 ; Cleanup library modules
47 ldy #<(__DESTRUCTOR_COUNT__*2)
49 lda #<__DESTRUCTOR_TABLE__
50 ldx #>__DESTRUCTOR_TABLE__
57 ; --------------------------------------------------------------------------
58 ; Generic table call handler. The code uses self modifying code and goes
59 ; into the data segment for this reason.
60 ; NOTE: The routine must not be called if the table is empty!
71 fetch1: lda $FFFF,y ; Patched at runtime
74 fetch2: lda $FFFF,y ; Patched at runtime
77 jmpvec: jsr $FFFF ; Patched at runtime
78 index: ldy #$FF ; Patched at runtime