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
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2002-06-03 20:23:15 +00:00
|
|
|
|
.import initlib, donelib
|
2011-06-07 21:22:02 +00:00
|
|
|
|
.import callmain, zerobss, callirq
|
|
|
|
|
.import __INTERRUPTOR_COUNT__
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.import __RAM_START__, __RAM_SIZE__
|
2011-04-25 18:45:57 +00:00
|
|
|
|
.import __ZPSAVE_LOAD__, __STACKSIZE__
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +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
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.segment "TAPEHDR"
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.byte $16, $16, $16 ; Sync bytes
|
|
|
|
|
.byte $24 ; End of header marker
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.byte $00 ; $2B0
|
|
|
|
|
.byte $00 ; $2AF
|
|
|
|
|
.byte $80 ; $2AE Machine code flag
|
|
|
|
|
.byte $C7 ; $2AD Autoload flag
|
2011-07-03 13:23:07 +00:00
|
|
|
|
.dbyt __ZPSAVE_LOAD__ - 1 ; $2AB
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.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.
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.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
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
ldx #zpspace-1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
L1: lda sp,x
|
2011-04-16 12:09:28 +00:00
|
|
|
|
sta zpsave,x ; Save the zero page locations we need
|
2003-04-13 22:12:09 +00:00
|
|
|
|
dex
|
2011-04-16 12:09:28 +00:00
|
|
|
|
bpl L1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
lda STATUS
|
|
|
|
|
sta stsave
|
|
|
|
|
and #%11011111
|
|
|
|
|
sta STATUS
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
; Save system stuff and setup the stack
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
tsx
|
|
|
|
|
stx spsave ; Save system stk ptr
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +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__)
|
2011-04-16 12:09:28 +00:00
|
|
|
|
sta sp+1 ; Set argument stack ptr
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
; If we have IRQ functions, chain our stub into the IRQ vector
|
|
|
|
|
|
|
|
|
|
lda #<__INTERRUPTOR_COUNT__
|
|
|
|
|
beq NoIRQ1
|
|
|
|
|
lda IRQVec
|
|
|
|
|
ldx IRQVec+1
|
|
|
|
|
sta IRQInd+1
|
|
|
|
|
stx IRQInd+2
|
|
|
|
|
lda #<IRQStub
|
|
|
|
|
ldx #>IRQStub
|
|
|
|
|
sei
|
|
|
|
|
sta IRQVec
|
|
|
|
|
stx IRQVec+1
|
|
|
|
|
cli
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
; Call module constructors
|
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
NoIRQ1: jsr initlib
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2003-03-10 21:21:46 +00:00
|
|
|
|
; Push arguments and call main()
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +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
|
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
; Reset the IRQ vector if we chained it.
|
|
|
|
|
|
|
|
|
|
pha ; Save the return code on stack
|
|
|
|
|
lda #<__INTERRUPTOR_COUNT__
|
|
|
|
|
beq NoIRQ2
|
|
|
|
|
lda IRQInd+1
|
|
|
|
|
ldx IRQInd+2
|
|
|
|
|
sei
|
|
|
|
|
sta IRQVec
|
|
|
|
|
stx IRQVec+1
|
|
|
|
|
cli
|
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
; Restore system stuff
|
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
NoIRQ2: ldx spsave
|
2002-06-03 20:23:15 +00:00
|
|
|
|
txs
|
2011-04-16 12:09:28 +00:00
|
|
|
|
lda stsave
|
|
|
|
|
sta STATUS
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
|
|
|
|
; Copy back the zero page stuff
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
ldx #zpspace-1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
L2: lda zpsave,x
|
|
|
|
|
sta sp,x
|
|
|
|
|
dex
|
2011-04-16 12:09:28 +00:00
|
|
|
|
bpl L2
|
2002-06-03 20:23:15 +00:00
|
|
|
|
|
|
|
|
|
; Back to BASIC
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
; The IRQ vector jumps here, if condes routines are defined with type 2.
|
|
|
|
|
|
|
|
|
|
IRQStub:
|
|
|
|
|
cld ; Just to be sure
|
|
|
|
|
jsr callirq ; Call the functions
|
|
|
|
|
jmp IRQInd ; Jump to the saved IRQ vector
|
|
|
|
|
|
2002-11-23 11:10:50 +00:00
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
; Data
|
|
|
|
|
|
2011-06-07 21:22:02 +00:00
|
|
|
|
.data
|
|
|
|
|
|
|
|
|
|
IRQInd: jmp $0000
|
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
.segment "ZPSAVE"
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
zpsave: .res zpspace
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
2002-06-03 20:23:15 +00:00
|
|
|
|
.bss
|
2011-06-07 21:22:02 +00:00
|
|
|
|
|
2011-04-16 12:09:28 +00:00
|
|
|
|
spsave: .res 1
|
|
|
|
|
stsave: .res 1
|