2019-09-27 07:38:51 +00:00
|
|
|
;
|
2022-04-02 13:39:35 +00:00
|
|
|
; Start-up code for cc65 (CX16 r39 version)
|
2019-09-27 07:38:51 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
.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
|
2022-04-02 13:39:35 +00:00
|
|
|
stx spsave ; Save the system stack ptr.
|
2019-09-27 07:38:51 +00:00
|
|
|
|
2020-05-02 17:46:06 +00:00
|
|
|
; Save space by putting some of the start-up code in the ONCE segment
|
2019-09-27 07:38:51 +00:00
|
|
|
; which will be re-used by the BSS segment, the heap, and the C stack.
|
|
|
|
|
|
|
|
jsr init
|
|
|
|
|
|
|
|
; Clear the BSS data.
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
2020-05-02 17:46:06 +00:00
|
|
|
; Push the command-line arguments, and call main().
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
; Restore the system stuff.
|
|
|
|
|
|
|
|
ldx spsave
|
|
|
|
txs ; Restore stack pointer
|
2019-09-28 04:54:27 +00:00
|
|
|
ldx ramsave
|
2022-04-02 13:39:35 +00:00
|
|
|
stx RAM_BANK ; Restore former RAM bank
|
|
|
|
lda #$04
|
|
|
|
sta ROM_BANK ; 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.
|
|
|
|
|
2022-04-02 13:39:35 +00:00
|
|
|
stz ROM_BANK
|
2019-09-27 07:38:51 +00:00
|
|
|
|
2019-12-25 15:56:32 +00:00
|
|
|
; Change to the second RAM bank.
|
2019-09-27 07:38:51 +00:00
|
|
|
|
2022-04-02 13:39:35 +00:00
|
|
|
lda RAM_BANK
|
2019-09-28 04:54:27 +00:00
|
|
|
sta ramsave ; Save the current RAM bank number
|
2019-12-25 15:56:32 +00:00
|
|
|
lda #$01
|
2022-04-02 13:39:35 +00:00
|
|
|
sta RAM_BANK
|
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
|
|
|
|
|
2019-12-25 15:56:32 +00:00
|
|
|
; Switch to the lower/UPPER PetSCII charset.
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
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
|