Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;----------------------------------------------------------------
- ; constants
- ;----------------------------------------------------------------
- PRG_COUNT = 1 ;1 = 16KB, 2 = 32KB
- MIRRORING = %0001 ;%0000 = horizontal, %0001 = vertical, %1000 = four-screen
- ;----------------------------------------------------------------
- ; variables
- ;----------------------------------------------------------------
- .enum $0000
- 00000
- 00000 ;NOTE: declare variables using the DSB and DSW directives, like this:
- 00000
- 00000 ;MyVariable0 .dsb 1
- 00000 ;MyVariable1 .dsb 3
- 00000
- 00000 .ende
- ;NOTE: you can also split the variable declarations into individual pages, like this:
- ;.enum $0100
- ;.ende
- ;.enum $0200
- ;.ende
- ;----------------------------------------------------------------
- ; iNES header
- ;----------------------------------------------------------------
- 4E 45 53 1A .db "NES", $1a ;identification of the iNES header
- 01 .db PRG_COUNT ;number of 16KB PRG-ROM pages
- 01 .db $01 ;number of 8KB CHR-ROM pages
- 01 .db $00|MIRRORING ;mapper 0 and mirroring
- 00 00 00 00 00 00 00 00.. .dsb 9, $00 ;clear the remaining bytes
- ;----------------------------------------------------------------
- ; program bank(s)
- ;----------------------------------------------------------------
- .base $10000-(PRG_COUNT*$4000)
- 0C000
- 0C000 Reset:
- 0C000
- 0C000 78 sei ; ignore IRQs
- 0C001 D8 cld ; disable decimal mode
- 0C002 A2 40 ldx #$40
- 0C004 8E 17 40 stx $4017 ; disable APU frame IRQ
- 0C007 A2 FF ldx #$ff
- 0C009 9A txs ; Set up stack
- 0C00A E8 inx ; now X = 0
- 0C00B 8E 00 20 stx $2000 ; disable NMI
- 0C00E 8E 01 20 stx $2001 ; disable rendering
- 0C011 8E 10 40 stx $4010 ; disable DMC IRQs
- 0C014
- 0C014 ; Optional (omitted):
- 0C014 ; Set up mapper and jmp to further init code here.
- 0C014
- 0C014 ; Clear the vblank flag, so we know that we are waiting for the
- 0C014 ; start of a vertical blank and not powering on with the
- 0C014 ; vblank flag spuriously set
- 0C014 2C 02 20 bit $2002
- 0C017
- 0C017 ; First of two waits for vertical blank to make sure that the
- 0C017 ; PPU has stabilized
- 0C017 @vblankwait1:
- 0C017 2C 02 20 bit $2002
- 0C01A 10 FB bpl @vblankwait1
- 0C01C
- 0C01C ; We now have about 30,000 cycles to burn before the PPU stabilizes.
- 0C01C ; One thing we can do with this time is put RAM in a known state.
- 0C01C ; Here we fill it with $00, which matches what (say) a C compiler
- 0C01C ; expects for BSS. Conveniently, X is still 0.
- 0C01C 8A txa
- 0C01D @clrmem:
- 0C01D 95 00 sta $000,x
- 0C01F 9D 00 01 sta $100,x
- 0C022 9D 00 03 sta $300,x
- 0C025 9D 00 04 sta $400,x
- 0C028 9D 00 05 sta $500,x
- 0C02B 9D 00 06 sta $600,x
- 0C02E 9D 00 07 sta $700,x ; Remove this if you're storing reset-persistent data
- 0C031
- 0C031 ; We skipped $200,x on purpose. Usually, RAM page 2 is used for the
- 0C031 ; display list to be copied to OAM. OAM needs to be initialized to
- 0C031 ; $EF-$FF, not 0, or you'll get a bunch of garbage sprites at (0, 0).
- 0C031
- 0C031 E8 inx
- 0C032 D0 E9 bne @clrmem
- 0C034
- 0C034 ; Other things you can do between vblank waits are set up audio
- 0C034 ; or set up other mapper registers.
- 0C034
- 0C034 @vblankwait2:
- 0C034 2C 02 20 bit $2002
- 0C037 10 FB bpl @vblankwait2
- 0C039
- 0C039
- 0C039 A9 3F LDA #$3F
- 0C03B 8D 06 20 STA $2006
- 0C03E A9 00 LDA #$00
- 0C040 8D 06 20 STA $2006
- 0C043 A9 2A LDA #$2A
- 0C045 8D 07 20 STA $2007
- 0C048
- 0C048 A9 32 LDA #$32 ;code for light blueish
- 0C04A 8D 07 20 STA $2007 ;write to PPU $3F10
- 0C04D A9 14 LDA #$14 ;code for pinkish
- 0C04F 8D 07 20 STA $2007 ;write to PPU $3F11
- 0C052 A9 2A LDA #$2A ;code for greenish
- 0C054 8D 07 20 STA $2007 ;write to PPU $3F12
- 0C057 A9 16 LDA #$16 ;code for redish
- 0C059 8D 07 20 STA $2007 ;write to PPU $3F13
- 0C05C A9 32 LDA #$32 ;code for light blueish
- 0C05E 8D 07 20 STA $2007 ;write to PPU $3F10
- 0C061 A9 32 LDA #$32 ;code for pinkish
- 0C063 8D 07 20 STA $2007 ;write to PPU $3F11
- 0C066 A9 30 LDA #$30 ;code for greenish
- 0C068 8D 07 20 STA $2007 ;write to PPU $3F12
- 0C06B A9 30 LDA #$30 ;code for redish
- 0C06D 8D 07 20 STA $2007 ;write to PPU $3F13
- 0C070
- 0C070 A2 00 LDX #$00 ; start out at 0
- 0C072 LoadPalettesLoop:
- 0C072 BD 00 00 LDA PaletteData, x ; load data from address (PaletteData + the value in x)
- *** Unknown label.
- 0C075 ; 1st time through loop it will load PaletteData+0
- 0C075 ; 2nd time through loop it will load PaletteData+1
- 0C075 ; 3rd time through loop it will load PaletteData+2
- 0C075 ; etc
- 0C075 8D 07 20 STA $2007 ; write to PPU
- 0C078 E8 INX ; X = X + 1
- 0C079 E0 20 CPX #$20 ; Compare X to hex $20, decimal 32
- 0C07B D0 F5 BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
- 0C07D ; if compare was equal to 32, keep going down
- 0C07D
- 0C07D
- 0C07D A9 18 LDA #%00011000
- 0C07F 8D 01 20 STA $2001
- 0C082
- 0C082
- 0C082 loop:
- 0C082 4C 82 C0 jmp loop
- 0C085
- 0C085 NMI:
- 0C085
- 0C085
- 0C085
- 0C085 IRQ:
- 0C085
- 0C085 ;NOTE: IRQ code goes here
- 0C085
- 0C085 ;----------------------------------------------------------------
- 0C085 ; interrupt vectors
- 0C085 ;----------------------------------------------------------------
- 0C085
- 0C085 00 00 00 00 00 00 00 00.. .org $fffa
- 0FFFA
- 0FFFA 85 C0 .dw NMI
- 0FFFC 00 C0 .dw Reset
- 0FFFE 85 C0 .dw IRQ
- 10000
- 10000 ;----------------------------------------------------------------
- 10000 ; CHR-ROM bank
- 10000 ;----------------------------------------------------------------
- 10000
- 10000 00 00 00 00 00 00 00 00.. .incbin "pong.chr"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement