2 ; Start-up 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
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 ; ------------------------------------------------------------------------
25 ; ------------------------------------------------------------------------
28 .include "zeropage.inc"
32 ; ------------------------------------------------------------------------
37 ; +--------+------+------------------------------------------+
38 ; | Offset | Size | Content(s) |
39 ; +--------+------+------------------------------------------+
42 ; | 4 | 1 | 16K PRG-ROM page count |
43 ; | 5 | 1 | 8K CHR-ROM page count |
44 ; | 6 | 1 | ROM Control Byte #1 |
46 ; | | | | ||||+- 0=Horizontal mirroring |
47 ; | | | | |||| 1=Vertical mirroring |
48 ; | | | | |||+-- 1=SRAM enabled |
49 ; | | | | ||+--- 1=512-byte trainer present |
50 ; | | | | |+---- 1=Four-screen mirroring |
52 ; | | | +--+----- Mapper # (lower 4-bits) |
53 ; | 7 | 1 | ROM Control Byte #2 |
56 ; | | | +--+----- Mapper # (upper 4-bits) |
58 ; | 16-.. | | Actual 16K PRG-ROM pages (in linear |
59 ; | ... | | order). If a trainer exists, it precedes |
60 ; | ... | | the first PRG-ROM page. |
61 ; | ..-EOF | | CHR-ROM pages (in ascending order). |
62 ; +--------+------+------------------------------------------+
64 .byte $4e,$45,$53,$1a ; "NES"^Z
65 .byte 2 ; ines prg - Specifies the number of 16k prg banks.
66 .byte 1 ; ines chr - Specifies the number of 8k chr banks.
67 .byte %00000011 ; ines mir - Specifies VRAM mirroring of the banks.
68 .byte %00000000 ; ines map - Specifies the NES mapper used.
69 .byte 0,0,0,0,0,0,0,0 ; 8 zeroes
72 ; ------------------------------------------------------------------------
73 ; Place the startup code in a special segment.
79 ; Set up the CPU and System-IRQ.
103 ; Initialize the data.
108 lda #<(__SRAM_START__ + __SRAM_SIZE__)
109 ldx #>(__SRAM_START__ + __SRAM_SIZE__)
111 stx sp+1 ; Set argument stack ptr
113 ; Call the module constructors.
117 ; Push the command-line arguments; and, call main().
121 ; Call the module destructors. This is also the exit() entry.
123 _exit: jsr donelib ; Run module destructors
129 ; ------------------------------------------------------------------------
130 ; System V-Blank Interrupt
131 ; Updates PPU Memory (buffered).
132 ; Updates VBLANK_FLAG and tickcount.
133 ; ------------------------------------------------------------------------
150 ; Reset the video counter.
172 ; ------------------------------------------------------------------------
174 ; ------------------------------------------------------------------------
178 .word nmi ; $fffa vblank nmi
179 .word start ; $fffc reset
180 .word irq ; $fffe irq / brk