]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/crt0.s
Normalized style.
[cc65] / libsrc / atari / crt0.s
index db8a595e30ea3a662092d0d026548face0e9552a..f1c7b864e8ffd1d10bd189863eed957650c032dd 100644 (file)
@@ -8,18 +8,19 @@
 ;       Stefan Haubenthal
 ;
 
-        .export         _exit
         .export         __STARTUP__ : absolute = 1      ; Mark as startup
+        .export         _exit, start
 
         .import         initlib, donelib
         .import         callmain, zerobss
-        .import         __STARTUP_LOAD__, __BSS_LOAD__
         .import         __RESERVED_MEMORY__
         .import         __RAM_START__, __RAM_SIZE__
-.if .defined(__ATARIXL__)
+.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        "atari.inc"
 
 ; ------------------------------------------------------------------------
-; EXE header
-
-.segment        "EXEHDR"
-
-        .word   $FFFF
-
-.if .defined(__ATARIXL__)
-.segment        "MAINHDR"
-.endif
-
-        .word   __STARTUP_LOAD__
-        .word   __BSS_LOAD__ - 1
-
-; ------------------------------------------------------------------------
-; Actual code
 
 .segment        "STARTUP"
 
@@ -52,7 +38,9 @@
 
 ; Real entry point:
 
-.if .defined(__ATARIXL__)
+start:
+
+.ifdef __ATARIXL__
         jsr     sram_init
 .endif
 
 ; 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
 
         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
 ; 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
 
@@ -125,17 +113,17 @@ _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
 
 ; Restore APPMHI
@@ -145,7 +133,7 @@ _exit:  jsr     donelib         ; Run module destructors
         lda     APPMHI_save+1
         sta     APPMHI+1
 
-.if .defined(__ATARIXL__)
+.ifdef __ATARIXL__
 
 ; Atari XL target stuff...
 
@@ -159,7 +147,9 @@ _exit:  jsr     donelib         ; Run module destructors
         sta     MEMTOP+1
 
 
-; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
+; 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
 
@@ -179,7 +169,9 @@ _exit:  jsr     donelib         ; Run module destructors
         lda     #0
         sta     ICBLH,x
         jsr     CIOV_org
-; add error checking here...
+; No error checking here, shouldn't happen(tm), and no way to
+; recover anyway.
+
         lda     #CLOSE
         sta     ICCOM,x
         jsr     CIOV_org
@@ -201,15 +193,9 @@ _exit:  jsr     donelib         ; Run module destructors
 
 .bss
 
-spsave:         .res    1
-old_shflok:     .res    1
-old_lmargin:    .res    1
-.if .not .defined(__ATARIXL__)
+SP_save:        .res    1
+SHFLOK_save:    .res    1
+LMARGN_save:    .res    1
+.ifndef __ATARIXL__
 APPMHI_save:    .res    2
 .endif
-
-
-.segment "AUTOSTRT"
-        .word   RUNAD                   ; defined in atari.inc
-        .word   RUNAD+1
-        .word   __STARTUP_LOAD__ + 1