2000-05-28 13:40:48 +00:00
|
|
|
;
|
2009-09-22 17:30:50 +00:00
|
|
|
; Oliver Schmidt, 15.09.2009
|
|
|
|
;
|
2000-05-28 13:40:48 +00:00
|
|
|
; Startup code for cc65 (Apple2 version)
|
|
|
|
;
|
|
|
|
|
2009-09-14 19:58:06 +00:00
|
|
|
.export _exit, done, return
|
2009-07-31 12:05:42 +00:00
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2005-04-27 18:01:57 +00:00
|
|
|
.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
|
2008-07-15 18:34:20 +00:00
|
|
|
.import __ZPSAVE_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
|
2008-07-15 18:34:20 +00:00
|
|
|
.word __ZPSAVE_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
|
2009-07-31 12:05:42 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Set source start address
|
2008-07-15 18:34:20 +00:00
|
|
|
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
2008-03-16 09:37:22 +00:00
|
|
|
sta $9B
|
|
|
|
sty $9C
|
2009-07-31 12:05:42 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Set source last address
|
2008-07-15 18:34:20 +00:00
|
|
|
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
|
|
|
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
2008-03-16 09:37:22 +00:00
|
|
|
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
|
2008-07-15 18:34:20 +00:00
|
|
|
lda #<__ZPSAVE_RUN__
|
|
|
|
ldy #>__ZPSAVE_RUN__
|
2008-03-16 09:37:22 +00:00
|
|
|
sta $9B
|
|
|
|
sty $9C
|
2009-07-31 12:05:42 +00:00
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Set source last address
|
2008-07-15 18:34:20 +00:00
|
|
|
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
2008-03-16 09:37:22 +00:00
|
|
|
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
|
2009-07-31 12:05:42 +00:00
|
|
|
|
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
|
2009-09-11 16:27:20 +00:00
|
|
|
lda int_num
|
2005-09-08 21:03:46 +00:00
|
|
|
beq exit
|
2005-04-21 01:41:50 +00:00
|
|
|
|
|
|
|
; Deallocate interrupt vector table entry
|
2009-09-11 16:27:20 +00:00
|
|
|
dec i_param ; 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
|
2009-09-11 16:27:20 +00:00
|
|
|
.addr i_param
|
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
|
|
|
|
2009-09-11 16:27:20 +00:00
|
|
|
; We're done
|
|
|
|
jmp (done)
|
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
|
2009-07-31 12:05:42 +00:00
|
|
|
|
2009-09-11 16:27:20 +00:00
|
|
|
; Check for ProDOS
|
|
|
|
ldy $BF00 ; MLI call entry point
|
|
|
|
cpy #$4C ; Is MLI present? (JMP opcode)
|
|
|
|
bne basic
|
|
|
|
|
|
|
|
; Check ProDOS system bit map
|
2011-01-26 21:37:42 +00:00
|
|
|
lda $BF6F ; Protection for pages $B8 - $BF
|
|
|
|
cmp #%00000001 ; Exactly system global page is protected
|
2009-09-11 16:27:20 +00:00
|
|
|
bne basic
|
|
|
|
|
|
|
|
; No BASIC.SYSTEM so quit to ProDOS dispatcher instead
|
|
|
|
lda #<quit
|
|
|
|
ldx #>quit
|
|
|
|
sta done
|
|
|
|
stx done+1
|
|
|
|
|
|
|
|
; No BASIC.SYSTEM so use addr of ProDOS system global page
|
|
|
|
lda #<$BF00
|
|
|
|
ldx #>$BF00
|
|
|
|
bne :+ ; Branch always
|
|
|
|
|
|
|
|
; Get highest available mem addr from BASIC interpreter
|
|
|
|
basic: lda HIMEM
|
|
|
|
ldx HIMEM+1
|
|
|
|
|
|
|
|
; Setup the C stack
|
|
|
|
: sta sp
|
|
|
|
stx sp+1
|
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
|
2009-09-11 16:27:20 +00:00
|
|
|
cpy #$4C ; Is MLI present? (JMP opcode)
|
2005-04-27 18:01:57 +00:00
|
|
|
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
|
2009-09-11 16:27:20 +00:00
|
|
|
.addr i_param
|
2005-04-27 18:01:57 +00:00
|
|
|
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."
|
2009-09-11 16:27:20 +00:00
|
|
|
intptr: 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
|
2009-09-14 19:58:06 +00:00
|
|
|
return: rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2009-09-11 16:27:20 +00:00
|
|
|
; Quit to ProDOS dispatcher
|
|
|
|
quit: jsr $BF00 ; MLI call entry point
|
|
|
|
.byte $65 ; Quit
|
|
|
|
.word q_param
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.rodata
|
|
|
|
|
|
|
|
; MLI parameter list for quit
|
|
|
|
q_param:.byte $04 ; param_count
|
|
|
|
.byte $00 ; quit_type
|
|
|
|
.word $0000 ; reserved
|
|
|
|
.byte $00 ; reserved
|
|
|
|
.word $0000 ; reserved
|
|
|
|
|
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
|
|
|
|
2009-09-11 16:27:20 +00:00
|
|
|
; MLI parameter list for (de)alloc interrupt
|
|
|
|
i_param:.byte $02 ; param_count
|
|
|
|
int_num:.byte $00 ; int_num
|
|
|
|
.addr intptr ; int_code
|
|
|
|
|
|
|
|
; Location to jump to when we're done
|
|
|
|
done: .addr DOSWARM
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2008-07-15 18:34:20 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.segment "ZPSAVE"
|
|
|
|
|
|
|
|
zpsave: .res zpspace
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
rvsave: .res 3
|