]> git.sur5r.net Git - cc65/blob - libsrc/runtime/condes.s
Fixed a bug
[cc65] / libsrc / runtime / condes.s
1 ;
2 ; Ullrich von Bassewitz, 20.11.2000
3 ;
4 ; CC65 runtime: Support for calling module constructors/destructors
5 ;
6 ; The condes routine must be called with the table address in a/x and the
7 ; size of the table in y. The current implementation limits the table size
8 ; to 254 bytes (127 vectors) but this shouldn't be problem for now and may
9 ; be changed later.
10 ;
11 ; libinit and libdone call condes with the predefined module constructor and
12 ; destructor tables, they must be called from the platform specific startup
13 ; code.
14
15 ;
16 ; The function does also export jmpvec as general purpose jump vector that
17 ; lies in the data segment so it's address may be patched at runtime.
18 ;
19
20         .export initlib, donelib, condes
21         .export jmpvec
22
23         .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
24         .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
25
26
27
28 .code
29
30 ; --------------------------------------------------------------------------
31 ; Initialize library modules
32
33 .proc   initlib
34
35         lda     #<__CONSTRUCTOR_TABLE__
36         ldx     #>__CONSTRUCTOR_TABLE__
37         ldy     #<(__CONSTRUCTOR_COUNT__*2)
38         bne     condes
39         rts
40
41 .endproc
42
43
44 ; --------------------------------------------------------------------------
45 ; Cleanup library modules
46
47 .proc   donelib
48
49         lda     #<__DESTRUCTOR_TABLE__
50         ldx     #>__DESTRUCTOR_TABLE__
51         ldy     #<(__DESTRUCTOR_COUNT__*2)
52         bne     condes
53         rts
54
55 .endproc
56
57
58 ; --------------------------------------------------------------------------
59 ; Generic table call handler
60
61 .proc   condes
62
63         sta     getbyt+1
64         stx     getbyt+2
65         sty     index
66
67 loop:   ldy     index
68         beq     done
69         dey
70         jsr     getbyt
71         sta     jmpvec+2
72         dey
73         jsr     getbyt
74         sta     jmpvec+1
75         sty     index
76         jsr     jmpvec
77 .ifpc02
78         bra     loop
79 .else
80         jmp     loop
81 .endif
82
83 done:   rts
84
85 .endproc
86
87
88 ; --------------------------------------------------------------------------
89 ; Data. The getbyte routine is placed in the data segment cause it's patched
90 ; at runtime.
91
92 .bss
93
94 index:  .byte   0
95
96 .data
97
98 getbyt: lda     $FFFF,y
99         rts
100
101 jmpvec: jmp     $FFFF
102
103