]> git.sur5r.net Git - cc65/blobdiff - libsrc/atari/crt0.s
Renamed RAM to MAIN for all disk based targets.
[cc65] / libsrc / atari / crt0.s
index 4542d8945ecd89d891711a64fb225628fd2c7b45..317fe56978c9dce213aa3aa8a88701f4bb548d2a 100644 (file)
 ; Startup code for cc65 (ATARI version)
 ;
 ; Contributing authors:
-;      Mark Keates
-;      Freddy Offenga
-;      Christian Groessler
-;      Stefan Haubenthal
+;       Mark Keates
+;       Freddy Offenga
+;       Christian Groessler
+;       Stefan Haubenthal
 ;
 
-       .export         _exit
-       .export         __STARTUP__ : absolute = 1      ; Mark as startup
-
-       .import         initlib, donelib
-       .import         callmain, zerobss, callirq
-       .import         __INTERRUPTOR_COUNT__
-       .import         __STARTUP_LOAD__, __ZPSAVE_LOAD__
-       .import         __RESERVED_MEMORY__
-
-       .include        "zeropage.inc"
-       .include        "atari.inc"
-
-; ------------------------------------------------------------------------
-; EXE header
-
-       .segment "EXEHDR"
-       .word   $FFFF
-       .word   __STARTUP_LOAD__
-       .word   __ZPSAVE_LOAD__ - 1
+        .export         __STARTUP__ : absolute = 1      ; Mark as startup
+        .export         _exit, start
+
+        .import         initlib, donelib
+        .import         callmain, zerobss
+        .import         __RESERVED_MEMORY__
+        .import         __MAIN_START__, __MAIN_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"
 
 ; ------------------------------------------------------------------------
-; Actual code
 
-       .segment        "STARTUP"
+.segment        "STARTUP"
 
-       rts     ; fix for SpartaDOS / OS/A+
-               ; they first call the entry point from AUTOSTRT and
-               ; then the load addess (this rts here).
-               ; We point AUTOSTRT directly after the rts.
+        rts     ; fix for SpartaDOS / OS/A+
+                ; They first call the entry point from AUTOSTRT; and
+                ; then, the load address (this rts here).
+                ; We point AUTOSTRT directly after the rts.
 
 ; Real entry point:
 
-; Save the zero page locations we need
+start:
 
-       ldx     #zpspace-1
-L1:    lda     sp,x
-       sta     zpsave,x
-       dex
-       bpl     L1
+.ifdef __ATARIXL__
+        jsr     sram_init
+.endif
 
-; Clear the BSS data
+; Clear the BSS data.
 
-       jsr     zerobss
+        jsr     zerobss
 
-; Setup the stack
+; Set up the stack.
 
-       tsx
-       stx     spsave
+        tsx
+        stx     SP_save
 
-; Report memory usage
+.ifdef __ATARIXL__
 
-       lda     APPMHI
-       sta     appmsav                 ; remember old APPMHI value
-       lda     APPMHI+1
-       sta     appmsav+1
+        lda     #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
+        ldx     #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
+        sta     sp
+        stx     sp+1
 
-       sec
-       lda     MEMTOP
-       sbc     #<__RESERVED_MEMORY__
-       sta     APPMHI                  ; initialize our APPMHI value
-       sta     sp                      ; setup runtime stack part 1
-       lda     MEMTOP+1
-       sbc     #>__RESERVED_MEMORY__
-       sta     APPMHI+1
-       sta     sp+1                    ; setup runtime stack part 2
+.else
 
-; If we have IRQ functions, chain our stub into the IRQ vector
+; Report the memory usage.
 
-       lda     #<__INTERRUPTOR_COUNT__
-       beq     NoIRQ1
-       lda     VVBLKI
-       ldx     VVBLKI+1
-       sta     IRQInd+1
-       stx     IRQInd+2
-       lda     #6
-       ldy     #<IRQStub
-       ldx     #>IRQStub
-       jsr     SETVBV
+        lda     APPMHI
+        sta     APPMHI_save             ; remember old APPMHI value
+        lda     APPMHI+1
+        sta     APPMHI_save+1
 
-; Call module constructors
+        sec
+        lda     MEMTOP
+        sbc     #<__RESERVED_MEMORY__
+        sta     APPMHI                  ; initialize our APPMHI value
+        sta     sp                      ; set up runtime stack part 1
+        lda     MEMTOP+1
+        sbc     #>__RESERVED_MEMORY__
+        sta     APPMHI+1
+        sta     sp+1                    ; set up runtime stack part 2
 
