2 ; Startup code for cc65 (C16 version)
4 ; Note: The C16 is actually the Plus/4 with just 16KB of memory. So, many
5 ; things are similar here; and, we even use the plus4.inc include file.
9 .export __STARTUP__ : absolute = 1 ; Mark as startup
10 .import initlib, donelib
11 .import callmain, zerobss
12 .import MEMTOP, RESTOR, BSOUT, CLRCH
15 .include "zeropage.inc"
18 ; ------------------------------------------------------------------------
25 ; Save the zero-page locations that we need.
33 ; Switch to the second charset.
42 ; Save some system stuff; and, set up the stack.
45 stx spsave ; save system stk ptr
48 jsr MEMTOP ; Get top memory
49 cpy #$80 ; We can only use the low 32K :-(
54 sty sp+1 ; set argument stack ptr
56 ; Call the module constructors.
60 ; Push the command-line arguments; and, call main().
64 ; Call the module destructors. This is also the exit() entry.
66 _exit: pha ; Save the return code on stack
67 jsr donelib ; Run module destructors
69 ; Copy back the zero-page stuff.
77 ; Store the return code into BASIC's status variable.
82 ; Restore the stack pointer.
91 ; ------------------------------------------------------------------------
97 ; ------------------------------------------------------------------------