2000-05-28 13:40:48 +00:00
|
|
|
;
|
2012-06-10 21:05:51 +00:00
|
|
|
; Oliver Schmidt, 2009-09-15
|
2009-09-22 17:30:50 +00:00
|
|
|
;
|
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
|
2013-02-12 22:39:38 +00:00
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2005-04-27 18:01:57 +00:00
|
|
|
.import zerobss
|
2013-02-12 22:39:38 +00:00
|
|
|
.import initlib, donelib
|
|
|
|
.import callmain
|
|
|
|
.import __LC_START__, __LC_LAST__ ; Linker generated
|
|
|
|
.import __INIT_RUN__, __INIT_SIZE__ ; Linker generated
|
|
|
|
.import __ZPSAVE_RUN__ ; 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
|
|
|
|
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
|
2013-02-12 22:39:38 +00:00
|
|
|
txs ; Init stack pointer
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Switch in LC bank 2 for W/O.
|
2013-02-12 22:39:38 +00:00
|
|
|
bit $C081
|
|
|
|
bit $C081
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the source start address.
|
2013-02-12 22:39:38 +00:00
|
|
|
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
|
|
|
sta $9B
|
|
|
|
sty $9C
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the source last address.
|
2013-02-12 22:39:38 +00:00
|
|
|
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
|
|
|
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__)
|
|
|
|
sta $96
|
|
|
|
sty $97
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the destination last address.
|
2013-02-12 22:39:38 +00:00
|
|
|
lda #<__LC_LAST__
|
|
|
|
ldy #>__LC_LAST__
|
|
|
|
sta $94
|
|
|
|
sty $95
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call into the Applesoft Block Transfer Utility -- which handles zero-
|
|
|
|
; sized blocks well -- to move the content of the LC memory area.
|
2013-02-12 22:39:38 +00:00
|
|
|
jsr $D396 ; BLTU + 3
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the source start address.
|
2013-02-12 22:39:38 +00:00
|
|
|
lda #<__ZPSAVE_RUN__
|
|
|
|
ldy #>__ZPSAVE_RUN__
|
|
|
|
sta $9B
|
|
|
|
sty $9C
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the source last address.
|
2013-02-12 22:39:38 +00:00
|
|
|
lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__)
|
|
|
|
sta $96
|
|
|
|
sty $97
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the destination last address.
|
2013-02-12 22:39:38 +00:00
|
|
|
lda #<(__INIT_RUN__ + __INIT_SIZE__)
|
|
|
|
ldy #>(__INIT_RUN__ + __INIT_SIZE__)
|
|
|
|
sta $94
|
|
|
|
sty $95
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call into the Applesoft Block Transfer Utility -- which handles moving
|
|
|
|
; overlapping blocks upwards well -- to move the INIT segment.
|
2013-02-12 22:39:38 +00:00
|
|
|
jsr $D396 ; BLTU + 3
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Avoid a re-entrance of donelib. This is also the exit() entry.
|
2005-04-27 18:01:57 +00:00
|
|
|
_exit: ldx #<exit
|
|
|
|
lda #>exit
|
2013-02-12 22:39:38 +00:00
|
|
|
jsr reset ; Setup RESET vector
|
2009-07-31 12:05:42 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Switch in ROM, in case it wasn't already switched in by a RESET.
|
2013-02-12 22:39:38 +00:00
|
|
|
bit $C082
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the module destructors.
|
2005-09-08 21:03:46 +00:00
|
|
|
jsr donelib
|
|
|
|
|
2014-08-23 18:05:36 +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
|
|
|
|
2014-08-23 18:05:36 +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
|
2014-01-26 17:10:01 +00:00
|
|
|
jmp done
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-27 18:01:57 +00:00
|
|
|
.segment "INIT"
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Save the zero-page locations that 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Clear the BSS data.
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr zerobss
|
|
|
|
|
2014-08-23 18:05:36 +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
|
2013-02-12 22:39:38 +00:00
|
|
|
jsr reset ; Setup RESET vector
|
2009-07-31 12:05:42 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Check for ProDOS.
|
2013-02-12 22:39:38 +00:00
|
|
|
ldy $BF00 ; MLI call entry point
|
|
|
|
cpy #$4C ; Is MLI present? (JMP opcode)
|
2009-09-11 16:27:20 +00:00
|
|
|
bne basic
|
2014-08-23 18:05:36 +00:00
|
|
|
|
|
|
|
; Check the 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
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; No BASIC.SYSTEM; so, quit to the ProDOS dispatcher instead.
|
2009-09-11 16:27:20 +00:00
|
|
|
lda #<quit
|
|
|
|
ldx #>quit
|
2014-01-26 17:10:01 +00:00
|
|
|
sta done+1
|
|
|
|
stx done+2
|
2014-08-23 18:05:36 +00:00
|
|
|
|
|
|
|
; No BASIC.SYSTEM; so, use the addr of the ProDOS system global page.
|
2009-09-11 16:27:20 +00:00
|
|
|
lda #<$BF00
|
|
|
|
ldx #>$BF00
|
|
|
|
bne :+ ; Branch always
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Get the highest available mem addr from the BASIC interpreter.
|
2009-09-11 16:27:20 +00:00
|
|
|
basic: lda HIMEM
|
|
|
|
ldx HIMEM+1
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set up the C stack.
|
2009-09-11 16:27:20 +00:00
|
|
|
: sta sp
|
|
|
|
stx sp+1
|
2005-04-21 01:41:50 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Enable interrupts, as old ProDOS versions (i.e. 1.1.1)
|
|
|
|
; jump to SYS and BIN programs with interrupts disabled.
|
2013-02-12 22:39:38 +00:00
|
|
|
cli
|
2005-09-08 21:03:46 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the module constructors.
|
2013-02-12 22:39:38 +00:00
|
|
|
jsr initlib
|
2005-09-08 21:03:46 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Switch in LC bank 2 for R/O.
|
2013-02-12 22:39:38 +00:00
|
|
|
bit $C080
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Push the command-line arguments; and, call main().
|
2005-09-08 21:03:46 +00:00
|
|
|
jmp callmain
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
.code
|
2005-04-27 18:01:57 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set up the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Quit to the ProDOS dispatcher.
|
2009-09-11 16:27:20 +00:00
|
|
|
quit: jsr $BF00 ; MLI call entry point
|
|
|
|
.byte $65 ; Quit
|
|
|
|
.word q_param
|
|
|
|
|
|
|
|
.rodata
|
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
; 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
|
|
|
|
2014-01-26 17:10:01 +00:00
|
|
|
; Final jump when we're done
|
|
|
|
done: jmp DOSWARM ; Potentially patched at runtime
|
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
|