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
|
2016-03-07 00:28:55 +00:00
|
|
|
.import __MAIN_START__, __MAIN_SIZE__, __STACKSIZE__
|
2013-05-09 11:56:54 +00:00
|
|
|
.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
|
|
|
|
2014-08-23 18:05:36 +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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Before doing anything else, we have to set up 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
|
2014-08-23 18:05:36 +00:00
|
|
|
lda #MMU_CFG_CC65 ; Bank0 with Kernal ROM
|
2013-05-09 11:56:54 +00:00
|
|
|
sta MMU_CR
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Save the zero-page locations that we need.
|
2001-10-26 13:48:49 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
; Save some system stuff; and, set up the stack.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
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
|
|
|
|
2016-03-07 00:28:55 +00:00
|
|
|
lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
|
|
|
|
ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
|
2013-05-09 11:56:54 +00:00
|
|
|
sta sp
|
2016-03-07 00:28:55 +00:00
|
|
|
stx sp+1 ; Set argument stack ptr
|
2001-09-13 15:27:19 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the module constructors.
|
2008-08-31 18:22:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr initlib
|
2008-08-31 18:22:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set the bank for the file name to our execution bank. We must do this
|
|
|
|
; *after* calling the constructors because some of them might depend on
|
|
|
|
; the original value of this register.
|
2008-08-31 18:22:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
sta FNAM_BANK
|
2008-08-31 18:22:51 +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
|
2008-08-31 18:22:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Back from main() [this is also the exit() entry]. Run the 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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Copy back the zero-page stuff.
|
2000-05-28 13:40:48 +00:00
|
|
|
|
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
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Place the program return code into BASIC's status variable.
|
2004-03-02 17:08:07 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
pla
|
|
|
|
sta ST
|
2004-03-02 17:08:07 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Reset the stack and the memory configuration.
|
2004-03-08 20:38:58 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx spsave
|
|
|
|
txs
|
|
|
|
ldx mmusave
|
|
|
|
stx MMU_CR
|
2004-03-08 20:38:58 +00:00
|
|
|
|
2014-08-23 18:05:36 +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
|
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "INIT"
|
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
|