1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-05 08:05:51 +00:00
cc65/libsrc/atari/crt0.s

202 lines
4.4 KiB
ArmAsm
Raw Normal View History

;
; Startup code for cc65 (ATARI version)
;
; Contributing authors:
; Mark Keates
; Freddy Offenga
; Christian Groessler
; Stefan Haubenthal
;
.export __STARTUP__ : absolute = 1 ; Mark as startup
2013-10-18 01:07:01 +00:00
.export _exit, start
.import initlib, donelib
.import callmain, zerobss
.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"
; ------------------------------------------------------------------------
.segment "STARTUP"
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:
start:
.ifdef __ATARIXL__
jsr sram_init
.endif
; Clear the BSS data.
jsr zerobss
; Set up the stack.
tsx
2013-09-19 20:40:20 +00:00
stx SP_save
.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 APPMHI_save ; remember old APPMHI value
lda APPMHI+1
sta APPMHI_save+1
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
.endif
; Call the module constructors.
jsr initlib
; Set the left margin to 0.
lda LMARGN
2013-09-19 20:40:20 +00:00
sta LMARGN_save
ldy #0
sty LMARGN
; Set the keyboard to upper-/lower-case mode.
ldx SHFLOK
2013-09-19 20:40:20 +00:00
stx SHFLOK_save
sty SHFLOK
; Initialize the conio stuff.
2014-03-07 22:10:22 +00:00
dey ; Set Y to $FF
sty CH ; remove keypress which might be in the input buffer
; Push the command-line arguments; and, call main().
jsr callmain
; Call the module destructors. This is also the exit() entry.
_exit: jsr donelib ; Run module destructors
; Restore the system stuff.
2013-09-19 20:40:20 +00:00
ldx SP_save
txs ; Restore stack pointer
; Restore the left margin.
2013-09-19 20:40:20 +00:00
lda LMARGN_save
sta LMARGN
; Restore the kb mode.
2013-09-19 20:40:20 +00:00
lda SHFLOK_save
sta SHFLOK
; Restore APPMHI.
lda APPMHI_save
sta APPMHI
lda APPMHI_save+1
sta APPMHI+1
.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
2013-10-01 09:32:08 +00:00
; 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
2013-10-01 09:32:08 +00:00
; recover anyway.
lda #CLOSE
sta ICCOM,x
jsr CIOV_org
.endif
; Turn on the cursor.
ldx #0
stx CRSINH
; Back to DOS.
rts
; *** end of main startup code
; ------------------------------------------------------------------------
.bss
2013-09-19 20:40:20 +00:00
SP_save: .res 1
SHFLOK_save: .res 1
2013-09-19 20:40:20 +00:00
LMARGN_save: .res 1
.ifndef __ATARIXL__
APPMHI_save: .res 2
.endif