2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Startup code for cc65 (Apple2 version)
|
|
|
|
;
|
|
|
|
; This must be the *first* file on the linker command line
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _exit
|
2000-11-22 22:19:09 +00:00
|
|
|
.import initlib, donelib
|
2004-03-11 21:54:22 +00:00
|
|
|
.import zerobss
|
2002-11-23 11:10:50 +00:00
|
|
|
.import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
|
2003-03-10 21:21:46 +00:00
|
|
|
.import callmain
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-05-26 09:09:10 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "apple2.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-07-05 21:11:16 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; The executable header
|
|
|
|
|
|
|
|
.segment "EXEHDR"
|
|
|
|
|
2002-11-23 11:10:50 +00:00
|
|
|
.word __STARTUP_LOAD__ ; Start address
|
|
|
|
.word __BSS_LOAD__ - __STARTUP_LOAD__ ; Size
|
2002-07-05 21:11:16 +00:00
|
|
|
|
2002-11-23 11:10:50 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Place the startup code in a special segment.
|
|
|
|
|
|
|
|
.segment "STARTUP"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-03-11 21:54:22 +00:00
|
|
|
; ProDOS TechRefMan, chapter 5.2.1:
|
|
|
|
; "For maximum interrupt efficiency, a system program should not use more
|
|
|
|
; than the upper 3/4 of the stack."
|
|
|
|
|
|
|
|
ldx #$FF
|
|
|
|
txs ; Init stack pointer
|
|
|
|
|
|
|
|
; Save the zero page locations we need
|
|
|
|
|
2000-10-30 21:46:45 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L1: lda sp,x
|
2004-03-11 21:54:22 +00:00
|
|
|
sta zpsave,x
|
2000-10-30 21:46:45 +00:00
|
|
|
dex
|
2000-05-28 13:40:48 +00:00
|
|
|
bpl L1
|
|
|
|
|
|
|
|
; Clear the BSS data
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
|
|
|
; Save system stuff and setup the stack
|
|
|
|
|
2004-03-11 21:54:22 +00:00
|
|
|
lda HIMEM
|
2000-05-28 13:40:48 +00:00
|
|
|
sta sp
|
2004-03-11 21:54:22 +00:00
|
|
|
lda HIMEM+1
|
2003-03-10 21:21:46 +00:00
|
|
|
sta sp+1 ; Set argument stack ptr
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
; Call module constructors
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
jsr initlib
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-03-10 21:21:46 +00:00
|
|
|
; Push arguments and call main()
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-03-10 21:21:46 +00:00
|
|
|
jsr callmain
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
; Call module destructors. This is also the _exit entry.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
_exit: jsr donelib
|
2002-05-26 09:09:10 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Copy back the zero page stuff
|
|
|
|
|
2000-10-30 21:46:45 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L2: lda zpsave,x
|
|
|
|
sta sp,x
|
|
|
|
dex
|
2000-05-28 13:40:48 +00:00
|
|
|
bpl L2
|
|
|
|
|
2004-03-11 21:54:22 +00:00
|
|
|
; ProDOS TechRefMan, chapter 5.2.1:
|
|
|
|
; "System programs should set the stack pointer to $FF at the warm-start
|
|
|
|
; entry point."
|
|
|
|
|
|
|
|
ldx #$FF
|
|
|
|
txs ; Re-init stack pointer
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-03-11 21:54:22 +00:00
|
|
|
; Back to DOS
|
|
|
|
|
|
|
|
jmp DOSWARM
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-11-23 11:10:50 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
zpsave: .res zpspace
|