]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/crt0.s
no TGI_ERR_NO_MEM or TGI_ERR_NO_IOCB anymore: replaced by TGI_ERR_NO_RES
[cc65] / libsrc / atari / crt0.s
index 167f4c3f0024c44c3b07063922708629db2b2da8..8edc4046f09841e2d14242272a54f58864ba6409 100644 (file)
@@ -5,64 +5,38 @@
 ;      Mark Keates
 ;      Freddy Offenga
 ;      Christian Groessler
-;
-; This must be the *first* file on the linker command line
 ;
 
        .export         _exit
-       .constructor    initsp,26
+        .export         __STARTUP__ : absolute = 1      ; Mark as startup
+       .constructor    initsp, 26
 
-       .import         getargs, argc, argv
-       .import         initlib, donelib
+       .import         initlib, donelib, callmain
                .import         zerobss, pushax
-       .import         _main,__filetab,getfd
-       .import         __CODE_LOAD__, __BSS_LOAD__
-
+       .import         _main, __filetab, getfd
+       .import         __STARTUP_LOAD__, __ZPSAVE_LOAD__
+       .import         __RESERVED_MEMORY__
+.ifdef DYNAMIC_DD
+       .import         __getdefdev
+.endif
+
+        .include        "zeropage.inc"
        .include        "atari.inc"
-
-; ------------------------------------------------------------------------
-; Define and export the ZP variables for the runtime
-
-       .exportzp       sp, sreg, regsave
-       .exportzp       ptr1, ptr2, ptr3, ptr4
-       .exportzp       tmp1, tmp2, tmp3, tmp4
-       .exportzp       fntemp, regbank, zpspace
-
-
-.zeropage
-
-zpstart        = *
-sp:            .res    2       ; Stack pointer
-sreg:          .res    2       ; Secondary register/high 16 bit for longs
-regsave:       .res    2       ; slot to save/restore (E)AX into
-ptr1:          .res    2
-ptr2:          .res    2
-ptr3:          .res    2
-ptr4:          .res    2
-tmp1:          .res    1
-tmp2:          .res    1
-tmp3:          .res    1
-tmp4:          .res    1
-fntemp:                .res    2       ; Pointer to file name
-regbank:       .res    6       ; 6 byte register bank
-
-zpspace        = * - zpstart           ; Zero page space allocated
-
-.code
+        .include        "_file.inc"
 
 ; ------------------------------------------------------------------------
 ; EXE header
 
        .segment "EXEHDR"
        .word   $FFFF
-       .word   __CODE_LOAD__
-       .word   __BSS_LOAD__ - 1
-       .code
-       .reloc
+       .word   __STARTUP_LOAD__
+       .word   __ZPSAVE_LOAD__ - 1
 
 ; ------------------------------------------------------------------------
 ; Actual code
 
+       .segment        "STARTUP"
+
        rts     ; fix for SpartaDOS / OS/A+
                ; they first call the entry point from AUTOSTRT and
                ; then the load addess (this rts here).
@@ -94,14 +68,20 @@ L1: lda     sp,x
        lda     APPMHI+1
        sta     appmsav+1
 
+       sec
        lda     MEMTOP
+       sbc     #<__RESERVED_MEMORY__
        sta     APPMHI                  ; initialize our APPMHI value
-       ldx     MEMTOP+1
-       stx     APPMHI+1
+       lda     MEMTOP+1
+       sbc     #>__RESERVED_MEMORY__
+       sta     APPMHI+1
 
 ; Call module constructors
 
        jsr     initlib
+.ifdef DYNAMIC_DD
+       jsr     __getdefdev
+.endif
 
 ; set left margin to 0
 
@@ -125,27 +105,17 @@ L1:       lda     sp,x
 
        lda     #0
        jsr     getfd
-       sta     __filetab               ; setup stdin
+               sta     __filetab + (0 * .sizeof(_FILE)); setup stdin
        lda     #0
        jsr     getfd
-       sta     __filetab + 2           ; setup stdout
+       sta     __filetab + (1 * .sizeof(_FILE)); setup stdout
        lda     #0
        jsr     getfd
-       sta     __filetab + 4           ; setup stderr
-
-; Pass command line if present
+       sta     __filetab + (2 * .sizeof(_FILE)); setup stderr
 
-       jsr     getargs
+; Push arguments and call main
 
-       lda     argc
-       ldx     argc+1
-       jsr     pushax          ; argc
-       lda     #<argv
-       ldx     #>argv
-       jsr     pushax          ; argv
-
-       ldy     #4              ; Argument size
-       jsr     _main           ; call the users code
+       jsr     callmain
 
 ; Call module destructors. This is also the _exit entry.
 
@@ -181,6 +151,11 @@ L2:        lda     zpsave,x
        dex
        bpl     L2
 
+; turn on cursor
+
+       inx
+       stx     CRSINH
+
 ; Back to DOS
 
        rts
@@ -189,6 +164,8 @@ L2: lda     zpsave,x
 
 ; setup sp
 
+.segment        "INIT"
+
 initsp:
        lda     APPMHI
        sta     sp
@@ -196,7 +173,7 @@ initsp:
        sta     sp+1
        rts
 
-       .data
+.segment        "ZPSAVE"
 
 zpsave:        .res    zpspace
 
@@ -208,6 +185,6 @@ old_shflok: .res    1
 old_lmargin:   .res    1
 
        .segment "AUTOSTRT"
-       .word   $02E0
-       .word   $02E1
-       .word   __CODE_LOAD__ + 1
+       .word   RUNAD                   ; defined in atari.h
+       .word   RUNAD+1
+       .word   __STARTUP_LOAD__ + 1