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+
|
2014-08-23 18:05:36 +00:00
|
|
|
; They first call the entry point from AUTOSTRT; and
|
|
|
|
; then, the load address (this rts here).
|
2013-05-09 11:56:54 +00:00
|
|
|
; 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
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Clear the BSS data.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr zerobss
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set up 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Report the 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
|
2014-08-23 18:05:36 +00:00
|
|
|
sta sp ; set up runtime stack part 1
|
2013-05-09 11:56:54 +00:00
|
|
|
lda MEMTOP+1
|
|
|
|
sbc #>__RESERVED_MEMORY__
|
|
|
|
sta APPMHI+1
|
2014-08-23 18:05:36 +00:00
|
|
|
sta sp+1 ; set up runtime stack part 2
|
2000-09-07 21:49:13 +00:00
|
|
|
|
2013-05-30 00:30:19 +00:00
|
|
|
.endif
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the module constructors.
|
2000-12-03 21:40:07 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr initlib
|
2000-12-03 21:40:07 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the keyboard to upper-/lower-case 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Initialize the conio stuff.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Push the command-line 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Restore the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Restore the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Restore the 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
|
|
|
|
2014-08-23 18:05:36 +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
|
|
|
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; 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.
|
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
|
2014-08-23 18:05:36 +00:00
|
|
|
; No error checking here, shouldn't happen(TM); and, no way to
|
2013-10-01 09:32:08 +00:00
|
|
|
; 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
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Turn on the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Back to DOS.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
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
|