]> git.sur5r.net Git - cc65/blobdiff - libsrc/nes/crt0.s
don't use constructor to setup runtime stack
[cc65] / libsrc / nes / crt0.s
index a4676c7e210e2ebc4bba306eb1dc7e1209cb9f89..373c3b9a3d3888f4b56c7edcd3c96c435c47bf0a 100644 (file)
@@ -3,13 +3,12 @@
 ;
 ; 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
@@ -19,8 +18,7 @@
        .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__
-        
+
         .include        "zeropage.inc"
        .include        "nes.inc"
 
@@ -57,7 +55,7 @@
 ;    | ..-EOF |      | CHR-ROM pages (in ascending order).      |
 ;    +--------+------+------------------------------------------+
 
-        .byte   $4e,$45,$53,$1a        ; "nes\n"
+        .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   0,0,0,0,0,0,0,0 ; 8 zeroes
 
 
-; ------------------------------------------------------------------------
-; Create an empty LOWCODE segment to avoid linker warnings
-
-.segment        "LOWCODE"
-
 ; ------------------------------------------------------------------------
 ; Place the startup code in a special segment.
 
@@ -101,43 +94,8 @@ start:
 
         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:
-
-        ; 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
 
@@ -165,7 +123,7 @@ _exit:  jsr donelib         ; Run module destructors
 ; ------------------------------------------------------------------------
 ; System V-Blank Interupt
 ; updates PPU Memory (buffered)
-; updates VBLANK_FLAG and _tickcount
+; updates VBLANK_FLAG and tickcount
 ; ------------------------------------------------------------------------
 
 nmi:    pha
@@ -177,9 +135,9 @@ nmi:    pha
         lda     #1
         sta     VBLANK_FLAG
 
-        inc     _tickcount
+        inc     tickcount
         bne     @s
-        inc     _tickcount+1
+        inc     tickcount+1
 
 @s:     jsr     ppubuf_flush
 
@@ -226,6 +184,6 @@ irq:
 
 .segment "CHARS"
 
-        .incbin "nes/neschar.bin"
+        .include        "neschar.inc"