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
|
2000-11-21 10:51:53 +00:00
|
|
|
; size of the table 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
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
.export initlib, donelib, condes
|
2000-11-21 10:51:53 +00:00
|
|
|
|
|
|
|
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
|
|
|
|
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
|
|
|
|
|
2003-10-10 17:52:12 +00:00
|
|
|
.macpack cpu
|
2000-11-20 22:17:14 +00:00
|
|
|
|
|
|
|
.code
|
|
|
|
|
2000-11-21 10:51:53 +00:00
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Initialize library modules
|
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
.proc initlib
|
2000-11-21 10:51:53 +00:00
|
|
|
|
|
|
|
lda #<__CONSTRUCTOR_TABLE__
|
|
|
|
ldx #>__CONSTRUCTOR_TABLE__
|
|
|
|
ldy #<(__CONSTRUCTOR_COUNT__*2)
|
|
|
|
bne condes
|
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Cleanup library modules
|
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
.proc donelib
|
2000-11-21 10:51:53 +00:00
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
lda #<__DESTRUCTOR_TABLE__
|
|
|
|
ldx #>__DESTRUCTOR_TABLE__
|
|
|
|
ldy #<(__DESTRUCTOR_COUNT__*2)
|
|
|
|
bne condes
|
2000-11-21 10:51:53 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
2003-12-14 17:41:27 +00:00
|
|
|
; Generic table call handler. We cannot use callax here, since condes is also
|
|
|
|
; used for interrupt handlers, and callax clobbers ptr1.
|
2000-11-21 10:51:53 +00:00
|
|
|
|
|
|
|
.proc condes
|
|
|
|
|
|
|
|
sta getbyt+1
|
2000-11-20 22:17:14 +00:00
|
|
|
stx getbyt+2
|
2003-10-10 17:52:12 +00:00
|
|
|
sty index
|
2000-11-20 22:17:14 +00:00
|
|
|
|
|
|
|
loop: ldy index
|
|
|
|
beq done
|
|
|
|
dey
|
|
|
|
jsr getbyt
|
2003-12-14 17:41:27 +00:00
|
|
|
sta jmpvec+2
|
2003-12-14 18:57:08 +00:00
|
|
|
dey
|
|
|
|
jsr getbyt
|
|
|
|
sta jmpvec+1
|
2000-11-20 23:05:52 +00:00
|
|
|
sty index
|
2003-12-14 17:41:27 +00:00
|
|
|
jsr jmpvec
|
2003-10-10 17:52:12 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
2000-11-27 22:59:03 +00:00
|
|
|
bra loop
|
|
|
|
.else
|
|
|
|
jmp loop
|
|
|
|
.endif
|
2000-11-20 22:17:14 +00:00
|
|
|
|
|
|
|
done: rts
|
|
|
|
|
2000-11-21 10:51:53 +00:00
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
2000-11-20 22:17:14 +00:00
|
|
|
; --------------------------------------------------------------------------
|
2003-12-14 17:41:27 +00:00
|
|
|
; Data. The getbyte and jmpvec routines are placed in the data segment
|
|
|
|
; cause they're patched at runtime.
|
2000-11-20 22:17:14 +00:00
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
index: .byte 0
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
getbyt: lda $FFFF,y
|
|
|
|
rts
|
|
|
|
|
2003-12-14 17:41:27 +00:00
|
|
|
jmpvec: jmp $0000
|