mirror of
https://github.com/cc65/cc65.git
synced 2024-07-05 21:29:03 +00:00
Optimized the condes routine, because it is used to schedule interrupt
handlers on many platforms, so too many cycles are evil. git-svn-id: svn://svn.cc65.org/cc65/trunk@2962 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ac08caec07
commit
e4554505d6
@ -4,9 +4,9 @@
|
|||||||
; CC65 runtime: Support for calling module constructors/destructors
|
; CC65 runtime: Support for calling module constructors/destructors
|
||||||
;
|
;
|
||||||
; The condes routine must be called with the table address in a/x and the
|
; The condes routine must be called with the table address in a/x and the
|
||||||
; size of the table in y. The current implementation limits the table size
|
; size of the table (which must not be zero!) in y. The current implementation
|
||||||
; to 254 bytes (127 vectors) but this shouldn't be problem for now and may
|
; limits the table size to 254 bytes (127 vectors) but this shouldn't be
|
||||||
; be changed later.
|
; problem for now and may be changed later.
|
||||||
;
|
;
|
||||||
; libinit and libdone call condes with the predefined module constructor and
|
; libinit and libdone call condes with the predefined module constructor and
|
||||||
; destructor tables, they must be called from the platform specific startup
|
; destructor tables, they must be called from the platform specific startup
|
||||||
@ -27,11 +27,12 @@
|
|||||||
|
|
||||||
.proc initlib
|
.proc initlib
|
||||||
|
|
||||||
|
ldy #<(__CONSTRUCTOR_COUNT__*2)
|
||||||
|
beq exit
|
||||||
lda #<__CONSTRUCTOR_TABLE__
|
lda #<__CONSTRUCTOR_TABLE__
|
||||||
ldx #>__CONSTRUCTOR_TABLE__
|
ldx #>__CONSTRUCTOR_TABLE__
|
||||||
ldy #<(__CONSTRUCTOR_COUNT__*2)
|
jmp condes
|
||||||
bne condes
|
exit: rts
|
||||||
rts
|
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
@ -41,57 +42,41 @@
|
|||||||
|
|
||||||
.proc donelib
|
.proc donelib
|
||||||
|
|
||||||
lda #<__DESTRUCTOR_TABLE__
|
ldy #<(__DESTRUCTOR_COUNT__*2)
|
||||||
ldx #>__DESTRUCTOR_TABLE__
|
beq initlib::exit
|
||||||
ldy #<(__DESTRUCTOR_COUNT__*2)
|
lda #<__DESTRUCTOR_TABLE__
|
||||||
bne condes
|
ldx #>__DESTRUCTOR_TABLE__
|
||||||
rts
|
jmp condes
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
; --------------------------------------------------------------------------
|
; --------------------------------------------------------------------------
|
||||||
; Generic table call handler. We cannot use callax here, since condes is also
|
; Generic table call handler. Since the routine is also used to call a table
|
||||||
; used for interrupt handlers, and callax clobbers ptr1.
|
; of interrupt handlers, it uses heavily self modifying code for performance
|
||||||
|
; reasons. It will go into the data segment for this reason ...
|
||||||
.proc condes
|
; NOTE: The routine must not be called if the table is empty!
|
||||||
|
|
||||||
sta getbyt+1
|
|
||||||
stx getbyt+2
|
|
||||||
sty index
|
|
||||||
|
|
||||||
loop: ldy index
|
|
||||||
beq done
|
|
||||||
dey
|
|
||||||
jsr getbyt
|
|
||||||
sta jmpvec+2
|
|
||||||
dey
|
|
||||||
jsr getbyt
|
|
||||||
sta jmpvec+1
|
|
||||||
sty index
|
|
||||||
jsr jmpvec
|
|
||||||
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
|
||||||
bra loop
|
|
||||||
.else
|
|
||||||
jmp loop
|
|
||||||
.endif
|
|
||||||
|
|
||||||
done: rts
|
|
||||||
|
|
||||||
.endproc
|
|
||||||
|
|
||||||
|
|
||||||
; --------------------------------------------------------------------------
|
|
||||||
; Data. The getbyte and jmpvec routines are placed in the data segment
|
|
||||||
; cause they're patched at runtime.
|
|
||||||
|
|
||||||
.bss
|
|
||||||
|
|
||||||
index: .byte 0
|
|
||||||
|
|
||||||
.data
|
.data
|
||||||
|
|
||||||
getbyt: lda $FFFF,y
|
.proc condes
|
||||||
rts
|
|
||||||
|
sta fetch1+1
|
||||||
|
stx fetch1+2
|
||||||
|
sta fetch2+1
|
||||||
|
stx fetch2+2
|
||||||
|
loop: dey
|
||||||
|
fetch1: lda $FFFF,y ; Patched at runtime
|
||||||
|
sta jmpvec+2
|
||||||
|
dey
|
||||||
|
fetch2: lda $FFFF,y ; Patched at runtime
|
||||||
|
sta jmpvec+1
|
||||||
|
sty index+1
|
||||||
|
jmpvec: jsr $FFFF ; Patched at runtime
|
||||||
|
index: ldy #$FF ; Patched at runtime
|
||||||
|
bne loop
|
||||||
|
rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
jmpvec: jmp $0000
|
|
||||||
|
Loading…
Reference in New Issue
Block a user