]> git.sur5r.net Git - cc65/blobdiff - libsrc/cbm510/crt0.s
remove superfluous ".code" line
[cc65] / libsrc / cbm510 / crt0.s
index da0ef0ab2191db3d7bbc8438dc7a339689f76ad7..ef2cb8c6295a8256597c2016d1e5dc6c2bc03e1b 100644 (file)
@@ -1,16 +1,15 @@
 ;
 ; Startup code for cc65 (CBM 500 version)
-;
-; This must be the *first* file on the linker command line
 ;
 
        .export         _exit
+        .export         __STARTUP__ : absolute = 1      ; Mark as startup
 
-       .import         _clrscr, initlib, donelib, condes
+       .import         _clrscr, initlib, donelib, callirq_y
        .import         push0, callmain
        .import         __CHARRAM_START__, __CHARRAM_SIZE__, __VIDRAM_START__
        .import         __BSS_RUN__, __BSS_SIZE__, __EXTZP_RUN__
-       .import         __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
+       .import         __INTERRUPTOR_COUNT__
        .import         scnkey, UDTIM
 
        .include        "zeropage.inc"
@@ -425,15 +424,15 @@ ccopy2:   lda     __VIDRAM_START__,y
         lda     ExecReg
                sta     IndReg
 
-; Call module constructors, enable chained IRQs afterwards.
+; Activate chained interrupt handlers, then enable interrupts.
 
-        jsr    initlib
-        lda     #.lobyte(__IRQFUNC_COUNT__*2)
+        lda     #.lobyte(__INTERRUPTOR_COUNT__*2)
         sta     irqcount
+       cli
 
-; Enable interrupts
+; Call module constructors.
 
-       cli
+        jsr    initlib
 
 ; Push arguments and call main()
 
@@ -442,9 +441,10 @@ ccopy2:    lda     __VIDRAM_START__,y
 ; Call module destructors. This is also the _exit entry and the default entry
 ; point for the break vector.
 
-_exit:  lda     #$00
-        sta     irqcount        ; Disable custom irq handlers
+_exit:  pha                    ; Save the return code on stack
         jsr    donelib         ; Run module destructors
+       lda     #$00
+        sta     irqcount        ; Disable custom irq handlers
 
 ; Address the system bank
 
@@ -481,6 +481,12 @@ _exit:  lda     #$00
         bne     @L0
 .endif
 
+; Place the program return code into ST
+
+       pla
+       ldy     #$9C            ; ST
+       sta     (sysp0),y
+
 ; Setup the welcome code at the stack bottom in the system bank.
 
         ldy     #$FF
@@ -533,9 +539,7 @@ irq:    pha
 
                ldy     irqcount
         beq     irqskip
-               lda     #<__IRQFUNC_TABLE__
-       ldx     #>__IRQFUNC_TABLE__
-       jsr     condes                  ; Call the functions
+               jsr     callirq_y               ; Call the functions
 
 ; Done with chained IRQ handlers, check the TPI for IRQs and handle them