123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- ;============================================================================
- ; Macros
- ;============================================================================
- ;============================================================================
- ;LoadPalette - Macro that loads palette information into CGRAM
- ;----------------------------------------------------------------------------
- ; In: SRC_ADDR -- 24 bit address of source data,
- ; START -- Color # to start on,
- ; SIZE -- # of COLORS to copy
- ;----------------------------------------------------------------------------
- ; Out: None
- ;----------------------------------------------------------------------------
- ; Modifies: A,X
- ; Requires: mem/A = 8 bit, X/Y = 16 bit
- ;----------------------------------------------------------------------------
- .MACRO LoadPalette
- lda #\2
- sta $2121 ; Start at START color
- lda #:\1 ; Using : before the parameter gets its bank.
- ldx #\1 ; Not using : gets the offset address.
- ldy #(\3 * 2) ; 2 bytes for every color
- jsr DMAPalette
- .ENDM
- ;============================================================================
- ; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM
- ;----------------------------------------------------------------------------
- ; In: SRC_ADDR -- 24 bit address of source data
- ; DEST -- VRAM address to write to (WORD address!!)
- ; SIZE -- number of BYTEs to copy
- ;----------------------------------------------------------------------------
- ; Out: None
- ;----------------------------------------------------------------------------
- ; Modifies: A, X, Y
- ;----------------------------------------------------------------------------
- ;LoadBlockToVRAM SRC_ADDRESS, DEST, SIZE
- ; requires: mem/A = 8 bit, X/Y = 16 bit
- .MACRO LoadBlockToVRAM
- lda #$80
- sta $2115
- ldx #\2 ; DEST
- stx $2116 ; $2116: Word address for accessing VRAM.
- lda #:\1 ; SRCBANK
- ldx #\1 ; SRCOFFSET
- ldy #\3 ; SIZE
- jsr LoadVRAM
- .ENDM
- ;============================================================================
- ; Routines
- ;============================================================================
- .BANK 0
- .ORG 0
- .SECTION "LoadVRAMCode" SEMIFREE
- ;============================================================================
- ; LoadVRAM -- Load data into VRAM
- ;----------------------------------------------------------------------------
- ; In: A:X -- points to the data
- ; Y -- Number of bytes to copy (0 to 65535) (assumes 16-bit index)
- ;----------------------------------------------------------------------------
- ; Out: None
- ;----------------------------------------------------------------------------
- ; Modifies: none
- ;----------------------------------------------------------------------------
- ; Notes: Assumes VRAM address has been previously set!!
- ;----------------------------------------------------------------------------
- LoadVRAM:
- pha
- phx
- phy
- phb
- php ; Preserve Registers
-
- sep #$20
- stx $4302 ; Store Data offset into DMA source offset
- sta $4304 ; Store data Bank into DMA source bank
- sty $4305 ; Store size of data block
- lda #$01
- sta $4300 ; Set DMA mode (word, normal increment)
- lda #$18 ; Set the destination register (VRAM write register)
- sta $4301
- lda #$01 ; Initiate DMA transfer (channel 1)
- sta $420B
- plp ; restore registers
- plb
- ply
- plx
- pla
- rts ; return
- ;============================================================================
- .ENDS
- .BANK 0
- .ORG 0
- .SECTION "DMAPaletteCode" SEMIFREE
- ;============================================================================
- ; DMAPalette -- Load entire palette using DMA
- ;----------------------------------------------------------------------------
- ; In: A:X -- points to the data
- ; Y -- Size of data
- ;----------------------------------------------------------------------------
- ; Out: None
- ;----------------------------------------------------------------------------
- ; Modifies: none
- ;----------------------------------------------------------------------------
- DMAPalette:
- pha
- phx
- phb
- php ; Preserve Registers
-
- sep #$20
- stx $4302 ; Store data offset into DMA source offset
- sta $4304 ; Store data bank into DMA source bank
- sty $4305 ; Store size of data block
- stz $4300 ; Set DMA Mode (byte, normal increment)
- lda #$22 ; Set destination register ($2122 - CGRAM Write)
- sta $4301
- lda #$01 ; Initiate DMA transfer
- sta $420B
- plp ; Restore registers
- plb
- plx
- pla
- rts ; return from subroutine
- ;============================================================================
- .ENDS
|