mirror of
https://github.com/cc65/cc65.git
synced 2024-10-04 18:57:06 +00:00
Added an exit handler - code from Oliver Schmidt
git-svn-id: svn://svn.cc65.org/cc65/trunk@3341 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
e55a4bcfd4
commit
10431b1067
@ -14,6 +14,8 @@ HIMEM := $73 ; Highest available memory address+1
|
|||||||
;-----------------------------------------------------------------------------
|
;-----------------------------------------------------------------------------
|
||||||
; Vectors
|
; Vectors
|
||||||
|
|
||||||
|
SOFTEV := $03F2 ; Vector for warm start
|
||||||
|
PWREDUP := $03F4 ; This must be = EOR #$A5 of SOFTEV+1
|
||||||
DOSWARM := $03D0 ; DOS warmstart vector
|
DOSWARM := $03D0 ; DOS warmstart vector
|
||||||
BRKVec := $03F0 ; Break vector
|
BRKVec := $03F0 ; Break vector
|
||||||
MLI := $BF00 ; ProDOS Machine Language Interface
|
MLI := $BF00 ; ProDOS Machine Language Interface
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
; This must be the *first* file on the linker command line
|
; This must be the *first* file on the linker command line
|
||||||
;
|
;
|
||||||
|
|
||||||
.export _exit
|
.export _exit, __Exit
|
||||||
.import initlib, donelib
|
.import initlib, donelib
|
||||||
.import zerobss
|
.import zerobss
|
||||||
.import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
|
.import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
|
||||||
@ -36,16 +36,32 @@
|
|||||||
; Save the zero page locations we need
|
; Save the zero page locations we need
|
||||||
|
|
||||||
ldx #zpspace-1
|
ldx #zpspace-1
|
||||||
L1: lda sp,x
|
: lda sp,x
|
||||||
sta zpsave,x
|
sta zpsave,x
|
||||||
dex
|
dex
|
||||||
bpl L1
|
bpl :-
|
||||||
|
|
||||||
|
; Save the original RESET vector
|
||||||
|
|
||||||
|
ldx #$02
|
||||||
|
: lda SOFTEV,x
|
||||||
|
sta rvsave,x
|
||||||
|
dex
|
||||||
|
bpl :-
|
||||||
|
|
||||||
|
; ProDOS TechRefMan, chapter 5.3.5:
|
||||||
|
; "Your system program should place in the RESET vector the address of a
|
||||||
|
; routine that ... closes the files."
|
||||||
|
|
||||||
|
ldx #<_exit
|
||||||
|
lda #>_exit
|
||||||
|
jsr reset ; Setup RESET vector
|
||||||
|
|
||||||
; Clear the BSS data
|
; Clear the BSS data
|
||||||
|
|
||||||
jsr zerobss
|
jsr zerobss
|
||||||
|
|
||||||
; Save system stuff and setup the stack
|
; Setup the stack
|
||||||
|
|
||||||
lda HIMEM
|
lda HIMEM
|
||||||
sta sp
|
sta sp
|
||||||
@ -60,17 +76,31 @@ L1: lda sp,x
|
|||||||
|
|
||||||
jsr callmain
|
jsr callmain
|
||||||
|
|
||||||
; Call module destructors. This is also the _exit entry.
|
; Avoid re-entrance of donelib. This is also the _exit entry
|
||||||
|
|
||||||
_exit: jsr donelib
|
_exit: ldx #<__Exit
|
||||||
|
lda #>__Exit
|
||||||
|
jsr reset ; Setup RESET vector
|
||||||
|
|
||||||
|
; Call module destructors
|
||||||
|
|
||||||
|
jsr donelib
|
||||||
|
|
||||||
|
; Restore the original RESET vector. This is also the __Exit entry
|
||||||
|
|
||||||
|
__Exit: ldx #$02
|
||||||
|
: lda rvsave,x
|
||||||
|
sta SOFTEV,x
|
||||||
|
dex
|
||||||
|
bpl :-
|
||||||
|
|
||||||
; Copy back the zero page stuff
|
; Copy back the zero page stuff
|
||||||
|
|
||||||
ldx #zpspace-1
|
ldx #zpspace-1
|
||||||
L2: lda zpsave,x
|
: lda zpsave,x
|
||||||
sta sp,x
|
sta sp,x
|
||||||
dex
|
dex
|
||||||
bpl L2
|
bpl :-
|
||||||
|
|
||||||
; ProDOS TechRefMan, chapter 5.2.1:
|
; ProDOS TechRefMan, chapter 5.2.1:
|
||||||
; "System programs should set the stack pointer to $FF at the warm-start
|
; "System programs should set the stack pointer to $FF at the warm-start
|
||||||
@ -83,9 +113,20 @@ L2: lda zpsave,x
|
|||||||
|
|
||||||
jmp DOSWARM
|
jmp DOSWARM
|
||||||
|
|
||||||
|
; ------------------------------------------------------------------------
|
||||||
|
; Setup RESET vector
|
||||||
|
|
||||||
|
reset: stx SOFTEV
|
||||||
|
sta SOFTEV+1
|
||||||
|
eor #$A5
|
||||||
|
sta PWREDUP
|
||||||
|
rts
|
||||||
|
|
||||||
; ------------------------------------------------------------------------
|
; ------------------------------------------------------------------------
|
||||||
; Data
|
; Data
|
||||||
|
|
||||||
.data
|
.data
|
||||||
|
|
||||||
zpsave: .res zpspace
|
zpsave: .res zpspace
|
||||||
|
|
||||||
|
rvsave: .res 3
|
||||||
|
Loading…
Reference in New Issue
Block a user