2019-09-27 07:38:51 +00:00
|
|
|
;
|
|
|
|
; Start-up code for cc65 (CX16 version)
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _exit
|
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as start-up
|
|
|
|
|
|
|
|
.import initlib, donelib
|
|
|
|
.import zerobss, callmain
|
2019-09-28 04:54:27 +00:00
|
|
|
.import CHROUT
|
2019-09-27 07:38:51 +00:00
|
|
|
.import __MAIN_START__, __MAIN_SIZE__ ; Linker-generated
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "cx16.inc"
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Start-up code
|
|
|
|
|
|
|
|
.segment "STARTUP"
|
|
|
|
|
|
|
|
Start: tsx
|
|
|
|
stx spsave ; Save the system stack ptr
|
|
|
|
|
|
|
|
; Save space by putting some of the start-up code in the ONCE segment,
|
|
|
|
; which will be re-used by the BSS segment, the heap, and the C stack.
|
|
|
|
|
|
|
|
jsr init
|
|
|
|
|
|
|
|
; Clear the BSS data.
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
|
|
|
; Push the command-line arguments; and, call main().
|
|
|
|
|
|
|
|
jsr callmain
|
|
|
|
|
2019-11-16 18:11:40 +00:00
|
|
|
; Back from main() [this is also the exit() entry].
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
; Put the program return code into BASIC's status variable.
|
|
|
|
|
|
|
|
sta STATUS
|
|
|
|
|
|
|
|
; Run the module destructors.
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
jsr donelib
|
|
|
|
|
2019-11-16 18:11:40 +00:00
|
|
|
.if 0 ; We no longer need to preserve zero-page space for cc65's variables.
|
2019-09-27 07:38:51 +00:00
|
|
|
; Copy back the zero-page stuff.
|
|
|
|
|
|
|
|
ldx #zpspace-1
|
|
|
|
L2: lda zpsave,x
|
|
|
|
sta sp,x
|
|
|
|
dex
|
|
|
|
bpl L2
|
2019-11-16 18:11:40 +00:00
|
|
|
.endif
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; Restore the system stuff.
|
|
|
|
|
|
|
|
ldx spsave
|
|
|
|
txs ; Restore stack pointer
|
2019-09-28 04:54:27 +00:00
|
|
|
ldx ramsave
|
2019-09-27 07:38:51 +00:00
|
|
|
stx VIA1::PRA2 ; Restore former RAM bank
|
2019-09-28 04:54:27 +00:00
|
|
|
lda VIA1::PRB
|
|
|
|
and #<~$07
|
2019-10-07 18:36:54 +00:00
|
|
|
ora #$04
|
2019-09-28 04:54:27 +00:00
|
|
|
sta VIA1::PRB ; Change back to BASIC ROM
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; Back to BASIC.
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.segment "ONCE"
|
|
|
|
|
|
|
|
init:
|
2019-09-28 04:54:27 +00:00
|
|
|
; Change from BASIC's ROM to Kernal's ROM.
|
|
|
|
|
|
|
|
lda VIA1::PRB
|
2019-10-07 18:36:54 +00:00
|
|
|
and #<~$07
|
2019-09-28 04:54:27 +00:00
|
|
|
sta VIA1::PRB
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; Change to the first RAM bank.
|
|
|
|
|
|
|
|
lda VIA1::PRA2
|
2019-09-28 04:54:27 +00:00
|
|
|
sta ramsave ; Save the current RAM bank number
|
2019-09-27 07:38:51 +00:00
|
|
|
lda #$00 ; Choose RAM bank zero
|
|
|
|
sta VIA1::PRA2
|
|
|
|
|
2019-11-16 18:11:40 +00:00
|
|
|
.if 0 ; We no longer need to preserve zero-page space for cc65's variables.
|
2019-09-27 07:38:51 +00:00
|
|
|
; Save the zero-page locations that we need.
|
|
|
|
|
|
|
|
ldx #zpspace-1
|
|
|
|
L1: lda sp,x
|
|
|
|
sta zpsave,x
|
|
|
|
dex
|
|
|
|
bpl L1
|
2019-11-16 18:11:40 +00:00
|
|
|
.endif
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; Set up the stack.
|
|
|
|
|
|
|
|
lda #<(__MAIN_START__ + __MAIN_SIZE__)
|
|
|
|
ldx #>(__MAIN_START__ + __MAIN_SIZE__)
|
|
|
|
sta sp
|
|
|
|
stx sp+1 ; Set argument stack ptr
|
|
|
|
|
|
|
|
; Switch to the second charset.
|
|
|
|
|
|
|
|
lda #$0E
|
2019-09-28 04:54:27 +00:00
|
|
|
jsr CHROUT
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; Call the module constructors.
|
|
|
|
|
|
|
|
jmp initlib
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data
|
|
|
|
|
|
|
|
.segment "INIT"
|
|
|
|
|
2019-09-28 04:54:27 +00:00
|
|
|
ramsave:
|
2019-09-27 07:38:51 +00:00
|
|
|
.res 1
|
|
|
|
spsave: .res 1
|
2019-11-16 18:11:40 +00:00
|
|
|
.if 0
|
2019-09-27 07:38:51 +00:00
|
|
|
zpsave: .res zpspace
|
2019-11-16 18:11:40 +00:00
|
|
|
.endif
|