; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM ;---------------------------------------------------------------------------- ; In: PALBANK -- bank of source data (00-FF) ; PALOFFSET -- offset into PALBANK of source data ; PALSTART -- CGRAM address to write to (palette index) ; PALSIZE -- number of colors to copy (2 bytes per color) ;---------------------------------------------------------------------------- ; Out: None ;---------------------------------------------------------------------------- ; Modifies: X, Y ;---------------------------------------------------------------------------- LoadNewPalette .macro (PALBANK,PALOFFSET,PALSTART,PALSIZE) PHB PHA PHP REP #$10 SEP #$20 .mem 8 .index 16 LDA #PALBANK PHA PLB LDX #PALOFFSET AND $FFFF LDY #PALSIZE-1 LDA #PALSTART JSR LoadPalette PLP PLA PLB .endm ;============================================================================ ; LoadPalette -- Load palette data into PPU Color RAM ;---------------------------------------------------------------------------- ; In: DS:X -- points to the palette data (in standard SNES color format) ; Y -- Number of colors in palette - 1 (0 to 255) ; A -- First color index to write to (0 to 255) ;---------------------------------------------------------------------------- ; Out: None ;---------------------------------------------------------------------------- ; Modifies: none ;---------------------------------------------------------------------------- LoadPalette: php pha phx phy ;Preserve registers rep #$30 sep #$20 .mem 8 .index 16 iny ;Increment Y (so Y=count instead of count-1) sta $802121 ;Store the first color index into CGADDR - lda !$0000,X ;Load the first byte of the color sta $802122 ;store it into CGDATA inx ;increment input pointer lda !$0000,X ;Load the second byte of the color sta $802122 ;store it into CGDATA inx ;increment input pointer dey ;Decrement color count bne - ;If color count is not zero (zero flag != 0), continue loop ply plx pla plp rts ;============================================================================