.inesprg 1 ; 1x 16KB bank of PRG code .ineschr 1 ; 1x 8KB bank of CHR data .inesmap 0 ; mapper 0 = NROM, no bank swapping .inesmir 1 ; background mirroring (ignore for now) .bank 0 .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 $4010 ; 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 palette address at 0 LoadPalettesLoop: LDA palette, x STA $2007 ; write palette address to PPU INX ; X = X + 1 CPX #$20 ; If X != $20 (decimal 32)... BNE LoadPalettesLoop ; ...loop back to LoadPalettesLoop LoadSprites: LDX #$00 ; start sprite address at 0 LoadSpritesLoop: LDA sprites, x STA $0200, x ; write sprite address into RAM address ($0200 + x) INX ; X = X + 1 CPX #$10 ; If X != $10 (decimal 16)... BNE LoadSpritesLoop ; ...loop back to LoadSpritesLoop LoadBackground: LDA $2002 ; read PPU status to reset the high/low latch LDA #$20 STA $2006 ; write the high byte of $2000 address LDA #$00 STA $2006 ; write the low byte of $2000 address ; Load the empty space on the top 8 rows of the background LDA #$00 ; load tile 0 (blank) LDX #$00 ; start current background tile at 0 LoadEmptySpaceLoop: STA $2007 ; write to PPU INX ; X = X + 1 CPX #$00 ; If X != $00 (decimal 0; done to copy 256 bytes, or 8 rows)... BNE LoadEmptySpaceLoop ; ...loop back to LoadEmptySpaceLoop ; Load the top row of the diagonal square tiles LDX #$00 ; start current background tile at 0 LoadTopRowLoop: LDA bg_top_row, x ; load tile data for top row STA $2007 ; write to PPU INX ; X = X + 1 CPX #$20 ; If X != $20 (decimal 32, or 1 row)... BNE LoadTopRowLoop ; ...loop back to LoadTopRowLoop ; Load the rows of tiling for the diagonal square tiles LDY #$00 ; start at the 0th "row" of tiling ; really, 1 "row" is 2 rows of background LoadTilingRows: LDX #$00 ; start current background tile at 0 LoadTilingLoop: LDA bg_tiling, x ; load tile data for tiling row STA $2007 ; write to PPU INX ; X = X + 1 CPX #$40 ; If X != $40 (decimal 64, or 2 rows) BNE LoadTilingLoop ; ...loop back to LoadTilingLoop ; One "row" of tiling is done being drawn INY ; Y = Y + 1 CPY #$09 ; If Y != $09 (decimal 9, which will draw 9 "rows" of tiling) BNE LoadTilingRows ; ...loop back to LoadTilingRows LoadAttribute: LDA $2002 ; read PPU status to reset the high/low latch LDA #$23 STA $2006 ; write the high byte of $23C0 address LDA #$C0 STA $2006 ; write the low byte of $23C0 address LDA #$00 ; every square in the background will use palette 0 LDX #$00 ; start current attribute byte at 0 LoadAttributeLoop: STA $2007 ; write to PPU INX ; X = X + 1 CPX #$00 ; If X != $00 (decimal 0; done to copy 256 bytes)... BNE LoadAttributeLoop ; ...loop back to LoadAttributeLoop 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 Forever: JMP Forever ;jump back to Forever, infinite loop NMI: 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 LatchController: LDA #$01 STA $4016 LDA #$00 STA $4016 ; tell both the controllers to latch buttons ButtonA: LDA $4016 ; player 1 - A AND #%00000001 ; look only at bit 0 BNE ButtonB ; Button stuff here ButtonB: LDA $4016 ; player 1 - B AND #%00000001 ; look only at bit 0 BNE SelectButton ; Button stuff here SelectButton: LDA $4016 ; player 1 - Select AND #%00000001 ; look only at bit 0 BNE StartButton ; Button stuff here StartButton: LDA $4016 ; player 1 - Start AND #%00000001 ; look only at bit 0 BNE UpButton ; Button stuff here UpButton: LDA $4016 ; player 1 - Up AND #%00000001 ; look only at bit 0 BNE DownButton LDA $0200 ; load sprite Y position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $0200 ; save sprite Y position LDA $0204 ; load sprite Y position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $0204 ; save sprite Y position LDA $0208 ; load sprite Y position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $0208 ; save sprite Y position LDA $020C ; load sprite Y position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $020C ; save sprite Y position DownButton: LDA $4016 ; player 1 - Down AND #%00000001 ; look only at bit 0 BNE LeftButton LDA $0200 ; load sprite Y position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $0200 ; save sprite Y position LDA $0204 ; load sprite Y position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $0204 ; save sprite Y position LDA $0208 ; load sprite Y position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $0208 ; save sprite Y position LDA $020C ; load sprite Y position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $020C ; save sprite Y position LeftButton: LDA $4016 ; player 1 - Left AND #%00000001 ; look only at bit 0 BNE RightButton LDA $0203 ; load sprite X position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $0203 ; save sprite X position LDA $0207 ; load sprite X position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $0207 ; save sprite X position LDA $020B ; load sprite X position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $020B ; save sprite X position LDA $020F ; load sprite X position CLC ; clear carry for addition ADC #$01 ; A = A + 1 STA $020F ; save sprite X position RightButton: LDA $4016 ; player 1 - Right AND #%00000001 ; look only at bit 0 BNE NotRightButton LDA $0203 ; load sprite X position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $0203 ; save sprite X position LDA $0207 ; load sprite X position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $0207 ; save sprite X position LDA $020B ; load sprite X position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $020B ; save sprite X position LDA $020F ; load sprite X position SEC ; set carry for subtraction SBC #$01 ; A = A - 1 STA $020F ; save sprite X position NotRightButton: JMP ButtonA RTI ;;;;;;;;;;;;;; .bank 1 .org $E000 palette: .db $3B,$20,$00,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette .db $3B,$20,$00,$0F, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette sprites: ;vert tile attr horiz .db $80, $00, $00, $80 ;sprite 0 .db $80, $01, $00, $88 ;sprite 1 .db $88, $02, $00, $80 ;sprite 2 .db $88, $03, $00, $88 ;sprite 3 bg_top_row: .db $01,$02,$01,$02,$01,$02,$01,$02,$01,$02,$01,$02,$01,$02,$01,$02 ;;one row of lone white-square tops .db $01,$02,$01,$02,$01,$02,$01,$02,$01,$02,$01,$02,$01,$02,$01,$02 ;; bg_tiling: .db $03,$04,$03,$04,$03,$04,$03,$04,$03,$04,$03,$04,$03,$04,$03,$04 ;;one row of white-square bottoms .db $03,$04,$03,$04,$03,$04,$03,$04,$03,$04,$03,$04,$03,$04,$03,$04 ;; .db $05,$06,$05,$06,$05,$06,$05,$06,$05,$06,$05,$06,$05,$06,$05,$06 ;;one row of white-square tops .db $05,$06,$05,$06,$05,$06,$05,$06,$05,$06,$05,$06,$05,$06,$05,$06 ;; .org $FFFA .dw NMI .dw RESET .dw 0 ;;;;;;;;;;;;;; .bank 2 .org $0000 .incbin "walrush.chr" ;include graphics file for WalRush