2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Startup code for cc65 (ATARI version)
|
|
|
|
;
|
|
|
|
; Contributing authors:
|
2013-05-09 11:56:54 +00:00
|
|
|
; Mark Keates
|
|
|
|
; Freddy Offenga
|
|
|
|
; Christian Groessler
|
|
|
|
; Stefan Haubenthal
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _exit
|
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2000-12-03 23:50:16 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import initlib, donelib
|
|
|
|
.import callmain, zerobss
|
|
|
|
.import __STARTUP_LOAD__, __ZPSAVE_LOAD__
|
|
|
|
.import __RESERVED_MEMORY__
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "atari.inc"
|
2013-05-30 00:30:19 +00:00
|
|
|
.include "save_area.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; EXE header
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "EXEHDR"
|
2013-02-12 22:39:38 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.word $FFFF
|
2013-05-30 00:30:19 +00:00
|
|
|
|
|
|
|
.if .defined(__ATARIXL__)
|
|
|
|
.segment "MAINHDR"
|
|
|
|
.endif
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.word __STARTUP_LOAD__
|
|
|
|
.word __ZPSAVE_LOAD__ - 1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Actual code
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "STARTUP"
|
2002-05-26 09:09:10 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
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.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Real entry point:
|
|
|
|
|
|
|
|
; Save the zero page locations we need
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L1: lda sp,x
|
|
|
|
sta zpsave,x
|
|
|
|
dex
|
|
|
|
bpl L1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Clear the BSS data
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr zerobss
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Setup the stack
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
tsx
|
|
|
|
stx spsave
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-30 00:30:19 +00:00
|
|
|
.if .not .defined(__ATARIXL__)
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Report memory usage
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda APPMHI
|
|
|
|
sta appmsav ; remember old APPMHI value
|
|
|
|
lda APPMHI+1
|
|
|
|
sta appmsav+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
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2013-05-30 00:30:19 +00:00
|
|
|
.else
|
|
|
|
|
|
|
|
; for now... needs to use value from linker script later
|
|
|
|
lda MEMTOP
|
|
|
|
sta sp
|
|
|
|
lda MEMTOP+1
|
|
|
|
sta sp+1
|
|
|
|
|
|
|
|
.endif
|
|
|
|
|
2000-12-03 21:40:07 +00:00
|
|
|
; Call module constructors
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr initlib
|
2000-12-03 21:40:07 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Set left margin to 0
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda LMARGN
|
|
|
|
sta old_lmargin
|
|
|
|
ldy #0
|
|
|
|
sty LMARGN
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Set keyb to upper/lowercase mode
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx SHFLOK
|
|
|
|
stx old_shflok
|
|
|
|
sty SHFLOK
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Initialize conio stuff
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
dey ; Set X to $FF
|
|
|
|
sty CH
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2003-08-12 19:59:51 +00:00
|
|
|
; Push arguments and call main
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr callmain
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
; Call module destructors. This is also the _exit entry.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
_exit: jsr donelib ; Run module destructors
|
2000-11-22 22:19:09 +00:00
|
|
|
|
|
|
|
; Restore system stuff
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx spsave
|
|
|
|
txs ; Restore stack pointer
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Restore left margin
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda old_lmargin
|
|
|
|
sta LMARGN
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Restore kb mode
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda old_shflok
|
|
|
|
sta SHFLOK
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-30 00:30:19 +00:00
|
|
|
.if .not .defined(__ATARIXL__)
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Restore APPMHI
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda appmsav
|
|
|
|
sta APPMHI
|
|
|
|
lda appmsav+1
|
|
|
|
sta APPMHI+1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-30 00:30:19 +00:00
|
|
|
.else
|
|
|
|
|
|
|
|
; Atari XL target stuff...
|
|
|
|
|
|
|
|
lda PORTB_save
|
|
|
|
sta PORTB
|
|
|
|
lda MEMTOP_save
|
|
|
|
sta MEMTOP
|
|
|
|
lda MEMTOP_save+1
|
|
|
|
sta MEMTOP+1
|
|
|
|
lda APPMHI_save
|
|
|
|
sta APPMHI
|
|
|
|
lda APPMHI_save+1
|
|
|
|
sta APPMHI+1
|
|
|
|
.endif
|
|
|
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Copy back the zero page stuff
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L2: lda zpsave,x
|
|
|
|
sta sp,x
|
|
|
|
dex
|
|
|
|
bpl L2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Turn on cursor
|
2002-11-05 00:35:16 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
inx
|
|
|
|
stx CRSINH
|
2002-11-05 00:35:16 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Back to DOS
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
; *** end of main startup code
|
2011-06-13 16:42:45 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2000-06-25 01:45:30 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "ZPSAVE"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
zpsave: .res zpspace
|
2000-06-25 01:45:30 +00:00
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
spsave: .res 1
|
|
|
|
appmsav: .res 1
|
|
|
|
old_shflok: .res 1
|
|
|
|
old_lmargin: .res 1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "AUTOSTRT"
|
|
|
|
.word RUNAD ; defined in atari.h
|
|
|
|
.word RUNAD+1
|
|
|
|
.word __STARTUP_LOAD__ + 1
|