]> git.sur5r.net Git - cc65/blobdiff - libsrc/nes/crt0.s
Create static drivers directly from source files.
[cc65] / libsrc / nes / crt0.s
index cda42852209799ca51ea644b2f7adcde35de99df..68b489dacca3f7fe857d2eb71646fc4cd0c32367 100644 (file)
@@ -3,26 +3,24 @@
 ;
 ; 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:
 
@@ -81,86 +74,51 @@ 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
@@ -217,8 +175,8 @@ irq:
         .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
@@ -226,6 +184,6 @@ irq:
 
 .segment "CHARS"
 
-        .incbin "nes/neschar.bin"
+        .include        "neschar.inc"