1
0
mirror of https://github.com/cc65/cc65.git synced 2024-10-31 04:04:49 +00:00
cc65/libsrc/pce/crt0.s

142 lines
4.2 KiB
ArmAsm
Raw Normal View History

;
; Startup code for cc65 (PCEngine version)
;
; by Groepaz/Hitmen <groepaz@gmx.net>
; based on code by Ullrich von Bassewitz <uz@cc65.org>
;
; This must be the *first* file on the linker command line
;
2015-08-29 13:58:57 +00:00
.export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup
2015-07-12 14:40:52 +00:00
2015-08-29 13:58:57 +00:00
.import initlib, donelib
.import push0, _main, zerobss
.import initheap
2015-09-19 13:55:43 +00:00
.import IRQStub
2015-07-12 14:40:52 +00:00
; Linker generated
2015-08-29 13:58:57 +00:00
.import __RAM_START__, __RAM_SIZE__
.import __ROM0_START__, __ROM0_SIZE__
.import __ROM_START__, __ROM_SIZE__
.import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
.import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
.import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
.import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__
.import __BSS_SIZE__
2015-07-12 14:40:52 +00:00
2015-08-29 13:58:57 +00:00
.include "pce.inc"
2015-09-19 13:37:39 +00:00
.include "extzp.inc"
2015-07-12 14:40:52 +00:00
2015-08-29 13:58:57 +00:00
.importzp sp
.importzp ptr1,ptr2
2015-09-19 13:55:43 +00:00
.importzp tmp1,tmp2,tmp3
; ------------------------------------------------------------------------
; Place the startup code in a special segment.
2015-08-29 13:58:57 +00:00
.segment "STARTUP"
start:
; Set up the CPU and System-IRQ
2015-08-29 13:58:57 +00:00
; Initialize CPU
sei
nop
csh ; Set high speed CPU mode
2015-08-29 13:58:57 +00:00
nop
cld
nop
; Set up stack and memory mapping
2015-08-29 13:58:57 +00:00
ldx #$FF ; Stack top ($21FF)
txs
; At startup all MPRs are set to 0, so init them
2015-08-29 13:58:57 +00:00
lda #$ff
tam #%00000001 ; 0000-1FFF = Hardware page
lda #$F8
tam #%00000010 ; 2000-3FFF = Work RAM
; FIXME: setup a larger block of memory to use with C-code
;lda #$F7
;tam #%00000100 ; 4000-5FFF = Save RAM
;lda #1
;tam #%00001000 ; 6000-7FFF Page 2
;lda #2
;tam #%00010000 ; 8000-9FFF Page 3
;lda #3
;tam #%00100000 ; A000-BFFF Page 4
;lda #4
;tam #%01000000 ; C000-DFFF Page 5
;lda #0
;tam #%10000000 ; e000-fFFF hucard/syscard bank 0
; Clear work RAM (2000-3FFF)
stz <$00
tii $2000, $2001, $1FFF
; Initialize hardware
2015-09-19 13:37:39 +00:00
stz TIMER_CTRL ; Timer off
2015-08-29 13:58:57 +00:00
lda #$07
sta IRQ_MASK ; Interrupts off
stz IRQ_STATUS ; Acknowledge timer
; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/
.import vdc_init
jsr vdc_init
; Turn on background and VD interrupt/IRQ1
lda #$05
sta IRQ_MASK ; IRQ1=on
; Clear the BSS data
jsr zerobss
; Copy the .data segment to RAM
tii __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
; Set up the stack
2015-08-29 13:58:57 +00:00
lda #<(__RAM_START__+__RAM_SIZE__)
ldx #>(__RAM_START__+__RAM_SIZE__)
2015-08-29 13:58:57 +00:00
sta sp
stx sp + 1
2015-08-29 13:58:57 +00:00
; Call module constructors
jsr initlib
2015-08-29 13:58:57 +00:00
cli ; allow IRQ only after constructors have run
2015-07-16 14:54:40 +00:00
2015-08-29 13:58:57 +00:00
; Pass an empty command line
jsr push0 ; argc
jsr push0 ; argv
2015-07-12 08:32:55 +00:00
2015-08-29 13:58:57 +00:00
ldy #4 ; Argument size
jsr _main ; Call the users code
2015-08-29 13:58:57 +00:00
; Call module destructors. This is also the _exit entry.
_exit:
2015-08-29 13:58:57 +00:00
jsr donelib ; Run module destructors
2015-08-29 13:58:57 +00:00
; reset the PCEngine (start over)
jmp start
_nmi:
2015-08-29 13:58:57 +00:00
rti
2015-08-29 13:58:57 +00:00
.export initmainargs
initmainargs:
2015-08-29 13:58:57 +00:00
rts
; ------------------------------------------------------------------------
; hardware vectors
; ------------------------------------------------------------------------
2015-08-29 13:58:57 +00:00
.segment "VECTORS"
2015-09-19 13:55:43 +00:00
.word IRQStub ; $fff6 IRQ2 (External IRQ, BRK)
.word IRQStub ; $fff8 IRQ1 (VDC)
.word IRQStub ; $fffa Timer
2015-08-29 13:58:57 +00:00
.word _nmi ; $fffc NMI
.word start ; $fffe reset