]> git.sur5r.net Git - cc65/blobdiff - libsrc/apple2/crt0.s
Working on loadable mouse drivers
[cc65] / libsrc / apple2 / crt0.s
index d51c282a2968468dde5278020d7d9709f0d0f252..3e428449f58eee8da1a79f901c12c8c99dc8d73d 100644 (file)
@@ -6,20 +6,38 @@
 
        .export         _exit
        .import         initlib, donelib
-       .import         zerobss, push0
-       .import         _main
+       .import         zerobss
+               .import         __STARTUP_LOAD__, __BSS_LOAD__  ; Linker generated
+       .import         callmain
 
         .include        "zeropage.inc"
        .include        "apple2.inc"
 
 ; ------------------------------------------------------------------------
-; Actual code
+; The executable header
 
-.code
+.segment       "EXEHDR"
+
+               .word   __STARTUP_LOAD__                ; Start address
+               .word   __BSS_LOAD__ - __STARTUP_LOAD__ ; Size
+
+; ------------------------------------------------------------------------
+; Place the startup code in a special segment.
+
+.segment               "STARTUP"
+
+; ProDOS TechRefMan, chapter 5.2.1:
+; "For maximum interrupt efficiency, a system program should not use more
+;  than the upper 3/4 of the stack."
+
+       ldx     #$FF
+       txs                     ; Init stack pointer
+
+; Save the zero page locations we need
 
                ldx     #zpspace-1
 L1:    lda     sp,x
-       sta     zpsave,x        ; Save the zero page locations we need
+       sta     zpsave,x
        dex
                bpl     L1
 
@@ -29,47 +47,23 @@ L1: lda     sp,x
 
 ; Save system stuff and setup the stack
 
-               tsx
-               stx     spsave          ; Save the system stack ptr
-
-       lda     #<TOPMEM
+       lda     HIMEM
        sta     sp
-       lda     #>TOPMEM
-               sta     sp+1            ; Set argument stack ptr
+       lda     HIMEM+1
+               sta     sp+1            ; Set argument stack ptr
 
 ; Call module constructors
 
        jsr     initlib
 
-; Initialize conio stuff
-
-       lda     #$ff
-       sta     TEXTTYP
-
-; Set up to use Apple ROM $C000-$CFFF
-
-       ;;      sta     USEROM
+; Push arguments and call main()
 
-; Pass an empty command line
-
-       jsr     push0           ; argc
-       jsr     push0           ; argv
-
-       ldy     #4              ; Argument size
-               jsr     _main           ; call the users code
+       jsr     callmain
 
 ; Call module destructors. This is also the _exit entry.
 
 _exit: jsr     donelib
 
-; Restore system stuff
-
-       lda     #$ff            ; Reset text mode
-       sta     TEXTTYP
-
-       ldx     spsave
-       txs                     ; Restore stack pointer
-
 ; Copy back the zero page stuff
 
        ldx     #zpspace-1
@@ -78,15 +72,20 @@ L2: lda     zpsave,x
        dex
                bpl     L2
 
-; Reset changed vectors, back to basic
+; ProDOS TechRefMan, chapter 5.2.1:
+; "System programs should set the stack pointer to $FF at the warm-start
+;  entry point."
 
-       jmp     RESTOR
+       ldx     #$FF
+       txs                     ; Re-init stack pointer
 
+; Back to DOS
 
-.data
+       jmp     DOSWARM
 
-zpsave:        .res    zpspace
+; ------------------------------------------------------------------------
+; Data
 
-.bss
+.data
 
-spsave:        .res    1
+zpsave:        .res    zpspace