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>
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
.export _exit
|
2009-07-31 12:05:42 +00:00
|
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2002-06-03 20:23:15 +00:00
|
|
|
|
.import initlib, donelib
|
2003-04-13 22:12:09 +00:00
|
|
|
|
.import callmain, zerobss
|
2010-10-02 10:37:20 +00:00
|
|
|
|
.import __RAM_START__, __RAM_SIZE__
|
|
|
|
|
.import __BSS_LOAD__, __STACKSIZE__
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
.include "atmos.inc"
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
2003-04-13 22:12:09 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
; Oric tape header
|
|
|
|
|
|
|
|
|
|
.segment "TAPEHDR"
|
|
|
|
|
|
|
|
|
|
.byte $16, $16, $16 ; Sync bytes
|
|
|
|
|
.byte $24 ; End of header marker
|
|
|
|
|
|
|
|
|
|
.byte $00 ; $2B0
|
|
|
|
|
.byte $00 ; $2AF
|
|
|
|
|
.byte $80 ; $2AE Machine code flag
|
|
|
|
|
.byte $C7 ; $2AD Autoload flag
|
2008-07-03 19:39:14 +00:00
|
|
|
|
.dbyt __BSS_LOAD__ ; $2AB
|
2003-04-13 22:12:09 +00:00
|
|
|
|
.dbyt __RAM_START__ ; $2A9
|
|
|
|
|
.byte $00 ; $2A8
|
|
|
|
|
.byte $00 ; Zero terminated name
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
2002-11-23 11:10:50 +00:00
|
|
|
|
; Place the startup code in a special segment.
|
|
|
|
|
|
|
|
|
|
.segment "STARTUP"
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2003-04-13 22:12:09 +00:00
|
|
|
|
; Save the zero page area we're about to use
|
|
|
|
|
|
|
|
|
|
ldx #zpspace-1
|
|
|
|
|
L1: lda sp,x
|
|
|
|
|
sta zpsave,x ; Save the zero page locations we need
|
|
|
|
|
dex
|
|
|
|
|
bpl L1
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
; Clear the BSS data
|
|
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
|
2003-04-13 22:12:09 +00:00
|
|
|
|
; Unprotect columns 0 and 1
|
|
|
|
|
|
|
|
|
|
lda STATUS
|
|
|
|
|
sta stsave
|
|
|
|
|
and #%11011111
|
|
|
|
|
sta STATUS
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
; Save system stuff and setup the stack
|
|
|
|
|
|
|
|
|
|
tsx
|
|
|
|
|
stx spsave ; save system stk ptr
|
|
|
|
|
|
2010-10-02 10:37:20 +00:00
|
|
|
|
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
2002-06-03 20:23:15 +00:00
|
|
|
|
sta sp
|
2010-10-02 10:37:20 +00:00
|
|
|
|
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
2002-06-03 20:23:15 +00:00
|
|
|
|
sta sp+1 ; Set argument stack ptr
|
|
|
|
|
|
|
|
|
|
; Call module constructors
|
|
|
|
|
|
|
|
|
|
jsr initlib
|
|
|
|
|
|
2003-03-10 21:21:46 +00:00
|
|
|
|
; Push arguments and call main()
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2003-03-10 21:21:46 +00:00
|
|
|
|
jsr callmain
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
|
|
|
|
; Call module destructors. This is also the _exit entry.
|
|
|
|
|
|
|
|
|
|
_exit: jsr donelib ; Run module destructors
|
|
|
|
|
|
|
|
|
|
; Restore system stuff
|
|
|
|
|
|
|
|
|
|
ldx spsave
|
|
|
|
|
txs
|
2003-04-13 22:12:09 +00:00
|
|
|
|
lda stsave
|
|
|
|
|
sta STATUS
|
|
|
|
|
|
|
|
|
|
; Copy back the zero page stuff
|
|
|
|
|
|
|
|
|
|
ldx #zpspace-1
|
|
|
|
|
L2: lda zpsave,x
|
|
|
|
|
sta sp,x
|
|
|
|
|
dex
|
|
|
|
|
bpl L2
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
|
|
|
|
; Back to BASIC
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
2002-11-23 11:10:50 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
; Data
|
|
|
|
|
|
2008-07-03 19:39:14 +00:00
|
|
|
|
.segment "ZPSAVE"
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
|
|
|
|
zpsave: .res zpspace
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
.bss
|
|
|
|
|
spsave: .res 1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
stsave: .res 1
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
|
|
|
|
|