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 __RAM_START__, __RAM_SIZE__, __STACKSIZE__
14 .include "zeropage.inc"
18 ; ------------------------------------------------------------------------
25 ; Switch to the second charset
30 ; Before doing anything else, we have to setup 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 we need
51 ; Save system stuff and setup the stack
57 stx spsave ; Save the system stack pointer
59 lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
61 lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
62 sta sp+1 ; Set argument stack ptr
64 ; Call module constructors
68 ; Set the bank for the file name to our execution bank. We must do this,
69 ; *after* calling constructors, because some of them may depend on the
70 ; original value of this register.
75 ; Push arguments and call main()
79 ; Back from main (this is also the _exit entry). Run 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 ST
97 ; Reset the stack and the memory configuration
104 ; Done, return to BASIC
108 ; ------------------------------------------------------------------------
115 ; ------------------------------------------------------------------------