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>
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; 2014-08-22, 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
|
|
|
|
|
.import initlib, donelib
|
|
|
|
|
.import callmain, zerobss
|
|
|
|
|
.import __RAM_START__, __RAM_SIZE__
|
|
|
|
|
.import __ZPSAVE_LOAD__, __STACKSIZE__
|
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
|
|
|
|
|
2003-04-13 22:12:09 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
; Oric tape header
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.segment "TAPEHDR"
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.byte $16, $16, $16 ; Sync bytes
|
|
|
|
|
.byte $24 ; End of header marker
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.byte $00 ; $2B0
|
|
|
|
|
.byte $00 ; $2AF
|
|
|
|
|
.byte $80 ; $2AE Machine code flag
|
|
|
|
|
.byte $C7 ; $2AD Autoload flag
|
|
|
|
|
.dbyt __ZPSAVE_LOAD__ - 1 ; $2AB
|
|
|
|
|
.dbyt __RAM_START__ ; $2A9
|
|
|
|
|
.byte $00 ; $2A8
|
|
|
|
|
.byte ((.VERSION >> 8) & $0F) + '0'
|
|
|
|
|
.byte ((.VERSION >> 4) & $0F) + '0'
|
|
|
|
|
.byte (.VERSION & $0F) + '0'
|
|
|
|
|
.byte $00 ; Zero terminated compiler version
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
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
|
|
|
|
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; Save the zero-page area that we're about to use.
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
ldx #zpspace-1
|
|
|
|
|
L1: lda sp,x
|
2014-08-21 14:46:25 +00:00
|
|
|
|
sta zpsave,x
|
2013-05-09 11:56:54 +00:00
|
|
|
|
dex
|
|
|
|
|
bpl L1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2014-08-21 14:46:25 +00:00
|
|
|
|
; Clear the BSS data.
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
jsr zerobss
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-08-21 14:46:25 +00:00
|
|
|
|
; Unprotect screen columns 0 and 1.
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
lda STATUS
|
|
|
|
|
sta stsave
|
|
|
|
|
and #%11011111
|
|
|
|
|
sta STATUS
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; Save some system stuff; and, set up the stack.
|
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
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
|
|
|
|
sta sp
|
|
|
|
|
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
|
|
|
|
sta sp+1 ; Set argument stack ptr
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2014-08-22 21:19:58 +00:00
|
|
|
|
; Call the module constructors.
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
jsr initlib
|
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
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
_exit: jsr donelib ; Run module destructors
|
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
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
ldx #zpspace-1
|
|
|
|
|
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
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
.segment "ZPSAVE"
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
zpsave: .res zpspace
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
.bss
|
2011-06-07 21:22:02 +00:00
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
spsave: .res 1
|
|
|
|
|
stsave: .res 1
|