;
; 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
;
.export _exit
- .import initlib, donelib
- .import push0, _main, zerobss
+ .export __STARTUP__ : absolute = 1 ; Mark as startup
+ .import initlib, donelib, callmain
+ .import push0, _main, zerobss, copydata
.import ppubuf_flush
; Linker generated symbols
- .import __RAM_START__, __RAM_SIZE__
- .import __SRAM_START__, __SRAM_SIZE__
- .import __ROM0_START__, __ROM0_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 __RAM_START__, __RAM_SIZE__
+ .import __SRAM_START__, __SRAM_SIZE__
+ .import __ROM0_START__, __ROM0_SIZE__
+ .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
+ .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
+ .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
.include "zeropage.inc"
- .include "nes.inc"
+ .include "nes.inc"
; ------------------------------------------------------------------------
; | ..-EOF | | CHR-ROM pages (in ascending order). |
; +--------+------+------------------------------------------+
- .byte $4e,$45,$53,$1a ; "nes\n"
- .byte 2 ; ines prg - Specifies the number of 16k prg banks.
- .byte 1 ; ines chr - Specifies the number of 8k chr banks.
- .byte %00000011 ; ines mir - Specifies VRAM mirroring of the banks.
- .byte %00000000 ; ines map - Specifies the NES mapper used.
- .byte 0,0,0,0,0,0,0,0 ; 8 zeroes
-
-
-; ------------------------------------------------------------------------
-; Create an empty LOWCODE segment to avoid linker warnings
+ .byte $4e,$45,$53,$1a ; "NES"^Z
+ .byte 2 ; ines prg - Specifies the number of 16k prg banks.
+ .byte 1 ; ines chr - Specifies the number of 8k chr banks.
+ .byte %00000011 ; ines mir - Specifies VRAM mirroring of the banks.
+ .byte %00000000 ; ines map - Specifies the NES mapper used.
+ .byte 0,0,0,0,0,0,0,0 ; 8 zeroes
-.segment "LOWCODE"
; ------------------------------------------------------------------------
; Place the startup code in a special segment.
-.segment "STARTUP"
+.segment "STARTUP"
start:
sei
cld
- ldx #0
- stx VBLANK_FLAG
+ ldx #0
+ stx VBLANK_FLAG
- stx ringread
- stx ringwrite
- stx ringcount
+ stx ringread
+ stx ringwrite
+ stx ringcount
txs
lda #$20
@l: sta ringbuff,x
- sta ringbuff+$0100,x
- sta ringbuff+$0200,x
+ sta ringbuff+$0100,x
+ sta ringbuff+$0200,x
inx
- bne @l
+ bne @l
; Clear the BSS data
- jsr zerobss
-
-; Copy the .data segment to RAM
-
- lda #<(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__)
- sta ptr1
- lda #>(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__)
- sta ptr1+1
- lda #<(__DATA_RUN__)
- sta ptr2
- lda #>(__DATA_RUN__)
- sta ptr2+1
-
- ldx #>(__DATA_SIZE__)
-
-@l2: beq @s1 ; no more full pages
-
- ; copy one page
- ldy #0
-@l1: lda (ptr1),y
- sta (ptr2),y
- iny
- bne @l1
-
- inc ptr1+1
- inc ptr2+1
- dex
- bne @l2
-
- ; copy remaining bytes
-@s1:
+ jsr zerobss
- ; copy one page
- ldy #0
-@l3: lda (ptr1),y
- sta (ptr2),y
- iny
- cpy #<(__DATA_SIZE__)
- bne @l3
+; initialize data
+ jsr copydata
; setup the stack
lda #<(__SRAM_START__ + __SRAM_SIZE__)
- sta sp
- lda #>(__SRAM_START__ + __SRAM_SIZE__)
- sta sp+1 ; Set argument stack ptr
+ sta sp
+ lda #>(__SRAM_START__ + __SRAM_SIZE__)
+ sta sp+1 ; Set argument stack ptr
; Call module constructors
- jsr initlib
+ jsr initlib
; Push arguments and call main()
- jsr callmain
+ jsr callmain
; Call module destructors. This is also the _exit entry.
-_exit: jsr donelib ; Run module destructors
+_exit: jsr donelib ; Run module destructors
; Reset the NES
- jmp start
+ jmp start
; ------------------------------------------------------------------------
; System V-Blank Interupt
.word irq1 ; $fff6 ?
.word timerirq ; $fff8 ?
.word nmi ; $fffa vblank nmi
- .word start ; $fffc reset
- .word irq ; $fffe irq / brk
+ .word start ; $fffc reset
+ .word irq ; $fffe irq / brk
; ------------------------------------------------------------------------
; character data
.segment "CHARS"
- .incbin "nes/neschar.bin"
+ .include "neschar.inc"