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
|
|
|
|
2002-12-26 15:45:48 +00:00
|
|
|
.import jmpvec
|
2000-11-21 10:51:53 +00:00
|
|
|
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
|
|
|
|
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Generic table call handler
|
|
|
|
|
|
|
|
.proc condes
|
|
|
|
|
|
|
|
sta getbyt+1
|
2000-11-20 22:17:14 +00:00
|
|
|
stx getbyt+2
|
|
|
|
sty index
|
|
|
|
|
|
|
|
loop: ldy index
|
|
|
|
beq done
|
|
|
|
dey
|
|
|
|
jsr getbyt
|
|
|
|
sta jmpvec+2
|
|
|
|
dey
|
|
|
|
jsr getbyt
|
|
|
|
sta jmpvec+1
|
2000-11-20 23:05:52 +00:00
|
|
|
sty index
|
2000-11-20 22:17:14 +00:00
|
|
|
jsr jmpvec
|
2000-11-27 22:59:03 +00:00
|
|
|
.ifpc02
|
|
|
|
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
|
|
|
; --------------------------------------------------------------------------
|
|
|
|
; Data. The getbyte routine is placed in the data segment cause it's patched
|
|
|
|
; at runtime.
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
index: .byte 0
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
getbyt: lda $FFFF,y
|
|
|
|
rts
|
|
|
|
|
2000-11-21 10:51:53 +00:00
|
|
|
|