]> git.sur5r.net Git - cc65/blobdiff - libsrc/atmos/crt0.s
Comment additions and changes.
[cc65] / libsrc / atmos / crt0.s
index 5955fd94b7a50355a7079092e46ace4f6357981a..677dee84e68bfe9232bd85472805420f8128f1ba 100644 (file)
@@ -8,45 +8,54 @@
 
        .export         _exit
        .import         initlib, donelib
-       .import         push0, _main, zerobss
-       .import         __RAM_START__, __RAM_SIZE__     ; Linker generated
+       .import         callmain, zerobss
+               .import         __RAM_START__, __RAM_SIZE__, __BSS_LOAD__
+
+        .include        "zeropage.inc"
+        .include        "atmos.inc"
 
 
 ; ------------------------------------------------------------------------
-; Define and export the ZP variables for the Oric runtime
+; Oric tape header
+
+.segment        "TAPEHDR"
 
-       .exportzp       sp, sreg, regsave
-       .exportzp       ptr1, ptr2, ptr3, ptr4
-       .exportzp       tmp1, tmp2, tmp3, tmp4
-       .exportzp       regbank, zpspace
+        .byte   $16, $16, $16   ; Sync bytes
+        .byte   $24             ; End of header marker
 
-.zeropage
+        .byte   $00                             ; $2B0
+        .byte   $00                             ; $2AF
+        .byte   $80                             ; $2AE Machine code flag
+        .byte   $C7                             ; $2AD Autoload flag
+        .dbyt   __BSS_LOAD__                    ; $2AB
+        .dbyt   __RAM_START__                   ; $2A9
+        .byte   $00                             ; $2A8
+        .byte   $00                             ; Zero terminated name
 
-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
-regbank:       .res    6       ; 6 byte register bank
+; ------------------------------------------------------------------------
+; Place the startup code in a special segment.
 
-zpspace        = * - zpstart           ; Zero page space allocated
+.segment               "STARTUP"
 
-.code
+; Save the zero page area we're about to use
 
-; ------------------------------------------------------------------------
-; Actual code
+       ldx     #zpspace-1
+L1:    lda     sp,x
+       sta     zpsave,x        ; Save the zero page locations we need
+       dex
+               bpl     L1
 
 ; Clear the BSS data
 
        jsr     zerobss
 
+; Unprotect columns 0 and 1
+
+        lda     STATUS
+        sta     stsave
+        and     #%11011111
+        sta     STATUS
+
 ; Save system stuff and setup the stack
 
                tsx
@@ -61,13 +70,9 @@ zpspace      = * - zpstart           ; Zero page space allocated
 
        jsr     initlib
 
-; Pass an empty command line
-
-               jsr     push0           ; argc
-       jsr     push0           ; argv
+; Push arguments and call main()
 
-       ldy     #4              ; Argument size
-               jsr     _main           ; call the users code
+               jsr     callmain
 
 ; Call module destructors. This is also the _exit entry.
 
@@ -77,12 +82,30 @@ _exit:      jsr     donelib         ; Run module destructors
 
        ldx     spsave
        txs
+        lda     stsave
+        sta     STATUS
+
+; Copy back the zero page stuff
+
+               ldx     #zpspace-1
+L2:    lda     zpsave,x
+       sta     sp,x
+       dex
+               bpl     L2
 
 ; Back to BASIC
 
        rts
 
+; ------------------------------------------------------------------------
+; Data
+
+.segment        "ZPSAVE"
+
+zpsave:        .res    zpspace
+
 .bss
 spsave:        .res    1
+stsave: .res    1