2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Startup code for cc65 (ATARI version)
|
|
|
|
;
|
|
|
|
; Contributing authors:
|
|
|
|
; Mark Keates
|
|
|
|
; Freddy Offenga
|
|
|
|
; Christian Groessler
|
2011-06-13 16:42:45 +00:00
|
|
|
; Stefan Haubenthal
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
.export _exit
|
2011-06-13 16:42:45 +00:00
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2000-12-03 23:50:16 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
.import initlib, donelib
|
|
|
|
.import callmain, zerobss, callirq
|
|
|
|
.import __INTERRUPTOR_COUNT__
|
2009-08-04 20:04:41 +00:00
|
|
|
.import __STARTUP_LOAD__, __ZPSAVE_LOAD__
|
2005-08-07 15:48:32 +00:00
|
|
|
.import __RESERVED_MEMORY__
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
.include "zeropage.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
.include "atari.inc"
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; EXE header
|
|
|
|
|
|
|
|
.segment "EXEHDR"
|
|
|
|
.word $FFFF
|
2009-08-04 20:04:41 +00:00
|
|
|
.word __STARTUP_LOAD__
|
2008-07-04 17:32:00 +00:00
|
|
|
.word __ZPSAVE_LOAD__ - 1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Actual code
|
|
|
|
|
2009-08-04 20:04:41 +00:00
|
|
|
.segment "STARTUP"
|
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
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
ldx #zpspace-1
|
2000-10-30 21:46:45 +00:00
|
|
|
L1: lda sp,x
|
|
|
|
sta zpsave,x
|
|
|
|
dex
|
2000-05-28 13:40:48 +00:00
|
|
|
bpl L1
|
|
|
|
|
|
|
|
; Clear the BSS data
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Setup the stack
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
tsx
|
|
|
|
stx spsave
|
|
|
|
|
2011-06-13 16:42:45 +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
|
2009-11-23 22:06:32 +00:00
|
|
|
sta sp ; setup runtime stack part 1
|
2005-08-07 15:48:32 +00:00
|
|
|
lda MEMTOP+1
|
|
|
|
sbc #>__RESERVED_MEMORY__
|
|
|
|
sta APPMHI+1
|
2009-11-23 22:06:32 +00:00
|
|
|
sta sp+1 ; setup runtime stack part 2
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; If we have IRQ functions, chain our stub into the IRQ vector
|
|
|
|
|
|
|
|
lda #<__INTERRUPTOR_COUNT__
|
|
|
|
beq NoIRQ1
|
|
|
|
lda VVBLKI
|
|
|
|
ldx VVBLKI+1
|
|
|
|
sta IRQInd+1
|
|
|
|
stx IRQInd+2
|
|
|
|
lda #6
|
|
|
|
ldy #<IRQStub
|
|
|
|
ldx #>IRQStub
|
|
|
|
jsr SETVBV
|
|
|
|
|
2000-12-03 21:40:07 +00:00
|
|
|
; Call module constructors
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
NoIRQ1: 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
|
|
|
|
|
|
|
lda LMARGN
|
|
|
|
sta old_lmargin
|
2009-11-23 21:17:56 +00:00
|
|
|
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
|
|
|
|
|
|
|
ldx SHFLOK
|
|
|
|
stx old_shflok
|
2009-11-23 21:17:56 +00:00
|
|
|
sty SHFLOK
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Initialize conio stuff
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
dey ; Set X to $FF
|
2009-11-23 21:17:56 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Reset the IRQ vector if we chained it.
|
|
|
|
|
|
|
|
pha ; Save the return code on stack
|
|
|
|
lda #<__INTERRUPTOR_COUNT__
|
|
|
|
beq NoIRQ2
|
|
|
|
lda #6
|
|
|
|
ldy IRQInd+1
|
|
|
|
ldx IRQInd+2
|
|
|
|
jsr SETVBV
|
|
|
|
|
2000-11-22 22:19:09 +00:00
|
|
|
; Restore system stuff
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
NoIRQ2: 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
|
|
|
|
|
|
|
lda old_lmargin
|
|
|
|
sta LMARGN
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Restore kb mode
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
lda old_shflok
|
|
|
|
sta SHFLOK
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; 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
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Turn on cursor
|
2002-11-05 00:35:16 +00:00
|
|
|
|
|
|
|
inx
|
|
|
|
stx CRSINH
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Back to DOS
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; The IRQ vector jumps here, if condes routines are defined with type 2.
|
|
|
|
|
|
|
|
IRQStub:
|
|
|
|
cld ; Just to be sure
|
|
|
|
jsr callirq ; Call the functions
|
|
|
|
jmp IRQInd ; Jump to the saved IRQ vector
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
IRQInd: jmp $0000
|
|
|
|
|
2000-06-25 01:45:30 +00:00
|
|
|
; *** end of main startup code
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
.segment "ZPSAVE"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +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"
|
2009-08-04 20:04:41 +00:00
|
|
|
.word RUNAD ; defined in atari.h
|
2009-04-29 21:37:10 +00:00
|
|
|
.word RUNAD+1
|
2009-08-04 20:04:41 +00:00
|
|
|
.word __STARTUP_LOAD__ + 1
|