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
|
|
|
|
;
|
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.export _exit
|
|
|
|
.import zerobss
|
|
|
|
.import initlib, donelib
|
|
|
|
.import callmain, callirq
|
|
|
|
.import COUT
|
|
|
|
.import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated
|
|
|
|
.import __INTERRUPTOR_COUNT__ ; Linker generated
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-05-26 09:09:10 +00:00
|
|
|
.include "zeropage.inc"
|
2005-04-27 18:01:57 +00:00
|
|
|
.include "apple2.inc"
|
|
|
|
.include "mli.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-07-05 21:11:16 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.segment "EXEHDR"
|
2002-07-05 21:11:16 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.addr __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
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.segment "STARTUP"
|
2005-04-21 01:41:50 +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."
|
2005-04-27 18:01:57 +00:00
|
|
|
ldx #$FF
|
|
|
|
txs ; Init stack pointer
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Delegate all further processing to keep STARTUP small
|
2005-04-27 18:01:57 +00:00
|
|
|
jsr init
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Avoid re-entrance of donelib. This is also the _exit entry
|
2005-04-27 18:01:57 +00:00
|
|
|
_exit: ldx #<exit
|
|
|
|
lda #>exit
|
|
|
|
jsr reset ; Setup RESET vector
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2005-04-24 22:13:15 +00:00
|
|
|
; Check for valid interrupt vector table entry number
|
|
|
|
lda intnum
|
2005-04-27 18:01:57 +00:00
|
|
|
beq :+
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Deallocate interrupt vector table entry
|
2005-04-27 18:01:57 +00:00
|
|
|
dec params ; Adjust parameter count
|
|
|
|
jsr ENTRY
|
|
|
|
.byte $41 ; Dealloc interrupt
|
|
|
|
.addr params
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Call module destructors
|
2005-04-27 18:01:57 +00:00
|
|
|
: jsr donelib
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2005-04-24 22:13:15 +00:00
|
|
|
; Restore the original RESET vector
|
2005-04-27 18:01:57 +00:00
|
|
|
exit: ldx #$02
|
|
|
|
: lda rvsave,x
|
|
|
|
sta SOFTEV,x
|
2005-04-21 01:41:50 +00:00
|
|
|
dex
|
2005-04-27 18:01:57 +00:00
|
|
|
bpl :-
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Copy back the zero page stuff
|
2005-04-27 18:01:57 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
: lda zpsave,x
|
|
|
|
sta sp,x
|
2005-04-21 01:41:50 +00:00
|
|
|
dex
|
2005-04-27 18:01:57 +00:00
|
|
|
bpl :-
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; ProDOS TechRefMan, chapter 5.2.1:
|
|
|
|
; "System programs should set the stack pointer to $FF at the
|
|
|
|
; warm-start entry point."
|
2005-04-27 18:01:57 +00:00
|
|
|
ldx #$FF
|
|
|
|
txs ; Re-init stack pointer
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Back to DOS
|
2005-04-27 18:01:57 +00:00
|
|
|
jmp DOSWARM
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2004-12-21 15:56:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.segment "INIT"
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Save the zero page locations we need
|
2005-04-27 18:01:57 +00:00
|
|
|
init: ldx #zpspace-1
|
|
|
|
: lda sp,x
|
|
|
|
sta zpsave,x
|
2005-04-21 01:41:50 +00:00
|
|
|
dex
|
2005-04-27 18:01:57 +00:00
|
|
|
bpl :-
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Save the original RESET vector
|
2005-04-27 18:01:57 +00:00
|
|
|
ldx #$02
|
|
|
|
: lda SOFTEV,x
|
|
|
|
sta rvsave,x
|
2005-04-21 01:41:50 +00:00
|
|
|
dex
|
2005-04-27 18:01:57 +00:00
|
|
|
bpl :-
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; ProDOS TechRefMan, chapter 5.3.5:
|
|
|
|
; "Your system program should place in the RESET vector the
|
|
|
|
; address of a routine that ... closes the files."
|
2005-04-27 18:01:57 +00:00
|
|
|
ldx #<_exit
|
|
|
|
lda #>_exit
|
|
|
|
jsr reset ; Setup RESET vector
|
2005-04-24 22:13:15 +00:00
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; Clear the BSS data
|
2005-04-27 18:01:57 +00:00
|
|
|
jsr zerobss
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Setup the stack
|
2005-04-27 18:01:57 +00:00
|
|
|
lda HIMEM
|
|
|
|
sta sp
|
|
|
|
lda HIMEM+1
|
|
|
|
sta sp+1 ; Set argument stack ptr
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Call module constructors
|
2005-04-27 18:01:57 +00:00
|
|
|
jsr initlib
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Check for interruptors
|
|
|
|
lda #<__INTERRUPTOR_COUNT__
|
2005-04-27 18:01:57 +00:00
|
|
|
beq :+
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Check for ProDOS
|
2005-04-27 18:01:57 +00:00
|
|
|
lda ENTRY
|
|
|
|
cmp #$4C ; Is MLI present? (JMP opcode)
|
|
|
|
bne prterr
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Allocate interrupt vector table entry
|
2005-04-27 18:01:57 +00:00
|
|
|
jsr ENTRY
|
|
|
|
.byte $40 ; Alloc interrupt
|
|
|
|
.addr params
|
|
|
|
bcs prterr
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Push arguments and call main()
|
2005-04-27 18:01:57 +00:00
|
|
|
: jmp callmain
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-24 22:13:15 +00:00
|
|
|
; Print error message and return
|
2005-04-27 18:01:57 +00:00
|
|
|
prterr: ldx #msglen-1
|
|
|
|
: lda errmsg,x
|
|
|
|
jsr COUT
|
2005-04-24 22:13:15 +00:00
|
|
|
dex
|
2005-04-27 18:01:57 +00:00
|
|
|
bpl :-
|
2005-04-24 22:13:15 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
errmsg: .ifdef __APPLE2ENH__
|
2005-04-27 18:01:57 +00:00
|
|
|
.byte $8D, 't'|$80, 'p'|$80, 'u'|$80, 'r'|$80, 'r'|$80
|
|
|
|
.byte 'e'|$80, 't'|$80, 'n'|$80, 'i'|$80, ' '|$80, 'c'|$80
|
|
|
|
.byte 'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80
|
|
|
|
.byte 't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80
|
|
|
|
.byte 'a'|$80, 'F'|$80, $8D
|
2005-04-24 22:13:15 +00:00
|
|
|
.else
|
2005-04-27 18:01:57 +00:00
|
|
|
.byte $8D, 'T'|$80, 'P'|$80, 'U'|$80, 'R'|$80, 'R'|$80
|
|
|
|
.byte 'E'|$80, 'T'|$80, 'N'|$80, 'I'|$80, ' '|$80, 'C'|$80
|
|
|
|
.byte 'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80
|
|
|
|
.byte 'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80
|
|
|
|
.byte 'A'|$80, 'F'|$80, $8D
|
2005-04-24 22:13:15 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
msglen = * - errmsg
|
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2004-12-21 15:56:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.segment "LOWCODE"
|
2002-05-26 09:09:10 +00:00
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; ProDOS TechRefMan, chapter 6.2:
|
2005-04-27 18:01:57 +00:00
|
|
|
; "Each installed routine must begin with a CLD instruction."
|
2005-04-21 01:41:50 +00:00
|
|
|
intrpt: cld
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
; Call interruptors and check for success
|
|
|
|
jsr callirq
|
|
|
|
bcc :+
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; ProDOS TechRefMan, chapter 6.2:
|
|
|
|
; "When the routine that can process the interrupt is called, it
|
|
|
|
; should ... return (via an RTS) with the carry flag clear."
|
|
|
|
clc
|
|
|
|
rts
|
2004-03-11 21:54:22 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
; ProDOS TechRefMan, chapter 6.2:
|
|
|
|
; "When a routine that cannot process the interrupt is called,
|
|
|
|
; it should return (via an RTS) with the cary flag set ..."
|
|
|
|
: sec
|
|
|
|
rts
|
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
.code
|
2004-03-11 21:54:22 +00:00
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; Setup RESET vector
|
2005-04-27 18:01:57 +00:00
|
|
|
reset: stx SOFTEV
|
|
|
|
sta SOFTEV+1
|
|
|
|
eor #$A5
|
|
|
|
sta PWREDUP
|
2005-04-21 01:41:50 +00:00
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2004-12-21 15:56:48 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
.data
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
zpsave: .res zpspace
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
rvsave: .res 3
|
2004-12-21 15:56:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
params: .byte $02 ; Parameter count
|
|
|
|
intnum: .byte $00 ; Interrupt number
|
|
|
|
.addr intrpt ; Interrupt handler
|