;macro for loading graphics data into the VRAM ;only use if SIZE is less than 256 bytes ;syntax LoadVRAM LABEL VRAM_ADDRESS SIZE .macro LoadVRAM pha ; save the current accumulator, Y index and status registers for the time the function is executed. phy php rep #$20 ; set the accumulator (A) register into 16 bit mode sep #$10 ; set the index (X and Y) register into 8 bit mode ldy #$80 ; we will try to write 128 ($80) bytes in one row ... sty $2115 ; ... and we will let the PPU let this know. lda #\2 ; the controller will get the hardware register ($2118) as location to where to write the data. sta $2116 ; but we still need to specify WHERE in VRAM we want to write the data - what we are doing right now. ldy #\3 ; number of bytes to be sent from the controller. sty $4305 lda #\1 ; from where the data is supposed to be loaded from sta $4302 sep #$20 ; set the accumulator (A) register into 8 bit mode ldy #:\1 ; from which bank the data is supposed to be loaded from sty $4304 ldy #$01 ; set the mode on how the channel is supposed to do it's work. 1= word increment sty $4300 ldy #$18 ; remember that I wrote "the controller will get the hardware register"? This is it. 2118 is the VRAM gate. sty $4301 ldy #$01 ; turn on bit 1 (channel 0) of DMA - that is, start rollin' sty $420b plp ; Restore the state of all registers before leaving the function. ply pla .endm