2002-06-03 20:23:15 +00:00
|
|
|
|
;
|
|
|
|
|
; Startup code for cc65 (Oric version)
|
|
|
|
|
;
|
|
|
|
|
; By Debrune J<>r<EFBFBD>me <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org>
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; 2016-03-18, Greg King
|
2002-06-03 20:23:15 +00:00
|
|
|
|
;
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.export _exit
|
|
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2016-03-18 15:28:56 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.import initlib, donelib
|
|
|
|
|
.import callmain, zerobss
|
2016-03-18 15:28:56 +00:00
|
|
|
|
.import __MAIN_START__, __MAIN_SIZE__
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
.include "atmos.inc"
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2002-11-23 11:10:50 +00:00
|
|
|
|
; Place the startup code in a special segment.
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.segment "STARTUP"
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
tsx
|
|
|
|
|
stx spsave ; Save system stk ptr
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Save space by putting some of the start-up code in a segment
|
|
|
|
|
; that will be re-used.
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
jsr init
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Clear the BSS variables (after the constructors have been run).
|
|
|
|
|
|
|
|
|
|
jsr zerobss
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; Push the command-line arguments; and, call main().
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
jsr callmain
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; Call the module destructors. This is also the exit() entry.
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-11-09 11:32:11 +00:00
|
|
|
|
_exit: jsr donelib
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; Restore the system stuff.
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
ldx spsave
|
|
|
|
|
txs
|
|
|
|
|
lda stsave
|
|
|
|
|
sta STATUS
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2014-08-21 14:46:25 +00:00
|
|
|
|
; Copy back the zero-page stuff.
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
ldx #zpspace - 1
|
2013-05-09 11:56:54 +00:00
|
|
|
|
L2: lda zpsave,x
|
|
|
|
|
sta sp,x
|
|
|
|
|
dex
|
|
|
|
|
bpl L2
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-08-21 14:46:25 +00:00
|
|
|
|
; Back to BASIC.
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
rts
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Put this code in a place that will be re-used by BSS, the heap,
|
|
|
|
|
; and the C stack.
|
|
|
|
|
|
|
|
|
|
.segment "ONCE"
|
2011-06-07 21:22:02 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Save the zero-page area that we're about to use.
|
|
|
|
|
|
|
|
|
|
init: ldx #zpspace - 1
|
|
|
|
|
L1: lda sp,x
|
|
|
|
|
sta zpsave,x
|
|
|
|
|
dex
|
|
|
|
|
bpl L1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Currently, color isn't supported on the text screen.
|
|
|
|
|
; Unprotect screen columns 0 and 1 (where each line's color codes would sit).
|
2014-11-09 11:32:11 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
lda STATUS
|
|
|
|
|
sta stsave
|
|
|
|
|
and #%11011111
|
|
|
|
|
sta STATUS
|
2014-11-09 11:32:11 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Set up the C stack.
|
2014-11-09 11:32:11 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
lda #<(__MAIN_START__ + __MAIN_SIZE__)
|
|
|
|
|
ldx #>(__MAIN_START__ + __MAIN_SIZE__)
|
|
|
|
|
sta sp
|
|
|
|
|
stx sp+1 ; Set argument stack ptr
|
2015-01-08 22:07:28 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
; Call the module constructors.
|
2015-01-08 08:51:20 +00:00
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
jmp initlib
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
2016-03-18 15:28:56 +00:00
|
|
|
|
.segment "INIT"
|
2011-06-07 21:22:02 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
spsave: .res 1
|
|
|
|
|
stsave: .res 1
|
2016-03-18 15:28:56 +00:00
|
|
|
|
zpsave: .res zpspace
|