2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Startup code for cc65 (C128 version)
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _exit
|
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
|
|
|
.import initlib, donelib
|
|
|
|
.import zerobss
|
|
|
|
.import push0, callmain
|
|
|
|
.import RESTOR, BSOUT, CLRCH
|
|
|
|
.import __RAM_START__, __RAM_SIZE__, __STACKSIZE__
|
|
|
|
.importzp ST
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "c128.inc"
|
2002-11-19 23:02:47 +00:00
|
|
|
|
2001-09-13 15:27:19 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2009-12-09 12:42:24 +00:00
|
|
|
; Startup code
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "STARTUP"
|
2009-12-09 12:42:24 +00:00
|
|
|
|
|
|
|
Start:
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2001-10-26 13:48:49 +00:00
|
|
|
; Switch to the second charset
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #14
|
|
|
|
jsr BSOUT
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2001-10-26 13:48:49 +00:00
|
|
|
; Before doing anything else, we have to setup our banking configuration.
|
|
|
|
; Otherwise just the lowest 16K are actually RAM. Writing through the ROM
|
|
|
|
; to the underlying RAM works, but it is bad style.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda MMU_CR ; Get current memory configuration...
|
|
|
|
pha ; ...and save it for later
|
|
|
|
lda #MMU_CFG_CC65 ; Bank0 with kernal ROM
|
|
|
|
sta MMU_CR
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2001-10-26 13:48:49 +00:00
|
|
|
; 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
|
2001-10-26 13:48:49 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
; Save system stuff and setup the stack
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
pla ; Get MMU setting
|
|
|
|
sta mmusave
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
tsx
|
|
|
|
stx spsave ; Save the system stack pointer
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
|
|
|
sta sp
|
|
|
|
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
|
|
|
sta sp+1 ; Set argument stack ptr
|
2001-09-13 15:27:19 +00:00
|
|
|
|
2008-08-31 18:22:51 +00:00
|
|
|
; Call module constructors
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr initlib
|
2008-08-31 18:22:51 +00:00
|
|
|
|
|
|
|
; Set the bank for the file name to our execution bank. We must do this,
|
|
|
|
; *after* calling constructors, because some of them may depend on the
|
|
|
|
; original value of this register.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
sta FNAM_BANK
|
2008-08-31 18:22:51 +00:00
|
|
|
|
2003-03-10 21:21:46 +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
|
2008-08-31 18:22:51 +00:00
|
|
|
|
|
|
|
; Back from main (this is also the _exit entry). Run module destructors
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
_exit: pha ; Save the return code on stack
|
|
|
|
jsr donelib
|
2001-09-13 15:27:19 +00:00
|
|
|
|
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
|
|
|
|
2004-03-02 17:08:07 +00:00
|
|
|
; Place the program return code into ST
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
pla
|
|
|
|
sta ST
|
2004-03-02 17:08:07 +00:00
|
|
|
|
2004-03-08 20:38:58 +00:00
|
|
|
; Reset the stack and the memory configuration
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx spsave
|
|
|
|
txs
|
|
|
|
ldx mmusave
|
|
|
|
stx MMU_CR
|
2004-03-08 20:38:58 +00:00
|
|
|
|
2012-01-01 19:58:31 +00:00
|
|
|
; Done, return to BASIC
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2001-09-13 15:27:19 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "ZPSAVE"
|
2008-07-03 19:39:14 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
zpsave: .res zpspace
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-02-12 22:39:38 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
.bss
|
2013-02-12 22:39:38 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
spsave: .res 1
|
|
|
|
mmusave:.res 1
|