2003-04-14 21:28:51 +00:00
|
|
|
;
|
2018-08-29 16:13:58 +00:00
|
|
|
; Start-up code for cc65 (NES version)
|
2003-04-14 21:28:51 +00:00
|
|
|
;
|
|
|
|
; by Groepaz/Hitmen <groepaz@gmx.net>
|
|
|
|
; based on code by Ullrich von Bassewitz <uz@cc65.org>
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _exit
|
2009-07-31 12:05:42 +00:00
|
|
|
.export __STARTUP__ : absolute = 1 ; Mark as startup
|
2018-08-29 16:13:58 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.import initlib, donelib, callmain
|
|
|
|
.import push0, _main, zerobss, copydata
|
2003-04-14 21:28:51 +00:00
|
|
|
.import ppubuf_flush
|
|
|
|
|
2018-08-29 16:13:58 +00:00
|
|
|
; Linker-generated symbols
|
2013-05-09 11:56:54 +00:00
|
|
|
.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__
|
2003-05-02 13:40:01 +00:00
|
|
|
|
2018-08-29 16:13:58 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Character data
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
.forceimport NESfont
|
|
|
|
|
2003-04-14 21:28:51 +00:00
|
|
|
.include "zeropage.inc"
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "nes.inc"
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2018-08-29 16:13:58 +00:00
|
|
|
; 16-byte INES header
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
.segment "HEADER"
|
|
|
|
|
|
|
|
; +--------+------+------------------------------------------+
|
|
|
|
; | Offset | Size | Content(s) |
|
|
|
|
; +--------+------+------------------------------------------+
|
|
|
|
; | 0 | 3 | 'NES' |
|
|
|
|
; | 3 | 1 | $1A |
|
|
|
|
; | 4 | 1 | 16K PRG-ROM page count |
|
|
|
|
; | 5 | 1 | 8K CHR-ROM page count |
|
|
|
|
; | 6 | 1 | ROM Control Byte #1 |
|
|
|
|
; | | | %####vTsM |
|
|
|
|
; | | | | ||||+- 0=Horizontal mirroring |
|
|
|
|
; | | | | |||| 1=Vertical mirroring |
|
|
|
|
; | | | | |||+-- 1=SRAM enabled |
|
|
|
|
; | | | | ||+--- 1=512-byte trainer present |
|
|
|
|
; | | | | |+---- 1=Four-screen mirroring |
|
|
|
|
; | | | | | |
|
|
|
|
; | | | +--+----- Mapper # (lower 4-bits) |
|
|
|
|
; | 7 | 1 | ROM Control Byte #2 |
|
|
|
|
; | | | %####0000 |
|
|
|
|
; | | | | | |
|
|
|
|
; | | | +--+----- Mapper # (upper 4-bits) |
|
|
|
|
; | 8-15 | 8 | $00 |
|
|
|
|
; | 16-.. | | Actual 16K PRG-ROM pages (in linear |
|
|
|
|
; | ... | | order). If a trainer exists, it precedes |
|
|
|
|
; | ... | | the first PRG-ROM page. |
|
|
|
|
; | ..-EOF | | CHR-ROM pages (in ascending order). |
|
|
|
|
; +--------+------+------------------------------------------+
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.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
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Place the startup code in a special segment.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.segment "STARTUP"
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
start:
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set up the CPU and System-IRQ.
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
sei
|
|
|
|
cld
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #0
|
|
|
|
stx VBLANK_FLAG
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
stx ringread
|
|
|
|
stx ringwrite
|
|
|
|
stx ringcount
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
txs
|
|
|
|
|
|
|
|
lda #$20
|
|
|
|
@l: sta ringbuff,x
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ringbuff+$0100,x
|
|
|
|
sta ringbuff+$0200,x
|
2003-04-14 21:28:51 +00:00
|
|
|
inx
|
2013-05-09 11:56:54 +00:00
|
|
|
bne @l
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Clear the BSS data.
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr zerobss
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Initialize the data.
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr copydata
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Set up the stack.
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
lda #<(__SRAM_START__ + __SRAM_SIZE__)
|
2016-03-07 00:44:19 +00:00
|
|
|
ldx #>(__SRAM_START__ + __SRAM_SIZE__)
|
2013-05-09 11:56:54 +00:00
|
|
|
sta sp
|
2016-03-07 00:44:19 +00:00
|
|
|
stx sp+1 ; Set argument stack ptr
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the module constructors.
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr initlib
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Push the command-line arguments; and, call main().
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr callmain
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Call the module destructors. This is also the exit() entry.
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
_exit: jsr donelib ; Run module destructors
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Reset the NES.
|
2003-04-14 21:28:51 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp start
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2014-08-23 18:05:36 +00:00
|
|
|
; System V-Blank Interrupt
|
|
|
|
; Updates PPU Memory (buffered).
|
|
|
|
; Updates VBLANK_FLAG and tickcount.
|
2003-04-14 21:28:51 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nmi: pha
|
|
|
|
tya
|
|
|
|
pha
|
|
|
|
txa
|
|
|
|
pha
|
|
|
|
|
|
|
|
lda #1
|
|
|
|
sta VBLANK_FLAG
|
|
|
|
|
2003-05-02 13:40:01 +00:00
|
|
|
inc tickcount
|
2003-04-14 21:28:51 +00:00
|
|
|
bne @s
|
2003-05-02 13:40:01 +00:00
|
|
|
inc tickcount+1
|
2003-04-14 21:28:51 +00:00
|
|
|
|
|
|
|
@s: jsr ppubuf_flush
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Reset the video counter.
|
2003-04-14 21:28:51 +00:00
|
|
|
lda #$20
|
|
|
|
sta PPU_VRAM_ADDR2
|
|
|
|
lda #$00
|
|
|
|
sta PPU_VRAM_ADDR2
|
|
|
|
|
2014-08-23 18:05:36 +00:00
|
|
|
; Reset scrolling.
|
2003-04-14 21:28:51 +00:00
|
|
|
sta PPU_VRAM_ADDR1
|
|
|
|
sta PPU_VRAM_ADDR1
|
|
|
|
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
|
|
|
|
; Interrupt exit
|
|
|
|
|
|
|
|
irq:
|
|
|
|
rti
|
|
|
|
|
2018-08-29 16:13:58 +00:00
|
|
|
|
2003-04-14 21:28:51 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2018-08-29 16:13:58 +00:00
|
|
|
; Hardware vectors
|
2003-04-14 21:28:51 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.segment "VECTORS"
|
|
|
|
|
|
|
|
.word nmi ; $fffa vblank nmi
|
2013-05-09 11:56:54 +00:00
|
|
|
.word start ; $fffc reset
|
|
|
|
.word irq ; $fffe irq / brk
|