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__
25 ; --------------------------------------------------------------------------
26 ; Initialize library modules
30 ldy #<(__CONSTRUCTOR_COUNT__*2)
32 lda #<__CONSTRUCTOR_TABLE__
33 ldx #>__CONSTRUCTOR_TABLE__
40 ; --------------------------------------------------------------------------
41 ; Cleanup library modules
45 ldy #<(__DESTRUCTOR_COUNT__*2)
47 lda #<__DESTRUCTOR_TABLE__
48 ldx #>__DESTRUCTOR_TABLE__
54 ; --------------------------------------------------------------------------
55 ; Generic table call handler. Since the routine is also used to call a table
56 ; of interrupt handlers, it uses heavily self modifying code for performance
57 ; reasons. It will go into the data segment for this reason ...
58 ; NOTE: The routine must not be called if the table is empty!
69 fetch1: lda $FFFF,y ; Patched at runtime
72 fetch2: lda $FFFF,y ; Patched at runtime
75 jmpvec: jsr $FFFF ; Patched at runtime
76 index: ldy #$FF ; Patched at runtime