2 ; Startup code for cc65 (NES version)
4 ; by Groepaz/Hitmen <groepaz@gmx.net>
5 ; based on code by Ullrich von Bassewitz <uz@cc65.org>
7 ; This must be the *first* file on the linker command line
11 .import initlib, donelib, callmain
12 .import push0, _main, zerobss, copydata
15 ; Linker generated symbols
16 .import __RAM_START__, __RAM_SIZE__
17 .import __SRAM_START__, __SRAM_SIZE__
18 .import __ROM0_START__, __ROM0_SIZE__
19 .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
20 .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
21 .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
23 .include "zeropage.inc"
27 ; ------------------------------------------------------------------------
28 ; 16 bytes INES header
32 ; +--------+------+------------------------------------------+
33 ; | Offset | Size | Content(s) |
34 ; +--------+------+------------------------------------------+
37 ; | 4 | 1 | 16K PRG-ROM page count |
38 ; | 5 | 1 | 8K CHR-ROM page count |
39 ; | 6 | 1 | ROM Control Byte #1 |
41 ; | | | | ||||+- 0=Horizontal mirroring |
42 ; | | | | |||| 1=Vertical mirroring |
43 ; | | | | |||+-- 1=SRAM enabled |
44 ; | | | | ||+--- 1=512-byte trainer present |
45 ; | | | | |+---- 1=Four-screen mirroring |
47 ; | | | +--+----- Mapper # (lower 4-bits) |
48 ; | 7 | 1 | ROM Control Byte #2 |
51 ; | | | +--+----- Mapper # (upper 4-bits) |
53 ; | 16-.. | | Actual 16K PRG-ROM pages (in linear |
54 ; | ... | | order). If a trainer exists, it precedes |
55 ; | ... | | the first PRG-ROM page. |
56 ; | ..-EOF | | CHR-ROM pages (in ascending order). |
57 ; +--------+------+------------------------------------------+
59 .byte $4e,$45,$53,$1a ; "NES"^Z
60 .byte 2 ; ines prg - Specifies the number of 16k prg banks.
61 .byte 1 ; ines chr - Specifies the number of 8k chr banks.
62 .byte %00000011 ; ines mir - Specifies VRAM mirroring of the banks.
63 .byte %00000000 ; ines map - Specifies the NES mapper used.
64 .byte 0,0,0,0,0,0,0,0 ; 8 zeroes
67 ; ------------------------------------------------------------------------
68 ; Place the startup code in a special segment.
74 ; setup the CPU and System-IRQ
103 lda #<(__SRAM_START__ + __SRAM_SIZE__)
105 lda #>(__SRAM_START__ + __SRAM_SIZE__)
106 sta sp+1 ; Set argument stack ptr
108 ; Call module constructors
112 ; Push arguments and call main()
116 ; Call module destructors. This is also the _exit entry.
118 _exit: jsr donelib ; Run module destructors
124 ; ------------------------------------------------------------------------
125 ; System V-Blank Interupt
126 ; updates PPU Memory (buffered)
127 ; updates VBLANK_FLAG and tickcount
128 ; ------------------------------------------------------------------------
145 ; reset the video counter
169 ; ------------------------------------------------------------------------
171 ; ------------------------------------------------------------------------
177 .word timerirq ; $fff8 ?
178 .word nmi ; $fffa vblank nmi
179 .word start ; $fffc reset
180 .word irq ; $fffe irq / brk
182 ; ------------------------------------------------------------------------
184 ; ------------------------------------------------------------------------
188 .include "neschar.inc"