-NoIRQ1:        jsr     initlib
+.endif
 
-; Set left margin to 0
+; Call the module constructors.
 
-       lda     LMARGN
-       sta     old_lmargin
-       ldy     #0
-       sty     LMARGN
+        jsr     initlib
 
-; Set keyb to upper/lowercase mode
+; Set the left margin to 0.
 
-       ldx     SHFLOK
-       stx     old_shflok
-       sty     SHFLOK
+        lda     LMARGN
+        sta     LMARGN_save
+        ldy     #0
+        sty     LMARGN
 
-; Initialize conio stuff
+; Set the keyboard to upper-/lower-case mode.
 
-       dey                             ; Set X to $FF
-       sty     CH
+        ldx     SHFLOK
+        stx     SHFLOK_save
+        sty     SHFLOK
 
-; Push arguments and call main
+; Initialize the conio stuff.
 
-       jsr     callmain
+        dey                     ; Set Y to $FF
+        sty     CH              ; remove keypress which might be in the input buffer
 
-; Call module destructors. This is also the _exit entry.
+; Push the command-line arguments; and, call main().
 
-_exit: jsr     donelib         ; Run module destructors
+        jsr     callmain
 
-; Reset the IRQ vector if we chained it.
+; Call the module destructors. This is also the exit() entry.
 
-       pha                     ; Save the return code on stack
-       lda     #<__INTERRUPTOR_COUNT__
-       beq     NoIRQ2
-       lda     #6
-       ldy     IRQInd+1
-       ldx     IRQInd+2
-       jsr     SETVBV
+_exit:  jsr     donelib         ; Run module destructors
 
-; Restore system stuff
+; Restore the system stuff.
 
-NoIRQ2:        ldx     spsave
-       txs                     ; Restore stack pointer
+        ldx     SP_save
+        txs                     ; Restore stack pointer
 
-; Restore left margin
+; Restore the left margin.
 
-       lda     old_lmargin
-       sta     LMARGN
+        lda     LMARGN_save
+        sta     LMARGN
 
-; Restore kb mode
+; Restore the kb mode.
 
-       lda     old_shflok
-       sta     SHFLOK
+        lda     SHFLOK_save
+        sta     SHFLOK
 
-; Restore APPMHI
+; Restore APPMHI.
 
-       lda     appmsav
-       sta     APPMHI
-       lda     appmsav+1
-       sta     APPMHI+1
+        lda     APPMHI_save
+        sta     APPMHI
+        lda     APPMHI_save+1
+        sta     APPMHI+1
 
-; Copy back the zero page stuff
+.ifdef __ATARIXL__
 
-       ldx     #zpspace-1
-L2:    lda     zpsave,x
-       sta     sp,x
-       dex
-       bpl     L2
+; Atari XL target stuff...
 
-; Turn on cursor
+        lda     PORTB_save
+        sta     PORTB
+        lda     RAMTOP_save
+        sta     RAMTOP
+        lda     MEMTOP_save
+        sta     MEMTOP
+        lda     MEMTOP_save+1
+        sta     MEMTOP+1
 
-       inx
-       stx     CRSINH
 
-; Back to DOS
+; Issue a GRAPHICS 0 call (copied'n'pasted from the TGI drivers), in
+; order to restore screen memory to its default location just
+; before the ROM.
 
-       rts
+        jsr     findfreeiocb
 
-; ------------------------------------------------------------------------
-; The IRQ vector jumps here, if condes routines are defined with type 2.
+        ; 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.
 
-IRQStub:
-       cld                             ; Just to be sure
-       jsr     callirq                 ; Call the functions
-       jmp     IRQInd                  ; Jump to the saved IRQ vector
+        lda     #CLOSE
+        sta     ICCOM,x
+        jsr     CIOV_org
 
-; ------------------------------------------------------------------------
-; Data
+.endif
 
-.data
+; Turn on the cursor.
 
-IRQInd: jmp    $0000
+        ldx     #0
+        stx     CRSINH
 
-; *** end of main startup code
+; Back to DOS.
 
-.segment       "ZPSAVE"
+        rts
 
-zpsave: .res   zpspace
+; *** end of main startup code
 
-       .bss
+; ------------------------------------------------------------------------
 
-spsave:                .res    1
-appmsav:       .res    1
-old_shflok:    .res    1
-old_lmargin:   .res    1
+.bss
 
-       .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