]> git.sur5r.net Git - cc65/blob - libsrc/pce/condes.s
aa28833c2cea8d2c5750238c51445edb1377eadd
[cc65] / libsrc / pce / 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         .export initlib, donelib, condes
17
18         .import callax
19         .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
20         .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
21
22
23
24 .code
25
26 ; --------------------------------------------------------------------------
27 ; Initialize library modules
28
29 .proc   initlib
30
31         lda     #<__CONSTRUCTOR_TABLE__
32         ldx     #>__CONSTRUCTOR_TABLE__
33         ldy     #<(__CONSTRUCTOR_COUNT__*2)
34         bne     condes
35         rts
36
37 .endproc
38
39
40 ; --------------------------------------------------------------------------
41 ; Cleanup library modules
42
43 .proc   donelib
44
45         lda     #<__DESTRUCTOR_TABLE__
46         ldx     #>__DESTRUCTOR_TABLE__
47         ldy     #<(__DESTRUCTOR_COUNT__*2)
48         bne     condes
49         rts
50
51 .endproc
52
53
54 ; --------------------------------------------------------------------------
55 ; Generic table call handler
56
57 .proc   condes
58
59         sta getbyt+1
60         stx     getbyt+2
61         sty     index
62
63 loop:   ldy     index
64         beq     done
65         dey
66         jsr     getbyt
67         tax
68         dey
69         jsr     getbyt
70         sty     index
71         jsr     callax
72 .ifpc02
73         bra     loop
74 .else
75         jmp     loop
76 .endif
77
78 done:   rts
79
80 .endproc
81
82
83 ; --------------------------------------------------------------------------
84 ; Data. The getbyte routine is placed in the data segment cause it's patched
85 ; at runtime.
86
87 .bss
88
89 index:  .byte   0
90
91 .data
92
93 getbyt:
94 ;;getbyt_:
95         lda     $FFFF,y
96         rts