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 ; setup the CPU and System-IRQ
102 lda #<(__SRAM_START__ + __SRAM_SIZE__)
104 lda #>(__SRAM_START__ + __SRAM_SIZE__)
105 sta sp+1 ; Set argument stack ptr
107 ; Call module constructors
111 ; Push arguments and call main()
115 ; Call module destructors. This is also the _exit entry.
117 _exit: jsr donelib ; Run module destructors
123 ; ------------------------------------------------------------------------
124 ; System V-Blank Interupt
125 ; updates PPU Memory (buffered)
126 ; updates VBLANK_FLAG and tickcount
127 ; ------------------------------------------------------------------------
144 ; reset the video counter
168 ; ------------------------------------------------------------------------
170 ; ------------------------------------------------------------------------
176 .word timerirq ; $fff8 ?
177 .word nmi ; $fffa vblank nmi
178 .word start ; $fffc reset
179 .word irq ; $fffe irq / brk
181 ; ------------------------------------------------------------------------
183 ; ------------------------------------------------------------------------
187 .include "neschar.inc"