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
|
2008-03-16 09:37:22 +00:00
|
|
|
.import __RAM_START__ , __RAM_LAST__ ; Linker generated
|
|
|
|
.import __MOVE_START__, __MOVE_LAST__ ; Linker generated
|
|
|
|
.import __LC_START__ , __LC_LAST__ ; Linker generated
|
|
|
|
.import __BSS_RUN__ , __INIT_SIZE__ ; Linker generated
|
2005-04-27 18:01:57 +00:00
|
|
|
.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"
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
.linecont +
|
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
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.addr __RAM_START__ ; Start address
|
|
|
|
.word __BSS_RUN__ - __RAM_START__ + \
|
|
|
|
__MOVE_LAST__ - __MOVE_START__ ; 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
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Switch in LC bank 2 for W/O
|
|
|
|
bit $C081
|
|
|
|
bit $C081
|
|
|
|
|
|
|
|
; Set source start address
|
|
|
|
lda #<(__BSS_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__BSS_RUN__ + __INIT_SIZE__)
|
|
|
|
sta $9B
|
|
|
|
sty $9C
|
|
|
|
|
|
|
|
; Set source last address
|
|
|
|
lda #<(__BSS_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
|
|
|
ldy #>(__BSS_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
|
|
|
sta $96
|
|
|
|
sty $97
|
|
|
|
|
|
|
|
; Set destination last address
|
|
|
|
lda #<__LC_LAST__
|
|
|
|
ldy #>__LC_LAST__
|
|
|
|
sta $94
|
|
|
|
sty $95
|
|
|
|
|
|
|
|
; Call into Applesoft Block Transfer Utility - which handles zero
|
|
|
|
; sized blocks well - to move content of the LC memory area
|
|
|
|
jsr $D396 ; BLTU + 3
|
|
|
|
|
|
|
|
; Set source start address
|
|
|
|
lda #<__BSS_RUN__
|
|
|
|
ldy #>__BSS_RUN__
|
|
|
|
sta $9B
|
|
|
|
sty $9C
|
|
|
|
|
|
|
|
; Set source last address
|
|
|
|
lda #<(__BSS_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__BSS_RUN__ + __INIT_SIZE__)
|
|
|
|
sta $96
|
|
|
|
sty $97
|
|
|
|
|
|
|
|
; Set destination last address
|
|
|
|
lda #<__RAM_LAST__
|
|
|
|
ldy #>__RAM_LAST__
|
|
|
|
sta $94
|
|
|
|
sty $95
|
|
|
|
|
|
|
|
; Call into Applesoft Block Transfer Utility - which handles moving
|
|
|
|
; overlapping blocks upwards well - to move the INIT segment
|
|
|
|
jsr $D396 ; BLTU + 3
|
|
|
|
|
|
|
|
; Delegate all further processing to keep the STARTUP segment 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
|
2008-03-16 09:37:22 +00:00
|
|
|
|
|
|
|
; Switch in ROM in case it wasn't already switched in by a RESET
|
|
|
|
bit $C082
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2005-09-08 21:03:46 +00:00
|
|
|
; Call module destructors
|
|
|
|
jsr donelib
|
|
|
|
|
2005-04-24 22:13:15 +00:00
|
|
|
; Check for valid interrupt vector table entry number
|
|
|
|
lda intnum
|
2005-09-08 21:03:46 +00:00
|
|
|
beq exit
|
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
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr $BF00 ; MLI call entry point
|
2005-04-27 18:01:57 +00:00
|
|
|
.byte $41 ; Dealloc interrupt
|
|
|
|
.addr params
|
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
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Clear the BSS data
|
|
|
|
jsr zerobss
|
|
|
|
|
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
|
|
|
; 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
|
|
|
|
|
|
|
; 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
|
2008-03-16 09:37:22 +00:00
|
|
|
lda $BF00 ; MLI call entry point
|
2005-04-27 18:01:57 +00:00
|
|
|
cmp #$4C ; Is MLI present? (JMP opcode)
|
|
|
|
bne prterr
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Allocate interrupt vector table entry
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr $BF00 ; MLI call entry point
|
2005-04-27 18:01:57 +00:00
|
|
|
.byte $40 ; Alloc interrupt
|
|
|
|
.addr params
|
|
|
|
bcs prterr
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2005-09-08 21:03:46 +00:00
|
|
|
; Enable interrupts as old ProDOS versions (i.e. 1.1.1)
|
|
|
|
; jump to SYS and BIN programs with interrupts disabled
|
|
|
|
cli
|
|
|
|
|
|
|
|
; Call module constructors
|
|
|
|
: jsr initlib
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Switch in LC bank 2 for R/O
|
|
|
|
bit $C080
|
|
|
|
|
2005-04-21 01:41:50 +00:00
|
|
|
; Push arguments and call main()
|
2005-09-08 21:03:46 +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
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr $FDED ; 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
|
|
|
; 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
|
|
|
params: .byte $02 ; Parameter count
|
|
|
|
intnum: .byte $00 ; Interrupt number
|
2008-03-16 09:37:22 +00:00
|
|
|
.addr intrpt ; Interrupt handler
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
rvsave: .res 3
|