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
|
|
|
|
.import zerobss, push0
|
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
|
|
|
|
2000-10-30 21:46:45 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L1: lda sp,x
|
2003-03-10 21:21:46 +00:00
|
|
|
sta zpsave,x ; Save the zero page locations we need
|
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
|
|
|
|
|
|
|
|
tsx
|
2003-03-10 21:21:46 +00:00
|
|
|
stx spsave ; Save the system stack ptr
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-07-15 20:03:37 +00:00
|
|
|
lda MEMSIZE
|
2000-05-28 13:40:48 +00:00
|
|
|
sta sp
|
2002-07-15 20:03:37 +00:00
|
|
|
lda MEMSIZE+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
|
|
|
|
|
|
|
; Initialize conio stuff
|
|
|
|
|
|
|
|
lda #$ff
|
|
|
|
sta TEXTTYP
|
|
|
|
|
|
|
|
; Set up to use Apple ROM $C000-$CFFF
|
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
;; sta USEROM
|
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-11-22 22:19:09 +00:00
|
|
|
; Restore system stuff
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-03-10 21:21:46 +00:00
|
|
|
lda #$ff ; Reset text mode
|
2000-11-22 22:19:09 +00:00
|
|
|
sta TEXTTYP
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
ldx spsave
|
|
|
|
txs ; Restore stack pointer
|
|
|
|
|
|
|
|
; 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
|
|
|
|
|
|
|
|
; Reset changed vectors, back to basic
|
|
|
|
|
|
|
|
jmp RESTOR
|
|
|
|
|
2002-11-23 11:10:50 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
zpsave: .res zpspace
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
spsave: .res 1
|