]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/crt0.s
Normalized style.
[cc65] / libsrc / atari / crt0.s
index 73d2167137c00d116f81dd2373c9e1c5159e0ddd..f1c7b864e8ffd1d10bd189863eed957650c032dd 100644 (file)
@@ -8,42 +8,26 @@
 ;       Stefan Haubenthal
 ;
 
-        .export         _exit
         .export         __STARTUP__ : absolute = 1      ; Mark as startup
+        .export         _exit, start
 
         .import         initlib, donelib
         .import         callmain, zerobss
-        .import         __STARTUP_LOAD__, __ZPSAVE_LOAD__, __BSS_LOAD__
         .import         __RESERVED_MEMORY__
-       .import         __RAM_START__, __RAM_SIZE__
-       .import         zpsave
-       .import         sram_init
-
+        .import         __RAM_START__, __RAM_SIZE__
+.ifdef __ATARIXL__
+        .import         __STACKSIZE__
+        .import         sram_init
+        .import         scrdev
+        .import         findfreeiocb
+        .forceimport    sramprep                        ; force inclusion of the "shadow RAM preparation" load chunk
+        .include        "save_area.inc"
+.endif
 
         .include        "zeropage.inc"
         .include        "atari.inc"
-       .include        "save_area.inc"
 
 ; ------------------------------------------------------------------------
-; EXE header
-
-.segment        "EXEHDR"
-
-        .word   $FFFF
-
-.if .defined(__ATARIXL__)
-.segment       "MAINHDR"
-.endif
-
-        .word   __STARTUP_LOAD__
-.if .defined(__ATARIXL__)
-        .word   __BSS_LOAD__ - 1
-.else
-        .word   __ZPSAVE_LOAD__ - 1
-.endif
-
-; ------------------------------------------------------------------------
-; Actual code
 
 .segment        "STARTUP"
 
 
 ; Real entry point:
 
-.if .not .defined(__ATARIXL__)         ; already done in previous load chunk
-
-; Save the zero page locations we need
-
-        ldx     #zpspace-1
-L1:     lda     sp,x
-        sta     zpsave,x
-        dex
-        bpl     L1
-
-.else
-
-       jsr     sram_init
+start:
 
+.ifdef __ATARIXL__
+        jsr     sram_init
 .endif
 
 ; Clear the BSS data
@@ -77,16 +51,23 @@ L1:     lda     sp,x
 ; Setup the stack
 
         tsx
-        stx     spsave
+        stx     SP_save
+
+.ifdef __ATARIXL__
 
-.if .not .defined(__ATARIXL__)
+        lda     #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
+        sta     sp
+        lda     #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
+        sta     sp+1
+
+.else
 
 ; Report memory usage
 
         lda     APPMHI
-        sta     appmsav                 ; remember old APPMHI value
+        sta     APPMHI_save             ; remember old APPMHI value
         lda     APPMHI+1
-        sta     appmsav+1
+        sta     APPMHI_save+1
 
         sec
         lda     MEMTOP
@@ -98,13 +79,6 @@ L1:     lda     sp,x
         sta     APPMHI+1
         sta     sp+1                    ; setup runtime stack part 2
 
-.else
-
-       lda     #<(__RAM_START__ + __RAM_SIZE__ - 1)
-       sta     sp
-       lda     #>(__RAM_START__ + __RAM_SIZE__ - 1)
-       sta     sp+1
-
 .endif
 
 ; Call module constructors
@@ -114,20 +88,20 @@ L1:     lda     sp,x
 ; Set left margin to 0
 
         lda     LMARGN
-        sta     old_lmargin
+        sta     LMARGN_save
         ldy     #0
         sty     LMARGN
 
 ; Set keyb to upper/lowercase mode
 
         ldx     SHFLOK
-        stx     old_shflok
+        stx     SHFLOK_save
         sty     SHFLOK
 
 ; Initialize conio stuff
 
-        dey                             ; Set X to $FF
-        sty     CH
+        dey                     ; Set Y to $FF
+        sty     CH              ; remove keypress which might be in the input buffer
 
 ; Push arguments and call main
 
@@ -139,56 +113,74 @@ _exit:  jsr     donelib         ; Run module destructors
 
 ; Restore system stuff
 
-        ldx     spsave
+        ldx     SP_save
         txs                     ; Restore stack pointer
 
 ; Restore left margin
 
-        lda     old_lmargin
+        lda     LMARGN_save
         sta     LMARGN
 
 ; Restore kb mode
 
-        lda     old_shflok
+        lda     SHFLOK_save
         sta     SHFLOK
 
-.if .not .defined(__ATARIXL__)
-
 ; Restore APPMHI
 
-        lda     appmsav
+        lda     APPMHI_save
         sta     APPMHI
-        lda     appmsav+1
+        lda     APPMHI_save+1
         sta     APPMHI+1
 
-.else
+.ifdef __ATARIXL__
 
 ; Atari XL target stuff...
 
-       lda     PORTB_save
-       sta     PORTB
-       lda     MEMTOP_save
-       sta     MEMTOP
-       lda     MEMTOP_save+1
-       sta     MEMTOP+1
-       lda     APPMHI_save
-       sta     APPMHI
-       lda     APPMHI_save+1
-       sta     APPMHI+1
-.endif
-
-
-; Copy back the zero page stuff
+        lda     PORTB_save
+        sta     PORTB
+        lda     RAMTOP_save
+        sta     RAMTOP
+        lda     MEMTOP_save
+        sta     MEMTOP
+        lda     MEMTOP_save+1
+        sta     MEMTOP+1
+
+
+; Issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) in
+; order to restore screen memory to its defailt location just
+; before the ROM.
+
+        jsr     findfreeiocb
+
+        ; Reopen it in Graphics 0
+        lda     #OPEN
+        sta     ICCOM,x
+        lda     #OPNIN | OPNOT
+        sta     ICAX1,x
+        lda     #0
+        sta     ICAX2,x
+        lda     #<scrdev
+        sta     ICBAL,x
+        lda     #>scrdev
+        sta     ICBAH,x
+        lda     #3
+        sta     ICBLL,x
+        lda     #0
+        sta     ICBLH,x
+        jsr     CIOV_org
+; No error checking here, shouldn't happen(tm), and no way to
+; recover anyway.
+
+        lda     #CLOSE
+        sta     ICCOM,x
+        jsr     CIOV_org
 
-        ldx     #zpspace-1
-L2:     lda     zpsave,x
-        sta     sp,x
-        dex
-        bpl     L2
+.endif
 
 ; Turn on cursor
 
-        inx
+        ldx     #0
         stx     CRSINH
 
 ; Back to DOS
@@ -201,12 +193,9 @@ L2:     lda     zpsave,x
 
 .bss
 
-spsave:         .res    1
-appmsav:        .res    1
-old_shflok:     .res    1
-old_lmargin:    .res    1
-
-        .segment "AUTOSTRT"
-        .word   RUNAD                   ; defined in atari.h
-        .word   RUNAD+1
-        .word   __STARTUP_LOAD__ + 1
+SP_save:        .res    1
+SHFLOK_save:    .res    1
+LMARGN_save:    .res    1
+.ifndef __ATARIXL__
+APPMHI_save:    .res    2
+.endif