Last active
August 29, 2015 13:56
-
-
Save jedahan/8961805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.inesprg 2 ; 2x 16KB PRG code | |
.ineschr 1 ; 1x 8KB CHR data | |
.inesmap 0 ; mapper 0 = NROM, no bank swapping | |
.inesmir 1 ; background mirroring | |
;;;;;;;;;;;;;;; | |
.bank 2 | |
.org $C000 | |
RESET: | |
SEI ; disable IRQs | |
CLD ; disable decimal mode | |
LDX #$40 | |
STX $4017 ; disable APU frame IRQ | |
LDX #$FF | |
TXS ; Set up stack | |
INX ; now X = 0 | |
STX $2000 ; disable NMI | |
STX $2001 ; disable rendering | |
STX $4015 ; disable DMC IRQs | |
vblankwait1: ; First wait for vblank to make sure PPU is ready | |
BIT $2002 | |
BPL vblankwait1 | |
clrmem: | |
LDA #$00 | |
STA $0000, x | |
STA $0100, x | |
STA $0300, x | |
STA $0400, x | |
STA $0500, x | |
STA $0600, x | |
STA $0700, x | |
LDA #$FE | |
STA $0200, x | |
INX | |
BNE clrmem | |
vblankwait2: ; Second wait for vblank, PPU is ready after this | |
BIT $2002 | |
BPL vblankwait2 | |
LoadPalettes: | |
LDA $2002 ; read PPU status to reset the high/low latch | |
LDA #$3F | |
STA $2006 ; write the high byte of $3F00 address | |
LDA #$00 | |
STA $2006 ; write the low byte of $3F00 address | |
LDX #$00 ; start out at 0 | |
LoadPalettesLoop: | |
LDA palette, x ; load data from address (palette + the value in x) | |
; 1st time through loop it will load palette+0 | |
; 2nd time through loop it will load palette+1 | |
; 3rd time through loop it will load palette+2 | |
; etc | |
STA $2007 ; write to PPU | |
INX ; X = X + 1 | |
CPX #$20 ; Compare X to hex $20, decimal 32 - copying 32 bytes = 4 sprites | |
BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero | |
; if compare was equal to 64, keep going down | |
LoadBackground: | |
LDA $2002 ; read PPU status to reset the high/low latch | |
LDA #$20 | |
STA $2006 ; write the high byte ($20) of $2000 address | |
LDA #$00 | |
STA $2006 ; write the low byte ($00) of $2000 address | |
LDX #$00 ; start out at 0 | |
LoadBackgroundLoop: | |
LDA background, x ; load data from address (background + the value in x) | |
STA $2007 ; write to PPU | |
INX ; X++ | |
BNE LoadBackgroundLoop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero | |
; if compare was equal to 00, keep going down | |
LDX #$00 ; start out at 0 | |
LoadBackgroundLoop2: ; Do this one more time for the next 256 bytes | |
LDA background+256, x | |
STA $2007 | |
INX | |
BNE LoadBackgroundLoop2 | |
LDX #$00 | |
LoadBackgroundLoop3: ; Do this one more time for the next 256 bytes | |
LDA background+512, x | |
STA $2007 | |
INX | |
BNE LoadBackgroundLoop3 | |
LDX #$00 | |
LoadBackgroundLoop4: ; Do this one more time for the next 256 bytes | |
LDA background+768, x | |
STA $2007 | |
INX | |
BNE LoadBackgroundLoop4 | |
LoadAttribute: | |
LDA $2002 ; read PPU status to reset the high/low latch | |
LDA #$23 | |
STA $2006 ; write the high byte ($23) of $23C0 address | |
LDA #$C0 | |
STA $2006 ; write the low byte ($C0) of $23C0 address | |
LDX #$00 ; start out at 0 | |
LoadAttributeLoop: | |
LDA attribute, x ; load data from address (attribute + the value in x) | |
STA $2007 ; write to PPU | |
INX ; X = X + 1 | |
CPX #$40 ; Compare X to hex $40, decimal 16*4 - copying 64 bytes | |
BNE LoadAttributeLoop ; Branch to LoadAttributeLoop if compare was Not Equal to zero | |
; if X was equal to 64, keep going down | |
LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1 | |
STA $2000 | |
LDA #$00 | |
STA $2005 | |
LDA #$00 | |
STA $2005 | |
;;;;;;;;;;;;;; Here is our main loop. Beautiful. | |
Forever: | |
JMP Forever ;jump back to Forever, infinite loop | |
;;;;;;;;;;;;;; What to do in between frames? | |
NMI: | |
LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1 | |
STA $2000 | |
LDA #%00011110 ; enable sprites, enable background, no clipping on left side | |
STA $2001 | |
LDA #$00 | |
STA $2003 ; set the low byte (00) of the RAM address | |
LDA #$02 | |
STA $4014 ; set the high byte (02) of the RAM address, start the transfer | |
RTI ; return from interrupt | |
;;;;;;;;;;;;;; Setup nametables, attribute tables, palettes | |
.bank 3 | |
.org $E000 | |
palette: | |
.db $0F,$13,$23,$33, $0F,$44,$55,$66, $77,$88,$99,$AA, $0F,$78,$BD,$DE ;; background palette | |
.db $0F,$13,$23,$33, $0A,$44,$55,$66, $77,$88,$99,$AA, $0F,$78,$BD,$DE ;; sprite palette | |
background: | |
;; we put down 2 blank lines because NTSC is 240x224 instead of PALs 256x224 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1A,$1B,$1C,$1D,$1E,$1F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E,$4F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$5A,$5B,$5C,$5D,$5E,$5F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$6A,$6B,$6C,$6D,$6E,$6F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$7A,$7B,$7C,$7D,$7E,$7F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$7A,$7B,$7C,$7D,$7E,$7F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A,$9B,$9C,$9D,$9E,$9F | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $A0,$A1,$A2,$A3,$A4,$A5,$A6,$A7,$A8,$A9,$AA,$AB,$AC,$AD,$AE,$AF | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $B0,$B1,$B2,$B3,$B4,$B5,$B6,$B7,$B8,$B9,$BA,$BB,$BC,$BD,$BE,$BF | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $C0,$C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$C9,$CA,$CB,$CC,$CD,$CE,$CF | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $D0,$D1,$D2,$D3,$D4,$D5,$D6,$D7,$D8,$D9,$DA,$DB,$DC,$DD,$DE,$DF | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $E0,$E1,$E2,$E3,$E4,$E5,$E6,$E7,$E8,$E9,$EA,$EB,$EC,$ED,$EE,$EF | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7,$F8,$F9,$FA,$FB,$FC,$FD,$FE,$FF | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 | |
.db $00,$00,$00,$00,$00,$00,$00,$00 | |
attribute: ; attribute table is $40 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
.db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000 | |
;;;;;;;;;;;;;; Set up interrupts | |
.org $FFFA ;first of the three vectors starts here | |
.dw NMI ;when an NMI happens (once per frame if enabled) jump to label NMI | |
.dw RESET ;when the processor first turns on or is reset, jump to label RESET | |
.dw 0 ;external interrupt IRQ is not used in this tutorial | |
;;;;;;;;;;;;;; Load graphics file to a new bank | |
.bank 4 | |
.org $0000 | |
.incbin "embassy.chr" ;includes 8KB graphics file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment