2 ; Startup code for cc65 (C128 version)
6 .export __STARTUP__ : absolute = 1 ; Mark as startup
7 .import initlib, donelib
9 .import push0, callmain
10 .import RESTOR, BSOUT, CLRCH
11 .import __MAIN_START__, __MAIN_SIZE__, __STACKSIZE__
14 .include "zeropage.inc"
18 ; ------------------------------------------------------------------------
25 ; Switch to the second charset.
30 ; Before doing anything else, we have to set up our banking configuration.
31 ; Otherwise, just the lowest 16K are actually RAM. Writing through the ROM
32 ; to the underlying RAM works; but, it is bad style.
34 lda MMU_CR ; Get current memory configuration...
35 pha ; ...and save it for later
36 lda #MMU_CFG_CC65 ; Bank0 with Kernal ROM
39 ; Save the zero-page locations that we need.
51 ; Save some system stuff; and, set up the stack.
57 stx spsave ; Save the system stack pointer
59 lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
60 ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
62 stx sp+1 ; Set argument stack ptr
64 ; Call the module constructors.
68 ; Set the bank for the file name to our execution bank. We must do this
69 ; *after* calling the constructors because some of them might depend on
70 ; the original value of this register.
75 ; Push the command-line arguments; and, call main().
79 ; Back from main() [this is also the exit() entry]. Run the module destructors.
81 _exit: pha ; Save the return code on stack
84 ; Copy back the zero-page stuff.
92 ; Place the program return code into BASIC's status variable.
97 ; Reset the stack and the memory configuration.
104 ; Done, return to BASIC.
108 ; ------------------------------------------------------------------------
115 ; ------------------------------------------------------------------------