2000-11-20 22:17:14 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 20.11.2000
|
|
|
|
;
|
|
|
|
; CC65 runtime: Support for calling module constructors/destructors
|
|
|
|
;
|
|
|
|
; The condes routine must be called with the table address in a/x and the
|
2004-03-25 07:58:58 +00:00
|
|
|
; size of the table (which must not be zero!) in y. The current implementation
|
|
|
|
; limits the table size to 254 bytes (127 vectors) but this shouldn't be
|
|
|
|
; problem for now and may be changed later.
|
2000-11-20 22:17:14 +00:00
|
|
|
;
|
2000-11-21 10:51:53 +00:00
|
|
|
; libinit and libdone call condes with the predefined module constructor and
|
|
|
|
; destructor tables, they must be called from the platform specific startup
|
|
|
|
; code.
|
2000-11-27 22:59:03 +00:00
|
|
|
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export initlib, donelib, condes
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
|
|
|
|
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2003-10-10 17:52:12 +00:00
|
|
|
.macpack cpu
|
2000-11-20 22:17:14 +00:00
|
|
|
|
2000-11-21 10:51:53 +00:00
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Initialize library modules
|
|
|
|
|
2005-02-26 09:06:46 +00:00
|
|
|
.segment "INIT"
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc initlib
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #<(__CONSTRUCTOR_COUNT__*2)
|
|
|
|
beq exit
|
|
|
|
lda #<__CONSTRUCTOR_TABLE__
|
|
|
|
ldx #>__CONSTRUCTOR_TABLE__
|
2004-03-25 07:58:58 +00:00
|
|
|
jmp condes
|
|
|
|
exit: rts
|
2000-11-21 10:51:53 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Cleanup library modules
|
|
|
|
|
2005-02-26 09:06:46 +00:00
|
|
|
.code
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc donelib
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #<(__DESTRUCTOR_COUNT__*2)
|
|
|
|
beq exit
|
|
|
|
lda #<__DESTRUCTOR_TABLE__
|
|
|
|
ldx #>__DESTRUCTOR_TABLE__
|
|
|
|
jmp condes
|
2005-02-26 09:06:46 +00:00
|
|
|
exit: rts
|
2000-11-21 10:51:53 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
2004-04-04 14:15:45 +00:00
|
|
|
; Generic table call handler. The code uses self modifying code and goes
|
|
|
|
; into the data segment for this reason.
|
2004-03-25 07:58:58 +00:00
|
|
|
; NOTE: The routine must not be called if the table is empty!
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2004-03-25 07:58:58 +00:00
|
|
|
.data
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc condes
|
2000-11-20 22:17:14 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sta fetch1+1
|
|
|
|
stx fetch1+2
|
|
|
|
sta fetch2+1
|
|
|
|
stx fetch2+2
|
2004-03-25 07:58:58 +00:00
|
|
|
loop: dey
|
|
|
|
fetch1: lda $FFFF,y ; Patched at runtime
|
2003-12-14 17:41:27 +00:00
|
|
|
sta jmpvec+2
|
2013-05-09 11:56:54 +00:00
|
|
|
dey
|
2004-03-25 07:58:58 +00:00
|
|
|
fetch2: lda $FFFF,y ; Patched at runtime
|
2003-12-14 18:57:08 +00:00
|
|
|
sta jmpvec+1
|
2013-05-09 11:56:54 +00:00
|
|
|
sty index+1
|
|
|
|
jmpvec: jsr $FFFF ; Patched at runtime
|
|
|
|
index: ldy #$FF ; Patched at runtime
|
|
|
|
bne loop
|
2004-03-25 07:58:58 +00:00
|
|
|
rts
|
2000-11-20 22:17:14 +00:00
|
|
|
|
2000-11-21 10:51:53 +00:00
|
|
|
.endproc
|
|
|
|
|
|
|
|
|