;
; Startup code for cc65 (C16 version)
;
-; This must be the *first* file on the linker command line
-;
-; Note: The C16 is actually the Plus/4 with just 16KB of memory. So many
-; things are similar here, and we even use the plus4.inc include file.
+; Note: The C16 is actually the Plus/4 with just 16KB of memory. So, many
+; things are similar here; and, we even use the plus4.inc include file.
;
- .export _exit
- .import initlib, donelib
- .import push0, callmain, zerobss
+ .export _exit
+ .export __STARTUP__ : absolute = 1 ; Mark as startup
+ .import initlib, donelib
+ .import callmain, zerobss
.import MEMTOP, RESTOR, BSOUT, CLRCH
+ .importzp ST
.include "zeropage.inc"
- .include "../plus4/plus4.inc"
-
+ .include "plus4.inc"
; ------------------------------------------------------------------------
-; Place the startup code in a special segment.
+; Startup code
-.segment "STARTUP"
+.segment "STARTUP"
-; BASIC header with a SYS call
+Start:
- .word Head ; Load address
-Head: .word @Next
- .word .version ; Line number
- .byte $9E,"4109" ; SYS 4109
- .byte $00 ; End of BASIC line
-@Next: .word 0 ; BASIC end marker
-
-; ------------------------------------------------------------------------
-; Actual code
+; Save the zero-page locations that we need.
- ldx #zpspace-1
-L1: lda sp,x
- sta zpsave,x ; save the zero page locations we need
- dex
- bpl L1
+ ldx #zpspace-1
+L1: lda sp,x
+ sta zpsave,x
+ dex
+ bpl L1
-; Close open files
+; Switch to the second charset.
- jsr CLRCH
+ lda #14
+ jsr BSOUT
-; Switch to second charset
+; Clear the BSS data.
- lda #14
- jsr BSOUT
+ jsr zerobss
-; Clear the BSS data
+; Save some system stuff; and, set up the stack.
- jsr zerobss
+ tsx
+ stx spsave ; save system stk ptr
-; Save system stuff and setup the stack
+ sec
+ jsr MEMTOP ; Get top memory
+ cpy #$80 ; We can only use the low 32K :-(
+ bcc MemOk
+ ldy #$80
+ ldx #$00
+MemOk: stx sp
+ sty sp+1 ; set argument stack ptr
- tsx
- stx spsave ; save system stk ptr
+; Call the module constructors.
- sec
- jsr MEMTOP ; Get top memory
- cpy #$80 ; We can only use the low 32K :-(
- bcc MemOk
- ldy #$80
- ldx #$00
-MemOk: stx sp
- sty sp+1 ; set argument stack ptr
+ jsr initlib
-; Call module constructors
+; Push the command-line arguments; and, call main().
- jsr initlib
+ jsr callmain
-; Push arguments and call main()
+; Call the module destructors. This is also the exit() entry.
- jsr callmain
+_exit: pha ; Save the return code on stack
+ jsr donelib ; Run module destructors
-; Call module destructors. This is also the _exit entry.
+; Copy back the zero-page stuff.
-_exit: pha ; Save the return code on stack
- jsr donelib ; Run module destructors
+ ldx #zpspace-1
+L2: lda zpsave,x
+ sta sp,x
+ dex
+ bpl L2
-; Restore system stuff
+; Store the return code into BASIC's status variable.
- ldx spsave
- txs
+ pla
+ sta ST
-; Copy back the zero page stuff
+; Restore the stack pointer.
- ldx #zpspace-1
-L2: lda zpsave,x
- sta sp,x
- dex
- bpl L2
+ ldx spsave
+ txs
-; Store the return code into ST
+; Back to BASIC.
- pla
- sta ST
+ rts
-; Reset changed vectors
+; ------------------------------------------------------------------------
- jmp RESTOR
+.segment "INIT"
+zpsave: .res zpspace
-.data
-zpsave: .res zpspace
+; ------------------------------------------------------------------------
.bss
-spsave: .res 1
-
+spsave: .res 1