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
|
2016-03-17 20:07:19 +00:00
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
.import initlib, donelib
|
2016-03-17 20:07:19 +00:00
|
|
|
.import zerobss, callmain
|
|
|
|
.import __ONCE_LOAD__, __ONCE_SIZE__ ; Linker generated
|
2013-02-12 22:39:38 +00:00
|
|
|
.import __LC_START__, __LC_LAST__ ; 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
|
|
|
|
2016-03-17 20:07:19 +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
|
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; Save space by putting some of the start-up code in the ONCE segment,
|
|
|
|
; which can be re-used by the BSS segment, the heap and the C stack.
|
|
|
|
jsr init
|
2013-02-12 22:39:38 +00:00
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; Clear the BSS data.
|
|
|
|
jsr zerobss
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; Push the command-line arguments; and, call main().
|
|
|
|
jsr callmain
|
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
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "ONCE"
|
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
|
|
|
; 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
|
|
|
|
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
|
|
|
|
2016-03-17 20:07:19 +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."
|
|
|
|
ldx #<_exit
|
|
|
|
lda #>_exit
|
|
|
|
jsr reset ; Setup RESET vector
|
|
|
|
|
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
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; Switch in LC bank 2 for W/O.
|
|
|
|
bit $C081
|
|
|
|
bit $C081
|
|
|
|
|
|
|
|
; Set the source start address.
|
|
|
|
; Aka __LC_LOAD__ iff segment LC exists.
|
|
|
|
lda #<(__ONCE_LOAD__ + __ONCE_SIZE__)
|
|
|
|
ldy #>(__ONCE_LOAD__ + __ONCE_SIZE__)
|
|
|
|
sta $9B
|
|
|
|
sty $9C
|
|
|
|
|
|
|
|
; Set the source last address.
|
|
|
|
; Aka __LC_LOAD__ + __LC_SIZE__ iff segment LC exists.
|
|
|
|
lda #<((__ONCE_LOAD__ + __ONCE_SIZE__) + (__LC_LAST__ - __LC_START__))
|
|
|
|
ldy #>((__ONCE_LOAD__ + __ONCE_SIZE__) + (__LC_LAST__ - __LC_START__))
|
|
|
|
sta $96
|
|
|
|
sty $97
|
|
|
|
|
|
|
|
; Set the destination last address.
|
|
|
|
; Aka __LC_RUN__ + __LC_SIZE__ iff segment LC exists.
|
|
|
|
lda #<__LC_LAST__
|
|
|
|
ldy #>__LC_LAST__
|
|
|
|
sta $94
|
|
|
|
sty $95
|
|
|
|
|
|
|
|
; Call into Applesoft Block Transfer Up -- which handles zero-
|
|
|
|
; sized blocks well -- to move the content of the LC memory area.
|
|
|
|
jsr $D39A ; BLTU2
|
|
|
|
|
|
|
|
; Switch in LC bank 2 for R/O and return.
|
2013-02-12 22:39:38 +00:00
|
|
|
bit $C080
|
2016-03-17 20:07:19 +00:00
|
|
|
rts
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; ------------------------------------------------------------------------
|
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
|
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2009-09-11 16:27:20 +00:00
|
|
|
.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
|
|
|
|
2016-03-17 20:07:19 +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
|
|
|
|
2016-03-17 20:07:19 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "INIT"
|
2008-07-15 18:34:20 +00:00
|
|
|
|
|
|
|
zpsave: .res zpspace
|
2008-03-16 09:37:22 +00:00
|
|
|
rvsave: .res 3
|