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>
9 .export __STARTUP__ : absolute = 1 ; Mark as startup
10 .import initlib, donelib, callmain
11 .import push0, _main, zerobss, copydata
14 ; Linker generated symbols
15 .import __RAM_START__, __RAM_SIZE__
16 .import __SRAM_START__, __SRAM_SIZE__
17 .import __ROM0_START__, __ROM0_SIZE__
18 .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__
19 .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__
20 .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__
22 .include "zeropage.inc"
26 ; ------------------------------------------------------------------------
27 ; 16 bytes INES header
31 ; +--------+------+------------------------------------------+
32 ; | Offset | Size | Content(s) |
33 ; +--------+------+------------------------------------------+
36 ; | 4 | 1 | 16K PRG-ROM page count |
37 ; | 5 | 1 | 8K CHR-ROM page count |
38 ; | 6 | 1 | ROM Control Byte #1 |
40 ; | | | | ||||+- 0=Horizontal mirroring |
41 ; | | | | |||| 1=Vertical mirroring |
42 ; | | | | |||+-- 1=SRAM enabled |
43 ; | | | | ||+--- 1=512-byte trainer present |
44 ; | | | | |+---- 1=Four-screen mirroring |
46 ; | | | +--+----- Mapper # (lower 4-bits) |
47 ; | 7 | 1 | ROM Control Byte #2 |
50 ; | | | +--+----- Mapper # (upper 4-bits) |
52 ; | 16-.. | | Actual 16K PRG-ROM pages (in linear |
53 ; | ... | | order). If a trainer exists, it precedes |
54 ; | ... | | the first PRG-ROM page. |
55 ; | ..-EOF | | CHR-ROM pages (in ascending order). |
56 ; +--------+------+------------------------------------------+
58 .byte $4e,$45,$53,$1a ; "NES"^Z
59 .byte 2 ; ines prg - Specifies the number of 16k prg banks.
60 .byte 1 ; ines chr - Specifies the number of 8k chr banks.
61 .byte %00000011 ; ines mir - Specifies VRAM mirroring of the banks.
62 .byte %00000000 ; ines map - Specifies the NES mapper used.
63 .byte 0,0,0,0,0,0,0,0 ; 8 zeroes
66 ; ------------------------------------------------------------------------
67 ; Place the startup code in a special segment.
73 ; Set up the CPU and System-IRQ.
97 ; Initialize the data.
102 lda #<(__SRAM_START__ + __SRAM_SIZE__)
103 ldx #>(__SRAM_START__ + __SRAM_SIZE__)
105 stx sp+1 ; Set argument stack ptr
107 ; Call the module constructors.
111 ; Push the command-line arguments; and, call main().
115 ; Call the module destructors. This is also the exit() entry.
117 _exit: jsr donelib ; Run module destructors
123 ; ------------------------------------------------------------------------
124 ; System V-Blank Interrupt
125 ; Updates PPU Memory (buffered).
126 ; Updates VBLANK_FLAG and tickcount.
127 ; ------------------------------------------------------------------------
144 ; Reset the video counter.
165 ; ------------------------------------------------------------------------
167 ; ------------------------------------------------------------------------
171 .word nmi ; $fffa vblank nmi
172 .word start ; $fffc reset
173 .word irq ; $fffe irq / brk
175 ; ------------------------------------------------------------------------
177 ; ------------------------------------------------------------------------
181 .include "neschar.inc"