]> git.sur5r.net Git - cc65/blobdiff - libsrc/plus4/crt0.s
Replaced whole bunch for Makefiles with a single generic Makefile.
[cc65] / libsrc / plus4 / crt0.s
index 032ad7947027003eaa3b588349815de1ed17f9a1..73460d82b367d08ef5cbcd946ecc8db6ed8a2850 100644 (file)
@@ -1,15 +1,17 @@
 ;
 ; Startup code for cc65 (Plus/4 version)
-;
-; This must be the *first* file on the linker command line
 ;
 
        .export         _exit
         .export         brk_jmp
+        .export         __STARTUP__ : absolute = 1      ; Mark as startup
 
        .import         callirq_y, initlib, donelib
-       .import         push0, callmain, zerobss
+       .import         callmain, zerobss
        .import         __INTERRUPTOR_COUNT__
+       .import         __RAM_START__, __RAM_SIZE__     ; Linker generated
+       .import         __STACKSIZE__                   ; Linker generated
+       .importzp       ST
 
         .include        "zeropage.inc"
        .include        "plus4.inc"
 IRQInd                 = $500  ; JMP $0000 - used as indirect IRQ vector
 
 ; ------------------------------------------------------------------------
-; Place the startup code in a special segment to cope with the quirks of
-; plus/4 banking.
+; Startup code
 
 .segment               "STARTUP"
 
-        .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
+Start:
 
-; ------------------------------------------------------------------------
-; Actual code
+; Save the zero page locations we need
 
         sei                     ; No interrupts since we're banking out the ROM
         sta     ENABLE_RAM
                ldx     #zpspace-1
 L1:    lda     sp,x
-       sta     zpsave,x        ; save the zero page locations we need
+       sta     zpsave,x
        dex
                bpl     L1
         sta     ENABLE_ROM
         cli
 
-; Close open files
-
-       jsr     $FFCC           ; CLRCH
-
 ; Switch to second charset
 
        lda     #14
@@ -61,9 +52,9 @@ L1:   lda     sp,x
                tsx
                stx     spsave          ; save system stk ptr
 
-        lda     #<$FD00
+        lda     #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
         sta     sp
-        lda     #>$FD00
+        lda     #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
         sta     sp+1
 
 ; Setup the IRQ vector in the banked RAM and switch off the ROM
@@ -80,16 +71,16 @@ L1: lda     sp,x
 
        jsr     zerobss
 
-; Call module constructors
-
-       jsr     initlib
-
 ; Initialize irqcount, which means that from now own custom linked in IRQ
 ; handlers (via condes) will be called.
 
         lda     #.lobyte(__INTERRUPTOR_COUNT__*2)
         sta     irqcount
 
+; Call module constructors
+
+       jsr     initlib
+
 ; Push arguments and call main()
 
        jsr     callmain
@@ -97,9 +88,12 @@ L1:  lda     sp,x
 ; Back from main (this is also the _exit entry). Run module destructors.
 
 _exit:         pha                     ; Save the return code
+        jsr    donelib         ; Run module destructors
+
+; Disable chained IRQ handlers
+
        lda     #0
         sta     irqcount        ; Disable custom IRQ handlers
-        jsr    donelib         ; Run module destructors
 
 ; Copy back the zero page stuff
 
@@ -119,11 +113,10 @@ L2:       lda     zpsave,x
                ldx     spsave
                txs
 
-; Enable the ROM, reset changed vectors and return to BASIC
+; Enable the ROM and return to BASIC
 
         sta     ENABLE_ROM
-       jmp     $FF8A           ; RESTOR
-
+               rts
 
 ; ------------------------------------------------------------------------
 ; IRQ handler. The handler in the ROM enables the kernal and jumps to
@@ -200,10 +193,10 @@ brk_jmp:        jmp     $0000
 
 spsave:                .res    1
 
+irqcount:       .byte   0
+
 .segment        "ZPSAVE"
 
 zpsave:                .res    zpspace
 
-.bss
-irqcount:       .byte   0