Permalink
Cannot retrieve contributors at this time
145 lines (133 sloc)
2.63 KB
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
| .include "snes.inc" | |
| .include "global.inc" | |
| .smart | |
| .i16 | |
| .segment "CODE3" | |
| ;; | |
| ; Clears 2048 bytes ($1000 words) of video memory to a constant | |
| ; value. This can be one nametable, 128 2bpp tiles, 64 4bpp tiles, | |
| ; or 32 8bpp tiles. Must be called during vertical or forced blank. | |
| ; @param X starting address of nametable in VRAM (16-bit) | |
| ; @param Y value to write (16-bit) | |
| .proc ppu_clear_nt | |
| sty $0000 | |
| ldy #1024 ; number of bytes to clear | |
| ; Clear low bytes | |
| seta8 | |
| stz PPUCTRL ; +1 on PPUDATA low byte write | |
| lda #$00 ; point at low byte of Y | |
| jsl doonedma | |
| lda #INC_DATAHI ; +1 on PPUDATA high byte write | |
| sta PPUCTRL | |
| lda #$01 ; point at high byte of Y | |
| doonedma: | |
| stx PPUADDR | |
| sta DMAADDR | |
| ora #<PPUDATA | |
| sta DMAPPUREG | |
| lda #DMA_CONST|DMA_LINEAR | |
| sta DMAMODE | |
| sty DMALEN | |
| stz DMAADDRHI | |
| stz DMAADDRBANK | |
| lda #$01 | |
| sta COPYSTART | |
| rtl | |
| .endproc | |
| ;; | |
| ; Moves remaining entries in the CPU's local copy of OAM to | |
| ; (-128, 225) to get them offscreen. | |
| ; @param X index of first sprite in OAM (0-508) | |
| .proc ppu_clear_oam | |
| setaxy16 | |
| lowoamloop: | |
| lda #(225 << 8) | <-128 | |
| sta OAM,x | |
| lda #$0100 ; bit 8: offscreen | |
| sta OAMHI,x | |
| inx | |
| inx | |
| inx | |
| inx | |
| cpx #512 ; 128 sprites times 4 bytes per sprite | |
| bcc lowoamloop | |
| rtl | |
| .endproc | |
| ;; | |
| ; Converts high OAM (sizes and X sign bits) to the packed format | |
| ; expected by the S-PPU. | |
| .proc ppu_pack_oamhi | |
| setxy16 | |
| ldx #0 | |
| txy | |
| packloop: | |
| ; pack four sprites' size+xhi bits from OAMHI | |
| sep #$20 | |
| lda OAMHI+13,y | |
| asl a | |
| asl a | |
| ora OAMHI+9,y | |
| asl a | |
| asl a | |
| ora OAMHI+5,y | |
| asl a | |
| asl a | |
| ora OAMHI+1,y | |
| sta OAMHI,x | |
| rep #$21 ; seta16 + clc for following addition | |
| ; move to the next set of 4 OAM entries | |
| inx | |
| tya | |
| adc #16 | |
| tay | |
| ; done yet? | |
| cpx #32 ; 128 sprites divided by 4 sprites per byte | |
| bcc packloop | |
| rtl | |
| .endproc | |
| ;; | |
| ; Copies packed OAM data to the S-PPU using DMA channel 0. | |
| .proc ppu_copy_oam | |
| setaxy16 | |
| lda #DMAMODE_OAMDATA | |
| ldx #OAM | |
| ldy #544 | |
| ; falls through to ppu_copy | |
| .endproc | |
| ;; | |
| ; Copies data to the S-PPU using DMA channel 0. | |
| ; @param X source address | |
| ; @param DBR source bank | |
| ; @param Y number of bytes to copy | |
| ; @param A 15-8: destination PPU register; 7-0: DMA mode | |
| ; useful constants: | |
| ; DMAMODE_PPUDATA, DMAMODE_CGDATA, DMAMODE_OAMDATA | |
| .proc ppu_copy | |
| php | |
| setaxy16 | |
| sta DMAMODE | |
| stx DMAADDR | |
| sty DMALEN | |
| seta8 | |
| phb | |
| pla | |
| sta DMAADDRBANK | |
| lda #%00000001 | |
| sta COPYSTART | |
| plp | |
| rtl | |
| .endproc | |
| ;; | |
| ; Waits for the start of vertical blanking. | |
| .proc ppu_vsync | |
| php | |
| seta8 | |
| loop1: | |
| bit VBLSTATUS ; Wait for leaving previous vblank | |
| bmi loop1 | |
| loop2: | |
| bit VBLSTATUS ; Wait for start of this vblank | |
| bpl loop2 | |
| plp | |
| rtl | |
| .endproc | |