; PPU utilities ; Clears VBL flag then waits for it to be set ; Preserved: A, X, Y wait_vbl: bit PPUSTATUS : bit PPUSTATUS bpl :- rts ; Turns NMI on ; Preserved: X, Y nmi_on: lda #PPUCTRL_NMI sta PPUCTRL rts ; Turns NMI off ; Preserved: X, Y nmi_off: lda #0 sta PPUCTRL rts ; Sets VRAM address to A * $100 ; Preserved: X, Y set_vpage: bit PPUSTATUS sta PPUADDR lda #0 sta PPUADDR rts ; Sets VRAM address to A * $100 + X ; Preserved: A, X, Y set_vaddr: bit PPUSTATUS sta PPUADDR stx PPUADDR rts ; Sets X and Y scroll ; Preserved: A, X, Y set_vscroll: bit PPUSTATUS stx PPUSCROLL sty PPUSCROLL rts ; Turns off NMI and disables BG and sprites ; Preserved: A, X, Y disable_ppu: pha lda #0 sta PPUCTRL sta PPUMASK bit PPUSTATUS sta PPUADDR sta PPUADDR pla rts ; Sets sprite memory to $FF ; Preserved: Y clear_sprites: lda #$ff ldx #0 : sta SPRDATA dex bne :- rts ; Clears/fills nametable with 0/A and clear attributes to 0 clear_nametable: lda #0 fill_nametable: pha lda #$20 jsr set_vpage pla ldx #240 : sta PPUDATA sta PPUDATA sta PPUDATA sta PPUDATA dex bne :- lda #0 ldx #64 : sta PPUDATA dex bne :- rts ; Clears/fills VRAM with 0/A clear_vram: lda #0 fill_vram: ldx #0 ldy #$24 bne fill_vram_ ; Clears/fills CHR with 0/A fill_chr1: ldx #$10 ldy #$10 bne fill_vram_ fill_chr0: ldx #0 ldy #$10 bne fill_vram_ clear_chr: lda #0 fill_chr: ldx #0 ldy #$20 ; Fill Y*$100 bytes of VRAM with A, starting at X*$100 fill_vram_: bit PPUSTATUS stx PPUADDR ldx #0 stx PPUADDR : sta PPUDATA dex bne :- dey bne :- rts