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 __STARTUP__ : absolute = 1 ; Mark as startup
|
2013-10-18 01:07:01 +00:00
|
|
|
.export _exit, start
|
2000-12-03 23:50:16 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import initlib, donelib
|
|
|
|
.import callmain, zerobss
|
|
|
|
.import __RESERVED_MEMORY__
|
2013-07-03 09:38:28 +00:00
|
|
|
.import __RAM_START__, __RAM_SIZE__
|
2013-09-19 20:36:22 +00:00
|
|
|
.ifdef __ATARIXL__
|
2013-09-17 21:03:33 +00:00
|
|
|
.import __STACKSIZE__
|
2013-07-03 09:38:28 +00:00
|
|
|
.import sram_init
|
|
|
|
.import scrdev
|
|
|
|
.import findfreeiocb
|
2013-10-18 20:07:05 +00:00
|
|
|
.forceimport sramprep ; force inclusion of the "shadow RAM preparation" load chunk
|
2013-07-03 09:38:28 +00:00
|
|
|
.include "save_area.inc"
|
2013-06-12 23:17:53 +00:00
|
|
|
.endif
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "atari.inc"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
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:
|
|
|
|
|
2013-09-13 16:28:17 +00:00
|
|
|
start:
|
|
|
|
|
2013-09-19 20:36:22 +00:00
|
|
|
.ifdef __ATARIXL__
|
2013-07-03 09:38:28 +00:00
|
|
|
jsr sram_init
|
2013-05-30 23:47:25 +00:00
|
|
|
.endif
|
|
|
|
|
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
|
2013-09-19 20:40:20 +00:00
|
|
|
stx SP_save
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2014-06-03 16:30:11 +00:00
|
|
|
.ifdef __ATARIXL__
|
|
|
|
|
|
|
|
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
|
|
|
sta sp
|
|
|
|
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
|
|
|
sta sp+1
|
|
|
|
|
|
|
|
.else
|
2013-05-30 00:30:19 +00:00
|
|
|
|
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
|
2013-07-03 09:38:28 +00:00
|
|
|
sta APPMHI_save ; remember old APPMHI value
|
2013-05-09 11:56:54 +00:00
|
|
|
lda APPMHI+1
|
2013-07-03 09:38:28 +00:00
|
|
|
sta APPMHI_save+1
|
2013-05-09 11:56:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
.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
|
2013-09-19 20:40:20 +00:00
|
|
|
sta LMARGN_save
|
2013-05-09 11:56:54 +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
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx SHFLOK
|
2013-09-19 20:40:20 +00:00
|
|
|
stx SHFLOK_save
|
2013-05-09 11:56:54 +00:00
|
|
|
sty SHFLOK
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; Initialize 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
|
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-09-19 20:40:20 +00:00
|
|
|
ldx SP_save
|
2013-05-09 11:56:54 +00:00
|
|
|
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-09-19 20:40:20 +00:00
|
|
|
lda LMARGN_save
|
2013-05-09 11:56:54 +00:00
|
|
|
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-09-19 20:40:20 +00:00
|
|
|
lda SHFLOK_save
|
2013-05-09 11:56:54 +00:00
|
|
|
sta SHFLOK
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Restore APPMHI
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2013-07-03 09:38:28 +00:00
|
|
|
lda APPMHI_save
|
2013-05-09 11:56:54 +00:00
|
|
|
sta APPMHI
|
2013-07-03 09:38:28 +00:00
|
|
|
lda APPMHI_save+1
|
2013-05-09 11:56:54 +00:00
|
|
|
sta APPMHI+1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-09-19 20:36:22 +00:00
|
|
|
.ifdef __ATARIXL__
|
2013-05-30 00:30:19 +00:00
|
|
|
|
|
|
|
; Atari XL target stuff...
|
|
|
|
|
2013-07-03 09:38:28 +00:00
|
|
|
lda PORTB_save
|
|
|
|
sta PORTB
|
|
|
|
lda RAMTOP_save
|
|
|
|
sta RAMTOP
|
|
|
|
lda MEMTOP_save
|
|
|
|
sta MEMTOP
|
|
|
|
lda MEMTOP_save+1
|
|
|
|
sta MEMTOP+1
|
2013-06-12 23:17:53 +00:00
|
|
|
|
|
|
|
|
2013-10-01 09:32:08 +00:00
|
|
|
; Issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) in
|
|
|
|
; order to restore screen memory to its defailt location just
|
|
|
|
; before the ROM.
|
2013-06-12 23:17:53 +00:00
|
|
|
|
2013-07-03 09:38:28 +00:00
|
|
|
jsr findfreeiocb
|
2013-06-12 23:17:53 +00:00
|
|
|
|
|
|
|
; 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
|
2013-10-01 09:32:08 +00:00
|
|
|
; No error checking here, shouldn't happen(tm), and no way to
|
|
|
|
; recover anyway.
|
|
|
|
|
2013-06-24 23:27:47 +00:00
|
|
|
lda #CLOSE
|
|
|
|
sta ICCOM,x
|
|
|
|
jsr CIOV_org
|
2013-06-12 23:17:53 +00:00
|
|
|
|
2013-05-30 00:30:19 +00:00
|
|
|
.endif
|
|
|
|
|
2011-06-13 16:42:45 +00:00
|
|
|
; Turn on cursor
|
2002-11-05 00:35:16 +00:00
|
|
|
|
2013-07-02 17:55:00 +00:00
|
|
|
ldx #0
|
2013-05-09 11:56:54 +00:00
|
|
|
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-02-12 22:39:38 +00:00
|
|
|
.bss
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-09-19 20:40:20 +00:00
|
|
|
SP_save: .res 1
|
2013-09-19 21:21:09 +00:00
|
|
|
SHFLOK_save: .res 1
|
2013-09-19 20:40:20 +00:00
|
|
|
LMARGN_save: .res 1
|
2013-09-19 20:36:22 +00:00
|
|
|
.ifndef __ATARIXL__
|
2013-07-03 09:38:28 +00:00
|
|
|
APPMHI_save: .res 2
|
2013-06-24 22:53:21 +00:00
|
|
|
.endif
|