2004-10-08 18:14:19 +00:00
|
|
|
; ***
|
|
|
|
; CC65 Lynx Library
|
|
|
|
;
|
|
|
|
; Originally by Bastian Schick
|
|
|
|
; http://www.geocities.com/SiliconValley/Byte/4242/lynx/
|
|
|
|
;
|
|
|
|
; Ported to cc65 (http://www.cc65.org) by
|
|
|
|
; Shawn Jefferson, June 2004
|
|
|
|
;
|
|
|
|
; ***
|
|
|
|
;
|
|
|
|
; Startup code for cc65 (Lynx version). Based on Atari 8-bit startup
|
|
|
|
; code structure. The C stack is located at the end of the RAM memory
|
|
|
|
; segment and grows downward. Bastian Schick's executable header is put
|
|
|
|
; on the front of the fully linked binary (see EXEHDR segment.)
|
|
|
|
;
|
|
|
|
|
|
|
|
.include "lynx.inc"
|
|
|
|
.export _exit
|
2009-07-31 12:05:42 +00:00
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2004-10-08 18:14:19 +00:00
|
|
|
|
2009-09-11 13:56:20 +00:00
|
|
|
.import callirq, initlib, donelib
|
2004-10-08 18:14:19 +00:00
|
|
|
.import zerobss
|
|
|
|
.import callmain
|
|
|
|
.import _main
|
2004-10-14 16:50:13 +00:00
|
|
|
.import __BSS_LOAD__
|
2009-09-11 13:56:20 +00:00
|
|
|
.import __INTERRUPTOR_COUNT__
|
2010-10-02 10:37:20 +00:00
|
|
|
.import __RAM_START__, __RAM_SIZE__, __STACKSIZE__
|
2004-10-08 18:14:19 +00:00
|
|
|
|
|
|
|
.include "zeropage.inc"
|
2004-11-06 13:51:02 +00:00
|
|
|
.include "extzp.inc"
|
2004-10-08 18:14:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; EXE header (BLL header)
|
|
|
|
|
|
|
|
.segment "EXEHDR"
|
|
|
|
.word $0880
|
2004-10-14 16:50:13 +00:00
|
|
|
.dbyt __RAM_START__
|
2005-05-02 08:09:36 +00:00
|
|
|
.dbyt __BSS_LOAD__ - __RAM_START__ + 10
|
2004-10-08 18:14:19 +00:00
|
|
|
.byte $42,$53
|
|
|
|
.byte $39,$33
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Mikey and Suzy init data, reg offsets and data
|
|
|
|
|
|
|
|
.rodata
|
|
|
|
|
|
|
|
SuzyInitReg: .byte $28,$2a,$04,$06,$92,$83,$90
|
|
|
|
SuzyInitData: .byte $7f,$7f,$00,$00,$24,$f3,$01
|
|
|
|
|
|
|
|
MikeyInitReg: .byte $00,$01,$08,$09,$20,$28,$30,$38,$44,$50,$8a,$8b,$8c,$92,$93
|
|
|
|
MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$29
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Actual code
|
|
|
|
|
2004-10-08 18:52:22 +00:00
|
|
|
.segment "STARTUP"
|
2004-10-08 18:14:19 +00:00
|
|
|
|
|
|
|
; set up system
|
|
|
|
|
|
|
|
sei
|
|
|
|
cld
|
|
|
|
ldx #$FF
|
|
|
|
txs
|
|
|
|
|
|
|
|
; init bank switching
|
|
|
|
|
|
|
|
lda #$C
|
|
|
|
sta MAPCTL ; $FFF9
|
|
|
|
|
|
|
|
; disable all timer interrupts
|
|
|
|
|
|
|
|
lda #$80
|
|
|
|
trb TIM0CTLA
|
|
|
|
trb TIM1CTLA
|
|
|
|
trb TIM2CTLA
|
|
|
|
trb TIM3CTLA
|
|
|
|
trb TIM5CTLA
|
|
|
|
trb TIM6CTLA
|
|
|
|
trb TIM7CTLA
|
|
|
|
|
|
|
|
; disable TX/RX IRQ, set to 8E1
|
|
|
|
|
|
|
|
lda #%11101
|
|
|
|
sta SERCTL
|
|
|
|
|
|
|
|
; clear all pending interrupts
|
|
|
|
|
|
|
|
lda INTSET
|
|
|
|
sta INTRST
|
|
|
|
|
|
|
|
; setup the stack
|
|
|
|
|
2010-10-02 10:37:20 +00:00
|
|
|
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
2004-10-08 18:14:19 +00:00
|
|
|
sta sp
|
2010-10-02 10:37:20 +00:00
|
|
|
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
|
2004-10-08 18:14:19 +00:00
|
|
|
sta sp+1
|
|
|
|
|
|
|
|
; Init Mickey
|
|
|
|
|
|
|
|
ldx #.sizeof(MikeyInitReg)-1
|
|
|
|
mloop: ldy MikeyInitReg,x
|
|
|
|
lda MikeyInitData,x
|
|
|
|
sta $fd00,y
|
|
|
|
dex
|
|
|
|
bpl mloop
|
|
|
|
|
|
|
|
; these are RAM-shadows of read only regs
|
|
|
|
|
|
|
|
ldx #$1b
|
|
|
|
stx __iodat
|
|
|
|
dex ; $1A
|
|
|
|
stx __iodir
|
|
|
|
ldx #$d
|
|
|
|
stx __viddma
|
|
|
|
|
|
|
|
; Init Suzy
|
|
|
|
|
|
|
|
ldx #.sizeof(SuzyInitReg)-1
|
|
|
|
sloop: ldy SuzyInitReg,x
|
|
|
|
lda SuzyInitData,x
|
|
|
|
sta $fc00,y
|
|
|
|
dex
|
|
|
|
bpl sloop
|
|
|
|
|
|
|
|
lda #$24
|
|
|
|
sta __sprsys
|
|
|
|
|
|
|
|
; Clear the BSS data
|
|
|
|
|
|
|
|
jsr zerobss
|
|
|
|
|
2009-09-11 13:56:20 +00:00
|
|
|
; If we have IRQ functions, set the IRQ vector
|
|
|
|
; as Lynx is a console there is not much point in releasing the IRQ
|
|
|
|
|
|
|
|
lda #<__INTERRUPTOR_COUNT__
|
|
|
|
beq NoIRQ1
|
|
|
|
lda #<IRQStub
|
|
|
|
ldx #>IRQStub
|
|
|
|
sei
|
|
|
|
sta INTVECTL
|
|
|
|
stx INTVECTH
|
|
|
|
cli
|
|
|
|
|
2004-10-08 18:14:19 +00:00
|
|
|
; Call module constructors
|
|
|
|
|
2009-09-11 13:56:20 +00:00
|
|
|
NoIRQ1: jsr initlib
|
2004-10-08 18:14:19 +00:00
|
|
|
|
|
|
|
; Push arguments and call main
|
|
|
|
|
|
|
|
jsr callmain
|
|
|
|
|
|
|
|
; Call module destructors. This is also the _exit entry.
|
|
|
|
|
|
|
|
_exit: jsr donelib ; Run module destructors
|
|
|
|
|
|
|
|
; Endless loop
|
|
|
|
|
|
|
|
noret: bra noret
|
|
|
|
|
|
|
|
|
2009-09-17 09:32:05 +00:00
|
|
|
.segment "CODE"
|
2009-09-11 13:56:20 +00:00
|
|
|
IRQStub:
|
|
|
|
phy
|
|
|
|
phx
|
|
|
|
pha
|
|
|
|
cld
|
|
|
|
jsr callirq
|
2009-09-13 13:37:44 +00:00
|
|
|
lda INTSET
|
|
|
|
sta INTRST
|
2009-09-11 13:56:20 +00:00
|
|
|
pla
|
|
|
|
plx
|
|
|
|
ply
|
|
|
|
rti
|
|
|
|
|