2015-11-22 18:02:47 +00:00
|
|
|
|
2015-11-29 15:01:36 +00:00
|
|
|
.export Start, _exit
|
2015-11-22 18:02:47 +00:00
|
|
|
|
2015-11-29 00:14:59 +00:00
|
|
|
.import initlib, donelib, callmain
|
|
|
|
.import push0, _main, zerobss, copydata
|
2015-11-22 18:02:47 +00:00
|
|
|
|
2015-11-29 00:14:59 +00:00
|
|
|
; Linker generated symbols
|
|
|
|
.import __RAM_START__, __RAM_SIZE__
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "gamate.inc"
|
2015-11-22 18:02:47 +00:00
|
|
|
|
2015-11-29 15:01:36 +00:00
|
|
|
Start:
|
2015-11-29 00:14:59 +00:00
|
|
|
; setup the CPU and System-IRQ
|
|
|
|
|
|
|
|
; Initialize CPU
|
|
|
|
sei
|
|
|
|
cld
|
|
|
|
|
2015-11-29 19:04:10 +00:00
|
|
|
ldx #0
|
|
|
|
stx ZP_IRQ_CTRL ; disable calling cartridge IRQ/NMI handler
|
|
|
|
|
2016-03-07 00:44:19 +00:00
|
|
|
; Set up stack and memory mapping
|
2015-11-29 19:04:10 +00:00
|
|
|
;ldx #$FF ; Stack top ($01FF)
|
|
|
|
dex
|
2015-11-29 00:14:59 +00:00
|
|
|
txs
|
|
|
|
|
|
|
|
; Clear the BSS data
|
|
|
|
jsr zerobss
|
|
|
|
|
|
|
|
; Copy the .data segment to RAM
|
|
|
|
jsr copydata
|
|
|
|
|
2016-03-07 00:44:19 +00:00
|
|
|
; Set up the stack
|
2015-11-29 00:14:59 +00:00
|
|
|
lda #<(__RAM_START__+__RAM_SIZE__)
|
2016-03-07 00:28:55 +00:00
|
|
|
ldx #>(__RAM_START__+__RAM_SIZE__)
|
2015-11-29 00:14:59 +00:00
|
|
|
sta sp
|
2016-03-07 00:28:55 +00:00
|
|
|
stx sp + 1
|
2015-11-29 00:14:59 +00:00
|
|
|
|
|
|
|
; Call module constructors
|
|
|
|
jsr initlib
|
|
|
|
|
2015-11-29 19:04:10 +00:00
|
|
|
lda #1
|
|
|
|
sta ZP_IRQ_CTRL ; enable calling cartridge IRQ/NMI handler
|
2016-03-07 00:28:55 +00:00
|
|
|
cli ; allow IRQ only after constructors have run
|
2015-11-29 00:14:59 +00:00
|
|
|
|
|
|
|
; Pass an empty command line
|
|
|
|
jsr push0 ; argc
|
|
|
|
jsr push0 ; argv
|
|
|
|
|
|
|
|
ldy #4 ; Argument size
|
|
|
|
jsr _main ; call the users code
|
|
|
|
|
|
|
|
; Call module destructors. This is also the _exit entry.
|
|
|
|
_exit:
|
|
|
|
jsr donelib ; Run module destructors
|
|
|
|
|
|
|
|
; reset (start over)
|
2015-11-29 15:01:36 +00:00
|
|
|
jmp Start
|
2015-11-22 18:02:47 +00:00
|
|
|
|
2015-11-29 00:14:59 +00:00
|
|
|
.export initmainargs
|
|
|
|
initmainargs:
|
|
|
|
rts
|