2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Startup code for cc65 (ATARI version)
|
|
|
|
;
|
|
|
|
; Contributing authors:
|
|
|
|
; Mark Keates
|
|
|
|
; Freddy Offenga
|
|
|
|
; Christian Groessler
|
|
|
|
;
|
|
|
|
; This must be the *first* file on the linker command line
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _exit
|
2003-08-12 19:59:51 +00:00
|
|
|
.constructor initsp, 26
|
2000-12-03 23:50:16 +00:00
|
|
|
|
2003-08-12 19:59:51 +00:00
|
|
|
.import initlib, donelib, callmain
|
2000-11-23 19:05:32 +00:00
|
|
|
.import zerobss, pushax
|
2003-08-12 19:59:51 +00:00
|
|
|
.import _main, __filetab, getfd
|
2008-07-04 17:32:00 +00:00
|
|
|
.import __LOWCODE_LOAD__, __ZPSAVE_LOAD__
|
2005-08-07 15:48:32 +00:00
|
|
|
.import __RESERVED_MEMORY__
|
2004-12-16 22:43:47 +00:00
|
|
|
.ifdef DYNAMIC_DD
|
|
|
|
.import __getdefdev
|
|
|
|
.endif
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-05-26 09:09:10 +00:00
|
|
|
.include "zeropage.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
.include "atari.inc"
|
2002-04-21 14:19:16 +00:00
|
|
|
.include "_file.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; EXE header
|
|
|
|
|
|
|
|
.segment "EXEHDR"
|
|
|
|
.word $FFFF
|
2005-03-31 21:53:12 +00:00
|
|
|
.word __LOWCODE_LOAD__
|
2008-07-04 17:32:00 +00:00
|
|
|
.word __ZPSAVE_LOAD__ - 1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Actual code
|
|
|
|
|
2005-03-31 21:53:12 +00:00
|
|
|
.segment "LOWCODE"
|
2002-05-26 09:09:10 +00:00
|
|
|
|
2000-05-28 13:40:48 +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.
|
|
|
|
|
|
|
|
; Real entry point:
|
|
|
|
|
|
|
|
; Save the zero page locations we need
|
|
|
|
|
2000-10-30 21:46:45 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L1: lda sp,x
|
|
|
|
sta zpsave,x
|
|
|
|
dex
|
2000-05-28 13:40:48 +00:00
|
|
|
bpl L1
|
|
|
|
|
|
|
|
; Clear the BSS data
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
|
|
|
; setup the stack
|
|
|
|
|
|
|
|
tsx
|
|
|
|
stx spsave
|
|
|
|
|
2000-12-03 23:50:16 +00:00
|
|
|
; report memory usage
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
lda APPMHI
|
2000-12-03 23:50:16 +00:00
|
|
|
sta appmsav ; remember old APPMHI value
|
2000-05-28 13:40:48 +00:00
|
|
|
lda APPMHI+1
|
|
|
|
sta appmsav+1
|
2000-06-25 01:45:30 +00:00
|
|
|
|
2005-08-07 15:48:32 +00:00
|
|
|
sec
|
2000-12-03 23:50:16 +00:00
|
|
|
lda MEMTOP
|
2005-08-07 15:48:32 +00:00
|
|
|
sbc #<__RESERVED_MEMORY__
|
2000-12-03 23:50:16 +00:00
|
|
|
sta APPMHI ; initialize our APPMHI value
|
2005-08-07 15:48:32 +00:00
|
|
|
lda MEMTOP+1
|
|
|
|
sbc #>__RESERVED_MEMORY__
|
|
|
|
sta APPMHI+1
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2000-12-03 21:40:07 +00:00
|
|
|
; Call module constructors
|
|
|
|
|
|
|
|
jsr initlib
|
2004-12-16 22:43:47 +00:00
|
|
|
.ifdef DYNAMIC_DD
|
|
|
|
jsr __getdefdev
|
|
|
|
.endif
|
2000-12-03 21:40:07 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; set left margin to 0
|
|
|
|
|
|
|
|
lda LMARGN
|
|
|
|
sta old_lmargin
|
|
|
|
lda #0
|
|
|
|
sta LMARGN
|
|
|
|
|
|
|
|
; set keyb to upper/lowercase mode
|
|
|
|
|
|
|
|
ldx SHFLOK
|
|
|
|
stx old_shflok
|
|
|
|
sta SHFLOK
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Initialize conio stuff
|
|
|
|
|
|
|
|
lda #$FF
|
|
|
|
sta CH
|
|
|
|
|
2000-05-30 22:21:40 +00:00
|
|
|
; set stdio stream handles
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
lda #0
|
2000-05-30 22:21:40 +00:00
|
|
|
jsr getfd
|
2003-12-03 10:15:33 +00:00
|
|
|
sta __filetab + (0 * .sizeof(_FILE)); setup stdin
|
2000-05-30 22:21:40 +00:00
|
|
|
lda #0
|
|
|
|
jsr getfd
|
2003-12-03 10:15:33 +00:00
|
|
|
sta __filetab + (1 * .sizeof(_FILE)); setup stdout
|
2000-05-30 22:21:40 +00:00
|
|
|
lda #0
|
|
|
|
jsr getfd
|
2003-12-03 10:15:33 +00:00
|
|
|
sta __filetab + (2 * .sizeof(_FILE)); setup stderr
|
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
|
|
|
|
2003-08-12 19:59:51 +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
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
_exit: jsr donelib ; Run module destructors
|
|
|
|
|
|
|
|
; Restore system stuff
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
ldx spsave
|
2000-11-22 22:19:09 +00:00
|
|
|
txs ; Restore stack pointer
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; restore left margin
|
|
|
|
|
|
|
|
lda old_lmargin
|
|
|
|
sta LMARGN
|
|
|
|
|
|
|
|
; restore kb mode
|
|
|
|
|
|
|
|
lda old_shflok
|
|
|
|
sta SHFLOK
|
|
|
|
|
|
|
|
; restore APPMHI
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
lda appmsav
|
|
|
|
sta APPMHI
|
|
|
|
lda appmsav+1
|
|
|
|
sta APPMHI+1
|
|
|
|
|
|
|
|
; Copy back the zero page stuff
|
|
|
|
|
2000-10-30 21:46:45 +00:00
|
|
|
ldx #zpspace-1
|
|
|
|
L2: lda zpsave,x
|
|
|
|
sta sp,x
|
|
|
|
dex
|
2000-05-28 13:40:48 +00:00
|
|
|
bpl L2
|
|
|
|
|
2002-11-05 00:35:16 +00:00
|
|
|
; turn on cursor
|
|
|
|
|
|
|
|
inx
|
|
|
|
stx CRSINH
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Back to DOS
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
2000-06-25 01:45:30 +00:00
|
|
|
; *** end of main startup code
|
|
|
|
|
2000-12-03 23:50:16 +00:00
|
|
|
; setup sp
|
2000-06-25 01:45:30 +00:00
|
|
|
|
2005-02-26 09:38:46 +00:00
|
|
|
.segment "INIT"
|
|
|
|
|
2000-12-09 22:31:07 +00:00
|
|
|
initsp:
|
2000-12-03 23:50:16 +00:00
|
|
|
lda APPMHI
|
|
|
|
sta sp
|
|
|
|
lda APPMHI+1
|
|
|
|
sta sp+1
|
2000-06-25 01:45:30 +00:00
|
|
|
rts
|
|
|
|
|
2008-07-03 19:39:14 +00:00
|
|
|
.segment "ZPSAVE"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
zpsave: .res zpspace
|
2000-06-25 01:45:30 +00:00
|
|
|
|
|
|
|
.bss
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
spsave: .res 1
|
|
|
|
appmsav: .res 1
|
|
|
|
old_shflok: .res 1
|
|
|
|
old_lmargin: .res 1
|
|
|
|
|
|
|
|
.segment "AUTOSTRT"
|
|
|
|
.word $02E0
|
|
|
|
.word $02E1
|
2005-03-31 21:53:12 +00:00
|
|
|
.word __LOWCODE_LOAD__ + 1
|