X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libsrc%2Fatari%2Fcrt0.s;h=0ea6e390f0f750fbf47032d77fe58aaa55dd1f68;hb=91b9451c60682c0fda984750406d58b1b019f87e;hp=f007e64ad9b3dfdf70f0c28f1fbae1ce24fd7aa4;hpb=85885001b133e2dc320b6f6459259afa69784ca8;p=cc65 diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index f007e64ad..0ea6e390f 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -8,138 +8,182 @@ ; 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__ .import __RESERVED_MEMORY__ + .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" ; ------------------------------------------------------------------------ -; EXE header - -.segment "EXEHDR" - - .word $FFFF - .word __STARTUP_LOAD__ - .word __ZPSAVE_LOAD__ - 1 - -; ------------------------------------------------------------------------ -; Actual code .segment "STARTUP" rts ; fix for SpartaDOS / OS/A+ - ; they first call the entry point from AUTOSTRT and - ; then the load addess (this rts here). + ; 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 -; Setup the stack +; Set up the stack. tsx - stx spsave + stx SP_save -; Report memory usage +.ifdef __ATARIXL__ + + lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) + sta sp + lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) + sta sp+1 + +.else + +; Report the 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 sbc #<__RESERVED_MEMORY__ sta APPMHI ; initialize our APPMHI value - sta sp ; setup runtime stack part 1 + sta sp ; set up runtime stack part 1 lda MEMTOP+1 sbc #>__RESERVED_MEMORY__ sta APPMHI+1 - sta sp+1 ; setup runtime stack part 2 + sta sp+1 ; set up runtime stack part 2 + +.endif -; Call module constructors +; Call the module constructors. jsr initlib -; Set left margin to 0 +; Set the left margin to 0. lda LMARGN - sta old_lmargin + sta LMARGN_save ldy #0 sty LMARGN -; Set keyb to upper/lowercase mode +; Set the keyboard to upper-/lower-case mode. ldx SHFLOK - stx old_shflok + stx SHFLOK_save sty SHFLOK -; Initialize conio stuff +; Initialize the 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 +; Push the command-line arguments; and, call main(). 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 -; Restore system stuff +; Restore the system stuff. - ldx spsave + ldx SP_save txs ; Restore stack pointer -; Restore left margin +; Restore the left margin. - lda old_lmargin + lda LMARGN_save sta LMARGN -; Restore kb mode +; Restore the kb mode. - lda old_shflok + lda SHFLOK_save sta SHFLOK -; Restore APPMHI +; Restore APPMHI. - lda appmsav + lda APPMHI_save sta APPMHI - lda appmsav+1 + lda APPMHI_save+1 sta APPMHI+1 -; Copy back the zero page stuff - - ldx #zpspace-1 -L2: lda zpsave,x - sta sp,x - dex - bpl L2 - -; Turn on cursor - - inx +.ifdef __ATARIXL__ + +; Atari XL target 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 the TGI drivers), in +; order to restore screen memory to its default 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 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 + +.endif + +; Turn on the cursor. + + ldx #0 stx CRSINH -; Back to DOS +; Back to DOS. rts @@ -147,20 +191,11 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ -.segment "ZPSAVE" - -zpsave: .res zpspace - -; ------------------------------------------------------------------------ - .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