X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libsrc%2Fatari%2Fcrt0.s;h=317fe56978c9dce213aa3aa8a88701f4bb548d2a;hb=d8c31cf1d3b724b83bd411736472e1c16fb1b0c0;hp=bb2c6b493a5bfcb0091e22e197cc03f9b046188e;hpb=e64672acc702ed16deba2a812913f30fdcdec016;p=cc65 diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index bb2c6b493..317fe5697 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -2,190 +2,200 @@ ; Startup code for cc65 (ATARI version) ; ; Contributing authors: -; Mark Keates -; Freddy Offenga -; Christian Groessler +; Mark Keates +; Freddy Offenga +; Christian Groessler +; Stefan Haubenthal ; -; This must be the *first* file on the linker command line -; - - .export _exit - .constructor initsp, 26 - .import initlib, donelib, callmain - .import zerobss, pushax - .import _main, __filetab, getfd - .import __LOWCODE_LOAD__, __ZPSAVE_LOAD__ - .import __RESERVED_MEMORY__ -.ifdef DYNAMIC_DD - .import __getdefdev + .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" - .include "_file.inc" + .include "atari.inc" ; ------------------------------------------------------------------------ -; EXE header - .segment "EXEHDR" - .word $FFFF - .word __LOWCODE_LOAD__ - .word __ZPSAVE_LOAD__ - 1 +.segment "STARTUP" -; ------------------------------------------------------------------------ -; Actual code + 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. - .segment "LOWCODE" +; Real entry point: - 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. +start: -; Real entry point: +.ifdef __ATARIXL__ + jsr sram_init +.endif -; Save the zero page locations we need +; Clear the BSS data. - ldx #zpspace-1 -L1: lda sp,x - sta zpsave,x - dex - bpl L1 + jsr zerobss -; Clear the BSS data +; Set up the stack. - jsr zerobss + tsx + stx SP_save -; setup the stack +.ifdef __ATARIXL__ - tsx - stx spsave + lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) + ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) + sta sp + stx sp+1 -; report memory usage +.else - lda APPMHI - sta appmsav ; remember old APPMHI value - lda APPMHI+1 - sta appmsav+1 +; Report the memory usage. - sec - lda MEMTOP - sbc #<__RESERVED_MEMORY__ - sta APPMHI ; initialize our APPMHI value - lda MEMTOP+1 - sbc #>__RESERVED_MEMORY__ - sta APPMHI+1 + 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 - jsr initlib -.ifdef DYNAMIC_DD - jsr __getdefdev .endif -; set left margin to 0 +; Call the module constructors. - lda LMARGN - sta old_lmargin - lda #0 - sta LMARGN + jsr initlib -; set keyb to upper/lowercase mode +; Set the left margin to 0. - ldx SHFLOK - stx old_shflok - sta SHFLOK + lda LMARGN + sta LMARGN_save + ldy #0 + sty LMARGN -; Initialize conio stuff +; Set the keyboard to upper-/lower-case mode. - lda #$FF - sta CH + ldx SHFLOK + stx SHFLOK_save + sty SHFLOK -; set stdio stream handles +; Initialize the conio stuff. - lda #0 - jsr getfd - sta __filetab + (0 * .sizeof(_FILE)); setup stdin - lda #0 - jsr getfd - sta __filetab + (1 * .sizeof(_FILE)); setup stdout - lda #0 - jsr getfd - sta __filetab + (2 * .sizeof(_FILE)); setup stderr + dey ; Set Y to $FF + sty CH ; remove keypress which might be in the input buffer -; Push arguments and call main +; Push the command-line arguments; and, call main(). - jsr callmain + jsr callmain -; Call module destructors. This is also the _exit entry. +; Call the module destructors. This is also the exit() entry. -_exit: jsr donelib ; Run module destructors +_exit: jsr donelib ; Run module destructors -; Restore system stuff +; Restore the system stuff. - 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 -; *** end of main startup code + ; Reopen it in Graphics 0 + lda #OPEN + sta ICCOM,x + lda #OPNIN | OPNOT + sta ICAX1,x + lda #0 + sta ICAX2,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. -; setup sp + lda #CLOSE + sta ICCOM,x + jsr CIOV_org -.segment "INIT" +.endif + +; Turn on the cursor. + + ldx #0 + stx CRSINH -initsp: - lda APPMHI - sta sp - lda APPMHI+1 - sta sp+1 - rts +; 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 $02E0 - .word $02E1 - .word __LOWCODE_LOAD__ + 1 +SP_save: .res 1 +SHFLOK_save: .res 1 +LMARGN_save: .res 1 +.ifndef __ATARIXL__ +APPMHI_save: .res 2 +.endif